Skip to content

Instantly share code, notes, and snippets.

@lpcdma
Created May 1, 2017 13:29
Show Gist options
  • Save lpcdma/5890f5a45eb4ada261eb6b83c580c16a to your computer and use it in GitHub Desktop.
Save lpcdma/5890f5a45eb4ada261eb6b83c580c16a to your computer and use it in GitHub Desktop.
获得证书用于java程序连接
HOST=myhost.example.com
PORT=443
KEYSTOREFILE=dest_keystore
KEYSTOREPASS=changeme
# 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