Last active
October 14, 2021 16:01
-
-
Save matthewromano/4178946 to your computer and use it in GitHub Desktop.
Trust Manager to trust all SSL certificates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private SSLSocketFactory buildSocketFactory() throws KeyManagementException, NoSuchAlgorithmException { | |
SSLContext ctx = SSLContext.getInstance("TLS"); | |
ctx.init(null, new TrustManager[] { new BlindTrustManager() }, null); | |
return ctx.getSocketFactory(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
What's
mode
inBuildSocketFactory
?
Old code, most likely
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's
mode
inBuildSocketFactory
?