'Installing pcks12 certificate in android "wrong password" bug

When trying to import a pkcs12 certificate file into android for use with the openvpn connect app, I am prompted to input a password. This is the password relevant to this pkcs12 file. I proceed to input the correct password and am met with a "incorrect password" message.

To confirm that it is not the file that is faulty, I then tried to install the same certificate on a windows computer, where the same password was accepted and the certificate was installed without issue.

This was tested on two different smartphones running android 11 security update 2022-02-05.

Has anyone seen this issue before? I can only find similar issues online with no resolution.



Solution 1:[1]

PKCS12 is a encrypted container format for certificates and cryptographic keys. For encrypting the contained data multiple algorithms exists. Unfortunately not all systems processing PKCS#12 files do support all possible encryption algorithms.

When reading a PKCS#12 file by a system/program and it encounters an unsupported cryptographic algorithm you would expect an error message like "unable to read file: unknown or unsupported algorithm". Unfortunately in reality most implementations just output the generic error message "incorrect password".

Detecting the used encryption algorithm:

For detecting the used encryption algorithm execute

openssl pkcs12 -info -in example.p12

After entering the password(s) you will see the decoded data of the PKCS12 file, the encryption type can be seen by certain lines in the output.

The most recent encryption format (that is not yet supported by all programs) is used if you find a line like:

Shrouded Keybag: PBES2, PBKDF2, AES-256-CBC, Iteration 10000, PRF hmacWithSHA256

The older often called "legacy" encryption format is used if you find a line like:

Shrouded Keybag: pbeWithSHA1And3-KeyTripleDES-CBC, Iteration 1

A third even older algorithm exists. I have not found an example PKCS#12 file, but it should be output as pbeWithSHA1And40BitRC2-CBC.

Converting a PKCS#12 file to the old encryption format

Changing the encryption type used by a PKCS#12 file is pretty complicated as you have to extract all the contained keys and certificates and the reassemble everything into a new file. The necessary openssl commands are denoted here:

https://help.globalscape.com/help/archive/secureserver3/Converting_an_incompatible_PKCS_12_format_file_to_a_compatible_PKCS_12_.htm

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1