First retrieve the server's certificate, and format it in a format suitable to import into the JRE's keystore format. Just replace the hostname and port that you want to connect to:
echo | openssl s_client -connect hostname:port 2>/dev/null | openssl x509 > test_self_signed.cerThis will create file that will look roughly like this:
-----BEGIN CERTIFICATE----- MIIDezCCAmOgAwIBAgIEaejl6zANBgkqhkiG9w0BAQsFADBuMRAwDgYDVQQGEwdV bmtub3duMRAwDgYDVQQIEwdVbmtub3duMRAwDgYDVQQHEwdVbmtub3duMRAwDgYD ... quite a few more lines here ... /FHwsiau3ntmBn358GhaD4exNPkf346eDcYnHii/nvfEJivC5vEDnQsFBcxSWEU6 P/GspsPqjjuEwxh6HDGOYBNg7a7jwk66uwPJ/QoRNg== -----END CERTIFICATE-----
Second, import the file into the JRE's keystore. If using a JDK, the JRE is in a directory called jre inside your JDK. Make sure that you have the proper permissions, if the JDK is installed system wide, you might require root access for the next step. Ensure that you are importing the cert into the JDK version that you're using, since you might have several versions installed in your computer.
keytool -import -alias test_self_signed -file self_signed.cer -keystore lib/security/cacerts -storepass changeitFinally, you can list the certs in the keystore to ensure your cert was imported:
keytool -list -keystore lib/security/cacerts -storepass changeitOr you can search for only your particular cert by passing the alias name:
keytool -list -alias test_self_signed -keystore lib/security/cacerts -storepass changeitYou will see an output similar to this:
test_self_signed, May 5, 2015, trustedCertEntry, Certificate fingerprint (SHA1): 9C:A6:FC:74:05:02:B1:11:F9:02:BB:3C:14:DA:7A:5B:84:F2:F0:A8The commands were put together from examples I found here and here.
No comments:
Post a Comment