My app keeps crashing on Android 10 when I try to load a p12 certificate from the asset folder.
My file is fine.
This code always worked on previous Android versions.
AssetManager assetManager = ctx.getAssets();
AssetFileDescriptor fileDescriptor = assetManager.openFd(certificatePath);
FileInputStream fisCertificate = fileDescriptor.createInputStream();
KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(fisCertificate,"".toCharArray()); // no passwords here
...
fisCertificate.close();
I got the following error:
2021-01-22 14:51:02.447 26333-26333/bzh.toto.myapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: bzh.toto.myapp, PID: 26333
java.lang.RuntimeException: Unable to start activity ComponentInfo{bzh.toto.myapp/bzh.toto.myapp.SplashScreenActivity}: java.lang.RuntimeException: java.security.cert.CertificateException: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: java.lang.NullPointerException: gen->length < 14 || gen->data == null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3388)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3527)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2123)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7710)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.lang.RuntimeException: java.security.cert.CertificateException: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: java.lang.NullPointerException: gen->length < 14 || gen->data == null
at com.android.org.bouncycastle.jcajce.provider.keystore.pkcs12.PKCS12KeyStoreSpi.engineLoad(PKCS12KeyStoreSpi.java:1153)
at java.security.KeyStore.load(KeyStore.java:1484)
at bzh.toto.myapp.services.CertificateService.copyAssetCertificateToSDCard(CertificateService.java:133)
at bzh.toto.myapp.services.CertificateService.checkCertificatePresence(CertificateService.java:53)
at bzh.toto.myapp.utils.RealwearActivityUtils.checkCertificate(RealwearActivityUtils.java:72)
at bzh.toto.myapp.SplashScreenActivity.onCreate(SplashScreenActivity.java:48)
at android.app.Activity.performCreate(Activity.java:7820)
at android.app.Activity.performCreate(Activity.java:7809)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1318)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3363)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3527)?
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)?
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)?
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)?
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2123)?
at android.os.Handler.dispatchMessage(Handler.java:107)?
at android.os.Looper.loop(Looper.java:214)?
at android.app.ActivityThread.main(ActivityThread.java:7710)?
at java.lang.reflect.Method.invoke(Native Method)?
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)?
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Do you have any idea ? :) thanks
question from:
https://stackoverflow.com/questions/65848530/keystore-load-crash-on-android-10 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…