Skip to content

Commit

Permalink
PKI: Fix managed key signatures when using specified signature_bits (#…
Browse files Browse the repository at this point in the history
…17328)

* PKI: Fix managed key signatures when using specified signature_bits

 - When calling sign-intermediate and other apis with signature_bits
   value overridden with a backing managed key we did not use that
   value as tests for the private key type were not working.

* Add cl
  • Loading branch information
stevendpclark authored Sep 28, 2022
1 parent 9d49bfa commit f28e921
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
3 changes: 3 additions & 0 deletions changelog/17328.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
secrets/pki: Do not ignore provided signature bits value when signing intermediate and leaf certificates with a managed key
```
7 changes: 6 additions & 1 deletion sdk/helper/certutil/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,12 @@ func signCertificate(data *CreationBundle, randReader io.Reader) (*ParsedCertBun
certTemplate.NotBefore = time.Now().Add(-1 * data.Params.NotBeforeDuration)
}

switch data.SigningBundle.PrivateKeyType {
privateKeyType := data.SigningBundle.PrivateKeyType
if privateKeyType == ManagedPrivateKey {
privateKeyType = GetPrivateKeyTypeFromSigner(data.SigningBundle.PrivateKey)
}

switch privateKeyType {
case RSAPrivateKey:
certTemplateSetSigAlgo(certTemplate, data)
case ECPrivateKey:
Expand Down
12 changes: 6 additions & 6 deletions sdk/helper/certutil/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,16 @@ type KeyBundle struct {
}

func GetPrivateKeyTypeFromSigner(signer crypto.Signer) PrivateKeyType {
switch signer.(type) {
case *rsa.PrivateKey:
// We look at the public key types to work-around limitations/typing of managed keys.
switch signer.Public().(type) {
case *rsa.PublicKey:
return RSAPrivateKey
case *ecdsa.PrivateKey:
case *ecdsa.PublicKey:
return ECPrivateKey
case ed25519.PrivateKey:
case ed25519.PublicKey:
return Ed25519PrivateKey
default:
return UnknownPrivateKey
}
return UnknownPrivateKey
}

// ToPEMBundle converts a string-based certificate bundle
Expand Down

0 comments on commit f28e921

Please sign in to comment.