Merge branch 'develop' into feature/exchangeable-annotations
This commit is contained in:
commit
8a9bb5cabc
|
@ -21,6 +21,10 @@
|
||||||
- Removed `URLProtectionSpace.iosIsProxy` property
|
- Removed `URLProtectionSpace.iosIsProxy` property
|
||||||
- `historyUrl` and `baseUrl` of `InAppWebViewInitialData` can be `null`
|
- `historyUrl` and `baseUrl` of `InAppWebViewInitialData` can be `null`
|
||||||
|
|
||||||
|
## 5.4.4+3
|
||||||
|
|
||||||
|
- Removed Android unsafe trust manager
|
||||||
|
|
||||||
## 5.4.4+2
|
## 5.4.4+2
|
||||||
|
|
||||||
- Fixed LICENSE
|
- Fixed LICENSE
|
||||||
|
|
|
@ -148,50 +148,12 @@ public class Util {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OkHttpClient getUnsafeOkHttpClient() {
|
public static OkHttpClient getBasicOkHttpClient() {
|
||||||
try {
|
return new OkHttpClient.Builder()
|
||||||
// Create a trust manager that does not validate certificate chains
|
.connectTimeout(15, TimeUnit.SECONDS)
|
||||||
final TrustManager[] trustAllCerts = new TrustManager[] {
|
.writeTimeout(15, TimeUnit.SECONDS)
|
||||||
new X509TrustManager() {
|
.readTimeout(15, TimeUnit.SECONDS)
|
||||||
@Override
|
.build();
|
||||||
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
|
||||||
return new java.security.cert.X509Certificate[]{};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Install the all-trusting trust manager
|
|
||||||
final SSLContext sslContext = SSLContext.getInstance("SSL");
|
|
||||||
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
|
|
||||||
// Create an ssl socket factory with our all-trusting manager
|
|
||||||
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
|
|
||||||
|
|
||||||
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
|
||||||
builder.sslSocketFactory(sslSocketFactory, (X509TrustManager)trustAllCerts[0]);
|
|
||||||
builder.hostnameVerifier(new HostnameVerifier() {
|
|
||||||
@Override
|
|
||||||
public boolean verify(String hostname, SSLSession session) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
OkHttpClient okHttpClient = builder
|
|
||||||
.connectTimeout(15, TimeUnit.SECONDS)
|
|
||||||
.writeTimeout(15, TimeUnit.SECONDS)
|
|
||||||
.readTimeout(15, TimeUnit.SECONDS)
|
|
||||||
.build();
|
|
||||||
return okHttpClient;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,6 +22,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
|
||||||
|
import javax.net.ssl.SSLHandshakeException;
|
||||||
|
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
@ -183,7 +185,7 @@ public class ContentBlockerHandler {
|
||||||
Response response = null;
|
Response response = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response = Util.getUnsafeOkHttpClient().newCall(mRequest).execute();
|
response = Util.getBasicOkHttpClient().newCall(mRequest).execute();
|
||||||
byte[] dataBytes = response.body().bytes();
|
byte[] dataBytes = response.body().bytes();
|
||||||
InputStream dataStream = new ByteArrayInputStream(dataBytes);
|
InputStream dataStream = new ByteArrayInputStream(dataBytes);
|
||||||
|
|
||||||
|
@ -200,12 +202,14 @@ public class ContentBlockerHandler {
|
||||||
return new WebResourceResponse(contentType, encoding, dataStream);
|
return new WebResourceResponse(contentType, encoding, dataStream);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
response.body().close();
|
response.body().close();
|
||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
Log.e(LOG_TAG, e.getMessage());
|
if (!(e instanceof SSLHandshakeException)) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Log.e(LOG_TAG, e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -235,7 +239,7 @@ public class ContentBlockerHandler {
|
||||||
Request mRequest = new Request.Builder().url(url).head().build();
|
Request mRequest = new Request.Builder().url(url).head().build();
|
||||||
Response response = null;
|
Response response = null;
|
||||||
try {
|
try {
|
||||||
response = Util.getUnsafeOkHttpClient().newCall(mRequest).execute();
|
response = Util.getBasicOkHttpClient().newCall(mRequest).execute();
|
||||||
|
|
||||||
if (response.header("content-type") != null) {
|
if (response.header("content-type") != null) {
|
||||||
String[] contentTypeSplitted = response.header("content-type").split(";");
|
String[] contentTypeSplitted = response.header("content-type").split(";");
|
||||||
|
@ -255,8 +259,10 @@ public class ContentBlockerHandler {
|
||||||
response.body().close();
|
response.body().close();
|
||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
e.printStackTrace();
|
if (!(e instanceof SSLHandshakeException)) {
|
||||||
Log.e(LOG_TAG, e.getMessage());
|
e.printStackTrace();
|
||||||
|
Log.e(LOG_TAG, e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return responseResourceType;
|
return responseResourceType;
|
||||||
|
|
Loading…
Reference in New Issue