Skip to content

Instantly share code, notes, and snippets.

@cmittendorf
Created April 22, 2011 08:41
Show Gist options
  • Save cmittendorf/936284 to your computer and use it in GitHub Desktop.
Save cmittendorf/936284 to your computer and use it in GitHub Desktop.
get the cert from a ssl connection for importing into a keystore
#!/bin/sh
#
# usage: retrieve-cert.sh remote.host.name [port]
#
if [ $# -eq 0 -o $# -gt 2 ]; then
echo `basename $0`" <host> <port:443>"
exit
fi
REMHOST=$1
REMPORT=${2:-443}
echo |\
openssl s_client -connect ${REMHOST}:${REMPORT} 2>&1 |\
sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment