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 
5 #ifndef DEVT_H
6 #define DEVT_H
7 
8 /*
9  * devt.h
10  *
11  * This file contains definitions for the low-level cryptoki devices.
12  */
13 
14 #ifndef NSSBASET_H
15 #include "nssbaset.h"
16 #endif /* NSSBASET_H */
17 
18 #ifndef NSSPKIT_H
19 #include "nsspkit.h"
20 #endif /* NSSPKIT_H */
21 
22 #ifndef NSSDEVT_H
23 #include "nssdevt.h"
24 #endif /* NSSDEVT_H */
25 
26 #ifndef BASET_H
27 #include "baset.h"
28 #endif /* BASET_H */
29 
30 #include "secmodt.h"
31 
32 PR_BEGIN_EXTERN_C
33 
34 typedef struct nssSessionStr nssSession;
35 
36 /* XXX until NSSTokenStr is moved */
37 struct nssDeviceBaseStr {
38     NSSArena *arena;
39     PZLock *lock;
40     PRInt32 refCount;
41     NSSUTF8 *name;
42     PRUint32 flags;
43 };
44 
45 typedef struct nssTokenObjectCacheStr nssTokenObjectCache;
46 
47 /* XXX until devobject.c goes away */
48 struct NSSTokenStr {
49     struct nssDeviceBaseStr base;
50     NSSSlot *slot;    /* Parent (or peer, if you will) */
51     CK_FLAGS ckFlags; /* from CK_TOKEN_INFO.flags */
52     PRUint32 flags;
53     void *epv;
54     nssSession *defaultSession;
55     NSSTrustDomain *trustDomain;
56     PRIntervalTime lastTime;
57     nssTokenObjectCache *cache;
58     PK11SlotInfo *pk11slot;
59 };
60 
61 typedef enum {
62     nssSlotAskPasswordTimes_FirstTime = 0,
63     nssSlotAskPasswordTimes_EveryTime = 1,
64     nssSlotAskPasswordTimes_Timeout = 2
65 } nssSlotAskPasswordTimes;
66 
67 struct nssSlotAuthInfoStr {
68     PRTime lastLogin;
69     nssSlotAskPasswordTimes askTimes;
70     PRIntervalTime askPasswordTimeout;
71 };
72 
73 /* values for lastTokenPingState */
74 typedef enum {
75     nssSlotLastPingState_Reset = 0,  /* the state has just been reset, discard
76                                       * our cache */
77     nssSlotLastPingState_Update = 1, /* we are updating the lastTokenPingTime */
78     nssSlotLastPingState_Valid = 2,  /* lastTokenPingTime is valid */
79 } nssSlotLastPingState;
80 
81 struct NSSSlotStr {
82     struct nssDeviceBaseStr base;
83     NSSModule *module; /* Parent */
84     NSSToken *token;   /* Peer */
85     CK_SLOT_ID slotID;
86     CK_FLAGS ckFlags; /* from CK_SLOT_INFO.flags */
87     struct nssSlotAuthInfoStr authInfo;
88     PRIntervalTime lastTokenPingTime;
89     nssSlotLastPingState lastTokenPingState;
90     PZLock *lock;
91     void *epv;
92     PK11SlotInfo *pk11slot;
93     PZLock *isPresentLock;
94     PRCondVar *isPresentCondition;
95     PRThread *isPresentThread;
96 };
97 
98 struct nssSessionStr {
99     /* Must not hold slot->lock when taking lock.
100      * See ordering in nssSlot_IsTokenPresent.
101      */
102     PZLock *lock;
103     CK_SESSION_HANDLE handle;
104     NSSSlot *slot;
105     PRBool isRW;
106     PRBool ownLock;
107 };
108 
109 typedef enum {
110     NSSCertificateType_Unknown = 0,
111     NSSCertificateType_PKIX = 1
112 } NSSCertificateType;
113 
114 typedef enum {
115     nssTrustLevel_Unknown = 0,
116     nssTrustLevel_NotTrusted = 1,
117     nssTrustLevel_Trusted = 2,
118     nssTrustLevel_TrustedDelegator = 3,
119     nssTrustLevel_MustVerify = 4,
120     nssTrustLevel_ValidDelegator = 5
121 } nssTrustLevel;
122 
123 typedef struct nssCryptokiInstanceStr nssCryptokiInstance;
124 
125 struct nssCryptokiInstanceStr {
126     CK_OBJECT_HANDLE handle;
127     NSSToken *token;
128     PRBool isTokenObject;
129     NSSUTF8 *label;
130 };
131 
132 typedef struct nssCryptokiInstanceStr nssCryptokiObject;
133 
134 typedef struct nssTokenCertSearchStr nssTokenCertSearch;
135 
136 typedef enum {
137     nssTokenSearchType_AllObjects = 0,
138     nssTokenSearchType_SessionOnly = 1,
139     nssTokenSearchType_TokenOnly = 2,
140     nssTokenSearchType_TokenForced = 3
141 } nssTokenSearchType;
142 
143 struct nssTokenCertSearchStr {
144     nssTokenSearchType searchType;
145     PRStatus (*callback)(NSSCertificate *c, void *arg);
146     void *cbarg;
147     nssList *cached;
148     /* TODO: add a cache query callback if the list would be large
149      *       (traversal)
150      */
151 };
152 
153 struct nssSlotListStr;
154 typedef struct nssSlotListStr nssSlotList;
155 
156 struct NSSAlgorithmAndParametersStr {
157     CK_MECHANISM mechanism;
158 };
159 
160 PR_END_EXTERN_C
161 
162 #endif /* DEVT_H */
163