日本語

TUTORIAL - Installation of certificates in the system credential storage

Table of contents

1. Introduction
2. Who should read this?
3. Preparations
3.1 Prepare SSL/TLS certificate files
3.1.1 Self-signed server certificate
3.1.2 Client certificate
3.2 Prepare a file management application
3.3 Set screen lock
4. Obtain SSL/TLS certificate files
4.1 Obtain via network
4.2 Obtain via offline works
5. Install SSL/TLS certificate files
5.1 Guide to the certificate installation screen
5.2 Install a self-signed server certificate
5.3 Install a client certificate
5.4 Check the installed self-signed server certificate
5.5 Check the installed client certificate

1. Introduction

When an Android device connects to the peer broker using SSL/TLS, the broker requests to present a client certificate and/or a self-signed server certificate to the Android device, depending on the broker setting. That is, you need to pre-install the required SSL/TLS certificates on the Android device.

There are two options how an Android application access to the SSL/TLS certificates.

* a) When you implement an Android application, embed the SSL/TLS certificate files as the asset of the program.
* b) Pre-install the required certificates in the system credential storage, and refer them on application runtime.

On the latter case b), you do not have to embed any sensitive information such like SSL/TLS certificates in a program.

* Even if the Android device has lost or stolen, sensitive information will not be leaked to the third party.
* Upon the expiration of SSL/TLS certificates, you can update them without modifying the program.

That is, you can reduce security threats because of above points. In this document, we focus on the case b) and present concrete procedures about how to install the SSL/TLS certificates in the Android system credential storage (KeyChain) [1].

The screen shots on this document are taken on a Google Pixel 4 (Android 11) device. There may be some differences of screen appearances or descriptive expressions depending on the OS version. Please read accordingly, based on the running environment of your Android device.

[1] Security features

2. Who should read this document?

If an Android device going to connect to a broker using SSL/TLS, required certificates must have prepared on the Android device. It depends the security policy on the broker side that determines what kind of certificates are required on the Android side.

To summarize, if your Android device connects to the broker which uses a server certificate signed by a commercial CA, and does not require any client certificate, then you can finish here. Otherwise, install appropriate SSL/TLS certificates on your Android device referring the following descriptions.

[2] Certificate authority

3. Preparations

3.1 Prepare SSL/TLS certificate files

Ask management staff to issue SSL/TLS certificate files to be installed on your Android device.

3.1.1 Self-signed server certificate

PC% file ./vm00_cacert.crt
./vm00_cacert.crt: PEM certificate

PC% openssl verify vm00_cacert.crt
vm00_cacert.crt: C = JP, ST = Example_State, O = Example_Organization, CN = private-ca
error 18 at 0 depth lookup:self signed certificate
OK

[3] X.509

3.1.2 Client certificate

PC% file ./client03*
./client03.pfx: data
./client03.txt: ASCII text

PC% openssl pkcs12 -in client03.pfx -info -noout
Enter Import Password:
MAC Iteration 2048
MAC verified OK
PKCS7 Encrypted data: pbeWithSHA1And40BitRC2-CBC, Iteration 2048
Certificate bag
PKCS7 Data
Shrouded Keybag: pbeWithSHA1And3-KeyTripleDES-CBC, Iteration 2048

[4] PKCS#12

3.2 Prepare a file management application

3.3 Set screen lock

This section is optional for Android 10 or later devices. [5]

If you install a user specified secret file in the system credential storage (KeyChain), you are required to set screen lock. With the fact that you can unlock screen, you passed the device authentication as the legitimate owner. Though you can proceed without setting screen lock, you will be prompted to do so at the time of SSL/TLS certificate installation.

    Home
    --> Settings
      --> Security
        --> Screen lock
          --> Choose a screen lock method (except "None" and "Swipe")

[5] KeyChain behavior changes and improvements

4. Obtain SSL/TLS certificate files

4.1 Obtain via network

4.2 Obtain via offline works

    1) Turn off power of your Android device.
    2) Remove the SD card from the chassis.
    3) Insert the SD card to your working PC and mount to the file system.
    4) Copy the target SSL/TLS certificate files to the SD card.
       Destination path can be anywhere, but root directory is handy.
    5) Unmount from the file system and eject the SD card.
    6) Insert the SD card to your Android device.
    7) Turn on power of your Android device.
# Android 10 or earlier
% adb push client03.pfx /mnt/sdcard
% adb push vm00_cacert.crt /mnt/sdcard
# Android 11
% adb push client03.pfx /mnt/sdcard
adb: error: stat failed when trying to push to /mnt/sdcard: Permission denied
 
% adb push client03.pfx /sdcard
% adb push vm00_cacert.crt /sdcard

[6] Android Debug Bridge (adb)

5. Install SSL/TLS certificate files

5.1 Guide to the certificate installation screen

Guide to the certificate installation screen

To manipulate certificates managed by the system credential storage (KeyChain), you need to dig into the deep layer of system settings. At first, move to the base location as follows.

5.2 Install a self-signed server certificate

Install a self-signed server certificate

5.3 Install a client certificate

Install a client certificate(1)

Install a client certificate(2)

5.4 Check the installed self-signed server certificate

Check the installed self-signed server certificate

Go through the following steps to check if the self-signed server certificate has properly installed in the system credential storage (KeyChain).

5.5 Check the installed client certificate

Check the installed client certificate(1)

Go through the following steps to check if the client certificate has properly installed in the system credential storage (KeyChain).

Check the installed client certificate(2)

If you select the self-signed server certificate (No alias name) in the screen (n2), its credential details can be seen in a dialog (o2). Check the difference between (o) and (o2), especially in the red circle.