如何防止Android应用程序中的ChoosePrivateKeyAlias对话框? [英] How to prevent choosePrivateKeyAlias dialog in android app?

查看:89
本文介绍了如何防止Android应用程序中的ChoosePrivateKeyAlias对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个android应用,可在webview中调用受保护的网站. Web视图检索证书以将其提供给网站.

I have an android app that call a secured website in a webview. The webview retrieve the certificate to give it to the website.

我必须使用KeyChain.choosePrivateKeyAlias(this, keyChainAliasCallback, null, null, null, -1, CERT_ALIAS);方法,这将显示类似这样的对话框

I have to use the KeyChain.choosePrivateKeyAlias(this, keyChainAliasCallback, null, null, null, -1, CERT_ALIAS); method, and this displays a dialog like this

我只想在用户第一次使用该应用程序时显示此窗口,但我不知道是否可能.

I'd want to display this window only the first time the user uses the app, but I don't know if it's possible.

我看到了有关使用设备/所有者配置文件进行拦截的信息.这是否意味着它应该在android上工作?对我来说有点模糊.

I saw about intercepting this with a device/owner profile. Does that mean that it should be on android work ? it's a little blurry to me.

另一种解决方案是保存证书和私钥,以便在任何其他应用程序或用户无法访问的地方首次访问.我考虑了私有模式下的SharedPreferences.

Another solution would be to save certificate and private key retrieve the first time somewhere inaccessible by any other app nor the user. I think about SharedPreferences in private mode.

我错了吗?

感谢您的回答!

推荐答案

我不确定解决此问题的最佳方法,但这是我所做的对我来说很好的方法.

I'm not sure about the best way to resolve this problem, but here is what I did that worked fine for me.

我在首选项中检查了一个布尔变量,如果它返回false,则显示choosePrivateKeyAlias窗口.如果返回true,则表明我有权直接检索证书,因此无需显示弹出窗口.

I checked a boolean variable in the preferences, and if it returns false, I display the choosePrivateKeyAlias window. If it returns true, I know that I have permission to retrieve the certificate directly, so there's no need to display the popup.

boolean isGranted = prefs.getBoolean("MY_CERT", false);
if(!isGranted) {
        //Get cert and private key from internal android store
        KeyChainAliasCallback keyChainAliasCallback = new KeyChainAliasCallback() {
            @Override
            public void alias(@Nullable String s) {
                Log.d(TAG, "selected alias = " + s);
                SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
                editor.putBoolean("MY_CERT", true);
                editor.commit();
                retriveCertsTask.execute();
            }
        };
        KeyChain.choosePrivateKeyAlias(mActivity, keyChainAliasCallback, null, null, null, -1, CERT_ALIAS);
    } else {
        // Retrieve certs an private key
        retriveCertsTask.execute();
    }
}

希望有帮助...

这篇关于如何防止Android应用程序中的ChoosePrivateKeyAlias对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