|
|
I am actually using WSClient, but got no luck with it.
I've tried two solutions (look for them at the end of the message) but none actually works. They work for URL connection examples, though, but not for WSClient :(
Could somebody help me?
Btw I can not add the untrusted cert to the trusted certs list because I don't have the password.
Solution 1 (Groovy-based): def nullTrustManager = [
checkClientTrusted: { chain, authType -> }, checkServerTrusted: { chain, authType -> }, getAcceptedIssuers: { null } ]
def nullHostnameVerifier = [ verify: { hostname, session -> true } ] SSLContext sc = SSLContext.getInstance("SSL")
sc.init(null, [nullTrustManager as X509TrustManager] as TrustManager[], null) HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()) HttpsURLConnection.setDefaultHostnameVerifier(nullHostnameVerifier as HostnameVerifier)
Solution 2 (Java-based): // Create a trust manager that does not validate certificate chains TrustManager[] trustAllCerts = [ new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null; } public void checkClientTrusted( java.security.cert.X509Certificate[] certs, String authType) {
} public void checkServerTrusted( java.security.cert.X509Certificate[] certs, String authType) { } }
] // Install the all-trusting trust manager try { SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch (Exception e) { _log.error("Error 1: "+e.getMessage()); }
|