简体   繁体   English

肥皂SSL握手

[英]Soap SSL handshake

My client is successfully getting response from server through HTTP. 我的客户端通过HTTP成功获得服务器的响应。

SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
SOAPConnection connection = sfc.createConnection();

SOAPMessage soapMessageResponse = connection.call(soapRequest, new URL(serviceLocation));

I want SSL communication between client/server. 我想要客户端/服务器之间的SSL通信。

In another project I am successfully creating SSLSocketFactory from a KeyStore and TrustManagerFactory for SSL handshake. 在另一个项目中,我从KeyStoreTrustManagerFactory成功创建SSLSocketFactory以进行SSL握手。

How can I use SSLSocketFactory code in webservice client to make client SSL communication successful to call server. 如何在Web服务客户端中使用SSLSocketFactory代码使客户端SSL通信成功调用服务器。

I'm pretty sure it will use the default SSLContext. 我很确定它会使用默认的SSLContext。 You can change that with SSLContext.setDefault(). 您可以使用SSLContext.setDefault()更改它。

SSLContext c = SSLContext.getInstance("SSL");
TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX");
tmf.init(yourKeystore);
TrustManager tm = tmf.getTrustManagers()[0];
tm.
c.init(null, tm, null);

Here are some other values for the string parameters above. 以下是字符串参数的其他一些

If you need more complete control, you can implement your own subclass of SSLContext which returns your own implementation of SSLSocketFactory and set that SSLContext as the default: 如果需要更完整的控制,可以实现自己的SSLContext子类,它返回自己的SSLSocketFactory实现,并将SSLContext设置为默认值:

public class MySSLContext extends SSLContext {

    private SSLContext wrapped;
    private SSLSocketFactory mySocketFactory;

    public MySSLContext(SSLContext toWrap, SSLSocketFactory mySocketFactory) {
        wrapped = toWrap;
        this.mySocketFactory = mySocketFactory;
    }

    public SSLSocketFactory getSocketFactory() {
        return mySocketFactory;
    }

    public SSLSessionContext getClientSessionContext() {
        return wrapped;
    }

    // other delegates

}

This line of code will not work in case of SSL. 这行代码在SSL的情况下不起作用。

SOAPMessage soapMessageResponse = connection.call(soapRequest, new URL(serviceLocation));

Create trustmanager and keymanagers from here . 这里创建信任管理员和密钥管理员。

In order to get response through SSL from axis2 webservice you need to open streams like given here 为了通过来自axis2 webservice的SSL获得响应,您需要打开此处给出的流

Hi if you add this code your webservice class ı think your problem will be solve . 嗨,如果您添加此代码您的Web服务类ı认为您的问题将得到解决。

     `

   //just put it your somewhere 
 public static class miTM implements javax.net.ssl.TrustManager,
    javax.net.ssl.X509TrustManager {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
    return null;
}

public boolean isServerTrusted(
        java.security.cert.X509Certificate[] certs) {
    return true;
}

public boolean isClientTrusted(
        java.security.cert.X509Certificate[] certs) {
    return true;
}

public void checkServerTrusted(
        java.security.cert.X509Certificate[] certs, String authType)
        throws java.security.cert.CertificateException {
    return;
}

public void checkClientTrusted(
        java.security.cert.X509Certificate[] certs, String authType)
        throws java.security.cert.CertificateException {
    return;
}
    }





 // CAll This function in your webservice class .
private static void trustAllHttpsCertificates() throws Exception {

// Create a trust manager that does not validate certificate chains:

javax.net.ssl.TrustManager[] trustAllCerts =

new javax.net.ssl.TrustManager[1];

javax.net.ssl.TrustManager tm = new miTM();

trustAllCerts[0] = tm;

javax.net.ssl.SSLContext sc =

javax.net.ssl.SSLContext.getInstance("SSL");

sc.init(null, trustAllCerts, null);

javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(

sc.getSocketFactory());

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM