Adding Picasso support for self-signed certificates.
This commit is contained in:
@@ -42,7 +42,11 @@ public class IssuesService {
|
||||
MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(ctx);
|
||||
sslContext.init(null, new X509TrustManager[]{memorizingTrustManager}, new SecureRandom());
|
||||
|
||||
OkHttpClient okHttpClient = new OkHttpClient.Builder().cache(cache).sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager).hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier())).addInterceptor(new Interceptor() {
|
||||
OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
||||
.cache(cache)
|
||||
.sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager)
|
||||
.hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier()))
|
||||
.addInterceptor(new Interceptor() {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package org.mian.gitnex.clients;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
import com.squareup.picasso.OkHttp3Downloader;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import org.mian.gitnex.helpers.MemorizingTrustManager;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Objects;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
public class PicassoService {
|
||||
|
||||
private static PicassoService picassoService;
|
||||
private Picasso picasso;
|
||||
|
||||
private PicassoService(Context context) {
|
||||
|
||||
Picasso.Builder builder = new Picasso.Builder(context);
|
||||
|
||||
try {
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
|
||||
MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(context);
|
||||
sslContext.init(null, new X509TrustManager[]{memorizingTrustManager}, new SecureRandom());
|
||||
|
||||
OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder()
|
||||
.sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager)
|
||||
.hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier()));
|
||||
|
||||
builder.downloader(new OkHttp3Downloader(okHttpClient.build()));
|
||||
builder.listener((picasso, uri, exception) -> {
|
||||
|
||||
Log.e("PicassoService", Objects.requireNonNull(uri.toString())); // important!!
|
||||
Log.e("PicassoService", exception.toString());
|
||||
});
|
||||
|
||||
picasso = builder.build();
|
||||
}
|
||||
catch(Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Picasso get() {
|
||||
|
||||
return picasso;
|
||||
}
|
||||
|
||||
public static synchronized PicassoService getInstance(Context context) {
|
||||
|
||||
if(picassoService == null) {
|
||||
picassoService = new PicassoService(context);
|
||||
}
|
||||
|
||||
return picassoService;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,7 +42,11 @@ public class PullRequestsService {
|
||||
MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(ctx);
|
||||
sslContext.init(null, new X509TrustManager[]{memorizingTrustManager}, new SecureRandom());
|
||||
|
||||
OkHttpClient okHttpClient = new OkHttpClient.Builder().cache(cache).sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager).hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier())).addInterceptor(new Interceptor() {
|
||||
OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
||||
.cache(cache)
|
||||
.sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager)
|
||||
.hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier()))
|
||||
.addInterceptor(new Interceptor() {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
|
||||
@@ -42,9 +42,12 @@ public class RetrofitClient {
|
||||
MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(ctx);
|
||||
sslContext.init(null, new X509TrustManager[]{memorizingTrustManager}, new SecureRandom());
|
||||
|
||||
OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder().cache(cache)
|
||||
OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder()
|
||||
.cache(cache)
|
||||
//.addInterceptor(logging)
|
||||
.sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager).hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier())).addInterceptor(chain -> {
|
||||
.sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager)
|
||||
.hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier()))
|
||||
.addInterceptor(chain -> {
|
||||
|
||||
Request request = chain.request();
|
||||
if(connToInternet) {
|
||||
|
||||
Reference in New Issue
Block a user