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