Skip to content

Commit 72c7d12

Browse files
exclude the trust anchor from prospective certification path with pathlen check
1 parent fe8541c commit 72c7d12

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

tests/api.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21763,6 +21763,15 @@ static int test_PathLenSelfIssued(void)
2176321763
cm), WC_NO_ERR_TRACE(ASN_PATHLEN_INV_E));
2176421764
wc_FreeDecodedCert(&decodedCert);
2176521765

21766+
/* Step 6: Parse the trust anchor itself as a chain cert.
21767+
* A peer is allowed to include the root in the chain it sends.
21768+
* Per RFC 5280 6.1 the trust anchor is not part of the prospective
21769+
* certification path, so its own pathLen=0 must not fire against
21770+
* itself. */
21771+
wc_InitDecodedCert(&decodedCert, rootDer, (word32)rootDerSz, NULL);
21772+
ExpectIntEQ(wc_ParseCert(&decodedCert, CHAIN_CERT_TYPE, VERIFY, cm), 0);
21773+
wc_FreeDecodedCert(&decodedCert);
21774+
2176621775
wolfSSL_CertManagerFree(cm);
2176721776
wc_ecc_free(&entityKey);
2176821777
wc_ecc_free(&icaKey);

wolfcrypt/src/asn.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22527,7 +22527,22 @@ int ParseCertRelative(DecodedCert* cert, int type, int verify, void* cm,
2252722527
* max_path_length, but the issuer's constraint still
2252822528
* applies. A self-issued cert from a CA with maxPathLen=0
2252922529
* cannot act as an intermediate CA. */
22530-
if (cert->ca->maxPathLen == 0) {
22530+
if (cert->publicKey != NULL &&
22531+
cert->ca->publicKey != NULL &&
22532+
cert->pubKeySize > 0 &&
22533+
cert->pubKeySize == cert->ca->pubKeySize &&
22534+
XMEMCMP(cert->publicKey, cert->ca->publicKey,
22535+
cert->pubKeySize) == 0) {
22536+
/* Exclude the trust anchor itself from step (l). Per
22537+
* RFC 5280 6.1, when the trust anchor is supplied as a
22538+
* self-signed certificate it "is not included as part
22539+
* of the prospective certification path" */
22540+
22541+
/* Trust anchor: honor issuer's constraint */
22542+
cert->maxPathLen = (word16)min(cert->ca->maxPathLen,
22543+
cert->maxPathLen);
22544+
}
22545+
else if (cert->ca->maxPathLen == 0) {
2253122546
cert->maxPathLen = 0;
2253222547
if (verify != NO_VERIFY) {
2253322548
WOLFSSL_MSG("\tSelf-issued cert, maxPathLen is 0");

0 commit comments

Comments
 (0)