Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | /* |
michael@0 | 5 | * Internal data structures and functions used by pkcs11.c |
michael@0 | 6 | */ |
michael@0 | 7 | #ifndef _LGDB_H_ |
michael@0 | 8 | #define _LGDB_H_ 1 |
michael@0 | 9 | |
michael@0 | 10 | #include "nssilock.h" |
michael@0 | 11 | #include "seccomon.h" |
michael@0 | 12 | #include "secoidt.h" |
michael@0 | 13 | #include "lowkeyti.h" |
michael@0 | 14 | #include "pkcs11t.h" |
michael@0 | 15 | #include "sdb.h" |
michael@0 | 16 | #include "cdbhdl.h" |
michael@0 | 17 | |
michael@0 | 18 | |
michael@0 | 19 | #define MULTIACCESS "multiaccess:" |
michael@0 | 20 | |
michael@0 | 21 | |
michael@0 | 22 | /* path stuff (was machine dependent) used by dbinit.c and pk11db.c */ |
michael@0 | 23 | #define PATH_SEPARATOR "/" |
michael@0 | 24 | #define SECMOD_DB "secmod.db" |
michael@0 | 25 | #define CERT_DB_FMT "%scert%s.db" |
michael@0 | 26 | #define KEY_DB_FMT "%skey%s.db" |
michael@0 | 27 | |
michael@0 | 28 | SEC_BEGIN_PROTOS |
michael@0 | 29 | |
michael@0 | 30 | |
michael@0 | 31 | /* internal utility functions used by pkcs11.c */ |
michael@0 | 32 | extern const CK_ATTRIBUTE *lg_FindAttribute(CK_ATTRIBUTE_TYPE type, |
michael@0 | 33 | const CK_ATTRIBUTE *templ, CK_ULONG count); |
michael@0 | 34 | extern CK_RV lg_Attribute2SecItem(PLArenaPool *,CK_ATTRIBUTE_TYPE type, |
michael@0 | 35 | const CK_ATTRIBUTE *templ, CK_ULONG count, |
michael@0 | 36 | SECItem *item); |
michael@0 | 37 | extern CK_RV lg_Attribute2SSecItem(PLArenaPool *,CK_ATTRIBUTE_TYPE type, |
michael@0 | 38 | const CK_ATTRIBUTE *templ, CK_ULONG count, |
michael@0 | 39 | SECItem *item); |
michael@0 | 40 | extern CK_RV lg_PrivAttr2SecItem(PLArenaPool *,CK_ATTRIBUTE_TYPE type, |
michael@0 | 41 | const CK_ATTRIBUTE *templ, CK_ULONG count, |
michael@0 | 42 | SECItem *item, SDB *sdbpw); |
michael@0 | 43 | extern CK_RV lg_PrivAttr2SSecItem(PLArenaPool *,CK_ATTRIBUTE_TYPE type, |
michael@0 | 44 | const CK_ATTRIBUTE *templ, CK_ULONG count, |
michael@0 | 45 | SECItem *item, SDB *sdbpw); |
michael@0 | 46 | extern CK_RV lg_GetULongAttribute(CK_ATTRIBUTE_TYPE type, |
michael@0 | 47 | const CK_ATTRIBUTE *templ, CK_ULONG count, |
michael@0 | 48 | CK_ULONG *out); |
michael@0 | 49 | extern PRBool lg_hasAttribute(CK_ATTRIBUTE_TYPE type, |
michael@0 | 50 | const CK_ATTRIBUTE *templ, CK_ULONG count); |
michael@0 | 51 | extern PRBool lg_isTrue(CK_ATTRIBUTE_TYPE type, |
michael@0 | 52 | const CK_ATTRIBUTE *templ, CK_ULONG count); |
michael@0 | 53 | extern PRBool lg_isSensitive(CK_ATTRIBUTE_TYPE type, CK_OBJECT_CLASS inClass); |
michael@0 | 54 | extern char *lg_getString(CK_ATTRIBUTE_TYPE type, |
michael@0 | 55 | const CK_ATTRIBUTE *templ, CK_ULONG count); |
michael@0 | 56 | extern unsigned int lg_MapTrust(CK_TRUST trust, PRBool clientAuth); |
michael@0 | 57 | |
michael@0 | 58 | /* clear out all the existing object ID to database key mappings. |
michael@0 | 59 | * used to reinit a token */ |
michael@0 | 60 | extern CK_RV lg_ClearTokenKeyHashTable(SDB *sdb); |
michael@0 | 61 | |
michael@0 | 62 | |
michael@0 | 63 | extern void lg_FreeSearch(SDBFind *search); |
michael@0 | 64 | |
michael@0 | 65 | NSSLOWCERTCertDBHandle *lg_getCertDB(SDB *sdb); |
michael@0 | 66 | NSSLOWKEYDBHandle *lg_getKeyDB(SDB *sdb); |
michael@0 | 67 | |
michael@0 | 68 | const char *lg_EvaluateConfigDir(const char *configdir, char **domain); |
michael@0 | 69 | |
michael@0 | 70 | |
michael@0 | 71 | /* |
michael@0 | 72 | * object handle modifiers |
michael@0 | 73 | */ |
michael@0 | 74 | #define LG_TOKEN_MASK 0xc0000000L |
michael@0 | 75 | #define LG_TOKEN_TYPE_MASK 0x38000000L |
michael@0 | 76 | #define LG_TOKEN_TYPE_SHIFT 27 |
michael@0 | 77 | /* keydb (high bit == 0) */ |
michael@0 | 78 | #define LG_TOKEN_TYPE_PRIV 0x08000000L |
michael@0 | 79 | #define LG_TOKEN_TYPE_PUB 0x10000000L |
michael@0 | 80 | #define LG_TOKEN_TYPE_KEY 0x18000000L |
michael@0 | 81 | /* certdb (high bit == 1) */ |
michael@0 | 82 | #define LG_TOKEN_TYPE_TRUST 0x20000000L |
michael@0 | 83 | #define LG_TOKEN_TYPE_CRL 0x28000000L |
michael@0 | 84 | #define LG_TOKEN_TYPE_SMIME 0x30000000L |
michael@0 | 85 | #define LG_TOKEN_TYPE_CERT 0x38000000L |
michael@0 | 86 | |
michael@0 | 87 | #define LG_TOKEN_KRL_HANDLE (LG_TOKEN_TYPE_CRL|1) |
michael@0 | 88 | |
michael@0 | 89 | #define LG_SEARCH_BLOCK_SIZE 10 |
michael@0 | 90 | #define LG_BUF_SPACE 50 |
michael@0 | 91 | #define LG_STRICT PR_FALSE |
michael@0 | 92 | |
michael@0 | 93 | /* |
michael@0 | 94 | * token object utilities |
michael@0 | 95 | */ |
michael@0 | 96 | void lg_addHandle(SDBFind *search, CK_OBJECT_HANDLE handle); |
michael@0 | 97 | PRBool lg_poisonHandle(SDB *sdb, SECItem *dbkey, CK_OBJECT_HANDLE handle); |
michael@0 | 98 | PRBool lg_tokenMatch(SDB *sdb, const SECItem *dbKey, CK_OBJECT_HANDLE class, |
michael@0 | 99 | const CK_ATTRIBUTE *templ, CK_ULONG count); |
michael@0 | 100 | const SECItem *lg_lookupTokenKeyByHandle(SDB *sdb, CK_OBJECT_HANDLE handle); |
michael@0 | 101 | CK_OBJECT_HANDLE lg_mkHandle(SDB *sdb, SECItem *dbKey, CK_OBJECT_HANDLE class); |
michael@0 | 102 | SECStatus lg_deleteTokenKeyByHandle(SDB *sdb, CK_OBJECT_HANDLE handle); |
michael@0 | 103 | |
michael@0 | 104 | SECStatus lg_util_encrypt(PLArenaPool *arena, SDB *sdbpw, |
michael@0 | 105 | SECItem *plainText, SECItem **cipherText); |
michael@0 | 106 | SECStatus lg_util_decrypt(SDB *sdbpw, |
michael@0 | 107 | SECItem *cipherText, SECItem **plainText); |
michael@0 | 108 | PLHashTable *lg_GetHashTable(SDB *sdb); |
michael@0 | 109 | void lg_DBLock(SDB *sdb); |
michael@0 | 110 | void lg_DBUnlock(SDB *sdb); |
michael@0 | 111 | |
michael@0 | 112 | typedef void (*LGFreeFunc)(void *); |
michael@0 | 113 | |
michael@0 | 114 | |
michael@0 | 115 | /* |
michael@0 | 116 | * database functions |
michael@0 | 117 | */ |
michael@0 | 118 | |
michael@0 | 119 | /* lg_FindObjectsInit initializes a search for token and session objects |
michael@0 | 120 | * that match a template. */ |
michael@0 | 121 | CK_RV lg_FindObjectsInit(SDB *sdb, const CK_ATTRIBUTE *pTemplate, |
michael@0 | 122 | CK_ULONG ulCount, SDBFind **search); |
michael@0 | 123 | /* lg_FindObjects continues a search for token and session objects |
michael@0 | 124 | * that match a template, obtaining additional object handles. */ |
michael@0 | 125 | CK_RV lg_FindObjects(SDB *sdb, SDBFind *search, |
michael@0 | 126 | CK_OBJECT_HANDLE *phObject,CK_ULONG ulMaxObjectCount, |
michael@0 | 127 | CK_ULONG *pulObjectCount); |
michael@0 | 128 | |
michael@0 | 129 | /* lg_FindObjectsFinal finishes a search for token and session objects. */ |
michael@0 | 130 | CK_RV lg_FindObjectsFinal(SDB* lgdb, SDBFind *search); |
michael@0 | 131 | |
michael@0 | 132 | /* lg_CreateObject parses the template and create an object stored in the |
michael@0 | 133 | * DB that reflects the object specified in the template. */ |
michael@0 | 134 | CK_RV lg_CreateObject(SDB *sdb, CK_OBJECT_HANDLE *handle, |
michael@0 | 135 | const CK_ATTRIBUTE *templ, CK_ULONG count); |
michael@0 | 136 | |
michael@0 | 137 | CK_RV lg_GetAttributeValue(SDB *sdb, CK_OBJECT_HANDLE object_id, |
michael@0 | 138 | CK_ATTRIBUTE *template, CK_ULONG count); |
michael@0 | 139 | CK_RV lg_SetAttributeValue(SDB *sdb, CK_OBJECT_HANDLE object_id, |
michael@0 | 140 | const CK_ATTRIBUTE *template, CK_ULONG count); |
michael@0 | 141 | CK_RV lg_DestroyObject(SDB *sdb, CK_OBJECT_HANDLE object_id); |
michael@0 | 142 | |
michael@0 | 143 | CK_RV lg_Close(SDB *sdb); |
michael@0 | 144 | CK_RV lg_Reset(SDB *sdb); |
michael@0 | 145 | |
michael@0 | 146 | /* |
michael@0 | 147 | * The old database doesn't share and doesn't support |
michael@0 | 148 | * transactions. |
michael@0 | 149 | */ |
michael@0 | 150 | CK_RV lg_Begin(SDB *sdb); |
michael@0 | 151 | CK_RV lg_Commit(SDB *sdb); |
michael@0 | 152 | CK_RV lg_Abort(SDB *sdb); |
michael@0 | 153 | CK_RV lg_GetMetaData(SDB *sdb, const char *id, SECItem *item1, SECItem *item2); |
michael@0 | 154 | CK_RV lg_PutMetaData(SDB *sdb, const char *id, |
michael@0 | 155 | const SECItem *item1, const SECItem *item2); |
michael@0 | 156 | |
michael@0 | 157 | SEC_END_PROTOS |
michael@0 | 158 | |
michael@0 | 159 | #ifndef XP_UNIX |
michael@0 | 160 | |
michael@0 | 161 | #define NO_FORK_CHECK |
michael@0 | 162 | |
michael@0 | 163 | #endif |
michael@0 | 164 | |
michael@0 | 165 | #ifndef NO_FORK_CHECK |
michael@0 | 166 | |
michael@0 | 167 | extern PRBool lg_parentForkedAfterC_Initialize; |
michael@0 | 168 | #define SKIP_AFTER_FORK(x) if (!lg_parentForkedAfterC_Initialize) x |
michael@0 | 169 | |
michael@0 | 170 | #else |
michael@0 | 171 | |
michael@0 | 172 | #define SKIP_AFTER_FORK(x) x |
michael@0 | 173 | |
michael@0 | 174 | #endif /* NO_FORK_CHECK */ |
michael@0 | 175 | |
michael@0 | 176 | #endif /* _LGDB_H_ */ |
michael@0 | 177 |