|
|
|
|
56
|
public static OkHttpClient.Builder getUnsafeOkHttpClient(OkHttpClient client) {
|
56
|
public static OkHttpClient.Builder getUnsafeOkHttpClient(OkHttpClient client) {
|
57
|
try {
|
57
|
try {
|
58
|
// Create a trust manager that does not validate certificate chains
|
58
|
// Create a trust manager that does not validate certificate chains
|
59
|
- final TrustManager[] trustAllCerts = new TrustManager[]{
|
|
|
60
|
- new X509TrustManager() {
|
|
|
61
|
- @Override
|
|
|
62
|
- public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
|
|
|
63
|
- }
|
|
|
64
|
-
|
|
|
65
|
- @Override
|
|
|
66
|
- public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
|
|
|
67
|
- }
|
|
|
68
|
-
|
|
|
69
|
- @Override
|
|
|
70
|
- public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
|
|
71
|
- return new java.security.cert.X509Certificate[]{};
|
|
|
72
|
- }
|
|
|
73
|
- }
|
|
|
|
|
59
|
+ final X509TrustManager x509TrustManager = new X509TrustManager() {
|
|
|
60
|
+ @Override
|
|
|
61
|
+ public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
|
|
|
62
|
+ }
|
|
|
63
|
+
|
|
|
64
|
+ @Override
|
|
|
65
|
+ public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
|
|
|
66
|
+ }
|
|
|
67
|
+
|
|
|
68
|
+ @Override
|
|
|
69
|
+ public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
|
|
70
|
+ return new java.security.cert.X509Certificate[]{};
|
|
|
71
|
+ }
|
74
|
};
|
72
|
};
|
|
|
73
|
+ final TrustManager[] trustAllCerts = new TrustManager[]{ x509TrustManager };
|
75
|
|
74
|
|
76
|
// Install the all-trusting trust manager
|
75
|
// Install the all-trusting trust manager
|
77
|
final SSLContext sslContext = SSLContext.getInstance("SSL");
|
76
|
final SSLContext sslContext = SSLContext.getInstance("SSL");
|
|
|
|
|
80
|
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
|
79
|
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
|
81
|
|
80
|
|
82
|
OkHttpClient.Builder builder = client.newBuilder();
|
81
|
OkHttpClient.Builder builder = client.newBuilder();
|
83
|
- builder.sslSocketFactory(sslSocketFactory);
|
|
|
|
|
82
|
+ builder.sslSocketFactory(sslSocketFactory, x509TrustManager);
|
84
|
builder.hostnameVerifier(new HostnameVerifier() {
|
83
|
builder.hostnameVerifier(new HostnameVerifier() {
|
85
|
@Override
|
84
|
@Override
|
86
|
public boolean verify(String hostname, SSLSession session) {
|
85
|
public boolean verify(String hostname, SSLSession session) {
|