HttpUnit WebConversation SSL 问题
如何从 WebConversation
或 WebRequest
对象的上下文中忽略 SSL 证书问题?我知道我可以创建一个接受所有证书的假 TrustManager
,但是如何在 HttpUnit 上下文中设置它?
这是我遇到的异常:
[Security:090508]Certificate chain received from my.domain.com - NUM.NUM.NUM.NUM was incomplete.,
[Security:090477]Certificate chain received from my.domain.com - NUM.NUM.NUM.NUM was not trusted causing SSL handshake failure.
我需要以某种方式将 SSLSocket 设置设置为 WebConversation 或 WebRequest 对象;查看 HttpUnit 的 JavaDocs,没有这样的方法或构造函数可以这样做。有没有办法可以将其包装在某个暴露了 SSLSocket 属性的对象中?
How can I ignore SSL certificate issues from the context of the WebConversation
or WebRequest
object? I know I can create a fake TrustManager
that accepts all certificates but how can I set this in the HttpUnit context?
Here is the exception I am getting:
[Security:090508]Certificate chain received from my.domain.com - NUM.NUM.NUM.NUM was incomplete.,
[Security:090477]Certificate chain received from my.domain.com - NUM.NUM.NUM.NUM was not trusted causing SSL handshake failure.
I need to somehow set the SSLSocket settings to the WebConversation or WebRequest object; looking at the JavaDocs for HttpUnit there is no such method or constructor to do so. Is there a way I can wrap this inside some object which has exposed SSLSocket properties?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
对我有用的是使用此工具将服务器的无效证书添加到新的密钥库(创建一个文件 jssecacerts),然后用新的密钥库替换现有的密钥库。
cp cacerts cacerts.bak
cp ~/tools/jssecacerts cacerts
HttpUnit 之后工作正常。
What worked for me was using this tool to add the server's invalid cert to a new keystore (creates a file jssecacerts), then replace my existing keystore with the new one.
cp cacerts cacerts.bak
cp ~/tools/jssecacerts cacerts
HttpUnit worked fine after that.
根据 此常见问题解答条目,HttpUnit 似乎正在使用 Java 提供的 SSL 实现标准库。编写和安装“接受所有”TrustManager 非常简单:
但是您应该记住,此代码示例可能需要一些修改才能与 HttpUnit 一起使用(例如,如果库使用自定义 SocketFactory 建立连接) )
因为 HttpUnit 似乎没有提供任何 API 来设置自定义 SSLSocketFactry,这里是设置默认 SSL 上下文的替代解决方案(仅限 Java 6)
According to this FAQ entry, it seems that HttpUnit is using the SSL implementation provided by the Java standard library. Writing and installing an "accept all"
TrustManager
is straightforward:However you should keep in mind that this code sample may need some modifications to work with HttpUnit (for instance if the library establishes the connections using a custom SocketFactory)
Since it seems that HttpUnit does not provide any API to set a custom SSLSocketFactry here is an alternative solution setting the default SSL context (Java 6 only)
如果您有权访问 WebClient,则可以执行以下操作来跳过 SSL 证书验证:
If you have access to the WebClient you can do this to skip SSL certificate validation:
有点晚了,我刚刚遇到这个问题,但我设法让
httpunit 1.7.2
按照Jsc
与AnyTrustManager
一起工作使用以下代码回答(httpunit 在底层使用HttpsURLConnectionOldImpl
):A little late, i only just ran into this issue, but i managed to get
httpunit 1.7.2
working withAnyTrustManager
as perJsc
's answer with the following code (httpunit usesHttpsURLConnectionOldImpl
under de hood):截至 2019 年,在 Mac 上使用 Oracle 8 jvm 和 httpunit 1.7,Jcs 8 年前的答案仍然非常接近,只需要多一行。
as of 2019, with an oracle 8 jvm on a mac, and httpunit 1.7, Jcs' answer from 8 years ago is still very close, just needs one more line.