如何以编程方式安装在Android的CA证书(对于EAP无线网络配置)?无线网络、证书、方式、安装在

2023-09-06 02:20:15 作者:爷、你惹不起

我的目标: 创建EAP无线网络配置 - 包括CA证书 - 在Android中programmitcally

My objective: Create an EAP WiFi configuration - including the CA Certificate - in Android programmitcally.

问题: 如何以编程方式安装CA证书(然后引用了EAP无线网络配置的证书)?

Problem: How do I install a CA Certificate programmatically (and then reference that certificate in the EAP WiFi configuration)?

我已经找到一个非常有用的链接,可以让我在这里创建和保存EAP无线网络配置: How以编程方式创建和读​​取WEP / EAP无线网络配置,Android的?

I found a very useful link already that allows me to create and save EAP WiFi configurations here: How to programatically create and read WEP/EAP WiFi configurations in Android?

然而,这假定您已经安装了CA证书在设备上。我想安装在我的应用程序的证书 - 无论是从应用程序的资源,或从服务器发送

However this assumes that you have already installed the CA Certificate on the device. I would like to install the certificate within my app - either from the resources in the app, or sent from a server.

这甚至可能吗? (生根不是在这种情况下的一个选项)。 如果是这样,怎么样?

Is this even possible? (Rooting is not an option in this case.) If so, how?

更多信息...

我还发现了一种证书添加到密钥库: http://stackoverflow.com/a/4490543/1172101

I also found a way to add a certificate to a KeyStore: http://stackoverflow.com/a/4490543/1172101

然而,这是专门用于创建安全套接字并通过HTTPS连接。我想使用无线网络的证书。

However this is used specifically for creating a secure socket and connecting via HTTPS. I want to use the certificate for WiFi.

不幸的是,我还没有找到一种方法来安装CA证书编程 - 从应用程序内

Unfortunately, I have yet to find a way to install a CA Certificate programmatically - from within the app.

然而,有可能通过在机器人的Web浏览器中安装证书。因此,该溶液(现在)是:以 启动一个意图打开,直接作用到CA证书的Web浏览器的URL。

However, it is possible to install a certificate via the Web browser in Android. Thus, the solution (for now) is to: Launch an intent to open a URL in the Web browser that goes directly to the CA certificate.

这个工作,但也有一些挑战:

This works but there are some challenges:

用户必须命名证书。这是一个挑战,因为我们加入了WiFi配置programmitically。因此,我们必须要求用户给该证书的名称相同。 用户必须输入密码。如果他们没有密码设置,用户将创建一个与输入两次。如果他们已经设置了安全密码,用户必须要记住,同样的口令,然后输入。 假设用户成功完成这些步骤后,他离开了挂在浏览器中。

这导致了几个问题:

从我的应用程序,有没有办法强制名用户通过浏览器?安装证书 从我的应用程序,有没有什么办法知道当证书安装完成,然后给焦点回到我的应用程序?

只要让我知道如果你需要任何澄清。

Just let me know if you need any clarification.

推荐答案

您不能直接安装,因为非系统应用程序没有访问密钥存储区。在ICS,对于这样的一个API KeyChain.createInstallIntent(),将推出一个系统对话框,询问用户是否要安装该证书。在pre-ICS则可以直接使用该组件名称(这可能会或可能不会在所有设备上工作,虽然)启动安装意图实现同样的事情。经过浏览器实际上是在做同样的事情的一种迂回的方式。

You cannot install it directly since non-system applications don't have access to the key store. On ICS, there is an API for this KeyChain.createInstallIntent() that would launch a system dialog asking the user whether they want to install the certificate. On pre-ICS you can achieve the same thing by launching the install intent using the component name directly (this may or may not work on all devices though). Going through the browser is actually a roundabout way of doing the same thing.

至于你的问题:

您不能指定/强制的名称。为什么你关心的实际名称? 在没有真正通过浏览器。如果您使用的系统的意图,您可以返回到您的活动,如果你使用会得到一个回调 startActivityForResult()

更新:安卓4.3有 WifiEnterpriseConfig 这两个创建配置文件并安装密钥和证书在系统证书存储区。你只需要在 CHANGE_WIFI_STATE 许可。

Update: Android 4.3 has WifiEnterpriseConfig which both creates a profile and installs keys and certificates in the system credential store. You only need the CHANGE_WIFI_STATE permission.