mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-05 05:34:41 +02:00
Change to compare each name to each matching type in permittedNames list.
This commit is contained in:
@@ -13489,114 +13489,120 @@ 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) {
|
/* Check each DNS name matches a permitted. */
|
||||||
switch (base->type) {
|
name = cert->altNames;
|
||||||
case ASN_DNS_TYPE:
|
while (name != NULL) {
|
||||||
{
|
int matchDns = 0;
|
||||||
DNS_entry* name = cert->altNames;
|
int permittedDns = 0;
|
||||||
|
base = signer->permittedNames;
|
||||||
if (name != NULL)
|
do {
|
||||||
needDns = 1;
|
/* Looking for perrmittedNames that are for DNS. */
|
||||||
|
if (base->type == ASN_DNS_TYPE) {
|
||||||
/* check if already found a matching permitted subtree */
|
permittedDns = 1;
|
||||||
if (matchDns == 1)
|
matchDns = MatchBaseName(ASN_DNS_TYPE,
|
||||||
break;
|
name->name, name->len,
|
||||||
|
base->name, base->nameSz);
|
||||||
while (name != NULL) {
|
|
||||||
matchDns = MatchBaseName(ASN_DNS_TYPE,
|
|
||||||
name->name, name->len,
|
|
||||||
base->name, base->nameSz);
|
|
||||||
|
|
||||||
#ifndef WOLFSSL_NO_ASN_STRICT
|
|
||||||
/* found a bad name */
|
|
||||||
if (matchDns == 0)
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
name = name->next;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case ASN_RFC822_TYPE:
|
base = base->next;
|
||||||
{
|
}
|
||||||
DNS_entry* name = cert->altEmailNames;
|
while (base != NULL && !matchDns);
|
||||||
|
/* If we found an DNS type permittedName then name must have had a
|
||||||
|
* match. */
|
||||||
|
if (permittedDns && !matchDns)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (name != NULL)
|
if (!permittedDns)
|
||||||
needEmail = 1;
|
break;
|
||||||
|
|
||||||
/* check if already found a matching permitted subtree */
|
name = name->next;
|
||||||
if (matchEmail == 1)
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
while (name != NULL) {
|
/* Check each email name matches a permitted. */
|
||||||
matchEmail = MatchBaseName(ASN_DNS_TYPE,
|
name = cert->altEmailNames;
|
||||||
name->name, name->len,
|
while (name != NULL) {
|
||||||
base->name, base->nameSz);
|
int matchEmail = 0;
|
||||||
|
int permittedEmail = 0;
|
||||||
#ifndef WOLFSSL_NO_ASN_STRICT
|
base = signer->permittedNames;
|
||||||
/* found a bad name */
|
do {
|
||||||
if (matchEmail == 0)
|
/* Looking for perrmittedNames that are for email. */
|
||||||
break;
|
if (base->type == ASN_RFC822_TYPE) {
|
||||||
#endif
|
permittedEmail = 1;
|
||||||
name = name->next;
|
matchEmail = MatchBaseName(ASN_DNS_TYPE,
|
||||||
}
|
name->name, name->len,
|
||||||
break;
|
base->name, base->nameSz);
|
||||||
}
|
}
|
||||||
case ASN_DIR_TYPE:
|
base = base->next;
|
||||||
{
|
}
|
||||||
/* allow permitted dirName smaller than actual subject */
|
while ((base != NULL) && !matchEmail);
|
||||||
needDir = 1;
|
/* If we found an email type permittedName then name must have had a
|
||||||
|
* match. */
|
||||||
|
if (permittedEmail && !matchEmail)
|
||||||
|
return 0;
|
||||||
|
|
||||||
/* check if already found a matching permitted subtree */
|
if (!permittedEmail)
|
||||||
if (matchDir == 1)
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
if (cert->subjectRaw != NULL &&
|
name = name->next;
|
||||||
cert->subjectRawLen >= base->nameSz &&
|
}
|
||||||
XMEMCMP(cert->subjectRaw, base->name,
|
|
||||||
base->nameSz) == 0) {
|
/* Check subject name matches a permitted name. */
|
||||||
|
if (cert->subjectRaw != NULL) {
|
||||||
|
matchDir = 0;
|
||||||
|
permittedDir = 0;
|
||||||
|
base = signer->permittedNames;
|
||||||
|
while (base != NULL && !matchDir) {
|
||||||
|
/* Looking for perrmittedNames that are for directoryName. */
|
||||||
|
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;
|
||||||
|
|
||||||
#ifndef WOLFSSL_NO_ASN_STRICT
|
|
||||||
/* RFC 5280 section 4.2.1.10
|
|
||||||
"Restrictions of the form directoryName MUST be
|
|
||||||
applied to the subject field .... and to any names
|
|
||||||
of type directoryName in the subjectAltName
|
|
||||||
extension"
|
|
||||||
*/
|
|
||||||
if (cert->altDirNames != NULL) {
|
|
||||||
DNS_entry* cur = cert->altDirNames;
|
|
||||||
while (cur != NULL) {
|
|
||||||
if (XMEMCMP(cur->name, base->name, base->nameSz)
|
|
||||||
!= 0) {
|
|
||||||
WOLFSSL_MSG("DIR alt name constraint err");
|
|
||||||
matchDir = 0; /* did not match */
|
|
||||||
}
|
|
||||||
cur = cur->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* !WOLFSSL_NO_ASN_STRICT */
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
default:
|
base = base->next;
|
||||||
break;
|
}
|
||||||
} /* switch */
|
/* If we found an dir name type permittedName then name must have
|
||||||
base = base->next;
|
* had a match. */
|
||||||
|
if (permittedDir && !matchDir)
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((needDns && !matchDns) ||
|
#ifndef WOLFSSL_NO_ASN_STRICT
|
||||||
(needEmail && !matchEmail) ||
|
/* RFC 5280 section 4.2.1.10
|
||||||
(needDir && !matchDir)) {
|
"Restrictions of the form directoryName MUST be
|
||||||
return 0;
|
applied to the subject field .... and to any names
|
||||||
|
of type directoryName in the subjectAltName
|
||||||
|
extension"
|
||||||
|
*/
|
||||||
|
/* Check each alt dir name matches a permitted. */
|
||||||
|
name = cert->altDirNames;
|
||||||
|
while (permittedDir && name != NULL) {
|
||||||
|
int matchAltDir = 0;
|
||||||
|
base = signer->permittedNames;
|
||||||
|
do {
|
||||||
|
/* Looking for perrmittedNames that are for directoryName. */
|
||||||
|
if (base->type == ASN_DIR_TYPE) {
|
||||||
|
if (XMEMCMP(name->name, base->name, base->nameSz) == 0) {
|
||||||
|
matchAltDir = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
base = base->next;
|
||||||
|
}
|
||||||
|
while ((base != NULL) && !matchAltDir);
|
||||||
|
/* If we found an dir name type permittedName then name must have
|
||||||
|
* had a match. */
|
||||||
|
if (permittedDir && !matchAltDir)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
name = name->next;
|
||||||
}
|
}
|
||||||
|
#endif /* !WOLFSSL_NO_ASN_STRICT */
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
Reference in New Issue
Block a user