Skip to content

Instantly share code, notes, and snippets.

Created July 31, 2016 14:58
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/25937fede6b0984d44edfc9f2a9305de to your computer and use it in GitHub Desktop.
Save anonymous/25937fede6b0984d44edfc9f2a9305de to your computer and use it in GitHub Desktop.
NianticTrustManager.class from Pokemon Go 0.31.0
package com.nianticlabs.nia.network;
import android.content.Context;
import com.nianticlabs.nia.contextservice.ContextService;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
public class NianticTrustManager extends ContextService implements X509TrustManager {
private native void nativeCheckClientTrusted(X509Certificate[] x509CertificateArr, String str) throws CertificateException;
private native void nativeCheckServerTrusted(X509Certificate[] x509CertificateArr, String str) throws CertificateException;
private native X509Certificate[] nativeGetAcceptedIssuers();
public NianticTrustManager(Context context, long nativeClassPointer) {
super(context, nativeClassPointer);
}
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
synchronized (this.callbackLock) {
nativeCheckServerTrusted(chain, authType);
}
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
synchronized (this.callbackLock) {
nativeCheckServerTrusted(chain, authType);
}
}
public X509Certificate[] getAcceptedIssuers() {
X509Certificate[] nativeGetAcceptedIssuers;
synchronized (this.callbackLock) {
nativeGetAcceptedIssuers = nativeGetAcceptedIssuers();
}
return nativeGetAcceptedIssuers;
}
public static X509TrustManager getTrustManager(KeyStore keystore) {
return getTrustManager(TrustManagerFactory.getDefaultAlgorithm(), keystore);
}
public static X509TrustManager getTrustManager(String algorithm, KeyStore keystore) {
try {
TrustManagerFactory factory = TrustManagerFactory.getInstance(algorithm);
factory.init(keystore);
for (TrustManager tm : factory.getTrustManagers()) {
if (tm != null && (tm instanceof X509TrustManager)) {
return (X509TrustManager) tm;
}
}
} catch (NoSuchAlgorithmException e) {
} catch (KeyStoreException e2) {
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment