diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 01ca42362..396fc821a 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -24344,8 +24344,17 @@ static int EncodeExtensions(Cert* cert, byte* output, word32 maxSz, /* Set Basic Constraints to be a Certificate Authority. */ SetASN_Boolean(&dataASN[CERTEXTSASN_IDX_BC_CA], 1); SetASN_Buffer(&dataASN[CERTEXTSASN_IDX_BC_OID], bcOID, sizeof(bcOID)); - /* TODO: consider adding path length field in Cert. */ - dataASN[CERTEXTSASN_IDX_BC_PATHLEN].noOut = 1; + if (cert->pathLen + #ifdef WOLFSSL_CERT_EXT + && ((cert->keyUsage & KEYUSE_KEY_CERT_SIGN) || (!cert->keyUsage)) + #endif + ) { + SetASN_Int8Bit(&dataASN[CERTEXTSASN_IDX_BC_PATHLEN], + cert->pathLen); + } + else { + dataASN[CERTEXTSASN_IDX_BC_PATHLEN].noOut = 1; + } } else if (cert->basicConstSet) { /* Set Basic Constraints to be a non Certificate Authority. */ @@ -24941,8 +24950,11 @@ static int EncodeCert(Cert* cert, DerCert* der, RsaKey* rsaKey, ecc_key* eccKey, * asserted and the key usage extension, if present, asserts the * keyCertSign bit */ /* Set CA and path length */ - if ((cert->isCA) && (cert->pathLen) && - ((cert->keyUsage & KEYUSE_KEY_CERT_SIGN) || (!cert->keyUsage))) { + if ((cert->isCA) && (cert->pathLen) +#ifdef WOLFSSL_CERT_EXT + && ((cert->keyUsage & KEYUSE_KEY_CERT_SIGN) || (!cert->keyUsage)) +#endif + ) { der->caSz = SetCaWithPathLen(der->ca, sizeof(der->ca), cert->pathLen); if (der->caSz <= 0) return CA_TRUE_E;