File: | libxmlsec/unxlngi6.pro/misc/build/xmlsec1-1.2.14/src/nss/tokens.c |
Location: | line 74, column 22 |
Description: | Dereference of null pointer |
1 | /** | |||
2 | * XMLSec library | |||
3 | * | |||
4 | * This is free software; see Copyright file in the source | |||
5 | * distribution for preciese wording. | |||
6 | * | |||
7 | * Copyright.................................. | |||
8 | * | |||
9 | * Contributor(s): _____________________________ | |||
10 | * | |||
11 | */ | |||
12 | ||||
13 | /** | |||
14 | * In order to ensure that particular crypto operation is performed on | |||
15 | * particular crypto device, a subclass of xmlSecList is used to store slot and | |||
16 | * mechanism information. | |||
17 | * | |||
18 | * In the list, a slot is bound with a mechanism. If the mechanism is available, | |||
19 | * this mechanism only can perform on the slot; otherwise, it can perform on | |||
20 | * every eligibl slot in the list. | |||
21 | * | |||
22 | * When try to find a slot for a particular mechanism, the slot bound with | |||
23 | * avaliable mechanism will be looked up firstly. | |||
24 | */ | |||
25 | #include "globals.h" | |||
26 | #include <string.h> | |||
27 | ||||
28 | #include <xmlsec/xmlsec.h> | |||
29 | #include <xmlsec/errors.h> | |||
30 | #include <xmlsec/list.h> | |||
31 | ||||
32 | #include <xmlsec/nss/tokens.h> | |||
33 | ||||
34 | int | |||
35 | xmlSecNssKeySlotSetMechList( | |||
36 | xmlSecNssKeySlotPtr keySlot , | |||
37 | CK_MECHANISM_TYPE_PTR mechanismList | |||
38 | ) { | |||
39 | int counter ; | |||
40 | ||||
41 | xmlSecAssert2( keySlot != NULL , -1 )if(!( keySlot != ((void*)0) ) ) { xmlSecError("tokens.c",41,__FUNCTION__ , ((void*)0), "keySlot != NULL", 100, " "); return(-1); } ; | |||
42 | ||||
43 | if( keySlot->mechanismList != CK_NULL_PTR0 ) { | |||
44 | xmlFree( keySlot->mechanismList ) ; | |||
45 | ||||
46 | for( counter = 0 ; *( mechanismList + counter ) != CKM_INVALID_MECHANISM0xffffffffUL ; counter ++ ) ; | |||
47 | keySlot->mechanismList = ( CK_MECHANISM_TYPE_PTR )xmlMalloc( ( counter + 1 ) * sizeof( CK_MECHANISM_TYPE ) ) ; | |||
48 | if( keySlot->mechanismList == NULL((void*)0) ) { | |||
49 | xmlSecError( XMLSEC_ERRORS_HERE"tokens.c",49,__FUNCTION__ , | |||
50 | NULL((void*)0) , | |||
51 | NULL((void*)0) , | |||
52 | XMLSEC_ERRORS_R_XMLSEC_FAILED1 , | |||
53 | XMLSEC_ERRORS_NO_MESSAGE" " ) ; | |||
54 | return( -1 ); | |||
55 | } | |||
56 | for( ; counter >= 0 ; counter -- ) | |||
57 | *( keySlot->mechanismList + counter ) = *( mechanismList + counter ) ; | |||
58 | } | |||
59 | ||||
60 | return( 0 ); | |||
61 | } | |||
62 | ||||
63 | int | |||
64 | xmlSecNssKeySlotEnableMech( | |||
65 | xmlSecNssKeySlotPtr keySlot , | |||
66 | CK_MECHANISM_TYPE mechanism | |||
67 | ) { | |||
68 | int counter ; | |||
69 | CK_MECHANISM_TYPE_PTR newList ; | |||
70 | ||||
71 | xmlSecAssert2( keySlot != NULL , -1 )if(!( keySlot != ((void*)0) ) ) { xmlSecError("tokens.c",71,__FUNCTION__ , ((void*)0), "keySlot != NULL", 100, " "); return(-1); } ; | |||
72 | ||||
73 | if( mechanism != CKM_INVALID_MECHANISM0xffffffffUL ) { | |||
74 | for( counter = 0 ; *( keySlot->mechanismList + counter ) != CKM_INVALID_MECHANISM0xffffffffUL ; counter ++ ) ; | |||
| ||||
75 | newList = ( CK_MECHANISM_TYPE_PTR )xmlMalloc( ( counter + 1 + 1 ) * sizeof( CK_MECHANISM_TYPE ) ) ; | |||
76 | if( newList == NULL((void*)0) ) { | |||
77 | xmlSecError( XMLSEC_ERRORS_HERE"tokens.c",77,__FUNCTION__ , | |||
78 | NULL((void*)0) , | |||
79 | NULL((void*)0) , | |||
80 | XMLSEC_ERRORS_R_XMLSEC_FAILED1 , | |||
81 | XMLSEC_ERRORS_NO_MESSAGE" " ) ; | |||
82 | return( -1 ); | |||
83 | } | |||
84 | *( newList + counter + 1 ) = CKM_INVALID_MECHANISM0xffffffffUL ; | |||
85 | *( newList + counter ) = mechanism ; | |||
86 | for( counter -= 1 ; counter >= 0 ; counter -- ) | |||
87 | *( newList + counter ) = *( keySlot->mechanismList + counter ) ; | |||
88 | ||||
89 | xmlFree( keySlot->mechanismList ) ; | |||
90 | keySlot->mechanismList = newList ; | |||
91 | } | |||
92 | ||||
93 | return(0); | |||
94 | } | |||
95 | ||||
96 | int | |||
97 | xmlSecNssKeySlotDisableMech( | |||
98 | xmlSecNssKeySlotPtr keySlot , | |||
99 | CK_MECHANISM_TYPE mechanism | |||
100 | ) { | |||
101 | int counter ; | |||
102 | ||||
103 | xmlSecAssert2( keySlot != NULL , -1 )if(!( keySlot != ((void*)0) ) ) { xmlSecError("tokens.c",103, __FUNCTION__, ((void*)0), "keySlot != NULL", 100, " "); return (-1); } ; | |||
104 | ||||
105 | for( counter = 0 ; *( keySlot->mechanismList + counter ) != CKM_INVALID_MECHANISM0xffffffffUL ; counter ++ ) { | |||
106 | if( *( keySlot->mechanismList + counter ) == mechanism ) { | |||
107 | for( ; *( keySlot->mechanismList + counter ) != CKM_INVALID_MECHANISM0xffffffffUL ; counter ++ ) { | |||
108 | *( keySlot->mechanismList + counter ) = *( keySlot->mechanismList + counter + 1 ) ; | |||
109 | } | |||
110 | ||||
111 | break ; | |||
112 | } | |||
113 | } | |||
114 | ||||
115 | return(0); | |||
116 | } | |||
117 | ||||
118 | CK_MECHANISM_TYPE_PTR | |||
119 | xmlSecNssKeySlotGetMechList( | |||
120 | xmlSecNssKeySlotPtr keySlot | |||
121 | ) { | |||
122 | if( keySlot != NULL((void*)0) ) | |||
123 | return keySlot->mechanismList ; | |||
124 | else | |||
125 | return NULL((void*)0) ; | |||
126 | } | |||
127 | ||||
128 | int | |||
129 | xmlSecNssKeySlotSetSlot( | |||
130 | xmlSecNssKeySlotPtr keySlot , | |||
131 | PK11SlotInfo* slot | |||
132 | ) { | |||
133 | xmlSecAssert2( keySlot != NULL , -1 )if(!( keySlot != ((void*)0) ) ) { xmlSecError("tokens.c",133, __FUNCTION__, ((void*)0), "keySlot != NULL", 100, " "); return (-1); } ; | |||
134 | ||||
135 | if( slot != NULL((void*)0) && keySlot->slot != slot ) { | |||
136 | if( keySlot->slot != NULL((void*)0) ) | |||
137 | PK11_FreeSlot( keySlot->slot ) ; | |||
138 | ||||
139 | if( keySlot->mechanismList != NULL((void*)0) ) { | |||
140 | xmlFree( keySlot->mechanismList ) ; | |||
141 | keySlot->mechanismList = NULL((void*)0) ; | |||
142 | } | |||
143 | ||||
144 | keySlot->slot = PK11_ReferenceSlot( slot ) ; | |||
145 | } | |||
146 | ||||
147 | return(0); | |||
148 | } | |||
149 | ||||
150 | int | |||
151 | xmlSecNssKeySlotInitialize( | |||
152 | xmlSecNssKeySlotPtr keySlot , | |||
153 | PK11SlotInfo* slot | |||
154 | ) { | |||
155 | xmlSecAssert2( keySlot != NULL , -1 )if(!( keySlot != ((void*)0) ) ) { xmlSecError("tokens.c",155, __FUNCTION__, ((void*)0), "keySlot != NULL", 100, " "); return (-1); } ; | |||
156 | xmlSecAssert2( keySlot->slot == NULL , -1 )if(!( keySlot->slot == ((void*)0) ) ) { xmlSecError("tokens.c" ,156,__FUNCTION__, ((void*)0), "keySlot->slot == NULL", 100 , " "); return(-1); } ; | |||
157 | xmlSecAssert2( keySlot->mechanismList == NULL , -1 )if(!( keySlot->mechanismList == ((void*)0) ) ) { xmlSecError ("tokens.c",157,__FUNCTION__, ((void*)0), "keySlot->mechanismList == NULL" , 100, " "); return(-1); } ; | |||
158 | ||||
159 | if( slot != NULL((void*)0) ) { | |||
160 | keySlot->slot = PK11_ReferenceSlot( slot ) ; | |||
161 | } | |||
162 | ||||
163 | return(0); | |||
164 | } | |||
165 | ||||
166 | void | |||
167 | xmlSecNssKeySlotFinalize( | |||
168 | xmlSecNssKeySlotPtr keySlot | |||
169 | ) { | |||
170 | xmlSecAssert( keySlot != NULL )if(!( keySlot != ((void*)0) ) ) { xmlSecError("tokens.c",170, __FUNCTION__, ((void*)0), "keySlot != NULL", 100, " "); return ; } ; | |||
171 | ||||
172 | if( keySlot->mechanismList != NULL((void*)0) ) { | |||
173 | xmlFree( keySlot->mechanismList ) ; | |||
174 | keySlot->mechanismList = NULL((void*)0) ; | |||
175 | } | |||
176 | ||||
177 | if( keySlot->slot != NULL((void*)0) ) { | |||
178 | PK11_FreeSlot( keySlot->slot ) ; | |||
179 | keySlot->slot = NULL((void*)0) ; | |||
180 | } | |||
181 | ||||
182 | } | |||
183 | ||||
184 | PK11SlotInfo* | |||
185 | xmlSecNssKeySlotGetSlot( | |||
186 | xmlSecNssKeySlotPtr keySlot | |||
187 | ) { | |||
188 | if( keySlot != NULL((void*)0) ) | |||
189 | return keySlot->slot ; | |||
190 | else | |||
191 | return NULL((void*)0) ; | |||
192 | } | |||
193 | ||||
194 | xmlSecNssKeySlotPtr | |||
195 | xmlSecNssKeySlotCreate() { | |||
196 | xmlSecNssKeySlotPtr keySlot ; | |||
197 | ||||
198 | /* Allocates a new xmlSecNssKeySlot and fill the fields */ | |||
199 | keySlot = ( xmlSecNssKeySlotPtr )xmlMalloc( sizeof( xmlSecNssKeySlot ) ) ; | |||
200 | if( keySlot == NULL((void*)0) ) { | |||
201 | xmlSecError( XMLSEC_ERRORS_HERE"tokens.c",201,__FUNCTION__ , | |||
202 | NULL((void*)0) , | |||
203 | NULL((void*)0) , | |||
204 | XMLSEC_ERRORS_R_XMLSEC_FAILED1 , | |||
205 | XMLSEC_ERRORS_NO_MESSAGE" " ) ; | |||
206 | return( NULL((void*)0) ); | |||
207 | } | |||
208 | memset( keySlot, 0, sizeof( xmlSecNssKeySlot ) ) ; | |||
209 | ||||
210 | return( keySlot ) ; | |||
211 | } | |||
212 | ||||
213 | int | |||
214 | xmlSecNssKeySlotCopy( | |||
215 | xmlSecNssKeySlotPtr newKeySlot , | |||
216 | xmlSecNssKeySlotPtr keySlot | |||
217 | ) { | |||
218 | CK_MECHANISM_TYPE_PTR mech ; | |||
219 | int counter ; | |||
220 | ||||
221 | xmlSecAssert2( newKeySlot != NULL , -1 )if(!( newKeySlot != ((void*)0) ) ) { xmlSecError("tokens.c",221 ,__FUNCTION__, ((void*)0), "newKeySlot != NULL", 100, " "); return (-1); } ; | |||
222 | xmlSecAssert2( keySlot != NULL , -1 )if(!( keySlot != ((void*)0) ) ) { xmlSecError("tokens.c",222, __FUNCTION__, ((void*)0), "keySlot != NULL", 100, " "); return (-1); } ; | |||
223 | ||||
224 | if( keySlot->slot != NULL((void*)0) && newKeySlot->slot != keySlot->slot ) { | |||
225 | if( newKeySlot->slot != NULL((void*)0) ) | |||
226 | PK11_FreeSlot( newKeySlot->slot ) ; | |||
227 | ||||
228 | newKeySlot->slot = PK11_ReferenceSlot( keySlot->slot ) ; | |||
229 | } | |||
230 | ||||
231 | if( keySlot->mechanismList != CK_NULL_PTR0 ) { | |||
232 | xmlFree( newKeySlot->mechanismList ) ; | |||
233 | ||||
234 | for( counter = 0 ; *( keySlot->mechanismList + counter ) != CKM_INVALID_MECHANISM0xffffffffUL ; counter ++ ) ; | |||
235 | newKeySlot->mechanismList = ( CK_MECHANISM_TYPE_PTR )xmlMalloc( ( counter + 1 ) * sizeof( CK_MECHANISM_TYPE ) ) ; | |||
236 | if( newKeySlot->mechanismList == NULL((void*)0) ) { | |||
237 | xmlSecError( XMLSEC_ERRORS_HERE"tokens.c",237,__FUNCTION__ , | |||
238 | NULL((void*)0) , | |||
239 | NULL((void*)0) , | |||
240 | XMLSEC_ERRORS_R_XMLSEC_FAILED1 , | |||
241 | XMLSEC_ERRORS_NO_MESSAGE" " ) ; | |||
242 | return( -1 ); | |||
243 | } | |||
244 | for( ; counter >= 0 ; counter -- ) | |||
245 | *( newKeySlot->mechanismList + counter ) = *( keySlot->mechanismList + counter ) ; | |||
246 | } | |||
247 | ||||
248 | return( 0 ); | |||
249 | } | |||
250 | ||||
251 | xmlSecNssKeySlotPtr | |||
252 | xmlSecNssKeySlotDuplicate( | |||
253 | xmlSecNssKeySlotPtr keySlot | |||
254 | ) { | |||
255 | xmlSecNssKeySlotPtr newKeySlot ; | |||
256 | int ret ; | |||
257 | ||||
258 | xmlSecAssert2( keySlot != NULL , NULL )if(!( keySlot != ((void*)0) ) ) { xmlSecError("tokens.c",258, __FUNCTION__, ((void*)0), "keySlot != NULL", 100, " "); return (((void*)0)); } ; | |||
259 | ||||
260 | newKeySlot = xmlSecNssKeySlotCreate() ; | |||
261 | if( newKeySlot == NULL((void*)0) ) { | |||
262 | xmlSecError( XMLSEC_ERRORS_HERE"tokens.c",262,__FUNCTION__ , | |||
263 | NULL((void*)0) , | |||
264 | NULL((void*)0) , | |||
265 | XMLSEC_ERRORS_R_XMLSEC_FAILED1 , | |||
266 | XMLSEC_ERRORS_NO_MESSAGE" " ) ; | |||
267 | return( NULL((void*)0) ); | |||
268 | } | |||
269 | ||||
270 | if( xmlSecNssKeySlotCopy( newKeySlot, keySlot ) < 0 ) { | |||
271 | xmlSecError( XMLSEC_ERRORS_HERE"tokens.c",271,__FUNCTION__ , | |||
272 | NULL((void*)0) , | |||
273 | NULL((void*)0) , | |||
274 | XMLSEC_ERRORS_R_XMLSEC_FAILED1 , | |||
275 | XMLSEC_ERRORS_NO_MESSAGE" " ) ; | |||
276 | return( NULL((void*)0) ); | |||
277 | } | |||
278 | ||||
279 | return( newKeySlot ); | |||
280 | } | |||
281 | ||||
282 | void | |||
283 | xmlSecNssKeySlotDestroy( | |||
284 | xmlSecNssKeySlotPtr keySlot | |||
285 | ) { | |||
286 | xmlSecAssert( keySlot != NULL )if(!( keySlot != ((void*)0) ) ) { xmlSecError("tokens.c",286, __FUNCTION__, ((void*)0), "keySlot != NULL", 100, " "); return ; } ; | |||
287 | ||||
288 | if( keySlot->mechanismList != NULL((void*)0) ) | |||
289 | xmlFree( keySlot->mechanismList ) ; | |||
290 | ||||
291 | if( keySlot->slot != NULL((void*)0) ) | |||
292 | PK11_FreeSlot( keySlot->slot ) ; | |||
293 | ||||
294 | xmlFree( keySlot ) ; | |||
295 | } | |||
296 | ||||
297 | int | |||
298 | xmlSecNssKeySlotBindMech( | |||
299 | xmlSecNssKeySlotPtr keySlot , | |||
300 | CK_MECHANISM_TYPE type | |||
301 | ) { | |||
302 | int counter ; | |||
303 | ||||
304 | xmlSecAssert2( keySlot != NULL , 0 )if(!( keySlot != ((void*)0) ) ) { xmlSecError("tokens.c",304, __FUNCTION__, ((void*)0), "keySlot != NULL", 100, " "); return (0); } ; | |||
305 | xmlSecAssert2( keySlot->slot != NULL , 0 )if(!( keySlot->slot != ((void*)0) ) ) { xmlSecError("tokens.c" ,305,__FUNCTION__, ((void*)0), "keySlot->slot != NULL", 100 , " "); return(0); } ; | |||
306 | xmlSecAssert2( type != CKM_INVALID_MECHANISM , 0 )if(!( type != 0xffffffffUL ) ) { xmlSecError("tokens.c",306,__FUNCTION__ , ((void*)0), "type != CKM_INVALID_MECHANISM", 100, " "); return (0); } ; | |||
307 | ||||
308 | for( counter = 0 ; *( keySlot->mechanismList + counter ) != CKM_INVALID_MECHANISM0xffffffffUL ; counter ++ ) { | |||
309 | if( *( keySlot->mechanismList + counter ) == type ) | |||
310 | return(1) ; | |||
311 | } | |||
312 | ||||
313 | return( 0 ) ; | |||
314 | } | |||
315 | ||||
316 | int | |||
317 | xmlSecNssKeySlotSupportMech( | |||
318 | xmlSecNssKeySlotPtr keySlot , | |||
319 | CK_MECHANISM_TYPE type | |||
320 | ) { | |||
321 | xmlSecAssert2( keySlot != NULL , 0 )if(!( keySlot != ((void*)0) ) ) { xmlSecError("tokens.c",321, __FUNCTION__, ((void*)0), "keySlot != NULL", 100, " "); return (0); } ; | |||
322 | xmlSecAssert2( keySlot->slot != NULL , 0 )if(!( keySlot->slot != ((void*)0) ) ) { xmlSecError("tokens.c" ,322,__FUNCTION__, ((void*)0), "keySlot->slot != NULL", 100 , " "); return(0); } ; | |||
323 | xmlSecAssert2( type != CKM_INVALID_MECHANISM , 0 )if(!( type != 0xffffffffUL ) ) { xmlSecError("tokens.c",323,__FUNCTION__ , ((void*)0), "type != CKM_INVALID_MECHANISM", 100, " "); return (0); } ; | |||
324 | ||||
325 | if( PK11_DoesMechanism( keySlot->slot , type ) == PR_TRUE1 ) { | |||
326 | return(1); | |||
327 | } else | |||
328 | return(0); | |||
329 | } | |||
330 | ||||
331 | void | |||
332 | xmlSecNssKeySlotDebugDump( | |||
333 | xmlSecNssKeySlotPtr keySlot , | |||
334 | FILE* output | |||
335 | ) { | |||
336 | xmlSecAssert( keySlot != NULL )if(!( keySlot != ((void*)0) ) ) { xmlSecError("tokens.c",336, __FUNCTION__, ((void*)0), "keySlot != NULL", 100, " "); return ; } ; | |||
337 | xmlSecAssert( output != NULL )if(!( output != ((void*)0) ) ) { xmlSecError("tokens.c",337,__FUNCTION__ , ((void*)0), "output != NULL", 100, " "); return; } ; | |||
338 | ||||
339 | fprintf( output, "== KEY SLOT\n" ); | |||
340 | } | |||
341 | ||||
342 | void | |||
343 | xmlSecNssKeySlotDebugXmlDump( | |||
344 | xmlSecNssKeySlotPtr keySlot , | |||
345 | FILE* output | |||
346 | ) { | |||
347 | } | |||
348 | ||||
349 | /** | |||
350 | * Key Slot List | |||
351 | */ | |||
352 | #ifdef __MINGW32__ // for runtime-pseudo-reloc | |||
353 | static struct _xmlSecPtrListKlass xmlSecNssKeySlotPtrListKlass = { | |||
354 | #else | |||
355 | static xmlSecPtrListKlass xmlSecNssKeySlotPtrListKlass = { | |||
356 | #endif | |||
357 | BAD_CAST(xmlChar *) "mechanism-list", | |||
358 | (xmlSecPtrDuplicateItemMethod)xmlSecNssKeySlotDuplicate, | |||
359 | (xmlSecPtrDestroyItemMethod)xmlSecNssKeySlotDestroy, | |||
360 | (xmlSecPtrDebugDumpItemMethod)xmlSecNssKeySlotDebugDump, | |||
361 | (xmlSecPtrDebugDumpItemMethod)xmlSecNssKeySlotDebugXmlDump, | |||
362 | }; | |||
363 | ||||
364 | xmlSecPtrListId | |||
365 | xmlSecNssKeySlotListGetKlass(void) { | |||
366 | return(&xmlSecNssKeySlotPtrListKlass); | |||
367 | } | |||
368 | ||||
369 | ||||
370 | /*- | |||
371 | * Global PKCS#11 crypto token repository -- Key slot list | |||
372 | */ | |||
373 | static xmlSecPtrListPtr _xmlSecNssKeySlotList = NULL((void*)0) ; | |||
374 | ||||
375 | PK11SlotInfo* | |||
376 | xmlSecNssSlotGet( | |||
377 | CK_MECHANISM_TYPE type | |||
378 | ) { | |||
379 | PK11SlotInfo* slot = NULL((void*)0) ; | |||
380 | xmlSecNssKeySlotPtr keySlot ; | |||
381 | xmlSecSizesize_t ksSize ; | |||
382 | xmlSecSizesize_t ksPos ; | |||
383 | char flag ; | |||
384 | ||||
385 | if( _xmlSecNssKeySlotList == NULL((void*)0) ) { | |||
386 | slot = PK11_GetBestSlot( type , NULL((void*)0) ) ; | |||
387 | } else { | |||
388 | ksSize = xmlSecPtrListGetSize( _xmlSecNssKeySlotList ) ; | |||
389 | ||||
390 | /*- | |||
391 | * Firstly, checking whether the mechanism is bound with a special slot. | |||
392 | * If no bound slot, we try to find the first eligible slot in the list. | |||
393 | */ | |||
394 | for( flag = 0, ksPos = 0 ; ksPos < ksSize ; ksPos ++ ) { | |||
395 | keySlot = ( xmlSecNssKeySlotPtr )xmlSecPtrListGetItem( _xmlSecNssKeySlotList, ksPos ) ; | |||
396 | if( keySlot != NULL((void*)0) && xmlSecNssKeySlotBindMech( keySlot, type ) ) { | |||
397 | slot = xmlSecNssKeySlotGetSlot( keySlot ) ; | |||
398 | flag = 2 ; | |||
399 | } else if( flag == 0 && xmlSecNssKeySlotSupportMech( keySlot, type ) ) { | |||
400 | slot = xmlSecNssKeySlotGetSlot( keySlot ) ; | |||
401 | flag = 1 ; | |||
402 | } | |||
403 | ||||
404 | if( flag == 2 ) | |||
405 | break ; | |||
406 | } | |||
407 | if( slot != NULL((void*)0) ) | |||
408 | slot = PK11_ReferenceSlot( slot ) ; | |||
409 | } | |||
410 | ||||
411 | if( slot != NULL((void*)0) && PK11_NeedLogin( slot ) ) { | |||
412 | if( PK11_Authenticate( slot , PR_TRUE1 , NULL((void*)0) ) != SECSuccess ) { | |||
413 | xmlSecError( XMLSEC_ERRORS_HERE"tokens.c",413,__FUNCTION__ , | |||
414 | NULL((void*)0) , | |||
415 | NULL((void*)0) , | |||
416 | XMLSEC_ERRORS_R_XMLSEC_FAILED1 , | |||
417 | XMLSEC_ERRORS_NO_MESSAGE" " ) ; | |||
418 | PK11_FreeSlot( slot ) ; | |||
419 | return( NULL((void*)0) ); | |||
420 | } | |||
421 | } | |||
422 | ||||
423 | return slot ; | |||
424 | } | |||
425 | ||||
426 | int | |||
427 | xmlSecNssSlotInitialize( | |||
428 | void | |||
429 | ) { | |||
430 | if( _xmlSecNssKeySlotList != NULL((void*)0) ) { | |||
431 | xmlSecPtrListDestroy( _xmlSecNssKeySlotList ) ; | |||
432 | _xmlSecNssKeySlotList = NULL((void*)0) ; | |||
433 | } | |||
434 | ||||
435 | _xmlSecNssKeySlotList = xmlSecPtrListCreate( xmlSecNssKeySlotListIdxmlSecNssKeySlotListGetKlass() ) ; | |||
436 | if( _xmlSecNssKeySlotList == NULL((void*)0) ) { | |||
437 | xmlSecError( XMLSEC_ERRORS_HERE"tokens.c",437,__FUNCTION__ , | |||
438 | NULL((void*)0) , | |||
439 | NULL((void*)0) , | |||
440 | XMLSEC_ERRORS_R_XMLSEC_FAILED1 , | |||
441 | XMLSEC_ERRORS_NO_MESSAGE" " ) ; | |||
442 | return( -1 ); | |||
443 | } | |||
444 | ||||
445 | return(0); | |||
446 | } | |||
447 | ||||
448 | void | |||
449 | xmlSecNssSlotShutdown( | |||
450 | void | |||
451 | ) { | |||
452 | if( _xmlSecNssKeySlotList != NULL((void*)0) ) { | |||
453 | xmlSecPtrListDestroy( _xmlSecNssKeySlotList ) ; | |||
454 | _xmlSecNssKeySlotList = NULL((void*)0) ; | |||
455 | } | |||
456 | } | |||
457 | ||||
458 | int | |||
459 | xmlSecNssSlotAdopt( | |||
460 | PK11SlotInfo* slot, | |||
461 | CK_MECHANISM_TYPE type | |||
462 | ) { | |||
463 | xmlSecNssKeySlotPtr keySlot ; | |||
464 | xmlSecSizesize_t ksSize ; | |||
465 | xmlSecSizesize_t ksPos ; | |||
466 | char flag ; | |||
467 | ||||
468 | xmlSecAssert2( _xmlSecNssKeySlotList != NULL, -1 )if(!( _xmlSecNssKeySlotList != ((void*)0) ) ) { xmlSecError("tokens.c" ,468,__FUNCTION__, ((void*)0), "_xmlSecNssKeySlotList != NULL" , 100, " "); return(-1); } ; | |||
469 | xmlSecAssert2( slot != NULL, -1 )if(!( slot != ((void*)0) ) ) { xmlSecError("tokens.c",469,__FUNCTION__ , ((void*)0), "slot != NULL", 100, " "); return(-1); } ; | |||
470 | ||||
471 | ksSize = xmlSecPtrListGetSize( _xmlSecNssKeySlotList ) ; | |||
472 | ||||
473 | /*- | |||
474 | * Firstly, checking whether the slot is in the repository already. | |||
475 | */ | |||
476 | flag = 0 ; | |||
477 | for( ksPos = 0 ; ksPos < ksSize ; ksPos ++ ) { | |||
| ||||
478 | keySlot = ( xmlSecNssKeySlotPtr )xmlSecPtrListGetItem( _xmlSecNssKeySlotList, ksPos ) ; | |||
479 | /* If find the slot in the list */ | |||
480 | if( keySlot != NULL((void*)0) && xmlSecNssKeySlotGetSlot( keySlot ) == slot ) { | |||
481 | /* If mechnism type is valid, bind the slot with the mechanism */ | |||
482 | if( type != CKM_INVALID_MECHANISM0xffffffffUL ) { | |||
483 | if( xmlSecNssKeySlotEnableMech( keySlot, type ) < 0 ) { | |||
484 | xmlSecError( XMLSEC_ERRORS_HERE"tokens.c",484,__FUNCTION__ , | |||
485 | NULL((void*)0) , | |||
486 | NULL((void*)0) , | |||
487 | XMLSEC_ERRORS_R_XMLSEC_FAILED1 , | |||
488 | XMLSEC_ERRORS_NO_MESSAGE" " ) ; | |||
489 | return(-1); | |||
490 | } | |||
491 | } | |||
492 | ||||
493 | flag = 1 ; | |||
494 | } | |||
495 | } | |||
496 | ||||
497 | /* If the slot do not in the list, add a new item to the list */ | |||
498 | if( flag == 0 ) { | |||
499 | /* Create a new KeySlot */ | |||
500 | keySlot = xmlSecNssKeySlotCreate() ; | |||
501 | if( keySlot == NULL((void*)0) ) { | |||
502 | xmlSecError( XMLSEC_ERRORS_HERE"tokens.c",502,__FUNCTION__ , | |||
503 | NULL((void*)0) , | |||
504 | NULL((void*)0) , | |||
505 | XMLSEC_ERRORS_R_XMLSEC_FAILED1 , | |||
506 | XMLSEC_ERRORS_NO_MESSAGE" " ) ; | |||
507 | return(-1); | |||
508 | } | |||
509 | ||||
510 | /* Initialize the keySlot with a slot */ | |||
511 | if( xmlSecNssKeySlotInitialize( keySlot, slot ) < 0 ) { | |||
512 | xmlSecError( XMLSEC_ERRORS_HERE"tokens.c",512,__FUNCTION__ , | |||
513 | NULL((void*)0) , | |||
514 | NULL((void*)0) , | |||
515 | XMLSEC_ERRORS_R_XMLSEC_FAILED1 , | |||
516 | XMLSEC_ERRORS_NO_MESSAGE" " ) ; | |||
517 | xmlSecNssKeySlotDestroy( keySlot ) ; | |||
518 | return(-1); | |||
519 | } | |||
520 | ||||
521 | /* If mechnism type is valid, bind the slot with the mechanism */ | |||
522 | if( type != CKM_INVALID_MECHANISM0xffffffffUL ) { | |||
523 | if( xmlSecNssKeySlotEnableMech( keySlot, type ) < 0 ) { | |||
524 | xmlSecError( XMLSEC_ERRORS_HERE"tokens.c",524,__FUNCTION__ , | |||
525 | NULL((void*)0) , | |||
526 | NULL((void*)0) , | |||
527 | XMLSEC_ERRORS_R_XMLSEC_FAILED1 , | |||
528 | XMLSEC_ERRORS_NO_MESSAGE" " ) ; | |||
529 | xmlSecNssKeySlotDestroy( keySlot ) ; | |||
530 | return(-1); | |||
531 | } | |||
532 | } | |||
533 | ||||
534 | /* Add keySlot into the list */ | |||
535 | if( xmlSecPtrListAdd( _xmlSecNssKeySlotList, keySlot ) < 0 ) { | |||
536 | xmlSecError( XMLSEC_ERRORS_HERE"tokens.c",536,__FUNCTION__ , | |||
537 | NULL((void*)0) , | |||
538 | NULL((void*)0) , | |||
539 | XMLSEC_ERRORS_R_XMLSEC_FAILED1 , | |||
540 | XMLSEC_ERRORS_NO_MESSAGE" " ) ; | |||
541 | xmlSecNssKeySlotDestroy( keySlot ) ; | |||
542 | return(-1); | |||
543 | } | |||
544 | } | |||
545 | ||||
546 | return(0); | |||
547 | } | |||
548 |