证书存在于cacert文件中,但抛出ssl异常

时间:2016-03-28 20:22:15

标签: java security ssl https glassfish

我在2个不同的服务器(1)上安装了2个应用程序,这些服务器托管在glassfish(2)批处理服务器(独立的Java应用程序)中。 这两个应用程序都使用通用的java程序(以jar文件的形式)来调用外部服务器。我正在使用' CloseableHttpClient'连接到该外部第三方服务器。 从我的服务器一(glassfish)我能够从外部服务器调用并获得响应,但批处理服务器上的相同程序在SSL之外抛出除了

  

javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到所请求目标的有效证书路径       在com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)       在com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1747)       在com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:241)       在com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:235)       在com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1209)       在com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:135)       在com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:593)       在com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:529)       at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:943)       at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1188)       at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1215)       at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1199)       at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:290)       at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:259)       在org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:125)       在org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:319)       at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)       at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)       在org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)       at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)       在org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)       在org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)       在org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)       在org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)       在com.csid.sms.util.postup.PostUpRestClient.executeRequest(PostUpRestClient.java:169)       在com.csid.sms.util.postup.PostUpRestClient.executeJsonPost(PostUpRestClient.java:134)       在com.csid.sms.util.postup.PostUpRestClient.executeJsonRequest(PostUpRestClient.java:106)       在com.csid.sms.util.postup.PostUpEmailRoute.triggerMessage(PostUpEmailRoute.java:213)       at itm.monitor.SummaryEmailPostupRoute.triggerMessage(SummaryEmailPostupRoute.java:154)       在com.csid.sms.messaging.MessagingHandler.triggerMessage(MessagingHandler.java:60)       at itm.monitor.SummaryEmailRoute.sendEmail(SummaryEmailRoute.java:49)       at itm.monitor.BatchEmailProcessor.sendEmail(BatchEmailProcessor.java:105)       at itm.monitor.BatchEmailProcessor.call(BatchEmailProcessor.java:51)       at itm.monitor.BatchEmailProcessor.call(BatchEmailProcessor.java:33)       at java.util.concurrent.FutureTask $ Sync.innerRun(FutureTask.java:303)       在java.util.concurrent.FutureTask.run(FutureTask.java:138)       at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:439)       at java.util.concurrent.FutureTask $ Sync.innerRun(FutureTask.java:303)       在java.util.concurrent.FutureTask.run(FutureTask.java:138)       at java.util.concurrent.ThreadPoolExecutor $ Worker.runTask(ThreadPoolExecutor.java:895)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:918)       在java.lang.Thread.run(Thread.java:662)   引发者:sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到所请求目标的有效证书路径       在sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:323)       at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:217)       at sun.security.validator.Validator.validate(Validator.java:218)       at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:126)       at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:209)       at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249)       在com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1188)       ......还有37个   引起:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径       at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:174)       在java.security.cert.CertPathBuilder.build(CertPathBuilder.java:238)       在sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:318)       ... 43更多

注意 - 此异常仅从批处理服务器抛出,而不是从管理服务器(在glassfish中托管)抛出。

在Google上搜索此错误后发现外部服务器获取的证书可能不是由某个受信任的机构颁发的,因此我使用' installCert' (this java program)。

现在使用keytool命令在cacert中验证证书

  

keytool -list -keystore cacerts

我可以看到外部证书列在受信任的证书列表中。 但仍然高于SSL例外。

有什么想法吗? 为什么我没有从管理服务器(glassfish)获得任何类型的SSL期望,这也是使用相同的Java代码? glassfish是否像浏览器一样自动导入证书?

2 个答案:

答案 0 :(得分:0)

您的批处理程序和管理应用程序可能表现不同,因为它们使用不同的JRE。每个JRE都有​​自己的cacerts。

答案 1 :(得分:0)

您需要验证JRE是否确实使用了您导入证书的信任库 添加JVM运行时参数“-Djavax.net.debug = all”并重新启动服务器。这将在服务器启动时打印由JVM加载的信任库。