Skip to content

Instantly share code, notes, and snippets.

@ironsmile
Last active December 10, 2015 19:58
Show Gist options
  • Save ironsmile/4485041 to your computer and use it in GitHub Desktop.
Save ironsmile/4485041 to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ $# -lt 1 ]
then
echo "Usage: $0 remote.host.name [port]"
exit 1
fi
REMHOST=$1
REMPORT=${2:-443}
echo "Downloading certificate from ${REMHOST}:${REMPORT}..."
echo | openssl s_client -connect ${REMHOST}:${REMPORT} 2>&1 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /tmp/$REMHOST
echo "Adding certificate to ${HOME}/.pki/nssdb..."
certutil -d sql:$HOME/.pki/nssdb -A -t "C,," -n "$REMHOST" -i /tmp/$REMHOST
echo "Cleaning up..."
rm /tmp/$REMHOST
echo "Done"
# Get cert NotAfter date:
# echo | openssl s_client -connect my.ucdn.com:443 2>&1 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | openssl x509 -inform PEM -enddate -noout | cut -c 10-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment