Skip to content

Commit f1b1483

Browse files
authored
Merge pull request #7669 from JacobBarthelmeh/x509_dn
sanity check for empty directory strings
2 parents 2312cb4 + 8ee01eb commit f1b1483

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

wolfcrypt/src/asn.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13903,6 +13903,18 @@ static int GetCertName(DecodedCert* cert, char* full, byte* hash, int nameType,
1390313903
return ASN_PARSE_E;
1390413904
}
1390513905

13906+
#ifndef WOLFSSL_NO_ASN_STRICT
13907+
/* RFC 5280 section 4.1.2.4 lists a DirecotryString as being
13908+
* 1..MAX in length */
13909+
if (strLen < 1) {
13910+
WOLFSSL_MSG("Non conforming DirectoryString of length 0 was"
13911+
" found");
13912+
WOLFSSL_MSG("Use WOLFSSL_NO_ASN_STRICT if wanting to allow"
13913+
" empty DirectoryString's");
13914+
return ASN_PARSE_E;
13915+
}
13916+
#endif
13917+
1390613918
if (id == ASN_COMMON_NAME) {
1390713919
if (nameType == SUBJECT) {
1390813920
cert->subjectCN = (char *)&input[srcIdx];
@@ -14533,6 +14545,18 @@ static int GetCertName(DecodedCert* cert, char* full, byte* hash, int nameType,
1453314545
/* Get string reference. */
1453414546
GetASN_GetRef(&dataASN[RDNASN_IDX_ATTR_VAL], &str, &strLen);
1453514547

14548+
#ifndef WOLFSSL_NO_ASN_STRICT
14549+
/* RFC 5280 section 4.1.2.4 lists a DirecotryString as being
14550+
* 1..MAX in length */
14551+
if (ret == 0 && strLen < 1) {
14552+
WOLFSSL_MSG("Non conforming DirectoryString of length 0 was"
14553+
" found");
14554+
WOLFSSL_MSG("Use WOLFSSL_NO_ASN_STRICT if wanting to allow"
14555+
" empty DirectoryString's");
14556+
ret = ASN_PARSE_E;
14557+
}
14558+
#endif
14559+
1453614560
/* Convert BER tag to a OpenSSL type. */
1453714561
switch (tag) {
1453814562
case CTC_UTF8:

0 commit comments

Comments
 (0)