@@ -10,6 +10,7 @@ import (
1010 "crypto/x509"
1111 "fmt"
1212 "net"
13+ "strings"
1314
1415 "github.com/hashicorp/vault/sdk/helper/certutil"
1516 "github.com/hashicorp/vault/sdk/helper/errutil"
@@ -253,12 +254,12 @@ func SignCert(b logical.SystemView, role *RoleEntry, entityInfo EntityInfo, caSi
253254 return nil , nil , errutil.InternalError {Err : fmt .Sprintf ("unsupported key type Value: %s" , role .KeyType )}
254255 }
255256
256- // Before validating key lengths, update our KeyBits/SignatureBits based
257+ // Before validating key lengths, update our KeyBits based
257258 // on the actual CSR key type.
258259 if role .KeyType == "any" {
259- // We update the Value of KeyBits and SignatureBits here (from the
260+ // We update the Value of KeyBits here (from the
260261 // role), using the specified key type. This allows us to convert
261- // the default Value (0) for SignatureBits and KeyBits to a
262+ // the default Value (0) for KeyBits to a
262263 // meaningful Value.
263264 //
264265 // We ignore the role's original KeyBits Value if the KeyType is any
@@ -268,8 +269,8 @@ func SignCert(b logical.SystemView, role *RoleEntry, entityInfo EntityInfo, caSi
268269 // docs saying when key_type=any, we only enforce our specified minimums
269270 // for signing operations
270271 var err error
271- if role .KeyBits , role . SignatureBits , err = certutil .ValidateDefaultOrValueKeyTypeSignatureLength (
272- actualKeyType , 0 , role . SignatureBits ); err != nil {
272+ if role .KeyBits , err = certutil .ValidateDefaultOrValueKeyType (
273+ actualKeyType , 0 ); err != nil {
273274 return nil , nil , errutil.InternalError {Err : fmt .Sprintf ("unknown internal error updating default values: %v" , err )}
274275 }
275276
@@ -282,6 +283,14 @@ func SignCert(b logical.SystemView, role *RoleEntry, entityInfo EntityInfo, caSi
282283 }
283284 }
284285
286+ // We fetch the key type from the certificate because the caSign.KeyType might be ManagedKeyType which isn't an
287+ // algorithm, this is awkward because of upper-lower case differences
288+ underlayingCaKeyType := strings .ToLower (caSign .Certificate .PublicKeyAlgorithm .String ())
289+ role .SignatureBits , err = certutil .ValidateDefaultOrValueHashBits (underlayingCaKeyType , role .SignatureBits )
290+ if err != nil {
291+ return nil , nil , errutil.InternalError {Err : fmt .Sprintf ("unknown internal error updating default signature length value: %v" , err )}
292+ }
293+
285294 // At this point, role.KeyBits and role.SignatureBits should both
286295 // be non-zero, for RSA and ECDSA keys. Validate the actualKeyBits based on
287296 // the role's values. If the KeyType was any, and KeyBits was set to 0,
0 commit comments