Skip to content

Instantly share code, notes, and snippets.

@Leaking
Created December 4, 2017 09:45
Show Gist options
  • Save Leaking/e15760ff075cd5a1cbe993d6c6b9299b to your computer and use it in GitHub Desktop.
Save Leaking/e15760ff075cd5a1cbe993d6c6b9299b to your computer and use it in GitHub Desktop.
getTrustManagerFromSSLSocketFactory
// 18(samsung) 19 (oppo) sslSocketFactory -- sslParameters -- trustManager
// 22(oppo) 24(hw) 27(nexus) sslSocketFactory -- sslParameters -- x509TrustManager
public TrustManager getTrustManagerFromSSLSocketFactory(SSLSocketFactory sslSocketFactory) {
try {
TrustManager result = null;
Field fieldSslPm = sslSocketFactory.getClass().getDeclaredField("sslParameters");
fieldSslPm.setAccessible(true);
Object objSSLParameters = fieldSslPm.get(sslSocketFactory);
if(Build.VERSION.SDK_INT > 19) {
Field fieldTmg = objSSLParameters.getClass().getDeclaredField("x509TrustManager");
fieldTmg.setAccessible(true);
result = (TrustManager)fieldTmg.get(objSSLParameters);
} else {
Field fieldTmg = objSSLParameters.getClass().getDeclaredField("trustManager");
fieldTmg.setAccessible(true);
result = (TrustManager)fieldTmg.get(objSSLParameters);
}
return result;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment