Bug 2063671

Summary: pk12util produces PKCS#12 files incompatible with openssl/gnutls, if password is longer than 63 characters
Product: [Fedora] Fedora Reporter: Daiki Ueno <dueno>
Component: nssAssignee: Bob Relyea <rrelyea>
Status: CLOSED CURRENTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: low    
Version: 36CC: crypto-team, elio.maldonado.batiz, kai-engert-fedora, kdudka, rrelyea
Target Milestone: ---Keywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-06-24 20:42:52 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Daiki Ueno 2022-03-14 05:57:22 UTC
Description of problem:

The PKCS#12 files produced by pk12util with the default parameters do not interoperate with gnutls nor openssl. See "Steps to reproduce" for details.

Version-Release number of selected component (if applicable):

[root@f640843fbf77 tmp]# rpm -qa nss-util gnutls openssl
gnutls-3.7.3-2.fc36.x86_64
nss-util-3.75.0-1.fc36.x86_64
openssl-3.0.0-1.fc36.x86_64

How reproducible:

always

Steps to Reproduce:

$ podman run -ti --pull=always fedora:36

[root@f640843fbf77 tmp]# cd /tmp
[root@f640843fbf77 tmp]# mkdir nssdb
[root@f640843fbf77 tmp]# certutil -N -d nssdb --empty-password
[root@f640843fbf77 tmp]# certutil -S -s "CN=Example CA" -n my-ca-cert -x -t "C,C,C" -1 -2 -5 -m 3650 -d nssdb
[root@f640843fbf77 tmp]# pk12util -o test.p12 -d nssdb -n my-ca-cert -W $(python3 -c 'print("A"*64)') -d nssdb
[root@f640843fbf77 tmp]# certtool -d 10 --p12-info --inder --infile test.p12 --password=$(python3 -c 'print("A"*64)')
[root@f640843fbf77 tmp]# openssl pkcs12 -in test.p12 -out file.pem -password pass:$(python3 -c 'print("A"*64)')

Actual results:

With certtool (GnuTLS):
  bag_decrypt: Decryption has failed.
  There were errors parsing the structure

With openssl pkcs12 (OpenSSL):
  Error outputting keys and certificates
  406C6C72597F0000:error:1C800064:Provider routines:ossl_cipher_unpadblock:bad decrypt:providers/implementations/ciphers/ciphercommon_block.c:124:
  406C6C72597F0000:error:11800074:PKCS12 routines:PKCS12_pbe_crypt_ex:pkcs12 cipherfinal error:crypto/pkcs12/p12_decr.c:86:maybe wrong password

Expected results:

Decryption succeeds.

Additional info:

According to the debug output, it looks like an inssue in key derivation.
If I use a password less than 64 byte (say, 63), it works.

[root@f640843fbf77 tmp]# pk12util -o test-short.p12 -d nssdb -n my-ca-cert -W $(python3 -c 'print("A"*63)') -d nssdb
[root@f640843fbf77 tmp]# certtool -d 10 --p12-info --inder --infile test-short.p12 --password=$(python3 -c 'print("A"*63)')
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----

Comment 1 Bob Relyea 2022-03-16 16:13:04 UTC
Yes, this is the known issue. It has an upstream bug and is fixed in rhel9.

The bug I fixed would have exactly this behavior.

bob

Comment 2 Bob Relyea 2022-06-24 20:42:52 UTC
should be fixed in the latest release of NSS.