Created
December 2, 2012 05:32
-
-
Save trentster/4187118 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 | |
DOMAIN="$1" | |
if [ -z "$DOMAIN" ]; then | |
echo "Usage: $(basename $0) <domain>" | |
exit 11 | |
fi | |
fail_if_error() { | |
[ $1 != 0 ] && { | |
unset PASSPHRASE | |
exit 10 | |
} | |
} | |
export PASSPHRASE=$(head -c 128 /dev/random | uuencode - | grep -v "^end" | tr "\n" "d") | |
subj=" | |
C=AU | |
ST=Victoria | |
O=Company | |
localityName=Melbourne | |
commonName=$DOMAIN | |
organizationalUnitName=Widgets | |
[email protected] | |
" | |
openssl genrsa -des3 -out $DOMAIN.key -passout env:PASSPHRASE 2048 | |
fail_if_error $? | |
openssl req \ | |
-new \ | |
-batch \ | |
-subj "$(echo -n "$subj" | tr "\n" "/")" \ | |
-key $DOMAIN.key \ | |
-out $DOMAIN.csr \ | |
-passin env:PASSPHRASE | |
fail_if_error $? | |
cp $DOMAIN.key $DOMAIN.key.org | |
fail_if_error $? | |
openssl rsa -in $DOMAIN.key.org -out $DOMAIN.key -passin env:PASSPHRASE | |
fail_if_error $? | |
openssl x509 -req -days 365 -in $DOMAIN.csr -signkey $DOMAIN.key -out $DOMAIN.crt | |
fail_if_error $? | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment