-
-
Save hernandesbsousa/6832038 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 | |
# | |
# Bash shell script for generating self-signed certs. Run this in a folder, as it | |
# generates a few files. Based on the following GIST Extract by Brad Landers: | |
# https://gist.github.com/bradland/1690807 | |
# | |
# Additional alterations by: Hernandes B. de Sousa | |
# Date: 2013-10-04 | |
# | |
# Script accepts a single argument, the fqdn for the cert | |
DOMAIN="$1" | |
COMPANY="$2" | |
if [ -z "$DOMAIN" ] || [ -z "$COMPANY" ]; then | |
echo "Usage: $(basename $0) <domain> <company>" | |
exit 11 | |
fi | |
fail_if_error() { | |
[ $1 != 0 ] && { | |
exit 10 | |
} | |
} | |
openssl genrsa -out $DOMAIN.key 4096; | |
fail_if_error $? | |
subj=" | |
C=BR | |
ST=SP | |
O=$COMPANY | |
localityName=Sao Paulo | |
commonName=$DOMAIN | |
emailAddress=admin@example.com | |
" | |
openssl req \ | |
-new \ | |
-batch \ | |
-subj "$(echo -n "$subj" | tr "\n" "/")" \ | |
-key $DOMAIN.key \ | |
-out $DOMAIN.csr | |
fail_if_error $? | |
openssl x509 -req -days 3650 -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