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 ***** */
45
/* find a better home for these... */
46
extern const SEC_ASN1Template SECKEY_PointerToEncryptedPrivateKeyInfoTemplate[];
47
extern SEC_ASN1TemplateChooser NSS_Get_SECKEY_PointerToEncryptedPrivateKeyInfoTemplate;
48
extern const SEC_ASN1Template SECKEY_EncryptedPrivateKeyInfoTemplate[];
49
extern SEC_ASN1TemplateChooser NSS_Get_SECKEY_EncryptedPrivateKeyInfoTemplate;
50
extern const SEC_ASN1Template SECKEY_PrivateKeyInfoTemplate[];
51
extern SEC_ASN1TemplateChooser NSS_Get_SECKEY_PrivateKeyInfoTemplate;
52
extern const SEC_ASN1Template SECKEY_PointerToPrivateKeyInfoTemplate[];
53
extern SEC_ASN1TemplateChooser NSS_Get_SECKEY_PointerToPrivateKeyInfoTemplate;
55
/* PKCS11 needs to be included */
56
typedef struct SECMODModuleStr SECMODModule;
57
typedef struct SECMODModuleListStr SECMODModuleList;
58
typedef NSSRWLock SECMODListLock;
59
typedef struct PK11SlotInfoStr PK11SlotInfo; /* defined in secmodti.h */
60
typedef struct PK11PreSlotInfoStr PK11PreSlotInfo; /* defined in secmodti.h */
61
typedef struct PK11SymKeyStr PK11SymKey; /* defined in secmodti.h */
62
typedef struct PK11ContextStr PK11Context; /* defined in secmodti.h */
63
typedef struct PK11SlotListStr PK11SlotList;
64
typedef struct PK11SlotListElementStr PK11SlotListElement;
65
typedef struct PK11RSAGenParamsStr PK11RSAGenParams;
66
typedef unsigned long SECMODModuleID;
67
typedef struct PK11DefaultArrayEntryStr PK11DefaultArrayEntry;
68
typedef struct PK11GenericObjectStr PK11GenericObject;
69
typedef void (*PK11FreeDataFunc)(void *);
71
struct SECMODModuleStr {
73
PRBool internal; /* true of internally linked modules, false
74
* for the loaded modules */
75
PRBool loaded; /* Set to true if module has been loaded */
76
PRBool isFIPS; /* Set to true if module is finst internal */
77
char *dllName; /* name of the shared library which implements
79
char *commonName; /* name of the module to display to the user */
80
void *library; /* pointer to the library. opaque. used only by
82
void *functionList; /* The PKCS #11 function table */
83
PZLock *refLock; /* only used pk11db.c */
84
int refCount; /* Module reference count */
85
PK11SlotInfo **slots; /* array of slot points attached to this mod*/
86
int slotCount; /* count of slot in above array */
87
PK11PreSlotInfo *slotInfo; /* special info about slots default settings */
88
int slotInfoCount; /* count */
89
SECMODModuleID moduleID; /* ID so we can find this module again */
91
unsigned long ssl[2]; /* SSL cipher enable flags */
92
char *libraryParams; /* Module specific parameters */
93
void *moduleDBFunc; /* function to return module configuration data*/
94
SECMODModule *parent; /* module that loaded us */
95
PRBool isCritical; /* This module must load successfully */
96
PRBool isModuleDB; /* this module has lists of PKCS #11 modules */
97
PRBool moduleDBOnly; /* this module only has lists of PKCS #11 modules */
98
int trustOrder; /* order for this module's certificate trust rollup */
99
int cipherOrder; /* order for cipher operations */
100
unsigned long evControlMask; /* control the running and shutdown of slot
101
* events (SECMOD_WaitForAnyTokenEvent) */
102
CK_VERSION cryptokiVersion; /* version of this library */
105
/* evControlMask flags */
107
* These bits tell the current state of a SECMOD_WaitForAnyTokenEvent.
109
* SECMOD_WAIT_PKCS11_EVENT - we're waiting in the PKCS #11 module in
110
* C_WaitForSlotEvent().
111
* SECMOD_WAIT_SIMULATED_EVENT - we're waiting in the NSS simulation code
112
* which polls for token insertion and removal events.
113
* SECMOD_END_WAIT - SECMOD_CancelWait has been called while the module is
114
* waiting in SECMOD_WaitForAnyTokenEvent. SECMOD_WaitForAnyTokenEvent
115
* should return immediately to it's caller.
117
#define SECMOD_END_WAIT 0x01
118
#define SECMOD_WAIT_SIMULATED_EVENT 0x02
119
#define SECMOD_WAIT_PKCS11_EVENT 0x04
121
struct SECMODModuleListStr {
122
SECMODModuleList *next;
123
SECMODModule *module;
126
struct PK11SlotListStr {
127
PK11SlotListElement *head;
128
PK11SlotListElement *tail;
132
struct PK11SlotListElementStr {
133
PK11SlotListElement *next;
134
PK11SlotListElement *prev;
139
struct PK11RSAGenParamsStr {
145
PK11CertListUnique = 0, /* get one instance of all certs */
146
PK11CertListUser = 1, /* get all instances of user certs */
147
PK11CertListRootUnique = 2, /* get one instance of CA certs without a private key.
148
* deprecated. Use PK11CertListCAUnique
150
PK11CertListCA = 3, /* get all instances of CA certs */
151
PK11CertListCAUnique = 4, /* get one instance of CA certs */
152
PK11CertListUserUnique = 5, /* get one instance of user certs */
153
PK11CertListAll = 6 /* get all instances of all certs */
157
* Entry into the Array which lists all the legal bits for the default flags
158
* in the slot, their definition, and the PKCS #11 mechanism the represent
159
* Always Statically allocated.
161
struct PK11DefaultArrayEntryStr {
164
unsigned long mechanism; /* this is a long so we don't include the
165
* whole pkcs 11 world to use this header */
169
#define SECMOD_RSA_FLAG 0x00000001L
170
#define SECMOD_DSA_FLAG 0x00000002L
171
#define SECMOD_RC2_FLAG 0x00000004L
172
#define SECMOD_RC4_FLAG 0x00000008L
173
#define SECMOD_DES_FLAG 0x00000010L
174
#define SECMOD_DH_FLAG 0x00000020L
175
#define SECMOD_FORTEZZA_FLAG 0x00000040L
176
#define SECMOD_RC5_FLAG 0x00000080L
177
#define SECMOD_SHA1_FLAG 0x00000100L
178
#define SECMOD_MD5_FLAG 0x00000200L
179
#define SECMOD_MD2_FLAG 0x00000400L
180
#define SECMOD_SSL_FLAG 0x00000800L
181
#define SECMOD_TLS_FLAG 0x00001000L
182
#define SECMOD_AES_FLAG 0x00002000L
183
#define SECMOD_SHA256_FLAG 0x00004000L
184
#define SECMOD_SHA512_FLAG 0x00008000L /* also for SHA384 */
185
/* reserved bit for future, do not use */
186
#define SECMOD_RESERVED_FLAG 0X08000000L
187
#define SECMOD_FRIENDLY_FLAG 0x10000000L
188
#define SECMOD_RANDOM_FLAG 0x80000000L
190
/* need to make SECMOD and PK11 prefixes consistant. */
191
#define PK11_OWN_PW_DEFAULTS 0x20000000L
192
#define PK11_DISABLE_FLAG 0x40000000L
194
/* FAKE PKCS #11 defines */
195
#define CKM_FAKE_RANDOM 0x80000efeL
196
#define CKM_INVALID_MECHANISM 0xffffffffL
197
#define CKA_DIGEST 0x81000000L
198
#define CKA_FLAGS_ONLY 0 /* CKA_CLASS */
203
* A 32-bit bitmask of PK11_ATTR_XXX flags
205
typedef PRUint32 PK11AttrFlags;
210
* The following PK11_ATTR_XXX bitflags are used to specify
211
* PKCS #11 object attributes that have Boolean values. Some NSS
212
* functions have a "PK11AttrFlags attrFlags" parameter whose value
213
* is the logical OR of these bitflags. NSS use these bitflags on
214
* private keys or secret keys. Some of these bitflags also apply
215
* to the public keys associated with the private keys.
217
* For each PKCS #11 object attribute, we need two bitflags to
218
* specify not only "true" and "false" but also "default". For
219
* example, PK11_ATTR_PRIVATE and PK11_ATTR_PUBLIC control the
220
* CKA_PRIVATE attribute. If PK11_ATTR_PRIVATE is set, we add
221
* { CKA_PRIVATE, &cktrue, sizeof(CK_BBOOL) }
222
* to the template. If PK11_ATTR_PUBLIC is set, we add
223
* { CKA_PRIVATE, &ckfalse, sizeof(CK_BBOOL) }
224
* to the template. If neither flag is set, we don't add any
225
* CKA_PRIVATE entry to the template.
229
* Attributes for PKCS #11 storage objects, which include not only
230
* keys but also certificates and domain parameters.
237
* These two flags determine whether the object is a token or
240
* These two flags are related and cannot both be set.
241
* If the PK11_ATTR_TOKEN flag is set, the object is a token
242
* object. If the PK11_ATTR_SESSION flag is set, the object is
243
* a session object. If neither flag is set, the object is *by
244
* default* a session object.
246
* These two flags specify the value of the PKCS #11 CKA_TOKEN
249
#define PK11_ATTR_TOKEN 0x00000001L
250
#define PK11_ATTR_SESSION 0x00000002L
256
* These two flags determine whether the object is a private or
257
* public object. A user may not access a private object until the
258
* user has authenticated to the token.
260
* These two flags are related and cannot both be set.
261
* If the PK11_ATTR_PRIVATE flag is set, the object is a private
262
* object. If the PK11_ATTR_PUBLIC flag is set, the object is a
263
* public object. If neither flag is set, it is token-specific
264
* whether the object is private or public.
266
* These two flags specify the value of the PKCS #11 CKA_PRIVATE
267
* attribute. NSS only uses this attribute on private and secret
268
* keys, so public keys created by NSS get the token-specific
269
* default value of the CKA_PRIVATE attribute.
271
#define PK11_ATTR_PRIVATE 0x00000004L
272
#define PK11_ATTR_PUBLIC 0x00000008L
275
* PK11_ATTR_MODIFIABLE
276
* PK11_ATTR_UNMODIFIABLE
278
* These two flags determine whether the object is modifiable or
281
* These two flags are related and cannot both be set.
282
* If the PK11_ATTR_MODIFIABLE flag is set, the object can be
283
* modified. If the PK11_ATTR_UNMODIFIABLE flag is set, the object
284
* is read-only. If neither flag is set, the object is *by default*
287
* These two flags specify the value of the PKCS #11 CKA_MODIFIABLE
290
#define PK11_ATTR_MODIFIABLE 0x00000010L
291
#define PK11_ATTR_UNMODIFIABLE 0x00000020L
293
/* Attributes for PKCS #11 key objects. */
296
* PK11_ATTR_SENSITIVE
297
* PK11_ATTR_INSENSITIVE
299
* These two flags are related and cannot both be set.
300
* If the PK11_ATTR_SENSITIVE flag is set, the key is sensitive.
301
* If the PK11_ATTR_INSENSITIVE flag is set, the key is not
302
* sensitive. If neither flag is set, it is token-specific whether
303
* the key is sensitive or not.
305
* If a key is sensitive, certain attributes of the key cannot be
306
* revealed in plaintext outside the token.
308
* This flag specifies the value of the PKCS #11 CKA_SENSITIVE
309
* attribute. Although the default value of the CKA_SENSITIVE
310
* attribute for secret keys is CK_FALSE per PKCS #11, some FIPS
311
* tokens set the default value to CK_TRUE because only CK_TRUE
312
* is allowed. So in practice the default value of this attribute
313
* is token-specific, hence the need for two bitflags.
315
#define PK11_ATTR_SENSITIVE 0x00000040L
316
#define PK11_ATTR_INSENSITIVE 0x00000080L
319
* PK11_ATTR_EXTRACTABLE
320
* PK11_ATTR_UNEXTRACTABLE
322
* These two flags are related and cannot both be set.
323
* If the PK11_ATTR_EXTRACTABLE flag is set, the key is extractable
324
* and can be wrapped. If the PK11_ATTR_UNEXTRACTABLE flag is set,
325
* the key is not extractable, and certain attributes of the key
326
* cannot be revealed in plaintext outside the token (just like a
327
* sensitive key). If neither flag is set, it is token-specific
328
* whether the key is extractable or not.
330
* These two flags specify the value of the PKCS #11 CKA_EXTRACTABLE
333
#define PK11_ATTR_EXTRACTABLE 0x00000100L
334
#define PK11_ATTR_UNEXTRACTABLE 0x00000200L
336
/* Cryptographic module types */
337
#define SECMOD_EXTERNAL 0 /* external module */
338
#define SECMOD_INTERNAL 1 /* internal default module */
339
#define SECMOD_FIPS 2 /* internal fips module */
341
/* default module configuration strings */
342
#define SECMOD_SLOT_FLAGS "slotFlags=[RSA,DSA,DH,RC2,RC4,DES,RANDOM,SHA1,MD5,MD2,SSL,TLS,AES,SHA256,SHA512]"
344
#define SECMOD_MAKE_NSS_FLAGS(fips,slot) \
345
"Flags=internal,critical"fips" slotparams=("#slot"={"SECMOD_SLOT_FLAGS"})"
347
#define SECMOD_INT_NAME "NSS Internal PKCS #11 Module"
348
#define SECMOD_INT_FLAGS SECMOD_MAKE_NSS_FLAGS("",1)
349
#define SECMOD_FIPS_NAME "NSS Internal FIPS PKCS #11 Module"
350
#define SECMOD_FIPS_FLAGS SECMOD_MAKE_NSS_FLAGS(",fips",3)
353
* What is the origin of a given Key. Normally this doesn't matter, but
354
* the fortezza code needs to know if it needs to invoke the SSL3 fortezza
358
PK11_OriginNULL = 0, /* There is not key, it's a null SymKey */
359
PK11_OriginDerive = 1, /* Key was derived from some other key */
360
PK11_OriginGenerated = 2, /* Key was generated (also PBE keys) */
361
PK11_OriginFortezzaHack = 3,/* Key was marked for fortezza hack */
362
PK11_OriginUnwrap = 4 /* Key was unwrapped or decrypted */
365
/* PKCS #11 disable reasons */
368
PK11_DIS_USER_SELECTED = 1,
369
PK11_DIS_COULD_NOT_INIT_TOKEN = 2,
370
PK11_DIS_TOKEN_VERIFY_FAILED = 3,
371
PK11_DIS_TOKEN_NOT_PRESENT = 4
372
} PK11DisableReasons;
374
/* types of PKCS #11 objects */
376
PK11_TypeGeneric = 0,
377
PK11_TypePrivKey = 1,
385
/* function pointer type for password callback function.
386
* This type is passed in to PK11_SetPasswordFunc()
388
typedef char *(PR_CALLBACK *PK11PasswordFunc)(PK11SlotInfo *slot, PRBool retry, void *arg);
389
typedef PRBool (PR_CALLBACK *PK11VerifyPasswordFunc)(PK11SlotInfo *slot, void *arg);
390
typedef PRBool (PR_CALLBACK *PK11IsLoggedInFunc)(PK11SlotInfo *slot, void *arg);
393
* Special strings the password callback function can return only if
394
* the slot is an protected auth path slot.
396
#define PK11_PW_RETRY "RETRY" /* an failed attempt to authenticate
397
* has already been made, just retry
399
#define PK11_PW_AUTHENTICATED "AUTH" /* a successful attempt to authenticate
400
* has completed. Continue without
401
* another call to C_Login */
402
/* All other non-null values mean that that NSS could call C_Login to force
403
* the authentication. The following define is to aid applications in
404
* documenting that is what it's trying to do */
405
#define PK11_PW_TRY "TRY" /* Default: a prompt has been presented
406
* to the user, initiate a C_Login
407
* to authenticate the token */
410
* PKCS #11 key structures
416
struct SECKEYAttributeStr {
420
typedef struct SECKEYAttributeStr SECKEYAttribute;
423
** A PKCS#8 private key info object
425
struct SECKEYPrivateKeyInfoStr {
428
SECAlgorithmID algorithm;
430
SECKEYAttribute **attributes;
432
typedef struct SECKEYPrivateKeyInfoStr SECKEYPrivateKeyInfo;
435
** A PKCS#8 private key info object
437
struct SECKEYEncryptedPrivateKeyInfoStr {
439
SECAlgorithmID algorithm;
440
SECItem encryptedData;
442
typedef struct SECKEYEncryptedPrivateKeyInfoStr SECKEYEncryptedPrivateKeyInfo;
445
* token removal detection
448
PK11TokenNotRemovable = 0,
449
PK11TokenPresent = 1,
450
PK11TokenChanged = 2,
455
PK11TokenRemovedOrChangedEvent = 0,
456
PK11TokenPresentEvent = 1
462
#define CRL_IMPORT_DEFAULT_OPTIONS 0x00000000
463
#define CRL_IMPORT_BYPASS_CHECKS 0x00000001
465
#endif /*_SECMODT_H_ */