Skip to content

Instantly share code, notes, and snippets.

@lapo-luchini
Created October 5, 2021 23:37
Show Gist options
  • Save lapo-luchini/6f596a9287fe5100b9f26728f9163c1e to your computer and use it in GitHub Desktop.
Save lapo-luchini/6f596a9287fe5100b9f26728f9163c1e to your computer and use it in GitHub Desktop.
A script to create a local CA for you zrepl installation. Uses elliptic curves and SANs to be compatible with latest go.
#!/bin/sh
if [ $# -ne 1 ]; then
echo "Usage: $0 FQDN"
exit 1
fi
cd `dirname "$0"`
if [ ! -f ca.crt ]; then
openssl ecparam -genkey -name prime256v1 -out ca.key
openssl req -x509 -new -SHA256 -nodes -days 3652 -subj "/CN=Root CA/OU=zrepl/O=YourName/C=IT" -key ca.key -out ca.crt
fi
if [ ! -f "$1.key" ]; then
openssl ecparam -genkey -name prime256v1 -out "$1.key"
fi
printf "[SAN]\nsubjectAltName=DNS:$1\n" > "$1.san"
openssl req -new -SHA256 -nodes -subj "/CN=$1/OU=zrepl/O=YourName/C=IT" -key "$1.key" -out "$1.csr"
openssl x509 -req -SHA256 -days 3652 -extfile "$1.san" -extensions SAN -in "$1.csr" -CA ca.crt -CAkey ca.key -CAcreateserial -out "$1.crt"
rm ca.srl "$1.csr" "$1.san"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment