【发布时间】:2016-01-19 15:27:58
【问题描述】:
我正在尝试使用 Restlet 的 ClientResource 通过 HTTPS 连接到使用自签名证书的服务器。我使用仅使用 ClientResource 和我的自定义 SSLContextFactory 作为属性添加的独立应用程序进行此工作,可以在此处看到它的代码:
https://github.com/pixelatedpete/selfsignedexample
当我在更复杂的 Restlet 应用程序(具有与上述相同的 pom)中使用相同的类(DynamicTrustManager 和 SelfSignSslSocketFactory)时,该应用程序使用 Restlet 提供通过 Jetty 服务的 REST API,我的自定义 SSLContextFactory 不再被使用。
我将它添加到上面的 ClientResource 上下文中,但我从未看到任何日志消息表明提供给 ClientResource 的 SSLContextFactory 被传递到底层 httpclient。
如果我直接使用 HttpClient 而不是 ClientResource 重写:
HttpPost post = new HttpPost(cr.getReference().toString());
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate) cf.generateCertificate(...);
DynamicTrustManager tm = new DynamicTrustManager(..., cert);
SelfSignTrustSslContextFactory scf = (SelfSignTrustSslContextFactory)
CloseableHttpClient httpclient = HttpClients.custom().setSslcontext(scf.createSslContext()).build();
CloseableHttpResponse response = httpclient.execute(post);
一切又恢复了。
这是其他人遇到过的并且可以指出我怀疑是我遗漏的非常明显的事情吗?
铌。再次尝试使用 Tomcat 并得到同样的问题
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
还尝试注入 SslContextFactory(我们在这里使用 Guice),但这也没有帮助。
【问题讨论】: