I am using Glide to load images in imageview.
Glide.with(getApplicationInstance()).load(imageUrl).placeholder(R.drawable.no_image).error(R.drawable.no_image).diskCacheStrategy(DiskCacheStrategy.RESOURCE).into(imgView);
It is working for http images but not with https in Android OS 4,5. image urls are using SSL self signed certificate. and its not loading in imageview.
From Glide Listener error:
javax.net.ssl.SSLHandshakeException(java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.)
call GlideException#logRootCauses(String) for more detail
I've tried to add GlideModule from https://futurestud.io/tutorials/glide-module-example-accepting-self-signed-https-certificates Result : App is not showing that screen. I am not able to find the logs for this crash as its doing quick.
I have used below GlideModule but still not working for Android prelollipop version.
@GlideModule
public class KioskGlideModule extends AppGlideModule {
@Override
public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
super.registerComponents(context, glide, registry);
OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder();
enableTls12OnPreLollipop(okHttpClient);
registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(okHttpClient.build()));
}
@Override
public boolean isManifestParsingEnabled() {
return false;
}
public static OkHttpClient.Builder enableTls12OnPreLollipop(OkHttpClient.Builder client) {
if (Build.VERSION.SDK_INT >= 16 && Build.VERSION.SDK_INT < 22) {
TrustManagerFactory tmf = null;
// Create a KeyStore containing our trusted CAs
String keyStoreType = KeyStore.getDefaultType();
KeyStore trustedKeyStore = null;
try {
trustedKeyStore = KeyStore.getInstance(keyStoreType);
} catch (KeyStoreException e) {
e.printStackTrace();
}
try {
trustedKeyStore.load(null, null);
} catch (IOException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (CertificateException e) {
e.printStackTrace();
}
// Create a TrustManager that trusts the CAs in our KeyStore
String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
try {
tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
try {
tmf.init(trustedKeyStore);
} catch (KeyStoreException e) {
e.printStackTrace();
}
try {
SSLContext sc = SSLContext.getInstance("TLSv1.2");
sc.init(null, null, null);
client.sslSocketFactory(new TlS12SocketFactory(), (X509TrustManager) (tmf.getTrustManagers()[0]));
ConnectionSpec cs = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.tlsVersions(TlsVersion.TLS_1_2)
.build();
List<ConnectionSpec> specs = new ArrayList<>();
specs.add(cs);
specs.add(ConnectionSpec.COMPATIBLE_TLS);
specs.add(ConnectionSpec.CLEARTEXT);
client.connectionSpecs(specs);
} catch (Exception exc) {
Log.e("OkHttpTLSCompat", "Error while setting TLS 1.2", exc);
}
}
return client;
}
}
Help to solve this issue. Thanks in advance!!