Skip to content

Commit a19a053

Browse files
committed
Fix RFC references and add WOLFSSL_ALLOW_CRIT_AIA
1 parent d320260 commit a19a053

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
@@ -18974,9 +18974,9 @@ enum {
1897418974
#define authKeyIdASN_Length (sizeof(authKeyIdASN) / sizeof(ASNItem))
1897518975
#endif
1897618976

18977-
/* Decode authority information access extension in a certificate.
18977+
/* Decode authority key identifier extension in a certificate.
1897818978
*
18979-
* X.509: RFC 5280, 4.2.2.1 - Authority Information Access.
18979+
* X.509: RFC 5280, 4.2.1.1 - Authority Key Identifier.
1898018980
*
1898118981
* @param [in] input Buffer holding data.
1898218982
* @param [in] sz Size of data in buffer.
@@ -19098,7 +19098,7 @@ static int DecodeAuthKeyId(const byte* input, word32 sz, DecodedCert* cert)
1909819098

1909919099
/* Decode subject key id extension in a certificate.
1910019100
*
19101-
* X.509: RFC 5280, 4.2.2.1 - Authority Information Access.
19101+
* X.509: RFC 5280, 4.2.1.2 - Subject Key Identifier.
1910219102
*
1910319103
* @param [in] input Buffer holding data.
1910419104
* @param [in] sz Size of data in buffer.
@@ -19148,7 +19148,7 @@ enum {
1914819148

1914919149
/* Decode key usage extension in a certificate.
1915019150
*
19151-
* X.509: RFC 5280, 4.2.2.1 - Authority Information Access.
19151+
* X.509: RFC 5280, 4.2.1.3 - Key Usage.
1915219152
*
1915319153
* @param [in] input Buffer holding data.
1915419154
* @param [in] sz Size of data in buffer.
@@ -19880,7 +19880,7 @@ int DecodePolicyOID(char *out, word32 outSz, const byte *in, word32 inSz)
1988019880
return ASN_PARSE_E;
1988119881
}
1988219882
#ifndef WOLFSSL_DUP_CERTPOL
19883-
/* From RFC 5280 section 4.2.1.3 "A certificate policy OID MUST
19883+
/* From RFC 5280 section 4.2.1.4 "A certificate policy OID MUST
1988419884
* NOT appear more than once in a certificate policies
1988519885
* extension". This is a sanity check for duplicates.
1988619886
* extCertPolicies should only have OID values, additional
@@ -19989,7 +19989,7 @@ int DecodePolicyOID(char *out, word32 outSz, const byte *in, word32 inSz)
1998919989
}
1999019990
}
1999119991
#ifndef WOLFSSL_DUP_CERTPOL
19992-
/* From RFC 5280 section 4.2.1.3 "A certificate policy OID MUST
19992+
/* From RFC 5280 section 4.2.1.4 "A certificate policy OID MUST
1999319993
* NOT appear more than once in a certificate policies
1999419994
* extension". This is a sanity check for duplicates.
1999519995
* extCertPolicies should only have OID values, additional
@@ -20327,7 +20327,19 @@ static int DecodeExtensionType(const byte* input, word32 length, word32 oid,
2032720327
case AUTH_INFO_OID:
2032820328
VERIFY_AND_SET_OID(cert->extAuthInfoSet);
2032920329
cert->extAuthInfoCrit = critical ? 1 : 0;
20330-
if (DecodeAuthInfo(input, length, cert) < 0) {
20330+
#ifndef WOLFSSL_ALLOW_CRIT_AIA
20331+
/* This check is added due to RFC 5280 section 4.2.2.1
20332+
* stating that conforming CA's must mark this extension
20333+
* as non-critical. When parsing extensions check that
20334+
* certificate was made in compliance with this. */
20335+
if (critical) {
20336+
WOLFSSL_MSG("Critical Authority Information Access is not"
20337+
"allowed");
20338+
WOLFSSL_MSG("Use macro WOLFSSL_ALLOW_CRIT_AIA if wanted");
20339+
ret = ASN_CRIT_EXT_E;
20340+
}
20341+
#endif
20342+
if ((ret == 0) && (DecodeAuthInfo(input, length, cert) < 0)) {
2033120343
ret = ASN_PARSE_E;
2033220344
}
2033320345
break;
@@ -20343,17 +20355,17 @@ static int DecodeExtensionType(const byte* input, word32 length, word32 oid,
2034320355
case AUTH_KEY_OID:
2034420356
VERIFY_AND_SET_OID(cert->extAuthKeyIdSet);
2034520357
cert->extAuthKeyIdCrit = critical ? 1 : 0;
20346-
#ifndef WOLFSSL_ALLOW_CRIT_SKID
20347-
/* This check is added due to RFC 5280 section 4.2.1.1
20348-
* stating that conforming CA's must mark this extension
20349-
* as non-critical. When parsing extensions check that
20350-
* certificate was made in compliance with this. */
20351-
if (critical) {
20352-
WOLFSSL_MSG("Critical Auth Key ID is not allowed");
20353-
WOLFSSL_MSG("Use macro WOLFSSL_ALLOW_CRIT_SKID if wanted");
20354-
ret = ASN_CRIT_EXT_E;
20355-
}
20356-
#endif
20358+
#ifndef WOLFSSL_ALLOW_CRIT_AKID
20359+
/* This check is added due to RFC 5280 section 4.2.1.1
20360+
* stating that conforming CA's must mark this extension
20361+
* as non-critical. When parsing extensions check that
20362+
* certificate was made in compliance with this. */
20363+
if (critical) {
20364+
WOLFSSL_MSG("Critical Auth Key ID is not allowed");
20365+
WOLFSSL_MSG("Use macro WOLFSSL_ALLOW_CRIT_AKID if wanted");
20366+
ret = ASN_CRIT_EXT_E;
20367+
}
20368+
#endif
2035720369
if ((ret == 0) && (DecodeAuthKeyId(input, length, cert) < 0)) {
2035820370
ret = ASN_PARSE_E;
2035920371
}
@@ -20363,17 +20375,17 @@ static int DecodeExtensionType(const byte* input, word32 length, word32 oid,
2036320375
case SUBJ_KEY_OID:
2036420376
VERIFY_AND_SET_OID(cert->extSubjKeyIdSet);
2036520377
cert->extSubjKeyIdCrit = critical ? 1 : 0;
20366-
#ifndef WOLFSSL_ALLOW_CRIT_SKID
20367-
/* This check is added due to RFC 5280 section 4.2.1.2
20368-
* stating that conforming CA's must mark this extension
20369-
* as non-critical. When parsing extensions check that
20370-
* certificate was made in compliance with this. */
20371-
if (critical) {
20372-
WOLFSSL_MSG("Critical Subject Key ID is not allowed");
20373-
WOLFSSL_MSG("Use macro WOLFSSL_ALLOW_CRIT_SKID if wanted");
20374-
ret = ASN_CRIT_EXT_E;
20375-
}
20376-
#endif
20378+
#ifndef WOLFSSL_ALLOW_CRIT_SKID
20379+
/* This check is added due to RFC 5280 section 4.2.1.2
20380+
* stating that conforming CA's must mark this extension
20381+
* as non-critical. When parsing extensions check that
20382+
* certificate was made in compliance with this. */
20383+
if (critical) {
20384+
WOLFSSL_MSG("Critical Subject Key ID is not allowed");
20385+
WOLFSSL_MSG("Use macro WOLFSSL_ALLOW_CRIT_SKID if wanted");
20386+
ret = ASN_CRIT_EXT_E;
20387+
}
20388+
#endif
2037720389

2037820390
if ((ret == 0) && (DecodeSubjKeyId(input, length, cert) < 0)) {
2037920391
ret = ASN_PARSE_E;
@@ -20382,21 +20394,21 @@ static int DecodeExtensionType(const byte* input, word32 length, word32 oid,
2038220394

2038320395
/* Certificate policies. */
2038420396
case CERT_POLICY_OID:
20385-
#if defined(WOLFSSL_SEP) || defined(WOLFSSL_QT)
20386-
VERIFY_AND_SET_OID(cert->extCertPolicySet);
20387-
#if defined(OPENSSL_EXTRA) || \
20388-
defined(OPENSSL_EXTRA_X509_SMALL)
20389-
cert->extCertPolicyCrit = critical ? 1 : 0;
20390-
#endif
20391-
#endif
20392-
#if defined(WOLFSSL_SEP) || defined(WOLFSSL_CERT_EXT) || \
20393-
defined(WOLFSSL_QT)
20394-
if (DecodeCertPolicy(input, length, cert) < 0) {
20395-
ret = ASN_PARSE_E;
20396-
}
20397-
#else
20398-
WOLFSSL_MSG("Certificate Policy extension not supported yet.");
20397+
#if defined(WOLFSSL_SEP) || defined(WOLFSSL_QT)
20398+
VERIFY_AND_SET_OID(cert->extCertPolicySet);
20399+
#if defined(OPENSSL_EXTRA) || \
20400+
defined(OPENSSL_EXTRA_X509_SMALL)
20401+
cert->extCertPolicyCrit = critical ? 1 : 0;
2039920402
#endif
20403+
#endif
20404+
#if defined(WOLFSSL_SEP) || defined(WOLFSSL_CERT_EXT) || \
20405+
defined(WOLFSSL_QT)
20406+
if (DecodeCertPolicy(input, length, cert) < 0) {
20407+
ret = ASN_PARSE_E;
20408+
}
20409+
#else
20410+
WOLFSSL_MSG("Certificate Policy extension not supported yet.");
20411+
#endif
2040020412
break;
2040120413

2040220414
/* Key usage. */

0 commit comments

Comments
 (0)