Bug 1159462

Summary: Missing PBKDF2 support
Product: [Fedora] Fedora Reporter: Endi Sukma Dewata <edewata>
Component: python-nssAssignee: John Dennis <jdennis>
Status: CLOSED CURRENTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 22CC: jdennis, mkosek
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: python-nss-0.17.0 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-07-19 12:21:17 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 Endi Sukma Dewata 2014-11-01 04:10:43 UTC
The current python-nss does not provide the interface required to generate a key using PBKDF2:

  key = PBKDF2(hash function, password, salt, iteration, key length)

Here is the NSS code required to perform the above operation:

SECItem password = {
     siBuffer,
     <password>,
     <password length>
};

SECItem salt = {
     siBuffer,
     <salt>,
     <salt length>
};

void *nullptr = NULL;

SECAlgorithmID *algID = PK11_CreatePBEV2AlgorithmID(
     SEC_OID_PKCS5_PBKDF2,
     <hash function>,
     <pseudo random function>
     <key length>,
     <iteration>,
     &salt);

PK11SlotInfo *slot = PK11_GetBestSlot(
     SEC_OID_PKCS5_PBKDF2,
     nullptr);

PK11SymKey *key = PK11_PBEKeyGen(
     slot,
     algID,
     &password,
     PR_FALSE,
     nullptr);

PK11_FreeSlot(slot);

SECOID_DestroyAlgorithmID(algID, PR_TRUE);

See also:
* http://mozilla.6506.n7.nabble.com/How-do-I-use-pbkdf2-in-nss-td325336.html
* http://svn.apache.org/repos/asf/apr/apr/trunk/crypto/apr_crypto_nss.c
* http://hg.mozilla.org/mozilla-central/file/a255a234946e/dom/crypto/WebCryptoTask.cpp

Comment 1 John Dennis 2014-11-07 21:59:12 UTC
Implemented in 0.17.0

A rawhide scratch build has been performed, please test and report

 http://koji.fedoraproject.org/koji/taskinfo?taskID=8066425

Be sure to install the python-nss-doc package.

An example of using it is in:

doc/examples/pbkdf2_example.py

The API doc contains the detailed function call information.

Comment 2 John Dennis 2014-11-17 18:23:43 UTC
Testing by Endi Dewata revealed a problem. A decryption context cannot be built using the same input parameters to create_pbev2_algorithm_id() and pbe_key_gen() because get_pbe_crypto_mechanism() returns a parameter block with random data (i.e. the IV) each time it's called. The parameter block *must* be the same during decryption. Therefore the parameter block created during encryption must be saved an used during decryption.

To facilitate passing the parameter block used during encryption to the decryption context the SecItem class was enhanced to serialize to and from base64

The pbkdf2_example.py example script was rewritten to better illustrate the separation of the encryption and decryption as well as utilizing the serialization of the params SecItem into and out of base64.

A new scratch build is available here:

http://koji.fedoraproject.org/koji/taskinfo?taskID=8167656

Comment 3 Endi Sukma Dewata 2015-01-16 23:35:54 UTC
John provided a new scratch build:

http://koji.fedoraproject.org/koji/taskinfo?taskID=8643043

Tests indicate that the code now works correctly. However, as John said, the NSS API requires that the parameter blocks used during encryption and decryption must be the identical, so the parameter block used for encryption may need to be serialized and stored somewhere, and then reloaded again for decryption.

Ideally it should not be necessary to store the parameter blocks, but for now this is sufficient. Please commit the changes. Thanks!

Comment 4 Jaroslav Reznik 2015-03-03 17:16:33 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 22 development cycle.
Changing version to '22'.

More information and reason for this action is here:
https://fedoraproject.org/wiki/Fedora_Program_Management/HouseKeeping/Fedora22

Comment 5 Fedora End Of Life 2016-07-19 12:21:17 UTC
Fedora 22 changed to end-of-life (EOL) status on 2016-07-19. Fedora 22 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.