Skip to content

Instantly share code, notes, and snippets.

@veggiedefender
Created May 20, 2018 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veggiedefender/0cb3350c8092e079765ae8a0645e4c64 to your computer and use it in GitHub Desktop.
Save veggiedefender/0cb3350c8092e079765ae8a0645e4c64 to your computer and use it in GitHub Desktop.
package com.valvesoftware.android.steam.community;
import android.util.Log;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
class DevHttpsTrustManager implements X509TrustManager {
private static final X509Certificate[] _AcceptedIssuers = new X509Certificate[0];
private static TrustManager[] trustManagers;
DevHttpsTrustManager() {
}
public static void allowSslToValveDev() {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String arg0, SSLSession arg1) {
return arg0 != null && (arg0.contains("valvesoftware.com") || arg0.contains("valve.org"));
}
});
SSLContext context = null;
if (trustManagers == null) {
trustManagers = new TrustManager[]{new DevHttpsTrustManager()};
}
try {
context = SSLContext.getInstance("TLS");
context.init(null, trustManagers, new SecureRandom());
} catch (NoSuchAlgorithmException e) {
Log.e(DevHttpsTrustManager.class.getSimpleName(), e.toString());
} catch (KeyManagementException e2) {
Log.e(DevHttpsTrustManager.class.getSimpleName(), e2.toString());
}
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
}
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return _AcceptedIssuers;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment