Skip to content

Commit 2ff3ccd

Browse files
committed
Allow serial number 0 for root CA certificates
1 parent 492ff38 commit 2ff3ccd

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

wolfcrypt/src/asn.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23897,18 +23897,7 @@ static int DecodeCertInternal(DecodedCert* cert, int verify, int* criticalExt,
2389723897
cert->version = version;
2389823898
cert->serialSz = (int)serialSz;
2389923899

23900-
#if !defined(WOLFSSL_NO_ASN_STRICT) && !defined(WOLFSSL_PYTHON) && \
23901-
!defined(WOLFSSL_ASN_ALLOW_0_SERIAL)
23902-
/* RFC 5280 section 4.1.2.2 states that non-conforming CAs may issue
23903-
* a negative or zero serial number and should be handled gracefully.
23904-
* Since it is a non-conforming CA that issues a serial of 0 then we
23905-
* treat it as an error here. */
23906-
if (cert->serialSz == 1 && cert->serial[0] == 0) {
23907-
WOLFSSL_MSG("Error serial number of 0, use WOLFSSL_NO_ASN_STRICT "
23908-
"if wanted");
23909-
ret = ASN_PARSE_E;
23910-
}
23911-
#endif
23900+
/* Check for serial size of zero */
2391223901
if (cert->serialSz == 0) {
2391323902
WOLFSSL_MSG("Error serial size is zero. Should be at least one "
2391423903
"even with no serial number.");
@@ -24124,6 +24113,20 @@ static int DecodeCertInternal(DecodedCert* cert, int verify, int* criticalExt,
2412424113
}
2412524114
}
2412624115

24116+
#if !defined(WOLFSSL_NO_ASN_STRICT) && !defined(WOLFSSL_PYTHON) && \
24117+
!defined(WOLFSSL_ASN_ALLOW_0_SERIAL)
24118+
/* Check for serial number of 0. RFC 5280 section 4.1.2.2 requires
24119+
* positive serial numbers. However, allow zero for self-signed CA
24120+
* certificates (root CAs) since they are explicitly trusted and some
24121+
* legacy root CAs in real-world trust stores have serial number 0. */
24122+
if ((ret == 0) && (cert->serialSz == 1) && (cert->serial[0] == 0)) {
24123+
if (!(cert->isCA && cert->selfSigned)) {
24124+
WOLFSSL_MSG("Error serial number of 0 for non-root certificate");
24125+
ret = ASN_PARSE_E;
24126+
}
24127+
}
24128+
#endif
24129+
2412724130
if ((ret == 0) && (!done) && (badDate != 0)) {
2412824131
/* Parsed whole certificate fine but return any date errors. */
2412924132
ret = badDate;

0 commit comments

Comments
 (0)