java.net.SocketException: Default SSL context init failed: / by zero

Hi all!

First of all, I am a newbie in webservices. :-)

I have a remote webservice to acess from java and get a message. I do not need to send any parameters, only get a String.

I have de client certificate ( .pfx).

I got the BouncyClaster lib.

PLEASE, take a llok ate the code and the exception stack trace below and let me know where I am doing the wrong thing

JAVA CODE

###############################

import java.security.Security;

import java.util.List;

import javax.xml.namespace.QName;

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

public class WSCall {

public static void main(String[] args) {

Service service = new Service();

Call call;

List rtnValues;

try {

Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

System.setProperty("javax.net.ssl.keyStore", "D:\\MY_CERTIFICATE.PFX");

System.setProperty("javax.net.ssl.keyStorePassword", "");

System.setProperty("javax.net.ssl.keyStoreType", "PKCS12");

System.setProperty("javax.net.ssl.trustStore", "D:\\certificadoACRaiz.cer");

System.setProperty("javax.net.ssl.trustStorePassword", "");

System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");

call = (Call)service.createCall();

call.setTargetEndpointAddress(new java.net.URL("https://WSURL"));

call.setOperationName(new QName("http://URL", "MYOPERATIONNAME"));

call.setReturnType(org.apache.axis.Constants.XSD_STRING);

call.addParameter("testParam",

org.apache.axis.Constants.XSD_STRING,

javax.xml.rpc.ParameterMode.IN);

call.invoke(new Object[] { "" });

rtnValues = call.getOutputValues();

System.out.println("WS return : " + rtnValues.get(0).toString());

} catch (Exception ex) {

System.out.println(ex.getCause());

System.out.println(ex.getMessage());

ex.printStackTrace();

} // end catch

}

}

################################

D:\>javac WSCall.java

D:\>java WSCall

java.net.SocketException: Default SSL context init failed: / by zero

; nested exception is:

java.net.SocketException: Default SSL context init failed: / by zero

AxisFault

faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException

faultSubcode:

faultString: java.net.SocketException: Default SSL context init failed: / by zero

faultActor:

faultNode:

faultDetail:

{http://xml.apache.org/axis/}stackTrace:java.net.SocketException: Default SSL context init failed:

at javax.net.ssl.DefaultSSLSocketFactory.createSocket(DashoA12275)

at org.apache.axis.components.net.JSSESocketFactory.create(JSSESocketFactory.java:92)

at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191)

at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:404)

at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)

at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)

at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)

at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)

at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)

at org.apache.axis.client.Call.invokeEngine(Call.java:2784)

at org.apache.axis.client.Call.invoke(Call.java:2767)

at org.apache.axis.client.Call.invoke(Call.java:2443)

at org.apache.axis.client.Call.invoke(Call.java:2366)

at org.apache.axis.client.Call.invoke(Call.java:1812)

at WSCall.main(WSCall.java:32)

{http://xml.apache.org/axis/}hostname:BESAO000667

java.net.SocketException: Default SSL context init failed: / by zero

at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)

at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:154)

at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)

at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)

at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)

at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)

at org.apache.axis.client.Call.invokeEngine(Call.java:2784)

at org.apache.axis.client.Call.invoke(Call.java:2767)

at org.apache.axis.client.Call.invoke(Call.java:2443)

at org.apache.axis.client.Call.invoke(Call.java:2366)

at org.apache.axis.client.Call.invoke(Call.java:1812)

at WSCall.main(WSCall.java:32)

Caused by: java.net.SocketException: Default SSL context init failed: / by zero

at javax.net.ssl.DefaultSSLSocketFactory.createSocket(DashoA12275)

at org.apache.axis.components.net.JSSESocketFactory.create(JSSESocketFactory.java:92)

at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191)

at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:404)

at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)

... 10 more

########################

thanks a lot

[5221 byte] By [Galadriela] at [2007-10-2 22:05:35]
# 1
Please!!!!!!! Can somebody help me ?
Galadriela at 2007-7-14 1:22:10 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 2
> System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");Dunno but if you are using >= JDK 1.4 you should delete this line.
ejpa at 2007-7-14 1:22:10 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 3

I had this problem when I used the certificate filename for javax.net.ssl.trustStore -- similar to what you have on this line: System.setProperty("javax.net.ssl.trustStore", "D:\\certificadoACRaiz.cer");

Instead of using the certificate directly, I found some instructions to use 'keytool' in the java distribution to build a Java Keystore File (JKS). I used the JKS filename for the trustStore property, and the problem went away.

Here is the command I used:

$ /usr/java/j2sdk1.4.2_12/bin/keytool -import -trustcacerts -keystore java-keystore -alias myAlias -file MyCertificate.cer

Enter keystore password: myPassword

Certificate already exists in system-wide CA keystore under alias <fooca>

Do you still want to add it to your own keystore? [no]: yes

Certificate was added to keystore

Then try this:

System.setProperty("javax.net.ssl.trustStore", "D:\\java-keystore");

System.setProperty("javax.net.ssl.trustStorePassword", "myPassword");

System.setProperty("javax.net.ssl.trustStoreType", "JKS");

Hope that helps -- patrick

PatrickBrooksa at 2007-7-14 1:22:10 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...