Skip to content

Instantly share code, notes, and snippets.

@stef
Created March 31, 2011 01:05
Show Gist options
  • Save stef/895630 to your computer and use it in GitHub Desktop.
Save stef/895630 to your computer and use it in GitHub Desktop.
downloads and caches ssl certificates
#!/bin/bash
BASEDIR="$HOME/.ssl"
function get {
echo | openssl s_client -showcerts -connect "$1":"$2" 2>/dev/null
}
function md5 {
openssl x509 -md5 -fingerprint -noout
}
function sha1 {
openssl x509 -sha1 -fingerprint -noout
}
function cert {
openssl x509 -in "$BASEDIR/$1:$2"
}
function store {
f=`mktemp`
get "$1" "$2" | egrep -v '^\s*(Session-ID:|Master-Key:|Start Time:).*' | head -n -2 >"$f"
fname="$BASEDIR/$1:$2"
diff "$f" "$fname" >/dev/null 2>&1 || {
[[ -f "$fname" ]] && cp "$fname" "$fname.$(date +%s)"
mv "$f" "$fname"
}
}
store "$1" "$2"
egrep "^(issuer|subject)=" "$BASEDIR/$1:$2"
cert "$1" "$2" | md5
cert "$1" "$2" | sha1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment