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
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.
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 ***** */
37 * Internal header file included only by files in pkcs11 dir, or in
38 * pkcs11 specific client and server files.
54 extern SECStatus
SECMOD_DeletePermDB(SECMODModule
*module
);
55 extern SECStatus
SECMOD_AddPermDB(SECMODModule
*module
);
56 extern SECStatus
SECMOD_Shutdown(void);
57 void nss_DumpModuleLog(void);
59 extern int secmod_PrivateModuleCount
;
61 extern void SECMOD_Init(void);
62 SECStatus
secmod_ModuleInit(SECMODModule
*mod
, PRBool
* alreadyLoaded
);
65 extern SECStatus
SECMOD_AddModuleToList(SECMODModule
*newModule
);
66 extern SECStatus
SECMOD_AddModuleToDBOnlyList(SECMODModule
*newModule
);
67 extern SECStatus
SECMOD_AddModuleToUnloadList(SECMODModule
*newModule
);
68 extern void SECMOD_RemoveList(SECMODModuleList
**,SECMODModuleList
*);
69 extern void SECMOD_AddList(SECMODModuleList
*,SECMODModuleList
*,SECMODListLock
*);
70 extern SECMODListLock
*SECMOD_NewListLock(void);
71 extern void SECMOD_DestroyListLock(SECMODListLock
*);
72 extern void SECMOD_GetWriteLock(SECMODListLock
*);
73 extern void SECMOD_ReleaseWriteLock(SECMODListLock
*);
75 /* Operate on modules by name */
76 extern SECMODModule
*SECMOD_FindModuleByID(SECMODModuleID
);
78 /* database/memory management */
79 extern SECMODModuleList
*SECMOD_NewModuleListElement(void);
80 extern SECMODModuleList
*SECMOD_DestroyModuleListElement(SECMODModuleList
*);
81 extern void SECMOD_DestroyModuleList(SECMODModuleList
*);
82 extern SECStatus
SECMOD_AddModule(SECMODModule
*newModule
);
84 extern unsigned long SECMOD_InternaltoPubMechFlags(unsigned long internalFlags
);
85 extern unsigned long SECMOD_InternaltoPubCipherFlags(unsigned long internalFlags
);
87 /* Library functions */
88 SECStatus
SECMOD_LoadPKCS11Module(SECMODModule
*);
89 SECStatus
SECMOD_UnloadModule(SECMODModule
*);
90 void SECMOD_SetInternalModule(SECMODModule
*);
92 void SECMOD_SlotDestroyModule(SECMODModule
*module
, PRBool fromSlot
);
93 CK_RV
pk11_notify(CK_SESSION_HANDLE session
, CK_NOTIFICATION event
,
95 void pk11_SignedToUnsigned(CK_ATTRIBUTE
*attrib
);
96 CK_OBJECT_HANDLE
pk11_FindObjectByTemplate(PK11SlotInfo
*slot
,
97 CK_ATTRIBUTE
*inTemplate
,int tsize
);
98 CK_OBJECT_HANDLE
*pk11_FindObjectsByTemplate(PK11SlotInfo
*slot
,
99 CK_ATTRIBUTE
*inTemplate
,int tsize
, int *objCount
);
100 SECStatus
PK11_UpdateSlotAttribute(PK11SlotInfo
*slot
,
101 PK11DefaultArrayEntry
*entry
, PRBool add
);
103 #define PK11_GETTAB(x) ((CK_FUNCTION_LIST_PTR)((x)->functionList))
104 #define PK11_SETATTRS(x,id,v,l) (x)->type = (id); \
105 (x)->pValue=(v); (x)->ulValueLen = (l);
106 SECStatus
PK11_CreateNewObject(PK11SlotInfo
*slot
, CK_SESSION_HANDLE session
,
107 const CK_ATTRIBUTE
*theTemplate
, int count
,
108 PRBool token
, CK_OBJECT_HANDLE
*objectID
);
110 SECStatus
pbe_PK11AlgidToParam(SECAlgorithmID
*algid
,SECItem
*mech
);
111 SECStatus
PBE_PK11ParamToAlgid(SECOidTag algTag
, SECItem
*param
,
112 PRArenaPool
*arena
, SECAlgorithmID
*algId
);
114 PK11SymKey
*pk11_TokenKeyGenWithFlagsAndKeyType(PK11SlotInfo
*slot
,
115 CK_MECHANISM_TYPE type
, SECItem
*param
, CK_KEY_TYPE keyType
,
116 int keySize
, SECItem
*keyId
, CK_FLAGS opFlags
,
117 PK11AttrFlags attrFlags
, void *wincx
);
119 CK_MECHANISM_TYPE
pk11_GetPBECryptoMechanism(SECAlgorithmID
*algid
,
120 SECItem
**param
, SECItem
*pwd
, PRBool faulty3DES
);
124 extern void pk11sdr_Init(void);
125 extern void pk11sdr_Shutdown(void);
128 * Private to pk11wrap.
131 PRBool
pk11_LoginStillRequired(PK11SlotInfo
*slot
, void *wincx
);
132 CK_SESSION_HANDLE
pk11_GetNewSession(PK11SlotInfo
*slot
, PRBool
*owner
);
133 void pk11_CloseSession(PK11SlotInfo
*slot
, CK_SESSION_HANDLE sess
, PRBool own
);
134 PK11SymKey
*pk11_ForceSlot(PK11SymKey
*symKey
, CK_MECHANISM_TYPE type
,
135 CK_ATTRIBUTE_TYPE operation
);
136 /* Convert key operation flags to PKCS #11 attributes. */
137 unsigned int pk11_OpFlagsToAttributes(CK_FLAGS flags
,
138 CK_ATTRIBUTE
*attrs
, CK_BBOOL
*ckTrue
);
139 /* Check for bad (conflicting) attribute flags */
140 PRBool
pk11_BadAttrFlags(PK11AttrFlags attrFlags
);
141 /* Convert key attribute flags to PKCS #11 attributes. */
142 unsigned int pk11_AttrFlagsToAttributes(PK11AttrFlags attrFlags
,
143 CK_ATTRIBUTE
*attrs
, CK_BBOOL
*ckTrue
, CK_BBOOL
*ckFalse
);
144 PRBool
pk11_FindAttrInTemplate(CK_ATTRIBUTE
*attr
, unsigned int numAttrs
,
145 CK_ATTRIBUTE_TYPE target
);
147 CK_MECHANISM_TYPE
pk11_mapWrapKeyType(KeyType keyType
);
148 PK11SymKey
*pk11_KeyExchange(PK11SlotInfo
*slot
, CK_MECHANISM_TYPE type
,
149 CK_ATTRIBUTE_TYPE operation
, CK_FLAGS flags
, PRBool isPerm
,
152 PRBool
pk11_HandleTrustObject(PK11SlotInfo
*slot
, CERTCertificate
*cert
,
153 CERTCertTrust
*trust
);
154 CK_OBJECT_HANDLE
pk11_FindPubKeyByAnyCert(CERTCertificate
*cert
,
155 PK11SlotInfo
**slot
, void *wincx
);
156 SECStatus
pk11_AuthenticateUnfriendly(PK11SlotInfo
*slot
, PRBool loadCerts
,
158 int PK11_NumberObjectsFor(PK11SlotInfo
*slot
, CK_ATTRIBUTE
*findTemplate
,
160 SECItem
*pk11_GetLowLevelKeyFromHandle(PK11SlotInfo
*slot
,
161 CK_OBJECT_HANDLE handle
);
162 SECStatus
PK11_TraverseSlot(PK11SlotInfo
*slot
, void *arg
);
163 CK_OBJECT_HANDLE
pk11_FindPrivateKeyFromCertID(PK11SlotInfo
*slot
,
165 SECKEYPrivateKey
*PK11_MakePrivKey(PK11SlotInfo
*slot
, KeyType keyType
,
166 PRBool isTemp
, CK_OBJECT_HANDLE privID
, void *wincx
);
168 SECItem
*pk11_GenerateNewParamWithKeyLen(CK_MECHANISM_TYPE type
, int keyLen
);
169 SECItem
*pk11_ParamFromIVWithLen(CK_MECHANISM_TYPE type
,
170 SECItem
*iv
, int keyLen
);