Skip to content

Instantly share code, notes, and snippets.

What would you like to do? blog example on how to disable SSL certificate validation in Java
package my.hydepark.ssl;
public class SSLCertificateValidation {
public static void disable() {
try {
SSLContext sslc = SSLContext.getInstance("TLS");
TrustManager[] trustManagerArray = { new NullX509TrustManager() };
sslc.init(null, trustManagerArray, null);
HttpsURLConnection.setDefaultHostnameVerifier(new NullHostnameVerifier());
} catch(Exception e) {
private static class NullX509TrustManager implements X509TrustManager {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
private static class NullHostnameVerifier implements HostnameVerifier {
public boolean verify(String hostname, SSLSession session) {
return true;
Copy link

jm1024 commented Sep 17, 2014


Nice clean example. Exactly what I needed.

Copy link

maxiwu commented Jan 4, 2016

this works, thanks

Copy link

aviadhadida commented Jan 21, 2016

Anyone has an idea how to make the same for websocket? i mean for Java websocket client and "wss"

Copy link

prodigy4440 commented Nov 29, 2017

Not working for me, i'm using Okhttp

Copy link

JamesSunny commented Sep 29, 2020

Very nice, it works with RestTemaple! thank you

Is it possible to limit it to one specific call?

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