| OLD | NEW |
| 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 Loading... |
| 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 2571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2619 slot->objectLock = NULL; | 2621 slot->objectLock = NULL; |
| 2620 } | 2622 } |
| 2621 if (slot->pwCheckLock) { | 2623 if (slot->pwCheckLock) { |
| 2622 SKIP_AFTER_FORK(PR_DestroyLock(slot->pwCheckLock)); | 2624 SKIP_AFTER_FORK(PR_DestroyLock(slot->pwCheckLock)); |
| 2623 slot->pwCheckLock = NULL; | 2625 slot->pwCheckLock = NULL; |
| 2624 } | 2626 } |
| 2625 PORT_Free(slot); | 2627 PORT_Free(slot); |
| 2626 return CKR_OK; | 2628 return CKR_OK; |
| 2627 } | 2629 } |
| 2628 | 2630 |
| 2629 #ifndef NO_FORK_CHECK | |
| 2630 | |
| 2631 static CK_RV ForkCheck(void) | |
| 2632 { | |
| 2633 CHECK_FORK(); | |
| 2634 return CKR_OK; | |
| 2635 } | |
| 2636 | |
| 2637 #endif | |
| 2638 | |
| 2639 /* | 2631 /* |
| 2640 * handle the SECMOD.db | 2632 * handle the SECMOD.db |
| 2641 */ | 2633 */ |
| 2642 char ** | 2634 char ** |
| 2643 NSC_ModuleDBFunc(unsigned long function,char *parameters, void *args) | 2635 NSC_ModuleDBFunc(unsigned long function,char *parameters, void *args) |
| 2644 { | 2636 { |
| 2645 char *secmod = NULL; | 2637 char *secmod = NULL; |
| 2646 char *appName = NULL; | 2638 char *appName = NULL; |
| 2647 char *filename = NULL; | 2639 char *filename = NULL; |
| 2648 #ifdef NSS_DISABLE_DBM | 2640 NSSDBType dbType = NSS_DB_TYPE_NONE; |
| 2649 SDBType dbType = SDB_SQL; | |
| 2650 #else | |
| 2651 SDBType dbType = SDB_LEGACY; | |
| 2652 #endif | |
| 2653 PRBool rw; | 2641 PRBool rw; |
| 2654 static char *success="Success"; | 2642 static char *success="Success"; |
| 2655 char **rvstr = NULL; | 2643 char **rvstr = NULL; |
| 2656 | 2644 |
| 2657 #ifndef NO_FORK_CHECK | 2645 rvstr = NSSUTIL_DoModuleDBFunction(function, parameters, args); |
| 2658 if (CKR_OK != ForkCheck()) return NULL; | 2646 if (rvstr != NULL) { |
| 2659 #endif | 2647 » return rvstr; |
| 2648 } |
| 2660 | 2649 |
| 2661 secmod = sftk_getSecmodName(parameters, &dbType, &appName,&filename, &rw); | 2650 if (PORT_GetError() != SEC_ERROR_LEGACY_DATABASE) { |
| 2651 » return NULL; |
| 2652 } |
| 2653 |
| 2654 /* The legacy database uses the old dbm, which is only linked with the |
| 2655 * legacy DB handler, which is only callable from softoken */ |
| 2656 |
| 2657 secmod = _NSSUTIL_GetSecmodName(parameters, &dbType, &appName, |
| 2658 » » » » &filename, &rw); |
| 2662 | 2659 |
| 2663 switch (function) { | 2660 switch (function) { |
| 2664 case SECMOD_MODULE_DB_FUNCTION_FIND: | 2661 case SECMOD_MODULE_DB_FUNCTION_FIND: |
| 2665 » rvstr = sftkdb_ReadSecmodDB(dbType,appName,filename,secmod,(char *)param
eters,rw); | 2662 » if (secmod == NULL) { |
| 2663 » PORT_SetError(SEC_ERROR_INVALID_ARGS); |
| 2664 » return NULL; |
| 2665 » } |
| 2666 » if (rw && (dbType != NSS_DB_TYPE_LEGACY) && |
| 2667 » (dbType != NSS_DB_TYPE_MULTIACCESS)) { |
| 2668 » /* if we get here, we are trying to update the local database */ |
| 2669 » /* force data from the legacy DB */ |
| 2670 » char *oldSecmod = NULL; |
| 2671 » char *oldAppName = NULL; |
| 2672 » char *oldFilename = NULL; |
| 2673 » char *end; |
| 2674 » PRBool oldrw; |
| 2675 » char **strings = NULL; |
| 2676 » int i; |
| 2677 |
| 2678 » dbType = NSS_DB_TYPE_LEGACY; |
| 2679 » oldSecmod = _NSSUTIL_GetSecmodName(parameters,&dbType, &oldAppName, |
| 2680 » » » » » &oldFilename, &oldrw); |
| 2681 » strings = sftkdbCall_ReadSecmodDB(appName, oldFilename, oldSecmod, |
| 2682 » » » » » (char *)parameters, oldrw); |
| 2683 » if (strings) { |
| 2684 » » /* write out the strings */ |
| 2685 » » for (i=0; strings[i]; i++) { |
| 2686 » » NSSUTIL_DoModuleDBFunction(SECMOD_MODULE_DB_FUNCTION_ADD, |
| 2687 » » » » parameters, strings[i]); |
| 2688 » » } |
| 2689 » » sftkdbCall_ReleaseSecmodDBData(oldAppName,oldFilename,oldSecmod, |
| 2690 » » » (char **)strings,oldrw); |
| 2691 » } else { |
| 2692 » » /* write out a dummy record */ |
| 2693 » » NSSUTIL_DoModuleDBFunction(SECMOD_MODULE_DB_FUNCTION_ADD, |
| 2694 » » » » parameters, " "); |
| 2695 » } |
| 2696 » if (oldSecmod) { PR_smprintf_free(oldSecmod); } |
| 2697 » if (oldAppName) { PORT_Free(oldAppName); } |
| 2698 » if (oldFilename) { PORT_Free(oldFilename); } |
| 2699 » rvstr = NSSUTIL_DoModuleDBFunction(function, parameters, args); |
| 2700 » break; |
| 2701 » } |
| 2702 » rvstr = sftkdbCall_ReadSecmodDB(appName,filename,secmod, |
| 2703 » » » » » (char *)parameters,rw); |
| 2666 break; | 2704 break; |
| 2667 case SECMOD_MODULE_DB_FUNCTION_ADD: | 2705 case SECMOD_MODULE_DB_FUNCTION_ADD: |
| 2668 » rvstr = (sftkdb_AddSecmodDB(dbType,appName,filename,secmod,(char *)args,
rw) | 2706 » if (secmod == NULL) { |
| 2669 » » » » == SECSuccess) ? &success: NULL; | 2707 » PORT_SetError(SEC_ERROR_INVALID_ARGS); |
| 2708 » return NULL; |
| 2709 » } |
| 2710 » rvstr = (sftkdbCall_AddSecmodDB(appName,filename,secmod, |
| 2711 » » » (char *)args,rw) == SECSuccess) ? &success: NULL; |
| 2670 break; | 2712 break; |
| 2671 case SECMOD_MODULE_DB_FUNCTION_DEL: | 2713 case SECMOD_MODULE_DB_FUNCTION_DEL: |
| 2672 » rvstr = (sftkdb_DeleteSecmodDB(dbType,appName,filename,secmod,(char *)ar
gs,rw) | 2714 » if (secmod == NULL) { |
| 2673 » » » » == SECSuccess) ? &success: NULL; | 2715 » PORT_SetError(SEC_ERROR_INVALID_ARGS); |
| 2716 » return NULL; |
| 2717 » } |
| 2718 » rvstr = (sftkdbCall_DeleteSecmodDB(appName,filename,secmod, |
| 2719 » » » (char *)args,rw) == SECSuccess) ? &success: NULL; |
| 2674 break; | 2720 break; |
| 2675 case SECMOD_MODULE_DB_FUNCTION_RELEASE: | 2721 case SECMOD_MODULE_DB_FUNCTION_RELEASE: |
| 2676 » rvstr = (sftkdb_ReleaseSecmodDBData(dbType, appName,filename,secmod, | 2722 » rvstr = (sftkdbCall_ReleaseSecmodDBData(appName,filename,secmod, |
| 2677 (char **)args,rw) == SECSuccess) ? &success: NULL; | 2723 (char **)args,rw) == SECSuccess) ? &success: NULL; |
| 2678 break; | 2724 break; |
| 2679 } | 2725 } |
| 2680 if (secmod) PR_smprintf_free(secmod); | 2726 if (secmod) PR_smprintf_free(secmod); |
| 2681 if (appName) PORT_Free(appName); | 2727 if (appName) PORT_Free(appName); |
| 2682 if (filename) PORT_Free(filename); | 2728 if (filename) PORT_Free(filename); |
| 2683 return rvstr; | 2729 return rvstr; |
| 2684 } | 2730 } |
| 2685 | 2731 |
| 2686 static void nscFreeAllSlots(int moduleIndex) | 2732 static void nscFreeAllSlots(int moduleIndex) |
| (...skipping 1944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4631 | 4677 |
| 4632 | 4678 |
| 4633 CK_RV NSC_WaitForSlotEvent(CK_FLAGS flags, CK_SLOT_ID_PTR pSlot, | 4679 CK_RV NSC_WaitForSlotEvent(CK_FLAGS flags, CK_SLOT_ID_PTR pSlot, |
| 4634 CK_VOID_PTR pReserved) | 4680 CK_VOID_PTR pReserved) |
| 4635 { | 4681 { |
| 4636 CHECK_FORK(); | 4682 CHECK_FORK(); |
| 4637 | 4683 |
| 4638 return CKR_FUNCTION_NOT_SUPPORTED; | 4684 return CKR_FUNCTION_NOT_SUPPORTED; |
| 4639 } | 4685 } |
| 4640 | 4686 |
| OLD | NEW |