Skip to content

Commit 7bafa04

Browse files
committed
Add serial 0 validation to original parser, fix CSR handling
1 parent 38a1ffc commit 7bafa04

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

wolfcrypt/src/asn.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24120,7 +24120,11 @@ static int DecodeCertInternal(DecodedCert* cert, int verify, int* criticalExt,
2412024120
* certificates (root CAs) since they are explicitly trusted and some
2412124121
* legacy root CAs in real-world trust stores have serial number 0. */
2412224122
if ((ret == 0) && (cert->serialSz == 1) && (cert->serial[0] == 0)) {
24123-
if (!(cert->isCA && cert->selfSigned)) {
24123+
if (!(cert->isCA && cert->selfSigned)
24124+
#ifdef WOLFSSL_CERT_REQ
24125+
&& !cert->isCSR
24126+
#endif
24127+
) {
2412424128
WOLFSSL_MSG("Error serial number of 0 for non-root certificate");
2412524129
ret = ASN_PARSE_E;
2412624130
}
@@ -25765,14 +25769,21 @@ int ParseCertRelative(DecodedCert* cert, int type, int verify, void* cm,
2576525769
* certificates (root CAs) since they are explicitly trusted and some
2576625770
* legacy root CAs in real-world trust stores have serial number 0. */
2576725771
if ((ret == 0) && (cert->serialSz == 1) && (cert->serial[0] == 0)) {
25768-
if (!(cert->isCA && cert->selfSigned)) {
25772+
if (!(cert->isCA && cert->selfSigned)
25773+
#ifdef WOLFSSL_CERT_REQ
25774+
&& !cert->isCSR
25775+
#endif
25776+
) {
2576925777
WOLFSSL_MSG("Error serial number of 0 for non-root certificate");
2577025778
ret = ASN_PARSE_E;
2577125779
}
2577225780
}
25781+
if (ret < 0) {
25782+
return ret;
25783+
}
2577325784
#endif
2577425785

25775-
if ((ret != 0) || (ret = GetSigAlg(cert,
25786+
if ((ret = GetSigAlg(cert,
2577625787
#ifdef WOLFSSL_CERT_REQ
2577725788
!cert->isCSR ? &confirmOID : &cert->signatureOID,
2577825789
#else

0 commit comments

Comments
 (0)