@@ -27,7 +27,6 @@ import (
27
27
"time"
28
28
29
29
v1 "github.com/Keyfactor/keyfactor-go-client-sdk/v24/api/keyfactor/v1"
30
- "github.com/hashicorp/errwrap"
31
30
"github.com/hashicorp/vault/sdk/helper/errutil"
32
31
"github.com/hashicorp/vault/sdk/logical"
33
32
"go.mozilla.org/pkcs7"
@@ -78,7 +77,7 @@ func (b *keyfactorBackend) submitCSR(ctx context.Context, req *logical.Request,
78
77
}
79
78
80
79
// build request parameter structure
81
- var metadataMap map [string ]interface {}
80
+ metadataMap := make ( map [string ]interface {})
82
81
83
82
err = json .Unmarshal ([]byte (metaDataJson ), & metadataMap )
84
83
@@ -95,12 +94,12 @@ func (b *keyfactorBackend) submitCSR(ctx context.Context, req *logical.Request,
95
94
Metadata : metadataMap ,
96
95
Timestamp : & time ,
97
96
Template : * v1 .NewNullableString (& templateName ),
98
- // SANs: map[string][]string{} ,
97
+ SANs : make ( map [string ][]string ) ,
99
98
}
100
99
101
100
// SANs parameter
102
- b .Logger ().Debug ("ip_sans = %s" , ip_sans )
103
- b .Logger ().Debug ("dns_sans = %s" , dns_sans )
101
+ b .Logger ().Debug (fmt . Sprintf ( "ip_sans = %s" , ip_sans ) )
102
+ b .Logger ().Debug (fmt . Sprintf ( "dns_sans = %s" , dns_sans ) )
104
103
105
104
if len (ip_sans ) > 0 {
106
105
enrollmentRequest .SANs ["ip" ] = ip_sans
@@ -110,38 +109,43 @@ func (b *keyfactorBackend) submitCSR(ctx context.Context, req *logical.Request,
110
109
enrollmentRequest .SANs ["dns" ] = dns_sans
111
110
}
112
111
113
- reqMap , _ := enrollmentRequest .ToMap ()
112
+ reqMap := make (map [string ]interface {})
113
+ reqMap , err = enrollmentRequest .ToMap ()
114
114
115
- b .Logger ().Debug ("request body: %s" , reqMap )
115
+ if err != nil {
116
+ b .Logger ().Error (fmt .Sprintf ("conversion of paramaters to map failed: %s" , err .Error ()))
117
+ }
118
+
119
+ b .Logger ().Debug (fmt .Sprintf ("request body: %s" , reqMap ))
116
120
117
121
// Send request and check status
118
122
119
- b .Logger ().Debug ("about to connect to " + config .KeyfactorUrl + " with Keyfactor client for CSR submission" )
123
+ b .Logger ().Debug ("setting parameters on the request.. " )
124
+
125
+ apiRequest := client .V1 .EnrollmentApi .NewCreateEnrollmentCSRRequest (ctx ).EnrollmentCSREnrollmentRequest (enrollmentRequest ).XCertificateformat ("PEM" )
120
126
121
- apiRequest := client .V1 .EnrollmentApi .NewCreateEnrollmentCSRRequest (ctx )
122
- apiRequest .XCertificateformat ("PEM" )
123
- apiRequest .EnrollmentCSREnrollmentRequest (enrollmentRequest )
127
+ b .Logger ().Debug ("about to connect to " + config .KeyfactorUrl + " with Keyfactor client for CSR submission" )
124
128
125
129
resData , httpRes , err := apiRequest .Execute ()
126
130
127
131
if err != nil || httpRes .StatusCode != 200 {
128
- b .Logger ().Error ("there was an error performing CSR enrollment. HttpStatusCode: %d, error: %s" , httpRes .StatusCode , err )
132
+ b .Logger ().Error (fmt . Sprintf ( "there was an error performing CSR enrollment. HttpStatusCode: %d, error: %s" , httpRes .StatusCode , err ) )
129
133
return nil , "" , err
130
134
}
131
135
132
136
// Read certificates from response
133
137
certs , ok := resData .CertificateInformation .GetCertificatesOk ()
134
138
135
139
if ! ok {
136
- b .Logger ().Error ("unable to read certificate response : %s" , err )
140
+ b .Logger ().Error (fmt . Sprintf ( "unable to read certificate response : %s" , err ) )
137
141
return nil , "" , err
138
142
}
139
143
140
144
serial := resData .CertificateInformation .SerialNumber
141
145
kfId := resData .CertificateInformation .KeyfactorID
142
146
143
147
resMap , _ := resData .ToMap ()
144
- b .Logger ().Debug ("full response: %s" , resMap )
148
+ b .Logger ().Debug (fmt . Sprintf ( "full response: %s" , resMap ) )
145
149
146
150
// store the ca chain
147
151
@@ -170,7 +174,7 @@ func (b *keyfactorBackend) submitCSR(ctx context.Context, req *logical.Request,
170
174
171
175
err = req .Storage .Put (ctx , entry )
172
176
if err != nil {
173
- return nil , "" , errwrap . Wrapf ("unable to store certificate locally: {{err}}" , err )
177
+ return nil , "" , fmt . Errorf ("unable to store certificate locally: {{err}}" , err )
174
178
}
175
179
176
180
kfIdEntry , err := logical .StorageEntryJSON ("kfId/" + normalizedSerial , kfId )
@@ -180,7 +184,7 @@ func (b *keyfactorBackend) submitCSR(ctx context.Context, req *logical.Request,
180
184
181
185
err = req .Storage .Put (ctx , kfIdEntry )
182
186
if err != nil {
183
- return nil , "" , errwrap . Wrapf ("unable to store the keyfactor ID for the certificate locally: {{err}}" , err )
187
+ return nil , "" , fmt . Errorf ("unable to store the keyfactor ID for the certificate locally: {{err}}" , err )
184
188
}
185
189
186
190
return certs , normalizedSerial , nil
@@ -203,7 +207,7 @@ func fetchCAInfo(ctx context.Context, req *logical.Request, b *keyfactorBackend,
203
207
if includeChain {
204
208
storagePath = fmt .Sprintf ("%s_chain" , storagePath ) // the storage path for the ca chain is "ca/{{ca name}}_chain"
205
209
}
206
- b .Logger ().Debug ("local storage path = %s" , storagePath )
210
+ b .Logger ().Debug (fmt . Sprintf ( "local storage path = %s" , storagePath ) )
207
211
208
212
caEntry , err := req .Storage .Get (ctx , storagePath )
209
213
@@ -546,67 +550,67 @@ func ConvertBase64P7BtoPEM(base64P7B string) ([]string, error) {
546
550
return pemEncodedCerts , nil
547
551
}
548
552
549
- type KeyfactorCertResponse []struct {
550
- ID int `json:"Id"`
551
- Thumbprint string `json:"Thumbprint"`
552
- SerialNumber string `json:"SerialNumber"`
553
- IssuedDN string `json:"IssuedDN"`
554
- IssuedCN string `json:"IssuedCN"`
555
- ImportDate time.Time `json:"ImportDate"`
556
- NotBefore time.Time `json:"NotBefore"`
557
- NotAfter time.Time `json:"NotAfter"`
558
- IssuerDN string `json:"IssuerDN"`
559
- PrincipalID interface {} `json:"PrincipalId"`
560
- TemplateID interface {} `json:"TemplateId"`
561
- CertState int `json:"CertState"`
562
- KeySizeInBits int `json:"KeySizeInBits"`
563
- KeyType int `json:"KeyType"`
564
- RequesterID int `json:"RequesterId"`
565
- IssuedOU interface {} `json:"IssuedOU"`
566
- IssuedEmail interface {} `json:"IssuedEmail"`
567
- KeyUsage int `json:"KeyUsage"`
568
- SigningAlgorithm string `json:"SigningAlgorithm"`
569
- CertStateString string `json:"CertStateString"`
570
- KeyTypeString string `json:"KeyTypeString"`
571
- RevocationEffDate interface {} `json:"RevocationEffDate"`
572
- RevocationReason interface {} `json:"RevocationReason"`
573
- RevocationComment interface {} `json:"RevocationComment"`
574
- CertificateAuthorityID int `json:"CertificateAuthorityId"`
575
- CertificateAuthorityName string `json:"CertificateAuthorityName"`
576
- TemplateName interface {} `json:"TemplateName"`
577
- ArchivedKey bool `json:"ArchivedKey"`
578
- HasPrivateKey bool `json:"HasPrivateKey"`
579
- PrincipalName interface {} `json:"PrincipalName"`
580
- CertRequestID interface {} `json:"CertRequestId"`
581
- RequesterName string `json:"RequesterName"`
582
- ContentBytes string `json:"ContentBytes"`
583
- ExtendedKeyUsages []interface {} `json:"ExtendedKeyUsages"`
584
- SubjectAltNameElements []interface {} `json:"SubjectAltNameElements"`
585
- CRLDistributionPoints []interface {} `json:"CRLDistributionPoints"`
586
- LocationsCount []interface {} `json:"LocationsCount"`
587
- SSLLocations []interface {} `json:"SSLLocations"`
588
- Locations []interface {} `json:"Locations"`
589
- Metadata Metadata `json:"Metadata"`
590
- CertificateKeyID int `json:"CertificateKeyId"`
591
- CARowIndex int `json:"CARowIndex"`
592
- DetailedKeyUsage DetailedKeyUsage `json:"DetailedKeyUsage"`
593
- KeyRecoverable bool `json:"KeyRecoverable"`
594
- }
595
- type Metadata struct {
596
- }
597
- type DetailedKeyUsage struct {
598
- CrlSign bool `json:"CrlSign"`
599
- DataEncipherment bool `json:"DataEncipherment"`
600
- DecipherOnly bool `json:"DecipherOnly"`
601
- DigitalSignature bool `json:"DigitalSignature"`
602
- EncipherOnly bool `json:"EncipherOnly"`
603
- KeyAgreement bool `json:"KeyAgreement"`
604
- KeyCertSign bool `json:"KeyCertSign"`
605
- KeyEncipherment bool `json:"KeyEncipherment"`
606
- NonRepudiation bool `json:"NonRepudiation"`
607
- HexCode string `json:"HexCode"`
608
- }
609
-
610
- type KeyfactorCertDownloadResponse struct {
611
- Content string `json:"Content"`
612
- }
553
+ // type KeyfactorCertResponse []struct {
554
+ // ID int `json:"Id"`
555
+ // Thumbprint string `json:"Thumbprint"`
556
+ // SerialNumber string `json:"SerialNumber"`
557
+ // IssuedDN string `json:"IssuedDN"`
558
+ // IssuedCN string `json:"IssuedCN"`
559
+ // ImportDate time.Time `json:"ImportDate"`
560
+ // NotBefore time.Time `json:"NotBefore"`
561
+ // NotAfter time.Time `json:"NotAfter"`
562
+ // IssuerDN string `json:"IssuerDN"`
563
+ // PrincipalID interface{} `json:"PrincipalId"`
564
+ // TemplateID interface{} `json:"TemplateId"`
565
+ // CertState int `json:"CertState"`
566
+ // KeySizeInBits int `json:"KeySizeInBits"`
567
+ // KeyType int `json:"KeyType"`
568
+ // RequesterID int `json:"RequesterId"`
569
+ // IssuedOU interface{} `json:"IssuedOU"`
570
+ // IssuedEmail interface{} `json:"IssuedEmail"`
571
+ // KeyUsage int `json:"KeyUsage"`
572
+ // SigningAlgorithm string `json:"SigningAlgorithm"`
573
+ // CertStateString string `json:"CertStateString"`
574
+ // KeyTypeString string `json:"KeyTypeString"`
575
+ // RevocationEffDate interface{} `json:"RevocationEffDate"`
576
+ // RevocationReason interface{} `json:"RevocationReason"`
577
+ // RevocationComment interface{} `json:"RevocationComment"`
578
+ // CertificateAuthorityID int `json:"CertificateAuthorityId"`
579
+ // CertificateAuthorityName string `json:"CertificateAuthorityName"`
580
+ // TemplateName interface{} `json:"TemplateName"`
581
+ // ArchivedKey bool `json:"ArchivedKey"`
582
+ // HasPrivateKey bool `json:"HasPrivateKey"`
583
+ // PrincipalName interface{} `json:"PrincipalName"`
584
+ // CertRequestID interface{} `json:"CertRequestId"`
585
+ // RequesterName string `json:"RequesterName"`
586
+ // ContentBytes string `json:"ContentBytes"`
587
+ // ExtendedKeyUsages []interface{} `json:"ExtendedKeyUsages"`
588
+ // SubjectAltNameElements []interface{} `json:"SubjectAltNameElements"`
589
+ // CRLDistributionPoints []interface{} `json:"CRLDistributionPoints"`
590
+ // LocationsCount []interface{} `json:"LocationsCount"`
591
+ // SSLLocations []interface{} `json:"SSLLocations"`
592
+ // Locations []interface{} `json:"Locations"`
593
+ // Metadata Metadata `json:"Metadata"`
594
+ // CertificateKeyID int `json:"CertificateKeyId"`
595
+ // CARowIndex int `json:"CARowIndex"`
596
+ // DetailedKeyUsage DetailedKeyUsage `json:"DetailedKeyUsage"`
597
+ // KeyRecoverable bool `json:"KeyRecoverable"`
598
+ // }
599
+ // type Metadata struct {
600
+ // }
601
+ // type DetailedKeyUsage struct {
602
+ // CrlSign bool `json:"CrlSign"`
603
+ // DataEncipherment bool `json:"DataEncipherment"`
604
+ // DecipherOnly bool `json:"DecipherOnly"`
605
+ // DigitalSignature bool `json:"DigitalSignature"`
606
+ // EncipherOnly bool `json:"EncipherOnly"`
607
+ // KeyAgreement bool `json:"KeyAgreement"`
608
+ // KeyCertSign bool `json:"KeyCertSign"`
609
+ // KeyEncipherment bool `json:"KeyEncipherment"`
610
+ // NonRepudiation bool `json:"NonRepudiation"`
611
+ // HexCode string `json:"HexCode"`
612
+ // }
613
+
614
+ // type KeyfactorCertDownloadResponse struct {
615
+ // Content string `json:"Content"`
616
+ // }
0 commit comments