Skip to content

Commit 653e5b0

Browse files
Merge pull request #6646 from embhorn/gh5636_5637
Fix RFC references and add WOLFSSL_ALLOW_CRIT_AIA
2 parents f0bfcc5 + a19a053 commit 653e5b0

1 file changed

Lines changed: 55 additions & 43 deletions

File tree

wolfcrypt/src/asn.c

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19054,9 +19054,9 @@ enum {
1905419054
#define authKeyIdASN_Length (sizeof(authKeyIdASN) / sizeof(ASNItem))
1905519055
#endif
1905619056

19057-
/* Decode authority information access extension in a certificate.
19057+
/* Decode authority key identifier extension in a certificate.
1905819058
*
19059-
* X.509: RFC 5280, 4.2.2.1 - Authority Information Access.
19059+
* X.509: RFC 5280, 4.2.1.1 - Authority Key Identifier.
1906019060
*
1906119061
* @param [in] input Buffer holding data.
1906219062
* @param [in] sz Size of data in buffer.
@@ -19178,7 +19178,7 @@ static int DecodeAuthKeyId(const byte* input, word32 sz, DecodedCert* cert)
1917819178

1917919179
/* Decode subject key id extension in a certificate.
1918019180
*
19181-
* X.509: RFC 5280, 4.2.2.1 - Authority Information Access.
19181+
* X.509: RFC 5280, 4.2.1.2 - Subject Key Identifier.
1918219182
*
1918319183
* @param [in] input Buffer holding data.
1918419184
* @param [in] sz Size of data in buffer.
@@ -19228,7 +19228,7 @@ enum {
1922819228

1922919229
/* Decode key usage extension in a certificate.
1923019230
*
19231-
* X.509: RFC 5280, 4.2.2.1 - Authority Information Access.
19231+
* X.509: RFC 5280, 4.2.1.3 - Key Usage.
1923219232
*
1923319233
* @param [in] input Buffer holding data.
1923419234
* @param [in] sz Size of data in buffer.
@@ -19970,7 +19970,7 @@ int DecodePolicyOID(char *out, word32 outSz, const byte *in, word32 inSz)
1997019970
return ASN_PARSE_E;
1997119971
}
1997219972
#ifndef WOLFSSL_DUP_CERTPOL
19973-
/* From RFC 5280 section 4.2.1.3 "A certificate policy OID MUST
19973+
/* From RFC 5280 section 4.2.1.4 "A certificate policy OID MUST
1997419974
* NOT appear more than once in a certificate policies
1997519975
* extension". This is a sanity check for duplicates.
1997619976
* extCertPolicies should only have OID values, additional
@@ -20079,7 +20079,7 @@ int DecodePolicyOID(char *out, word32 outSz, const byte *in, word32 inSz)
2007920079
}
2008020080
}
2008120081
#ifndef WOLFSSL_DUP_CERTPOL
20082-
/* From RFC 5280 section 4.2.1.3 "A certificate policy OID MUST
20082+
/* From RFC 5280 section 4.2.1.4 "A certificate policy OID MUST
2008320083
* NOT appear more than once in a certificate policies
2008420084
* extension". This is a sanity check for duplicates.
2008520085
* extCertPolicies should only have OID values, additional
@@ -20417,7 +20417,19 @@ static int DecodeExtensionType(const byte* input, word32 length, word32 oid,
2041720417
case AUTH_INFO_OID:
2041820418
VERIFY_AND_SET_OID(cert->extAuthInfoSet);
2041920419
cert->extAuthInfoCrit = critical ? 1 : 0;
20420-
if (DecodeAuthInfo(input, length, cert) < 0) {
20420+
#ifndef WOLFSSL_ALLOW_CRIT_AIA
20421+
/* This check is added due to RFC 5280 section 4.2.2.1
20422+
* stating that conforming CA's must mark this extension
20423+
* as non-critical. When parsing extensions check that
20424+
* certificate was made in compliance with this. */
20425+
if (critical) {
20426+
WOLFSSL_MSG("Critical Authority Information Access is not"
20427+
"allowed");
20428+
WOLFSSL_MSG("Use macro WOLFSSL_ALLOW_CRIT_AIA if wanted");
20429+
ret = ASN_CRIT_EXT_E;
20430+
}
20431+
#endif
20432+
if ((ret == 0) && (DecodeAuthInfo(input, length, cert) < 0)) {
2042120433
ret = ASN_PARSE_E;
2042220434
}
2042320435
break;
@@ -20433,17 +20445,17 @@ static int DecodeExtensionType(const byte* input, word32 length, word32 oid,
2043320445
case AUTH_KEY_OID:
2043420446
VERIFY_AND_SET_OID(cert->extAuthKeyIdSet);
2043520447
cert->extAuthKeyIdCrit = critical ? 1 : 0;
20436-
#ifndef WOLFSSL_ALLOW_CRIT_SKID
20437-
/* This check is added due to RFC 5280 section 4.2.1.1
20438-
* stating that conforming CA's must mark this extension
20439-
* as non-critical. When parsing extensions check that
20440-
* certificate was made in compliance with this. */
20441-
if (critical) {
20442-
WOLFSSL_MSG("Critical Auth Key ID is not allowed");
20443-
WOLFSSL_MSG("Use macro WOLFSSL_ALLOW_CRIT_SKID if wanted");
20444-
ret = ASN_CRIT_EXT_E;
20445-
}
20446-
#endif
20448+
#ifndef WOLFSSL_ALLOW_CRIT_AKID
20449+
/* This check is added due to RFC 5280 section 4.2.1.1
20450+
* stating that conforming CA's must mark this extension
20451+
* as non-critical. When parsing extensions check that
20452+
* certificate was made in compliance with this. */
20453+
if (critical) {
20454+
WOLFSSL_MSG("Critical Auth Key ID is not allowed");
20455+
WOLFSSL_MSG("Use macro WOLFSSL_ALLOW_CRIT_AKID if wanted");
20456+
ret = ASN_CRIT_EXT_E;
20457+
}
20458+
#endif
2044720459
if ((ret == 0) && (DecodeAuthKeyId(input, length, cert) < 0)) {
2044820460
ret = ASN_PARSE_E;
2044920461
}
@@ -20453,17 +20465,17 @@ static int DecodeExtensionType(const byte* input, word32 length, word32 oid,
2045320465
case SUBJ_KEY_OID:
2045420466
VERIFY_AND_SET_OID(cert->extSubjKeyIdSet);
2045520467
cert->extSubjKeyIdCrit = critical ? 1 : 0;
20456-
#ifndef WOLFSSL_ALLOW_CRIT_SKID
20457-
/* This check is added due to RFC 5280 section 4.2.1.2
20458-
* stating that conforming CA's must mark this extension
20459-
* as non-critical. When parsing extensions check that
20460-
* certificate was made in compliance with this. */
20461-
if (critical) {
20462-
WOLFSSL_MSG("Critical Subject Key ID is not allowed");
20463-
WOLFSSL_MSG("Use macro WOLFSSL_ALLOW_CRIT_SKID if wanted");
20464-
ret = ASN_CRIT_EXT_E;
20465-
}
20466-
#endif
20468+
#ifndef WOLFSSL_ALLOW_CRIT_SKID
20469+
/* This check is added due to RFC 5280 section 4.2.1.2
20470+
* stating that conforming CA's must mark this extension
20471+
* as non-critical. When parsing extensions check that
20472+
* certificate was made in compliance with this. */
20473+
if (critical) {
20474+
WOLFSSL_MSG("Critical Subject Key ID is not allowed");
20475+
WOLFSSL_MSG("Use macro WOLFSSL_ALLOW_CRIT_SKID if wanted");
20476+
ret = ASN_CRIT_EXT_E;
20477+
}
20478+
#endif
2046720479

2046820480
if ((ret == 0) && (DecodeSubjKeyId(input, length, cert) < 0)) {
2046920481
ret = ASN_PARSE_E;
@@ -20472,21 +20484,21 @@ static int DecodeExtensionType(const byte* input, word32 length, word32 oid,
2047220484

2047320485
/* Certificate policies. */
2047420486
case CERT_POLICY_OID:
20475-
#if defined(WOLFSSL_SEP) || defined(WOLFSSL_QT)
20476-
VERIFY_AND_SET_OID(cert->extCertPolicySet);
20477-
#if defined(OPENSSL_EXTRA) || \
20478-
defined(OPENSSL_EXTRA_X509_SMALL)
20479-
cert->extCertPolicyCrit = critical ? 1 : 0;
20480-
#endif
20481-
#endif
20482-
#if defined(WOLFSSL_SEP) || defined(WOLFSSL_CERT_EXT) || \
20483-
defined(WOLFSSL_QT)
20484-
if (DecodeCertPolicy(input, length, cert) < 0) {
20485-
ret = ASN_PARSE_E;
20486-
}
20487-
#else
20488-
WOLFSSL_MSG("Certificate Policy extension not supported yet.");
20487+
#if defined(WOLFSSL_SEP) || defined(WOLFSSL_QT)
20488+
VERIFY_AND_SET_OID(cert->extCertPolicySet);
20489+
#if defined(OPENSSL_EXTRA) || \
20490+
defined(OPENSSL_EXTRA_X509_SMALL)
20491+
cert->extCertPolicyCrit = critical ? 1 : 0;
2048920492
#endif
20493+
#endif
20494+
#if defined(WOLFSSL_SEP) || defined(WOLFSSL_CERT_EXT) || \
20495+
defined(WOLFSSL_QT)
20496+
if (DecodeCertPolicy(input, length, cert) < 0) {
20497+
ret = ASN_PARSE_E;
20498+
}
20499+
#else
20500+
WOLFSSL_MSG("Certificate Policy extension not supported yet.");
20501+
#endif
2049020502
break;
2049120503

2049220504
/* Key usage. */

0 commit comments

Comments
 (0)