Created
December 4, 2017 09:45
-
-
Save Leaking/e15760ff075cd5a1cbe993d6c6b9299b to your computer and use it in GitHub Desktop.
getTrustManagerFromSSLSocketFactory
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
// 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