From 04e22b0747a41bf56ca0dfce3d15e208720c7ef9 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Fri, 11 Dec 2020 10:00:11 +0700 Subject: [PATCH] add restriction to excluded DIR name constraint --- certs/test/cert-ext-ndir-exc.cfg | 24 +++++++++++++++++++ certs/test/cert-ext-ndir-exc.der | Bin 0 -> 1281 bytes certs/test/gen-ext-certs.sh | 32 ++++++++++++++++++++++++++ certs/test/include.am | 2 ++ tests/api.c | 38 ++++++++++++++++++++++++++++--- wolfcrypt/src/asn.c | 19 ++++++++++++++++ 6 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 certs/test/cert-ext-ndir-exc.cfg create mode 100644 certs/test/cert-ext-ndir-exc.der diff --git a/certs/test/cert-ext-ndir-exc.cfg b/certs/test/cert-ext-ndir-exc.cfg new file mode 100644 index 000000000..8d66b8a07 --- /dev/null +++ b/certs/test/cert-ext-ndir-exc.cfg @@ -0,0 +1,24 @@ +[ req ] +distinguished_name = req_distinguished_name +prompt = no +x509_extensions = constraints + +[ req_distinguished_name ] +C = US +ST = Montana +L = Bozeman +O = Sawtooth +OU = Consulting +CN = www.wolfssl.com +emailAddress = info@wolfsssl.com + +[constraints] +subjectKeyIdentifier=hash +authorityKeyIdentifier=keyid:always,issuer:always +basicConstraints=CA:TRUE +nameConstraints=critical,excluded;dirName:dir_name_exclude + +[dir_name_exclude] +countryName = US +stateOrProvinceName = California + diff --git a/certs/test/cert-ext-ndir-exc.der b/certs/test/cert-ext-ndir-exc.der new file mode 100644 index 0000000000000000000000000000000000000000..19afbab840a90d09b8b50c8658fb48465f70ec88 GIT binary patch literal 1281 zcmXqLV)<*(#QbytGZP~dlZb}T2I*f+%_b206S#$jDr<$o7rZ&}j##o#!SAD;? zp)`1kjqR!A==q{sFUtz+OJ20OU1oJ=NA1a{hpyjp$iJa@r&!uaH+arJsXw)=tIX_Y z+-s>}O+S|AbDk$#Ery8)TS=cyxN#l&cnjD(2=RqEj zw}e?(4VW1j{~MTrcyd4%i;jWTLJb48B`O9=sJRlFy*Pl`D={ZCEx#x)GZ8tN0dq1i znK3fVa8i1*{oG!?;uWut2Pnr&M>}lwh-}wAqvzRGa+-yYpLgME^J#@VZ}rB^Px%Lzl&_jMtAPU*C^gExtOr{YWl1RU!Mz|ICo=Cp|I2qi}$}$m<9Xy_sh?{ zt7Lof;f9oBXG}M!R7d72ymRB|`FJ`Y(J)x6bmi&CYg6~!3RFnw?ft$rxx;ItzVflh zzd2g;i6S&ySu`C>mdNlSj1BR literal 0 HcmV?d00001 diff --git a/certs/test/gen-ext-certs.sh b/certs/test/gen-ext-certs.sh index 65ce2124c..e418157ab 100755 --- a/certs/test/gen-ext-certs.sh +++ b/certs/test/gen-ext-certs.sh @@ -128,3 +128,35 @@ countryName = US EOF gen_cert +OUT=certs/test/cert-ext-ndir-exc.der +KEYFILE=certs/ca-key.der +CONFIG=certs/test/cert-ext-ndir-exc.cfg +tee >$CONFIG <nameSz) == 0) { 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" + */ + 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"); + return 0; + } + cur = cur->next; + } + } + #endif /* !WOLFSSL_NO_ASN_STRICT */ break; } }; /* switch */