在将我的应用程序从Windows2000移到Windows2008WindowsServer之后,我已经挣扎了将近一个星期来启动我的应用程序。
程序:
JAVA_HOME设置为C:\Progra~1\Java\jdk1.7.0_25\keytool将证书导入仙人掌keytool的-list中存在。我已经尝试用InstallCert重复第3步,以确保我没有搞砸任何事情。
上面的方法没有解决我的问题,所以我尝试以编程的方式完成它:
System.setProperty("javax.net.ssl.trustStore",
"C:/Progra~1/Java/jdk1.7.0_25/jre/lib/security/cacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");还是没有运气。我被困住了,不太确定从这里往哪个方向走。
堆栈跟踪:
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 sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
    at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1886)
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:276)
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:270)
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1341)
    at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:153)
    at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
    at sun.security.ssl.Handshaker.process_record(Handshaker.java:804)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1016)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:515)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
    at util.SMS.send(SMS.java:93)
    at domain.ActivationSMSSenderMain.sendActivationMessagesToCustomers(ActivationSMSSenderMain.java:80)
    at domain.ActivationSMSSenderMain.<init>(ActivationSMSSenderMain.java:44)
    at domain.ActivationSMSSenderMain.main(ActivationSMSSenderMain.java:341)
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:385)
    at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
    at sun.security.validator.Validator.validate(Validator.java:260)
    at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:326)
    at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:231)
    at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:126)
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1323)
    ... 14 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:196)
    at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:268)
    at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:380)
    ... 20 more更新:
System.out.println(System.getProperty("javax.net.ssl.trustStore"));和System.out.println(System.getProperty("javax.net.ssl.keyStore"));
返回null。
发布于 2014-07-11 19:46:39
我遇到了类似的问题,其原因和解决办法都很简单:
主要原因:没有使用keytool导入正确的证书
注意:只导入根CA (或您自己签名的)证书。
注意:不要导入中间的、非证书链根证书。
解决方案imap.gmail.com示例
javax.net.ssl.trustStorekeytool -import -alias gmail_imap -file Equifax_Secure_Certificate_Authority.pem导入证书发布于 2013-08-26 10:12:21
您已经将证书导入到JDK中提供的JRE的信任库中,但是您正在运行直接安装的JRE的java.exe。
编辑
为了清晰起见,并且为了解决下面评注中的误解,您需要将证书导入您打算使用的JRE的cacerts文件中,而且这很少会成为JDK内部传递的证书,因为客户端通常不会有JDK。下文评注中提出的任何其他建议都应被忽视,因为它没有在此表达我的意图。
一个更好的解决方案是创建您自己的信任库,从cacerts文件的副本开始,并特别告诉Java通过系统属性javax.net.ssl.trustStore.使用该库。
您应该将构建这个部分作为构建过程的一部分,以便跟上JDK升级所导致的cacerts文件的更改。
发布于 2016-02-10 07:21:15
如果您正在使用Eclipse,只需交叉检查Eclipse ->preferences-->java-->已安装的指向当前的JRE和配置证书的JRE。如果不删除JRE,则添加安装证书的jre。
https://stackoverflow.com/questions/18378869
复制相似问题