Skip to content

Instantly share code, notes, and snippets.

@wookietreiber
Last active December 19, 2015 21:29
Show Gist options
  • Save wookietreiber/6020822 to your computer and use it in GitHub Desktop.
Save wookietreiber/6020822 to your computer and use it in GitHub Desktop.
Downloads an SSL certificate and imports it into a Java keystore.
#!/bin/bash
KT_HOST=${KT_HOST:-$1}
KT_PORT=${KT_PORT:-${2:-443}}
KT_ALIAS=$KT_HOST:$KT_PORT
KT_STORE=${KT_STORE:-$3}
[[ -z $KT_HOST ]] && {
echo "usage: $(basename $0) host [port] [store]" > /dev/stderr
exit 1
}
dump_certificate() {
echo | openssl s_client -showcerts -connect $KT_ALIAS
}
keytool -import -alias $KT_ALIAS -file <(dump_certificate) ${KT_STORE:+-keystore $KT_STORE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment