| 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 |
| 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | #ifndef _PK11PRIV_H_ |
| 5 | #define _PK11PRIV_H_ |
| 6 | |
| 7 | #include <stddef.h> |
| 8 | |
| 9 | #include "plarena.h" |
| 10 | #include "seccomon.h" |
| 11 | #include "secoidt.h" |
| 12 | #include "secdert.h" |
| 13 | #include "keythi.h" |
| 14 | #include "certt.h" |
| 15 | #include "pkcs11t.h" |
| 16 | #include "secmodt.h" |
| 17 | #include "seccomon.h" |
| 18 | #include "pkcs7t.h" |
| 19 | #include "cmsreclist.h" |
| 20 | #include "pkcs11uri.h" |
| 21 | |
| 22 | /* |
| 23 | * These are the private NSS functions. They are not exported by nss.def, and |
| 24 | * are not callable outside nss3.dll. |
| 25 | */ |
| 26 | |
| 27 | SEC_BEGIN_PROTOS |
| 28 | |
| 29 | /************************************************************ |
| 30 | * Generic Slot Lists Management |
| 31 | ************************************************************/ |
| 32 | PK11SlotList *PK11_NewSlotList(void); |
| 33 | PK11SlotList *PK11_GetPrivateKeyTokens(CK_MECHANISM_TYPE type, |
| 34 | PRBool needRW, void *wincx); |
| 35 | SECStatus PK11_AddSlotToList(PK11SlotList *list, PK11SlotInfo *slot, PRBool sorted); |
| 36 | SECStatus PK11_DeleteSlotFromList(PK11SlotList *list, PK11SlotListElement *le); |
| 37 | PK11SlotListElement *PK11_FindSlotElement(PK11SlotList *list, |
| 38 | PK11SlotInfo *slot); |
| 39 | PK11SlotInfo *PK11_FindSlotBySerial(char *serial); |
| 40 | int PK11_GetMaxKeyLength(CK_MECHANISM_TYPE type); |
| 41 | |
| 42 | /************************************************************ |
| 43 | * Generic Slot Management |
| 44 | ************************************************************/ |
| 45 | CK_OBJECT_HANDLE PK11_CopyKey(PK11SlotInfo *slot, CK_OBJECT_HANDLE srcObject); |
| 46 | PRBool pk11_MatchUriTokenInfo(PK11SlotInfo *slot, PK11URI *uri); |
| 47 | SECStatus PK11_ReadAttribute(PK11SlotInfo *slot, CK_OBJECT_HANDLE id, |
| 48 | CK_ATTRIBUTE_TYPE type, PLArenaPool *arena, SECItem *result); |
| 49 | CK_ULONG PK11_ReadULongAttribute(PK11SlotInfo *slot, CK_OBJECT_HANDLE id, |
| 50 | CK_ATTRIBUTE_TYPE type); |
| 51 | char *PK11_MakeString(PLArenaPool *arena, char *space, char *staticSring, |
| 52 | int stringLen); |
| 53 | PRBool pk11_MatchString(const char *string, |
| 54 | const char *staticString, size_t staticStringLen); |
| 55 | int PK11_MapError(CK_RV error); |
| 56 | CK_SESSION_HANDLE PK11_GetRWSession(PK11SlotInfo *slot); |
| 57 | void PK11_RestoreROSession(PK11SlotInfo *slot, CK_SESSION_HANDLE rwsession); |
| 58 | PRBool PK11_RWSessionHasLock(PK11SlotInfo *slot, |
| 59 | CK_SESSION_HANDLE session_handle); |
| 60 | PK11SlotInfo *PK11_NewSlotInfo(SECMODModule *mod); |
| 61 | void PK11_EnterSlotMonitor(PK11SlotInfo *); |
| 62 | void PK11_ExitSlotMonitor(PK11SlotInfo *); |
| 63 | void PK11_CleanKeyList(PK11SlotInfo *slot); |
| 64 | |
| 65 | /************************************************************ |
| 66 | * Slot Password Management |
| 67 | ************************************************************/ |
| 68 | SECStatus PK11_DoPassword(PK11SlotInfo *slot, CK_SESSION_HANDLE session, |
| 69 | PRBool loadCerts, void *wincx, PRBool alreadyLocked, |
| 70 | PRBool contextSpecific); |
| 71 | SECStatus PK11_VerifyPW(PK11SlotInfo *slot, char *pw); |
| 72 | void PK11_HandlePasswordCheck(PK11SlotInfo *slot, void *wincx); |
| 73 | void PK11_SetVerifyPasswordFunc(PK11VerifyPasswordFunc func); |
| 74 | void PK11_SetIsLoggedInFunc(PK11IsLoggedInFunc func); |
| 75 | |
| 76 | /************************************************************ |
| 77 | * Manage the built-In Slot Lists |
| 78 | ************************************************************/ |
| 79 | SECStatus PK11_InitSlotLists(void); |
| 80 | void PK11_DestroySlotLists(void); |
| 81 | PK11SlotList *PK11_GetSlotList(CK_MECHANISM_TYPE type); |
| 82 | void PK11_LoadSlotList(PK11SlotInfo *slot, PK11PreSlotInfo *psi, int count); |
| 83 | void PK11_ClearSlotList(PK11SlotInfo *slot); |
| 84 | |
| 85 | /****************************************************************** |
| 86 | * Slot initialization |
| 87 | ******************************************************************/ |
| 88 | SECStatus PK11_InitToken(PK11SlotInfo *slot, PRBool loadCerts); |
| 89 | void PK11_InitSlot(SECMODModule *mod, CK_SLOT_ID slotID, PK11SlotInfo *slot); |
| 90 | PRBool PK11_NeedPWInitForSlot(PK11SlotInfo *slot); |
| 91 | SECStatus PK11_ReadSlotCerts(PK11SlotInfo *slot); |
| 92 | void pk11_SetInternalKeySlot(PK11SlotInfo *slot); |
| 93 | PK11SlotInfo *pk11_SwapInternalKeySlot(PK11SlotInfo *slot); |
| 94 | void pk11_SetInternalKeySlotIfFirst(PK11SlotInfo *slot); |
| 95 | |
| 96 | /********************************************************************* |
| 97 | * Mechanism Mapping functions |
| 98 | *********************************************************************/ |
| 99 | void PK11_AddMechanismEntry(CK_MECHANISM_TYPE type, CK_KEY_TYPE key, |
| 100 | CK_MECHANISM_TYPE keygen, CK_MECHANISM_TYPE pad, |
| 101 | int ivLen, int blocksize); |
| 102 | CK_MECHANISM_TYPE PK11_GetKeyMechanism(CK_KEY_TYPE type); |
| 103 | CK_MECHANISM_TYPE PK11_GetKeyGenWithSize(CK_MECHANISM_TYPE type, int size); |
| 104 | PRBool PK11_DoesMechanismFlag(PK11SlotInfo *, CK_MECHANISM_TYPE type, CK_FLAGS flags); |
| 105 | |
| 106 | /********************************************************************** |
| 107 | * Symetric, Public, and Private Keys |
| 108 | **********************************************************************/ |
| 109 | /* Key Generation specialized for SDR (fixed DES3 key) */ |
| 110 | PK11SymKey *PK11_GenDES3TokenKey(PK11SlotInfo *slot, SECItem *keyid, void *cx); |
| 111 | SECKEYPublicKey *(PK11SlotInfo *slot, KeyType keyType, |
| 112 | CK_OBJECT_HANDLE id); |
| 113 | CK_OBJECT_HANDLE PK11_FindObjectForCert(CERTCertificate *cert, |
| 114 | void *wincx, PK11SlotInfo **pSlot); |
| 115 | PK11SymKey *pk11_CopyToSlot(PK11SlotInfo *slot, CK_MECHANISM_TYPE type, |
| 116 | CK_ATTRIBUTE_TYPE operation, PK11SymKey *symKey); |
| 117 | unsigned int pk11_GetPredefinedKeyLength(CK_KEY_TYPE keyType); |
| 118 | CK_OBJECT_HANDLE PK11_DerivePubKeyFromPrivKey(SECKEYPrivateKey *privKey); |
| 119 | |
| 120 | /********************************************************************** |
| 121 | * Certs |
| 122 | **********************************************************************/ |
| 123 | SECStatus PK11_TraversePrivateKeysInSlot(PK11SlotInfo *slot, |
| 124 | SECStatus (*callback)(SECKEYPrivateKey *, void *), void *arg); |
| 125 | SECKEYPrivateKey *PK11_FindPrivateKeyFromNickname(char *nickname, void *wincx); |
| 126 | CK_OBJECT_HANDLE *PK11_FindObjectsFromNickname(char *nickname, |
| 127 | PK11SlotInfo **slotptr, CK_OBJECT_CLASS objclass, int *returnCount, |
| 128 | void *wincx); |
| 129 | CK_OBJECT_HANDLE PK11_MatchItem(PK11SlotInfo *slot, CK_OBJECT_HANDLE peer, |
| 130 | CK_OBJECT_CLASS o_class); |
| 131 | CK_BBOOL pk11_HasAttributeSet_Lock(PK11SlotInfo *slot, |
| 132 | CK_OBJECT_HANDLE id, |
| 133 | CK_ATTRIBUTE_TYPE type, |
| 134 | PRBool haslock); |
| 135 | CK_RV PK11_GetAttributes(PLArenaPool *arena, PK11SlotInfo *slot, |
| 136 | CK_OBJECT_HANDLE obj, CK_ATTRIBUTE *attr, int count); |
| 137 | int PK11_NumberCertsForCertSubject(CERTCertificate *cert); |
| 138 | SECStatus PK11_TraverseCertsForSubject(CERTCertificate *cert, |
| 139 | SECStatus (*callback)(CERTCertificate *, void *), void *arg); |
| 140 | SECStatus PK11_GetKEAMatchedCerts(PK11SlotInfo *slot1, |
| 141 | PK11SlotInfo *slot2, CERTCertificate **cert1, CERTCertificate **cert2); |
| 142 | SECStatus PK11_TraverseCertsInSlot(PK11SlotInfo *slot, |
| 143 | SECStatus (*callback)(CERTCertificate *, void *), void *arg); |
| 144 | SECStatus PK11_LookupCrls(CERTCrlHeadNode *nodes, int type, void *wincx); |
| 145 | |
| 146 | /********************************************************************** |
| 147 | * Crypto Contexts |
| 148 | **********************************************************************/ |
| 149 | PK11Context *PK11_CreateContextByRawKey(PK11SlotInfo *slot, |
| 150 | CK_MECHANISM_TYPE type, PK11Origin origin, CK_ATTRIBUTE_TYPE operation, |
| 151 | SECItem *key, SECItem *param, void *wincx); |
| 152 | PRBool PK11_HashOK(SECOidTag hashAlg); |
| 153 | /* |
| 154 | * Testing interfaces, not for general use. If your code isn't in |
| 155 | * gtests or cmd, stay away from these. This function forces |
| 156 | * an AEAD context into simulation mode even though the target token |
| 157 | * can already do PKCS #11 v3.0 Message (e.i. softoken). |
| 158 | */ |
| 159 | SECStatus _PK11_ContextSetAEADSimulation(PK11Context *context); |
| 160 | PRBool _PK11_ContextGetAEADSimulation(PK11Context *context); |
| 161 | |
| 162 | /********************************************************************** |
| 163 | * Functions which are deprecated.... |
| 164 | **********************************************************************/ |
| 165 | |
| 166 | SECItem * |
| 167 | PK11_FindCrlByName(PK11SlotInfo **slot, CK_OBJECT_HANDLE *handle, |
| 168 | SECItem *derName, int type, char **url); |
| 169 | |
| 170 | CK_OBJECT_HANDLE |
| 171 | PK11_PutCrl(PK11SlotInfo *slot, SECItem *crl, |
| 172 | SECItem *name, char *url, int type); |
| 173 | |
| 174 | SECItem * |
| 175 | PK11_FindSMimeProfile(PK11SlotInfo **slotp, char *emailAddr, SECItem *derSubj, |
| 176 | SECItem **profileTime); |
| 177 | SECStatus |
| 178 | PK11_SaveSMimeProfile(PK11SlotInfo *slot, char *emailAddr, SECItem *derSubj, |
| 179 | SECItem *emailProfile, SECItem *profileTime); |
| 180 | |
| 181 | PRBool PK11_IsPermObject(PK11SlotInfo *slot, CK_OBJECT_HANDLE handle); |
| 182 | |
| 183 | char *PK11_GetObjectNickname(PK11SlotInfo *slot, CK_OBJECT_HANDLE id); |
| 184 | SECStatus PK11_SetObjectNickname(PK11SlotInfo *slot, CK_OBJECT_HANDLE id, |
| 185 | const char *nickname); |
| 186 | |
| 187 | /* private */ |
| 188 | SECStatus pk11_TraverseAllSlots(SECStatus (*callback)(PK11SlotInfo *, void *), |
| 189 | void *cbArg, PRBool forceLogin, void *pwArg); |
| 190 | |
| 191 | /* fetch multiple CRLs for a specific issuer */ |
| 192 | SECStatus pk11_RetrieveCrls(CERTCrlHeadNode *nodes, SECItem *issuer, |
| 193 | void *wincx); |
| 194 | |
| 195 | /* set global options for NSS PKCS#11 module loader */ |
| 196 | SECStatus pk11_setGlobalOptions(PRBool noSingleThreadedModules, |
| 197 | PRBool allowAlreadyInitializedModules, |
| 198 | PRBool dontFinalizeModules); |
| 199 | |
| 200 | /* return whether NSS is allowed to call C_Finalize */ |
| 201 | PRBool pk11_getFinalizeModulesOption(void); |
| 202 | |
| 203 | /* fetch the FIPS state from the fips indicator, public versions of |
| 204 | * this function operate on the slot, the context, and the object */ |
| 205 | PRBool pk11slot_GetFIPSStatus(PK11SlotInfo *slot, CK_SESSION_HANDLE session, |
| 206 | CK_OBJECT_HANDLE object, CK_ULONG operationType); |
| 207 | |
| 208 | SEC_END_PROTOS |
| 209 | |
| 210 | #endif |
| 211 | |