Import from 1.9a8 tarball
[mozilla-nss.git] / security / nss / lib / pk11wrap / pk11priv.h
blobfeef1959a7b8a82a727208670c6171238933fc3c
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
36 #ifndef _PK11PRIV_H_
37 #define _PK11PRIV_H_
38 #include "plarena.h"
39 #include "seccomon.h"
40 #include "secoidt.h"
41 #include "secdert.h"
42 #include "keyt.h"
43 #include "certt.h"
44 #include "pkcs11t.h"
45 #include "secmodt.h"
46 #include "seccomon.h"
47 #include "pkcs7t.h"
48 #include "cmsreclist.h"
51 * These are the private NSS functions. They are not exported by nss.def, and
52 * are not callable outside nss3.dll.
55 SEC_BEGIN_PROTOS
57 /************************************************************
58 * Generic Slot Lists Management
59 ************************************************************/
60 PK11SlotList * PK11_NewSlotList(void);
61 PK11SlotList * PK11_GetPrivateKeyTokens(CK_MECHANISM_TYPE type,
62 PRBool needRW,void *wincx);
63 SECStatus PK11_AddSlotToList(PK11SlotList *list,PK11SlotInfo *slot);
64 SECStatus PK11_DeleteSlotFromList(PK11SlotList *list,PK11SlotListElement *le);
65 PK11SlotListElement *PK11_FindSlotElement(PK11SlotList *list,
66 PK11SlotInfo *slot);
67 PK11SlotInfo *PK11_FindSlotBySerial(char *serial);
69 /************************************************************
70 * Generic Slot Management
71 ************************************************************/
72 CK_OBJECT_HANDLE PK11_CopyKey(PK11SlotInfo *slot, CK_OBJECT_HANDLE srcObject);
73 SECStatus PK11_ReadAttribute(PK11SlotInfo *slot, CK_OBJECT_HANDLE id,
74 CK_ATTRIBUTE_TYPE type, PRArenaPool *arena, SECItem *result);
75 CK_ULONG PK11_ReadULongAttribute(PK11SlotInfo *slot, CK_OBJECT_HANDLE id,
76 CK_ATTRIBUTE_TYPE type);
77 char * PK11_MakeString(PRArenaPool *arena,char *space,char *staticSring,
78 int stringLen);
79 int PK11_MapError(CK_RV error);
80 CK_SESSION_HANDLE PK11_GetRWSession(PK11SlotInfo *slot);
81 void PK11_RestoreROSession(PK11SlotInfo *slot,CK_SESSION_HANDLE rwsession);
82 PRBool PK11_RWSessionHasLock(PK11SlotInfo *slot,
83 CK_SESSION_HANDLE session_handle);
84 PK11SlotInfo *PK11_NewSlotInfo(SECMODModule *mod);
85 void PK11_EnterSlotMonitor(PK11SlotInfo *);
86 void PK11_ExitSlotMonitor(PK11SlotInfo *);
87 void PK11_CleanKeyList(PK11SlotInfo *slot);
90 /************************************************************
91 * Slot Password Management
92 ************************************************************/
93 SECStatus PK11_DoPassword(PK11SlotInfo *slot, PRBool loadCerts, void *wincx);
94 SECStatus PK11_VerifyPW(PK11SlotInfo *slot,char *pw);
95 void PK11_HandlePasswordCheck(PK11SlotInfo *slot,void *wincx);
96 void PK11_SetVerifyPasswordFunc(PK11VerifyPasswordFunc func);
97 void PK11_SetIsLoggedInFunc(PK11IsLoggedInFunc func);
99 /************************************************************
100 * Manage the built-In Slot Lists
101 ************************************************************/
102 SECStatus PK11_InitSlotLists(void);
103 void PK11_DestroySlotLists(void);
104 PK11SlotList *PK11_GetSlotList(CK_MECHANISM_TYPE type);
105 void PK11_LoadSlotList(PK11SlotInfo *slot, PK11PreSlotInfo *psi, int count);
106 void PK11_ClearSlotList(PK11SlotInfo *slot);
109 /******************************************************************
110 * Slot initialization
111 ******************************************************************/
112 PRBool PK11_VerifyMechanism(PK11SlotInfo *slot,PK11SlotInfo *intern,
113 CK_MECHANISM_TYPE mech, SECItem *data, SECItem *iv);
114 PRBool PK11_VerifySlotMechanisms(PK11SlotInfo *slot);
115 SECStatus pk11_CheckVerifyTest(PK11SlotInfo *slot);
116 SECStatus PK11_InitToken(PK11SlotInfo *slot, PRBool loadCerts);
117 void PK11_InitSlot(SECMODModule *mod,CK_SLOT_ID slotID,PK11SlotInfo *slot);
118 PRBool PK11_NeedPWInitForSlot(PK11SlotInfo *slot);
119 SECStatus PK11_ReadSlotCerts(PK11SlotInfo *slot);
121 /*********************************************************************
122 * Mechanism Mapping functions
123 *********************************************************************/
124 void PK11_AddMechanismEntry(CK_MECHANISM_TYPE type, CK_KEY_TYPE key,
125 CK_MECHANISM_TYPE keygen, int ivLen, int blocksize);
126 CK_MECHANISM_TYPE PK11_GetKeyMechanism(CK_KEY_TYPE type);
127 CK_MECHANISM_TYPE PK11_GetKeyGenWithSize(CK_MECHANISM_TYPE type, int size);
129 /**********************************************************************
130 * Symetric, Public, and Private Keys
131 **********************************************************************/
132 /* Key Generation specialized for SDR (fixed DES3 key) */
133 PK11SymKey *PK11_GenDES3TokenKey(PK11SlotInfo *slot, SECItem *keyid, void *cx);
134 SECKEYPublicKey *PK11_ExtractPublicKey(PK11SlotInfo *slot, KeyType keyType,
135 CK_OBJECT_HANDLE id);
136 CK_OBJECT_HANDLE PK11_FindObjectForCert(CERTCertificate *cert,
137 void *wincx, PK11SlotInfo **pSlot);
138 PK11SymKey * pk11_CopyToSlot(PK11SlotInfo *slot,CK_MECHANISM_TYPE type,
139 CK_ATTRIBUTE_TYPE operation, PK11SymKey *symKey);
141 /**********************************************************************
142 * Certs
143 **********************************************************************/
144 SECStatus PK11_TraversePrivateKeysInSlot( PK11SlotInfo *slot,
145 SECStatus(* callback)(SECKEYPrivateKey*, void*), void *arg);
146 SECKEYPrivateKey * PK11_FindPrivateKeyFromNickname(char *nickname, void *wincx);
147 CK_OBJECT_HANDLE * PK11_FindObjectsFromNickname(char *nickname,
148 PK11SlotInfo **slotptr, CK_OBJECT_CLASS objclass, int *returnCount,
149 void *wincx);
150 CK_OBJECT_HANDLE PK11_MatchItem(PK11SlotInfo *slot,CK_OBJECT_HANDLE peer,
151 CK_OBJECT_CLASS o_class);
152 CK_BBOOL PK11_HasAttributeSet( PK11SlotInfo *slot,
153 CK_OBJECT_HANDLE id,
154 CK_ATTRIBUTE_TYPE type );
155 CK_RV PK11_GetAttributes(PRArenaPool *arena,PK11SlotInfo *slot,
156 CK_OBJECT_HANDLE obj,CK_ATTRIBUTE *attr, int count);
157 int PK11_NumberCertsForCertSubject(CERTCertificate *cert);
158 SECStatus PK11_TraverseCertsForSubject(CERTCertificate *cert,
159 SECStatus(*callback)(CERTCertificate *, void *), void *arg);
160 CERTCertificate *PK11_FindCertFromDERCertItem(PK11SlotInfo *slot,
161 SECItem *derCert, void *wincx);
162 CERTCertificate *PK11_FindCertFromDERSubjectAndNickname(
163 PK11SlotInfo *slot,
164 CERTCertificate *cert, char *nickname,
165 void *wincx);
166 SECStatus PK11_GetKEAMatchedCerts(PK11SlotInfo *slot1,
167 PK11SlotInfo *slot2, CERTCertificate **cert1, CERTCertificate **cert2);
168 SECStatus PK11_TraverseCertsInSlot(PK11SlotInfo *slot,
169 SECStatus(* callback)(CERTCertificate*, void *), void *arg);
170 SECStatus PK11_LookupCrls(CERTCrlHeadNode *nodes, int type, void *wincx);
173 /**********************************************************************
174 * Crypto Contexts
175 **********************************************************************/
176 PK11Context * PK11_CreateContextByRawKey(PK11SlotInfo *slot,
177 CK_MECHANISM_TYPE type, PK11Origin origin, CK_ATTRIBUTE_TYPE operation,
178 SECItem *key, SECItem *param, void *wincx);
179 PRBool PK11_HashOK(SECOidTag hashAlg);
182 /**********************************************************************
183 * Functions which are depricated....
184 **********************************************************************/
186 SECItem *
187 PK11_FindCrlByName(PK11SlotInfo **slot, CK_OBJECT_HANDLE *handle,
188 SECItem *derName, int type, char **url);
190 CK_OBJECT_HANDLE
191 PK11_PutCrl(PK11SlotInfo *slot, SECItem *crl,
192 SECItem *name, char *url, int type);
194 SECItem *
195 PK11_FindSMimeProfile(PK11SlotInfo **slotp, char *emailAddr, SECItem *derSubj,
196 SECItem **profileTime);
197 SECStatus
198 PK11_SaveSMimeProfile(PK11SlotInfo *slot, char *emailAddr, SECItem *derSubj,
199 SECItem *emailProfile, SECItem *profileTime);
201 PRBool PK11_IsPermObject(PK11SlotInfo *slot, CK_OBJECT_HANDLE handle);
203 char * PK11_GetObjectNickname(PK11SlotInfo *slot, CK_OBJECT_HANDLE id) ;
204 SECStatus PK11_SetObjectNickname(PK11SlotInfo *slot, CK_OBJECT_HANDLE id,
205 const char *nickname) ;
208 /* private */
209 SECStatus pk11_TraverseAllSlots( SECStatus (*callback)(PK11SlotInfo *,void *),
210 void *cbArg, PRBool forceLogin, void *pwArg);
212 /* fetch multiple CRLs for a specific issuer */
213 SECStatus pk11_RetrieveCrls(CERTCrlHeadNode *nodes, SECItem* issuer,
214 void *wincx);
216 /* set global options for NSS PKCS#11 module loader */
217 SECStatus pk11_setGlobalOptions(PRBool noSingleThreadedModules,
218 PRBool allowAlreadyInitializedModules,
219 PRBool dontFinalizeModules);
221 /* return whether NSS is allowed to call C_Finalize */
222 PRBool pk11_getFinalizeModulesOption(void);
224 SEC_END_PROTOS
226 #endif