Skip to content

Commit 83d80c3

Browse files
committed
Add serial 0 validation to non-template code path
1 parent 06d7d7d commit 83d80c3

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

wolfcrypt/src/asn.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25614,7 +25614,21 @@ int ParseCertRelative(DecodedCert* cert, int type, int verify, void* cm,
2561425614
cert->srcIdx = cert->sigIndex;
2561525615
}
2561625616

25617-
if ((ret = GetSigAlg(cert,
25617+
#if !defined(WOLFSSL_NO_ASN_STRICT) && !defined(WOLFSSL_PYTHON) && \
25618+
!defined(WOLFSSL_ASN_ALLOW_0_SERIAL)
25619+
/* Check for serial number of 0. RFC 5280 section 4.1.2.2 requires
25620+
* positive serial numbers. However, allow zero for self-signed CA
25621+
* certificates (root CAs) since they are explicitly trusted and some
25622+
* legacy root CAs in real-world trust stores have serial number 0. */
25623+
if ((ret == 0) && (cert->serialSz == 1) && (cert->serial[0] == 0)) {
25624+
if (!(cert->isCA && cert->selfSigned)) {
25625+
WOLFSSL_MSG("Error serial number of 0 for non-root certificate");
25626+
ret = ASN_PARSE_E;
25627+
}
25628+
}
25629+
#endif
25630+
25631+
if ((ret != 0) || (ret = GetSigAlg(cert,
2561825632
#ifdef WOLFSSL_CERT_REQ
2561925633
!cert->isCSR ? &confirmOID : &cert->signatureOID,
2562025634
#else

0 commit comments

Comments
 (0)