Android 4.1.2: KeyStore BKS implementation not found

I have a problem with BouncyCastle-Format on Android 4.1.2.

In my application, I am using SSL-Pinning to protect my clients from MITM-Attack. The public ssl certificate is stored in the raw resource directory. Everything works fine, but on Android 4.1.2 it will work by initializing the KeyStore.

Devices currently affected are: Samsung GT18190 / GT18190N; Sony ST26I; LG P880 - all with Android 4.1.2

Here is my code for creating SSLSocketFactory:

import android.content.Context;

import java.io.InputStream;
import java.security.KeyStore;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;


public class SSLSocket {

public static javax.net.ssl.SSLSocketFactory newSslSocketFactory(Context ctx) {
    char[] KEYSTORE_PASSWORD = "MYKEYSTOREPASSWORD".toCharArray();
    try {
        KeyStore trusted = KeyStore.getInstance("BKS");
        InputStream in = ctx.getResources().openRawResource(R.raw.ssl);
        try {
            trusted.load(in, KEYSTORE_PASSWORD);
        } finally {
            in.close();
        }

        String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
        tmf.init(trusted);

        SSLContext context = SSLContext.getInstance("TLS");
        context.init(null, tmf.getTrustManagers(), null);

        return context.getSocketFactory();
    } catch (Exception e) {
        throw new AssertionError(e);
    }
}
}

      

The following exception is thrown:

java.lang.AssertionError: java.security.KeyStoreException: java.security.NoSuchAlgorithmException: KeyStore BKS implementation not found

Does anyone have an idea to fix the problem for Android 4.1.2?

+3


source to share





All Articles