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