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
27SEC_BEGIN_PROTOS
28
29/************************************************************
30 * Generic Slot Lists Management
31 ************************************************************/
32PK11SlotList *PK11_NewSlotList(void);
33PK11SlotList *PK11_GetPrivateKeyTokens(CK_MECHANISM_TYPE type,
34 PRBool needRW, void *wincx);
35SECStatus PK11_AddSlotToList(PK11SlotList *list, PK11SlotInfo *slot, PRBool sorted);
36SECStatus PK11_DeleteSlotFromList(PK11SlotList *list, PK11SlotListElement *le);
37PK11SlotListElement *PK11_FindSlotElement(PK11SlotList *list,
38 PK11SlotInfo *slot);
39PK11SlotInfo *PK11_FindSlotBySerial(char *serial);
40int PK11_GetMaxKeyLength(CK_MECHANISM_TYPE type);
41
42/************************************************************
43 * Generic Slot Management
44 ************************************************************/
45CK_OBJECT_HANDLE PK11_CopyKey(PK11SlotInfo *slot, CK_OBJECT_HANDLE srcObject);
46PRBool pk11_MatchUriTokenInfo(PK11SlotInfo *slot, PK11URI *uri);
47SECStatus PK11_ReadAttribute(PK11SlotInfo *slot, CK_OBJECT_HANDLE id,
48 CK_ATTRIBUTE_TYPE type, PLArenaPool *arena, SECItem *result);
49CK_ULONG PK11_ReadULongAttribute(PK11SlotInfo *slot, CK_OBJECT_HANDLE id,
50 CK_ATTRIBUTE_TYPE type);
51char *PK11_MakeString(PLArenaPool *arena, char *space, char *staticSring,
52 int stringLen);
53PRBool pk11_MatchString(const char *string,
54 const char *staticString, size_t staticStringLen);
55int PK11_MapError(CK_RV error);
56CK_SESSION_HANDLE PK11_GetRWSession(PK11SlotInfo *slot);
57void PK11_RestoreROSession(PK11SlotInfo *slot, CK_SESSION_HANDLE rwsession);
58PRBool PK11_RWSessionHasLock(PK11SlotInfo *slot,
59 CK_SESSION_HANDLE session_handle);
60PK11SlotInfo *PK11_NewSlotInfo(SECMODModule *mod);
61void PK11_EnterSlotMonitor(PK11SlotInfo *);
62void PK11_ExitSlotMonitor(PK11SlotInfo *);
63void PK11_CleanKeyList(PK11SlotInfo *slot);
64
65/************************************************************
66 * Slot Password Management
67 ************************************************************/
68SECStatus PK11_DoPassword(PK11SlotInfo *slot, CK_SESSION_HANDLE session,
69 PRBool loadCerts, void *wincx, PRBool alreadyLocked,
70 PRBool contextSpecific);
71SECStatus PK11_VerifyPW(PK11SlotInfo *slot, char *pw);
72void PK11_HandlePasswordCheck(PK11SlotInfo *slot, void *wincx);
73void PK11_SetVerifyPasswordFunc(PK11VerifyPasswordFunc func);
74void PK11_SetIsLoggedInFunc(PK11IsLoggedInFunc func);
75
76/************************************************************
77 * Manage the built-In Slot Lists
78 ************************************************************/
79SECStatus PK11_InitSlotLists(void);
80void PK11_DestroySlotLists(void);
81PK11SlotList *PK11_GetSlotList(CK_MECHANISM_TYPE type);
82void PK11_LoadSlotList(PK11SlotInfo *slot, PK11PreSlotInfo *psi, int count);
83void PK11_ClearSlotList(PK11SlotInfo *slot);
84
85/******************************************************************
86 * Slot initialization
87 ******************************************************************/
88SECStatus PK11_InitToken(PK11SlotInfo *slot, PRBool loadCerts);
89void PK11_InitSlot(SECMODModule *mod, CK_SLOT_ID slotID, PK11SlotInfo *slot);
90PRBool PK11_NeedPWInitForSlot(PK11SlotInfo *slot);
91SECStatus PK11_ReadSlotCerts(PK11SlotInfo *slot);
92void pk11_SetInternalKeySlot(PK11SlotInfo *slot);
93PK11SlotInfo *pk11_SwapInternalKeySlot(PK11SlotInfo *slot);
94void pk11_SetInternalKeySlotIfFirst(PK11SlotInfo *slot);
95
96/*********************************************************************
97 * Mechanism Mapping functions
98 *********************************************************************/
99void PK11_AddMechanismEntry(CK_MECHANISM_TYPE type, CK_KEY_TYPE key,
100 CK_MECHANISM_TYPE keygen, CK_MECHANISM_TYPE pad,
101 int ivLen, int blocksize);
102CK_MECHANISM_TYPE PK11_GetKeyMechanism(CK_KEY_TYPE type);
103CK_MECHANISM_TYPE PK11_GetKeyGenWithSize(CK_MECHANISM_TYPE type, int size);
104PRBool 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) */
110PK11SymKey *PK11_GenDES3TokenKey(PK11SlotInfo *slot, SECItem *keyid, void *cx);
111SECKEYPublicKey *PK11_ExtractPublicKey(PK11SlotInfo *slot, KeyType keyType,
112 CK_OBJECT_HANDLE id);
113CK_OBJECT_HANDLE PK11_FindObjectForCert(CERTCertificate *cert,
114 void *wincx, PK11SlotInfo **pSlot);
115PK11SymKey *pk11_CopyToSlot(PK11SlotInfo *slot, CK_MECHANISM_TYPE type,
116 CK_ATTRIBUTE_TYPE operation, PK11SymKey *symKey);
117unsigned int pk11_GetPredefinedKeyLength(CK_KEY_TYPE keyType);
118CK_OBJECT_HANDLE PK11_DerivePubKeyFromPrivKey(SECKEYPrivateKey *privKey);
119
120/**********************************************************************
121 * Certs
122 **********************************************************************/
123SECStatus PK11_TraversePrivateKeysInSlot(PK11SlotInfo *slot,
124 SECStatus (*callback)(SECKEYPrivateKey *, void *), void *arg);
125SECKEYPrivateKey *PK11_FindPrivateKeyFromNickname(char *nickname, void *wincx);
126CK_OBJECT_HANDLE *PK11_FindObjectsFromNickname(char *nickname,
127 PK11SlotInfo **slotptr, CK_OBJECT_CLASS objclass, int *returnCount,
128 void *wincx);
129CK_OBJECT_HANDLE PK11_MatchItem(PK11SlotInfo *slot, CK_OBJECT_HANDLE peer,
130 CK_OBJECT_CLASS o_class);
131CK_BBOOL pk11_HasAttributeSet_Lock(PK11SlotInfo *slot,
132 CK_OBJECT_HANDLE id,
133 CK_ATTRIBUTE_TYPE type,
134 PRBool haslock);
135CK_RV PK11_GetAttributes(PLArenaPool *arena, PK11SlotInfo *slot,
136 CK_OBJECT_HANDLE obj, CK_ATTRIBUTE *attr, int count);
137int PK11_NumberCertsForCertSubject(CERTCertificate *cert);
138SECStatus PK11_TraverseCertsForSubject(CERTCertificate *cert,
139 SECStatus (*callback)(CERTCertificate *, void *), void *arg);
140SECStatus PK11_GetKEAMatchedCerts(PK11SlotInfo *slot1,
141 PK11SlotInfo *slot2, CERTCertificate **cert1, CERTCertificate **cert2);
142SECStatus PK11_TraverseCertsInSlot(PK11SlotInfo *slot,
143 SECStatus (*callback)(CERTCertificate *, void *), void *arg);
144SECStatus PK11_LookupCrls(CERTCrlHeadNode *nodes, int type, void *wincx);
145
146/**********************************************************************
147 * Crypto Contexts
148 **********************************************************************/
149PK11Context *PK11_CreateContextByRawKey(PK11SlotInfo *slot,
150 CK_MECHANISM_TYPE type, PK11Origin origin, CK_ATTRIBUTE_TYPE operation,
151 SECItem *key, SECItem *param, void *wincx);
152PRBool 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 */
159SECStatus _PK11_ContextSetAEADSimulation(PK11Context *context);
160PRBool _PK11_ContextGetAEADSimulation(PK11Context *context);
161
162/**********************************************************************
163 * Functions which are deprecated....
164 **********************************************************************/
165
166SECItem *
167PK11_FindCrlByName(PK11SlotInfo **slot, CK_OBJECT_HANDLE *handle,
168 SECItem *derName, int type, char **url);
169
170CK_OBJECT_HANDLE
171PK11_PutCrl(PK11SlotInfo *slot, SECItem *crl,
172 SECItem *name, char *url, int type);
173
174SECItem *
175PK11_FindSMimeProfile(PK11SlotInfo **slotp, char *emailAddr, SECItem *derSubj,
176 SECItem **profileTime);
177SECStatus
178PK11_SaveSMimeProfile(PK11SlotInfo *slot, char *emailAddr, SECItem *derSubj,
179 SECItem *emailProfile, SECItem *profileTime);
180
181PRBool PK11_IsPermObject(PK11SlotInfo *slot, CK_OBJECT_HANDLE handle);
182
183char *PK11_GetObjectNickname(PK11SlotInfo *slot, CK_OBJECT_HANDLE id);
184SECStatus PK11_SetObjectNickname(PK11SlotInfo *slot, CK_OBJECT_HANDLE id,
185 const char *nickname);
186
187/* private */
188SECStatus pk11_TraverseAllSlots(SECStatus (*callback)(PK11SlotInfo *, void *),
189 void *cbArg, PRBool forceLogin, void *pwArg);
190
191/* fetch multiple CRLs for a specific issuer */
192SECStatus pk11_RetrieveCrls(CERTCrlHeadNode *nodes, SECItem *issuer,
193 void *wincx);
194
195/* set global options for NSS PKCS#11 module loader */
196SECStatus pk11_setGlobalOptions(PRBool noSingleThreadedModules,
197 PRBool allowAlreadyInitializedModules,
198 PRBool dontFinalizeModules);
199
200/* return whether NSS is allowed to call C_Finalize */
201PRBool 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 */
205PRBool pk11slot_GetFIPSStatus(PK11SlotInfo *slot, CK_SESSION_HANDLE session,
206 CK_OBJECT_HANDLE object, CK_ULONG operationType);
207
208SEC_END_PROTOS
209
210#endif
211

source code of include/nss/pk11priv.h