2020-11-29 23:08:05 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-12-05 18:48:34 +00:00
|
|
|
set -eu
|
|
|
|
|
|
|
|
COUNTRY_CODE=CH
|
|
|
|
ORGANIZATION="Acme Ltd."
|
|
|
|
|
|
|
|
if [ ! -d "example_ca" ]; then
|
|
|
|
mkdir -p example_ca/root/newcerts example_ca/sub/newcerts
|
|
|
|
touch example_ca/root/index.txt example_ca/sub/index.txt
|
2020-11-29 23:08:05 +00:00
|
|
|
umask 077
|
2020-12-05 18:48:34 +00:00
|
|
|
mkdir example_ca/root/private example_ca/sub/private
|
|
|
|
openssl req -new -x509 \
|
|
|
|
-config ca.cnf \
|
|
|
|
-keyout example_ca/root/private/ca.key.pem \
|
|
|
|
-newkey rsa:3072 \
|
|
|
|
-nodes \
|
|
|
|
-subj "/CN=Example Root CA/C=${COUNTRY_CODE}/O=${ORGANIZATION}" \
|
|
|
|
-utf8 \
|
|
|
|
-days 3650 \
|
|
|
|
-out example_ca/root/ca.crt.pem
|
|
|
|
chmod +r example_ca/root/ca.crt.pem
|
|
|
|
openssl req -new \
|
|
|
|
-config ca.cnf \
|
|
|
|
-keyout example_ca/sub/private/ca.key.pem \
|
|
|
|
-newkey rsa:3072 \
|
|
|
|
-nodes \
|
|
|
|
-subj "/CN=Example Sub CA/C=${COUNTRY_CODE}/O=${ORGANIZATION}" \
|
|
|
|
-utf8 \
|
|
|
|
-out example_ca/sub/ca.csr.pem
|
|
|
|
openssl ca \
|
|
|
|
-config ca.cnf \
|
|
|
|
-name rootca \
|
|
|
|
-in example_ca/sub/ca.csr.pem \
|
|
|
|
-extensions sub_ca \
|
|
|
|
-out example_ca/sub/ca.crt.pem \
|
|
|
|
-create_serial \
|
|
|
|
-batch
|
2020-11-29 23:08:05 +00:00
|
|
|
fi
|