Skip to content

Instantly share code, notes, and snippets.

@webdev
Created July 13, 2015 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webdev/7e24ea6235cea6c2bffe to your computer and use it in GitHub Desktop.
Save webdev/7e24ea6235cea6c2bffe to your computer and use it in GitHub Desktop.
Self-signed Certificate
# https://gist.github.com/jessedearing/2351836
function check_ssl_cert() {
local hostname=$1
local ssl_dir=/etc/travis/ssl
local ssl_name=${hostname//./_}
local ssl_path=$ssl_dir/$ssl_name
mkdir -p $ssl_dir
if [[ -f $ssl_path.key || -f $ssl_path.bundle ]]; then
if [ ! -f $ssl_path.key ] || [ ! -f $ssl_path.bundle ]; then
echo "Error: Found some, but not all of the required crt, key files at $ssl_path.*"
exit 1
fi
else
echo "No custom certificate found in $ssl_dir. Generating a self-signed certificate ..."
generate_ssl_cert $hostname
mv $ssl_name* $ssl_dir
echo
fi
}
function generate_ssl_cert() {
local domain=$1
local name=${domain//./_}
local csr=$name.csr
local key=$name.key
local crt=$name.bundle
[ -z "$domain" ] && echo "Fatal: No domain name specified." && exit 1
rm -f $csr $key $crt
echo "Generating SSL key ..."
openssl genrsa -des3 -passout pass:passphrase -out $key 1024 # > /dev/null 2>&1
echo "Generating a Certificate Signing Request ..."
openssl req -new -key $key -passin pass:passphrase -out $csr -subj "/C=DE/ST=Germany/L=Berlin/O=Travis CI GmbH/CN=$domain" # > /dev/null 2>&1
echo "Removing passphrase from key ..."
cp $key $key.org
openssl rsa -in $key.org -passin pass:passphrase -out $key # > /dev/null 2>&1
rm $key.org
echo "Generating certificate ..."
openssl x509 -req -in $csr -signkey $key -out $crt -days 3650 # > /dev/null 2>&1
rm $csr
echo "Done."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment