Bug 1384147 - PKCS#12 export illogically fails with some PBE algorithms [rhel-7]
Summary: PKCS#12 export illogically fails with some PBE algorithms [rhel-7]
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: nss
Version: 7.3
Hardware: All
OS: Linux
medium
medium
Target Milestone: rc
: ---
Assignee: Daiki Ueno
QA Contact: Hubert Kario
URL:
Whiteboard:
Depends On: 1384107
Blocks: 1020868 rhel7-nss-pkcs12
TreeView+ depends on / blocked
 
Reported: 2016-10-12 16:24 UTC by Stanislav Zidek
Modified: 2018-03-22 17:36 UTC (History)
8 users (show)

Fixed In Version: nss-3.28.3-5.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of: 1384107
Environment:
Last Closed: 2017-08-01 16:47:42 UTC


Attachments (Terms of Use)


Links
System ID Priority Status Summary Last Updated
Red Hat Product Errata RHEA-2017:1977 normal SHIPPED_LIVE nss bug fix and enhancement update 2017-08-01 17:57:47 UTC
Red Hat Bugzilla 1220573 None None None Never
Mozilla Foundation 1268141 None None None 2016-10-12 16:24:51 UTC
Mozilla Foundation 1268143 None None None 2016-10-12 16:24:51 UTC
Mozilla Foundation 1350281 None None None 2017-03-24 13:08:43 UTC
Mozilla Foundation 1350332 None None None 2017-03-24 13:59:30 UTC
Red Hat Bugzilla 1384511 None None None Never
Red Hat Bugzilla 1462312 None None None Never
Red Hat Bugzilla 1462318 None None None Never

Internal Links: 1220573 1384511 1462312 1462318

Description Stanislav Zidek 2016-10-12 16:24:52 UTC
+++ This bug was initially created as a clone of Bug #1384107 +++

Description of problem:
While doing export with pk12util with algorithm specification for key/overall encryption (-c/-C), some algorithms fail for some types (key/overall) of encryption.

Version-Release number of selected component (if applicable):
nss-tools-3.21.0-17.el7

How reproducible:
always

Steps to Reproduce:
cat >ciphers <<_EOF
RC2-CBC
RC5-CBCPad
DES-EDE3-CBC
AES-128-CBC
AES-192-CBC
AES-256-CBC
CAMELLIA-128-CBC
CAMELLIA-192-CBC
CAMELLIA-256-CBC
PKCS #12 PBE with Sha1 and 128 Bit RC4
PKCS #12 PBE with Sha1 and 40 Bit RC4
PKCS #12 PBE with Sha1 and Triple DES CBC
PKCS #12 PBE with Sha1 and 128 Bit RC2 CBC
PKCS #12 PBE with Sha1 and 40 Bit RC2 CBC
PKCS12 V2 PBE with SHA1 and 128 Bit RC4
PKCS12 V2 PBE with SHA1 and 40 Bit RC4
PKCS12 V2 PBE with SHA1 and 3KEY Triple DES-cbc
PKCS12 V2 PBE with SHA1 and 2KEY Triple DES-cbc
PKCS12 V2 PBE with SHA1 and 128 Bit RC2 CBC
PKCS12 V2 PBE with SHA1 and 40 Bit RC2 CBC
PKCS #5 Password Based Encryption with MD2 and DES CBC
PKCS #5 Password Based Encryption with MD5 and DES CBC
PKCS #5 Password Based Encryption with SHA1 and DES CBC
_EOF
echo ".V3rysecu43pass" >pwfile
mkdir nssdb
certutil -N -f pwfile -d sql:nssdb/
printf "123456789012345678901234567890123456789012345678901234567890\n0\n5\n6\n9\ny\ny\n-1\ny\n5\n6\n7\n9\ny\n" |certutil -S -n ca -s 'CN=Test CA, O=Test Org, L=Test Loc, ST=Test State, C=TS' -t 'C,C,C' -x -w -3 -v 99 -1 -2 -5 -f pwfile -d sql:nssdb/
echo -n >good
echo -n >good-key
echo -n >good-overall
i=0
while read x; do
  echo "$i: cipher: '$x'"
  echo "Key encryption:"
  pk12util -o x${i}.p12 -n ca -w pwfile -k pwfile -d sql:nssdb/ -c "$x"
  res1=$?
  echo
  echo "RESULT: $res1"
  [[ $res1 = 0 ]] && echo "$x" >>good-key
  echo "Overall encryption:"
  pk12util -o x${i}.p12 -n ca -w pwfile -k pwfile -d sql:nssdb/ -C "$x"
  res2=$?
  echo
  echo "RESULT: $res2"
  [[ $res2 = 0 ]] && echo "$x" >>good-overall
  if [[ $res1 = 0 && $res2 = 0 ]]; then
    echo "$x" >>good
  fi
  echo "---------------------------"
  i=$((i+1))
