Skip to content

Commit e932e22

Browse files
authored
Merge pull request #24 from Keyfactor/download_ca_cert
fix(certificates): `IncludeHasPrivateKey` now available for cert lookups that don't use ID
2 parents 344d35d + 4c41668 commit e932e22

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

v2/api/certificate.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,15 @@ func (c *Client) DownloadCertificate(certId int, thumbprint string, serialNumber
168168
}
169169

170170
//todo: review this as it seems to be returning the wrong cert
171-
leaf := certs.Certificates[1]
172171

172+
var leaf *x509.Certificate
173173
if len(certs.Certificates) > 1 {
174+
//leaf is last cert in chain
175+
leaf = certs.Certificates[len(certs.Certificates)-1]
174176
return leaf, certs.Certificates, nil
175177
}
176178

177-
return leaf, nil, nil
179+
return certs.Certificates[0], nil, nil
178180
}
179181

180182
// EnrollCSR takes arguments for EnrollCSRFctArgs to enroll a passed Certificate Signing
@@ -335,7 +337,7 @@ func (c *Client) GetCertificateContext(gca *GetCertificateContextArgs) (*GetCert
335337
query := apiQuery{
336338
Query: []StringTuple{},
337339
}
338-
if gca.IncludeLocations != nil || gca.CollectionId != nil || gca.IncludeMetadata != nil {
340+
if gca.IncludeLocations != nil || gca.CollectionId != nil || gca.IncludeMetadata != nil || gca.IncludeHasPrivateKey != nil {
339341
if gca.IncludeLocations != nil {
340342
query.Query = append(query.Query, StringTuple{
341343
"includeLocations", strconv.FormatBool(*gca.IncludeLocations),
@@ -351,6 +353,11 @@ func (c *Client) GetCertificateContext(gca *GetCertificateContextArgs) (*GetCert
351353
"collectionId", fmt.Sprintf("%d", *gca.CollectionId),
352354
})
353355
}
356+
if gca.IncludeHasPrivateKey != nil {
357+
query.Query = append(query.Query, StringTuple{
358+
"includeHasPrivateKey", strconv.FormatBool(*gca.IncludeHasPrivateKey),
359+
})
360+
}
354361
}
355362

356363
var endpoint string

v2/api/certificate_models.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ type RevokeCertArgs struct {
5353

5454
// GetCertificateContextArgs holds the function arguments used for calling the GetCertificateContext method.
5555
type GetCertificateContextArgs struct {
56-
IncludeMetadata *bool // Query
57-
IncludeLocations *bool // Query
58-
CollectionId *int // Query
59-
Thumbprint string // Query
60-
CommonName string // Query
61-
Id int // Query
56+
IncludeMetadata *bool // Query
57+
IncludeLocations *bool // Query
58+
CollectionId *int // Query
59+
Thumbprint string // Query
60+
CommonName string // Query
61+
Id int // Query
62+
IncludeHasPrivateKey *bool
6263
}
6364

6465
// DeployPFXArgs holds the function arguments used for calling the DeployPFXCertificate method.

0 commit comments

Comments
 (0)