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: #ifndef _PK11PRIV_H_ andre@0: #define _PK11PRIV_H_ andre@0: #include "plarena.h" andre@0: #include "seccomon.h" andre@0: #include "secoidt.h" andre@0: #include "secdert.h" andre@0: #include "keyt.h" andre@0: #include "certt.h" andre@0: #include "pkcs11t.h" andre@0: #include "secmodt.h" andre@0: #include "seccomon.h" andre@0: #include "pkcs7t.h" andre@0: #include "cmsreclist.h" andre@0: andre@0: /* andre@0: * These are the private NSS functions. They are not exported by nss.def, and andre@0: * are not callable outside nss3.dll. andre@0: */ andre@0: andre@0: SEC_BEGIN_PROTOS andre@0: andre@0: /************************************************************ andre@0: * Generic Slot Lists Management andre@0: ************************************************************/ andre@0: PK11SlotList * PK11_NewSlotList(void); andre@0: PK11SlotList * PK11_GetPrivateKeyTokens(CK_MECHANISM_TYPE type, andre@0: PRBool needRW,void *wincx); andre@0: SECStatus PK11_AddSlotToList(PK11SlotList *list,PK11SlotInfo *slot, PRBool sorted); andre@0: SECStatus PK11_DeleteSlotFromList(PK11SlotList *list,PK11SlotListElement *le); andre@0: PK11SlotListElement *PK11_FindSlotElement(PK11SlotList *list, andre@0: PK11SlotInfo *slot); andre@0: PK11SlotInfo *PK11_FindSlotBySerial(char *serial); andre@0: int PK11_GetMaxKeyLength(CK_MECHANISM_TYPE type); andre@0: andre@0: /************************************************************ andre@0: * Generic Slot Management andre@0: ************************************************************/ andre@0: CK_OBJECT_HANDLE PK11_CopyKey(PK11SlotInfo *slot, CK_OBJECT_HANDLE srcObject); andre@0: SECStatus PK11_ReadAttribute(PK11SlotInfo *slot, CK_OBJECT_HANDLE id, andre@0: CK_ATTRIBUTE_TYPE type, PLArenaPool *arena, SECItem *result); andre@0: CK_ULONG PK11_ReadULongAttribute(PK11SlotInfo *slot, CK_OBJECT_HANDLE id, andre@0: CK_ATTRIBUTE_TYPE type); andre@0: char * PK11_MakeString(PLArenaPool *arena,char *space,char *staticSring, andre@0: int stringLen); andre@0: int PK11_MapError(CK_RV error); andre@0: CK_SESSION_HANDLE PK11_GetRWSession(PK11SlotInfo *slot); andre@0: void PK11_RestoreROSession(PK11SlotInfo *slot,CK_SESSION_HANDLE rwsession); andre@0: PRBool PK11_RWSessionHasLock(PK11SlotInfo *slot, andre@0: CK_SESSION_HANDLE session_handle); andre@0: PK11SlotInfo *PK11_NewSlotInfo(SECMODModule *mod); andre@0: void PK11_EnterSlotMonitor(PK11SlotInfo *); andre@0: void PK11_ExitSlotMonitor(PK11SlotInfo *); andre@0: void PK11_CleanKeyList(PK11SlotInfo *slot); andre@0: andre@0: andre@0: /************************************************************ andre@0: * Slot Password Management andre@0: ************************************************************/ andre@0: SECStatus PK11_DoPassword(PK11SlotInfo *slot, CK_SESSION_HANDLE session, andre@0: PRBool loadCerts, void *wincx, PRBool alreadyLocked, andre@0: PRBool contextSpecific); andre@0: SECStatus PK11_VerifyPW(PK11SlotInfo *slot,char *pw); andre@0: void PK11_HandlePasswordCheck(PK11SlotInfo *slot,void *wincx); andre@0: void PK11_SetVerifyPasswordFunc(PK11VerifyPasswordFunc func); andre@0: void PK11_SetIsLoggedInFunc(PK11IsLoggedInFunc func); andre@0: andre@0: /************************************************************ andre@0: * Manage the built-In Slot Lists andre@0: ************************************************************/ andre@0: SECStatus PK11_InitSlotLists(void); andre@0: void PK11_DestroySlotLists(void); andre@0: PK11SlotList *PK11_GetSlotList(CK_MECHANISM_TYPE type); andre@0: void PK11_LoadSlotList(PK11SlotInfo *slot, PK11PreSlotInfo *psi, int count); andre@0: void PK11_ClearSlotList(PK11SlotInfo *slot); andre@0: andre@0: andre@0: /****************************************************************** andre@0: * Slot initialization andre@0: ******************************************************************/ andre@0: SECStatus PK11_InitToken(PK11SlotInfo *slot, PRBool loadCerts); andre@0: void PK11_InitSlot(SECMODModule *mod,CK_SLOT_ID slotID,PK11SlotInfo *slot); andre@0: PRBool PK11_NeedPWInitForSlot(PK11SlotInfo *slot); andre@0: SECStatus PK11_ReadSlotCerts(PK11SlotInfo *slot); andre@0: void pk11_SetInternalKeySlot(PK11SlotInfo *slot); andre@0: PK11SlotInfo *pk11_SwapInternalKeySlot(PK11SlotInfo *slot); andre@0: void pk11_SetInternalKeySlotIfFirst(PK11SlotInfo *slot); andre@0: andre@0: /********************************************************************* andre@0: * Mechanism Mapping functions andre@0: *********************************************************************/ andre@0: void PK11_AddMechanismEntry(CK_MECHANISM_TYPE type, CK_KEY_TYPE key, andre@0: CK_MECHANISM_TYPE keygen, CK_MECHANISM_TYPE pad, andre@0: int ivLen, int blocksize); andre@0: CK_MECHANISM_TYPE PK11_GetKeyMechanism(CK_KEY_TYPE type); andre@0: CK_MECHANISM_TYPE PK11_GetKeyGenWithSize(CK_MECHANISM_TYPE type, int size); andre@0: andre@0: /********************************************************************** andre@0: * Symetric, Public, and Private Keys andre@0: **********************************************************************/ andre@0: /* Key Generation specialized for SDR (fixed DES3 key) */ andre@0: PK11SymKey *PK11_GenDES3TokenKey(PK11SlotInfo *slot, SECItem *keyid, void *cx); andre@0: SECKEYPublicKey *PK11_ExtractPublicKey(PK11SlotInfo *slot, KeyType keyType, andre@0: CK_OBJECT_HANDLE id); andre@0: CK_OBJECT_HANDLE PK11_FindObjectForCert(CERTCertificate *cert, andre@0: void *wincx, PK11SlotInfo **pSlot); andre@0: PK11SymKey * pk11_CopyToSlot(PK11SlotInfo *slot,CK_MECHANISM_TYPE type, andre@0: CK_ATTRIBUTE_TYPE operation, PK11SymKey *symKey); andre@0: andre@0: /********************************************************************** andre@0: * Certs andre@0: **********************************************************************/ andre@0: SECStatus PK11_TraversePrivateKeysInSlot( PK11SlotInfo *slot, andre@0: SECStatus(* callback)(SECKEYPrivateKey*, void*), void *arg); andre@0: SECKEYPrivateKey * PK11_FindPrivateKeyFromNickname(char *nickname, void *wincx); andre@0: CK_OBJECT_HANDLE * PK11_FindObjectsFromNickname(char *nickname, andre@0: PK11SlotInfo **slotptr, CK_OBJECT_CLASS objclass, int *returnCount, andre@0: void *wincx); andre@0: CK_OBJECT_HANDLE PK11_MatchItem(PK11SlotInfo *slot,CK_OBJECT_HANDLE peer, andre@0: CK_OBJECT_CLASS o_class); andre@0: CK_BBOOL PK11_HasAttributeSet( PK11SlotInfo *slot, andre@0: CK_OBJECT_HANDLE id, andre@0: CK_ATTRIBUTE_TYPE type, andre@0: PRBool haslock ); andre@0: CK_RV PK11_GetAttributes(PLArenaPool *arena,PK11SlotInfo *slot, andre@0: CK_OBJECT_HANDLE obj,CK_ATTRIBUTE *attr, int count); andre@0: int PK11_NumberCertsForCertSubject(CERTCertificate *cert); andre@0: SECStatus PK11_TraverseCertsForSubject(CERTCertificate *cert, andre@0: SECStatus(*callback)(CERTCertificate *, void *), void *arg); andre@0: SECStatus PK11_GetKEAMatchedCerts(PK11SlotInfo *slot1, andre@0: PK11SlotInfo *slot2, CERTCertificate **cert1, CERTCertificate **cert2); andre@0: SECStatus PK11_TraverseCertsInSlot(PK11SlotInfo *slot, andre@0: SECStatus(* callback)(CERTCertificate*, void *), void *arg); andre@0: SECStatus PK11_LookupCrls(CERTCrlHeadNode *nodes, int type, void *wincx); andre@0: andre@0: andre@0: /********************************************************************** andre@0: * Crypto Contexts andre@0: **********************************************************************/ andre@0: PK11Context * PK11_CreateContextByRawKey(PK11SlotInfo *slot, andre@0: CK_MECHANISM_TYPE type, PK11Origin origin, CK_ATTRIBUTE_TYPE operation, andre@0: SECItem *key, SECItem *param, void *wincx); andre@0: PRBool PK11_HashOK(SECOidTag hashAlg); andre@0: andre@0: andre@0: /********************************************************************** andre@0: * Functions which are deprecated.... andre@0: **********************************************************************/ andre@0: andre@0: SECItem * andre@0: PK11_FindCrlByName(PK11SlotInfo **slot, CK_OBJECT_HANDLE *handle, andre@0: SECItem *derName, int type, char **url); andre@0: andre@0: CK_OBJECT_HANDLE andre@0: PK11_PutCrl(PK11SlotInfo *slot, SECItem *crl, andre@0: SECItem *name, char *url, int type); andre@0: andre@0: SECItem * andre@0: PK11_FindSMimeProfile(PK11SlotInfo **slotp, char *emailAddr, SECItem *derSubj, andre@0: SECItem **profileTime); andre@0: SECStatus andre@0: PK11_SaveSMimeProfile(PK11SlotInfo *slot, char *emailAddr, SECItem *derSubj, andre@0: SECItem *emailProfile, SECItem *profileTime); andre@0: andre@0: PRBool PK11_IsPermObject(PK11SlotInfo *slot, CK_OBJECT_HANDLE handle); andre@0: andre@0: char * PK11_GetObjectNickname(PK11SlotInfo *slot, CK_OBJECT_HANDLE id) ; andre@0: SECStatus PK11_SetObjectNickname(PK11SlotInfo *slot, CK_OBJECT_HANDLE id, andre@0: const char *nickname) ; andre@0: andre@0: andre@0: /* private */ andre@0: SECStatus pk11_TraverseAllSlots( SECStatus (*callback)(PK11SlotInfo *,void *), andre@0: void *cbArg, PRBool forceLogin, void *pwArg); andre@0: andre@0: /* fetch multiple CRLs for a specific issuer */ andre@0: SECStatus pk11_RetrieveCrls(CERTCrlHeadNode *nodes, SECItem* issuer, andre@0: void *wincx); andre@0: andre@0: /* set global options for NSS PKCS#11 module loader */ andre@0: SECStatus pk11_setGlobalOptions(PRBool noSingleThreadedModules, andre@0: PRBool allowAlreadyInitializedModules, andre@0: PRBool dontFinalizeModules); andre@0: andre@0: /* return whether NSS is allowed to call C_Finalize */ andre@0: PRBool pk11_getFinalizeModulesOption(void); andre@0: andre@0: SEC_END_PROTOS andre@0: andre@0: #endif