Skip to content

Commit

Permalink
- pkg/certificate: add Format to Request struct to support specifyi…
Browse files Browse the repository at this point in the history
…ng the Request Format

- pkg/venafi/tpp/connector: set a default to the request.Format in `RetrieveCertificate()`, unless a Format is explicitly passed
  • Loading branch information
eyalle committed Feb 13, 2023
1 parent 8d6c4fc commit 19e7412
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 6 additions & 3 deletions pkg/certificate/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ import (
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"github.com/Venafi/vcert/v4/pkg/util"
"github.com/youmark/pkcs8"
"net"
"net/url"
"strings"
"time"

"github.com/Venafi/vcert/v4/pkg/verror"
"github.com/Venafi/vcert/v4/pkg/util"
"github.com/youmark/pkcs8"

"reflect"
"sort"

"github.com/Venafi/vcert/v4/pkg/verror"
)

// EllipticCurve represents the types of supported elliptic curves
Expand Down Expand Up @@ -211,6 +213,7 @@ type Request struct {
Location *Location
ValidityHours int
IssuerHint string
Format string
}

//SSH Certificate structures
Expand Down
13 changes: 9 additions & 4 deletions pkg/venafi/tpp/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,14 @@ func (c *Connector) RetrieveCertificate(req *certificate.Request) (certificates
includeChain := req.ChainOption != certificate.ChainOptionIgnore
rootFirstOrder := includeChain && req.ChainOption == certificate.ChainOptionRootFirst

// if Request doesn't contain a Fornat, use defaults
if req.Format == "" {
if req.KeyType == certificate.KeyTypeRSA {
req.Format = "Base64 (PKCS #8)"
}
req.Format = "base64"
}

if req.PickupID == "" && req.Thumbprint != "" {
// search cert by Thumbprint and fill pickupID
searchResult, err := c.searchCertificatesByFingerprint(req.Thumbprint)
Expand All @@ -1219,15 +1227,12 @@ func (c *Connector) RetrieveCertificate(req *certificate.Request) (certificates

certReq := certificateRetrieveRequest{
CertificateDN: req.PickupID,
Format: "base64",
RootFirstOrder: rootFirstOrder,
IncludeChain: includeChain,
Format: req.Format,
}
if req.CsrOrigin == certificate.ServiceGeneratedCSR || req.FetchPrivateKey {
certReq.IncludePrivateKey = true
if req.KeyType == certificate.KeyTypeRSA {
certReq.Format = "Base64 (PKCS #8)"
}
certReq.Password = req.KeyPassword
}

Expand Down

0 comments on commit 19e7412

Please sign in to comment.