Last active
April 24, 2021 15:30
-
-
Save Sascha-T/c61ac7b764ec9cadd560a8ccc63773dc 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
function pause(){ | |
clear | |
} | |
rm *.pem | |
rm ca.srl | |
read -p "Enter hostname: " HOST | |
echo Creating key... | |
openssl genrsa -aes256 -out ca-key.pem 4096 | |
pause | |
echo Enter CA passphrase | |
openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem | |
openssl genrsa -out server-key.pem 4096 | |
openssl req -subj "/CN=$HOST" -sha256 -new -key server-key.pem -out server.csr | |
pause | |
echo Please enter the hosts for the certificate | |
echo in the format of: "IP:X,IP:X" | |
read -p "HOSTS: " HOSTS | |
echo subjectAltName = DNS:$HOST,$HOSTS >> extfile.cnf | |
echo extendedKeyUsage = serverAuth >> extfile.cnf | |
pause | |
echo Enter CA passphrase | |
openssl x509 -req -days 365 -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem \ | |
-CAcreateserial -out server-cert.pem -extfile extfile.cnf | |
openssl genrsa -out key.pem 4096 | |
openssl req -subj '/CN=client' -new -key key.pem -out client.csr | |
echo extendedKeyUsage = clientAuth > extfile-client.cnf | |
pause | |
echo Enter CA passphrase | |
openssl x509 -req -days 365 -sha256 -in client.csr -CA ca.pem -CAkey ca-key.pem \ | |
-CAcreateserial -out cert.pem -extfile extfile-client.cnf | |
pause | |
echo Finishing setup... | |
rm -v client.csr server.csr extfile.cnf extfile-client.cnf | |
chmod -v 0400 ca-key.pem key.pem server-key.pem | |
chmod -v 0444 ca.pem server-cert.pem cert.pem | |
echo Done! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment