How to point OpenSSL to root certificates on an Android device?

I was able to cross-compile OpenSSL for ARMv6 for use with the Android NDK and make it work in my application. However, when I try to establish an HTTPS connection with a known host (for example, https://google.com ), I always get the error message "SSL certificate is invalid."

However, it is not difficult for me to display protected pages in any of the device browsers (brochure browser, Chrome, Firefox, etc.). Therefore, I can only assume that OpenSSL does not find the root certificates stored on the device.

Then my question breaks down into two very related questions:

  • Where does Android store root certificates on the device?
  • How can I point OpenSSL to them?
+6
source share
3 answers

Where does Android store root certificates on the device?

He is moving. With the advent of Ice Cream Sandwich (ICS), three stores are used. Three stores: /data/misc/keychain (supplied by Android), /data/misc/keychain/cacerts-added (added by CA users) and /data/misc/keychain/cacerts-removed (deleted by users or updates).

Prior to ICS, they used the BouncyCastle store located at /system/etc/security/cacerts.bks . It was a static store and could not be changed. If this needs to be changed, you need to update the firmware or image.

For an explanation of stores, see ICS Trust Store Implementation. His blog is Nikolai Elenkov, and he copes with the discussion of the system, and not just where the stores are.


How can I point OpenSSL to them?

You cannot do this, because what OpenSSL expects and what Android represents is two different presentation / storage formats. OpenSSL expects the collection of trust bindings in PEM format to be combined together. But the Android trust store is not in this format.

It often happens that you download cacert.pem . You then load them by calling SSL_CTX_load_verify_locations , specifying cacert.pem as the CAfile argument.

Even if you download cacert.pem from a trusted source, such as Mozilla or cURL, you still need to go through it and make sure you are happy with the collection of trusted bindings. The package has 155 potential trust anchors:

 $ cat cacert.pem | grep BEGIN | wc -l 155 

But, as I said in a comment, it implicitly uses the browser security model, and this is not a very good way to do something in many cases.


when I try to establish an HTTPS connection with a known host (for example, https://google.com ), I always get the error message "The SSL certificate is not valid.

To answer this question, simply use Google Internet Authority or GeoTrust Global CA with SSL_CTX_load_verify_locations . It is probably best used by the Google Internet Authority because it restricts network transmission.

Google Internet Administration :

 -----BEGIN CERTIFICATE----- MIID8DCCAtigAwIBAgIDAjp2MA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNVBAYTAlVT MRYwFAYDVQQKEw1HZW9UcnVzdCB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5kaFOSPeCpilKIn Z57QzxpeR+nBsqTP3UEaBU6bS+5Kb1VSsyShNwrrZHYqLizz/Tt1kL/6cdjHPTfS tQWVYrmm3ok9Nns4d0iXrKYgjy6myQzCsplFAMfOEVEiIuCl6rYVSAlk6l5PdPcF PseKUgzbFbS9bZvlxrFUaKnjaZC2mqUPuLk/IH2uSrW4nOQdtqvmlKXBx4Ot2/Un hw4EbNX/3aBd7YdStysVAq45pmp06drE57xNNB6pXE0zX5IJL4hmXXeXxx12E6nV 5fEWCRE11azbJHFwLJhWC9kXtNHjUStedejV0NxPNO3CBWaAocvmMw== -----END CERTIFICATE----- 

In an ideal world, you run a private PKI, and you only trust your PKI root to certify sites and services. You do not trust the public certification authority to confirm anything because they do not give any guarantees to the relying party. Essentially, a public CA tells you that their warez are not good, even if they sell them on sites.

In the next best world, you only use the public certification authority that certified the site. This means that you use Google Internet Authority or GeoTrust Global CA to certify Google properties; not, say Diginotar .

There are other ill-conceived problems. The Google Internet Authority is a subordinate CA without restrictions , certified by GeoTrust. Google can issue certificates for any site, not just Google properties. This is usually delayed by the RA, which is in fact an independent auditor who validates the signature request in the CA before release. But in this model, the organization that creates the request (Google) is the same organization that validates the request (Google) and the same organization that issues the certificate (Google). Browsers, CA and PKI are the only instance that, as far as I know, the independent auditor has been completely removed as a balance sheet because it was too inconvenient .

If you think that a subordinate would not do this, then you would be sadly mistaken. CNICC was simply removed from several browser trust stores because one of its unconditional subordinates was caught issuing certificates for sites and services that it did not authorize.

If the browser’s security model does break, this is an opportunity for the wrong CA to certify the site. And this includes successful phishing attempts for the user. That is, the browser will happily allow connection interception, since the user was phishing.

If you think about the upcoming opening of a public key with overrides will help, then you will be sadly mistaken. Although they almost never mention overrides, an attacker can tear a well-known good pinset. And even worse, the reporting feature is disabled for a broken tweezer with SHOULD NOT RESPOND , so the browser is involved in the cover.

There is much more information available on this subject. To get started, try Peter Gutmann Engineering Safety and Audun Jøsang Trust Extortion on the Internet .

+5
source
  • Where android root certificates are stored:

They move from version to version and device to device in accordance with many questions about adding certificates to the local keystore on different devices. Most of them require the device to be deployed, and subsequent comments indicate a break in the solution, as they move or change the format on a specific device.

  • How can I point openssl to them:

I'm not sure there is a “good” way to do this right now. The best workaround I could find is this answer , followed by dragging and dropping these certificates into your own application store that opensl understands.

Wrong solution, but you can use it.

+3
source

Where android root certificates are stored:

  • System certificates: they are stored in System/etc/security/cacerts.bks

  • ThirdParty certificates: they are stored in data/misc/keystore

How can I point openssl to them:

Android OS combined with your openssl library will take care of this. You do not need to specify it manually.

With the information you provided, I write below.

Given that you are an application, this is an application for VPN or clouds.

Perhaps the problem is due to the invalid SSL Root CA that you installed on the device to check SSL traffic.

Hope this helps

+1
source

All Articles