Created
April 10, 2021 12:54
-
-
Save sammy2077/a5c10cb25062e68060058be59ef26297 to your computer and use it in GitHub Desktop.
File to import certificate to 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 | |
KEYSTORE_FILE=./keystore.jks | |
KEYSTORE_PASS=agweria | |
HOST=$1 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage