Skip to content

Commit 8ad7800

Browse files
committed
Fix serial-0 check to allow TRUSTED_PEER_TYPE load path and correct test assertions
1 parent a0430cf commit 8ad7800

2 files changed

Lines changed: 5 additions & 23 deletions

File tree

tests/api/test_asn.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ int test_SerialNumber0_RootCA(void)
793793
EXPECT_DECLS;
794794

795795
#if !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
796-
!defined(WOLFSSL_NO_PEM)
796+
!defined(WOLFSSL_NO_PEM) && defined(WOLFSSL_PEM_TO_DER)
797797
/* Test that root CA certificates with serial number 0 are accepted,
798798
* while non-root certificates with serial 0 are rejected (issue #8615) */
799799

@@ -845,8 +845,8 @@ int test_SerialNumber0_RootCA(void)
845845

846846
/* Test 5: Self-signed non-CA certificate with serial 0 should be rejected */
847847
ExpectNotNull(cm = wolfSSL_CertManagerNew());
848-
ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, selfSignedNonCASerial0File, NULL),
849-
WC_NO_ERR_TRACE(ASN_PARSE_E));
848+
ExpectIntNE(wolfSSL_CertManagerLoadCA(cm, selfSignedNonCASerial0File, NULL),
849+
WOLFSSL_SUCCESS);
850850

851851
if (cm != NULL) {
852852
wolfSSL_CertManagerFree(cm);

wolfcrypt/src/asn.c

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24113,25 +24113,6 @@ static int DecodeCertInternal(DecodedCert* cert, int verify, int* criticalExt,
2411324113
}
2411424114
}
2411524115

24116-
#if !defined(WOLFSSL_NO_ASN_STRICT) && !defined(WOLFSSL_PYTHON) && \
24117-
!defined(WOLFSSL_ASN_ALLOW_0_SERIAL)
24118-
/* Defense-in-depth: reject serial number 0 for non-root certificates.
24119-
* RFC 5280 section 4.1.2.2 requires positive serial numbers.
24120-
* Allow serial 0 for self-signed CA certs (root CAs) since some legacy
24121-
* root CAs have serial 0. The primary enforcement with stricter type
24122-
* checking is in ParseCertRelative(). */
24123-
if ((ret == 0) && (cert->serialSz == 1) && (cert->serial[0] == 0)) {
24124-
if (!(cert->isCA && cert->selfSigned)
24125-
#ifdef WOLFSSL_CERT_REQ
24126-
&& !cert->isCSR
24127-
#endif
24128-
) {
24129-
WOLFSSL_MSG("Error serial number of 0 for non-root certificate");
24130-
ret = ASN_PARSE_E;
24131-
}
24132-
}
24133-
#endif
24134-
2413524116
if ((ret == 0) && (!done) && (badDate != 0)) {
2413624117
/* Parsed whole certificate fine but return any date errors. */
2413724118
ret = badDate;
@@ -25823,7 +25804,8 @@ int ParseCertRelative(DecodedCert* cert, int type, int verify, void* cm,
2582325804
* are explicitly trusted and some legacy root CAs in real-world
2582425805
* trust stores have serial number 0. */
2582525806
if ((ret == 0) && (cert->serialSz == 1) && (cert->serial[0] == 0)) {
25826-
if (!(type == CA_TYPE && cert->isCA && cert->selfSigned)
25807+
if (!((type == CA_TYPE || type == TRUSTED_PEER_TYPE) &&
25808+
cert->isCA && cert->selfSigned)
2582725809
#ifdef WOLFSSL_CERT_REQ
2582825810
&& !cert->isCSR
2582925811
#endif

0 commit comments

Comments
 (0)