Skip to content

Instantly share code, notes, and snippets.

@hughe
Last active May 10, 2017 04:04
Show Gist options
  • Save hughe/236c9f4dd10399b0e2dc53851154880f to your computer and use it in GitHub Desktop.
Save hughe/236c9f4dd10399b0e2dc53851154880f to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -o errexit -o pipefail -o nounset
ROOT="root"
if [[ -f "$ROOT.key" || -f "$ROOT.crt" ]]; then
echo "Root certificate already exist"
exit 1
fi
# generate a CA in
openssl req -new -newkey rsa:2048 -sha256 -days 3650 -x509 -extensions v3_ca -keyout "$ROOT.key" -out "$ROOT.crt"
#!/usr/bin/env bash
set -o errexit -o pipefail -o nounset
if [[ "$#" -ne 1 ]]; then
echo "Usage: $0 <domain>"
exit 1
fi
DOMAIN="$1"
NAME="$DOMAIN"
ROOT="root"
# generate private key
openssl genrsa -out "$NAME.key" 2048
# generate signing request
openssl req -new -sha256 -key "$NAME.key" -out "$NAME.csr"
# generate public certificate
openssl x509 -req -days 3650 -in "$NAME.csr" -CA "$ROOT.crt" -CAkey "$ROOT.key" -CAcreateserial -out "$NAME.crt"
# remove signing request
rm "$NAME.csr"
# generate packed pem file for Caddy (it contains the certificate and
# private key)
cat "$NAME.crt" "$NAME.key" > "$NAME.packed.pem"
# generate a bundle file for StorReduce and most webservers (it
# contains the certificate and the CA certificate)
cat "$NAME.crt" "$ROOT.crt" > "$NAME.bundle.pem"
@hughe
Copy link
Author

hughe commented May 10, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment