Hello,
I'm attempting to ignore the SSL certificate in a Java application as follows:
System.setProperty(
"org.apache.axis.components.net.SecureSocketFactory",
"org.apache.axis.components.net.SunFakeTrustSocketFactory"
);
I'm getting the following error at runtime:
Exception in thread "main" java.lang.NoClassDefFoundError: sun.security.provider.Sun
at java.lang.J9VMInternals.verifyImpl(
Native Method)
at java.lang.J9VMInternals.verify(
J9VMInternals.java:72)
at java.lang.J9VMInternals.verify(
J9VMInternals.java:70)
at java.lang.J9VMInternals.initialize(
J9VMInternals.java:134)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(
Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(
NativeConstructorAccessorImpl.java:44)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(
Constructor.java:516)
at org.apache.commons.discovery.tools.ClassUtils.newInstance(
ClassUtils.java:160)
at org.apache.axis.AxisProperties$1.run(
AxisProperties.java:183)
at java.security.AccessController.doPrivileged(
AccessController.java:202)
at org.apache.axis.AxisProperties.newInstance(
AxisProperties.java:166)
at org.apache.axis.components.net.SocketFactoryFactory.getFactory(
SocketFactoryFactory.java:75)
at org.apache.axis.transport.http.HTTPSender.getSocket(
HTTPSender.java:187)
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 com.vmware.vim25.VimBindingStub.retrieveServiceContent(
VimBindingStub.java:47221)
at vim.samples.ws.HelloVI.main(
HelloVI.java:64)
Caused by:
java.lang.ClassNotFoundException: sun.security.provider.Sun
at java.lang.Throwable.<init>(
Throwable.java:80)
at java.lang.ClassNotFoundException.<init>(
ClassNotFoundException.java:77)
at java.net.URLClassLoader.findClass(
URLClassLoader.java:385)
at java.lang.ClassLoader.loadClass(
ClassLoader.java:653)
at sun.misc.Launcher$AppClassLoader.loadClass(
Launcher.java:346)
at java.lang.ClassLoader.loadClass(
ClassLoader.java:619)
... 27 more
Any ideas on how to fix this - thanks!
Not sure if this will help you but there is a class to help install the certificate called InstallCert made by someone at Sun(http://code.google.com/p/java-use-examples/source/browse/trunk/src/com/aw/ad/util/InstallCert.java).
Other than that in the Java code sample there is a Fake SSL Factory (FakeSSLSocketFactory.java) that might help you.
Let me know if this helps.
Thanks
Hen
Hi,
so late but i have one solution. It works.
First,
before login with your client SDK like "vCloudClient.login(valueLogin, valuePwd)", do that :
vCloudClient.registerScheme("https", 443, FakeSSLSocketFactory.getInstance());
https : if U use an https client.
443 : https port
FakeSSLSocketFactory : you have to create it (some exemple after).
Second,
Write FakeSSLSocketFactory class :
-------------------------------------------------------------------------------------------------------------------------
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
/**
*
* @author rhnirina
*
*/
public class FakeSSLSocketFactory extends SSLSocketFactory {
SSLContext sslContext = SSLContext.getInstance("TLS");
public FakeSSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
super(truststore);
TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
sslContext.init(null, new TrustManager[] {
tm }, null);
}
public static SSLSocketFactory getInstance() throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException {
return new SSLSocketFactory(new TrustStrategy() {
public boolean isTrusted(final X509Certificate[] chain, final String authType) throws CertificateException {
return true;
}
}, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
}
@Override
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException {
return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
}
@Override
public Socket createSocket() throws IOException {
return sslContext.getSocketFactory().createSocket();
}
}
-------------------------------------------------------------------------------------------------------------------------
it will work (hope so).
I hope that it help you.