Skip to content

Commit 8f00fc2

Browse files
authored
Merge pull request wolfSSL#8890 from kareem-wolfssl/zd20022
Allow larger pathLen values in Basic Constraints.
2 parents cd7256a + 9fa1d2e commit 8f00fc2

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

wolfcrypt/src/asn.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2768,7 +2768,7 @@ int GetASNInt(const byte* input, word32* inOutIdx, int* len,
27682768
}
27692769

27702770
#ifndef WOLFSSL_ASN_TEMPLATE
2771-
#ifndef NO_CERTS
2771+
#if !defined(NO_CERTS) && defined(WOLFSSL_CUSTOM_CURVES)
27722772
/* Get the DER/BER encoding of an ASN.1 INTEGER that has a value of no more than
27732773
* 7 bits.
27742774
*
@@ -2800,7 +2800,7 @@ static int GetInteger7Bit(const byte* input, word32* inOutIdx, word32 maxIdx)
28002800
}
28012801
#endif /* !NO_CERTS */
28022802

2803-
#if defined(WC_RSA_PSS) && !defined(NO_RSA)
2803+
#if ((defined(WC_RSA_PSS) && !defined(NO_RSA)) || !defined(NO_CERTS))
28042804
/* Get the DER/BER encoding of an ASN.1 INTEGER that has a value of no more than
28052805
* 16 bits.
28062806
*
@@ -20640,10 +20640,15 @@ static int DecodeBasicCaConstraint(const byte* input, int sz, DecodedCert* cert)
2064020640
return 0;
2064120641
}
2064220642

20643-
ret = GetInteger7Bit(input, &idx, (word32)sz);
20643+
ret = GetInteger16Bit(input, &idx, (word32)sz);
2064420644
if (ret < 0)
2064520645
return ret;
20646-
cert->pathLength = (byte)ret;
20646+
else if (ret > WOLFSSL_MAX_PATH_LEN) {
20647+
WOLFSSL_ERROR_VERBOSE(ASN_PATHLEN_SIZE_E);
20648+
return ASN_PATHLEN_SIZE_E;
20649+
}
20650+
20651+
cert->pathLength = (word16)ret;
2064720652
cert->pathLengthSet = 1;
2064820653

2064920654
return 0;
@@ -20660,7 +20665,7 @@ static int DecodeBasicCaConstraint(const byte* input, int sz, DecodedCert* cert)
2066020665
if (ret == 0) {
2066120666
/* Get the CA boolean and path length when present. */
2066220667
GetASN_Boolean(&dataASN[BASICCONSASN_IDX_CA], &isCA);
20663-
GetASN_Int8Bit(&dataASN[BASICCONSASN_IDX_PLEN], &cert->pathLength);
20668+
GetASN_Int16Bit(&dataASN[BASICCONSASN_IDX_PLEN], &cert->pathLength);
2066420669

2066520670
ret = GetASN_Items(basicConsASN, dataASN, basicConsASN_Length, 1, input,
2066620671
&idx, (word32)sz);
@@ -20677,11 +20682,6 @@ static int DecodeBasicCaConstraint(const byte* input, int sz, DecodedCert* cert)
2067720682
ret = ASN_PARSE_E;
2067820683
}
2067920684
#endif
20680-
/* Path length must be a 7-bit value. */
20681-
if ((ret == 0) && (cert->pathLength >= (1 << 7))) {
20682-
WOLFSSL_ERROR_VERBOSE(ASN_PARSE_E);
20683-
ret = ASN_PARSE_E;
20684-
}
2068520685
if ((ret == 0) && cert->pathLength > WOLFSSL_MAX_PATH_LEN) {
2068620686
WOLFSSL_ERROR_VERBOSE(ASN_PATHLEN_SIZE_E);
2068720687
ret = ASN_PATHLEN_SIZE_E;

wolfssl/wolfcrypt/asn.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,8 +1642,8 @@ struct DecodedCert {
16421642
const byte* extAuthKeyIdIssuerSN; /* Authority Key ID authorityCertSerialNumber */
16431643
word32 extAuthKeyIdIssuerSNSz; /* Authority Key ID authorityCertSerialNumber length */
16441644
#endif
1645-
byte pathLength; /* CA basic constraint path length */
1646-
byte maxPathLen; /* max_path_len see RFC 5280 section
1645+
word16 pathLength; /* CA basic constraint path length */
1646+
word16 maxPathLen; /* max_path_len see RFC 5280 section
16471647
* 6.1.2 "Initialization" - (k) for
16481648
* description of max_path_len */
16491649
byte policyConstSkip; /* Policy Constraints skip certs value */
@@ -1943,7 +1943,7 @@ struct Signer {
19431943
word32 pubKeySize;
19441944
word32 keyOID; /* key type */
19451945
word16 keyUsage;
1946-
byte maxPathLen;
1946+
word16 maxPathLen;
19471947
WC_BITFIELD selfSigned:1;
19481948
const byte* publicKey;
19491949
int nameLen;

0 commit comments

Comments
 (0)