Skip to content

Commit

Permalink
Merge pull request Fuzion24#11 from jakev/non_existing_class
Browse files Browse the repository at this point in the history
Check for TrustManagerImpl before hooking
  • Loading branch information
Fuzion24 committed Nov 5, 2015
2 parents 26bc1d8 + b03a283 commit 147d5be
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions app/src/main/java/just/trust/me/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,17 @@ protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
/* JSSE Hooks */
/* libcore/luni/src/main/java/javax/net/ssl/TrustManagerFactory.java */
/* public final TrustManager[] getTrustManager() */
findAndHookMethod("javax.net.ssl.TrustManagerFactory", lpparam.classLoader, "getTrustManagers", new XC_MethodHook() {
findAndHookMethod("javax.net.ssl.TrustManagerFactory", lpparam.classLoader, "getTrustManagers", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Class<?> cls = findClass("com.android.org.conscrypt.TrustManagerImpl", lpparam.classLoader);

TrustManager[] managers = (TrustManager[])param.getResult();
if(managers.length > 0 && cls.isInstance(managers[0]))
return;
if (hasTrustManagerImpl()) {
Class<?> cls = findClass("com.android.org.conscrypt.TrustManagerImpl", lpparam.classLoader);

TrustManager[] managers = (TrustManager[])param.getResult();
if(managers.length > 0 && cls.isInstance(managers[0]))
return;
}

param.setResult(new TrustManager[]{new ImSureItsLegitTrustManager()});
}
Expand Down Expand Up @@ -204,18 +207,36 @@ protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
}
});

/* external/conscrypt/src/platform/java/org/conscrypt/TrustManagerImpl.java#217 */
/* public List<X509Certificate> checkServerTrusted(X509Certificate[] chain, String authType, String host) throws CertificateException */
findAndHookMethod("com.android.org.conscrypt.TrustManagerImpl", lpparam.classLoader, "checkServerTrusted", X509Certificate[].class, String.class, String.class, new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
ArrayList<X509Certificate> list = new ArrayList<X509Certificate>();
return list;
}
});
/* Only for newer devices should we try to hook TrustManagerImpl */
if (hasTrustManagerImpl()) {

/* external/conscrypt/src/platform/java/org/conscrypt/TrustManagerImpl.java#217 */
/* public List<X509Certificate> checkServerTrusted(X509Certificate[] chain,
String authType, String host) throws CertificateException */
findAndHookMethod("com.android.org.conscrypt.TrustManagerImpl", lpparam.classLoader,
"checkServerTrusted", X509Certificate[].class, String.class,
String.class, new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
ArrayList<X509Certificate> list = new ArrayList<X509Certificate>();
return list;
}
});
}
} // End Hooks

/* Helpers */
// Check for TrustManagerImpl class
public boolean hasTrustManagerImpl() {

try {
Class.forName("com.android.org.conscrypt.TrustManagerImpl");
} catch(ClassNotFoundException e) {
return false;
}
return true;
}

//Create a SingleClientConnManager that trusts everyone!
public ClientConnectionManager getSCCM() {

Expand Down
Binary file modified bin/JustTrustMe.apk
Binary file not shown.

0 comments on commit 147d5be

Please sign in to comment.