获取错误版本的密钥库。在安卓中

huangapple go评论133阅读模式
英文:

Getting Wrong version of key store. in android

问题

我正在使用一个JKS文件来注册密钥库,但是在下面的代码中出现了“密钥库的版本错误”。

TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());

InputStream keyStoreStream = mContext.getResources().openRawResource(R.raw.ssokeystore);
keyStore.load(keyStoreStream, "<<Password>>".toCharArray());//即使提供了正确的密码,仍然在这里出现错误

trustManagerFactory.init(keyStore);
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustManagers, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

可能的原因是什么?我的主要用例是允许应用程序发出的任何https调用通过注册证书。

以下是堆栈跟踪:

W/System.err: java.io.IOException: Wrong version of key store.
W/System.err:     at com.android.org.bouncycastle.jcajce.provider.keystore.bc.BcKeyStoreSpi.engineLoad(BcKeyStoreSpi.java:815)
W/System.err:     at java.security.KeyStore.load(KeyStore.java:1484)
W/System.err:     at net.openid.appauthdemo.TrustStoreConfiguration.ssoTtrustStore(TrustStoreConfiguration.java:32)
W/System.err:     at net.openid.appauthdemo.LoginActivity.onCreate(LoginActivity.java:117)
W/System.err:     at android.app.Activity.performCreate(Activity.java:7224)
W/System.err:     at android.app.Activity.performCreate(Activity.java:7213)
W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2926)
W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
W/System.err:     at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
W/System.err:     at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
W/System.err:     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:106)
W/System.err:     at android.os.Looper.loop(Looper.java:201)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6810)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
英文:

I am making a keystore get registered using a jks file but getting "Wrong version of key store." with the below code

TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
InputStream keyStoreStream=mContext.getResources().openRawResource(R.raw.ssokeystore);
keyStore.load(keyStoreStream, &quot;&lt;&lt;Password&gt;&gt;&quot;.toCharArray());//Getting the error here even giving the right password
trustManagerFactory.init(keyStore);
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
SSLContext sc = SSLContext.getInstance(&quot;SSL&quot;);
sc.init(null, trustManagers, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

What could be the reason for it, My main use case is to allow any https calls made from the application by registering the certificate

Here is the stacktrace

W/System.err: java.io.IOException: Wrong version of key store.
W/System.err:     at com.android.org.bouncycastle.jcajce.provider.keystore.bc.BcKeyStoreSpi.engineLoad(BcKeyStoreSpi.java:815)
W/System.err:     at java.security.KeyStore.load(KeyStore.java:1484)
W/System.err:     at net.openid.appauthdemo.TrustStoreConfiguration.ssoTtrustStore(TrustStoreConfiguration.java:32)
W/System.err:     at net.openid.appauthdemo.LoginActivity.onCreate(LoginActivity.java:117)
W/System.err:     at android.app.Activity.performCreate(Activity.java:7224)
W/System.err:     at android.app.Activity.performCreate(Activity.java:7213)
W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2926)
W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
W/System.err:     at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
W/System.err:     at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
W/System.err:     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:106)
W/System.err:     at android.os.Looper.loop(Looper.java:201)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6810)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

答案1

得分: 1

你的KeyStore是哪种类型,它在哪个操作系统版本上崩溃?根据KeyStore文档,在Android平台上支持以下类型

获取错误版本的密钥库。在安卓中

英文:

What type is your KeyStore, and what OS version is it crashing on? According to the KeyStore documentation, the following types are supported on the Android platform:

获取错误版本的密钥库。在安卓中

答案2

得分: 0

最简单的解决方法(截至2021年10月,在Android上保证有效)是从现有的Java KeyStore切换到BouncyCastle KeyStore(BKS)。

打开你的KeyStore文件,然后使用KeyStore Explorer(可在网上下载的Mac和Windows可执行文件)切换到BKS。

英文:

Easiest way to solve (guaranteed to work on Android, as of Oct 2021) is to switch from your existing Java KeyStore to BouncyCastle KeyStore (BKS).

Open your KeyStore file, and then use KeyStore Explorer (downloadable executable for Mac and Windows available online) to switch to BKS.

huangapple
  • 本文由 发表于 2020年7月25日 02:15:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/63079308.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定