Path: blob/main/crypto/krb5/src/tests/pkinit-certs/make-certs.sh
34889 views
#!/bin/sh -e12NAMETYPE=13KRBTGT_NAMETYPE=24KEYSIZE=20485DAYS=40006REALM=KRBTEST.COM7LOWREALM=krbtest.com8KRB5_PRINCIPAL_SAN=1.3.6.1.5.2.29KRB5_UPN_SAN=1.3.6.1.4.1.311.20.2.310PKINIT_KDC_EKU=1.3.6.1.5.2.3.511PKINIT_CLIENT_EKU=1.3.6.1.5.2.3.412TLS_SERVER_EKU=1.3.6.1.5.5.7.3.113TLS_CLIENT_EKU=1.3.6.1.5.5.7.3.214EMAIL_PROTECTION_EKU=1.3.6.1.5.5.7.3.415# Add TLS EKUs to these if we're testing with NSS and we still have to16# piggy-back on the TLS trust settings.17KDC_EKU_LIST=$PKINIT_KDC_EKU18CLIENT_EKU_LIST=$PKINIT_CLIENT_EKU1920cat > openssl.cnf << EOF21[req]22prompt = no23distinguished_name = \$ENV::SUBJECT2425[ca]26CN = test CA certificate27C = US28ST = Massachusetts29L = Cambridge30O = MIT31OU = Insecure PKINIT Kerberos test CA32CN = pkinit test suite CA; do not use otherwise3334[kdc]35C = US36ST = Massachusetts37O = KRBTEST.COM38CN = KDC3940[user]41C = US42ST = Massachusetts43O = KRBTEST.COM44CN = user4546[exts_ca]47subjectKeyIdentifier = hash48authorityKeyIdentifier = keyid:always,issuer:always49keyUsage = nonRepudiation,digitalSignature,keyEncipherment,dataEncipherment,keyAgreement,keyCertSign,cRLSign50basicConstraints = critical,CA:TRUE5152[components_kdc]530.component=GeneralString:krbtgt541.component=GeneralString:$REALM5556[princ_kdc]57nametype=EXPLICIT:0,INTEGER:$KRBTGT_NAMETYPE58components=EXPLICIT:1,SEQUENCE:components_kdc5960[krb5princ_kdc]61realm=EXPLICIT:0,GeneralString:$REALM62princ=EXPLICIT:1,SEQUENCE:princ_kdc6364[exts_kdc]65subjectKeyIdentifier = hash66authorityKeyIdentifier = keyid:always,issuer:always67keyUsage = nonRepudiation,digitalSignature,keyEncipherment,keyAgreement68basicConstraints = critical,CA:FALSE69subjectAltName = otherName:$KRB5_PRINCIPAL_SAN;SEQUENCE:krb5princ_kdc70extendedKeyUsage = $KDC_EKU_LIST7172[components_client]73component=GeneralString:user7475[princ_client]76nametype=EXPLICIT:0,INTEGER:$NAMETYPE77components=EXPLICIT:1,SEQUENCE:components_client7879[krb5princ_client]80realm=EXPLICIT:0,GeneralString:$REALM81princ=EXPLICIT:1,SEQUENCE:princ_client8283[exts_client]84subjectKeyIdentifier = hash85authorityKeyIdentifier = keyid:always,issuer:always86keyUsage = nonRepudiation,digitalSignature,keyEncipherment,keyAgreement87basicConstraints = critical,CA:FALSE88subjectAltName = otherName:$KRB5_PRINCIPAL_SAN;SEQUENCE:krb5princ_client89extendedKeyUsage = $CLIENT_EKU_LIST9091[exts_upn_client]92subjectKeyIdentifier = hash93authorityKeyIdentifier = keyid:always,issuer:always94keyUsage = nonRepudiation,digitalSignature,keyEncipherment,keyAgreement95basicConstraints = critical,CA:FALSE96subjectAltName = otherName:$KRB5_UPN_SAN;UTF8:user@$LOWREALM97extendedKeyUsage = $CLIENT_EKU_LIST9899[exts_upn2_client]100subjectKeyIdentifier = hash101authorityKeyIdentifier = keyid:always,issuer:always102keyUsage = nonRepudiation,digitalSignature,keyEncipherment,keyAgreement103basicConstraints = critical,CA:FALSE104subjectAltName = otherName:$KRB5_UPN_SAN;UTF8:user105extendedKeyUsage = $CLIENT_EKU_LIST106107[exts_upn3_client]108subjectKeyIdentifier = hash109authorityKeyIdentifier = keyid:always,issuer:always110keyUsage = nonRepudiation,digitalSignature,keyEncipherment,keyAgreement111basicConstraints = critical,CA:FALSE112subjectAltName = otherName:$KRB5_UPN_SAN;UTF8:user@$REALM113extendedKeyUsage = $CLIENT_EKU_LIST114115[exts_none]116EOF117118# Generate an RSA private key and a password-protected PEM file for it..119openssl genrsa $KEYSIZE > privkey.pem120openssl rsa -in privkey.pem -out privkey-enc.pem -des3 -passout pass:encrypted121122# Generate an EC private key.123openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 > eckey.pem124125# Generate a "CA" certificate.126SUBJECT=ca openssl req -config openssl.cnf -new -x509 -extensions exts_ca \127-set_serial 1 -days $DAYS -key privkey.pem -out ca.pem128129serial=2130gen_cert() {131keyfile=${4-privkey.pem}132SUBJECT=$1 openssl req -config openssl.cnf -new -key $keyfile -out csr133SUBJECT=$1 openssl x509 -extfile openssl.cnf -extensions $2 \134-set_serial $serial -days $DAYS -req -CA ca.pem -CAkey privkey.pem \135-in csr -out $3136serial=$((serial + 1))137rm -f csr138}139140gen_pkcs12() {141# Use -descert to make OpenSSL 1.1 generate files OpenSSL 3.0 can142# read (the default uses RC2, which is only available in the143# legacy provider in OpenSSL 3). This option causes an algorithm144# downgrade with OpenSSL 3.0 (AES to DES3), but that isn't145# important for test certs.146openssl pkcs12 -export -descert -in "$1" -inkey privkey.pem -out "$2" \147-passout pass:"$3"148}149150# Generate a KDC certificate.151gen_cert kdc exts_kdc kdc.pem152153# Generate a client certificate and PKCS#12 bundles.154gen_cert user exts_client user.pem155gen_pkcs12 user.pem user.p12156gen_pkcs12 user.pem user-enc.p12 encrypted157158# Generate an EC client certificate.159gen_cert user exts_client ecuser.pem eckey.pem160161# Generate a client certificate and PKCS#12 bundle with a UPN SAN.162gen_cert user exts_upn_client user-upn.pem163gen_pkcs12 user-upn.pem user-upn.p12164165# Same, but with no realm in the UPN SAN.166gen_cert user exts_upn2_client user-upn2.pem167gen_pkcs12 user-upn2.pem user-upn2.p12168169# Same, but with an uppercase realm in the UPN SAN.170gen_cert user exts_upn3_client user-upn3.pem171gen_pkcs12 user-upn3.pem user-upn3.p12172173# Generate a client certificate and PKCS#12 bundle with no PKINIT extensions.174gen_cert user exts_none generic.pem175gen_pkcs12 generic.pem generic.p12176177# Clean up.178rm -f openssl.cnf179180181