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?
If you have access to the WebClient you can do this to skip SSL certificate validation:
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):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)
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.
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.