Skip to content

Commit 8baf393

Browse files
author
gojimmypi
committed
Introduce WOLFSSL_ASN_ALLOW_0_SERIAL
1 parent e99bbf9 commit 8baf393

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

wolfcrypt/src/asn.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ ASN Options:
5656
* WOLFSSL_CERT_GEN: Cert generation. Saves extra certificate info in GetName.
5757
* WOLFSSL_NO_ASN_STRICT: Disable strict RFC compliance checks to
5858
restore 3.13.0 behavior.
59+
* WOLFSSL_ASN_ALLOW_0_SERIAL: Even if WOLFSSL_NO_ASN_STRICT is not defined,
60+
allow a length=1, but zero value serial numnber.
5961
* WOLFSSL_NO_OCSP_OPTIONAL_CERTS: Skip optional OCSP certs (responder issuer
6062
must still be trusted)
6163
* WOLFSSL_NO_TRUSTED_CERTS_VERIFY: Workaround for situation where entire cert
@@ -13987,7 +13989,7 @@ static int GetCertName(DecodedCert* cert, char* full, byte* hash, int nameType,
1398713989
}
1398813990

1398913991
#ifndef WOLFSSL_NO_ASN_STRICT
13990-
/* RFC 5280 section 4.1.2.4 lists a DirecotryString as being
13992+
/* RFC 5280 section 4.1.2.4 lists a DirectoryString as being
1399113993
* 1..MAX in length */
1399213994
if (strLen < 1) {
1399313995
WOLFSSL_MSG("Non conforming DirectoryString of length 0 was"
@@ -14629,7 +14631,7 @@ static int GetCertName(DecodedCert* cert, char* full, byte* hash, int nameType,
1462914631
GetASN_GetRef(&dataASN[RDNASN_IDX_ATTR_VAL], &str, &strLen);
1463014632

1463114633
#ifndef WOLFSSL_NO_ASN_STRICT
14632-
/* RFC 5280 section 4.1.2.4 lists a DirecotryString as being
14634+
/* RFC 5280 section 4.1.2.4 lists a DirectoryString as being
1463314635
* 1..MAX in length */
1463414636
if (ret == 0 && strLen < 1) {
1463514637
WOLFSSL_MSG("Non conforming DirectoryString of length 0 was"
@@ -21895,8 +21897,8 @@ static int CheckDate(ASNGetData *dataASN, int dateType)
2189521897
* @param [in] verify Whether to verify dates before and after now.
2189621898
* @param [out] criticalExt Critical extension return code.
2189721899
* @param [out] badDateRet Bad date return code.
21898-
* @param [in] stopAtPubKey Stop parsing before subkectPublicKeyInfo.
21899-
* @param [in] stopAfterPubKey Stop parsing after subkectPublicKeyInfo.
21900+
* @param [in] stopAtPubKey Stop parsing before subjectPublicKeyInfo.
21901+
* @param [in] stopAfterPubKey Stop parsing after subjectPublicKeyInfo.
2190021902
* @return 0 on success.
2190121903
* @return ASN_CRIT_EXT_E when a critical extension was not recognized.
2190221904
* @return ASN_TIME_E when date BER tag is nor UTC or GENERALIZED time.
@@ -22005,7 +22007,8 @@ static int DecodeCertInternal(DecodedCert* cert, int verify, int* criticalExt,
2200522007
cert->version = version;
2200622008
cert->serialSz = (int)serialSz;
2200722009

22008-
#if !defined(WOLFSSL_NO_ASN_STRICT) && !defined(WOLFSSL_PYTHON)
22010+
#if !defined(WOLFSSL_NO_ASN_STRICT) && !defined(WOLFSSL_PYTHON) && \
22011+
!defined(WOLFSSL_ASN_ALLOW_0_SERIAL)
2200922012
/* RFC 5280 section 4.1.2.2 states that non-conforming CAs may issue
2201022013
* a negative or zero serial number and should be handled gracefully.
2201122014
* Since it is a non-conforming CA that issues a serial of 0 then we
@@ -22016,6 +22019,11 @@ static int DecodeCertInternal(DecodedCert* cert, int verify, int* criticalExt,
2201622019
ret = ASN_PARSE_E;
2201722020
}
2201822021
#endif
22022+
if (cert->serialSz == 0) {
22023+
WOLFSSL_MSG("Error serial size is zero. Should be at least one "
22024+
"even with no serial number.");
22025+
ret = ASN_PARSE_E;
22026+
}
2201922027

2202022028
cert->signatureOID = dataASN[X509CERTASN_IDX_TBS_ALGOID_OID].data.oid.sum;
2202122029
cert->keyOID = dataASN[X509CERTASN_IDX_TBS_SPUBKEYINFO_ALGO_OID].data.oid.sum;

0 commit comments

Comments
 (0)