Skip to content

Instantly share code, notes, and snippets.

@samdfonseca
Last active October 18, 2016 16:19
Show Gist options
  • Save samdfonseca/aabc718377566892c0bf4afa34047587 to your computer and use it in GitHub Desktop.
Save samdfonseca/aabc718377566892c0bf4afa34047587 to your computer and use it in GitHub Desktop.
Whitelist self-signed certs on OS X
#!/usr/bin/env bash -e
SERVERNAME=$(echo "$1" | sed -E -e 's/https?:\/\///' -e 's/\/.*//')
echo "$SERVERNAME"
if [[ "$SERVERNAME" =~ .*\..* ]]; then
echo "Adding certificate for $SERVERNAME"
echo -n | openssl s_client -connect $SERVERNAME:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | tee /tmp/$SERVERNAME.cert
sudo security add-trusted-cert -d -r trustRoot -k "$HOME/Library/Keychains/login.keychain" /tmp/$SERVERNAME.cert
else
echo "Usage: $0 www.site.name"
echo "http:// and such will be stripped automatically"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment