How to bypass the security certificate validation in axis ssl code
843811May 24 2003 — edited May 26 2003Hi, All:
I created SSL soap files from WSDL. but got javax.net.ssl.SSLException: untrusted server cert chain
I did several steps after that
a. import cert:
1. rename: D:/java/sdks/jdk1.3/jre/lib/security/cacerts to D:/java/sdks/jdk1.3/jre/lib/security/cacerts.bak
2. D:\java\sdks\jdk1.3>keytool -import -keystore jre/lib/security/cacerts -file my.cer
3. D:\java\sdks\jdk1.3>keytool -list -keystore D:/java/sdks/jdk1.3/jre/lib/security/cacerts
by doing step 3, I know I had cert installed
b. I put System.setProperty("javax.net.ssl.trustStore", "D:\\java\\sdks\\jdk1.3\\jre\\lib\\security\\cacerts"); in my java file
but it still not working.
I was told I could bypass security certificate validation, but search online, found some sample code as:
........
X509TrustManager tm = new MyX509TrustManager();
KeyManager[] km = null;
TrustManager[] tma = { tm };
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(km,tma,new java.security.SecureRandom());
SSLSocketFactory sf1 = sc.getSocketFactory();
........
XmlRpcClient client = new XmlRpcClient( url );
XmlRpc.setDebug( false );
response = (String)client.execute( method, v );
if( response != null && !response.equals( "1" ) )
throw new Exception( "Error code: " + response + " " +
(String)errorCodes.get( response ) );
........
not sure how to import this kind of code into WSDL generate soap connection.
Can anyone give me some hint?
a very simple version of my code is like this:
Service service = new Service();
try {
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName(new QName("test"));
int value = -6;
value = ((java.lang.Integer)call.invoke( new java.lang.Object[] {""} ) ).intValue();;
}catch (Exception re) {
throw new junit.framework.AssertionFailedError("Remote Exception caught: " + re);
}
Thanks
Nina