加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 如何在Jetty上运行的Restlet应用程序中使用自定义SSLCon

发布时间:2020-12-15 00:37:31 所属栏目:Java 来源:网络整理
导读:我正在尝试使用Restlet的ClientResource将HTTPS连接到使用自签名证书的服务器.我使用一个独立的应用程序,只使用ClientResource,我的自定义SSLContextFactory添加为属性,代码可以在这里看到: https://github.com/pixelatedpete/selfsignedexample 当我在更复
我正在尝试使用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),但这也没有帮助.

解决方法

好的,所以最终想通了 – 我错过了客户端位:
Client client = new Client(crCtx,Protocol.HTTPS);
ClientResource clientResource = new ClientResource("https://example.com");
clientResource.setNext(client);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读