SSL made easier for Testing By Dummy SSL
Introduction
JDK 1.4.2 and above JSSE allows to plugin the implementation of the ssl security provider.
Sometimes its difficult to get the ssl/jsse working correctly due to a number of reasons.
Specially in testing applications, where the url's are accessible via ssl , parts or all of the the ssl implementation/provider can be swapped sith a custom
if the server certificate is a self signed cert, not valid or not a trusted cert.
The idea there being is to replace sun default SSL Socket Server Factory with a dummy implementation as show below.
| package com.livrona.ssl.utils; import java.io.IOException; import java.net.InetAddress; import java.net.Socket; import javax.net.SocketFactory; /** public DummySSLSocketFactory() public static SocketFactory getDefault() public Socket createSocket(Socket socket, String s, int i, boolean flag) public Socket createSocket(InetAddress inaddr, int i, InetAddress inaddr1, int j) public Socket createSocket(InetAddress inaddr, int i) throws IOException public Socket createSocket(String s, int i, InetAddress inaddr, int j) public Socket createSocket(String s, int i) throws IOException public String[] getDefaultCipherSuites() public String[] getSupportedCipherSuites() |
| package com.livrona.ssl.utils;
import java.security.cert.CertificateException; import javax.net.ssl.X509TrustManager; /** public boolean isServerTrusted(X509Certificate[] cert) public X509Certificate[] getAcceptedIssuers() /* (non-Javadoc) } } |
In order to override the inbuilt implementation with the dummy one, call this line at the application startup and you should be set.
| Security.setProperty("ssl.SocketFactory.provider", com.livrona.ssl.utils.DummySSLSocketFactory"); |
Trouble Shooting
In order to trouble shoot and see if this thing really works we can turn the ssl debugging on by adding following option to the java command line.
-Djavax.net.debug=ssl,handshake,data,trustmanager
So in this way you can still do SSL without the hassle.This has worked for me more than 2 times, when the server certificate with no good.
If there are other ways to do, please share here.













Comments
Great post! This almost
Great post! This almost saved me hours, having not to setup ssl yet do end to end testing. Thanks
Post new comment