annotate nss/lib/softoken/legacydb/lgutil.c @ 4:b513267f632f tip

Build DBM module
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 05 Aug 2014 18:58:03 +0200
parents 150b72113545
children
rev   line source
3
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
1 /* This Source Code Form is subject to the terms of the Mozilla Public
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
4 #include "lgdb.h"
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
5 #include "secerr.h"
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
6 #include "lgglue.h"
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
7
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
8 /*
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
9 * ******************** Attribute Utilities *******************************
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
10 */
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
11
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
12 /*
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
13 * look up and attribute structure from a type and Object structure.
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
14 * The returned attribute is referenced and needs to be freed when
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
15 * it is no longer needed.
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
16 */
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
17 const CK_ATTRIBUTE *
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
18 lg_FindAttribute(CK_ATTRIBUTE_TYPE type, const CK_ATTRIBUTE *templ,
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
19 CK_ULONG count )
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
20 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
21 unsigned int i;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
22
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
23 for (i=0; i < count; i++) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
24 if (templ[i].type == type) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
25 return &templ[i];
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
26 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
27 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
28 return NULL;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
29 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
30
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
31
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
32 /*
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
33 * return true if object has attribute
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
34 */
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
35 PRBool
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
36 lg_hasAttribute(CK_ATTRIBUTE_TYPE type, const CK_ATTRIBUTE *templ,
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
37 CK_ULONG count )
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
38 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
39 if (lg_FindAttribute(type, templ, count) == NULL) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
40 return PR_FALSE;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
41 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
42 return PR_TRUE;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
43 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
44
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
45 /*
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
46 * copy an attribute into a SECItem. Secitem is allocated in the specified
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
47 * arena.
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
48 */
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
49 CK_RV
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
50 lg_Attribute2SecItem(PLArenaPool *arena, CK_ATTRIBUTE_TYPE type,
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
51 const CK_ATTRIBUTE *templ, CK_ULONG count,
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
52 SECItem *item)
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
53 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
54 int len;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
55 const CK_ATTRIBUTE *attribute;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
56
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
57 attribute = lg_FindAttribute(type, templ, count);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
58 if (attribute == NULL) return CKR_TEMPLATE_INCOMPLETE;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
59 len = attribute->ulValueLen;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
60
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
61 if (arena) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
62 item->data = (unsigned char *) PORT_ArenaAlloc(arena,len);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
63 } else {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
64 item->data = (unsigned char *) PORT_Alloc(len);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
65 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
66 if (item->data == NULL) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
67 return CKR_HOST_MEMORY;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
68 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
69 item->len = len;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
70 PORT_Memcpy(item->data, attribute->pValue, len);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
71 return CKR_OK;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
72 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
73
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
74
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
75 /*
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
76 * copy an unsigned attribute into a SECItem. Secitem is allocated in
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
77 * the specified arena.
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
78 */
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
79 CK_RV
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
80 lg_Attribute2SSecItem(PLArenaPool *arena, CK_ATTRIBUTE_TYPE type,
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
81 const CK_ATTRIBUTE *templ, CK_ULONG count,
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
82 SECItem *item)
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
83 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
84 const CK_ATTRIBUTE *attribute;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
85 item->data = NULL;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
86
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
87 attribute = lg_FindAttribute(type, templ, count);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
88 if (attribute == NULL) return CKR_TEMPLATE_INCOMPLETE;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
89
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
90 (void)SECITEM_AllocItem(arena, item, attribute->ulValueLen);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
91 if (item->data == NULL) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
92 return CKR_HOST_MEMORY;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
93 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
94 PORT_Memcpy(item->data, attribute->pValue, item->len);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
95 return CKR_OK;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
96 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
97
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
98 /*
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
99 * copy an unsigned attribute into a SECItem. Secitem is allocated in
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
100 * the specified arena.
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
101 */
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
102 CK_RV
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
103 lg_PrivAttr2SSecItem(PLArenaPool *arena, CK_ATTRIBUTE_TYPE type,
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
104 const CK_ATTRIBUTE *templ, CK_ULONG count,
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
105 SECItem *item, SDB *sdbpw)
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
106 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
107 const CK_ATTRIBUTE *attribute;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
108 SECItem epki, *dest = NULL;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
109 SECStatus rv;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
110
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
111 item->data = NULL;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
112
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
113 attribute = lg_FindAttribute(type, templ, count);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
114 if (attribute == NULL) return CKR_TEMPLATE_INCOMPLETE;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
115
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
116 epki.data = attribute->pValue;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
117 epki.len = attribute->ulValueLen;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
118
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
119 rv = lg_util_decrypt(sdbpw, &epki, &dest);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
120 if (rv != SECSuccess) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
121 return CKR_USER_NOT_LOGGED_IN;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
122 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
123 (void)SECITEM_AllocItem(arena, item, dest->len);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
124 if (item->data == NULL) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
125 SECITEM_FreeItem(dest, PR_TRUE);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
126 return CKR_HOST_MEMORY;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
127 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
128
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
129 PORT_Memcpy(item->data, dest->data, item->len);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
130 SECITEM_FreeItem(dest, PR_TRUE);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
131 return CKR_OK;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
132 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
133
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
134 CK_RV
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
135 lg_PrivAttr2SecItem(PLArenaPool *arena, CK_ATTRIBUTE_TYPE type,
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
136 const CK_ATTRIBUTE *templ, CK_ULONG count,
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
137 SECItem *item, SDB *sdbpw)
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
138 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
139 return lg_PrivAttr2SSecItem(arena, type, templ, count, item, sdbpw);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
140 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
141
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
142 /*
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
143 * this is only valid for CK_BBOOL type attributes. Return the state
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
144 * of that attribute.
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
145 */
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
146 PRBool
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
147 lg_isTrue(CK_ATTRIBUTE_TYPE type, const CK_ATTRIBUTE *templ, CK_ULONG count)
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
148 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
149 const CK_ATTRIBUTE *attribute;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
150 PRBool tok = PR_FALSE;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
151
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
152 attribute=lg_FindAttribute(type, templ, count);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
153 if (attribute == NULL) { return PR_FALSE; }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
154 tok = (PRBool)(*(CK_BBOOL *)attribute->pValue);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
155
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
156 return tok;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
157 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
158
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
159 /*
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
160 * return a null terminated string from attribute 'type'. This string
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
161 * is allocated and needs to be freed with PORT_Free() When complete.
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
162 */
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
163 char *
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
164 lg_getString(CK_ATTRIBUTE_TYPE type, const CK_ATTRIBUTE *templ, CK_ULONG count)
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
165 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
166 const CK_ATTRIBUTE *attribute;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
167 char *label = NULL;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
168
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
169 attribute = lg_FindAttribute(type, templ, count);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
170 if (attribute == NULL) return NULL;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
171
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
172 if (attribute->pValue != NULL) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
173 label = (char *) PORT_Alloc(attribute->ulValueLen+1);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
174 if (label == NULL) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
175 return NULL;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
176 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
177
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
178 PORT_Memcpy(label,attribute->pValue, attribute->ulValueLen);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
179 label[attribute->ulValueLen] = 0;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
180 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
181 return label;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
182 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
183
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
184 CK_RV
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
185 lg_GetULongAttribute(CK_ATTRIBUTE_TYPE type, const CK_ATTRIBUTE *templ,
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
186 CK_ULONG count, CK_ULONG *longData)
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
187 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
188 const CK_ATTRIBUTE *attribute;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
189 CK_ULONG value = 0;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
190 const unsigned char *data;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
191 int i;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
192
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
193 attribute = lg_FindAttribute(type, templ, count);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
194 if (attribute == NULL) return CKR_TEMPLATE_INCOMPLETE;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
195
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
196 if (attribute->ulValueLen != 4) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
197 return CKR_ATTRIBUTE_VALUE_INVALID;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
198 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
199 data = (const unsigned char *)attribute->pValue;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
200 for (i=0; i < 4; i++) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
201 value |= (CK_ULONG)(data[i]) << ((3-i)*8);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
202 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
203
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
204 *longData = value;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
205 return CKR_OK;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
206 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
207
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
208 /*
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
209 * ******************** Object Utilities *******************************
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
210 */
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
211
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
212 SECStatus
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
213 lg_deleteTokenKeyByHandle(SDB *sdb, CK_OBJECT_HANDLE handle)
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
214 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
215 SECItem *item;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
216 PRBool rem;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
217 PLHashTable *hashTable= lg_GetHashTable(sdb);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
218
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
219 item = (SECItem *)PL_HashTableLookup(hashTable, (void *)handle);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
220 rem = PL_HashTableRemove(hashTable,(void *)handle) ;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
221 if (rem && item) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
222 SECITEM_FreeItem(item,PR_TRUE);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
223 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
224 return rem ? SECSuccess : SECFailure;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
225 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
226
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
227 /* must be called holding lg_DBLock(sdb) */
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
228 static SECStatus
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
229 lg_addTokenKeyByHandle(SDB *sdb, CK_OBJECT_HANDLE handle, SECItem *key)
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
230 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
231 PLHashEntry *entry;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
232 SECItem *item;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
233 PLHashTable *hashTable= lg_GetHashTable(sdb);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
234
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
235 item = SECITEM_DupItem(key);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
236 if (item == NULL) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
237 return SECFailure;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
238 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
239 entry = PL_HashTableAdd(hashTable,(void *)handle,item);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
240 if (entry == NULL) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
241 SECITEM_FreeItem(item,PR_TRUE);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
242 return SECFailure;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
243 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
244 return SECSuccess;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
245 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
246
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
247 /* must be called holding lg_DBLock(sdb) */
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
248 const SECItem *
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
249 lg_lookupTokenKeyByHandle(SDB *sdb, CK_OBJECT_HANDLE handle)
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
250 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
251 PLHashTable *hashTable= lg_GetHashTable(sdb);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
252 return (const SECItem *)PL_HashTableLookup(hashTable, (void *)handle);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
253 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
254
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
255
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
256 static PRIntn
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
257 lg_freeHashItem(PLHashEntry* entry, PRIntn index, void *arg)
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
258 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
259 SECItem *item = (SECItem *)entry->value;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
260
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
261 SECITEM_FreeItem(item, PR_TRUE);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
262 return HT_ENUMERATE_NEXT;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
263 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
264
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
265 CK_RV
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
266 lg_ClearTokenKeyHashTable(SDB *sdb)
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
267 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
268 PLHashTable *hashTable;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
269 lg_DBLock(sdb);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
270 hashTable= lg_GetHashTable(sdb);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
271 PL_HashTableEnumerateEntries(hashTable, lg_freeHashItem, NULL);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
272 lg_DBUnlock(sdb);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
273 return CKR_OK;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
274 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
275
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
276 /*
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
277 * handle Token Object stuff
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
278 */
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
279 static void
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
280 lg_XORHash(unsigned char *key, unsigned char *dbkey, int len)
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
281 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
282 int i;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
283
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
284 PORT_Memset(key, 0, 4);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
285
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
286 for (i=0; i < len-4; i += 4) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
287 key[0] ^= dbkey[i];
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
288 key[1] ^= dbkey[i+1];
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
289 key[2] ^= dbkey[i+2];
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
290 key[3] ^= dbkey[i+3];
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
291 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
292 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
293
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
294 /* Make a token handle for an object and record it so we can find it again */
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
295 CK_OBJECT_HANDLE
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
296 lg_mkHandle(SDB *sdb, SECItem *dbKey, CK_OBJECT_HANDLE class)
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
297 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
298 unsigned char hashBuf[4];
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
299 CK_OBJECT_HANDLE handle;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
300 const SECItem *key;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
301
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
302 handle = class;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
303 /* there is only one KRL, use a fixed handle for it */
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
304 if (handle != LG_TOKEN_KRL_HANDLE) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
305 lg_XORHash(hashBuf,dbKey->data,dbKey->len);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
306 handle = (hashBuf[0] << 24) | (hashBuf[1] << 16) |
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
307 (hashBuf[2] << 8) | hashBuf[3];
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
308 handle = class | (handle & ~(LG_TOKEN_TYPE_MASK|LG_TOKEN_MASK));
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
309 /* we have a CRL who's handle has randomly matched the reserved KRL
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
310 * handle, increment it */
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
311 if (handle == LG_TOKEN_KRL_HANDLE) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
312 handle++;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
313 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
314 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
315
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
316 lg_DBLock(sdb);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
317 while ((key = lg_lookupTokenKeyByHandle(sdb,handle)) != NULL) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
318 if (SECITEM_ItemsAreEqual(key,dbKey)) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
319 lg_DBUnlock(sdb);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
320 return handle;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
321 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
322 handle++;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
323 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
324 lg_addTokenKeyByHandle(sdb,handle,dbKey);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
325 lg_DBUnlock(sdb);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
326 return handle;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
327 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
328
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
329 PRBool
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
330 lg_poisonHandle(SDB *sdb, SECItem *dbKey, CK_OBJECT_HANDLE class)
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
331 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
332 unsigned char hashBuf[4];
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
333 CK_OBJECT_HANDLE handle;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
334 const SECItem *key;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
335
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
336 handle = class;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
337 /* there is only one KRL, use a fixed handle for it */
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
338 if (handle != LG_TOKEN_KRL_HANDLE) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
339 lg_XORHash(hashBuf,dbKey->data,dbKey->len);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
340 handle = (hashBuf[0] << 24) | (hashBuf[1] << 16) |
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
341 (hashBuf[2] << 8) | hashBuf[3];
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
342 handle = class | (handle & ~(LG_TOKEN_TYPE_MASK|LG_TOKEN_MASK));
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
343 /* we have a CRL who's handle has randomly matched the reserved KRL
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
344 * handle, increment it */
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
345 if (handle == LG_TOKEN_KRL_HANDLE) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
346 handle++;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
347 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
348 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
349 lg_DBLock(sdb);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
350 while ((key = lg_lookupTokenKeyByHandle(sdb,handle)) != NULL) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
351 if (SECITEM_ItemsAreEqual(key,dbKey)) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
352 key->data[0] ^= 0x80;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
353 lg_DBUnlock(sdb);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
354 return PR_TRUE;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
355 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
356 handle++;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
357 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
358 lg_DBUnlock(sdb);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
359 return PR_FALSE;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
360 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
361
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
362 static LGEncryptFunc lg_encrypt_stub = NULL;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
363 static LGDecryptFunc lg_decrypt_stub = NULL;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
364
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
365 void
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
366 legacy_SetCryptFunctions(LGEncryptFunc enc, LGDecryptFunc dec)
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
367 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
368 lg_encrypt_stub = enc;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
369 lg_decrypt_stub = dec;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
370 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
371
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
372 SECStatus lg_util_encrypt(PLArenaPool *arena, SDB *sdb,
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
373 SECItem *plainText, SECItem **cipherText)
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
374 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
375 if (lg_encrypt_stub == NULL) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
376 PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
377 return SECFailure;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
378 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
379 return (*lg_encrypt_stub)(arena, sdb, plainText, cipherText);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
380 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
381
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
382 SECStatus lg_util_decrypt(SDB *sdb, SECItem *cipherText, SECItem **plainText)
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
383 {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
384 if (lg_decrypt_stub == NULL) {
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
385 PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
386 return SECFailure;
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
387 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
388 return (*lg_decrypt_stub)(sdb, cipherText, plainText);
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
389 }
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
390
150b72113545 Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
391
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)