Created
January 27, 2014 16:48
-
-
Save c99koder/8652297 to your computer and use it in GitHub Desktop.
This file contains 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
TrustManager[] tms = new TrustManager[1]; | |
tms[0] = new X509TrustManager() { | |
@Override | |
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { | |
throw new CertificateException("Not implemented"); | |
} | |
@Override | |
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { | |
try { | |
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("X509"); | |
trustManagerFactory.init((KeyStore)null); | |
for (TrustManager trustManager: trustManagerFactory.getTrustManagers()) { | |
if (trustManager instanceof X509TrustManager) { | |
X509TrustManager x509TrustManager = (X509TrustManager)trustManager; | |
x509TrustManager.checkServerTrusted(chain, authType); | |
} | |
} | |
} catch (KeyStoreException e) { | |
throw new CertificateException(e); | |
} catch (NoSuchAlgorithmException e) { | |
throw new CertificateException(e); | |
} | |
if(BuildConfig.SSL_CN.length() > 0 && !chain[0].getSubjectDN().getName().startsWith("CN=*.irccloud.com")) { | |
throw new CertificateException("Incorrect CN in cert chain"); | |
} | |
} | |
@Override | |
public X509Certificate[] getAcceptedIssuers() { | |
return null; | |
} | |
}; | |
WebSocketClient.setTrustManagers(tms); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment