Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
R
RatelExtension
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ratel
RatelExtension
Commits
3719a922
Commit
3719a922
authored
Aug 15, 2020
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixJustTrustMe for android 9.0
parent
1bd498d3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
36 deletions
+85
-36
JustTrustMe.java
...main/java/com/virjar/ratel/api/extension/JustTrustMe.java
+85
-36
No files found.
src/main/java/com/virjar/ratel/api/extension/JustTrustMe.java
View file @
3719a922
...
...
@@ -2,7 +2,6 @@ package com.virjar.ratel.api.extension;
import
android.annotation.SuppressLint
;
import
android.content.Context
;
import
android.net.http.SslError
;
import
android.util.Log
;
import
android.webkit.SslErrorHandler
;
...
...
@@ -11,6 +10,7 @@ import android.webkit.WebView;
import
com.virjar.ratel.api.RatelToolKit
;
import
com.virjar.ratel.api.rposed.RC_MethodHook
;
import
com.virjar.ratel.api.rposed.RC_MethodReplacement
;
import
com.virjar.ratel.api.rposed.RposedBridge
;
import
com.virjar.ratel.api.rposed.RposedHelpers
;
import
org.apache.http.conn.ClientConnectionManager
;
...
...
@@ -24,6 +24,7 @@ import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import
org.apache.http.params.HttpParams
;
import
java.io.IOException
;
import
java.lang.reflect.Method
;
import
java.net.Socket
;
import
java.security.KeyManagementException
;
import
java.security.KeyStore
;
...
...
@@ -65,6 +66,42 @@ public class JustTrustMe {
//do nothing
}
private
static
void
trustAllCertificateInternal
()
throws
Throwable
{
currentPackageName
=
RatelToolKit
.
packageName
;
//这个需要第一个
trustAndroidRootTrustManager
();
trustApache
();
trustJSSE
();
trustWebView
();
trustConscrypt
();
//SSLContext.init >> (null,ImSureItsLegitTrustManager,null)
RposedHelpers
.
findAndHookMethod
(
"javax.net.ssl.SSLContext"
,
RatelToolKit
.
sContext
.
getClassLoader
(),
"init"
,
KeyManager
[].
class
,
TrustManager
[].
class
,
SecureRandom
.
class
,
new
RC_MethodHook
()
{
@Override
protected
void
beforeHookedMethod
(
MethodHookParam
param
)
throws
Throwable
{
param
.
args
[
0
]
=
null
;
param
.
args
[
1
]
=
new
TrustManager
[]{
new
ImSureItsLegitTrustManager
()};
param
.
args
[
2
]
=
null
;
}
});
processOkHttp
(
RatelToolKit
.
hostClassLoader
);
processHttpClientAndroidLib
(
RatelToolKit
.
hostClassLoader
);
processXutils
(
RatelToolKit
.
hostClassLoader
);
}
// End Hooks
private
interface
ClassExistEvent
{
void
onClassFind
(
Class
clazz
);
}
...
...
@@ -80,11 +117,34 @@ public class JustTrustMe {
}
}
private
static
boolean
hasAndroidRootTrustManager
=
false
;
private
static
void
trustAllCertificateInternal
()
throws
Throwable
{
currentPackageName
=
RatelToolKit
.
packageName
;
private
static
void
trustAndroidRootTrustManager
()
{
try
{
Class
.
forName
(
"android.security.net.config.RootTrustManager"
,
false
,
RatelToolKit
.
hostClassLoader
);
}
catch
(
Throwable
throwable
)
{
return
;
}
hasAndroidRootTrustManager
=
true
;
hookIfClassExist
(
"android.security.net.config.RootTrustManager"
,
new
ClassExistEvent
()
{
@Override
public
void
onClassFind
(
Class
clazz
)
{
for
(
Method
method
:
clazz
.
getDeclaredMethods
())
{
if
(
method
.
getName
().
equals
(
"checkServerTrusted"
)
&&
method
.
getReturnType
().
equals
(
Void
.
class
))
{
RposedBridge
.
hookMethod
(
method
,
new
RC_MethodReplacement
()
{
@Override
protected
Object
replaceHookedMethod
(
MethodHookParam
param
)
throws
Throwable
{
return
null
;
}
});
}
}
}
});
}
private
static
void
trustApache
()
{
/* Apache Hooks */
/* external/apache-http/src/org/apache/http/impl/client/DefaultHttpClient.java */
/* public DefaultHttpClient() */
...
...
@@ -205,7 +265,9 @@ public class JustTrustMe {
}
});
}
private
static
void
trustJSSE
()
{
/* JSSE Hooks */
/* libcore/luni/src/main/java/javax/net/ssl/TrustManagerFactory.java */
/* public final TrustManager[] getTrustManager() */
...
...
@@ -221,6 +283,15 @@ public class JustTrustMe {
if
(
managers
.
length
>
0
&&
cls
.
isInstance
(
managers
[
0
]))
return
;
}
TrustManager
[]
trustManagers
=
(
TrustManager
[])
param
.
getResult
();
for
(
TrustManager
trustManager
:
trustManagers
)
{
Class
<?
extends
TrustManager
>
aClass
=
trustManager
.
getClass
();
//Android 9以后,被 android.security.net.config.RootTrustManager管理
//此时不能替换为ImSureItsLegitTrustManager
if
(
aClass
.
getName
().
equals
(
"android.security.net.config.RootTrustManager"
))
{
return
;
}
}
param
.
setResult
(
new
TrustManager
[]{
new
ImSureItsLegitTrustManager
()});
}
...
...
@@ -258,8 +329,10 @@ public class JustTrustMe {
return
null
;
}
});
}
private
static
void
trustWebView
()
{
/* WebView Hooks */
/* frameworks/base/core/java/android/webkit/WebViewClient.java */
/* public void onReceivedSslError(Webview, SslErrorHandler, SslError) */
...
...
@@ -285,37 +358,9 @@ public class JustTrustMe {
return
null
;
}
});
}
//SSLContext.init >> (null,ImSureItsLegitTrustManager,null)
RposedHelpers
.
findAndHookMethod
(
"javax.net.ssl.SSLContext"
,
RatelToolKit
.
sContext
.
getClassLoader
(),
"init"
,
KeyManager
[].
class
,
TrustManager
[].
class
,
SecureRandom
.
class
,
new
RC_MethodHook
()
{
@Override
protected
void
beforeHookedMethod
(
MethodHookParam
param
)
throws
Throwable
{
param
.
args
[
0
]
=
null
;
param
.
args
[
1
]
=
new
TrustManager
[]{
new
ImSureItsLegitTrustManager
()};
param
.
args
[
2
]
=
null
;
}
});
// Multi-dex support: https://github.com/rovo89/XposedBridge/issues/30#issuecomment-68486449
RposedHelpers
.
findAndHookMethod
(
"android.app.Application"
,
RatelToolKit
.
sContext
.
getClassLoader
(),
"attach"
,
Context
.
class
,
new
RC_MethodHook
()
{
@Override
protected
void
afterHookedMethod
(
MethodHookParam
param
)
throws
Throwable
{
// Hook OkHttp or third party libraries.
Context
context
=
(
Context
)
param
.
args
[
0
];
processOkHttp
(
context
.
getClassLoader
());
processHttpClientAndroidLib
(
context
.
getClassLoader
());
processXutils
(
context
.
getClassLoader
());
}
}
);
private
static
void
trustConscrypt
()
{
/* Only for newer devices should we try to hook TrustManagerImpl */
if
(
hasTrustManagerImpl
())
{
/* TrustManagerImpl Hooks */
...
...
@@ -359,8 +404,8 @@ public class JustTrustMe {
//
}
}
}
}
// End Hooks
/* Helpers */
// Check for TrustManagerImpl class
...
...
@@ -368,7 +413,7 @@ public class JustTrustMe {
private
static
boolean
hasTrustManagerImpl
()
{
try
{
Class
.
forName
(
"com.android.org.conscrypt.TrustManagerImpl"
);
Class
.
forName
(
"com.android.org.conscrypt.TrustManagerImpl"
,
false
,
RatelToolKit
.
hostClassLoader
);
}
catch
(
ClassNotFoundException
e
)
{
return
false
;
}
...
...
@@ -586,6 +631,10 @@ public class JustTrustMe {
public
void
checkServerTrusted
(
X509Certificate
[]
chain
,
String
authType
)
throws
CertificateException
{
}
@SuppressLint
(
"TrustAllX509TrustManager"
)
public
void
checkServerTrusted
(
X509Certificate
[]
chain
,
String
authType
,
String
str2
,
String
str3
)
throws
CertificateException
{
}
@Override
public
X509Certificate
[]
getAcceptedIssuers
()
{
return
new
X509Certificate
[
0
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment