Skip to content

Commit 4b198c8

Browse files
committed
Add serial 0 validation to original parser, fix CSR handling
1 parent 83d80c3 commit 4b198c8

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

wolfcrypt/src/asn.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23976,7 +23976,11 @@ static int DecodeCertInternal(DecodedCert* cert, int verify, int* criticalExt,
2397623976
* certificates (root CAs) since they are explicitly trusted and some
2397723977
* legacy root CAs in real-world trust stores have serial number 0. */
2397823978
if ((ret == 0) && (cert->serialSz == 1) && (cert->serial[0] == 0)) {
23979-
if (!(cert->isCA && cert->selfSigned)) {
23979+
if (!(cert->isCA && cert->selfSigned)
23980+
#ifdef WOLFSSL_CERT_REQ
23981+
&& !cert->isCSR
23982+
#endif
23983+
) {
2398023984
WOLFSSL_MSG("Error serial number of 0 for non-root certificate");
2398123985
ret = ASN_PARSE_E;
2398223986
}
@@ -25621,14 +25625,21 @@ int ParseCertRelative(DecodedCert* cert, int type, int verify, void* cm,
2562125625
* certificates (root CAs) since they are explicitly trusted and some
2562225626
* legacy root CAs in real-world trust stores have serial number 0. */
2562325627
if ((ret == 0) && (cert->serialSz == 1) && (cert->serial[0] == 0)) {
25624-
if (!(cert->isCA && cert->selfSigned)) {
25628+
if (!(cert->isCA && cert->selfSigned)
25629+
#ifdef WOLFSSL_CERT_REQ
25630+
&& !cert->isCSR
25631+
#endif
25632+
) {
2562525633
WOLFSSL_MSG("Error serial number of 0 for non-root certificate");
2562625634
ret = ASN_PARSE_E;
2562725635
}
2562825636
}
25637+
if (ret < 0) {
25638+
return ret;
25639+
}
2562925640
#endif
2563025641

25631-
if ((ret != 0) || (ret = GetSigAlg(cert,
25642+
if ((ret = GetSigAlg(cert,
2563225643
#ifdef WOLFSSL_CERT_REQ
2563325644
!cert->isCSR ? &confirmOID : &cert->signatureOID,
2563425645
#else

0 commit comments

Comments
 (0)