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 CK_SLOT_ID slotID; 85 CK_FLAGS ckFlags; /* from CK_SLOT_INFO.flags */ 86 struct nssSlotAuthInfoStr authInfo; 87 PRIntervalTime lastTokenPingTime; 88 nssSlotLastPingState lastTokenPingState; 89 PZLock *lock; 90 void *epv; 91 PK11SlotInfo *pk11slot; 92 PZLock *isPresentLock; 93 PRCondVar *isPresentCondition; 94 PRThread *isPresentThread; 95 }; 96 97 struct nssSessionStr { 98 /* Must not hold slot->lock when taking lock. 99 * See ordering in nssSlot_IsTokenPresent. 100 */ 101 PZLock *lock; 102 CK_SESSION_HANDLE handle; 103 NSSSlot *slot; 104 PRBool isRW; 105 PRBool ownLock; 106 }; 107 108 typedef enum { 109 NSSCertificateType_Unknown = 0, 110 NSSCertificateType_PKIX = 1 111 } NSSCertificateType; 112 113 typedef enum { 114 nssTrustLevel_Unknown = 0, 115 nssTrustLevel_NotTrusted = 1, 116 nssTrustLevel_Trusted = 2, 117 nssTrustLevel_TrustedDelegator = 3, 118 nssTrustLevel_MustVerify = 4, 119 nssTrustLevel_ValidDelegator = 5 120 } nssTrustLevel; 121 122 typedef struct nssCryptokiInstanceStr nssCryptokiInstance; 123 124 struct nssCryptokiInstanceStr { 125 CK_OBJECT_HANDLE handle; 126 NSSToken *token; 127 PRBool isTokenObject; 128 NSSUTF8 *label; 129 }; 130 131 typedef struct nssCryptokiInstanceStr nssCryptokiObject; 132 133 typedef struct nssTokenCertSearchStr nssTokenCertSearch; 134 135 typedef enum { 136 nssTokenSearchType_AllObjects = 0, 137 nssTokenSearchType_SessionOnly = 1, 138 nssTokenSearchType_TokenOnly = 2, 139 nssTokenSearchType_TokenForced = 3 140 } nssTokenSearchType; 141 142 struct nssTokenCertSearchStr { 143 nssTokenSearchType searchType; 144 PRStatus (*callback)(NSSCertificate *c, void *arg); 145 void *cbarg; 146 nssList *cached; 147 /* TODO: add a cache query callback if the list would be large 148 * (traversal) 149 */ 150 }; 151 152 struct nssSlotListStr; 153 typedef struct nssSlotListStr nssSlotList; 154 155 struct NSSAlgorithmAndParametersStr { 156 CK_MECHANISM mechanism; 157 }; 158 159 PR_END_EXTERN_C 160 161 #endif /* DEVT_H */ 162