1*e0c4386eSCy Schubert#! /bin/bash 2*e0c4386eSCy Schubert 3*e0c4386eSCy Schubert# Primary root: root-cert 4*e0c4386eSCy Schubert./mkcert.sh genroot "Root CA" root-key root-cert 5*e0c4386eSCy Schubert# root cert variants: CA:false, key2, DN2, expired 6*e0c4386eSCy Schubert./mkcert.sh genss "Root CA" root-key root-nonca 7*e0c4386eSCy Schubert./mkcert.sh genroot "Root CA" root-key2 root-cert2 8*e0c4386eSCy Schubert./mkcert.sh genroot "Root Cert 2" root-key root-name2 9*e0c4386eSCy SchubertDAYS=-1 ./mkcert.sh genroot "Root CA" root-key root-expired 10*e0c4386eSCy Schubert# cross root and root cross cert 11*e0c4386eSCy Schubert./mkcert.sh genroot "Cross Root" cross-key cross-root 12*e0c4386eSCy Schubert./mkcert.sh genca "Root CA" root-key root-cross-cert cross-key cross-root 13*e0c4386eSCy Schubert# trust variants: +serverAuth -serverAuth +clientAuth -clientAuth 14*e0c4386eSCy Schubertopenssl x509 -in root-cert.pem -trustout \ 15*e0c4386eSCy Schubert -addtrust serverAuth -out root+serverAuth.pem 16*e0c4386eSCy Schubertopenssl x509 -in root-cert.pem -trustout \ 17*e0c4386eSCy Schubert -addreject serverAuth -out root-serverAuth.pem 18*e0c4386eSCy Schubertopenssl x509 -in root-cert.pem -trustout \ 19*e0c4386eSCy Schubert -addtrust clientAuth -out root+clientAuth.pem 20*e0c4386eSCy Schubertopenssl x509 -in root-cert.pem -trustout \ 21*e0c4386eSCy Schubert -addreject clientAuth -out root-clientAuth.pem 22*e0c4386eSCy Schubert# trust variants: +anyEKU -anyEKU 23*e0c4386eSCy Schubertopenssl x509 -in root-cert.pem -trustout \ 24*e0c4386eSCy Schubert -addtrust anyExtendedKeyUsage -out root+anyEKU.pem 25*e0c4386eSCy Schubertopenssl x509 -in root-cert.pem -trustout \ 26*e0c4386eSCy Schubert -addreject anyExtendedKeyUsage -out root-anyEKU.pem 27*e0c4386eSCy Schubert# root-cert2 trust variants: +serverAuth -serverAuth +clientAuth 28*e0c4386eSCy Schubertopenssl x509 -in root-cert2.pem -trustout \ 29*e0c4386eSCy Schubert -addtrust serverAuth -out root2+serverAuth.pem 30*e0c4386eSCy Schubertopenssl x509 -in root-cert2.pem -trustout \ 31*e0c4386eSCy Schubert -addreject serverAuth -out root2-serverAuth.pem 32*e0c4386eSCy Schubertopenssl x509 -in root-cert2.pem -trustout \ 33*e0c4386eSCy Schubert -addtrust clientAuth -out root2+clientAuth.pem 34*e0c4386eSCy Schubert# root-nonca trust variants: +serverAuth +anyEKU 35*e0c4386eSCy Schubertopenssl x509 -in root-nonca.pem -trustout \ 36*e0c4386eSCy Schubert -addtrust serverAuth -out nroot+serverAuth.pem 37*e0c4386eSCy Schubertopenssl x509 -in root-nonca.pem -trustout \ 38*e0c4386eSCy Schubert -addtrust anyExtendedKeyUsage -out nroot+anyEKU.pem 39*e0c4386eSCy Schubert 40*e0c4386eSCy Schubert# Root CA security level variants: 41*e0c4386eSCy Schubert# MD5 self-signature 42*e0c4386eSCy SchubertOPENSSL_SIGALG=md5 \ 43*e0c4386eSCy Schubert./mkcert.sh genroot "Root CA" root-key root-cert-md5 44*e0c4386eSCy Schubert# 768-bit key 45*e0c4386eSCy SchubertOPENSSL_KEYBITS=768 \ 46*e0c4386eSCy Schubert./mkcert.sh genroot "Root CA" root-key-768 root-cert-768 47*e0c4386eSCy Schubert 48*e0c4386eSCy Schubert# primary client-EKU root: croot-cert 49*e0c4386eSCy Schubert./mkcert.sh genroot "Root CA" root-key croot-cert clientAuth 50*e0c4386eSCy Schubert# trust variants: +serverAuth -serverAuth +clientAuth -clientAuth +anyEKU -anyEKU 51*e0c4386eSCy Schubertopenssl x509 -in croot-cert.pem -trustout \ 52*e0c4386eSCy Schubert -addtrust serverAuth -out croot+serverAuth.pem 53*e0c4386eSCy Schubertopenssl x509 -in croot-cert.pem -trustout \ 54*e0c4386eSCy Schubert -addreject serverAuth -out croot-serverAuth.pem 55*e0c4386eSCy Schubertopenssl x509 -in croot-cert.pem -trustout \ 56*e0c4386eSCy Schubert -addtrust clientAuth -out croot+clientAuth.pem 57*e0c4386eSCy Schubertopenssl x509 -in croot-cert.pem -trustout \ 58*e0c4386eSCy Schubert -addreject clientAuth -out croot-clientAuth.pem 59*e0c4386eSCy Schubertopenssl x509 -in croot-cert.pem -trustout \ 60*e0c4386eSCy Schubert -addtrust anyExtendedKeyUsage -out croot+anyEKU.pem 61*e0c4386eSCy Schubertopenssl x509 -in croot-cert.pem -trustout \ 62*e0c4386eSCy Schubert -addreject anyExtendedKeyUsage -out croot-anyEKU.pem 63*e0c4386eSCy Schubert 64*e0c4386eSCy Schubert# primary server-EKU root: sroot-cert 65*e0c4386eSCy Schubert./mkcert.sh genroot "Root CA" root-key sroot-cert serverAuth 66*e0c4386eSCy Schubert# trust variants: +serverAuth -serverAuth +clientAuth -clientAuth +anyEKU -anyEKU 67*e0c4386eSCy Schubertopenssl x509 -in sroot-cert.pem -trustout \ 68*e0c4386eSCy Schubert -addtrust serverAuth -out sroot+serverAuth.pem 69*e0c4386eSCy Schubertopenssl x509 -in sroot-cert.pem -trustout \ 70*e0c4386eSCy Schubert -addreject serverAuth -out sroot-serverAuth.pem 71*e0c4386eSCy Schubertopenssl x509 -in sroot-cert.pem -trustout \ 72*e0c4386eSCy Schubert -addtrust clientAuth -out sroot+clientAuth.pem 73*e0c4386eSCy Schubertopenssl x509 -in sroot-cert.pem -trustout \ 74*e0c4386eSCy Schubert -addreject clientAuth -out sroot-clientAuth.pem 75*e0c4386eSCy Schubertopenssl x509 -in sroot-cert.pem -trustout \ 76*e0c4386eSCy Schubert -addtrust anyExtendedKeyUsage -out sroot+anyEKU.pem 77*e0c4386eSCy Schubertopenssl x509 -in sroot-cert.pem -trustout \ 78*e0c4386eSCy Schubert -addreject anyExtendedKeyUsage -out sroot-anyEKU.pem 79*e0c4386eSCy Schubert 80*e0c4386eSCy Schubert# Primary intermediate ca: ca-cert 81*e0c4386eSCy Schubert./mkcert.sh genca "CA" ca-key ca-cert root-key root-cert 82*e0c4386eSCy Schubert# ca variants: CA:false, no bc, key2, DN2, issuer2, expired 83*e0c4386eSCy Schubert./mkcert.sh genee "CA" ca-key ca-nonca root-key root-cert 84*e0c4386eSCy Schubert./mkcert.sh gen_nonbc_ca "CA" ca-key ca-nonbc root-key root-cert 85*e0c4386eSCy Schubert./mkcert.sh genca "CA" ca-key2 ca-cert2 root-key root-cert 86*e0c4386eSCy Schubert./mkcert.sh genca "CA2" ca-key ca-name2 root-key root-cert 87*e0c4386eSCy Schubert./mkcert.sh genca "CA" ca-key ca-root2 root-key2 root-cert2 88*e0c4386eSCy SchubertDAYS=-1 ./mkcert.sh genca "CA" ca-key ca-expired root-key root-cert 89*e0c4386eSCy Schubert# trust variants: +serverAuth, -serverAuth, +clientAuth, -clientAuth 90*e0c4386eSCy Schubertopenssl x509 -in ca-cert.pem -trustout \ 91*e0c4386eSCy Schubert -addtrust serverAuth -out ca+serverAuth.pem 92*e0c4386eSCy Schubertopenssl x509 -in ca-cert.pem -trustout \ 93*e0c4386eSCy Schubert -addreject serverAuth -out ca-serverAuth.pem 94*e0c4386eSCy Schubertopenssl x509 -in ca-cert.pem -trustout \ 95*e0c4386eSCy Schubert -addtrust clientAuth -out ca+clientAuth.pem 96*e0c4386eSCy Schubertopenssl x509 -in ca-cert.pem -trustout \ 97*e0c4386eSCy Schubert -addreject clientAuth -out ca-clientAuth.pem 98*e0c4386eSCy Schubert# trust variants: +anyEKU, -anyEKU 99*e0c4386eSCy Schubertopenssl x509 -in ca-cert.pem -trustout \ 100*e0c4386eSCy Schubert -addtrust anyExtendedKeyUsage -out ca+anyEKU.pem 101*e0c4386eSCy Schubertopenssl x509 -in ca-cert.pem -trustout \ 102*e0c4386eSCy Schubert -addreject anyExtendedKeyUsage -out ca-anyEKU.pem 103*e0c4386eSCy Schubert# ca-nonca trust variants: +serverAuth, +anyEKU 104*e0c4386eSCy Schubertopenssl x509 -in ca-nonca.pem -trustout \ 105*e0c4386eSCy Schubert -addtrust serverAuth -out nca+serverAuth.pem 106*e0c4386eSCy Schubertopenssl x509 -in ca-nonca.pem -trustout \ 107*e0c4386eSCy Schubert -addtrust anyExtendedKeyUsage -out nca+anyEKU.pem 108*e0c4386eSCy Schubert 109*e0c4386eSCy Schubert# Intermediate CA security variants: 110*e0c4386eSCy Schubert# MD5 issuer signature, 111*e0c4386eSCy SchubertOPENSSL_SIGALG=md5 \ 112*e0c4386eSCy Schubert./mkcert.sh genca "CA" ca-key ca-cert-md5 root-key root-cert 113*e0c4386eSCy Schubertopenssl x509 -in ca-cert-md5.pem -trustout \ 114*e0c4386eSCy Schubert -addtrust anyExtendedKeyUsage -out ca-cert-md5-any.pem 115*e0c4386eSCy Schubert# Issuer has 768-bit key 116*e0c4386eSCy Schubert./mkcert.sh genca "CA" ca-key ca-cert-768i root-key-768 root-cert-768 117*e0c4386eSCy Schubert# CA has 768-bit key 118*e0c4386eSCy SchubertOPENSSL_KEYBITS=768 \ 119*e0c4386eSCy Schubert./mkcert.sh genca "CA" ca-key-768 ca-cert-768 root-key root-cert 120*e0c4386eSCy Schubert# EC cert with explicit curve 121*e0c4386eSCy Schubert./mkcert.sh genca "CA" ca-key-ec-explicit ca-cert-ec-explicit root-key root-cert 122*e0c4386eSCy Schubert# EC cert with named curve 123*e0c4386eSCy Schubert./mkcert.sh genca "CA" ca-key-ec-named ca-cert-ec-named root-key root-cert 124*e0c4386eSCy Schubert 125*e0c4386eSCy Schubert# client intermediate ca: cca-cert 126*e0c4386eSCy Schubert./mkcert.sh genca -p clientAuth "CA" ca-key cca-cert root-key root-cert 127*e0c4386eSCy Schubert# trust variants: +serverAuth, -serverAuth, +clientAuth, -clientAuth, +anyEKU, -anyEKU 128*e0c4386eSCy Schubertopenssl x509 -in cca-cert.pem -trustout \ 129*e0c4386eSCy Schubert -addtrust serverAuth -out cca+serverAuth.pem 130*e0c4386eSCy Schubertopenssl x509 -in cca-cert.pem -trustout \ 131*e0c4386eSCy Schubert -addreject serverAuth -out cca-serverAuth.pem 132*e0c4386eSCy Schubertopenssl x509 -in cca-cert.pem -trustout \ 133*e0c4386eSCy Schubert -addtrust clientAuth -out cca+clientAuth.pem 134*e0c4386eSCy Schubertopenssl x509 -in cca-cert.pem -trustout \ 135*e0c4386eSCy Schubert -addreject clientAuth -out cca-clientAuth.pem 136*e0c4386eSCy Schubertopenssl x509 -in cca-cert.pem -trustout \ 137*e0c4386eSCy Schubert -addtrust anyExtendedKeyUsage -out cca+anyEKU.pem 138*e0c4386eSCy Schubertopenssl x509 -in cca-cert.pem -trustout \ 139*e0c4386eSCy Schubert -addreject anyExtendedKeyUsage -out cca-anyEKU.pem 140*e0c4386eSCy Schubert 141*e0c4386eSCy Schubert# server intermediate ca: sca-cert 142*e0c4386eSCy Schubert./mkcert.sh genca -p serverAuth "CA" ca-key sca-cert root-key root-cert 143*e0c4386eSCy Schubert# trust variants: +serverAuth, -serverAuth, +clientAuth, -clientAuth, +anyEKU, -anyEKU 144*e0c4386eSCy Schubertopenssl x509 -in sca-cert.pem -trustout \ 145*e0c4386eSCy Schubert -addtrust serverAuth -out sca+serverAuth.pem 146*e0c4386eSCy Schubertopenssl x509 -in sca-cert.pem -trustout \ 147*e0c4386eSCy Schubert -addreject serverAuth -out sca-serverAuth.pem 148*e0c4386eSCy Schubertopenssl x509 -in sca-cert.pem -trustout \ 149*e0c4386eSCy Schubert -addtrust clientAuth -out sca+clientAuth.pem 150*e0c4386eSCy Schubertopenssl x509 -in sca-cert.pem -trustout \ 151*e0c4386eSCy Schubert -addreject clientAuth -out sca-clientAuth.pem 152*e0c4386eSCy Schubertopenssl x509 -in sca-cert.pem -trustout \ 153*e0c4386eSCy Schubert -addtrust anyExtendedKeyUsage -out sca+anyEKU.pem 154*e0c4386eSCy Schubertopenssl x509 -in sca-cert.pem -trustout \ 155*e0c4386eSCy Schubert -addreject anyExtendedKeyUsage -out sca-anyEKU.pem 156*e0c4386eSCy Schubert 157*e0c4386eSCy Schubert# Primary leaf cert: ee-cert with default purpose: serverAuth 158*e0c4386eSCy Schubert./mkcert.sh genee server.example ee-key ee-cert ca-key ca-cert 159*e0c4386eSCy Schubert# ee variants: expired, issuer-key2, issuer-name2, bad-pathlen 160*e0c4386eSCy Schubert./mkcert.sh genee server.example ee-key ee-expired ca-key ca-cert -days -1 161*e0c4386eSCy Schubert./mkcert.sh genee server.example ee-key ee-cert2 ca-key2 ca-cert2 162*e0c4386eSCy Schubert./mkcert.sh genee server.example ee-key ee-name2 ca-key ca-name2 163*e0c4386eSCy Schubert./mkcert.sh genee server.example ee-key ee-pathlen ca-key ca-cert \ 164*e0c4386eSCy Schubert -extfile <(echo "basicConstraints=CA:false,pathlen:0") # bash needed here 165*e0c4386eSCy Schubert# purpose variants: clientAuth 166*e0c4386eSCy Schubert./mkcert.sh genee -p clientAuth server.example ee-key ee-client ca-key ca-cert 167*e0c4386eSCy Schubert# trust variants: +serverAuth, -serverAuth, +clientAuth, -clientAuth 168*e0c4386eSCy Schubertopenssl x509 -in ee-cert.pem -trustout \ 169*e0c4386eSCy Schubert -addtrust serverAuth -out ee+serverAuth.pem 170*e0c4386eSCy Schubertopenssl x509 -in ee-cert.pem -trustout \ 171*e0c4386eSCy Schubert -addreject serverAuth -out ee-serverAuth.pem 172*e0c4386eSCy Schubertopenssl x509 -in ee-client.pem -trustout \ 173*e0c4386eSCy Schubert -addtrust clientAuth -out ee+clientAuth.pem 174*e0c4386eSCy Schubertopenssl x509 -in ee-client.pem -trustout \ 175*e0c4386eSCy Schubert -addreject clientAuth -out ee-clientAuth.pem 176*e0c4386eSCy Schubert 177*e0c4386eSCy Schubert# Leaf cert security level variants 178*e0c4386eSCy Schubert# MD5 issuer signature 179*e0c4386eSCy SchubertOPENSSL_SIGALG=md5 \ 180*e0c4386eSCy Schubert./mkcert.sh genee server.example ee-key ee-cert-md5 ca-key ca-cert 181*e0c4386eSCy Schubert# 768-bit issuer key 182*e0c4386eSCy Schubert./mkcert.sh genee server.example ee-key ee-cert-768i ca-key-768 ca-cert-768 183*e0c4386eSCy Schubert# 768-bit leaf key 184*e0c4386eSCy SchubertOPENSSL_KEYBITS=768 \ 185*e0c4386eSCy Schubert./mkcert.sh genee server.example ee-key-768 ee-cert-768 ca-key ca-cert 186*e0c4386eSCy Schubert# EC cert with explicit curve signed by named curve ca 187*e0c4386eSCy Schubert./mkcert.sh genee server.example ee-key-ec-explicit ee-cert-ec-explicit ca-key-ec-named ca-cert-ec-named 188*e0c4386eSCy Schubert# EC cert with named curve signed by explicit curve ca 189*e0c4386eSCy Schubert./mkcert.sh genee server.example ee-key-ec-named-explicit \ 190*e0c4386eSCy Schubert ee-cert-ec-named-explicit ca-key-ec-explicit ca-cert-ec-explicit 191*e0c4386eSCy Schubert# EC cert with named curve signed by named curve ca 192*e0c4386eSCy Schubert./mkcert.sh genee server.example ee-key-ec-named-named \ 193*e0c4386eSCy Schubert ee-cert-ec-named-named ca-key-ec-named ca-cert-ec-named 194*e0c4386eSCy Schubert# 1024-bit leaf key 195*e0c4386eSCy SchubertOPENSSL_KEYBITS=1024 \ 196*e0c4386eSCy Schubert./mkcert.sh genee server.example ee-key-1024 ee-cert-1024 ca-key ca-cert 197*e0c4386eSCy Schubert# 3072-bit leaf key 198*e0c4386eSCy SchubertOPENSSL_KEYBITS=3072 \ 199*e0c4386eSCy Schubert./mkcert.sh genee server.example ee-key-3072 ee-cert-3072 ca-key ca-cert 200*e0c4386eSCy Schubert# 4096-bit leaf key 201*e0c4386eSCy SchubertOPENSSL_KEYBITS=4096 \ 202*e0c4386eSCy Schubert./mkcert.sh genee server.example ee-key-4096 ee-cert-4096 ca-key ca-cert 203*e0c4386eSCy Schubert# 8192-bit leaf key 204*e0c4386eSCy SchubertOPENSSL_KEYBITS=8192 \ 205*e0c4386eSCy Schubert./mkcert.sh genee server.example ee-key-8192 ee-cert-8192 ca-key ca-cert 206*e0c4386eSCy Schubert 207*e0c4386eSCy Schubert# self-signed end-entity cert with explicit keyUsage not including KeyCertSign 208*e0c4386eSCy Schubertopenssl req -new -x509 -key ee-key.pem -subj /CN=ee-self-signed -out ee-self-signed.pem -addext keyUsage=digitalSignature -days 36525 209*e0c4386eSCy Schubert 210*e0c4386eSCy Schubert# Proxy certificates, off of ee-client 211*e0c4386eSCy Schubert# Start with some good ones 212*e0c4386eSCy Schubert./mkcert.sh req pc1-key "0.CN = server.example" "1.CN = proxy 1" | \ 213*e0c4386eSCy Schubert ./mkcert.sh genpc pc1-key pc1-cert ee-key ee-client \ 214*e0c4386eSCy Schubert "language = id-ppl-anyLanguage" "pathlen = 1" "policy = text:AB" 215*e0c4386eSCy Schubert./mkcert.sh req pc2-key "0.CN = server.example" "1.CN = proxy 1" "2.CN = proxy 2" | \ 216*e0c4386eSCy Schubert ./mkcert.sh genpc pc2-key pc2-cert pc1-key pc1-cert \ 217*e0c4386eSCy Schubert "language = id-ppl-anyLanguage" "pathlen = 0" "policy = text:AB" 218*e0c4386eSCy Schubert# And now a couple of bad ones 219*e0c4386eSCy Schubert# pc3: incorrect CN 220*e0c4386eSCy Schubert./mkcert.sh req bad-pc3-key "0.CN = server.example" "1.CN = proxy 3" | \ 221*e0c4386eSCy Schubert ./mkcert.sh genpc bad-pc3-key bad-pc3-cert pc1-key pc1-cert \ 222*e0c4386eSCy Schubert "language = id-ppl-anyLanguage" "pathlen = 0" "policy = text:AB" 223*e0c4386eSCy Schubert# pc4: incorrect pathlen 224*e0c4386eSCy Schubert./mkcert.sh req bad-pc4-key "0.CN = server.example" "1.CN = proxy 1" "2.CN = proxy 4" | \ 225*e0c4386eSCy Schubert ./mkcert.sh genpc bad-pc4-key bad-pc4-cert pc1-key pc1-cert \ 226*e0c4386eSCy Schubert "language = id-ppl-anyLanguage" "pathlen = 1" "policy = text:AB" 227*e0c4386eSCy Schubert# pc5: no policy 228*e0c4386eSCy Schubert./mkcert.sh req pc5-key "0.CN = server.example" "1.CN = proxy 1" "2.CN = proxy 5" | \ 229*e0c4386eSCy Schubert ./mkcert.sh genpc pc5-key pc5-cert pc1-key pc1-cert \ 230*e0c4386eSCy Schubert "language = id-ppl-anyLanguage" "pathlen = 0" 231*e0c4386eSCy Schubert# pc6: incorrect CN (made into a component of a multivalue RDN) 232*e0c4386eSCy Schubert./mkcert.sh req bad-pc6-key "0.CN = server.example" "1.CN = proxy 1" "2.+CN = proxy 6" | \ 233*e0c4386eSCy Schubert ./mkcert.sh genpc bad-pc6-key bad-pc6-cert pc1-key pc1-cert \ 234*e0c4386eSCy Schubert "language = id-ppl-anyLanguage" "pathlen = 0" "policy = text:AB" 235*e0c4386eSCy Schubert 236*e0c4386eSCy Schubert# Name constraints test certificates. 237*e0c4386eSCy Schubert 238*e0c4386eSCy Schubert# NC CA1 only permits the host www.good.org and *.good.com email address 239*e0c4386eSCy Schubert# good@good.org and *@good.com and IP addresses 127.0.0.1 and 240*e0c4386eSCy Schubert# 192.168.0.0/16 241*e0c4386eSCy Schubert 242*e0c4386eSCy SchubertNC="permitted;DNS:www.good.org, permitted;DNS:good.com," 243*e0c4386eSCy SchubertNC="$NC permitted;email:good@good.org, permitted;email:good.com," 244*e0c4386eSCy SchubertNC="$NC permitted;IP:127.0.0.1/255.255.255.255, permitted;IP:192.168.0.0/255.255.0.0" 245*e0c4386eSCy Schubert 246*e0c4386eSCy SchubertNC=$NC ./mkcert.sh genca "Test NC CA 1" ncca1-key ncca1-cert root-key root-cert 247*e0c4386eSCy Schubert 248*e0c4386eSCy Schubert# NC CA2 allows anything apart from hosts www.bad.org and *.bad.com 249*e0c4386eSCy Schubert# and email addresses bad@bad.org and *@bad.com 250*e0c4386eSCy Schubert 251*e0c4386eSCy SchubertNC="excluded;DNS:www.bad.org, excluded;DNS:bad.com," 252*e0c4386eSCy SchubertNC="$NC excluded;email:bad@bad.org, excluded;email:bad.com, " 253*e0c4386eSCy SchubertNC="$NC excluded;IP:10.0.0.0/255.0.0.0" 254*e0c4386eSCy Schubert 255*e0c4386eSCy SchubertNC=$NC ./mkcert.sh genca "Test NC CA 2" ncca2-key ncca2-cert root-key root-cert 256*e0c4386eSCy Schubert 257*e0c4386eSCy Schubert# Name constraints subordinate CA. Adds www.good.net (which should be 258*e0c4386eSCy Schubert# disallowed because parent CA doesn't permit it) adds ok.good.com 259*e0c4386eSCy Schubert# (which should be allowed because parent allows *.good.com 260*e0c4386eSCy Schubert# and now excludes bad.ok.good.com (allowed in permitted subtrees 261*e0c4386eSCy Schubert# but explicitly excluded). 262*e0c4386eSCy Schubert 263*e0c4386eSCy SchubertNC="permitted;DNS:www.good.net, permitted;DNS:ok.good.com, " 264*e0c4386eSCy SchubertNC="$NC excluded;DNS:bad.ok.good.com" 265*e0c4386eSCy SchubertNC=$NC ./mkcert.sh genca "Test NC sub CA" ncca3-key ncca3-cert \ 266*e0c4386eSCy Schubert ncca1-key ncca1-cert 267*e0c4386eSCy Schubert 268*e0c4386eSCy Schubert# all subjectAltNames allowed by CA1. Some CNs are not! 269*e0c4386eSCy Schubert 270*e0c4386eSCy Schubert./mkcert.sh req alt1-key "O = Good NC Test Certificate 1" \ 271*e0c4386eSCy Schubert "1.CN=www.example.net" "2.CN=Joe Bloggs" | \ 272*e0c4386eSCy Schubert ./mkcert.sh geneealt alt1-key alt1-cert ncca1-key ncca1-cert \ 273*e0c4386eSCy Schubert "DNS.1 = www.good.org" "DNS.2 = any.good.com" \ 274*e0c4386eSCy Schubert "email.1 = good@good.org" "email.2 = any@good.com" \ 275*e0c4386eSCy Schubert "IP = 127.0.0.1" "IP = 192.168.0.1" 276*e0c4386eSCy Schubert 277*e0c4386eSCy Schubert# all DNS-like CNs allowed by CA1, no DNS SANs. 278*e0c4386eSCy Schubert 279*e0c4386eSCy Schubert./mkcert.sh req goodcn1-key "O = Good NC Test Certificate 1" \ 280*e0c4386eSCy Schubert "1.CN=www.good.org" "2.CN=any.good.com" \ 281*e0c4386eSCy Schubert "3.CN=not..dns" "4.CN=not@dns" "5.CN=not-.dns" "6.CN=not.dns." | \ 282*e0c4386eSCy Schubert ./mkcert.sh geneealt goodcn1-key goodcn1-cert ncca1-key ncca1-cert \ 283*e0c4386eSCy Schubert "IP = 127.0.0.1" "IP = 192.168.0.1" 284*e0c4386eSCy Schubert 285*e0c4386eSCy Schubert# all DNS-like CNs allowed by CA1, no SANs 286*e0c4386eSCy Schubert 287*e0c4386eSCy Schubert./mkcert.sh req goodcn2-key "O = Good NC Test Certificate 1" \ 288*e0c4386eSCy Schubert "CN=www.good.org" | \ 289*e0c4386eSCy Schubert ./mkcert.sh geneeconfig goodcn2-key goodcn2-cert ncca1-key ncca1-cert 290*e0c4386eSCy Schubert 291*e0c4386eSCy Schubert# Some DNS-like CNs not permitted by CA1, no DNS SANs. 292*e0c4386eSCy Schubert 293*e0c4386eSCy Schubert./mkcert.sh req badcn1-key "O = Good NC Test Certificate 1" \ 294*e0c4386eSCy Schubert "1.CN=www.good.org" "3.CN=bad.net" | \ 295*e0c4386eSCy Schubert ./mkcert.sh geneealt badcn1-key badcn1-cert ncca1-key ncca1-cert \ 296*e0c4386eSCy Schubert "IP = 127.0.0.1" "IP = 192.168.0.1" 297*e0c4386eSCy Schubert 298*e0c4386eSCy Schubert# no subjectAltNames excluded by CA2. 299*e0c4386eSCy Schubert 300*e0c4386eSCy Schubert./mkcert.sh req alt2-key "O = Good NC Test Certificate 2" | \ 301*e0c4386eSCy Schubert ./mkcert.sh geneealt alt2-key alt2-cert ncca2-key ncca2-cert \ 302*e0c4386eSCy Schubert "DNS.1 = www.anything.org" "DNS.2 = any.other.com" \ 303*e0c4386eSCy Schubert "email.1 = other@bad.org" "email.2 = any@something.com" 304*e0c4386eSCy Schubert 305*e0c4386eSCy Schubert# hostname other.good.org which is not allowed by CA1. 306*e0c4386eSCy Schubert 307*e0c4386eSCy Schubert./mkcert.sh req badalt1-key "O = Bad NC Test Certificate 1" | \ 308*e0c4386eSCy Schubert ./mkcert.sh geneealt badalt1-key badalt1-cert ncca1-key ncca1-cert \ 309*e0c4386eSCy Schubert "DNS.1 = other.good.org" "DNS.2 = any.good.com" \ 310*e0c4386eSCy Schubert "email.1 = good@good.org" "email.2 = any@good.com" 311*e0c4386eSCy Schubert 312*e0c4386eSCy Schubert# any.bad.com is excluded by CA2. 313*e0c4386eSCy Schubert 314*e0c4386eSCy Schubert./mkcert.sh req badalt2-key 'O = Bad NC Test Certificate 2' | \ 315*e0c4386eSCy Schubert ./mkcert.sh geneealt badalt2-key badalt2-cert ncca2-key ncca2-cert \ 316*e0c4386eSCy Schubert "DNS.1 = www.good.org" "DNS.2 = any.bad.com" \ 317*e0c4386eSCy Schubert "email.1 = good@good.org" "email.2 = any@good.com" 318*e0c4386eSCy Schubert 319*e0c4386eSCy Schubert# other@good.org not permitted by CA1 320*e0c4386eSCy Schubert 321*e0c4386eSCy Schubert./mkcert.sh req badalt3-key "O = Bad NC Test Certificate 3" | \ 322*e0c4386eSCy Schubert ./mkcert.sh geneealt badalt3-key badalt1-cert ncca1-key ncca1-cert \ 323*e0c4386eSCy Schubert "DNS.1 = www.good.org" "DNS.2 = any.good.com" \ 324*e0c4386eSCy Schubert "email.1 = other@good.org" "email.2 = any@good.com" 325*e0c4386eSCy Schubert 326*e0c4386eSCy Schubert# all subject alt names OK but subject email address not allowed by CA1. 327*e0c4386eSCy Schubert 328*e0c4386eSCy Schubert./mkcert.sh req badalt4-key 'O = Bad NC Test Certificate 4' \ 329*e0c4386eSCy Schubert "emailAddress = any@other.com" | \ 330*e0c4386eSCy Schubert ./mkcert.sh geneealt badalt4-key badalt4-cert ncca1-key ncca1-cert \ 331*e0c4386eSCy Schubert "DNS.1 = www.good.org" "DNS.2 = any.good.com" \ 332*e0c4386eSCy Schubert "email.1 = good@good.org" "email.2 = any@good.com" 333*e0c4386eSCy Schubert 334*e0c4386eSCy Schubert# IP address not allowed by CA1 335*e0c4386eSCy Schubert./mkcert.sh req badalt5-key "O = Bad NC Test Certificate 5" | \ 336*e0c4386eSCy Schubert ./mkcert.sh geneealt badalt5-key badalt5-cert ncca1-key ncca1-cert \ 337*e0c4386eSCy Schubert "DNS.1 = www.good.org" "DNS.2 = any.good.com" \ 338*e0c4386eSCy Schubert "email.1 = good@good.org" "email.2 = any@good.com" \ 339*e0c4386eSCy Schubert "IP = 127.0.0.2" 340*e0c4386eSCy Schubert 341*e0c4386eSCy Schubert# No DNS-ID SANs and subject CN not allowed by CA1. 342*e0c4386eSCy Schubert./mkcert.sh req badalt6-key "O = Bad NC Test Certificate 6" \ 343*e0c4386eSCy Schubert "1.CN=other.good.org" "2.CN=Joe Bloggs" "3.CN=any.good.com" | \ 344*e0c4386eSCy Schubert ./mkcert.sh geneealt badalt6-key badalt6-cert ncca1-key ncca1-cert \ 345*e0c4386eSCy Schubert "email.1 = good@good.org" "email.2 = any@good.com" \ 346*e0c4386eSCy Schubert "IP = 127.0.0.1" "IP = 192.168.0.1" 347*e0c4386eSCy Schubert 348*e0c4386eSCy Schubert# No DNS-ID SANS and subject CN not allowed by CA1, BMPSTRING 349*e0c4386eSCy SchubertREQMASK=MASK:0x800 ./mkcert.sh req badalt7-key "O = Bad NC Test Certificate 7" \ 350*e0c4386eSCy Schubert "1.CN=other.good.org" "2.CN=Joe Bloggs" "3.CN=any.good.com" | \ 351*e0c4386eSCy Schubert ./mkcert.sh geneealt badalt7-key badalt7-cert ncca1-key ncca1-cert \ 352*e0c4386eSCy Schubert "email.1 = good@good.org" "email.2 = any@good.com" \ 353*e0c4386eSCy Schubert "IP = 127.0.0.1" "IP = 192.168.0.1" 354*e0c4386eSCy Schubert 355*e0c4386eSCy Schubert# all subjectAltNames allowed by chain 356*e0c4386eSCy Schubert 357*e0c4386eSCy Schubert./mkcert.sh req alt3-key "O = Good NC Test Certificate 3" \ 358*e0c4386eSCy Schubert "1.CN=www.ok.good.com" "2.CN=Joe Bloggs" | \ 359*e0c4386eSCy Schubert ./mkcert.sh geneealt alt3-key alt3-cert ncca3-key ncca3-cert \ 360*e0c4386eSCy Schubert "DNS.1 = www.ok.good.com" \ 361*e0c4386eSCy Schubert "email.1 = good@good.org" "email.2 = any@good.com" \ 362*e0c4386eSCy Schubert "IP = 127.0.0.1" "IP = 192.168.0.1" 363*e0c4386eSCy Schubert 364*e0c4386eSCy Schubert# www.good.net allowed by parent CA but not parent of parent 365*e0c4386eSCy Schubert 366*e0c4386eSCy Schubert./mkcert.sh req badalt8-key "O = Bad NC Test Certificate 8" \ 367*e0c4386eSCy Schubert "1.CN=www.good.com" "2.CN=Joe Bloggs" | \ 368*e0c4386eSCy Schubert ./mkcert.sh geneealt badalt8-key badalt8-cert ncca3-key ncca3-cert \ 369*e0c4386eSCy Schubert "DNS.1 = www.ok.good.com" "DNS.2 = www.good.net" \ 370*e0c4386eSCy Schubert "email.1 = good@good.org" "email.2 = any@good.com" \ 371*e0c4386eSCy Schubert "IP = 127.0.0.1" "IP = 192.168.0.1" 372*e0c4386eSCy Schubert 373*e0c4386eSCy Schubert# other.good.com not allowed by parent CA but allowed by parent of parent 374*e0c4386eSCy Schubert 375*e0c4386eSCy Schubert./mkcert.sh req badalt9-key "O = Bad NC Test Certificate 9" \ 376*e0c4386eSCy Schubert "1.CN=www.good.com" "2.CN=Joe Bloggs" | \ 377*e0c4386eSCy Schubert ./mkcert.sh geneealt badalt9-key badalt9-cert ncca3-key ncca3-cert \ 378*e0c4386eSCy Schubert "DNS.1 = www.good.com" "DNS.2 = other.good.com" \ 379*e0c4386eSCy Schubert "email.1 = good@good.org" "email.2 = any@good.com" \ 380*e0c4386eSCy Schubert "IP = 127.0.0.1" "IP = 192.168.0.1" 381*e0c4386eSCy Schubert 382*e0c4386eSCy Schubert# www.bad.net excluded by parent CA. 383*e0c4386eSCy Schubert 384*e0c4386eSCy Schubert./mkcert.sh req badalt10-key "O = Bad NC Test Certificate 10" \ 385*e0c4386eSCy Schubert "1.CN=www.ok.good.com" "2.CN=Joe Bloggs" | \ 386*e0c4386eSCy Schubert ./mkcert.sh geneealt badalt10-key badalt10-cert ncca3-key ncca3-cert \ 387*e0c4386eSCy Schubert "DNS.1 = www.ok.good.com" "DNS.2 = bad.ok.good.com" \ 388*e0c4386eSCy Schubert "email.1 = good@good.org" "email.2 = any@good.com" \ 389*e0c4386eSCy Schubert "IP = 127.0.0.1" "IP = 192.168.0.1" 390*e0c4386eSCy Schubert 391*e0c4386eSCy Schubert# Certs for CVE-2022-4203 testcase 392*e0c4386eSCy Schubert 393*e0c4386eSCy SchubertNC="excluded;otherName:SRVName;UTF8STRING:foo@example.org" ./mkcert.sh genca \ 394*e0c4386eSCy Schubert "Test NC CA othername" nccaothername-key nccaothername-cert \ 395*e0c4386eSCy Schubert root-key root-cert 396*e0c4386eSCy Schubert 397*e0c4386eSCy Schubert./mkcert.sh req alt-email-key "O = NC email in othername Test Certificate" | \ 398*e0c4386eSCy Schubert ./mkcert.sh geneealt bad-othername-key bad-othername-cert \ 399*e0c4386eSCy Schubert nccaothername-key nccaothername-cert \ 400*e0c4386eSCy Schubert "otherName.1 = SRVName;UTF8STRING:foo@example.org" 401*e0c4386eSCy Schubert 402*e0c4386eSCy Schubert# RSA-PSS signatures 403*e0c4386eSCy Schubert# SHA1 404*e0c4386eSCy Schubert./mkcert.sh genee PSS-SHA1 ee-key ee-pss-sha1-cert ca-key ca-cert \ 405*e0c4386eSCy Schubert -sha1 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:digest 406*e0c4386eSCy Schubert# EE SHA256 407*e0c4386eSCy Schubert./mkcert.sh genee PSS-SHA256 ee-key ee-pss-sha256-cert ca-key ca-cert \ 408*e0c4386eSCy Schubert -sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:digest 409*e0c4386eSCy Schubert# CA-PSS 410*e0c4386eSCy Schubert./mkcert.sh genca "CA-PSS" ca-pss-key ca-pss-cert root-key root-cert \ 411*e0c4386eSCy Schubert -sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:-1 412*e0c4386eSCy Schubert./mkcert.sh genee "EE-PSS" ee-key ee-pss-cert ca-pss-key ca-pss-cert \ 413*e0c4386eSCy Schubert -sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:-1 414*e0c4386eSCy Schubert# Should not have been possible to produce, see issue #13968: 415*e0c4386eSCy Schubert#./mkcert.sh genee "EE-PSS-wrong1.5" ee-key ee-pss-wrong1.5-cert ca-pss-key ca-pss-cert -sha256 416*e0c4386eSCy Schubert 417*e0c4386eSCy SchubertOPENSSL_KEYALG=ec OPENSSL_KEYBITS=brainpoolP256r1 ./mkcert.sh genee \ 418*e0c4386eSCy Schubert "Server ECDSA brainpoolP256r1 cert" server-ecdsa-brainpoolP256r1-key \ 419*e0c4386eSCy Schubert server-ecdsa-brainpoolP256r1-cert rootkey rootcert 420*e0c4386eSCy Schubert 421*e0c4386eSCy Schubertopenssl req -new -noenc -subj "/CN=localhost" \ 422*e0c4386eSCy Schubert -newkey rsa-pss -keyout server-pss-restrict-key.pem \ 423*e0c4386eSCy Schubert -pkeyopt rsa_pss_keygen_md:sha256 -pkeyopt rsa_pss_keygen_saltlen:32 | \ 424*e0c4386eSCy Schubert ./mkcert.sh geneenocsr "Server RSA-PSS restricted cert" \ 425*e0c4386eSCy Schubert server-pss-restrict-cert rootkey rootcert 426*e0c4386eSCy Schubert 427*e0c4386eSCy Schubert# CT entry 428*e0c4386eSCy Schubert./mkcert.sh genct server.example embeddedSCTs1-key embeddedSCTs1 embeddedSCTs1_issuer-key embeddedSCTs1_issuer ct-server-key 429*e0c4386eSCy Schubert 430*e0c4386eSCy SchubertOPENSSL_SIGALG= OPENSSL_KEYALG=ed448 ./mkcert.sh genroot "Root Ed448" \ 431*e0c4386eSCy Schubert root-ed448-key root-ed448-cert 432*e0c4386eSCy SchubertOPENSSL_SIGALG=ED448 OPENSSL_KEYALG=ed448 ./mkcert.sh genee ed448 \ 433*e0c4386eSCy Schubert server-ed448-key server-ed448-cert root-ed448-key root-ed448-cert 434*e0c4386eSCy Schubert 435*e0c4386eSCy Schubert# non-critical unknown extension 436*e0c4386eSCy Schubert./mkcert.sh geneeextra server.example ee-key ee-cert-noncrit-unknown-ext ca-key ca-cert "1.2.3.4=DER:05:00" 437*e0c4386eSCy Schubert 438*e0c4386eSCy Schubert# critical unknown extension 439*e0c4386eSCy Schubert./mkcert.sh geneeextra server.example ee-key ee-cert-crit-unknown-ext ca-key ca-cert "1.2.3.4=critical,DER:05:00" 440*e0c4386eSCy Schubert 441*e0c4386eSCy Schubert# critical id-pkix-ocsp-no-check extension 442*e0c4386eSCy Schubert./mkcert.sh geneeextra server.example ee-key ee-cert-ocsp-nocheck ca-key ca-cert "1.3.6.1.5.5.7.48.1.5=critical,DER:05:00" 443*e0c4386eSCy Schubert 444*e0c4386eSCy Schubert# certificatePolicies extension 445*e0c4386eSCy Schubert./mkcert.sh genca -c "1.3.6.1.4.1.16604.998855.1" "CA" ca-key ca-pol-cert root-key root-cert 446*e0c4386eSCy Schubert./mkcert.sh geneeextra server.example ee-key ee-cert-policies ca-key ca-cert "certificatePolicies=1.3.6.1.4.1.16604.998855.1" 447*e0c4386eSCy Schubert# We can create a cert with a duplicate policy oid - but its actually invalid! 448*e0c4386eSCy Schubert./mkcert.sh geneeextra server.example ee-key ee-cert-policies-bad ca-key ca-cert "certificatePolicies=1.3.6.1.4.1.16604.998855.1,1.3.6.1.4.1.16604.998855.1" 449