#! /bin/sh # This script generates a private key/certificate for a server, and signs it with the provided CA key # based on https://docs.ntpd-rs.pendulum-project.org/development/ca/ # Because this script generate keys without passwords set, they should only be used in a development setting. if [ -z "$1" ]; then echo "usage: gen-cert.sh name-of-server [ca-name]" echo echo "This will generate a name-of-server.key, name-of-server.pem and name-of-server.chain.pem file" echo "containing the private key, public certificate, and full certificate chain (respectively)" echo echo "The second argument denotes the name of the CA be used (found in the files ca-name.key and ca-name.pem)" echo "If this is omitted, the name 'testca' will be used." exit fi NAME="${1:-ntpd-rs.test}" CA="${2:-testca}" # generate a key openssl genrsa -out "$NAME".key 2048 # generate a certificate signing request openssl req -batch -new -key "$NAME".key -out "$NAME".csr # generate an ext file cat >> "$NAME".ext < "$NAME".chain.pem # cleanup rm "$NAME".csr