Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
66 views
in Technique[技术] by (71.8m points)

Keystore.load() crash on Android 10

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...