Skip to content

Commit 38a1ffc

Browse files
committed
Add serial 0 validation to non-template code path
1 parent 18178a3 commit 38a1ffc

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
@@ -25758,7 +25758,21 @@ int ParseCertRelative(DecodedCert* cert, int type, int verify, void* cm,
2575825758
cert->srcIdx = cert->sigIndex;
2575925759
}
2576025760

25761-
if ((ret = GetSigAlg(cert,
25761+
#if !defined(WOLFSSL_NO_ASN_STRICT) && !defined(WOLFSSL_PYTHON) && \
25762+
!defined(WOLFSSL_ASN_ALLOW_0_SERIAL)
25763+
/* Check for serial number of 0. RFC 5280 section 4.1.2.2 requires
25764+
* positive serial numbers. However, allow zero for self-signed CA
25765+
* certificates (root CAs) since they are explicitly trusted and some
25766+
* legacy root CAs in real-world trust stores have serial number 0. */
25767+
if ((ret == 0) && (cert->serialSz == 1) && (cert->serial[0] == 0)) {
25768+
if (!(cert->isCA && cert->selfSigned)) {
25769+
WOLFSSL_MSG("Error serial number of 0 for non-root certificate");
25770+
ret = ASN_PARSE_E;
25771+
}
25772+
}
25773+
#endif
25774+
25775+
if ((ret != 0) || (ret = GetSigAlg(cert,
2576225776
#ifdef WOLFSSL_CERT_REQ
2576325777
!cert->isCSR ? &confirmOID : &cert->signatureOID,
2576425778
#else

0 commit comments

Comments
 (0)