Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergeycherepanov/1f43dcca03e2a07b6e05620bafab1db4 to your computer and use it in GitHub Desktop.
Save sergeycherepanov/1f43dcca03e2a07b6e05620bafab1db4 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [[ -z $1 ]]; then
echo "Domain name does not provided"
exit 1
fi
DOMAIN=$1
if cat "/usr/local/etc/openssl/localCA/index.txt" | grep ${DOMAIN}; then
echo "Domain already exists"
exit 0
fi
tee /usr/local/etc/openssl/localCA/${DOMAIN}.cnf << EOM
[ req ]
prompt = no
distinguished_name = server_distinguished_name
req_extensions = v3_req
[ server_distinguished_name ]
commonName = ${DOMAIN}
stateOrProvinceName = NSW
countryName = AU
emailAddress = root@localhost
organizationName = Localhost
organizationalUnitName = Local Development Environment
[ v3_req ]
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName = @alt_names
[ alt_names ]
DNS.0 = *.${DOMAIN}
DNS.1 = ${DOMAIN}
EOM
export OPENSSL_CONF="/usr/local/etc/openssl/localCA/${DOMAIN}.cnf"
openssl req -newkey rsa:2048 -keyout /usr/local/etc/openssl/localCA/private/${DOMAIN}_key.pem -keyform PEM -out /usr/local/etc/openssl/localCA/${DOMAIN}_req.pem -outform PEM -nodes
openssl rsa < /usr/local/etc/openssl/localCA/private/${DOMAIN}_key.pem > /usr/local/etc/openssl/localCA/private/${DOMAIN}_key_encrypted.pem
export OPENSSL_CONF="/usr/local/etc/openssl/localCA/caconfig.cnf"
openssl ca -batch -in /usr/local/etc/openssl/localCA/${DOMAIN}_req.pem -out /usr/local/etc/openssl/localCA/certs/${DOMAIN}_crt.pem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment