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
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.
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
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!
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
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.