Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: mozilla/security/nss/lib/softoken/pkcs11.c

Issue 10961060: Update NSS to NSS 3.14 Beta 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/nss/
Patch Set: Add the NSS snapshot timestamp to README.chromium and nss-checkout.sh Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* This Source Code Form is subject to the terms of the Mozilla Public 1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 /* 4 /*
5 * This file implements PKCS 11 on top of our existing security modules 5 * This file implements PKCS 11 on top of our existing security modules
6 * 6 *
7 * For more information about PKCS 11 See PKCS 11 Token Inteface Standard. 7 * For more information about PKCS 11 See PKCS 11 Token Inteface Standard.
8 * This implementation has two slots: 8 * This implementation has two slots:
9 * slot 1 is our generic crypto support. It does not require login. 9 * slot 1 is our generic crypto support. It does not require login.
10 * It supports Public Key ops, and all they bulk ciphers and hashes. 10 * It supports Public Key ops, and all they bulk ciphers and hashes.
(...skipping 14 matching lines...) Expand all
25 #include "lowkeyi.h" 25 #include "lowkeyi.h"
26 #include "blapi.h" 26 #include "blapi.h"
27 #include "secder.h" 27 #include "secder.h"
28 #include "secport.h" 28 #include "secport.h"
29 #include "secrng.h" 29 #include "secrng.h"
30 #include "prtypes.h" 30 #include "prtypes.h"
31 #include "nspr.h" 31 #include "nspr.h"
32 #include "softkver.h" 32 #include "softkver.h"
33 #include "secoid.h" 33 #include "secoid.h"
34 #include "sftkdb.h" 34 #include "sftkdb.h"
35 #include "sftkpars.h" 35 #include "utilpars.h"
36 #include "ec.h" 36 #include "ec.h"
37 #include "secasn1.h" 37 #include "secasn1.h"
38 #include "secerr.h"
39 #include "lgglue.h"
38 40
39 PRBool parentForkedAfterC_Initialize; 41 PRBool parentForkedAfterC_Initialize;
40 42
41 #ifndef NO_FORK_CHECK 43 #ifndef NO_FORK_CHECK
42 44
43 PRBool sftkForkCheckDisabled; 45 PRBool sftkForkCheckDisabled;
44 46
45 #if defined(CHECK_FORK_PTHREAD) || defined(CHECK_FORK_MIXED) 47 #if defined(CHECK_FORK_PTHREAD) || defined(CHECK_FORK_MIXED)
46 PRBool forked = PR_FALSE; 48 PRBool forked = PR_FALSE;
47 #endif 49 #endif
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 CKF_SN_VR}, PR_TRUE}, 285 CKF_SN_VR}, PR_TRUE},
284 {CKM_SHA384_RSA_PKCS, {RSA_MIN_MODULUS_BITS,CK_MAX, 286 {CKM_SHA384_RSA_PKCS, {RSA_MIN_MODULUS_BITS,CK_MAX,
285 CKF_SN_VR}, PR_TRUE}, 287 CKF_SN_VR}, PR_TRUE},
286 {CKM_SHA512_RSA_PKCS, {RSA_MIN_MODULUS_BITS,CK_MAX, 288 {CKM_SHA512_RSA_PKCS, {RSA_MIN_MODULUS_BITS,CK_MAX,
287 CKF_SN_VR}, PR_TRUE}, 289 CKF_SN_VR}, PR_TRUE},
288 /* ------------------------- DSA Operations --------------------------- */ 290 /* ------------------------- DSA Operations --------------------------- */
289 {CKM_DSA_KEY_PAIR_GEN, {DSA_MIN_P_BITS, DSA_MAX_P_BITS, 291 {CKM_DSA_KEY_PAIR_GEN, {DSA_MIN_P_BITS, DSA_MAX_P_BITS,
290 CKF_GENERATE_KEY_PAIR}, PR_TRUE}, 292 CKF_GENERATE_KEY_PAIR}, PR_TRUE},
291 {CKM_DSA, {DSA_MIN_P_BITS, DSA_MAX_P_BITS, 293 {CKM_DSA, {DSA_MIN_P_BITS, DSA_MAX_P_BITS,
292 CKF_SN_VR}, PR_TRUE}, 294 CKF_SN_VR}, PR_TRUE},
295 {CKM_DSA_PARAMETER_GEN, {DSA_MIN_P_BITS, DSA_MAX_P_BITS,
296 CKF_GENERATE}, PR_TRUE},
293 {CKM_DSA_SHA1, {DSA_MIN_P_BITS, DSA_MAX_P_BITS, 297 {CKM_DSA_SHA1, {DSA_MIN_P_BITS, DSA_MAX_P_BITS,
294 CKF_SN_VR}, PR_TRUE}, 298 CKF_SN_VR}, PR_TRUE},
295 /* -------------------- Diffie Hellman Operations --------------------- */ 299 /* -------------------- Diffie Hellman Operations --------------------- */
296 /* no diffie hellman yet */ 300 /* no diffie hellman yet */
297 {CKM_DH_PKCS_KEY_PAIR_GEN, {DH_MIN_P_BITS, DH_MAX_P_BITS, 301 {CKM_DH_PKCS_KEY_PAIR_GEN, {DH_MIN_P_BITS, DH_MAX_P_BITS,
298 CKF_GENERATE_KEY_PAIR}, PR_TRUE}, 302 CKF_GENERATE_KEY_PAIR}, PR_TRUE},
299 {CKM_DH_PKCS_DERIVE, {DH_MIN_P_BITS, DH_MAX_P_BITS, 303 {CKM_DH_PKCS_DERIVE, {DH_MIN_P_BITS, DH_MAX_P_BITS,
300 CKF_DERIVE}, PR_TRUE}, 304 CKF_DERIVE}, PR_TRUE},
301 #ifdef NSS_ENABLE_ECC 305 #ifdef NSS_ENABLE_ECC
302 /* -------------------- Elliptic Curve Operations --------------------- */ 306 /* -------------------- Elliptic Curve Operations --------------------- */
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 /* ---------------------- SSL Key Derivations ------------------------- */ 439 /* ---------------------- SSL Key Derivations ------------------------- */
436 {CKM_SSL3_PRE_MASTER_KEY_GEN, {48, 48, CKF_GENERATE}, PR_FALSE}, 440 {CKM_SSL3_PRE_MASTER_KEY_GEN, {48, 48, CKF_GENERATE}, PR_FALSE},
437 {CKM_SSL3_MASTER_KEY_DERIVE, {48, 48, CKF_DERIVE}, PR_FALSE}, 441 {CKM_SSL3_MASTER_KEY_DERIVE, {48, 48, CKF_DERIVE}, PR_FALSE},
438 {CKM_SSL3_MASTER_KEY_DERIVE_DH, {8, 128, CKF_DERIVE}, PR_FALSE}, 442 {CKM_SSL3_MASTER_KEY_DERIVE_DH, {8, 128, CKF_DERIVE}, PR_FALSE},
439 {CKM_SSL3_KEY_AND_MAC_DERIVE, {48, 48, CKF_DERIVE}, PR_FALSE}, 443 {CKM_SSL3_KEY_AND_MAC_DERIVE, {48, 48, CKF_DERIVE}, PR_FALSE},
440 {CKM_SSL3_MD5_MAC, { 0, 16, CKF_DERIVE}, PR_FALSE}, 444 {CKM_SSL3_MD5_MAC, { 0, 16, CKF_DERIVE}, PR_FALSE},
441 {CKM_SSL3_SHA1_MAC, { 0, 20, CKF_DERIVE}, PR_FALSE}, 445 {CKM_SSL3_SHA1_MAC, { 0, 20, CKF_DERIVE}, PR_FALSE},
442 {CKM_MD5_KEY_DERIVATION, { 0, 16, CKF_DERIVE}, PR_FALSE}, 446 {CKM_MD5_KEY_DERIVATION, { 0, 16, CKF_DERIVE}, PR_FALSE},
443 {CKM_MD2_KEY_DERIVATION, { 0, 16, CKF_DERIVE}, PR_FALSE}, 447 {CKM_MD2_KEY_DERIVATION, { 0, 16, CKF_DERIVE}, PR_FALSE},
444 {CKM_SHA1_KEY_DERIVATION, { 0, 20, CKF_DERIVE}, PR_FALSE}, 448 {CKM_SHA1_KEY_DERIVATION, { 0, 20, CKF_DERIVE}, PR_FALSE},
449 {CKM_SHA224_KEY_DERIVATION, { 0, 28, CKF_DERIVE}, PR_FALSE},
450 {CKM_SHA256_KEY_DERIVATION, { 0, 32, CKF_DERIVE}, PR_FALSE},
451 {CKM_SHA384_KEY_DERIVATION, { 0, 48, CKF_DERIVE}, PR_FALSE},
452 {CKM_SHA512_KEY_DERIVATION, { 0, 64, CKF_DERIVE}, PR_FALSE},
445 {CKM_TLS_MASTER_KEY_DERIVE, {48, 48, CKF_DERIVE}, PR_FALSE}, 453 {CKM_TLS_MASTER_KEY_DERIVE, {48, 48, CKF_DERIVE}, PR_FALSE},
446 {CKM_TLS_MASTER_KEY_DERIVE_DH, {8, 128, CKF_DERIVE}, PR_FALSE}, 454 {CKM_TLS_MASTER_KEY_DERIVE_DH, {8, 128, CKF_DERIVE}, PR_FALSE},
447 {CKM_TLS_KEY_AND_MAC_DERIVE, {48, 48, CKF_DERIVE}, PR_FALSE}, 455 {CKM_TLS_KEY_AND_MAC_DERIVE, {48, 48, CKF_DERIVE}, PR_FALSE},
448 /* ---------------------- PBE Key Derivations ------------------------ */ 456 /* ---------------------- PBE Key Derivations ------------------------ */
449 {CKM_PBE_MD2_DES_CBC, {8, 8, CKF_DERIVE}, PR_TRUE}, 457 {CKM_PBE_MD2_DES_CBC, {8, 8, CKF_DERIVE}, PR_TRUE},
450 {CKM_PBE_MD5_DES_CBC, {8, 8, CKF_DERIVE}, PR_TRUE}, 458 {CKM_PBE_MD5_DES_CBC, {8, 8, CKF_DERIVE}, PR_TRUE},
451 /* ------------------ NETSCAPE PBE Key Derivations ------------------- */ 459 /* ------------------ NETSCAPE PBE Key Derivations ------------------- */
452 {CKM_NETSCAPE_PBE_SHA1_DES_CBC, { 8, 8, CKF_GENERATE}, PR_TRUE}, 460 {CKM_NETSCAPE_PBE_SHA1_DES_CBC, { 8, 8, CKF_GENERATE}, PR_TRUE},
453 {CKM_NETSCAPE_PBE_SHA1_FAULTY_3DES_CBC, {24,24, CKF_GENERATE}, PR_TRUE}, 461 {CKM_NETSCAPE_PBE_SHA1_FAULTY_3DES_CBC, {24,24, CKF_GENERATE}, PR_TRUE},
454 {CKM_PBE_SHA1_DES3_EDE_CBC, {24,24, CKF_GENERATE}, PR_TRUE}, 462 {CKM_PBE_SHA1_DES3_EDE_CBC, {24,24, CKF_GENERATE}, PR_TRUE},
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 if (crv != CKR_OK) { 861 if (crv != CKR_OK) {
854 return crv; 862 return crv;
855 } 863 }
856 crv = sftk_ConstrainAttribute(object, CKA_PUBLIC_EXPONENT, 2, 0, 0); 864 crv = sftk_ConstrainAttribute(object, CKA_PUBLIC_EXPONENT, 2, 0, 0);
857 if (crv != CKR_OK) { 865 if (crv != CKR_OK) {
858 return crv; 866 return crv;
859 } 867 }
860 break; 868 break;
861 case CKK_DSA: 869 case CKK_DSA:
862 crv = sftk_ConstrainAttribute(object, CKA_SUBPRIME, 870 crv = sftk_ConstrainAttribute(object, CKA_SUBPRIME,
863 » » » » » » DSA_Q_BITS, DSA_Q_BITS, 0); 871 » » » » » DSA_MIN_Q_BITS, DSA_MAX_Q_BITS, 0);
864 if (crv != CKR_OK) { 872 if (crv != CKR_OK) {
865 return crv; 873 return crv;
866 } 874 }
867 crv = sftk_ConstrainAttribute(object, CKA_PRIME, 875 crv = sftk_ConstrainAttribute(object, CKA_PRIME,
868 DSA_MIN_P_BITS, DSA_MAX_P_BITS, 64); 876 DSA_MIN_P_BITS, DSA_MAX_P_BITS, 64);
869 if (crv != CKR_OK) { 877 if (crv != CKR_OK) {
870 return crv; 878 return crv;
871 } 879 }
872 » crv = sftk_ConstrainAttribute(object, CKA_BASE, 1, DSA_MAX_P_BITS, 0); 880 » crv = sftk_ConstrainAttribute(object, CKA_BASE, 2, DSA_MAX_P_BITS, 0);
873 if (crv != CKR_OK) { 881 if (crv != CKR_OK) {
874 return crv; 882 return crv;
875 } 883 }
876 » crv = sftk_ConstrainAttribute(object, CKA_VALUE, 1, DSA_MAX_P_BITS, 0); 884 » crv = sftk_ConstrainAttribute(object, CKA_VALUE, 2, DSA_MAX_P_BITS, 0);
877 if (crv != CKR_OK) { 885 if (crv != CKR_OK) {
878 return crv; 886 return crv;
879 } 887 }
880 encrypt = CK_FALSE; 888 encrypt = CK_FALSE;
881 recover = CK_FALSE; 889 recover = CK_FALSE;
882 wrap = CK_FALSE; 890 wrap = CK_FALSE;
883 break; 891 break;
884 case CKK_DH: 892 case CKK_DH:
885 crv = sftk_ConstrainAttribute(object, CKA_PRIME, 893 crv = sftk_ConstrainAttribute(object, CKA_PRIME,
886 DH_MIN_P_BITS, DH_MAX_P_BITS, 0); 894 DH_MIN_P_BITS, DH_MAX_P_BITS, 0);
887 if (crv != CKR_OK) { 895 if (crv != CKR_OK) {
888 return crv; 896 return crv;
889 } 897 }
890 » crv = sftk_ConstrainAttribute(object, CKA_BASE, 1, DH_MAX_P_BITS, 0); 898 » crv = sftk_ConstrainAttribute(object, CKA_BASE, 2, DH_MAX_P_BITS, 0);
891 if (crv != CKR_OK) { 899 if (crv != CKR_OK) {
892 return crv; 900 return crv;
893 } 901 }
894 » crv = sftk_ConstrainAttribute(object, CKA_VALUE, 1, DH_MAX_P_BITS, 0); 902 » crv = sftk_ConstrainAttribute(object, CKA_VALUE, 2, DH_MAX_P_BITS, 0);
895 if (crv != CKR_OK) { 903 if (crv != CKR_OK) {
896 return crv; 904 return crv;
897 } 905 }
898 verify = CK_FALSE; 906 verify = CK_FALSE;
899 derive = CK_TRUE; 907 derive = CK_TRUE;
900 encrypt = CK_FALSE; 908 encrypt = CK_FALSE;
901 recover = CK_FALSE; 909 recover = CK_FALSE;
902 wrap = CK_FALSE; 910 wrap = CK_FALSE;
903 break; 911 break;
904 #ifdef NSS_ENABLE_ECC 912 #ifdef NSS_ENABLE_ECC
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 SFTKAttribute *primeAttr = NULL; 1350 SFTKAttribute *primeAttr = NULL;
1343 SFTKAttribute *subPrimeAttr = NULL; 1351 SFTKAttribute *subPrimeAttr = NULL;
1344 SFTKAttribute *baseAttr = NULL; 1352 SFTKAttribute *baseAttr = NULL;
1345 SFTKAttribute *seedAttr = NULL; 1353 SFTKAttribute *seedAttr = NULL;
1346 SFTKAttribute *hAttr = NULL; 1354 SFTKAttribute *hAttr = NULL;
1347 SFTKAttribute *attribute; 1355 SFTKAttribute *attribute;
1348 CK_RV crv = CKR_TEMPLATE_INCOMPLETE; 1356 CK_RV crv = CKR_TEMPLATE_INCOMPLETE;
1349 PQGParams params; 1357 PQGParams params;
1350 PQGVerify vfy, *verify = NULL; 1358 PQGVerify vfy, *verify = NULL;
1351 SECStatus result,rv; 1359 SECStatus result,rv;
1360 /* This bool keeps track of whether or not we need verify parameters.
1361 * If a P, Q and G or supplied, we dont' need verify parameters, as we
1362 * have PQ and G.
1363 * - If G is not supplied, the presumption is that we want to
1364 * verify P and Q only.
1365 * - If counter is supplied, it is presumed we want to verify PQ because
1366 * the counter is only used in verification.
1367 * - If H is supplied, is is presumed we want to verify G because H is
1368 * only used to verify G.
1369 * - Any verification step must have the SEED (counter or H could be
1370 * missing depending on exactly what we want to verify). If SEED is supplied ,
1371 * the code just goes ahead and runs verify (other errors are parameter
1372 * errors are detected by the PQG_VerifyParams function). If SEED is not
1373 * supplied, but we determined that we are trying to verify (because needVfy
1374 * is set, go ahead and return CKR_TEMPLATE_INCOMPLETE.
1375 */
1376 PRBool needVfy = PR_FALSE;
1352 1377
1353 primeAttr = sftk_FindAttribute(object,CKA_PRIME); 1378 primeAttr = sftk_FindAttribute(object,CKA_PRIME);
1354 if (primeAttr == NULL) goto loser; 1379 if (primeAttr == NULL) goto loser;
1355 params.prime.data = primeAttr->attrib.pValue; 1380 params.prime.data = primeAttr->attrib.pValue;
1356 params.prime.len = primeAttr->attrib.ulValueLen; 1381 params.prime.len = primeAttr->attrib.ulValueLen;
1357 1382
1358 subPrimeAttr = sftk_FindAttribute(object,CKA_SUBPRIME); 1383 subPrimeAttr = sftk_FindAttribute(object,CKA_SUBPRIME);
1359 if (subPrimeAttr == NULL) goto loser; 1384 if (subPrimeAttr == NULL) goto loser;
1360 params.subPrime.data = subPrimeAttr->attrib.pValue; 1385 params.subPrime.data = subPrimeAttr->attrib.pValue;
1361 params.subPrime.len = subPrimeAttr->attrib.ulValueLen; 1386 params.subPrime.len = subPrimeAttr->attrib.ulValueLen;
1362 1387
1363 baseAttr = sftk_FindAttribute(object,CKA_BASE); 1388 baseAttr = sftk_FindAttribute(object,CKA_BASE);
1364 if (baseAttr == NULL) goto loser; 1389 if (baseAttr != NULL) {
1365 params.base.data = baseAttr->attrib.pValue; 1390 » params.base.data = baseAttr->attrib.pValue;
1366 params.base.len = baseAttr->attrib.ulValueLen; 1391 » params.base.len = baseAttr->attrib.ulValueLen;
1392 } else {
1393 » params.base.data = NULL;
1394 » params.base.len = 0;
1395 » needVfy = PR_TRUE; /* presumably only including PQ so we can verify
1396 » » » * them. */
1397 }
1367 1398
1368 attribute = sftk_FindAttribute(object, CKA_NETSCAPE_PQG_COUNTER); 1399 attribute = sftk_FindAttribute(object, CKA_NETSCAPE_PQG_COUNTER);
1369 if (attribute != NULL) { 1400 if (attribute != NULL) {
1370 vfy.counter = *(CK_ULONG *) attribute->attrib.pValue; 1401 vfy.counter = *(CK_ULONG *) attribute->attrib.pValue;
1371 sftk_FreeAttribute(attribute); 1402 sftk_FreeAttribute(attribute);
1403 needVfy = PR_TRUE; /* included a count so we can verify PQ */
1404 } else {
1405 vfy.counter = -1;
1406 }
1372 1407
1373 » seedAttr = sftk_FindAttribute(object, CKA_NETSCAPE_PQG_SEED); 1408 hAttr = sftk_FindAttribute(object, CKA_NETSCAPE_PQG_H);
1374 » if (seedAttr == NULL) goto loser; 1409 if (hAttr != NULL) {
1410 » vfy.h.data = hAttr->attrib.pValue;
1411 » vfy.h.len = hAttr->attrib.ulValueLen;
1412 » needVfy = PR_TRUE; /* included H so we can verify G */
1413 } else {
1414 » vfy.h.data = NULL;
1415 » vfy.h.len = 0;
1416 }
1417 seedAttr = sftk_FindAttribute(object, CKA_NETSCAPE_PQG_SEED);
1418 if (seedAttr != NULL) {
1375 vfy.seed.data = seedAttr->attrib.pValue; 1419 vfy.seed.data = seedAttr->attrib.pValue;
1376 vfy.seed.len = seedAttr->attrib.ulValueLen; 1420 vfy.seed.len = seedAttr->attrib.ulValueLen;
1377 1421
1378 hAttr = sftk_FindAttribute(object, CKA_NETSCAPE_PQG_H);
1379 if (hAttr == NULL) goto loser;
1380 vfy.h.data = hAttr->attrib.pValue;
1381 vfy.h.len = hAttr->attrib.ulValueLen;
1382
1383 verify = &vfy; 1422 verify = &vfy;
1423 } else if (needVfy) {
1424 goto loser; /* Verify always needs seed, if we need verify and not seed
1425 * then fail */
1384 } 1426 }
1385 1427
1386 crv = CKR_FUNCTION_FAILED; 1428 crv = CKR_FUNCTION_FAILED;
1387 rv = PQG_VerifyParams(&params,verify,&result); 1429 rv = PQG_VerifyParams(&params,verify,&result);
1388 if (rv == SECSuccess) { 1430 if (rv == SECSuccess) {
1389 crv = (result== SECSuccess) ? CKR_OK : CKR_ATTRIBUTE_VALUE_INVALID; 1431 crv = (result== SECSuccess) ? CKR_OK : CKR_ATTRIBUTE_VALUE_INVALID;
1390 } 1432 }
1391 1433
1392 loser: 1434 loser:
1393 if (hAttr) sftk_FreeAttribute(hAttr); 1435 if (hAttr) sftk_FreeAttribute(hAttr);
(...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after
2583 slot->objectLock = NULL; 2625 slot->objectLock = NULL;
2584 } 2626 }
2585 if (slot->pwCheckLock) { 2627 if (slot->pwCheckLock) {
2586 SKIP_AFTER_FORK(PR_DestroyLock(slot->pwCheckLock)); 2628 SKIP_AFTER_FORK(PR_DestroyLock(slot->pwCheckLock));
2587 slot->pwCheckLock = NULL; 2629 slot->pwCheckLock = NULL;
2588 } 2630 }
2589 PORT_Free(slot); 2631 PORT_Free(slot);
2590 return CKR_OK; 2632 return CKR_OK;
2591 } 2633 }
2592 2634
2593 #ifndef NO_FORK_CHECK
2594
2595 static CK_RV ForkCheck(void)
2596 {
2597 CHECK_FORK();
2598 return CKR_OK;
2599 }
2600
2601 #endif
2602
2603 /* 2635 /*
2604 * handle the SECMOD.db 2636 * handle the SECMOD.db
2605 */ 2637 */
2606 char ** 2638 char **
2607 NSC_ModuleDBFunc(unsigned long function,char *parameters, void *args) 2639 NSC_ModuleDBFunc(unsigned long function,char *parameters, void *args)
2608 { 2640 {
2609 char *secmod = NULL; 2641 char *secmod = NULL;
2610 char *appName = NULL; 2642 char *appName = NULL;
2611 char *filename = NULL; 2643 char *filename = NULL;
2612 #ifdef NSS_DISABLE_DBM 2644 NSSDBType dbType = NSS_DB_TYPE_NONE;
2613 SDBType dbType = SDB_SQL;
2614 #else
2615 SDBType dbType = SDB_LEGACY;
2616 #endif
2617 PRBool rw; 2645 PRBool rw;
2618 static char *success="Success"; 2646 static char *success="Success";
2619 char **rvstr = NULL; 2647 char **rvstr = NULL;
2620 2648
2621 #ifndef NO_FORK_CHECK 2649 rvstr = NSSUTIL_DoModuleDBFunction(function, parameters, args);
2622 if (CKR_OK != ForkCheck()) return NULL; 2650 if (rvstr != NULL) {
2623 #endif 2651 » return rvstr;
2652 }
2624 2653
2625 secmod = sftk_getSecmodName(parameters, &dbType, &appName,&filename, &rw); 2654 if (PORT_GetError() != SEC_ERROR_LEGACY_DATABASE) {
2655 » return NULL;
2656 }
2657
2658 /* The legacy database uses the old dbm, which is only linked with the
2659 * legacy DB handler, which is only callable from softoken */
2660
2661 secmod = _NSSUTIL_GetSecmodName(parameters, &dbType, &appName,
2662 » » » » &filename, &rw);
2626 2663
2627 switch (function) { 2664 switch (function) {
2628 case SECMOD_MODULE_DB_FUNCTION_FIND: 2665 case SECMOD_MODULE_DB_FUNCTION_FIND:
2629 » rvstr = sftkdb_ReadSecmodDB(dbType,appName,filename,secmod,(char *)param eters,rw); 2666 » if (secmod == NULL) {
2667 » PORT_SetError(SEC_ERROR_INVALID_ARGS);
2668 » return NULL;
2669 » }
2670 » if (rw && (dbType != NSS_DB_TYPE_LEGACY) &&
2671 » (dbType != NSS_DB_TYPE_MULTIACCESS)) {
2672 » /* if we get here, we are trying to update the local database */
2673 » /* force data from the legacy DB */
2674 » char *oldSecmod = NULL;
2675 » char *oldAppName = NULL;
2676 » char *oldFilename = NULL;
2677 » PRBool oldrw;
2678 » char **strings = NULL;
2679 » int i;
2680
2681 » dbType = NSS_DB_TYPE_LEGACY;
2682 » oldSecmod = _NSSUTIL_GetSecmodName(parameters,&dbType, &oldAppName,
2683 » » » » » &oldFilename, &oldrw);
2684 » strings = sftkdbCall_ReadSecmodDB(appName, oldFilename, oldSecmod,
2685 » » » » » (char *)parameters, oldrw);
2686 » if (strings) {
2687 » » /* write out the strings */
2688 » » for (i=0; strings[i]; i++) {
2689 » » NSSUTIL_DoModuleDBFunction(SECMOD_MODULE_DB_FUNCTION_ADD,
2690 » » » » parameters, strings[i]);
2691 » » }
2692 » » sftkdbCall_ReleaseSecmodDBData(oldAppName,oldFilename,oldSecmod,
2693 » » » (char **)strings,oldrw);
2694 » } else {
2695 » » /* write out a dummy record */
2696 » » NSSUTIL_DoModuleDBFunction(SECMOD_MODULE_DB_FUNCTION_ADD,
2697 » » » » parameters, " ");
2698 » }
2699 » if (oldSecmod) { PR_smprintf_free(oldSecmod); }
2700 » if (oldAppName) { PORT_Free(oldAppName); }
2701 » if (oldFilename) { PORT_Free(oldFilename); }
2702 » rvstr = NSSUTIL_DoModuleDBFunction(function, parameters, args);
2703 » break;
2704 » }
2705 » rvstr = sftkdbCall_ReadSecmodDB(appName,filename,secmod,
2706 » » » » » (char *)parameters,rw);
2630 break; 2707 break;
2631 case SECMOD_MODULE_DB_FUNCTION_ADD: 2708 case SECMOD_MODULE_DB_FUNCTION_ADD:
2632 » rvstr = (sftkdb_AddSecmodDB(dbType,appName,filename,secmod,(char *)args, rw) 2709 » if (secmod == NULL) {
2633 » » » » == SECSuccess) ? &success: NULL; 2710 » PORT_SetError(SEC_ERROR_INVALID_ARGS);
2711 » return NULL;
2712 » }
2713 » rvstr = (sftkdbCall_AddSecmodDB(appName,filename,secmod,
2714 » » » (char *)args,rw) == SECSuccess) ? &success: NULL;
2634 break; 2715 break;
2635 case SECMOD_MODULE_DB_FUNCTION_DEL: 2716 case SECMOD_MODULE_DB_FUNCTION_DEL:
2636 » rvstr = (sftkdb_DeleteSecmodDB(dbType,appName,filename,secmod,(char *)ar gs,rw) 2717 » if (secmod == NULL) {
2637 » » » » == SECSuccess) ? &success: NULL; 2718 » PORT_SetError(SEC_ERROR_INVALID_ARGS);
2719 » return NULL;
2720 » }
2721 » rvstr = (sftkdbCall_DeleteSecmodDB(appName,filename,secmod,
2722 » » » (char *)args,rw) == SECSuccess) ? &success: NULL;
2638 break; 2723 break;
2639 case SECMOD_MODULE_DB_FUNCTION_RELEASE: 2724 case SECMOD_MODULE_DB_FUNCTION_RELEASE:
2640 » rvstr = (sftkdb_ReleaseSecmodDBData(dbType, appName,filename,secmod, 2725 » rvstr = (sftkdbCall_ReleaseSecmodDBData(appName,filename,secmod,
2641 (char **)args,rw) == SECSuccess) ? &success: NULL; 2726 (char **)args,rw) == SECSuccess) ? &success: NULL;
2642 break; 2727 break;
2643 } 2728 }
2644 if (secmod) PR_smprintf_free(secmod); 2729 if (secmod) PR_smprintf_free(secmod);
2645 if (appName) PORT_Free(appName); 2730 if (appName) PORT_Free(appName);
2646 if (filename) PORT_Free(filename); 2731 if (filename) PORT_Free(filename);
2647 return rvstr; 2732 return rvstr;
2648 } 2733 }
2649 2734
2650 static void nscFreeAllSlots(int moduleIndex) 2735 static void nscFreeAllSlots(int moduleIndex)
(...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after
3809 PZ_Unlock(slot->slotLock); 3894 PZ_Unlock(slot->slotLock);
3810 if (handle) { 3895 if (handle) {
3811 sftk_freeDB(handle); 3896 sftk_freeDB(handle);
3812 } 3897 }
3813 3898
3814 sftk_update_all_states(slot); 3899 sftk_update_all_states(slot);
3815 return CKR_OK; 3900 return CKR_OK;
3816 } 3901 }
3817 3902
3818 /* 3903 /*
3819 * Create a new slot on the fly. The slot that is passed in is the 3904 * Create or remove a new slot on the fly.
3820 * slot the request came from. Only the crypto or FIPS slots can 3905 * When creating a slot, "slot" is the slot that the request came from. The
3821 * be used. The resulting slot will live in the same module as 3906 * resulting slot will live in the same module as "slot".
3822 * the slot the request was passed to. object is the creation object 3907 * When removing a slot, "slot" is the slot to be removed.
3823 * that specifies the module spec for the new slot. 3908 * "object" is the creation object that specifies the module spec for the slot
3909 * to add or remove.
3824 */ 3910 */
3825 static CK_RV sftk_CreateNewSlot(SFTKSlot *slot, CK_OBJECT_CLASS class, 3911 static CK_RV sftk_CreateNewSlot(SFTKSlot *slot, CK_OBJECT_CLASS class,
3826 SFTKObject *object) 3912 SFTKObject *object)
3827 { 3913 {
3828 CK_SLOT_ID idMin, idMax; 3914 PRBool isValidUserSlot = PR_FALSE;
3915 PRBool isValidFIPSUserSlot = PR_FALSE;
3916 PRBool isValidSlot = PR_FALSE;
3829 PRBool isFIPS = PR_FALSE; 3917 PRBool isFIPS = PR_FALSE;
3830 unsigned long moduleIndex; 3918 unsigned long moduleIndex;
3831 SFTKAttribute *attribute; 3919 SFTKAttribute *attribute;
3832 sftk_parameters paramStrings; 3920 sftk_parameters paramStrings;
3833 char *paramString; 3921 char *paramString;
3834 CK_SLOT_ID slotID = 0; 3922 CK_SLOT_ID slotID = 0;
3835 SFTKSlot *newSlot = NULL; 3923 SFTKSlot *newSlot = NULL;
3836 CK_RV crv = CKR_OK; 3924 CK_RV crv = CKR_OK;
3837 3925
3838 /* only the crypto or FIPS slots can create new slot objects */ 3926 if (class != CKO_NETSCAPE_DELSLOT && class != CKO_NETSCAPE_NEWSLOT) {
3839 if (slot->slotID == NETSCAPE_SLOT_ID) {
3840 » idMin = SFTK_MIN_USER_SLOT_ID;
3841 » idMax = SFTK_MAX_USER_SLOT_ID;
3842 » moduleIndex = NSC_NON_FIPS_MODULE;
3843 » isFIPS = PR_FALSE;
3844 } else if (slot->slotID == FIPS_SLOT_ID) {
3845 » idMin = SFTK_MIN_FIPS_USER_SLOT_ID;
3846 » idMax = SFTK_MAX_FIPS_USER_SLOT_ID;
3847 » moduleIndex = NSC_FIPS_MODULE;
3848 » isFIPS = PR_TRUE;
3849 } else {
3850 return CKR_ATTRIBUTE_VALUE_INVALID; 3927 return CKR_ATTRIBUTE_VALUE_INVALID;
3851 } 3928 }
3852 attribute = sftk_FindAttribute(object,CKA_NETSCAPE_MODULE_SPEC); 3929 if (class == CKO_NETSCAPE_NEWSLOT && slot->slotID == FIPS_SLOT_ID) {
3930 » isFIPS = PR_TRUE;
3931 }
3932 attribute = sftk_FindAttribute(object, CKA_NETSCAPE_MODULE_SPEC);
3853 if (attribute == NULL) { 3933 if (attribute == NULL) {
3854 return CKR_TEMPLATE_INCOMPLETE; 3934 return CKR_TEMPLATE_INCOMPLETE;
3855 } 3935 }
3856 paramString = (char *)attribute->attrib.pValue; 3936 paramString = (char *)attribute->attrib.pValue;
3857 crv = sftk_parseParameters(paramString, &paramStrings, isFIPS); 3937 crv = sftk_parseParameters(paramString, &paramStrings, isFIPS);
3858 if (crv != CKR_OK) { 3938 if (crv != CKR_OK) {
3859 goto loser; 3939 goto loser;
3860 } 3940 }
3861 3941
3862 /* enforce only one at a time */ 3942 /* enforce only one at a time */
3863 if (paramStrings.token_count != 1) { 3943 if (paramStrings.token_count != 1) {
3864 crv = CKR_ATTRIBUTE_VALUE_INVALID; 3944 crv = CKR_ATTRIBUTE_VALUE_INVALID;
3865 goto loser; 3945 goto loser;
3866 } 3946 }
3867 3947
3868 slotID = paramStrings.tokens[0].slotID; 3948 slotID = paramStrings.tokens[0].slotID;
3869 3949
3870 /* stay within the valid ID space */ 3950 /* stay within the valid ID space */
3871 if ((slotID < idMin) || (slotID > idMax)) { 3951 isValidUserSlot = (slotID >= SFTK_MIN_USER_SLOT_ID &&
3952 slotID <= SFTK_MAX_USER_SLOT_ID);
3953 isValidFIPSUserSlot = (slotID >= SFTK_MIN_FIPS_USER_SLOT_ID &&
3954 slotID <= SFTK_MAX_FIPS_USER_SLOT_ID);
3955
3956 if (class == CKO_NETSCAPE_DELSLOT) {
3957 » if (slot->slotID == slotID) {
3958 » isValidSlot = isValidUserSlot || isValidFIPSUserSlot;
3959 » }
3960 } else {
3961 » /* only the crypto or FIPS slots can create new slot objects */
3962 » if (slot->slotID == NETSCAPE_SLOT_ID) {
3963 » isValidSlot = isValidUserSlot;
3964 » moduleIndex = NSC_NON_FIPS_MODULE;
3965 » } else if (slot->slotID == FIPS_SLOT_ID) {
3966 » isValidSlot = isValidFIPSUserSlot;
3967 » moduleIndex = NSC_FIPS_MODULE;
3968 » }
3969 }
3970
3971 if (!isValidSlot) {
3872 crv = CKR_ATTRIBUTE_VALUE_INVALID; 3972 crv = CKR_ATTRIBUTE_VALUE_INVALID;
3873 goto loser; 3973 goto loser;
3874 } 3974 }
3875 3975
3876 /* unload any existing slot at this id */ 3976 /* unload any existing slot at this id */
3877 newSlot = sftk_SlotFromID(slotID, PR_TRUE); 3977 newSlot = sftk_SlotFromID(slotID, PR_TRUE);
3878 if (newSlot && newSlot->present) { 3978 if (newSlot && newSlot->present) {
3879 crv = SFTK_ShutdownSlot(newSlot); 3979 crv = SFTK_ShutdownSlot(newSlot);
3880 if (crv != CKR_OK) { 3980 if (crv != CKR_OK) {
3881 goto loser; 3981 goto loser;
3882 } 3982 }
3883 } 3983 }
3884 3984
3885 /* if we were just planning on deleting the slot, then do so now */ 3985 /* if we were just planning on deleting the slot, then do so now */
3886 if (class == CKO_NETSCAPE_DELSLOT) { 3986 if (class == CKO_NETSCAPE_DELSLOT) {
3887 /* sort of a unconventional use of this error code, be we are 3987 /* sort of a unconventional use of this error code, be we are
3888 * overusing CKR_ATTRIBUTE_VALUE_INVALID, and it does apply */ 3988 » * overusing CKR_ATTRIBUTE_VALUE_INVALID, and it does apply */
3889 crv = newSlot ? CKR_OK : CKR_SLOT_ID_INVALID; 3989 crv = newSlot ? CKR_OK : CKR_SLOT_ID_INVALID;
3890 goto loser; /* really exit */ 3990 goto loser; /* really exit */
3891 } 3991 }
3892 3992
3893 if (newSlot) { 3993 if (newSlot) {
3894 crv = SFTK_SlotReInit(newSlot, paramStrings.configdir, 3994 crv = SFTK_SlotReInit(newSlot, paramStrings.configdir,
3895 paramStrings.updatedir, paramStrings.updateID, 3995 paramStrings.updatedir, paramStrings.updateID,
3896 &paramStrings.tokens[0], moduleIndex); 3996 &paramStrings.tokens[0], moduleIndex);
3897 } else { 3997 } else {
3898 crv = SFTK_SlotInit(paramStrings.configdir, 3998 crv = SFTK_SlotInit(paramStrings.configdir,
3899 paramStrings.updatedir, paramStrings.updateID, 3999 paramStrings.updatedir, paramStrings.updateID,
3900 &paramStrings.tokens[0], moduleIndex); 4000 &paramStrings.tokens[0], moduleIndex);
3901 } 4001 }
3902 if (crv != CKR_OK) { 4002
3903 » goto loser;
3904 }
3905 loser: 4003 loser:
3906 sftk_freeParams(&paramStrings); 4004 sftk_freeParams(&paramStrings);
3907 sftk_FreeAttribute(attribute); 4005 sftk_FreeAttribute(attribute);
3908 4006
3909 return crv; 4007 return crv;
3910 } 4008 }
3911 4009
3912 4010
3913 /* NSC_CreateObject creates a new object. */ 4011 /* NSC_CreateObject creates a new object. */
3914 CK_RV NSC_CreateObject(CK_SESSION_HANDLE hSession, 4012 CK_RV NSC_CreateObject(CK_SESSION_HANDLE hSession,
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
4595 4693
4596 4694
4597 CK_RV NSC_WaitForSlotEvent(CK_FLAGS flags, CK_SLOT_ID_PTR pSlot, 4695 CK_RV NSC_WaitForSlotEvent(CK_FLAGS flags, CK_SLOT_ID_PTR pSlot,
4598 CK_VOID_PTR pReserved) 4696 CK_VOID_PTR pReserved)
4599 { 4697 {
4600 CHECK_FORK(); 4698 CHECK_FORK();
4601 4699
4602 return CKR_FUNCTION_NOT_SUPPORTED; 4700 return CKR_FUNCTION_NOT_SUPPORTED;
4603 } 4701 }
4604 4702
OLDNEW
« no previous file with comments | « mozilla/security/nss/lib/softoken/pk11pars.h ('k') | mozilla/security/nss/lib/softoken/pkcs11c.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698