Created
February 17, 2019 04:08
-
-
Save ReeganExE/d718ca2857770faf39c218c4523e327c to your computer and use it in GitHub Desktop.
Import Certificate from websites to a Java keystore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# Change this | |
KEYSTORE_FILE=dest_keystore | |
KEYSTORE_PASS=changeit | |
import_cert() { | |
local HOST=$1 | |
local PORT=$2 | |
# get the SSL certificate | |
openssl s_client -connect ${HOST}:${PORT} </dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ${HOST}.cert | |
# delete the old alias and then import the new one | |
keytool -delete -keystore ${KEYSTORE_FILE} -storepass ${KEYSTORE_PASS} -alias ${HOST} &> /dev/null | |
# create a keystore and import certificate | |
keytool -import -noprompt -trustcacerts \ | |
-alias ${HOST} -file ${HOST}.cert \ | |
-keystore ${KEYSTORE_FILE} -storepass ${KEYSTORE_PASS} | |
rm ${HOST}.cert | |
} | |
import_cert stackoverflow.com 443 | |
import_cert www.google.com 443 | |
import_cert 172.217.194.104 443 # google |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment