andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: /* andre@0: * Internal header file included only by files in pkcs11 dir, or in andre@0: * pkcs11 specific client and server files. andre@0: */ andre@0: #ifndef _SECMODI_H_ andre@0: #define _SECMODI_H_ 1 andre@0: #include "pkcs11.h" andre@0: #include "nssilock.h" andre@0: #include "secoidt.h" andre@0: #include "secdert.h" andre@0: #include "certt.h" andre@0: #include "secmodt.h" andre@0: #include "keyt.h" andre@0: andre@0: SEC_BEGIN_PROTOS andre@0: andre@0: /* proto-types */ andre@0: extern SECStatus SECMOD_DeletePermDB(SECMODModule *module); andre@0: extern SECStatus SECMOD_AddPermDB(SECMODModule *module); andre@0: extern SECStatus SECMOD_Shutdown(void); andre@0: void nss_DumpModuleLog(void); andre@0: andre@0: extern int secmod_PrivateModuleCount; andre@0: andre@0: extern void SECMOD_Init(void); andre@0: SECStatus secmod_ModuleInit(SECMODModule *mod, SECMODModule **oldModule, andre@0: PRBool* alreadyLoaded); andre@0: andre@0: /* list managment */ andre@0: extern SECStatus SECMOD_AddModuleToList(SECMODModule *newModule); andre@0: extern SECStatus SECMOD_AddModuleToDBOnlyList(SECMODModule *newModule); andre@0: extern SECStatus SECMOD_AddModuleToUnloadList(SECMODModule *newModule); andre@0: extern void SECMOD_RemoveList(SECMODModuleList **,SECMODModuleList *); andre@0: extern void SECMOD_AddList(SECMODModuleList *,SECMODModuleList *,SECMODListLock *); andre@0: extern SECMODListLock *SECMOD_NewListLock(void); andre@0: extern void SECMOD_DestroyListLock(SECMODListLock *); andre@0: extern void SECMOD_GetWriteLock(SECMODListLock *); andre@0: extern void SECMOD_ReleaseWriteLock(SECMODListLock *); andre@0: andre@0: /* Operate on modules by name */ andre@0: extern SECMODModule *SECMOD_FindModuleByID(SECMODModuleID); andre@0: extern SECMODModule *secmod_FindModuleByFuncPtr(void *funcPtr); andre@0: andre@0: /* database/memory management */ andre@0: extern SECMODModuleList *SECMOD_NewModuleListElement(void); andre@0: extern SECMODModuleList *SECMOD_DestroyModuleListElement(SECMODModuleList *); andre@0: extern void SECMOD_DestroyModuleList(SECMODModuleList *); andre@0: extern SECStatus SECMOD_AddModule(SECMODModule *newModule); andre@0: andre@0: extern unsigned long SECMOD_InternaltoPubCipherFlags(unsigned long internalFlags); andre@0: andre@0: /* Library functions */ andre@0: SECStatus secmod_LoadPKCS11Module(SECMODModule *, SECMODModule **oldModule); andre@0: SECStatus SECMOD_UnloadModule(SECMODModule *); andre@0: void SECMOD_SetInternalModule(SECMODModule *); andre@0: PRBool secmod_IsInternalKeySlot(SECMODModule *); andre@0: void secmod_SetInternalKeySlotFlag(SECMODModule *mod, PRBool val); andre@0: andre@0: andre@0: /* tools for checking if we are loading the same database twice */ andre@0: typedef struct SECMODConfigListStr SECMODConfigList; andre@0: /* collect all the databases in a given spec */ andre@0: SECMODConfigList *secmod_GetConfigList(PRBool isFIPS, char *spec, int *count); andre@0: /* see is a spec matches a database on the list */ andre@0: PRBool secmod_MatchConfigList(char *spec, andre@0: SECMODConfigList *conflist, int count); andre@0: /* free our list of databases */ andre@0: void secmod_FreeConfigList(SECMODConfigList *conflist, int count); andre@0: andre@0: /* parsing parameters */ andre@0: /* returned char * must be freed by caller with PORT_Free */ andre@0: /* children and ids are null terminated arrays which must be freed with andre@0: * secmod_FreeChildren */ andre@0: char *secmod_ParseModuleSpecForTokens(PRBool convert, andre@0: PRBool isFIPS, andre@0: char *moduleSpec, andre@0: char ***children, andre@0: CK_SLOT_ID **ids); andre@0: void secmod_FreeChildren(char **children, CK_SLOT_ID *ids); andre@0: char *secmod_MkAppendTokensList(PLArenaPool *arena, char *origModuleSpec, andre@0: char *newModuleSpec, CK_SLOT_ID newID, andre@0: char **children, CK_SLOT_ID *ids); andre@0: andre@0: andre@0: void SECMOD_SlotDestroyModule(SECMODModule *module, PRBool fromSlot); andre@0: CK_RV pk11_notify(CK_SESSION_HANDLE session, CK_NOTIFICATION event, andre@0: CK_VOID_PTR pdata); andre@0: void pk11_SignedToUnsigned(CK_ATTRIBUTE *attrib); andre@0: CK_OBJECT_HANDLE pk11_FindObjectByTemplate(PK11SlotInfo *slot, andre@0: CK_ATTRIBUTE *inTemplate,int tsize); andre@0: CK_OBJECT_HANDLE *pk11_FindObjectsByTemplate(PK11SlotInfo *slot, andre@0: CK_ATTRIBUTE *inTemplate,int tsize, int *objCount); andre@0: andre@0: #define PK11_GETTAB(x) ((CK_FUNCTION_LIST_PTR)((x)->functionList)) andre@0: #define PK11_SETATTRS(x,id,v,l) (x)->type = (id); \ andre@0: (x)->pValue=(v); (x)->ulValueLen = (l); andre@0: SECStatus PK11_CreateNewObject(PK11SlotInfo *slot, CK_SESSION_HANDLE session, andre@0: const CK_ATTRIBUTE *theTemplate, int count, andre@0: PRBool token, CK_OBJECT_HANDLE *objectID); andre@0: andre@0: SECStatus pbe_PK11AlgidToParam(SECAlgorithmID *algid,SECItem *mech); andre@0: SECStatus PBE_PK11ParamToAlgid(SECOidTag algTag, SECItem *param, andre@0: PLArenaPool *arena, SECAlgorithmID *algId); andre@0: andre@0: PK11SymKey *pk11_TokenKeyGenWithFlagsAndKeyType(PK11SlotInfo *slot, andre@0: CK_MECHANISM_TYPE type, SECItem *param, CK_KEY_TYPE keyType, andre@0: int keySize, SECItem *keyId, CK_FLAGS opFlags, andre@0: PK11AttrFlags attrFlags, void *wincx); andre@0: andre@0: CK_MECHANISM_TYPE pk11_GetPBECryptoMechanism(SECAlgorithmID *algid, andre@0: SECItem **param, SECItem *pwd, PRBool faulty3DES); andre@0: andre@0: andre@0: andre@0: extern void pk11sdr_Init(void); andre@0: extern void pk11sdr_Shutdown(void); andre@0: andre@0: /* andre@0: * Private to pk11wrap. andre@0: */ andre@0: andre@0: PRBool pk11_LoginStillRequired(PK11SlotInfo *slot, void *wincx); andre@0: CK_SESSION_HANDLE pk11_GetNewSession(PK11SlotInfo *slot, PRBool *owner); andre@0: void pk11_CloseSession(PK11SlotInfo *slot, CK_SESSION_HANDLE sess, PRBool own); andre@0: PK11SymKey *pk11_ForceSlot(PK11SymKey *symKey, CK_MECHANISM_TYPE type, andre@0: CK_ATTRIBUTE_TYPE operation); andre@0: /* Convert key operation flags to PKCS #11 attributes. */ andre@0: unsigned int pk11_OpFlagsToAttributes(CK_FLAGS flags, andre@0: CK_ATTRIBUTE *attrs, CK_BBOOL *ckTrue); andre@0: /* Check for bad (conflicting) attribute flags */ andre@0: PRBool pk11_BadAttrFlags(PK11AttrFlags attrFlags); andre@0: /* Convert key attribute flags to PKCS #11 attributes. */ andre@0: unsigned int pk11_AttrFlagsToAttributes(PK11AttrFlags attrFlags, andre@0: CK_ATTRIBUTE *attrs, CK_BBOOL *ckTrue, CK_BBOOL *ckFalse); andre@0: PRBool pk11_FindAttrInTemplate(CK_ATTRIBUTE *attr, unsigned int numAttrs, andre@0: CK_ATTRIBUTE_TYPE target); andre@0: andre@0: CK_MECHANISM_TYPE pk11_mapWrapKeyType(KeyType keyType); andre@0: PK11SymKey *pk11_KeyExchange(PK11SlotInfo *slot, CK_MECHANISM_TYPE type, andre@0: CK_ATTRIBUTE_TYPE operation, CK_FLAGS flags, PRBool isPerm, andre@0: PK11SymKey *symKey); andre@0: andre@0: PRBool pk11_HandleTrustObject(PK11SlotInfo *slot, CERTCertificate *cert, andre@0: CERTCertTrust *trust); andre@0: CK_OBJECT_HANDLE pk11_FindPubKeyByAnyCert(CERTCertificate *cert, andre@0: PK11SlotInfo **slot, void *wincx); andre@0: SECStatus pk11_AuthenticateUnfriendly(PK11SlotInfo *slot, PRBool loadCerts, andre@0: void *wincx); andre@0: int PK11_NumberObjectsFor(PK11SlotInfo *slot, CK_ATTRIBUTE *findTemplate, andre@0: int templateCount); andre@0: SECItem *pk11_GetLowLevelKeyFromHandle(PK11SlotInfo *slot, andre@0: CK_OBJECT_HANDLE handle); andre@0: SECStatus PK11_TraverseSlot(PK11SlotInfo *slot, void *arg); andre@0: CK_OBJECT_HANDLE pk11_FindPrivateKeyFromCertID(PK11SlotInfo *slot, andre@0: SECItem *keyID); andre@0: SECKEYPrivateKey *PK11_MakePrivKey(PK11SlotInfo *slot, KeyType keyType, andre@0: PRBool isTemp, CK_OBJECT_HANDLE privID, void *wincx); andre@0: CERTCertificate *PK11_MakeCertFromHandle(PK11SlotInfo *slot, andre@0: CK_OBJECT_HANDLE certID, CK_ATTRIBUTE *privateLabel); andre@0: andre@0: SECItem *pk11_GenerateNewParamWithKeyLen(CK_MECHANISM_TYPE type, int keyLen); andre@0: SECItem *pk11_ParamFromIVWithLen(CK_MECHANISM_TYPE type, andre@0: SECItem *iv, int keyLen); andre@0: andre@0: SEC_END_PROTOS andre@0: andre@0: #endif andre@0: