Using browser's certificate in java program

你离开我真会死。 提交于 2019-11-29 07:27:28

You have to add the issuer CA's of your server certificate (or directly the server certificate in case of for example your cds is selfsigned) to the truststore in order to avoid PKIX path builder exception.

By default java truststore is on JAVA_HOME/jre/lib/security/cacerts (you can specify another trust store with javax.net.ssl.trustStore property).

To do this, first download the server certificate. You can download the server certificate for example with Chrome connecting to the server url and click on the green lock, then select the tab connection and click on certificate information:

Then save this certificate on disc.

Now you have to add this certificate to java trust store, you can do it with java keytool (if is in your path use keytool if not keytool is on JAVA_HOME/bin/keytool):

keytool -import -trustcacerts -alias myServerCertificate -file path/myServerCert.crt -keystore JAVA_HOME/jre/lib/security/cacerts

The default password for cacerts is: changeit

Hope this helps,

The other answers work, but I find exporting the cert in browsers to be troublesome. Here's my steps for exporting then importing the cert all from the command line: https://gist.github.com/jeffsheets/d2880dc1e2ea241b19f140c54809f750

Command to export a cert from a website to a .cer file (example uses google.com):

openssl s_client -servername google.com -connect google.com:443 </dev/null 2>/dev/null | openssl x509 -inform PEM -outform DER -out google.com.cer

Command to import into local java truststore (use your own location of JAVA_HOME)

"$JAVA_HOME"/bin/keytool -keystore "$JAVA_HOME"/jre/lib/security/cacerts -importcert -alias google.com -file google.com.cer
  • default java keystore password is changeit

  • if you get an update denied message, in Windows File Explorer set security on cacerts file to MODIFY for all Users (or chmod on linux)

  • if keytool is not found, define a JAVA_HOME environment variable (or replace $JAVA_HOME with the full path)
Tonino

Otherwise, Try to follow solution that you can found in this link: https://stackoverflow.com/a/3685601/2088039

You can export a certificate using Firefox, this site has instructions. Then you use keytool to add the certificate.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!