Skip to content

Commit 6ab286f

Browse files
baentscht8m
authored andcommitted
Add version field check to PKCS8 decoder
Fixes openssl#26459 Reviewed-by: Tom Cosgrove <[email protected]> Reviewed-by: Viktor Dukhovni <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#26464)
1 parent 40c01d8 commit 6ab286f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

crypto/asn1/d2i_pr.c

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <openssl/asn1.h>
2222
#include "crypto/asn1.h"
2323
#include "crypto/evp.h"
24+
#include "crypto/x509.h"
2425
#include "internal/asn1.h"
2526
#include "internal/sizes.h"
2627

@@ -51,6 +52,16 @@ d2i_PrivateKey_decoder(int keytype, EVP_PKEY **a, const unsigned char **pp,
5152
p8info = d2i_PKCS8_PRIV_KEY_INFO(NULL, pp, len);
5253
ERR_pop_to_mark();
5354
if (p8info != NULL) {
55+
int64_t v;
56+
57+
/* ascertain version is 0 or 1 as per RFC5958 */
58+
if (!ASN1_INTEGER_get_int64(&v, p8info->version)
59+
|| (v != 0 && v != 1)) {
60+
*pp = p;
61+
ERR_raise(ERR_LIB_ASN1, ASN1_R_ASN1_PARSE_ERROR);
62+
PKCS8_PRIV_KEY_INFO_free(p8info);
63+
return NULL;
64+
}
5465
if (key_name == NULL
5566
&& PKCS8_pkey_get0(&algoid, NULL, NULL, NULL, p8info)
5667
&& OBJ_obj2txt(keytypebuf, sizeof(keytypebuf), algoid, 0))

0 commit comments

Comments
 (0)