done <ciphers
cat good
cat good-key
cat good-overall

Actual results:

# cat good
RC2-CBC
DES-EDE3-CBC

# cat good-key
RC2-CBC
DES-EDE3-CBC
AES-128-CBC
AES-192-CBC
AES-256-CBC
CAMELLIA-128-CBC
CAMELLIA-192-CBC
CAMELLIA-256-CBC

# cat good-overall
RC2-CBC
DES-EDE3-CBC
PKCS #12 PBE with Sha1 and 128 Bit RC4
PKCS #12 PBE with Sha1 and 40 Bit RC4
PKCS #12 PBE with Sha1 and Triple DES CBC
PKCS #12 PBE with Sha1 and 128 Bit RC2 CBC
PKCS #12 PBE with Sha1 and 40 Bit RC2 CBC
PKCS12 V2 PBE with SHA1 and 128 Bit RC4
PKCS12 V2 PBE with SHA1 and 40 Bit RC4
PKCS12 V2 PBE with SHA1 and 3KEY Triple DES-cbc
PKCS12 V2 PBE with SHA1 and 2KEY Triple DES-cbc
PKCS12 V2 PBE with SHA1 and 128 Bit RC2 CBC
PKCS12 V2 PBE with SHA1 and 40 Bit RC2 CBC
PKCS #5 Password Based Encryption with MD2 and DES CBC
PKCS #5 Password Based Encryption with MD5 and DES CBC
PKCS #5 Password Based Encryption with SHA1 and DES CBC

Expected results:
Everything supported.

Comment 6 Hubert Kario 2017-03-23 15:26:07 UTC
Using:

cat >ciphers <<_EOF
SEED-CBC
IDEA_CBC
RC2-40-CBC
DES-40-CBC
DES-ECB
DES-CBC
RC4
RC4-40
RC4-56
NULL cipher
ChaCha20-Poly1305
_EOF

I'm getting:

# cat good
DES-CBC

# cat good-key
SEED-CBC
RC4

# cat good-overall
IDEA-CBC
NULL cipher


But with -C 'DES-CBC', OpenSSL can't perform decryption (-c 'DES-CBC' works)
With -C 'RC4', pk12util crashes.

Comment 7 Hubert Kario 2017-03-23 15:39:44 UTC
with IDEA-CBC and all the names staring with "PKCS", the certificate is actually NOT encrypted

Comment 8 Bob Relyea 2017-03-24 00:35:20 UTC
Softoken code should be in nss-softokn-3.28.3-4.el7

Comment 9 Kai Engert (:kaie) (inactive account) 2017-03-24 12:23:41 UTC
Daiki, do you think it's still possible to get this fixed for 7.4.0 ?

