Change to compare each name to each matching type in permittedNames list.

This commit is contained in:
Sean Parkinson
2021-10-22 10:43:29 +10:00
parent 785e37790a
commit 6e7dee3283

View File

@@ -13489,80 +13489,89 @@ static int ConfirmNameConstraints(Signer* signer, DecodedCert* cert)
/* Check against the permitted list */ /* Check against the permitted list */
if (signer->permittedNames != NULL) { if (signer->permittedNames != NULL) {
int needDns = 0; int permittedDir = 0;
int matchDns = 0; int matchDir;
int needEmail = 0; Base_entry* base;
int matchEmail = 0; DNS_entry* name;
int needDir = 0;
int matchDir = 0;
Base_entry* base = signer->permittedNames;
while (base != NULL) {
switch (base->type) {
case ASN_DNS_TYPE:
{
DNS_entry* name = cert->altNames;
if (name != NULL)
needDns = 1;
/* check if already found a matching permitted subtree */
if (matchDns == 1)
break;
/* Check each DNS name matches a permitted. */
name = cert->altNames;
while (name != NULL) { while (name != NULL) {
int matchDns = 0;
int permittedDns = 0;
base = signer->permittedNames;
do {
/* Looking for perrmittedNames that are for DNS. */
if (base->type == ASN_DNS_TYPE) {
permittedDns = 1;
matchDns = MatchBaseName(ASN_DNS_TYPE, matchDns = MatchBaseName(ASN_DNS_TYPE,
name->name, name->len, name->name, name->len,
base->name, base->nameSz); base->name, base->nameSz);
}
base = base->next;
}
while (base != NULL && !matchDns);
/* If we found an DNS type permittedName then name must have had a
* match. */
if (permittedDns && !matchDns)
return 0;
#ifndef WOLFSSL_NO_ASN_STRICT if (!permittedDns)
/* found a bad name */
if (matchDns == 0)
break; break;
#endif
name = name->next; name = name->next;
} }
break;
}
case ASN_RFC822_TYPE:
{
DNS_entry* name = cert->altEmailNames;
if (name != NULL)
needEmail = 1;
/* check if already found a matching permitted subtree */
if (matchEmail == 1)
break;
/* Check each email name matches a permitted. */
name = cert->altEmailNames;
while (name != NULL) { while (name != NULL) {
int matchEmail = 0;
int permittedEmail = 0;
base = signer->permittedNames;
do {
/* Looking for perrmittedNames that are for email. */
if (base->type == ASN_RFC822_TYPE) {
permittedEmail = 1;
matchEmail = MatchBaseName(ASN_DNS_TYPE, matchEmail = MatchBaseName(ASN_DNS_TYPE,
name->name, name->len, name->name, name->len,
base->name, base->nameSz); base->name, base->nameSz);
}
base = base->next;
}
while ((base != NULL) && !matchEmail);
/* If we found an email type permittedName then name must have had a
* match. */
if (permittedEmail && !matchEmail)
return 0;
#ifndef WOLFSSL_NO_ASN_STRICT if (!permittedEmail)
/* found a bad name */
if (matchEmail == 0)
break; break;
#endif
name = name->next; name = name->next;
} }
break;
}
case ASN_DIR_TYPE:
{
/* allow permitted dirName smaller than actual subject */
needDir = 1;
/* check if already found a matching permitted subtree */ /* Check subject name matches a permitted name. */
if (matchDir == 1) if (cert->subjectRaw != NULL) {
break; matchDir = 0;
permittedDir = 0;
if (cert->subjectRaw != NULL && base = signer->permittedNames;
cert->subjectRawLen >= base->nameSz && while (base != NULL && !matchDir) {
XMEMCMP(cert->subjectRaw, base->name, /* Looking for perrmittedNames that are for directoryName. */
base->nameSz) == 0) { if (base->type == ASN_DIR_TYPE) {
permittedDir = 1;
if (cert->subjectRawLen >= base->nameSz &&
XMEMCMP(cert->subjectRaw, base->name, base->nameSz)
== 0) {
matchDir = 1; matchDir = 1;
}
}
base = base->next;
}
/* If we found an dir name type permittedName then name must have
* had a match. */
if (permittedDir && !matchDir)
return 0;
}
#ifndef WOLFSSL_NO_ASN_STRICT #ifndef WOLFSSL_NO_ASN_STRICT
/* RFC 5280 section 4.2.1.10 /* RFC 5280 section 4.2.1.10
@@ -13571,32 +13580,29 @@ static int ConfirmNameConstraints(Signer* signer, DecodedCert* cert)
of type directoryName in the subjectAltName of type directoryName in the subjectAltName
extension" extension"
*/ */
if (cert->altDirNames != NULL) { /* Check each alt dir name matches a permitted. */
DNS_entry* cur = cert->altDirNames; name = cert->altDirNames;
while (cur != NULL) { while (permittedDir && name != NULL) {
if (XMEMCMP(cur->name, base->name, base->nameSz) int matchAltDir = 0;
!= 0) { base = signer->permittedNames;
WOLFSSL_MSG("DIR alt name constraint err"); do {
matchDir = 0; /* did not match */ /* Looking for perrmittedNames that are for directoryName. */
} if (base->type == ASN_DIR_TYPE) {
cur = cur->next; if (XMEMCMP(name->name, base->name, base->nameSz) == 0) {
matchAltDir = 1;
} }
} }
#endif /* !WOLFSSL_NO_ASN_STRICT */
}
break;
}
default:
break;
} /* switch */
base = base->next; base = base->next;
} }
while ((base != NULL) && !matchAltDir);
if ((needDns && !matchDns) || /* If we found an dir name type permittedName then name must have
(needEmail && !matchEmail) || * had a match. */
(needDir && !matchDir)) { if (permittedDir && !matchAltDir)
return 0; return 0;
name = name->next;
} }
#endif /* !WOLFSSL_NO_ASN_STRICT */
} }
return 1; return 1;