Created
June 21, 2019 09:26
-
-
Save jvanveen/9bb6121c3dfb60336f9d301768a1f1c9 to your computer and use it in GitHub Desktop.
Generate CA and Certificate for development
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z "$1" ]; then | |
echo -e "\nPlease call '$0 <domain-name>' to run this command!\n" | |
exit 1 | |
fi | |
PW=dummypw | |
CA=dev.ca | |
SUBJ="/C=NL/ST=City/L=City/O=My Company/OU=IT Department/CN=$1" | |
SUBJCA="/C=NL/ST=City/L=City/O=My Company/OU=IT Department/CN=My Company CA" | |
if [ ! -f "$CA.key" ]; then | |
echo "certificate authority not found; creating new one" | |
openssl genrsa -des3 -passout "pass:$PW" -out "$CA.key" 2048 | |
openssl req -x509 -new -nodes -key "$CA.key" -passin "pass:$PW" -sha256 -days 1825 -out "$CA.pem" -subj "$SUBJCA" | |
openssl x509 -outform der -in "$CA.pem" -out "$CA.crt" | |
# Add CA to system: | |
# Archlinux | |
if [ -f "/etc/arch-release" ]; then | |
echo "installing $CA.crt systemwide" | |
cp "$CA.crt" /etc/ca-certificates/trust-source/anchors | |
trust extract-compat | |
fi | |
fi | |
echo "creating certificate for $1" | |
openssl genrsa -out "$1.key" 2048 | |
openssl req -new -key "$1.key" -out "$1.csr" -subj "$SUBJ" | |
echo "authorityKeyIdentifier=keyid,issuer | |
basicConstraints=CA:FALSE | |
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment | |
subjectAltName = @alt_names | |
[alt_names] | |
DNS.1 = $1" >> "$1.ext" | |
openssl x509 -req -in "$1.csr" -passin "pass:$PW" -CA "$CA.pem" -CAkey "$CA.key" -CAcreateserial -out "$1.crt" -days 1825 -sha256 -extfile "$1.ext" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment