在Android中安装PCKS12证书“错误密码”漏洞

发布于 2025-01-21 17:30:32 字数 291 浏览 2 评论 0 原文

当尝试将PKCS12证书文件导入Android供Android供OpenVPN Connect应用程序使用时,我会提示我输入密码。这是与此PKCS12文件相关的密码。我继续输入正确的密码,并使用“不正确的密码”消息遇到。

为了确认并非文件有故障,然后我尝试在Windows计算机上安装相同的证书,该证书被接受了相同的密码,并且没有问题就安装了证书。

在运行Android 11 Security Update 2022-02-05的两台不同智能手机上进行了测试。

有人看过这个问题吗?我只能在网上找到类似的问题而没有解决方案。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

荒岛晴空 2025-01-28 17:30:32

我也有同样的问题。我花了大约一个月的时间来弄清楚。

TL; dr就是这样:

$ openssl pkcs12 -nodes < your.p12 > /tmp/certbag.pem
$ openssl pkcs12 -export -legacy -in /tmp/certbag.pem > /tmp/legacy.p12

然后使用 lacacy.p12

显然,Android无法导入更新的PKCS12文件。我在Android 12和Android 13上尝试了此操作。

在旧模式下,证书加密的默认算法是RC2_CBC或3DES_CBC,具体取决于构建中是否启用了RC2密码。专用密钥加密的默认算法是3DES_CBC。如果未指定遗产选项,则未加载旧版提供商,并且证书和私钥的默认加密算法为AES_256_CBC,with pbkdf2用于密钥推导。

使用 openssl pkcs12 -info 在我的情况下,我在原始.p12文件上看到了这一点,该文件是使用Python的Pycryptography PKCS12支持的:

MAC: sha256, Iteration 1
MAC length: 32, salt length: 8
PKCS7 Encrypted data: pbeWithSHA1And3-KeyTripleDES-CBC, Iteration 20000

并使用 openssl pkcs12 -Info -Info -info -leggacy 转换后的.p12文件我看到了:

MAC: sha1, Iteration 2048
MAC length: 20, salt length: 8
PKCS7 Encrypted data: pbeWithSHA1And40BitRC2-CBC, Iteration 2048

原始文件在转换(传统一个)时未能导入。

I had the same issue. It took me about a month to figure it out.

The tl;dr is this:

$ openssl pkcs12 -nodes < your.p12 > /tmp/certbag.pem
$ openssl pkcs12 -export -legacy -in /tmp/certbag.pem > /tmp/legacy.p12

Then use legacy.p12.

Apparently Android cannot import newer pkcs12 files. I tried this on Android 12 and Android 13. This is what man openssl-pkcs12 says for -legacy:

In the legacy mode, the default algorithm for certificate encryption is RC2_CBC or 3DES_CBC depending on whether the RC2 cipher is enabled in the build. The default algorithm for private key encryption is 3DES_CBC. If the legacy option is not specified, then the legacy provider is not loaded and the default encryption algorithm for both certificates and private keys is AES_256_CBC with PBKDF2 for key derivation.

Using openssl pkcs12 -info in my case I see this on the original .p12 file, which was created using Python's PyCryptography PKCS12 support:

MAC: sha256, Iteration 1
MAC length: 32, salt length: 8
PKCS7 Encrypted data: pbeWithSHA1And3-KeyTripleDES-CBC, Iteration 20000

And using openssl pkcs12 -info -legacy on the converted .p12 file I see this:

MAC: sha1, Iteration 2048
MAC length: 20, salt length: 8
PKCS7 Encrypted data: pbeWithSHA1And40BitRC2-CBC, Iteration 2048

The original one fails to import while the converted (legacy one) imports perfectly well.

后eg是否自 2025-01-28 17:30:32

如果任何人都在与 gnutls certtool ...

tl; dr; dr; dr都应该与Android 9&amp一起使用。 Android 12:

certtool --load-privkey client.key --load-certificate client.crt \
    --load-ca-certificate ca.crt \
    --to-p12 --outder --outfile client.p12 \
    --p12-name "A Friendly Name" \
    --hash SHA1 --pkcs-cipher 3des-pkcs12 --password YourPassword

创建PKCS#12文件时的说明

,您必须选择Mac Hash算法( -ash = XXX )和Cipher算法( -pkcs-cipher = xxx xxx )。从我的测试中,Android支持如下。

哈希算法 CIPHER算法 Android 9 Android 12
(Any) AES-128,AES-192,AES-256,aes-256 sha512
- pkcs12 no no
sha256 3des-pkcs12 no no
3des pkcs12 sha384 强>是
sha256 rc2-40
sha1 rc2-40 yes ,

是 可以在上面看到,Android 9实际上支持SHA256和SHA1作为Mac,但Android 12以某种方式仅支持SHA1。
在certtool中,即使您选择 -pkcs-cipher = 3Des-pkcs12 ,默认的Mac Hash算法也是SHA256。 ,您必须明确指定 - hash = sha1 ,否则p12文件对Android 12不起作用

