Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
LOCATION=${1?Error: no location provided}
PASSPHRASE=${2?Error: no passphrase provided}
HOSTIP=${3?Error: no host ip provided}
openssl genrsa -aes256 -passout pass:$PASSPHRASE -out ca-key.pem 4096
openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem -passin pass:$PASSPHRASE -subj "/L=$LOCATION/CN=$HOSTNAME"
openssl genrsa -out server-key.pem 4096
openssl req -subj "/CN=$HOSTNAME" -sha256 -new -key server-key.pem -out server.csr
echo subjectAltName = DNS:$HOSTNAME,IP:$HOSTIP,IP: >> extfile.cnf
openssl x509 -req -days 365 -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out server-cert.pem -extfile extfile.cnf -passin pass:$PASSPHRASE
openssl genrsa -out key.pem 4096
openssl req -subj '/CN=client' -new -key key.pem -out client.csr
echo extendedKeyUsage = clientAuth >>clientextfile.cnf
openssl x509 -req -days 365 -sha256 -in client.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out cert.pem -extfile clientextfile.cnf -passin pass:$PASSPHRASE
rm -v client.csr server.csr extfile.cnf clientextfile.cnf
chmod -v 0400 ca.pem server-cert.pem server-key.pem
chmod -v 0444 ca.pem server-cert.pem cert.pem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.