Hello Viktor, Thanks for your reply. The reason that I am trying to use the OpenSSL instead of using a library like Volley on Android is: The original environment of the project is in a private network. Our network provider shells all threats for us. So our app is installed on devices that are only required unsecured connections between devices and servers. Now we need some features from the original firmware for a new android app. The app users are going to use the internet. So the secured connections are required. If we can use OpenSSL to handle handshake and certificate verification the same code can be reused on firmware and potentially allowing our devices to use the internet in the future.
> Almost certainly, but your question is rather oddly phrased and notcompletely > clear. PEM files don't establish connections. Instead of using all certs in the trust store, I was trying to use as few cert files as possible. And you are right PEM files do not establish connections. I need cert file to verify the server's certs before establishing connections. Currently, I know the URL of our web service. I created a client then I tried to copy some certs from the Ubuntu trust store. Found the cert `09789157.0` is able to verify our test servers' certs. Then, I copied the text from the file 09789157.0, hard-coded the content of the file in the code, created an X509 object based on the text, and using `X509_STORE_add_cert` to add the cert to a store in a SSL_CTX. It works on Android. But I am thinking I might just do what you mentioned: "If you just extract the certificates, without the associated trust settings, you may well end up undermining some of the expected security properties, because some restricted use certificates may then lose their associated restrictions." So, my question is what should I do to find out the "associated trust settings" and include those settings? Thanks for your help r0nG Auckland, New Zealand ________________________________ 发件人: openssl-users <openssl-users-boun...@openssl.org> 代表 Viktor Dukhovni <openssl-us...@dukhovni.org> 发送时间: 2021年3月3日 5:34 收件人: email@example.com <firstname.lastname@example.org> 主题: Re: Question: How to using cert files on Android platform? On Wed, Mar 03, 2021 at 01:56:31AM +0000, Yang Rong wrote: > I am new to OpenSSL. I am working on a project using JNI+ OpenSSL on > an Android App. Can you briefly explain your motivation for using OpenSSL via JNI, rather than just use the native android TLS APIs, which then just use the Android trust store? > The OpenSSL is not able to use certs in the Android trust store. The Android trust store is likely more fine-grained than you'd naively expect. Not all the trusted certificates are necessarily trusted for the same purposes. If you just extract the certificates, without the associated trust settings, you may well end up undermining some of the expected security properties, because some restricted use certificates may then lose their associated restrictions. > Do we have a way to use the Android trust store in 2021? The simplest and generally most appropriate answer is: via the Android APIs, and without JNI into OpenSSL. If you have a compelling reason to use OpenSSL, you'll probably need to provision a dedicated trust store of known to be appropriate trust anchors. > The target API level of the Android App is 28. If OpenSSL is > still not able to use the Android default trust stores nowadays. I > would like to copy the certs from Ubuntu to the Android app. If it is appropriate to trust the same root CAs (something probably along the lines of the Mozilla cert bundle), then you could do that, but why is this necessary? > But I need to figure out which pem file is used to establish > connections. Now it seems that you're not well versed in OpenSSL, which strongly suggests that it is really best to stick to the provided APIs, and not roll your own security toolkit. > Is there a way any OpenSSL command line cmd is able to do > that? Almost certainly, but your question is rather oddly phrased and not completely clear. PEM files don't establish connections. Are you looking to capture the entire Ubuntu trust store, or just the specific trust-anchor that is *currently* the ultimate issuer of the server's certificate chain? Do you have good reason to believe that the server will continue to use the same root CAs indefinitely? ... If your reasons for not using the Android APIs are not absolutely compelling, your best bet is to use those, despite whatever non-critical disadvantages are driving you to consider OpenSSL instead. -- Viktor.