[size=large]今天在程序中用到了HTTPS连接的HTTPURLConnnection, 运行是发生了下面的错误,发现是要安装证书文件,稍微找了一下,把证书文件安装了,就正确了,在这里把证书文件的命令保存一下,以备以后查看:
[/size]
[size=large]
Suppose:
$JAVA_HOME = "C:\Program Files\Java\jdk1.6.0_01"
Run the following command to import the certifate file.
keytool -import -trustcacerts -alias cng_domain -file cng.cer -keystore % $JAVA_HOME/jre/lib/security/cacerts
[/size]
[size=large]至于怎么从浏览器里面导出证书文件我就不多说了。
chrome下面导出证书大家请看:[url]http://asialee.iteye.com/blog/1612513[/url]
[/size]
[size=large]
[/size]
[size=large][color=darkblue]
chrome导出证书向导,希望对大家有用.
[/color][/size]
[img]http://dl.iteye.com/upload/attachment/0071/5609/3f33e6d6-eed9-3a17-a544-3c6b9adb488e.png[/img]
[img]http://dl.iteye.com/upload/attachment/0071/5611/6aa81452-dc3c-3fcd-9706-e17e9e95a0d3.png[/img]
[img]http://dl.iteye.com/upload/attachment/0071/5613/089583de-b92c-3d41-9310-912391945875.png[/img]
[img]http://dl.iteye.com/upload/attachment/0071/5615/6e91c516-d21a-3997-946d-7e8c25902a38.png[/img]
[/size]
[size=large]
Suppose:
$JAVA_HOME = "C:\Program Files\Java\jdk1.6.0_01"
Run the following command to import the certifate file.
keytool -import -trustcacerts -alias cng_domain -file cng.cer -keystore % $JAVA_HOME/jre/lib/security/cacerts
[/size]
[size=large]至于怎么从浏览器里面导出证书文件我就不多说了。
chrome下面导出证书大家请看:[url]http://asialee.iteye.com/blog/1612513[/url]
[/size]
[size=large]
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
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1520)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:182)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:176)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:975)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:123)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:511)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:449)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:817)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1029)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1056)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1040)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:405)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:170)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:836)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)
at cng.api.GatewayConnector.procesRequest(GatewayConnector.java:141)
at cng.api.GatewayConnector.processPreAuthRequest(GatewayConnector.java:49)
at cng.test.Application.processPreAuth(Application.java:24)
at cng.test.Application.main(Application.java:13)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:285)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:191)
at sun.security.validator.Validator.validate(Validator.java:218)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:126)------------Begin Pre-Auth------------------------
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:209)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:954)
... 15 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:174)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:238)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:280)
... 21 more
Exception in thread "main" java.lang.NullPointerException
at cng.test.Application.printResponse(Application.java:68)
at cng.test.Application.processPreAuth(Application.java:27)
at cng.test.Application.main(Application.java:13)
[/size]
[size=large][color=darkblue]
chrome导出证书向导,希望对大家有用.
[/color][/size]
[img]http://dl.iteye.com/upload/attachment/0071/5609/3f33e6d6-eed9-3a17-a544-3c6b9adb488e.png[/img]
[img]http://dl.iteye.com/upload/attachment/0071/5611/6aa81452-dc3c-3fcd-9706-e17e9e95a0d3.png[/img]
[img]http://dl.iteye.com/upload/attachment/0071/5613/089583de-b92c-3d41-9310-912391945875.png[/img]
[img]http://dl.iteye.com/upload/attachment/0071/5615/6e91c516-d21a-3997-946d-7e8c25902a38.png[/img]