diff --git a/certs/test/cert-ext-mnc.der b/certs/test/cert-ext-mnc.der new file mode 100644 index 000000000..b7df09abb Binary files /dev/null and b/certs/test/cert-ext-mnc.der differ diff --git a/certs/test/cert-ext-nc.cfg b/certs/test/cert-ext-nc.cfg index 9e8ff6be5..ce3757091 100644 --- a/certs/test/cert-ext-nc.cfg +++ b/certs/test/cert-ext-nc.cfg @@ -10,7 +10,6 @@ L = Brisbane O = wolfSSL Inc OU = Engineering CN = www.wolfssl.com -emailAddress = support@wolfsssl.com [ v3_ca ] subjectKeyIdentifier = hash diff --git a/certs/test/cert-ext-nc.der b/certs/test/cert-ext-nc.der index e16710d1e..a390dbfd3 100644 Binary files a/certs/test/cert-ext-nc.der and b/certs/test/cert-ext-nc.der differ diff --git a/certs/test/cert-ext-ncdns.der b/certs/test/cert-ext-ncdns.der new file mode 100644 index 000000000..5222e1523 Binary files /dev/null and b/certs/test/cert-ext-ncdns.der differ diff --git a/certs/test/cert-ext-ncmixed.der b/certs/test/cert-ext-ncmixed.der new file mode 100644 index 000000000..a7fad165d Binary files /dev/null and b/certs/test/cert-ext-ncmixed.der differ diff --git a/certs/test/gen-ext-certs.sh b/certs/test/gen-ext-certs.sh index 8a19bc2c2..aa77314b0 100755 --- a/certs/test/gen-ext-certs.sh +++ b/certs/test/gen-ext-certs.sh @@ -34,7 +34,6 @@ L = Brisbane O = wolfSSL Inc OU = Engineering CN = www.wolfssl.com -emailAddress = support@wolfsssl.com [ v3_ca ] subjectKeyIdentifier = hash @@ -47,6 +46,92 @@ nsComment = "Testing name constraints" EOF gen_cert + +OUT=certs/test/cert-ext-mnc.der +KEYFILE=certs/test/cert-ext-mnc-key.der +CONFIG=certs/test/cert-ext-mnc.cfg +tee >$CONFIG <$CONFIG <$CONFIG <permittedNames != NULL) { - int needDns = 0; - int matchDns = 0; - int needEmail = 0; - int matchEmail = 0; - int needDir = 0; - int matchDir = 0; - Base_entry* base = signer->permittedNames; + int permittedDir = 0; + int matchDir; + Base_entry* base; + DNS_entry* name; - while (base != NULL) { - switch (base->type) { - case ASN_DNS_TYPE: - { - DNS_entry* name = cert->altNames; - - if (name != NULL) - needDns = 1; - - while (name != NULL) { - matchDns = MatchBaseName(ASN_DNS_TYPE, - name->name, name->len, - base->name, base->nameSz); - name = name->next; - } - break; + /* Check each DNS name matches a permitted. */ + name = cert->altNames; + while (name != NULL) { + int matchDns = 0; + int permittedDns = 0; + base = signer->permittedNames; + do { + /* Looking for permittedNames that are for DNS. */ + if (base->type == ASN_DNS_TYPE) { + permittedDns = 1; + matchDns = MatchBaseName(ASN_DNS_TYPE, + name->name, name->len, + base->name, base->nameSz); } - case ASN_RFC822_TYPE: - { - DNS_entry* name = cert->altEmailNames; + 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; - if (name != NULL) - needEmail = 1; + if (!permittedDns) + break; - while (name != NULL) { - matchEmail = MatchBaseName(ASN_DNS_TYPE, - name->name, name->len, - base->name, base->nameSz); - name = name->next; - } - break; + name = name->next; + } + + /* Check each email name matches a permitted. */ + name = cert->altEmailNames; + while (name != NULL) { + int matchEmail = 0; + int permittedEmail = 0; + base = signer->permittedNames; + do { + /* Looking for permittedNames that are for email. */ + if (base->type == ASN_RFC822_TYPE) { + permittedEmail = 1; + matchEmail = MatchBaseName(ASN_DNS_TYPE, + name->name, name->len, + base->name, base->nameSz); } - case ASN_DIR_TYPE: - { - /* allow permitted dirName smaller than actual subject */ - needDir = 1; - if (cert->subjectRaw != NULL && - cert->subjectRawLen >= base->nameSz && - XMEMCMP(cert->subjectRaw, base->name, - base->nameSz) == 0) { + 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; + + if (!permittedEmail) + break; + + name = name->next; + } + + /* Check subject name matches a permitted name. */ + if (cert->subjectRaw != NULL) { + matchDir = 0; + permittedDir = 0; + base = signer->permittedNames; + while (base != NULL && !matchDir) { + /* Looking for permittedNames 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; - - #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: - break; - } /* switch */ - base = base->next; + base = base->next; + } + /* If we found an dir name type permittedName then name must have + * had a match. */ + if (permittedDir && !matchDir) + return 0; } - if ((needDns && !matchDns) || - (needEmail && !matchEmail) || - (needDir && !matchDir)) { - return 0; + #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" + */ + /* Check each alt dir name matches a permitted. */ + name = cert->altDirNames; + while (permittedDir && name != NULL) { + int matchAltDir = 0; + base = signer->permittedNames; + do { + /* Looking for permittedNames 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;