Back to index

lightning-sunbird  0.9+nobinonly
pk11priv.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Netscape security libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1994-2000
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 #ifndef _PK11PRIV_H_
00037 #define _PK11PRIV_H_
00038 #include "plarena.h"
00039 #include "seccomon.h"
00040 #include "secoidt.h"
00041 #include "secdert.h"
00042 #include "keyt.h"
00043 #include "certt.h"
00044 #include "pkcs11t.h"
00045 #include "secmodt.h"
00046 #include "seccomon.h"
00047 #include "pkcs7t.h"
00048 #include "cmsreclist.h"
00049 
00050 /*
00051  * These are the private NSS functions. They are not exported by nss.def, and
00052  * are not callable outside nss3.dll. 
00053  */
00054 
00055 SEC_BEGIN_PROTOS
00056 
00057 /************************************************************
00058  * Generic Slot Lists Management
00059  ************************************************************/
00060 PK11SlotList * PK11_NewSlotList(void);
00061 PK11SlotList * PK11_GetPrivateKeyTokens(CK_MECHANISM_TYPE type,
00062                                           PRBool needRW,void *wincx);
00063 SECStatus PK11_AddSlotToList(PK11SlotList *list,PK11SlotInfo *slot);
00064 SECStatus PK11_DeleteSlotFromList(PK11SlotList *list,PK11SlotListElement *le);
00065 PK11SlotListElement *PK11_FindSlotElement(PK11SlotList *list,
00066                                                  PK11SlotInfo *slot);
00067 PK11SlotInfo *PK11_FindSlotBySerial(char *serial);
00068 
00069 /************************************************************
00070  * Generic Slot Management
00071  ************************************************************/
00072 CK_OBJECT_HANDLE PK11_CopyKey(PK11SlotInfo *slot, CK_OBJECT_HANDLE srcObject);
00073 SECStatus PK11_ReadAttribute(PK11SlotInfo *slot, CK_OBJECT_HANDLE id,
00074          CK_ATTRIBUTE_TYPE type, PRArenaPool *arena, SECItem *result);
00075 CK_ULONG PK11_ReadULongAttribute(PK11SlotInfo *slot, CK_OBJECT_HANDLE id,
00076          CK_ATTRIBUTE_TYPE type);
00077 char * PK11_MakeString(PRArenaPool *arena,char *space,char *staticSring,
00078                                                         int stringLen);
00079 int PK11_MapError(CK_RV error);
00080 CK_SESSION_HANDLE PK11_GetRWSession(PK11SlotInfo *slot);
00081 void PK11_RestoreROSession(PK11SlotInfo *slot,CK_SESSION_HANDLE rwsession);
00082 PRBool PK11_RWSessionHasLock(PK11SlotInfo *slot,
00083                                     CK_SESSION_HANDLE session_handle);
00084 PK11SlotInfo *PK11_NewSlotInfo(SECMODModule *mod);
00085 void PK11_EnterSlotMonitor(PK11SlotInfo *);
00086 void PK11_ExitSlotMonitor(PK11SlotInfo *);
00087 void PK11_CleanKeyList(PK11SlotInfo *slot);
00088 
00089 
00090 /************************************************************
00091  *  Slot Password Management
00092  ************************************************************/
00093 SECStatus PK11_DoPassword(PK11SlotInfo *slot, PRBool loadCerts, void *wincx);
00094 SECStatus PK11_VerifyPW(PK11SlotInfo *slot,char *pw);
00095 void PK11_HandlePasswordCheck(PK11SlotInfo *slot,void *wincx);
00096 void PK11_SetVerifyPasswordFunc(PK11VerifyPasswordFunc func);
00097 void PK11_SetIsLoggedInFunc(PK11IsLoggedInFunc func);
00098 
00099 /************************************************************
00100  * Manage the built-In Slot Lists
00101  ************************************************************/
00102 SECStatus PK11_InitSlotLists(void);
00103 void PK11_DestroySlotLists(void);
00104 PK11SlotList *PK11_GetSlotList(CK_MECHANISM_TYPE type);
00105 void PK11_LoadSlotList(PK11SlotInfo *slot, PK11PreSlotInfo *psi, int count);
00106 void PK11_ClearSlotList(PK11SlotInfo *slot);
00107 
00108 
00109 /******************************************************************
00110  *           Slot initialization
00111  ******************************************************************/
00112 PRBool PK11_VerifyMechanism(PK11SlotInfo *slot,PK11SlotInfo *intern,
00113   CK_MECHANISM_TYPE mech, SECItem *data, SECItem *iv);
00114 PRBool PK11_VerifySlotMechanisms(PK11SlotInfo *slot);
00115 SECStatus pk11_CheckVerifyTest(PK11SlotInfo *slot);
00116 SECStatus PK11_InitToken(PK11SlotInfo *slot, PRBool loadCerts);
00117 void PK11_InitSlot(SECMODModule *mod,CK_SLOT_ID slotID,PK11SlotInfo *slot);
00118 PRBool PK11_NeedPWInitForSlot(PK11SlotInfo *slot);
00119 SECStatus PK11_ReadSlotCerts(PK11SlotInfo *slot);
00120 
00121 /*********************************************************************
00122  *       Mechanism Mapping functions
00123  *********************************************************************/
00124 void PK11_AddMechanismEntry(CK_MECHANISM_TYPE type, CK_KEY_TYPE key,
00125                      CK_MECHANISM_TYPE keygen, int ivLen, int blocksize);
00126 CK_MECHANISM_TYPE PK11_GetKeyMechanism(CK_KEY_TYPE type);
00127 CK_MECHANISM_TYPE PK11_GetKeyGenWithSize(CK_MECHANISM_TYPE type, int size);
00128 
00129 /**********************************************************************
00130  *                   Symetric, Public, and Private Keys 
00131  **********************************************************************/
00132 /* Key Generation specialized for SDR (fixed DES3 key) */
00133 PK11SymKey *PK11_GenDES3TokenKey(PK11SlotInfo *slot, SECItem *keyid, void *cx);
00134 SECKEYPublicKey *PK11_ExtractPublicKey(PK11SlotInfo *slot, KeyType keyType,
00135                                     CK_OBJECT_HANDLE id);
00136 CK_OBJECT_HANDLE PK11_FindObjectForCert(CERTCertificate *cert,
00137                                    void *wincx, PK11SlotInfo **pSlot);
00138 PK11SymKey * pk11_CopyToSlot(PK11SlotInfo *slot,CK_MECHANISM_TYPE type,
00139                      CK_ATTRIBUTE_TYPE operation, PK11SymKey *symKey);
00140 
00141 /**********************************************************************
00142  *                   Certs
00143  **********************************************************************/
00144 SECStatus PK11_TraversePrivateKeysInSlot( PK11SlotInfo *slot,
00145     SECStatus(* callback)(SECKEYPrivateKey*, void*), void *arg);
00146 SECKEYPrivateKey * PK11_FindPrivateKeyFromNickname(char *nickname, void *wincx);
00147 CK_OBJECT_HANDLE * PK11_FindObjectsFromNickname(char *nickname,
00148        PK11SlotInfo **slotptr, CK_OBJECT_CLASS objclass, int *returnCount, 
00149                                                         void *wincx);
00150 CK_OBJECT_HANDLE PK11_MatchItem(PK11SlotInfo *slot,CK_OBJECT_HANDLE peer,
00151                                           CK_OBJECT_CLASS o_class); 
00152 CK_BBOOL PK11_HasAttributeSet( PK11SlotInfo *slot,
00153                             CK_OBJECT_HANDLE id,
00154                             CK_ATTRIBUTE_TYPE type );
00155 CK_RV PK11_GetAttributes(PRArenaPool *arena,PK11SlotInfo *slot,
00156                       CK_OBJECT_HANDLE obj,CK_ATTRIBUTE *attr, int count);
00157 int PK11_NumberCertsForCertSubject(CERTCertificate *cert);
00158 SECStatus PK11_TraverseCertsForSubject(CERTCertificate *cert, 
00159        SECStatus(*callback)(CERTCertificate *, void *), void *arg);
00160 CERTCertificate *PK11_FindCertFromDERCertItem(PK11SlotInfo *slot, 
00161                                      SECItem *derCert, void *wincx);
00162 CERTCertificate *PK11_FindCertFromDERSubjectAndNickname(
00163                                    PK11SlotInfo *slot, 
00164                                    CERTCertificate *cert, char *nickname,
00165                                    void *wincx);
00166 SECStatus PK11_GetKEAMatchedCerts(PK11SlotInfo *slot1,
00167    PK11SlotInfo *slot2, CERTCertificate **cert1, CERTCertificate **cert2);
00168 SECStatus PK11_TraverseCertsInSlot(PK11SlotInfo *slot,
00169        SECStatus(* callback)(CERTCertificate*, void *), void *arg);
00170 SECStatus PK11_LookupCrls(CERTCrlHeadNode *nodes, int type, void *wincx);
00171 
00172 
00173 /**********************************************************************
00174  *                   Crypto Contexts
00175  **********************************************************************/
00176 PK11Context * PK11_CreateContextByRawKey(PK11SlotInfo *slot, 
00177     CK_MECHANISM_TYPE type, PK11Origin origin, CK_ATTRIBUTE_TYPE operation,
00178                             SECItem *key, SECItem *param, void *wincx);
00179 PRBool PK11_HashOK(SECOidTag hashAlg);
00180 
00181 
00182 /**********************************************************************
00183  * Functions which are  depricated....
00184  **********************************************************************/
00185 
00186 SECItem *
00187 PK11_FindCrlByName(PK11SlotInfo **slot, CK_OBJECT_HANDLE *handle,
00188                                    SECItem *derName, int type, char **url);
00189 
00190 CK_OBJECT_HANDLE
00191 PK11_PutCrl(PK11SlotInfo *slot, SECItem *crl, 
00192                             SECItem *name, char *url, int type);
00193 
00194 SECItem *
00195 PK11_FindSMimeProfile(PK11SlotInfo **slotp, char *emailAddr, SECItem *derSubj,
00196                                    SECItem **profileTime);
00197 SECStatus
00198 PK11_SaveSMimeProfile(PK11SlotInfo *slot, char *emailAddr, SECItem *derSubj,
00199                      SECItem *emailProfile, SECItem *profileTime);
00200 
00201 PRBool PK11_IsPermObject(PK11SlotInfo *slot, CK_OBJECT_HANDLE handle);
00202 
00203 char * PK11_GetObjectNickname(PK11SlotInfo *slot, CK_OBJECT_HANDLE id) ;
00204 SECStatus PK11_SetObjectNickname(PK11SlotInfo *slot, CK_OBJECT_HANDLE id, 
00205                                           const char *nickname) ;
00206 
00207 
00208 /* private */
00209 SECStatus pk11_TraverseAllSlots( SECStatus (*callback)(PK11SlotInfo *,void *),
00210        void *cbArg, PRBool forceLogin, void *pwArg);
00211 
00212 /* fetch multiple CRLs for a specific issuer */
00213 SECStatus pk11_RetrieveCrls(CERTCrlHeadNode *nodes, SECItem* issuer,
00214                                    void *wincx);
00215 
00216 /* set global options for NSS PKCS#11 module loader */
00217 SECStatus pk11_setGlobalOptions(PRBool noSingleThreadedModules,
00218                                 PRBool allowAlreadyInitializedModules,
00219                                 PRBool dontFinalizeModules);
00220 
00221 /* return whether NSS is allowed to call C_Finalize */
00222 PRBool pk11_getFinalizeModulesOption(void);
00223 
00224 SEC_END_PROTOS
00225 
00226 #endif