Comment 11 Daiki Ueno 2017-03-24 13:05:00 UTC
(In reply to Hubert Kario from comment #7)
> with IDEA-CBC and all the names staring with "PKCS", the certificate is
> actually NOT encrypted

The latter is a problem in the test itself; the cipher names do not match any of the defined ones and thus encryption is skipped.

The correct names of those ciphers are:

PKCS #12 V2 PBE With SHA-1 And 128 Bit RC4
PKCS #12 V2 PBE With SHA-1 And 40 Bit RC4
PKCS #12 V2 PBE With SHA-1 And 3KEY Triple DES-CBC
PKCS #12 V2 PBE With SHA-1 And 2KEY Triple DES-CBC
PKCS #12 V2 PBE With SHA-1 And 128 Bit RC2 CBC
PKCS #12 V2 PBE With SHA-1 And 40 Bit RC2 CBC
PKCS #5 Password Based Encryption with MD2 and DES-CBC
PKCS #5 Password Based Encryption with MD5 and DES-CBC
PKCS #5 Password Based Encryption with SHA-1 and DES-CBC

Also, IDEA-CBC is not allowed in:
https://dxr.mozilla.org/mozilla-central/source/security/nss/lib/pkcs12/p12plcy.c#20

Comment 12 Hubert Kario 2017-03-24 13:09:59 UTC
(In reply to Daiki Ueno from comment #11)
> (In reply to Hubert Kario from comment #7)
> > with IDEA-CBC and all the names staring with "PKCS", the certificate is
> > actually NOT encrypted
> 
> The latter is a problem in the test itself; the cipher names do not match
> any of the defined ones and thus encryption is skipped.
> 
> The correct names of those ciphers are:
> 
> PKCS #12 V2 PBE With SHA-1 And 128 Bit RC4
> PKCS #12 V2 PBE With SHA-1 And 40 Bit RC4
> PKCS #12 V2 PBE With SHA-1 And 3KEY Triple DES-CBC
> PKCS #12 V2 PBE With SHA-1 And 2KEY Triple DES-CBC
> PKCS #12 V2 PBE With SHA-1 And 128 Bit RC2 CBC
> PKCS #12 V2 PBE With SHA-1 And 40 Bit RC2 CBC
> PKCS #5 Password Based Encryption with MD2 and DES-CBC
> PKCS #5 Password Based Encryption with MD5 and DES-CBC
> PKCS #5 Password Based Encryption with SHA-1 and DES-CBC

those are not the names in pk12util man page and I'm quite sure those were the names that did work previously, so that change would indicate a regression...
 
> Also, IDEA-CBC is not allowed in:
> https://dxr.mozilla.org/mozilla-central/source/security/nss/lib/pkcs12/
> p12plcy.c#20

then it should report it as such and not continue with file creation

Comment 13 Hubert Kario 2017-03-24 13:26:30 UTC
Speaking of man page, 
 - DES-CBC
 - RC2-CBC
 - DES-EDE3-CBC
 - AES-128-CBC
are described as "Symmetric CBC ciphers for PKCS#5 V2".

Now, use of AES-128-CBC will create a file that uses PBES2 encryption with PBKDF2 and AES-128-CBC cipher. Use of DES-EDE3-CBC will create a file that uses PBES1 scheme with OID of pbeWithSHA1And3-KeyTripleDES-CBC. That is _not_ a cipher that was defined in PKCS#5 v2.0. PBES1 with 3DES was defined in PKCS#12 v1.1 not PKCS#12 v2.0 (I don't think v2.0 exists...).

So, honestly, I'm quite confused about both the naming, the actual meaning of those names and their explanation...

Comment 14 Nikos Mavrogiannopoulos 2017-03-24 16:24:39 UTC
(In reply to Hubert Kario from comment #13)
> Speaking of man page, 
>  - DES-CBC
>  - RC2-CBC
>  - DES-EDE3-CBC
>  - AES-128-CBC
> are described as "Symmetric CBC ciphers for PKCS#5 V2".
> 
> Now, use of AES-128-CBC will create a file that uses PBES2 encryption with
> PBKDF2 and AES-128-CBC cipher. Use of DES-EDE3-CBC will create a file that
> uses PBES1 scheme with OID of pbeWithSHA1And3-KeyTripleDES-CBC. That is
> _not_ a cipher that was defined in PKCS#5 v2.0. PBES1 with 3DES was defined
> in PKCS#12 v1.1 not PKCS#12 v2.0 (I don't think v2.0 exists...).

Talking only about the protocols (rfc2898,rfc7292) it is a bit confusing. You can use 3DES with PKCS#12 under the PKCS#5 (PBES2) OIDs or under the PKCS#12 OIDs.

Comment 15 Bob Relyea 2017-03-29 16:12:47 UTC
So NSS does not support IDEA, but you should not get the key in pkcs #12 files on export. pk12util should return an error.

Comment 18 Hubert Kario 2017-06-16 17:38:17 UTC
Export with SHA-2 PBKDF2 and low iteration counts is tracked in bug 1462312.

Comment 19 Hubert Kario 2017-06-16 17:43:10 UTC
Issues with exporting using obsolete algorithms in tracked in bug 1462318.

Comment 21 errata-xmlrpc 2017-08-01 16:47:42 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2017:1977


Note You need to log in before you can comment on or make changes to this bug.