Skip to content

Commit

Permalink
fix: try decode PKCS8 private key first (#1790)
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian authored Mar 23, 2023
1 parent 86a9747 commit 02d4cf5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions x/cert/utils/key_pair_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,17 @@ func (kpm *keyPairManager) readImpl(fin io.Reader) ([]byte, []byte, []byte, erro

var privKeyPlaintext []byte

// PKCS#8 header defined in RFC7468 section 11
// nolint: gocritic
if block.Headers["Proc-Type"] == "4,ENCRYPTED" {
if block.Type == "ENCRYPTED PRIVATE KEY" {
privKeyPlaintext, err = pemutil.DecryptPKCS8PrivateKey(block.Bytes, kpm.passwordBytes)
} else if block.Headers["Proc-Type"] == "4,ENCRYPTED" {
// nolint: staticcheck
privKeyPlaintext, err = x509.DecryptPEMBlock(block, kpm.passwordBytes)
if errors.Is(err, x509.IncorrectPasswordError) {
// nolint: staticcheck
privKeyPlaintext, err = x509.DecryptPEMBlock(block, kpm.passwordLegacy)
}
// PKCS#8 header defined in RFC7468 section 11
} else if block.Type == "ENCRYPTED PRIVATE KEY" {
privKeyPlaintext, err = pemutil.DecryptPKCS8PrivateKey(block.Bytes, kpm.passwordBytes)
} else {
return nil, nil, nil, errUnsupportedEncryptedPEM
}
Expand Down

0 comments on commit 02d4cf5

Please sign in to comment.