Skip to content

Commit 57af974

Browse files
committed
crypto/x509: deprecate legacy PEM encryption
It's unfortunate that we don't implement PKCS#8 encryption (#8860) so we can't recommend an alternative but PEM encryption is so broken that it's worth deprecating outright. Fixes #41949 Fixes #32777 Change-Id: Ieb46444662adec108d0de3550b693a50545c2344 Reviewed-on: https://go-review.googlesource.com/c/go/+/264159 Trust: Filippo Valsorda <filippo@golang.org> Trust: Roland Shoemaker <roland@golang.org> Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
1 parent a36493e commit 57af974

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

src/crypto/x509/pem_decrypt.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ func (c rfc1423Algo) deriveKey(password, salt []byte) []byte {
9595
return out
9696
}
9797

98-
// IsEncryptedPEMBlock returns if the PEM block is password encrypted.
98+
// IsEncryptedPEMBlock returns whether the PEM block is password encrypted
99+
// according to RFC 1423.
100+
//
101+
// Deprecated: Legacy PEM encryption as specified in RFC 1423 is insecure by
102+
// design. Since it does not authenticate the ciphertext, it is vulnerable to
103+
// padding oracle attacks that can let an attacker recover the plaintext.
99104
func IsEncryptedPEMBlock(b *pem.Block) bool {
100105
_, ok := b.Headers["DEK-Info"]
101106
return ok
@@ -104,14 +109,18 @@ func IsEncryptedPEMBlock(b *pem.Block) bool {
104109
// IncorrectPasswordError is returned when an incorrect password is detected.
105110
var IncorrectPasswordError = errors.New("x509: decryption password incorrect")
106111

107-
// DecryptPEMBlock takes a password encrypted PEM block and the password used to
108-
// encrypt it and returns a slice of decrypted DER encoded bytes. It inspects
109-
// the DEK-Info header to determine the algorithm used for decryption. If no
110-
// DEK-Info header is present, an error is returned. If an incorrect password
111-
// is detected an IncorrectPasswordError is returned. Because of deficiencies
112-
// in the encrypted-PEM format, it's not always possible to detect an incorrect
113-
// password. In these cases no error will be returned but the decrypted DER
114-
// bytes will be random noise.
112+
// DecryptPEMBlock takes a PEM block encrypted according to RFC 1423 and the
113+
// password used to encrypt it and returns a slice of decrypted DER encoded
114+
// bytes. It inspects the DEK-Info header to determine the algorithm used for
115+
// decryption. If no DEK-Info header is present, an error is returned. If an
116+
// incorrect password is detected an IncorrectPasswordError is returned. Because
117+
// of deficiencies in the format, it's not always possible to detect an
118+
// incorrect password. In these cases no error will be returned but the
119+
// decrypted DER bytes will be random noise.
120+
//
121+
// Deprecated: Legacy PEM encryption as specified in RFC 1423 is insecure by
122+
// design. Since it does not authenticate the ciphertext, it is vulnerable to
123+
// padding oracle attacks that can let an attacker recover the plaintext.
115124
func DecryptPEMBlock(b *pem.Block, password []byte) ([]byte, error) {
116125
dek, ok := b.Headers["DEK-Info"]
117126
if !ok {
@@ -178,8 +187,12 @@ func DecryptPEMBlock(b *pem.Block, password []byte) ([]byte, error) {
178187
}
179188

180189
// EncryptPEMBlock returns a PEM block of the specified type holding the
181-
// given DER-encoded data encrypted with the specified algorithm and
182-
// password.
190+
// given DER encoded data encrypted with the specified algorithm and
191+
// password according to RFC 1423.
192+
//
193+
// Deprecated: Legacy PEM encryption as specified in RFC 1423 is insecure by
194+
// design. Since it does not authenticate the ciphertext, it is vulnerable to
195+
// padding oracle attacks that can let an attacker recover the plaintext.
183196
func EncryptPEMBlock(rand io.Reader, blockType string, data, password []byte, alg PEMCipher) (*pem.Block, error) {
184197
ciph := cipherByKey(alg)
185198
if ciph == nil {

0 commit comments

Comments
 (0)