Skip to content

Commit f518a8f

Browse files
committed
new build flag WOLFSSL_ALLOW_ENCODING_CA_FALSE
1 parent 4bbb0e3 commit f518a8f

4 files changed

Lines changed: 13 additions & 17 deletions

File tree

tests/api.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49918,9 +49918,8 @@ static int test_MakeCertWithPathLen(void)
4991849918
static int test_MakeCertWithCaFalse(void)
4991949919
{
4992049920
EXPECT_DECLS;
49921-
#if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \
49922-
defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME) && \
49923-
defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC)
49921+
#if defined(WOLFSSL_ALLOW_ENCODING_CA_FALSE) && defined(WOLFSSL_CERT_REQ) && \
49922+
!defined(NO_ASN_TIME) && defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC)
4992449923
const byte expectedIsCaSet = 1;
4992549924
const byte expectedIsCa = 0;
4992649925
Cert cert;

wolfcrypt/src/asn.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ ASN Options:
9696
cost of taking up more memory. Adds initials, givenname, dnQualifer for
9797
example.
9898
* WC_ASN_HASH_SHA256: Force use of SHA2-256 for the internal hash ID calcs.
99+
* WOLFSSL_ALLOW_ENCODING_CA_FALSE: Allow encoding BasicConstraints CA:FALSE
100+
* which is discouraged by X.690 (DER) specification - default values shall not
101+
* be encoded.
99102
*/
100103

101104
#include <wolfssl/wolfcrypt/error-crypt.h>
@@ -18548,7 +18551,7 @@ static int DecodeBasicCaConstraint(const byte* input, int sz, DecodedCert* cert)
1854818551
WOLFSSL_MSG("\tfail: constraint not valid BOOLEAN, set default FALSE");
1854918552
ret = 0;
1855018553
}
18551-
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
18554+
#ifdef WOLFSSL_ALLOW_ENCODING_CA_FALSE
1855218555
else {
1855318556
/* CA Boolean asserted, GetBoolean didn't return error. */
1855418557
cert->isCaSet = 1;
@@ -18590,18 +18593,15 @@ static int DecodeBasicCaConstraint(const byte* input, int sz, DecodedCert* cert)
1859018593

1859118594
/* Empty SEQUENCE is OK - nothing to store. */
1859218595
if ((ret == 0) && (dataASN[BASICCONSASN_IDX_SEQ].length != 0)) {
18593-
#if !defined(OPENSSL_EXTRA) && !defined(OPENSSL_EXTRA_X509_SMALL)
1859418596
/* Bad encoding when CA Boolean is false
1859518597
* (default when not present). */
18598+
#if !defined(ASN_TEMPLATE_SKIP_ISCA_CHECK) && \
18599+
!defined(WOLFSSL_ALLOW_ENCODING_CA_FALSE)
1859618600
if ((dataASN[BASICCONSASN_IDX_CA].length != 0) && (!isCA)) {
1859718601
WOLFSSL_ERROR_VERBOSE(ASN_PARSE_E);
1859818602
ret = ASN_PARSE_E;
1859918603
}
18600-
#else
18601-
if (dataASN[BASICCONSASN_IDX_CA].length != 0) {
18602-
cert->isCaSet = 1;
18603-
}
18604-
#endif
18604+
#endif
1860518605
/* Path length must be a 7-bit value. */
1860618606
if ((ret == 0) && (cert->pathLength >= (1 << 7))) {
1860718607
WOLFSSL_ERROR_VERBOSE(ASN_PARSE_E);
@@ -27811,7 +27811,7 @@ static int EncodeExtensions(Cert* cert, byte* output, word32 maxSz,
2781127811
dataASN[CERTEXTSASN_IDX_BC_PATHLEN].noOut = 1;
2781227812
}
2781327813
}
27814-
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
27814+
#ifdef WOLFSSL_ALLOW_ENCODING_CA_FALSE
2781527815
else if (cert->isCaSet) {
2781627816
SetASN_Boolean(&dataASN[CERTEXTSASN_IDX_BC_CA], 0);
2781727817
SetASN_Buffer(&dataASN[CERTEXTSASN_IDX_BC_OID], bcOID, sizeof(bcOID));
@@ -28466,7 +28466,7 @@ static int EncodeCert(Cert* cert, DerCert* der, RsaKey* rsaKey, ecc_key* eccKey,
2846628466

2846728467
der->extensionsSz += der->caSz;
2846828468
}
28469-
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
28469+
#ifdef WOLFSSL_ALLOW_ENCODING_CA_FALSE
2847028470
/* Set CA */
2847128471
else if (cert->isCaSet) {
2847228472
der->caSz = SetCaEx(der->ca, sizeof(der->ca), cert->isCA);
@@ -29874,7 +29874,7 @@ static int EncodeCertReq(Cert* cert, DerCert* der, RsaKey* rsaKey,
2987429874

2987529875
der->extensionsSz += der->caSz;
2987629876
}
29877-
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
29877+
#ifdef WOLFSSL_ALLOW_ENCODING_CA_FALSE
2987829878
/* Set CA */
2987929879
else if (cert->isCaSet) {
2988029880
der->caSz = SetCaEx(der->ca, sizeof(der->ca), cert->isCA);

wolfssl/wolfcrypt/asn.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,9 +1882,6 @@ struct DecodedCert {
18821882
byte extNameConstraintSet : 1;
18831883
#endif
18841884
byte isCA : 1; /* CA basic constraint true */
1885-
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
1886-
byte isCaSet : 1; /* CA basic constraint set */
1887-
#endif
18881885
byte pathLengthSet : 1; /* CA basic const path length set */
18891886
byte weOwnAltNames : 1; /* altNames haven't been given to copy */
18901887
byte extKeyUsageSet : 1;

wolfssl/wolfcrypt/asn_public.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ typedef struct Cert {
530530
byte* der; /* Pointer to buffer of current DecodedCert cache */
531531
void* heap; /* heap hint */
532532
byte basicConstSet:1; /* Indicator for when Basic Constraint is set */
533-
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
533+
#ifdef WOLFSSL_ALLOW_ENCODING_CA_FALSE
534534
byte isCaSet:1; /* Indicator for when isCA is set */
535535
#endif
536536
byte pathLenSet:1; /* Indicator for when path length is set */

0 commit comments

Comments
 (0)