因此

  • 。 XQ-AU52,Android 12)。
  • CERTTOOL默认MAC迭代为600000(与OpenSSL的2048相比)。在手机上安装.p12文件时,此偏执设置会导致几秒钟的速度降低。件。我还没有找到更改此迭代的参数(OpenSSL 3.x通过 -Iter 指定)。

In case anyone is struggling with GnuTLS certtool...

TL;DR this should work with both Android 9 & Android 12:

certtool --load-privkey client.key --load-certificate client.crt \
    --load-ca-certificate ca.crt \
    --to-p12 --outder --outfile client.p12 \
    --p12-name "A Friendly Name" \
    --hash SHA1 --pkcs-cipher 3des-pkcs12 --password YourPassword

Explanation

When creating PKCS#12 files, you have to choose MAC hash algorithm (--hash=xxx) and cipher algorithm (--pkcs-cipher=xxx). From my test, Android support is as below.

Hash Algorithm Cipher Algorithm Android 9 Android 12
(any) aes-128, aes-192, aes-256 no no
SHA384, SHA512 3des-pkcs12 no no
SHA256 3des-pkcs12 yes no
SHA1 3des-pkcs12 yes yes
SHA256 rc2-40 yes no
SHA1 rc2-40 yes yes

As can be seen above, Android 9 actually supports both SHA256 and SHA1 as MAC, but Android 12 somehow only supports SHA1.
In certtool, the default MAC hash algorithm is SHA256 even if you choose --pkcs-cipher=3des-pkcs12. Therefore you have to explicitly specify --hash=SHA1, otherwise the p12 file won't work for Android 12.

Other comments

  • Tested phones are Xperia XZ1 Compact (G8441, Android 9) and Xperia 10 ii (XQ-AU52, Android 12).
  • certtool default MAC iteration is 600000 (compared to openssl's 2048). This paranoid setting results several seconds slowness when installing .p12 files on phones & PCs. I haven't found a parameter to change this iteration (openssl 3.x specifies by -iter).
ゞ花落谁相伴 2025-01-28 17:30:32

PKCS12是用于证书和加密密钥的加密容器格式。为了加密包含的数据,存在多个算法。不幸的是,并非所有处理PKCS#12文件的系统都支持所有可能的加密算法。

当通过系统/程序读取PKCS#12文件时,它会遇到一个不支持的加密算法时,您会期待一条错误消息,例如“无法读取文件:未知或未支持的算法”。不幸的是,实际上,大多数实现只是输出通用错误消息“不正确的密码”。

检测使用的加密算法:

检测使用的加密算法执行

openssl pkcs12 -info -in example.p12

在输入密码后

,您将看到PKCS12文件的解码数据,可以通过输出中的某些行看到加密类型。如果您找到类似的行,则使用类似于“旧版”的加密格式,

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

如果您找到类似的行,则使用类似:第三个甚至较旧的算法,使用通常称为“遗产”加密格式,则使用

Shrouded Keybag: pbeWithSHA1And3-KeyTripleDES-CBC, Iteration 1

最新的加密格式(尚未得到所有程序的支持)。我尚未找到一个示例PKCS#12文件,但应将其作为 pbewithsha1and40bitrc2-cbc 输出。

将PKCS#12文件转换为旧的加密格式

更改PKCS#12文件使用的加密类型非常复杂,因为您必须提取所有包含的键和证书,并且将所有内容都重新组装成新文件。在此处表示必要的OPENSL命令:

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

岁月苍老的讽刺 2025-01-28 17:30:32

我遇到了这样一个问题,即上述解决方案带有 - 签证选项没有使用我的新电子邮件证书对实际的Ubuntu/openssl工作。
几乎没有其他问题:我有一个.pfx文件不是.p12不知道这是否是与其他结局相同的容器格式?

以下工作流程是成功的:

$ openssl pkcs12 -nodes < your.pfx > /home/ubuntu/certbag.pem
$ openssl pkcs12 -keypbe PBE-SHA1-3DES -certpbe PBE-SHA1-3DES -export -in /home/ubuntu/certbag.pem -out /home/ubuntu/new.pfx -name "SMIME-Cert"

删除certbag.pem之后!它包含您的私钥,没有加密!

证书在Android 10上无意识地进口。

多亏了上述解决方案和提供的链接!

I ran into the problem that the above solution with -legacy option did not work on an actual ubuntu/openssl with my new email certificate.
Little additional problem: I had a .pfx file not a .p12 not knowing if this is the same container format with other ending?

The following workflow was a succes:

$ openssl pkcs12 -nodes < your.pfx > /home/ubuntu/certbag.pem
$ openssl pkcs12 -keypbe PBE-SHA1-3DES -certpbe PBE-SHA1-3DES -export -in /home/ubuntu/certbag.pem -out /home/ubuntu/new.pfx -name "SMIME-Cert"

Delete certbag.pem afterwards! It contains your private key without encryption!

Certificate imports now flawlessly on android 10.

Thanks to the above solution and the provided links!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文