Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing self-signed certificate programmatically

I'm launching the KeyChain intent for installing a self-signed certificate that I have on memory as X509Certificate Object (got by the X509TrustManager, by the checkServerTrusted method). With this code:

Intent intent = KeyChain.createInstallIntent();
intent.putExtra(KeyChain.EXTRA_CERTIFICATE, certs[0].getEncoded());
intent.putExtra(KeyChain.EXTRA_NAME, "certificate");
context.startActivityForResult(intent,  0);

New activity is launched and I can get the message "certificate is installed", but I can't find it through Security certificates list, and when trying to connect to that host, it seems not to be installed.

Any idea about how to solve it?

like image 394
Jose Angel Zamora Avatar asked Nov 12 '22 20:11

Jose Angel Zamora


1 Answers

The Security Certificates List screen that you mention only contains a list of trusted CA certificates that you have added to the Android device. (Note: the system list of certificates is the list of trusted CAs that the device manufacturer has set). There is no screen (on a non-rooted phone at least) that shows you the KeyChain's certificates.

In order for an app to access a certificate/key, it needs to ask the OS for permission. To do this, the KeyChain class has a method called choosePrivateKeyAlias, which shows the user an activity to select which certificate the app can have access to. This activity should list any imported certificates that you have installed using the method above.

See the link below for more details.

Unifying Key Store Access in ICS

like image 72
ktambascio Avatar answered Nov 15 '22 11:11

ktambascio