Skip to content

Instantly share code, notes, and snippets.

@mshytikov
Created November 8, 2012 11:11
Show Gist options
  • Select an option

  • Save mshytikov/4038216 to your computer and use it in GitHub Desktop.

Select an option

Save mshytikov/4038216 to your computer and use it in GitHub Desktop.
get cert from remote server and install it to local machine
#!/bin/sh
#
# usage: install_cert.sh remote.host.name
# aggregated from:
# - http://stackoverflow.com/questions/699576/validating-parameters-to-a-bash-script
# - https://help.ubuntu.com/community/OpenSSL
# - http://www.madboa.com/geek/openssl/#cert-retrieve
die () {
echo >&2 "$@"
exit 1
}
REMHOST=$1
REMPORT=${2:-443}
CERT="$1.crt"
[ "$#" -eq 1 ] || die "1 argument required, $# provided"
openssl s_client -connect ${REMHOST}:${REMPORT} 2>&1 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ${CERT}
sudo cp $CERT /usr/share/ca-certificates/$CERT
sudo dpkg-reconfigure ca-certificates
sudo update-ca-certificates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment