@@ -95,7 +95,12 @@ func (c rfc1423Algo) deriveKey(password, salt []byte) []byte {
95
95
return out
96
96
}
97
97
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.
99
104
func IsEncryptedPEMBlock (b * pem.Block ) bool {
100
105
_ , ok := b .Headers ["DEK-Info" ]
101
106
return ok
@@ -104,14 +109,18 @@ func IsEncryptedPEMBlock(b *pem.Block) bool {
104
109
// IncorrectPasswordError is returned when an incorrect password is detected.
105
110
var IncorrectPasswordError = errors .New ("x509: decryption password incorrect" )
106
111
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.
115
124
func DecryptPEMBlock (b * pem.Block , password []byte ) ([]byte , error ) {
116
125
dek , ok := b .Headers ["DEK-Info" ]
117
126
if ! ok {
@@ -178,8 +187,12 @@ func DecryptPEMBlock(b *pem.Block, password []byte) ([]byte, error) {
178
187
}
179
188
180
189
// 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.
183
196
func EncryptPEMBlock (rand io.Reader , blockType string , data , password []byte , alg PEMCipher ) (* pem.Block , error ) {
184
197
ciph := cipherByKey (alg )
185
198
if ciph == nil {
0 commit comments