summaryrefslogtreecommitdiff
path: root/lib/pkcs12
Commit message (Collapse)AuthorAgeFilesLines
* Bug 1707130 NSS should use modern algorithms in PKCS#12 files by default r=mtRobert Relyea2021-05-045-106/+110
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Also fixes: Bug 452464 pk12util -o fails when -C option specifies AES or Camellia ciphers Related: Bug 1694689 Firefox should use modern algorithms in PKCS#12 files by default Bug 452471 pk12util -o fails when -c option specifies pkcs12v2 PBE ciphers The base of this fix is was a simple 3 line fix in pkcs12.c, changing the initial setting of cipher and cert cipher. Overview for why this patch is larger than just 3 lines: 1. First issue was found in trying to change the mac hashing value. a. While the decrypt side knew how to handle SHA2 hashes, the equivalent code was not updated on the encrypt side. I refactored that code and placed the common function in p12local.c. Now p12e.c and p12d.c share common code to find the required function to produce the mac key. b. The prf hmac was hard coded to SHA1. I changed the code to pass the hmac matching the hashing algorithm for the mac. This required changes to p12e.c to calculate and pass the new hmac as well and adding new PK11_ExportEncryptedPrivateKey and PK11_ExportEncryptedPrivKey to take the PKCS #5 v2 parameters. I also corrected an error which prevented pkcs12 encoding of ciphers other than AES. 2. Once I've made my changes, I realized we didn't have a way of testing them. While we had code that verified that particular sets of parameters for pkcs12 worked together and could be listed and imported, we didn't have a way to verify what algorithms were actually generated by our tools. a. pk12util -l doesn't list the encryption used for the certs, so I updated pp to take a pkcs12 option. In doing so I had to update pp to handle indefinite encoding when decoding blocks. I also factored that decoding out in it's own function so the change only needed to be placed once. Finally I renabled a function which prints the output of an EncryptedPrivate key. This function was disabled long ago when the Encrypted Private key info was made private for NSS. It has since been exported, so these functions could easily be enabled (archeological note: I verified that this disabling was not a recent think I found I had done it back when I still have a netscape email address;). b. I updated tools.sh to us the new pp -t pkcs12 feature to verify that the key encryption, cert encryption, and hash functions matched what we expected when we exported a new key. I also updated tools.sh to handle the new hash variable option to pk12util. c. I discovered several tests commented out with comments that the don't work. I enabled those tests and discovered that they can now encrypt, but the can't decrypt because of pkcs12 policy. I updated the policy code, but I updated it to use the new NSS system wide policy mechanism. This enabled all the ciphers to work. There is still policy work to do. The pk12 policy currently only prevents ciphers from use in decrypting the certificates, not decrypting the keys and not encrypting. I left that for future work. 3. New options for pp and pk12util were added to the man pages for these tools. --------------------------------------------------------------------------- With that in mind, here's a file by file description of the patch: automation/abi-check/expected-report-libnss3.so.txt -Add new exported functions. (see lib/nss/nss.def) cmd/lib/basicutil.h: -Removed the HAVE_EPV_TEMPLATE ifdefs (NSS has exported the Encrypted Private Key data structure for a while now. cmd/lib/secutil.c: global: Updated several functions to take a const char * m (message) rather than a char * m global: Made the various PrintPKCS7 return an error code. global: Added a state variable to be passed around the various PKCS7 Print functions. It gives the proper context to interpret PKCS7 Data Content. PKCS 12 used PKCS7 to package the various PKCS12 Safes and Bags. -Updated SECU_StripTagAndLength to handle indefinite encoding, and to set the Error code. -Added SECU_ExtractDERAndStep to grab the next DER Tag, Length, and Data. -Updated secu_PrintRawStringQuotesOptional to remove the inline DER parsing and use SECU_ExtractDERAndStep(). -Updated SECU_PrintEncodedObjectID to return the SECOidTag just like SECU_PrintObjectID. -Renable SECU_PrintPrivateKey -Added secu_PrintPKCS12Attributes to print out the Attributes tied to a PKCS #12 Bag -Added secu_PrintPKCS12Bag to print out a PKCS #12 Bag -Added secu_PrintPKCS7Data, which uses the state to determine what it was printing out. -Added secu_PrintDERPKCS7ContentInfo which is identical to the global function SECU_PrintPKCS7ContentInfo except it takes a state variable. The latter function now calls the former. -Added secu_PrintPKCS12DigestInfo to print the Hash information of the Mac. DigestInfo is the name in the PKCS 12 spec. -Added secu_PrintPKCS12MacData to print the Mac portion of the PKCS 12 file. -Added SECU_PrintPKCS12 to print otu the pkcs12 file. cmd/lib/secutil.h -Added string for pkc12 for the command line of pp reenabled SECU_PrintPrivateKey -Added SECU_PrintPKCS12 for export. cmd/pk12util/pk12util.c -Added the -M option to specify a hash algorithm for the mac. updated P12U_ExportPKCS12Object: pass the hash algorithm to the PasswordIntegrity handler. -Added PKCS12U_FindTagFromString: generalized string to SECOidTag which only filters based on the oid having a matching PKCS #11 mechanism. updated PKCS12U_MapCipherFromString to call use PKCS12U_FindTagFromString to get the candidate tag before doing it's post processing to decide if the tag is really an encryption algorithm. -Added PKCS12U_MapHashFromString with is like MapCipherFromString except it verifies the resulting tag is a hash object. -Updated main to 1) change the default cipher, change the default certCipher, and process the new hash argument. NOTE: in the old code we did not encrypt the certs in FIPS mode. That's because the certs were encrypted with RC4 in the default pkcs12 file, which wasn't a FIPS algorithm. Since AES is, we can use it independent on whether or not we are in FIPS mode. cmd/pp/pp.c -Added the pkcs12 option which calls SECU_PrintPKCS12 from secutil.c lib/nss/nss.def -Add exports to the new PK11_ExportEncryptedPrivKeyInfoV2 and PK11_ExportEncryptedPrivateKeyInfoV2 (V2 means PKCS 5 v2, not Version 2 of ExportEncrypted*Info). -Add export for the old HASH_GetHMACOidTagByHashOidTag which should have been exported long ago to avoid the proliferation of copies of this function in places like ssl. lib/pk11wrap/pk11akey.c -Add PK11_ExportEncryptedPrivKeyInfoV2 (which the old function now calls), which takes the 3 PKCS 5 v2 parameters. The underlying pkcs5 code can fill in missing tags if necessary, but supplying all three gives the caller full control of the underlying pkcs5 PBE used. -Add PK11_ExportEncryptedPrivateKeyInfoV2, same as the above function except it takes a cert which is used to look up the private key. It's the function that pkcs12 actually uses, but the former was exported for completeness. lib/pk11wrap/pk11pub.h -Added the new PK11_ExportEncryptedPriv*KeyInfoV2 functions. lib/pkcs12/p12d.c -Remove the switch statement and place it in p12local.c so that p12e.c can use the same function. lib/pkc12/p12e.c -Remove the unnecessary privAlg check so we can encode any mechanism we support. This only prevented encoding certificates in the pk12 file, not the keys. -add code to get the hmac used in the pbe prf from the integrity hash, which is under application control. -Do the same for key encryption, then use the new PK11_ExportEncryptedPrivateKeyInfo to pass that hash value. -Use the new sec_pkcs12_algtag_to_keygen_mech so there is only one switch statement to update rather than 2. -Update the hash data to old the length of the largest hash rather than the length of a SHA1 hash. lib/pkcs12/p12local.c - Add new function new sec_pkcs12_algtag_to_keygen_mech to factor out the common switch statement between p12e and p12d. lib/pkcs12/p12local.h -Export the new sec_pkcs12_algtag_to_keygen_mech lib/pkcs12/p12plcy.c -Map the old p12 policy functions to use the new NSS_GetAlgorithmPolicy. We keep the old table so that applications can change the policy with the old PKCS12 specific defines (so the old code keeps working). NOTE: policies now default to true rather than false. lib/util/secoidt.h -Add new NSS_USE_ALG_IN_PKCS12 used by pk11plcy.c NOTE: I have not updated the policy table in pk11wrap/pk11pars.c, so we can't yet control pkcs12 policy with the nss system policy table. That's a patch for another time. test/tools/tool.sh -global: Remove trailing spaces -global: DEFAULT is changed to 'default' -Update the PBE mechanism to exactly match the string in secoid.c. PKCS #12 does case independent compares, so case doesn't matter there, but now I'm comparing to the output of pp, and I didn't want to spend the time to figure out case independent compares in bash. -Add our defauts and shell variables at the top so there are easy to change in the future. export_with_*** have all been colapsed into a single export_p12_file which handles taking 'default' and turning off that argument. -Add for loops for the hash functions. -Restore the camellia ciphers back now that they work. -Restore the pkcs12V2pbe back now that they work. -Collect various pbe types into single variables and use those variables in loops -Reduce the number of tests ran in optimized mode (which takes 60x the time to do a pbe then than debug mode based on a larger iterator). -Add verify_p12 which dumps out the p12 file and makes sure the expected CERT_ENCRYPTION, KEY_ENCRYPTION, and HASH are used. doc/pp.xml -Add pkcs12 option doc/pk12util.xml -Add -M option -Update synopsis with options in the description but not in the synopsis Differential Revision: https://phabricator.services.mozilla.com/D113699
* Bug 1649322 - Fix null pointer passed as argument in pk11wrap/pk11pbe.c:1246 ↵Benjamin Beurdouche2020-07-091-3/+0
| | | | | | | | r=kjacobs This is a fixup patch that reverts https://hg.mozilla.org/projects/nss/rev/cc43ebf5bf88355837c5fafa2f3c46e37626707a and adds a null check around the memcpy in question. Differential Revision: https://phabricator.services.mozilla.com/D82494
* Bug 1649322 - Fix null pointer passed as argument in pk11wrap/pk11pbe.c:1246 ↵Benjamin Beurdouche2020-06-301-0/+3
| | | | | | r=kjacobs Differential Revision: https://phabricator.services.mozilla.com/D81668
* Bug 1629553 Merge simple config.mk files r=rrelyeaJan-Marek Glogowski2020-05-053-18/+1
| | | | | | | | | | | There is really no good reason to explicitly change the TARGET variable. And the empty SHARED_LIBRARY variable should also be in the manifest.mn to begin with. All the other empty variables start empty or undefined, so there is also no need to explicitly set them empty. Differential Revision: https://phabricator.services.mozilla.com/D70691
* Bug 1603628 Update NSS to handle PKCS #11 v3.0 r=daiki r=mhoyeRobert Relyea2020-02-182-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | https://phabricator.services.mozilla.com/D63241 This patch implements the first phase: updating the headers. lib/util/pkcs11.h lib/util/pkcs11f.h lib/util/pkcs11t.h Were updated using the released OASIS PKCS #11 v3.0 header files. lib/util/pkcs11n.h was updated to finally deprecate all uses of CK?_NETSCAPE_?. A new define as added: NSS_PKCS11_2_0_COMPAT. If it's defined, the small semantic changes (including the removal of deprecated defines) between the NSS PKCS #11 v2 header file and the new PKCS #11 v3 are reverted in favor of the PKCS #11 v2 definitions. This include the removal of CK?_NETSCAPE_? in favor of CK?_NSS_?. One notable change was caused by an inconsistancy between the spec and the released headers in PKCS #11 v2.40. CK_GCM_PARAMS had an extra field in the header that was not in the spec. OASIS considers the header file to be normative, so PKCS #11 v3.0 resolved the issue in favor of the header file definition. NSS had the spec definition, so now there are 2 defines for this structure: CK_NSS_GCM_PARAMS - the old nss define. Still used internally in freebl. CK_GCM_PARAMS_V3 - the new define. CK_GCM_PARAMS - no longer referenced in NSS itself. It's defined as CK_GCM_PARAMS_V3 if NSS_PKCS11_2_0_COMPAT is *not* defined, and it's defined as CKM_NSS_GCM_PARAMS if NSS_PKCS11_2_0_COMPAT is defined. Softoken has been updated to accept either CK_NSS_GCM_PARAMS or CK_GCM_PARAMS_V3. In a future patch NSS will be updated to use CK_GCM_PARAMS_V3 and fall back to CK_NSS_GMC_PARAMS. One other semantic difference between the 3.0 version of pkcs11f.h and the version here: In the oasis version of the header, you must define CK_PKCS11_2_0_ONLY to get just the PKCS #11 v2 defines. In our version you must define CK_PKCS11_3 to get the PCKS #11 v3 defines. Most of this patch is to handle changing the deprecated defines that have been removed in PCKS #11 v3 from NSS. Differential Revision: https://phabricator.services.mozilla.com/D63241
* Bug 1480647 - Warn about deprecation of key.h and keyt.h. Include keyhi.h ↵Cosmin Truta2018-09-143-3/+3
| | | | instead of key.h, and keythi.h instead of keyt.h. r=rrelyea
* Bug 1464616 - make sure arenas are the same, r=mtFranziskus Kiefer2018-06-061-1/+3
| | | | Differential Revision: https://phabricator.services.mozilla.com/D1565
* Bug 1464618 - null salt, r=mtFranziskus Kiefer2018-06-051-0/+1
| | | | Differential Revision: https://phabricator.services.mozilla.com/D1553
* Bug 1460673 - handle p12 properly, r=ttaubertFranziskus Kiefer2018-05-161-0/+1
| | | | Differential Revision: https://phabricator.services.mozilla.com/D1295
* Merge NSS trunk to NSS_TLS13_DRAFT19_BRANCHMartin Thomson2017-10-091-9/+54
|\
| * Bug 1399867, pkcs12: Add a compat option for password encoding, r=rrelyeaDaiki Ueno2017-09-141-9/+54
| |
* | Bug 1397990 - Run clang-format 4.0, r=meMartin Thomson2017-09-081-2/+1
|/ | | | | | | | These files were being reformatted by clang-format 4.0. If you make this change, then both 3.9 (in CI) and 4.0 are happy with the result. I don't plan to do this often, but it is a huge help. Note that the PK11 ECDSA tests are an odd duck, I have more on that coming.
* Bug 1353325, pkcs12: don't encode password if non-PKCS12 PBEs is used, r=rrelyeaDaiki Ueno2017-04-044-39/+75
|
* Bug 1353325, Backed out changeset 7e62307b5cf4 for build failure.Kai Engert2017-04-064-75/+39
|
* Bug 1353325, pkcs12: don't encode password if non-PKCS12 PBEs is used, r=rrelyeaDaiki Ueno2017-04-044-39/+75
|
* Bug 1268141 - pk12util can't import PKCS#12 files encrypted with ↵Daiki Ueno2017-01-305-9/+83
| | | | AES-128-CBC, r=rrelyea
* Bug 1268143 - pk12util can't import PKCS#12 files with SHA-256 MAC, r=rrelyeaDaiki Ueno2016-12-151-1/+13
|
* bug 1316604 - Add variables for <(nss_dist_dir)/{public,private}. r=franziskusTed Mielczarek2016-11-101-1/+1
| | | | | Mozilla's build system currently puts NSS public headers directly in $(DIST)/include/nss, so we need a way to override the export directory.
* Bug 1118245 - clang-format on lib/pkcs12, r=ttaubertFranziskus Kiefer2016-09-1013-5174/+5083
| | | | try: -b do -p none -t all
* Bug 1311615 - Building with gyp should copy headers, libs, executables to ↵Tim Taubert2016-10-211-2/+2
| | | | | | the right directory r=franziskus Differential Revision: https://nss-dev.phacility.com/D104
* bug 1237872 - Add gyp build system for NSS. r=fkieferTed Mielczarek2016-09-232-0/+58
|
* Bug 1280844 - Fix a null check in p12d.c. r=mt.Nicholas Nethercote2016-06-211-1/+1
| | | | MozReview-Commit-ID: Fon5Jt8qoNx
* Bug 1257885 - Fix some unchecked return values, r=ttaubertFranziskus Kiefer2016-04-291-2/+12
|
* Bug 1216501 - [CID 1327954][CID 1327953][CID 1327952][CID 1327951] Using ↵Franziskus Kiefer2015-10-211-0/+1
| | | | uninitialized value secitem.type when calling SECITEM_CopyItem_Util - copying secitem.type only if present, r=mt
* Bug 1214762, additional Windows bustage fix, variable declarations must go firstKai Engert2015-10-151-1/+1
|
* Bug 1214762, obvious bustage fix, variable declarations must go first.Kai Engert2015-10-151-1/+1
|
* Bug 1214762 - leaked_storage: Variable salt going out of scope leaks the ↵Franziskus Kiefer2015-10-141-6/+9
| | | | storage it points to, r=mt
* Bug 1182667 - Enable warnings as errors, r=rrelyeaMartin Thomson2015-08-172-7/+2
|
* Backed out changeset 4355f55afeb2 (Bug 1158489)Martin Thomson2015-08-122-2/+7
|
* Bug 1182667 - Removing warnings, enabling -Werror, r=rrelyeaMartin Thomson2015-08-072-7/+2
|
* Bug 1111901 - Segfault in pk12util when using -l option with certain .p12 ↵Elio Maldonado2015-03-021-1/+2
| | | | files, r=rsleevy
* Bug 1113453 - Support set certificate nickname in pkcs12 decoder context, r=kaieChuck Lee2015-02-252-3/+116
|
* Bug 974693 - memory corruption in sec_pkcs12_new_asafe(), r=ryan.sleeviMaks Naumov2014-03-141-1/+1
|
* Bug 618798 - add fall through comment, r=rrelyea, DONTBUILDcykesiopka bmo2013-06-281-0/+1
|
* Bug 802430: Allow NSS to be built with NO_NSPR_10_SUPPORT, r=wtcBrian Smith2013-05-026-34/+34
|
* Bug 845556, adjust Makefiles and tests to new NSS directory layout, r=wtcKai Engert2013-02-281-1/+1
| | | | (Previous changeset with identical description was accidentally empty.)
* Bug 845556, reorganize NSS directory layout, moving files, very large ↵Kai Engert2013-02-2817-0/+10577
changeset! r=wtc