【问题标题】:How do I use a custom SSLContextFactory in a Restlet application running on Jetty?如何在 Jetty 上运行的 Restlet 应用程序中使用自定义 SSLContextFactory?
【发布时间】: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),但这也没有帮助。

【问题讨论】:

    标签: java ssl restlet


    【解决方案1】:

    好的,所以终于弄明白了——我错过了客户端位:

    Client client = new Client(crCtx, Protocol.HTTPS);
    ClientResource clientResource = new ClientResource("https://example.com");
    clientResource.setNext(client);
    

    【讨论】:

      猜你喜欢
      • 2019-12-05
      • 1970-01-01
      • 2010-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-14
      • 2017-02-28
      相关资源
      最近更新 更多