Skip to content

Instantly share code, notes, and snippets.

@rammanokar
Created September 11, 2020 08:21
Show Gist options
  • Select an option

  • Save rammanokar/c8e51853589e6b8fa678ac498b88f565 to your computer and use it in GitHub Desktop.

Select an option

Save rammanokar/c8e51853589e6b8fa678ac498b88f565 to your computer and use it in GitHub Desktop.
Add cert form URL to JKS java keystore
HOST=google.com
PORT=443
KEYSTOREFILE="/etc/pki/java/cacerts"
KEYSTOREPASS=changeit
# get the SSL certificate
openssl s_client -connect ${HOST}:${PORT} </dev/null \
| sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ${HOST}.cert
# create a keystore and import certificate
keytool -import -noprompt -trustcacerts \
-alias ${HOST} -file ${HOST}.cert \
-keystore ${KEYSTOREFILE} -storepass ${KEYSTOREPASS}
#
## verify we've got it.
keytool -list -v -keystore ${KEYSTOREFILE} -storepass ${KEYSTOREPASS} -alias ${HOST}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment