Skip to content

Commit

Permalink
Merge pull request #24 from Keyfactor/download_ca_cert
Browse files Browse the repository at this point in the history
fix(certificates): `IncludeHasPrivateKey` now available for cert lookups that don't use ID
  • Loading branch information
spbsoluble authored Aug 7, 2023
2 parents 344d35d + 4c41668 commit e932e22
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
13 changes: 10 additions & 3 deletions v2/api/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,15 @@ func (c *Client) DownloadCertificate(certId int, thumbprint string, serialNumber
}

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

var leaf *x509.Certificate
if len(certs.Certificates) > 1 {
//leaf is last cert in chain
leaf = certs.Certificates[len(certs.Certificates)-1]
return leaf, certs.Certificates, nil
}

return leaf, nil, nil
return certs.Certificates[0], nil, nil
}

// EnrollCSR takes arguments for EnrollCSRFctArgs to enroll a passed Certificate Signing
Expand Down Expand Up @@ -335,7 +337,7 @@ func (c *Client) GetCertificateContext(gca *GetCertificateContextArgs) (*GetCert
query := apiQuery{
Query: []StringTuple{},
}
if gca.IncludeLocations != nil || gca.CollectionId != nil || gca.IncludeMetadata != nil {
if gca.IncludeLocations != nil || gca.CollectionId != nil || gca.IncludeMetadata != nil || gca.IncludeHasPrivateKey != nil {
if gca.IncludeLocations != nil {
query.Query = append(query.Query, StringTuple{
"includeLocations", strconv.FormatBool(*gca.IncludeLocations),
Expand All @@ -351,6 +353,11 @@ func (c *Client) GetCertificateContext(gca *GetCertificateContextArgs) (*GetCert
"collectionId", fmt.Sprintf("%d", *gca.CollectionId),
})
}
if gca.IncludeHasPrivateKey != nil {
query.Query = append(query.Query, StringTuple{
"includeHasPrivateKey", strconv.FormatBool(*gca.IncludeHasPrivateKey),
})
}
}

var endpoint string
Expand Down
13 changes: 7 additions & 6 deletions v2/api/certificate_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ type RevokeCertArgs struct {

// GetCertificateContextArgs holds the function arguments used for calling the GetCertificateContext method.
type GetCertificateContextArgs struct {
IncludeMetadata *bool // Query
IncludeLocations *bool // Query
CollectionId *int // Query
Thumbprint string // Query
CommonName string // Query
Id int // Query
IncludeMetadata *bool // Query
IncludeLocations *bool // Query
CollectionId *int // Query
Thumbprint string // Query
CommonName string // Query
Id int // Query
IncludeHasPrivateKey *bool
}

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

0 comments on commit e932e22

Please sign in to comment.