Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | /* |
michael@0 | 5 | * Internal header file included only by files in pkcs11 dir, or in |
michael@0 | 6 | * pkcs11 specific client and server files. |
michael@0 | 7 | */ |
michael@0 | 8 | #ifndef _SECMODI_H_ |
michael@0 | 9 | #define _SECMODI_H_ 1 |
michael@0 | 10 | #include "pkcs11.h" |
michael@0 | 11 | #include "nssilock.h" |
michael@0 | 12 | #include "secoidt.h" |
michael@0 | 13 | #include "secdert.h" |
michael@0 | 14 | #include "certt.h" |
michael@0 | 15 | #include "secmodt.h" |
michael@0 | 16 | #include "keyt.h" |
michael@0 | 17 | |
michael@0 | 18 | SEC_BEGIN_PROTOS |
michael@0 | 19 | |
michael@0 | 20 | /* proto-types */ |
michael@0 | 21 | extern SECStatus SECMOD_DeletePermDB(SECMODModule *module); |
michael@0 | 22 | extern SECStatus SECMOD_AddPermDB(SECMODModule *module); |
michael@0 | 23 | extern SECStatus SECMOD_Shutdown(void); |
michael@0 | 24 | void nss_DumpModuleLog(void); |
michael@0 | 25 | |
michael@0 | 26 | extern int secmod_PrivateModuleCount; |
michael@0 | 27 | |
michael@0 | 28 | extern void SECMOD_Init(void); |
michael@0 | 29 | SECStatus secmod_ModuleInit(SECMODModule *mod, SECMODModule **oldModule, |
michael@0 | 30 | PRBool* alreadyLoaded); |
michael@0 | 31 | |
michael@0 | 32 | /* list managment */ |
michael@0 | 33 | extern SECStatus SECMOD_AddModuleToList(SECMODModule *newModule); |
michael@0 | 34 | extern SECStatus SECMOD_AddModuleToDBOnlyList(SECMODModule *newModule); |
michael@0 | 35 | extern SECStatus SECMOD_AddModuleToUnloadList(SECMODModule *newModule); |
michael@0 | 36 | extern void SECMOD_RemoveList(SECMODModuleList **,SECMODModuleList *); |
michael@0 | 37 | extern void SECMOD_AddList(SECMODModuleList *,SECMODModuleList *,SECMODListLock *); |
michael@0 | 38 | extern SECMODListLock *SECMOD_NewListLock(void); |
michael@0 | 39 | extern void SECMOD_DestroyListLock(SECMODListLock *); |
michael@0 | 40 | extern void SECMOD_GetWriteLock(SECMODListLock *); |
michael@0 | 41 | extern void SECMOD_ReleaseWriteLock(SECMODListLock *); |
michael@0 | 42 | |
michael@0 | 43 | /* Operate on modules by name */ |
michael@0 | 44 | extern SECMODModule *SECMOD_FindModuleByID(SECMODModuleID); |
michael@0 | 45 | extern SECMODModule *secmod_FindModuleByFuncPtr(void *funcPtr); |
michael@0 | 46 | |
michael@0 | 47 | /* database/memory management */ |
michael@0 | 48 | extern SECMODModuleList *SECMOD_NewModuleListElement(void); |
michael@0 | 49 | extern SECMODModuleList *SECMOD_DestroyModuleListElement(SECMODModuleList *); |
michael@0 | 50 | extern void SECMOD_DestroyModuleList(SECMODModuleList *); |
michael@0 | 51 | extern SECStatus SECMOD_AddModule(SECMODModule *newModule); |
michael@0 | 52 | |
michael@0 | 53 | extern unsigned long SECMOD_InternaltoPubCipherFlags(unsigned long internalFlags); |
michael@0 | 54 | |
michael@0 | 55 | /* Library functions */ |
michael@0 | 56 | SECStatus secmod_LoadPKCS11Module(SECMODModule *, SECMODModule **oldModule); |
michael@0 | 57 | SECStatus SECMOD_UnloadModule(SECMODModule *); |
michael@0 | 58 | void SECMOD_SetInternalModule(SECMODModule *); |
michael@0 | 59 | PRBool secmod_IsInternalKeySlot(SECMODModule *); |
michael@0 | 60 | void secmod_SetInternalKeySlotFlag(SECMODModule *mod, PRBool val); |
michael@0 | 61 | |
michael@0 | 62 | |
michael@0 | 63 | /* tools for checking if we are loading the same database twice */ |
michael@0 | 64 | typedef struct SECMODConfigListStr SECMODConfigList; |
michael@0 | 65 | /* collect all the databases in a given spec */ |
michael@0 | 66 | SECMODConfigList *secmod_GetConfigList(PRBool isFIPS, char *spec, int *count); |
michael@0 | 67 | /* see is a spec matches a database on the list */ |
michael@0 | 68 | PRBool secmod_MatchConfigList(char *spec, |
michael@0 | 69 | SECMODConfigList *conflist, int count); |
michael@0 | 70 | /* free our list of databases */ |
michael@0 | 71 | void secmod_FreeConfigList(SECMODConfigList *conflist, int count); |
michael@0 | 72 | |
michael@0 | 73 | /* parsing parameters */ |
michael@0 | 74 | /* returned char * must be freed by caller with PORT_Free */ |
michael@0 | 75 | /* children and ids are null terminated arrays which must be freed with |
michael@0 | 76 | * secmod_FreeChildren */ |
michael@0 | 77 | char *secmod_ParseModuleSpecForTokens(PRBool convert, |
michael@0 | 78 | PRBool isFIPS, |
michael@0 | 79 | char *moduleSpec, |
michael@0 | 80 | char ***children, |
michael@0 | 81 | CK_SLOT_ID **ids); |
michael@0 | 82 | void secmod_FreeChildren(char **children, CK_SLOT_ID *ids); |
michael@0 | 83 | char *secmod_MkAppendTokensList(PLArenaPool *arena, char *origModuleSpec, |
michael@0 | 84 | char *newModuleSpec, CK_SLOT_ID newID, |
michael@0 | 85 | char **children, CK_SLOT_ID *ids); |
michael@0 | 86 | |
michael@0 | 87 | |
michael@0 | 88 | void SECMOD_SlotDestroyModule(SECMODModule *module, PRBool fromSlot); |
michael@0 | 89 | CK_RV pk11_notify(CK_SESSION_HANDLE session, CK_NOTIFICATION event, |
michael@0 | 90 | CK_VOID_PTR pdata); |
michael@0 | 91 | void pk11_SignedToUnsigned(CK_ATTRIBUTE *attrib); |
michael@0 | 92 | CK_OBJECT_HANDLE pk11_FindObjectByTemplate(PK11SlotInfo *slot, |
michael@0 | 93 | CK_ATTRIBUTE *inTemplate,int tsize); |
michael@0 | 94 | CK_OBJECT_HANDLE *pk11_FindObjectsByTemplate(PK11SlotInfo *slot, |
michael@0 | 95 | CK_ATTRIBUTE *inTemplate,int tsize, int *objCount); |
michael@0 | 96 | |
michael@0 | 97 | #define PK11_GETTAB(x) ((CK_FUNCTION_LIST_PTR)((x)->functionList)) |
michael@0 | 98 | #define PK11_SETATTRS(x,id,v,l) (x)->type = (id); \ |
michael@0 | 99 | (x)->pValue=(v); (x)->ulValueLen = (l); |
michael@0 | 100 | SECStatus PK11_CreateNewObject(PK11SlotInfo *slot, CK_SESSION_HANDLE session, |
michael@0 | 101 | const CK_ATTRIBUTE *theTemplate, int count, |
michael@0 | 102 | PRBool token, CK_OBJECT_HANDLE *objectID); |
michael@0 | 103 | |
michael@0 | 104 | SECStatus pbe_PK11AlgidToParam(SECAlgorithmID *algid,SECItem *mech); |
michael@0 | 105 | SECStatus PBE_PK11ParamToAlgid(SECOidTag algTag, SECItem *param, |
michael@0 | 106 | PLArenaPool *arena, SECAlgorithmID *algId); |
michael@0 | 107 | |
michael@0 | 108 | PK11SymKey *pk11_TokenKeyGenWithFlagsAndKeyType(PK11SlotInfo *slot, |
michael@0 | 109 | CK_MECHANISM_TYPE type, SECItem *param, CK_KEY_TYPE keyType, |
michael@0 | 110 | int keySize, SECItem *keyId, CK_FLAGS opFlags, |
michael@0 | 111 | PK11AttrFlags attrFlags, void *wincx); |
michael@0 | 112 | |
michael@0 | 113 | CK_MECHANISM_TYPE pk11_GetPBECryptoMechanism(SECAlgorithmID *algid, |
michael@0 | 114 | SECItem **param, SECItem *pwd, PRBool faulty3DES); |
michael@0 | 115 | |
michael@0 | 116 | |
michael@0 | 117 | |
michael@0 | 118 | extern void pk11sdr_Init(void); |
michael@0 | 119 | extern void pk11sdr_Shutdown(void); |
michael@0 | 120 | |
michael@0 | 121 | /* |
michael@0 | 122 | * Private to pk11wrap. |
michael@0 | 123 | */ |
michael@0 | 124 | |
michael@0 | 125 | PRBool pk11_LoginStillRequired(PK11SlotInfo *slot, void *wincx); |
michael@0 | 126 | CK_SESSION_HANDLE pk11_GetNewSession(PK11SlotInfo *slot, PRBool *owner); |
michael@0 | 127 | void pk11_CloseSession(PK11SlotInfo *slot, CK_SESSION_HANDLE sess, PRBool own); |
michael@0 | 128 | PK11SymKey *pk11_ForceSlot(PK11SymKey *symKey, CK_MECHANISM_TYPE type, |
michael@0 | 129 | CK_ATTRIBUTE_TYPE operation); |
michael@0 | 130 | /* Convert key operation flags to PKCS #11 attributes. */ |
michael@0 | 131 | unsigned int pk11_OpFlagsToAttributes(CK_FLAGS flags, |
michael@0 | 132 | CK_ATTRIBUTE *attrs, CK_BBOOL *ckTrue); |
michael@0 | 133 | /* Check for bad (conflicting) attribute flags */ |
michael@0 | 134 | PRBool pk11_BadAttrFlags(PK11AttrFlags attrFlags); |
michael@0 | 135 | /* Convert key attribute flags to PKCS #11 attributes. */ |
michael@0 | 136 | unsigned int pk11_AttrFlagsToAttributes(PK11AttrFlags attrFlags, |
michael@0 | 137 | CK_ATTRIBUTE *attrs, CK_BBOOL *ckTrue, CK_BBOOL *ckFalse); |
michael@0 | 138 | PRBool pk11_FindAttrInTemplate(CK_ATTRIBUTE *attr, unsigned int numAttrs, |
michael@0 | 139 | CK_ATTRIBUTE_TYPE target); |
michael@0 | 140 | |
michael@0 | 141 | CK_MECHANISM_TYPE pk11_mapWrapKeyType(KeyType keyType); |
michael@0 | 142 | PK11SymKey *pk11_KeyExchange(PK11SlotInfo *slot, CK_MECHANISM_TYPE type, |
michael@0 | 143 | CK_ATTRIBUTE_TYPE operation, CK_FLAGS flags, PRBool isPerm, |
michael@0 | 144 | PK11SymKey *symKey); |
michael@0 | 145 | |
michael@0 | 146 | PRBool pk11_HandleTrustObject(PK11SlotInfo *slot, CERTCertificate *cert, |
michael@0 | 147 | CERTCertTrust *trust); |
michael@0 | 148 | CK_OBJECT_HANDLE pk11_FindPubKeyByAnyCert(CERTCertificate *cert, |
michael@0 | 149 | PK11SlotInfo **slot, void *wincx); |
michael@0 | 150 | SECStatus pk11_AuthenticateUnfriendly(PK11SlotInfo *slot, PRBool loadCerts, |
michael@0 | 151 | void *wincx); |
michael@0 | 152 | int PK11_NumberObjectsFor(PK11SlotInfo *slot, CK_ATTRIBUTE *findTemplate, |
michael@0 | 153 | int templateCount); |
michael@0 | 154 | SECItem *pk11_GetLowLevelKeyFromHandle(PK11SlotInfo *slot, |
michael@0 | 155 | CK_OBJECT_HANDLE handle); |
michael@0 | 156 | SECStatus PK11_TraverseSlot(PK11SlotInfo *slot, void *arg); |
michael@0 | 157 | CK_OBJECT_HANDLE pk11_FindPrivateKeyFromCertID(PK11SlotInfo *slot, |
michael@0 | 158 | SECItem *keyID); |
michael@0 | 159 | SECKEYPrivateKey *PK11_MakePrivKey(PK11SlotInfo *slot, KeyType keyType, |
michael@0 | 160 | PRBool isTemp, CK_OBJECT_HANDLE privID, void *wincx); |
michael@0 | 161 | CERTCertificate *PK11_MakeCertFromHandle(PK11SlotInfo *slot, |
michael@0 | 162 | CK_OBJECT_HANDLE certID, CK_ATTRIBUTE *privateLabel); |
michael@0 | 163 | |
michael@0 | 164 | SECItem *pk11_GenerateNewParamWithKeyLen(CK_MECHANISM_TYPE type, int keyLen); |
michael@0 | 165 | SECItem *pk11_ParamFromIVWithLen(CK_MECHANISM_TYPE type, |
michael@0 | 166 | SECItem *iv, int keyLen); |
michael@0 | 167 | |
michael@0 | 168 | SEC_END_PROTOS |
michael@0 | 169 | |
michael@0 | 170 | #endif |
michael@0 | 171 |