Recently in the development of Java access to Azure Servicebus encountered SSL certificate problems, resulting in Java error, not normal access, error information as follows:
Javax.net.ssl.SSLException:Connection has been shutdown:javax.net.ssl.SSLHandshakeException: Sun.security.validator.ValidatorException:PKIX Path Building failed: Sun.security.provider.certpath.SunCertPathBuilderException:unable to find valid certification path to requested target
Workaround: Configure the Domain name certificate to access the Web site and import the server in the JDK environment
- Download Installcert.java from Https://github.com/escline/InstallCert
- Compiling Javac Installcert.java
- Run Installcert, the parameter is the URL you call (the address of the Azure event hub), and if it is port 80, you may omit port
Java Installcert [Host]:[port] Example: Java installcert abc.com:443
After running the certificate will be listed for you to choose, enter 1 to return the car, and finally generate a jssecacerts file in the current directory.
1. Export the certificate file
1) Use the cmd command to enter the directory where the Jssecacerts file is located
2) Run the following command to export the certificate file:
Keytool-exportcert-alias [Host]-1-keystore jssecacerts-storepass changeit-file [host].cer Example: Keytool-exportcert-alia s www.abc.com-1-keystore jssecacerts-storepass changeit-file www.abc.com.cer
Import the certificate file into the system KeyStore
Keytool-importcert-alias [Host]-keystore [path to System KeyStore]-storepass Changeit-file [host].cer Example: Keytool-impor Tcert-alias www.abc.com-keystore "C:\Program files\java\jre1.8.0_111\lib\security\cacerts"-storepass changeit-file Www.abc.com.cer
# Example:java Installcert woot.com:443 Loading keystore/usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/security/cacerts ... Opening connection to woot.com:443 ... Starting SSL handshake ... Javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX path Building failed:sun.security.provider.certpath.SunCertPathBuilderException:unable to find valid certification path to Requested target <...> Server sent 1 certificate (s): 1 Subject o=woot Inc, C=us, St=texas, L=carrollton, C N=*.woot.com Issuer cn=securetrust CA, O=securetrust Corporation, C=us SHA1 4b CA 6b, B3 (FF) C6 E7 9c FD B3 9b E3 3f 2e c4 MD5 E8 a5 1b d5 (BB fc) CC B1 c5 2b ac c4 7d Enter certificate to add To trusted KeyStore or ' Q ' to quit: [1][enter] [[Version:v3 subject:o=woot Inc, C=us, St=texas, L=carr Ollton, cn=*.woot.com Signature algorithm:sha1withrsa, OID = 1.2.840.113549.1.1.5 <...> AdDed certificate to KeyStore ' Jssecacerts ' using alias ' woot.com-1 ' Keytool-exportcert-alias woot.com-1-keystore jssecace Rts-storepass changeit-file woot.com.cer Certificate stored in file <woot.com.cer> (sudo) keytool-importcert -alias Woot.com-keystore/usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/security/cacerts-storepass Changeit-file Woot.com.cer owner:o=woot Inc, C=us, St=texas, L=carrollton, cn=*.woot.com issuer:cn=securetrust CA, O=securetrust Corporation, c=us <...> Trust this certificate? [No]: Yes Certificate is added to KeyStore
Reference URL: Https://github.com/escline/InstallCert
Configure Java SSL Access Web site certificate