Skip to content

Commit 077429b

Browse files
Merge remote-tracking branch 'remotes/from/ce/release/1.21.x' into release/1.21.x
2 parents f2d78b7 + 53dce8b commit 077429b

File tree

11 files changed

+908
-30
lines changed

11 files changed

+908
-30
lines changed

builtin/logical/pki/ca_util.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"golang.org/x/crypto/ed25519"
2222
)
2323

24-
func getGenerationParams(sc *storageContext, data *framework.FieldData) (exported bool, format string, role *issuing.RoleEntry, errorResp *logical.Response) {
24+
func getGenerationParams(sc *storageContext, data *framework.FieldData, isRoot bool) (exported bool, format string, role *issuing.RoleEntry, errorResp *logical.Response) {
2525
exportedStr := data.Get("exported").(string)
2626
switch exportedStr {
2727
case "exported":
@@ -76,7 +76,16 @@ func getGenerationParams(sc *storageContext, data *framework.FieldData) (exporte
7676
}
7777
*role.AllowWildcardCertificates = true
7878

79-
if role.KeyBits, role.SignatureBits, err = certutil.ValidateDefaultOrValueKeyTypeSignatureLength(role.KeyType, role.KeyBits, role.SignatureBits); err != nil {
79+
if role.KeyBits, err = certutil.ValidateDefaultOrValueKeyType(role.KeyType, role.KeyBits); err != nil {
80+
errorResp = logical.ErrorResponse(err.Error())
81+
}
82+
83+
signingKeyType := "any"
84+
if isRoot {
85+
signingKeyType = role.KeyType
86+
}
87+
88+
if role.SignatureBits, err = certutil.ValidateDefaultOrValueHashBits(signingKeyType, role.SignatureBits); err != nil {
8089
errorResp = logical.ErrorResponse(err.Error())
8190
}
8291

builtin/logical/pki/issuing/issue_common.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,13 @@ func GenerateCreationBundle(b logical.SystemView, role *RoleEntry, entityInfo En
442442
CSR: csr,
443443
}
444444

445+
// Make Sure Signature Bits are Correct for EC (or ECDSA) Keys
446+
// It's not possible to do later during the signing process because
447+
// signingKeyType := role.KeyType // if root
448+
// if caSign != nil {
449+
// signingKeyType = caSign.ParsedCertBundle.Certificate.PublicKeyAlgorithm.String()
450+
// }
451+
445452
// Don't deal with URLs or max path length if it's self-signed, as these
446453
// normally come from the signing bundle
447454
if caSign == nil {

builtin/logical/pki/issuing/sign_cert.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

builtin/logical/pki/path_intermediate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (b *backend) pathGenerateIntermediate(ctx context.Context, req *logical.Req
122122
data.Raw["use_pss"] = false
123123

124124
sc := b.makeStorageContext(ctx, req.Storage)
125-
exported, format, role, errorResp := getGenerationParams(sc, data)
125+
exported, format, role, errorResp := getGenerationParams(sc, data, false)
126126
if errorResp != nil {
127127
return errorResp, nil
128128
}

0 commit comments

Comments
 (0)