Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to install CA certificate programmatically on Android without user interaction

Tags:

I'm trying to install certificates without prompting the user. I know this is not good practice, but that's what PM wants.

Using KeyChain.createInstallIntent(), I can get Android to launch the certificate installation dialog by calling startActivity. However, when I pass the intent to sendBroadcast, nothing happens. Maybe the platform doesn't support this for security reasons?

String CERT_FILE = Environment.getExternalStorageDirectory() + "/test/IAT.crt"; Intent intent = KeyChain.createInstallIntent(); try {     FileInputStream certIs = new FileInputStream(CERT_FILE);     byte [] cert = new byte[(int)certFile.length()];     certIs.read(cert);     X509Certificate x509 = X509Certificate.getInstance(cert);     intent.putExtra(KeyChain.EXTRA_CERTIFICATE, x509.getEncoded());      intent.putExtra(KeyChain.EXTRA_NAME, "IAT Cert");     EapActivity.this.startActivityForResult(intent, 0);  // this works but shows UI     EapActivity.this.sendBroadcast(intent);  // this doesn't install cert } catch (IOException e) { 
like image 506
Pedro Avatar asked Jul 25 '12 19:07

Pedro


People also ask

How do I install a CA certificate?

Steps to install SSL CA Certificate in WindowsGo to 'File' and click on Add/Remove Snap-in… Browse to the certificate file, Click Next, Select Trusted Root Certification Authorities, Click Next, and then Finish. You will be asked the security warning, click yes.

How can I take self signed certificate in Android?

Go to Settings / Security / Credential storage and select “Install from device storage”. The . crt file will be detected and you will be prompted to enter a certificate name. After importing the certificate, you will find it in Settings / Security / Credential storage / Trusted credentials / User.


1 Answers

You can only install certificates silently if you have system privileges. Showing up a confirmation dialog is intentional, since trusting certificates can have serious consequences -- Android could happily open phishing sites without a warning, etc. That said, the dialog in ICS/JB is pretty bad -- it doesn't tell you what certificate you are installing and who issued it, just that it's a CA certificate, which is kind of obvious.

So, either use the public KeyChain API and use startActivity() to get the confirmation dialog, or pre-provision devices before handling them to users.

Update: In Android 4.4, DevicePolicyManager has a hidden API (installCaCert) that allows you to install certificates silently. You need the MANAGE_CA_CERTIFICATES permission, which is signature|system, so still not doable for user-installed apps.

like image 77
Nikolay Elenkov Avatar answered Sep 28 '22 04:09

Nikolay Elenkov