Skip to content

Commit 690d8f7

Browse files
sanity check on non conforming serial number of 0
1 parent 29df901 commit 690d8f7

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

wolfcrypt/src/asn.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21875,6 +21875,19 @@ static int DecodeCertInternal(DecodedCert* cert, int verify, int* criticalExt,
2187521875
/* Set fields extracted from data. */
2187621876
cert->version = version;
2187721877
cert->serialSz = (int)serialSz;
21878+
21879+
#ifndef WOLFSSL_NO_ASN_STRICT
21880+
/* RFC 5280 section 4.1.2.2 states that non-conforming CAs may issue
21881+
* a negative or zero serial number and should be handled gracefully.
21882+
* Since it is a non-conforming CA that issues a serial of 0 then we
21883+
* treat it as an error here. */
21884+
if (cert->serialSz == 1 && cert->serial[0] == 0) {
21885+
WOLFSSL_MSG("Error serial number of 0, use WOLFSSL_NO_ASN_STRICT "
21886+
"if wanted");
21887+
ret = ASN_PARSE_E;
21888+
}
21889+
#endif
21890+
2187821891
cert->signatureOID = dataASN[X509CERTASN_IDX_TBS_ALGOID_OID].data.oid.sum;
2187921892
cert->keyOID = dataASN[X509CERTASN_IDX_TBS_SPUBKEYINFO_ALGO_OID].data.oid.sum;
2188021893
cert->certBegin = dataASN[X509CERTASN_IDX_TBS_SEQ].offset;

0 commit comments

Comments
 (0)