Skip to content

Instantly share code, notes, and snippets.

@ntrp
Created May 10, 2016 08:17
Show Gist options
  • Save ntrp/76a023c4e2734ea83353afddf9470c5b to your computer and use it in GitHub Desktop.
Save ntrp/76a023c4e2734ea83353afddf9470c5b to your computer and use it in GitHub Desktop.
#!/bin/bash
function usage {
echo
echo "usage: trustcert <ALIAS> <FILE>"
echo
}
[[ $# -ne 2 ]] && usage && exit 1
if [[ "$2" =~ ^https://.* ]]; then
url="${2/https:\/\//}"
if [[ ! $url =~ ^.*:\d+$ ]]; then
url="$url:443"
fi
echo $url
openssl s_client -showcerts -connect $url < /dev/null | openssl x509 -outform DER > /tmp/cert.der
file="/tmp/cert.der"
else
file=$2
fi
certutil -d sql:$HOME/.pki/nssdb -A -t "CP,," -n $1 -i $file
certutil -d sql:$HOME/.pki/nssdb -L
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment