hickory-dns/scripts/gen_certs.sh

87 lines
1.8 KiB
Bash
Raw Normal View History

2017-04-06 07:08:43 +00:00
# !/bin/bash
set -e
OPENSSL=/usr/local/opt/openssl/bin/openssl
trust_dns_dir=$(dirname $0)/..
2019-04-09 12:36:20 +00:00
pushd $trust_dns_dir/tests/test-data
2017-04-06 07:08:43 +00:00
2017-04-21 06:03:52 +00:00
for i in ca.key ca.pem cert-key.pem cert.csr cert.pem cert.p12 ; do
2017-04-06 07:08:43 +00:00
[ -f $i ] && echo "$i exists" && exit 1;
done
echo
cat <<-EOF > /tmp/ca.conf
[req]
prompt = no
req_extensions = req_ext
distinguished_name = dn
[dn]
C = US
ST = California
L = San Francisco
2019-01-27 21:09:04 +00:00
O = Trust-DNS
2017-04-06 07:08:43 +00:00
CN = root.example.com
[req_ext]
2017-04-07 05:53:09 +00:00
basicConstraints = CA:TRUE
2017-04-06 07:08:43 +00:00
subjectAltName = @alt_names
[alt_names]
DNS.1 = root.example.com
EOF
# CA
echo "----> Generating CA <----"
${OPENSSL:?} genrsa -out ca.key 4096
2017-04-07 05:53:09 +00:00
${OPENSSL:?} req -x509 -new -nodes -key ca.key -days 365 -out ca.pem -verify -config /tmp/ca.conf
${OPENSSL:?} x509 -in ca.pem -out ca.der -outform der
2017-04-06 07:08:43 +00:00
cat <<-EOF > /tmp/cert.conf
[req]
prompt = no
req_extensions = req_ext
distinguished_name = dn
[dn]
C = US
ST = California
L = San Francisco
2019-01-27 21:09:04 +00:00
O = Trust-DNS
2017-04-06 07:08:43 +00:00
CN = ns.example.com
[req_ext]
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = ns.example.com
EOF
# Cert
echo "----> Generating CERT <----"
2017-04-21 06:03:52 +00:00
${OPENSSL:?} genrsa -out cert-key.pem 4096
${OPENSSL:?} req -new -nodes -key cert-key.pem -out cert.csr \
2017-04-06 07:08:43 +00:00
-verify \
-config /tmp/cert.conf
2019-04-09 12:36:20 +00:00
${OPENSSL:?} x509 -in ca.pem -inform pem -pubkey -noout > ca.pubkey
2017-04-06 07:08:43 +00:00
echo "----> Signing Cert <----"
${OPENSSL:?} x509 -req -days 365 -in cert.csr -CA ca.pem -CAkey ca.key -set_serial 0x8771f7bdee982fa6 -out cert.pem -extfile /tmp/cert.conf -extensions req_ext
2017-04-07 05:53:09 +00:00
echo "----> Verifying Cert <----"
${OPENSSL:?} verify -CAfile ca.pem cert.pem
2017-04-06 07:08:43 +00:00
echo "----> Createing PCKS12 <----"
2017-04-21 06:03:52 +00:00
${OPENSSL:?} pkcs12 -export -inkey cert-key.pem -in cert.pem -out cert.p12 -passout pass:mypass -name ns.example.com -chain -CAfile ca.pem
2017-04-06 07:08:43 +00:00
2017-04-07 05:53:09 +00:00
2017-04-06 07:08:43 +00:00
popd