Last active
October 8, 2022 17:47
-
-
Save csprabala/505964760aa714f1264b10f0cd622bed to your computer and use it in GitHub Desktop.
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 | |
HOSTNAME="*.internal.cloudapp.net" | |
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:127.0.0.1 >> 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