/[openpgpmdrv]/trunk/OpenPGPminidriver/CardAndContainerProperties.c
ViewVC logotype

Annotation of /trunk/OpenPGPminidriver/CardAndContainerProperties.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (hide annotations)
Thu Mar 11 20:32:26 2010 UTC (15 years, 1 month ago) by vletoux
File MIME type: text/plain
File size: 20422 byte(s)
improvement of the quality of the project.
More test for the qualification of the driver success but not all ...

1 vletoux 1 /* OpenPGP Smart Card Mini Driver
2     Copyright (C) 2009 Vincent Le Toux
3    
4     This library is Free software; you can redistribute it and/or
5     modify it under the terms of the GNU Lesser General Public
6     License version 2.1 as published by the Free Software Foundation.
7    
8     This library is distributed in the hope that it will be useful,
9     but WITHOUT ANY WARRANTY; without even the implied warranty of
10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11     Lesser General Public License for more details.
12    
13     You should have received a copy of the GNU Lesser General Public
14     License along with this library; if not, write to the Free Software
15     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16     */
17    
18     #include <windows.h>
19     #include <cardmod.h>
20     #include "Tracing.h"
21     #include "Context.h"
22     #include "CryptoOperations.h"
23     #include "PinOperations.h"
24    
25     // 4.4 Card capabilities
26    
27     /** This function queries the card and card-specific minidriver combination
28     for the functionality that is provided at this level, such as certificate or
29     file compression.*/
30    
31     DWORD WINAPI CardQueryCapabilities(
32     __in PCARD_DATA pCardData,
33     __inout PCARD_CAPABILITIES pCardCapabilities
34     )
35     {
36     DWORD dwReturn = 0, dwVersion;
37 vletoux 8 POPENPGP_CONTEXT pContext = NULL;
38 vletoux 1 Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
39     __try
40     {
41     if ( pCardData == NULL )
42     {
43     Trace(WINEVENT_LEVEL_ERROR, L"pCardData == NULL");
44     dwReturn = SCARD_E_INVALID_PARAMETER;
45     __leave;
46     }
47     if ( pCardCapabilities == NULL )
48     {
49     Trace(WINEVENT_LEVEL_ERROR, L"pCardCapabilities == NULL");
50     dwReturn = SCARD_E_INVALID_PARAMETER;
51     __leave;
52     }
53     dwVersion = (pCardCapabilities->dwVersion == 0) ? 1 : pCardCapabilities->dwVersion;
54     if ( dwVersion != CARD_CAPABILITIES_CURRENT_VERSION )
55     {
56     Trace(WINEVENT_LEVEL_ERROR, L"dwVersion %d", dwVersion);
57     dwReturn = ERROR_REVISION_MISMATCH;
58     __leave;
59     }
60 vletoux 8 dwReturn = CheckContext(pCardData);
61     if ( dwReturn)
62     {
63     __leave;
64     }
65     pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
66     pCardCapabilities->fKeyGen = !pContext->fIsReadOnly;
67     pCardCapabilities->fCertificateCompression = FALSE;
68 vletoux 1 dwReturn = 0;
69     }
70     __finally
71     {
72     }
73     Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
74     return dwReturn;
75     }
76    
77     // 4.5 Card and container properties
78    
79     /** The CardGetContainerProperty function is modeled after the query
80     functions of CAPI for keys. It takes a LPWSTR that indicates which parameter
81     is being requested. Then it returns data written into the pbData parameter.*/
82    
83     DWORD WINAPI CardGetContainerProperty(
84     __in PCARD_DATA pCardData,
85     __in BYTE bContainerIndex,
86     __in LPCWSTR wszProperty,
87     __out_bcount_part_opt(cbData, *pdwDataLen) PBYTE pbData,
88     __in DWORD cbData,
89     __out PDWORD pdwDataLen,
90     __in DWORD dwFlags
91     )
92     {
93     DWORD dwReturn = 0;
94     Trace(WINEVENT_LEVEL_VERBOSE, L"Enter bContainerIndex = %d wszProperty = %s", bContainerIndex, wszProperty);
95     __try
96     {
97     if ( pCardData == NULL )
98     {
99     Trace(WINEVENT_LEVEL_ERROR, L"pCardData == NULL");
100     dwReturn = SCARD_E_INVALID_PARAMETER;
101     __leave;
102     }
103 vletoux 8 if ( pbData == NULL )
104     {
105     Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
106     dwReturn = SCARD_E_INVALID_PARAMETER;
107     __leave;
108     }
109 vletoux 1 if ( pdwDataLen == NULL )
110     {
111     Trace(WINEVENT_LEVEL_ERROR, L"pdwDataLen == NULL");
112     dwReturn = SCARD_E_INVALID_PARAMETER;
113     __leave;
114     }
115     if ( wszProperty == NULL )
116     {
117     Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == NULL");
118     dwReturn = SCARD_E_INVALID_PARAMETER;
119     __leave;
120     }
121     if (dwFlags)
122     {
123     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
124     dwReturn = SCARD_E_INVALID_PARAMETER;
125     __leave;
126     }
127     if (bContainerIndex >= MaxContainer)
128     {
129     Trace(WINEVENT_LEVEL_ERROR, L"bContainerIndex == %d", bContainerIndex);
130     dwReturn = SCARD_E_NO_KEY_CONTAINER ;
131     __leave;
132     }
133     if (wcscmp(wszProperty,CCP_CONTAINER_INFO) == 0)
134     {
135     if (cbData < sizeof(CONTAINER_INFO))
136     {
137     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
138     dwReturn = ERROR_INSUFFICIENT_BUFFER;
139     __leave;
140     }
141     *pdwDataLen = cbData;
142     dwReturn = CardGetContainerInfo(pCardData, bContainerIndex, dwFlags, (PCONTAINER_INFO) pbData);
143     }
144     else if (wcscmp(wszProperty,CCP_PIN_IDENTIFIER) == 0)
145     {
146     if (cbData < sizeof(PIN_ID))
147     {
148     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
149     dwReturn = ERROR_INSUFFICIENT_BUFFER;
150     __leave;
151     }
152     *pdwDataLen = cbData;
153 vletoux 3 if(bContainerIndex >= MaxContainer)
154 vletoux 1 {
155     dwReturn = SCARD_E_NO_KEY_CONTAINER;
156     Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", bContainerIndex);
157     __leave;
158     }
159     (*(PDWORD)pbData) = Containers[bContainerIndex].PinId;
160     dwReturn = 0;
161     }
162     /*else if (wcscmp(wszProperty,CCP_ASSOCIATED_ECDH_KEY) == 0)
163     {
164     }*/
165     else
166     {
167     Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s", wszProperty);
168     dwReturn = SCARD_E_INVALID_PARAMETER;
169     __leave;
170     }
171     }
172     __finally
173     {
174     }
175     Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
176     return dwReturn;
177     }
178    
179     /** This function sets the properties on containers. Only two container
180     properties are supported:
181     • CCP_PIN_IDENTIFIER
182     • CCP_ASSOCIATED_ECDH_KEY
183     */
184    
185     DWORD WINAPI CardSetContainerProperty(
186     __in PCARD_DATA pCardData,
187     __in BYTE bContainerIndex,
188     __in LPCWSTR wszProperty,
189     __in_bcount(cbDataLen) PBYTE pbData,
190     __in DWORD cbDataLen,
191     __in DWORD dwFlags
192     )
193     {
194     DWORD dwReturn = 0;
195     Trace(WINEVENT_LEVEL_VERBOSE, L"Enter bContainerIndex = %d wszProperty = %s", bContainerIndex, wszProperty);
196     __try
197     {
198     if ( pCardData == NULL )
199     {
200     Trace(WINEVENT_LEVEL_ERROR, L"pCardData == NULL");
201     dwReturn = SCARD_E_INVALID_PARAMETER;
202     __leave;
203     }
204     if ( wszProperty == NULL )
205     {
206     Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == NULL");
207     dwReturn = SCARD_E_INVALID_PARAMETER;
208     __leave;
209     }
210     if ( pbData == NULL )
211     {
212     Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
213     dwReturn = SCARD_E_INVALID_PARAMETER;
214     __leave;
215     }
216     if (dwFlags)
217     {
218     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
219     dwReturn = SCARD_E_INVALID_PARAMETER;
220     __leave;
221     }
222     if (wcscmp(wszProperty,CCP_PIN_IDENTIFIER) == 0)
223     {
224     dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
225     __leave;
226     }
227     else if (wcscmp(wszProperty,CCP_ASSOCIATED_ECDH_KEY) == 0)
228     {
229     dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
230     __leave;
231     }
232     else
233     {
234     Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s", wszProperty);
235     dwReturn = SCARD_E_INVALID_PARAMETER;
236     __leave;
237     }
238    
239     }
240     __finally
241     {
242     }
243     Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
244     return dwReturn;
245     }
246    
247     /** The CardGetProperty function is modeled after the query functions of
248     CAPI for keys. It takes a LPWSTR that indicates which parameter is being
249     requested. The function returns data in the pbData parameter.*/
250    
251     DWORD WINAPI CardGetProperty(
252     __in PCARD_DATA pCardData,
253     __in LPCWSTR wszProperty,
254     __out_bcount_part_opt(cbData, *pdwDataLen) PBYTE pbData,
255     __in DWORD cbData,
256     __out PDWORD pdwDataLen,
257     __in DWORD dwFlags
258     )
259     {
260     DWORD dwReturn = 0;
261     PBYTE pbTempData = NULL;
262     DWORD dwTempSize = 0;
263 vletoux 8 POPENPGP_CONTEXT pContext = NULL;
264 vletoux 1 Trace(WINEVENT_LEVEL_VERBOSE, L"Enter wszProperty = %s", wszProperty);
265     __try
266     {
267     if ( pCardData == NULL )
268     {
269     Trace(WINEVENT_LEVEL_ERROR, L"pCardData == NULL");
270     dwReturn = SCARD_E_INVALID_PARAMETER;
271     __leave;
272     }
273     if ( wszProperty == NULL )
274     {
275     Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == NULL");
276     dwReturn = SCARD_E_INVALID_PARAMETER;
277     __leave;
278     }
279 vletoux 8 if ( pbData == NULL )
280     {
281     Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
282     dwReturn = SCARD_E_INVALID_PARAMETER;
283     __leave;
284     }
285 vletoux 1 if ( pdwDataLen == NULL )
286     {
287     Trace(WINEVENT_LEVEL_ERROR, L"pdwDataLen == NULL");
288     dwReturn = SCARD_E_INVALID_PARAMETER;
289     __leave;
290     }
291 vletoux 8 dwReturn = CheckContext(pCardData);
292     if ( dwReturn )
293     {
294     Trace(WINEVENT_LEVEL_ERROR, L"GetContext dwReturn == 0x%08X", dwReturn);
295     dwReturn = SCARD_E_INVALID_PARAMETER;
296     __leave;
297     }
298     pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
299 vletoux 1 if (wcscmp(wszProperty,CP_CARD_FREE_SPACE) == 0)
300     {
301 vletoux 8 if (dwFlags)
302     {
303     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
304     dwReturn = SCARD_E_INVALID_PARAMETER;
305     __leave;
306     }
307 vletoux 1 *pdwDataLen = sizeof(CARD_FREE_SPACE_INFO);
308     if (cbData < *pdwDataLen)
309     {
310     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
311     dwReturn = ERROR_INSUFFICIENT_BUFFER;
312     __leave;
313     }
314     dwReturn = CardQueryFreeSpace(pCardData, dwFlags, (PCARD_FREE_SPACE_INFO) pbData);
315     }
316     else if (wcscmp(wszProperty,CP_CARD_CAPABILITIES) == 0)
317     {
318 vletoux 8 if (dwFlags)
319     {
320     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
321     dwReturn = SCARD_E_INVALID_PARAMETER;
322     __leave;
323     }
324 vletoux 1 *pdwDataLen = sizeof(CARD_CAPABILITIES);
325     if (cbData < *pdwDataLen)
326     {
327     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
328     dwReturn = ERROR_INSUFFICIENT_BUFFER;
329     __leave;
330     }
331     dwReturn = CardQueryCapabilities(pCardData, (PCARD_CAPABILITIES) pbData);
332     }
333     else if (wcscmp(wszProperty,CP_CARD_KEYSIZES) == 0)
334     {
335     *pdwDataLen = sizeof(CARD_KEY_SIZES);
336     if (cbData < *pdwDataLen)
337     {
338     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
339     dwReturn = ERROR_INSUFFICIENT_BUFFER;
340     __leave;
341     }
342     dwReturn = CardQueryKeySizes(pCardData, dwFlags, 0, (PCARD_KEY_SIZES) pbData);
343     }
344     else if (wcscmp(wszProperty,CP_CARD_READ_ONLY) == 0)
345     {
346 vletoux 8 if (dwFlags)
347     {
348     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
349     dwReturn = SCARD_E_INVALID_PARAMETER;
350     __leave;
351     }
352 vletoux 1 *pdwDataLen = sizeof(BOOL);
353     if (cbData < *pdwDataLen)
354     {
355     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
356     dwReturn = ERROR_INSUFFICIENT_BUFFER;
357     __leave;
358     }
359 vletoux 8 *((PBOOL)pbData) = pContext->fIsReadOnly;
360 vletoux 1 }
361     else if (wcscmp(wszProperty,CP_CARD_CACHE_MODE) == 0)
362     {
363 vletoux 8 if (dwFlags)
364     {
365     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
366     dwReturn = SCARD_E_INVALID_PARAMETER;
367     __leave;
368     }
369 vletoux 1 *pdwDataLen = sizeof(DWORD);
370     if (cbData < *pdwDataLen)
371     {
372     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
373     dwReturn = ERROR_INSUFFICIENT_BUFFER;
374     __leave;
375     }
376     *((PDWORD)pbData) = CP_CACHE_MODE_NO_CACHE;
377     }
378     else if (wcscmp(wszProperty,CP_SUPPORTS_WIN_X509_ENROLLMENT) == 0)
379     {
380 vletoux 8 if (dwFlags)
381     {
382     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
383     dwReturn = SCARD_E_INVALID_PARAMETER;
384     __leave;
385     }
386 vletoux 1 *pdwDataLen = sizeof(BOOL);
387     if (cbData < *pdwDataLen)
388     {
389     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
390     dwReturn = ERROR_INSUFFICIENT_BUFFER;
391     __leave;
392     }
393     *((PBOOL)pbData) = FALSE;
394     }
395     else if (wcscmp(wszProperty,CP_CARD_GUID) == 0)
396     {
397 vletoux 8 if (dwFlags)
398     {
399     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
400     dwReturn = SCARD_E_INVALID_PARAMETER;
401     __leave;
402     }
403 vletoux 1 dwReturn = CardReadFile(pCardData, NULL, szCARD_IDENTIFIER_FILE, 0, &pbTempData, &dwTempSize);
404     if (dwReturn)
405     {
406     __leave;
407     }
408     *pdwDataLen = dwTempSize;
409     if (cbData < *pdwDataLen)
410     {
411     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
412     dwReturn = ERROR_INSUFFICIENT_BUFFER;
413     __leave;
414     }
415     memcpy(pbData, pbTempData, dwTempSize);
416     }
417     else if (wcscmp(wszProperty,CP_CARD_SERIAL_NO) == 0)
418     {
419 vletoux 8 if (dwFlags)
420     {
421     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
422     dwReturn = SCARD_E_INVALID_PARAMETER;
423     __leave;
424     }
425 vletoux 1 *pdwDataLen = sizeof(OPENPGP_AID);
426     if (cbData < *pdwDataLen)
427     {
428     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
429     dwReturn = ERROR_INSUFFICIENT_BUFFER;
430     __leave;
431     }
432     memcpy(pbData, &(((POPENPGP_CONTEXT)pCardData->pvVendorSpecific)->Aid), sizeof(OPENPGP_AID));
433     dwReturn = 0;
434     }
435     else if (wcscmp(wszProperty,CP_CARD_PIN_INFO) == 0)
436     {
437     PPIN_INFO pPinInfo;
438     *pdwDataLen = sizeof(PIN_INFO);
439     if (cbData < *pdwDataLen)
440     {
441     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
442     dwReturn = ERROR_INSUFFICIENT_BUFFER;
443     __leave;
444     }
445     pPinInfo = (PPIN_INFO) pbData;
446     dwReturn = GetPinInfo(dwFlags, pPinInfo);
447     }
448     else if (wcscmp(wszProperty,CP_CARD_LIST_PINS) == 0)
449     {
450     PPIN_SET pPinSet;
451 vletoux 8 if (dwFlags)
452     {
453     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
454     dwReturn = SCARD_E_INVALID_PARAMETER;
455     __leave;
456     }
457 vletoux 1 *pdwDataLen = sizeof(PIN_SET);
458     if (cbData < *pdwDataLen)
459     {
460     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
461     dwReturn = ERROR_INSUFFICIENT_BUFFER;
462     __leave;
463     }
464     pPinSet = (PPIN_SET) pbData;
465 vletoux 8 *pPinSet = CREATE_PIN_SET(ROLE_SIGNATURE);
466     SET_PIN(*pPinSet, ROLE_AUTHENTICATION);
467     SET_PIN(*pPinSet, ROLE_CONFIDENTIALITY);
468     SET_PIN(*pPinSet, ROLE_PUK);
469     SET_PIN(*pPinSet, ROLE_ADMIN);
470 vletoux 1 }
471     else if (wcscmp(wszProperty,CP_CARD_AUTHENTICATED_STATE) == 0)
472     {
473 vletoux 8 if (dwFlags)
474     {
475     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
476     dwReturn = SCARD_E_INVALID_PARAMETER;
477     __leave;
478     }
479 vletoux 1 dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
480     }
481     else if (wcscmp(wszProperty,CP_CARD_PIN_STRENGTH_VERIFY) == 0)
482     {
483     PPIN_SET pPinSet;
484 vletoux 8 switch(dwFlags)
485     {
486     case ROLE_SIGNATURE:
487     case ROLE_AUTHENTICATION:
488     case ROLE_CONFIDENTIALITY:
489     case ROLE_ADMIN:
490     case ROLE_PUK:
491     break;
492     default:
493     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
494     dwReturn = SCARD_E_INVALID_PARAMETER;
495     __leave;
496     }
497 vletoux 1 *pdwDataLen = sizeof(PIN_SET);
498     if (cbData < *pdwDataLen)
499     {
500     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
501     dwReturn = ERROR_INSUFFICIENT_BUFFER;
502     __leave;
503     }
504     pPinSet = (PPIN_SET) pbData;
505     *pPinSet = CARD_PIN_STRENGTH_PLAINTEXT;
506     }
507     else if (wcscmp(wszProperty,CP_KEY_IMPORT_SUPPORT) == 0)
508     {
509 vletoux 8 if (dwFlags)
510     {
511     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
512     dwReturn = SCARD_E_INVALID_PARAMETER;
513     __leave;
514     }
515 vletoux 1 *pdwDataLen = sizeof(DWORD);
516     if (cbData < *pdwDataLen)
517     {
518     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
519     dwReturn = ERROR_INSUFFICIENT_BUFFER;
520     __leave;
521     }
522 vletoux 8 if (pContext->fIsReadOnly)
523     {
524     *((PDWORD)pbData) = 0;
525     }
526     else
527     {
528     *((PDWORD)pbData) = CARD_KEY_IMPORT_RSA_KEYEST;
529     }
530 vletoux 1 }
531     else if (wcscmp(wszProperty,CP_ENUM_ALGORITHMS ) == 0)
532     {
533     if (dwFlags == CARD_CIPHER_OPERATION)
534     {
535     *pdwDataLen = sizeof(OPENPGP_SUPPORTED_CYPHER_ALGORITHM);
536     if (cbData < *pdwDataLen)
537     {
538     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
539     dwReturn = ERROR_INSUFFICIENT_BUFFER;
540     __leave;
541     }
542     memcpy(pbData,OPENPGP_SUPPORTED_CYPHER_ALGORITHM,*pdwDataLen);
543     }
544     else if (dwFlags == CARD_ASYMMETRIC_OPERATION )
545     {
546     *pdwDataLen = sizeof(OPENPGP_SUPPORTED_ASYMETRIC_ALGORITHM);
547     if (cbData < *pdwDataLen)
548     {
549     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
550     dwReturn = ERROR_INSUFFICIENT_BUFFER;
551     __leave;
552     }
553     memcpy(pbData,OPENPGP_SUPPORTED_ASYMETRIC_ALGORITHM,*pdwDataLen);
554     }
555     else
556     {
557     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
558     dwReturn = SCARD_E_INVALID_PARAMETER;
559     }
560     }
561     else if (wcscmp(wszProperty,CP_PADDING_SCHEMES ) == 0)
562     {
563     if (dwFlags == CARD_CIPHER_OPERATION)
564     {
565 vletoux 8 Trace(WINEVENT_LEVEL_ERROR, L"CARD_CIPHER_OPERATION", wszProperty);
566 vletoux 1 dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
567     }
568     else if (dwFlags == CARD_ASYMMETRIC_OPERATION )
569     {
570     *pdwDataLen = sizeof(DWORD);
571     if (cbData < *pdwDataLen)
572     {
573     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
574     dwReturn = ERROR_INSUFFICIENT_BUFFER;
575     __leave;
576     }
577     *((PDWORD)pbData) = CARD_PADDING_PKCS1;
578     }
579     else
580     {
581     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
582     dwReturn = SCARD_E_INVALID_PARAMETER;
583     }
584    
585     }
586     else if (wcscmp(wszProperty,CP_CHAINING_MODES ) == 0)
587     {
588 vletoux 8 if (dwFlags)
589     {
590     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
591     dwReturn = SCARD_E_INVALID_PARAMETER;
592     __leave;
593     }
594     Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s", wszProperty);
595 vletoux 1 dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
596     }
597 vletoux 8 else if ( wcscmp(wszProperty,CP_CARD_PIN_STRENGTH_CHANGE ) == 0
598     || wcscmp(wszProperty,CP_CARD_PIN_STRENGTH_UNBLOCK ) == 0)
599     {
600     Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s SCARD_E_UNSUPPORTED_FEATURE", wszProperty);
601     dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
602     }
603 vletoux 1 else
604     {
605 vletoux 8 Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s SCARD_E_INVALID_PARAMETER", wszProperty);
606 vletoux 1 dwReturn = SCARD_E_INVALID_PARAMETER;
607     __leave;
608     }
609     }
610     __finally
611     {
612     if (pbTempData)
613     {
614     pCardData->pfnCspFree(pbTempData);
615     }
616     }
617     Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
618     return dwReturn;
619     }
620    
621     /** This function can be used to set properties on the card.*/
622    
623     DWORD WINAPI CardSetProperty(
624     __in PCARD_DATA pCardData,
625     __in LPCWSTR wszProperty,
626     __in_bcount(cbDataLen) PBYTE pbData,
627     __in DWORD cbDataLen,
628     __in DWORD dwFlags
629     )
630     {
631     DWORD dwReturn = 0;
632     Trace(WINEVENT_LEVEL_VERBOSE, L"Enter wszProperty = %s", wszProperty);
633     __try
634     {
635     if ( pCardData == NULL )
636     {
637     Trace(WINEVENT_LEVEL_ERROR, L"pCardData == NULL");
638     dwReturn = SCARD_E_INVALID_PARAMETER;
639     __leave;
640     }
641     if ( wszProperty == NULL )
642     {
643     Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == NULL");
644     dwReturn = SCARD_E_INVALID_PARAMETER;
645     __leave;
646     }
647     if (dwFlags)
648     {
649     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
650     dwReturn = SCARD_E_INVALID_PARAMETER;
651     __leave;
652     }
653     if (wcscmp(wszProperty,CP_CARD_FREE_SPACE) == 0
654     || wcscmp(wszProperty,CP_CARD_CAPABILITIES) == 0
655     || wcscmp(wszProperty,CP_CARD_KEYSIZES) == 0
656     || wcscmp(wszProperty,CP_CARD_LIST_PINS) == 0
657     || wcscmp(wszProperty,CP_CARD_AUTHENTICATED_STATE) == 0
658     || wcscmp(wszProperty,CP_KEY_IMPORT_SUPPORT) == 0
659     || wcscmp(wszProperty,CP_ENUM_ALGORITHMS) == 0
660     || wcscmp(wszProperty,CP_PADDING_SCHEMES) == 0
661 vletoux 8 || wcscmp(wszProperty,CP_CHAINING_MODES) == 0
662     || wcscmp(wszProperty,CP_SUPPORTS_WIN_X509_ENROLLMENT) == 0
663     || wcscmp(wszProperty,CP_CARD_CACHE_MODE) == 0
664     || wcscmp(wszProperty,CP_CARD_SERIAL_NO) == 0
665     || wcscmp(wszProperty,CP_CARD_GUID) == 0
666     || wcscmp(wszProperty,CP_CARD_PIN_INFO) == 0
667     || wcscmp(wszProperty,CP_CARD_PIN_STRENGTH_VERIFY) == 0)
668 vletoux 1 {
669 vletoux 8 if ( pbData == NULL )
670     {
671     Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
672     dwReturn = SCARD_E_INVALID_PARAMETER;
673     __leave;
674     }
675 vletoux 1 Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s SCARD_E_UNSUPPORTED_FEATURE", wszProperty);
676     dwReturn = SCARD_E_UNSUPPORTED_FEATURE ;
677     __leave;
678     }
679     else if (wcscmp(wszProperty,CP_CARD_READ_ONLY) == 0)
680     {
681 vletoux 8 if ( pbData == NULL )
682     {
683     Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
684     dwReturn = SCARD_E_INVALID_PARAMETER;
685     __leave;
686     }
687     dwReturn = SCARD_W_SECURITY_VIOLATION;
688 vletoux 1 }
689 vletoux 8 else if (wcscmp(wszProperty,CP_PARENT_WINDOW) == 0)
690 vletoux 1 {
691 vletoux 8 if ( pbData == NULL )
692     {
693     Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
694     dwReturn = SCARD_E_INVALID_PARAMETER;
695     __leave;
696     }
697     if ( cbDataLen != sizeof(HWND) )
698     {
699     Trace(WINEVENT_LEVEL_ERROR, L"cbDataLen == %d", cbDataLen);
700     dwReturn = SCARD_E_INVALID_PARAMETER ;
701     __leave;
702     }
703     if ( *pbData != 0 && !IsWindow((HWND) *pbData) )
704     {
705     Trace(WINEVENT_LEVEL_ERROR, L"*pbData == %d GetLastError == %d", *pbData, GetLastError());
706     dwReturn = SCARD_E_INVALID_PARAMETER ;
707     __leave;
708     }
709     dwReturn = 0;
710 vletoux 1 }
711 vletoux 8 else if (wcscmp(wszProperty,CP_PIN_CONTEXT_STRING) == 0)
712 vletoux 1 {
713 vletoux 8 if ( pbData == NULL )
714     {
715     Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
716     dwReturn = SCARD_E_INVALID_PARAMETER;
717     __leave;
718     }
719     dwReturn = 0;
720 vletoux 1 }
721     else
722     {
723 vletoux 8 Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s Unknown", wszProperty);
724 vletoux 1 dwReturn = SCARD_E_INVALID_PARAMETER;
725     __leave;
726     }
727     }
728     __finally
729     {
730     }
731     Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
732     return dwReturn;
733     }
734    

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26