Skip to content

Instantly share code, notes, and snippets.

@matthewromano
Last active October 14, 2021 16:01
Show Gist options
  • Select an option

  • Save matthewromano/4178946 to your computer and use it in GitHub Desktop.

Select an option

Save matthewromano/4178946 to your computer and use it in GitHub Desktop.
Trust Manager to trust all SSL certificates
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.X509TrustManager;
public class BlindTrustManager implements X509TrustManager {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
}
private SSLSocketFactory buildSocketFactory() throws KeyManagementException, NoSuchAlgorithmException {
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, new TrustManager[] { new BlindTrustManager() }, null);
return ctx.getSocketFactory();
}
SSLSocketFactory sslSocketFactory = buildSocketFactory();
MyJAXService service = new MyJAXService();
MyServicePortProxy serviceProxy = service.getMyServicePortProxy();
Map<String, Object> requestContext = ((BindingProvider) serviceProxy).getRequestContext();
requestContext.put(BindingProviderProperties.SSL_SOCKET_FACTORY, sslSocketFactory);
@crusy
Copy link
Copy Markdown

crusy commented Apr 28, 2020

What's mode in BuildSocketFactory?

@matthewromano
Copy link
Copy Markdown
Author

What's mode in BuildSocketFactory?

Old code, most likely

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment