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

Annotation of /trunk/OpenPGPminidriver/CardAndContainerProperties.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (hide annotations)
Thu Mar 18 16:03:39 2010 UTC (15 years, 1 month ago) by vletoux
File MIME type: text/plain
File size: 21771 byte(s)
first working & stable version
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 vletoux 11 pCardCapabilities->fCertificateCompression = TRUE;
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 vletoux 9 if (bContainerIndex >= ContainerMax)
128 vletoux 1 {
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 9 if(bContainerIndex >= ContainerMax)
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_PUK);
468     SET_PIN(*pPinSet, ROLE_ADMIN);
469 vletoux 1 }
470     else if (wcscmp(wszProperty,CP_CARD_AUTHENTICATED_STATE) == 0)
471     {
472 vletoux 8 if (dwFlags)
473     {
474     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
475     dwReturn = SCARD_E_INVALID_PARAMETER;
476     __leave;
477     }
478 vletoux 1 dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
479     }
480     else if (wcscmp(wszProperty,CP_CARD_PIN_STRENGTH_VERIFY) == 0)
481     {
482     PPIN_SET pPinSet;
483 vletoux 8 switch(dwFlags)
484     {
485     case ROLE_SIGNATURE:
486     case ROLE_AUTHENTICATION:
487     case ROLE_ADMIN:
488     case ROLE_PUK:
489     break;
490     default:
491     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
492     dwReturn = SCARD_E_INVALID_PARAMETER;
493     __leave;
494     }
495 vletoux 1 *pdwDataLen = sizeof(PIN_SET);
496     if (cbData < *pdwDataLen)
497     {
498     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
499     dwReturn = ERROR_INSUFFICIENT_BUFFER;
500     __leave;
501     }
502     pPinSet = (PPIN_SET) pbData;
503     *pPinSet = CARD_PIN_STRENGTH_PLAINTEXT;
504     }
505     else if (wcscmp(wszProperty,CP_KEY_IMPORT_SUPPORT) == 0)
506     {
507 vletoux 8 if (dwFlags)
508     {
509     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
510     dwReturn = SCARD_E_INVALID_PARAMETER;
511     __leave;
512     }
513 vletoux 1 *pdwDataLen = sizeof(DWORD);
514     if (cbData < *pdwDataLen)
515     {
516     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
517     dwReturn = ERROR_INSUFFICIENT_BUFFER;
518     __leave;
519     }
520 vletoux 8 if (pContext->fIsReadOnly)
521     {
522     *((PDWORD)pbData) = 0;
523     }
524     else
525     {
526     *((PDWORD)pbData) = CARD_KEY_IMPORT_RSA_KEYEST;
527     }
528 vletoux 1 }
529     else if (wcscmp(wszProperty,CP_ENUM_ALGORITHMS ) == 0)
530     {
531     if (dwFlags == CARD_CIPHER_OPERATION)
532     {
533     *pdwDataLen = sizeof(OPENPGP_SUPPORTED_CYPHER_ALGORITHM);
534     if (cbData < *pdwDataLen)
535     {
536     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
537     dwReturn = ERROR_INSUFFICIENT_BUFFER;
538     __leave;
539     }
540     memcpy(pbData,OPENPGP_SUPPORTED_CYPHER_ALGORITHM,*pdwDataLen);
541     }
542     else if (dwFlags == CARD_ASYMMETRIC_OPERATION )
543     {
544     *pdwDataLen = sizeof(OPENPGP_SUPPORTED_ASYMETRIC_ALGORITHM);
545     if (cbData < *pdwDataLen)
546     {
547     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
548     dwReturn = ERROR_INSUFFICIENT_BUFFER;
549     __leave;
550     }
551     memcpy(pbData,OPENPGP_SUPPORTED_ASYMETRIC_ALGORITHM,*pdwDataLen);
552     }
553     else
554     {
555     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
556     dwReturn = SCARD_E_INVALID_PARAMETER;
557     }
558     }
559     else if (wcscmp(wszProperty,CP_PADDING_SCHEMES ) == 0)
560     {
561     if (dwFlags == CARD_CIPHER_OPERATION)
562     {
563 vletoux 8 Trace(WINEVENT_LEVEL_ERROR, L"CARD_CIPHER_OPERATION", wszProperty);
564 vletoux 1 dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
565     }
566     else if (dwFlags == CARD_ASYMMETRIC_OPERATION )
567     {
568     *pdwDataLen = sizeof(DWORD);
569     if (cbData < *pdwDataLen)
570     {
571     Trace(WINEVENT_LEVEL_ERROR, L"cbData == %d", cbData);
572     dwReturn = ERROR_INSUFFICIENT_BUFFER;
573     __leave;
574     }
575     *((PDWORD)pbData) = CARD_PADDING_PKCS1;
576     }
577     else
578     {
579     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
580     dwReturn = SCARD_E_INVALID_PARAMETER;
581     }
582    
583     }
584     else if (wcscmp(wszProperty,CP_CHAINING_MODES ) == 0)
585     {
586 vletoux 8 if (dwFlags)
587     {
588     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
589     dwReturn = SCARD_E_INVALID_PARAMETER;
590     __leave;
591     }
592     Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s", wszProperty);
593 vletoux 1 dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
594     }
595 vletoux 8 else if ( wcscmp(wszProperty,CP_CARD_PIN_STRENGTH_CHANGE ) == 0
596     || wcscmp(wszProperty,CP_CARD_PIN_STRENGTH_UNBLOCK ) == 0)
597     {
598     Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s SCARD_E_UNSUPPORTED_FEATURE", wszProperty);
599     dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
600     }
601 vletoux 1 else
602     {
603 vletoux 8 Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s SCARD_E_INVALID_PARAMETER", wszProperty);
604 vletoux 1 dwReturn = SCARD_E_INVALID_PARAMETER;
605     __leave;
606     }
607     }
608     __finally
609     {
610     if (pbTempData)
611     {
612     pCardData->pfnCspFree(pbTempData);
613     }
614     }
615     Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
616     return dwReturn;
617     }
618    
619     /** This function can be used to set properties on the card.*/
620    
621     DWORD WINAPI CardSetProperty(
622     __in PCARD_DATA pCardData,
623     __in LPCWSTR wszProperty,
624     __in_bcount(cbDataLen) PBYTE pbData,
625     __in DWORD cbDataLen,
626     __in DWORD dwFlags
627     )
628     {
629     DWORD dwReturn = 0;
630 vletoux 10 POPENPGP_CONTEXT pContext = NULL;
631 vletoux 1 Trace(WINEVENT_LEVEL_VERBOSE, L"Enter wszProperty = %s", wszProperty);
632     __try
633     {
634     if ( pCardData == NULL )
635     {
636     Trace(WINEVENT_LEVEL_ERROR, L"pCardData == NULL");
637     dwReturn = SCARD_E_INVALID_PARAMETER;
638     __leave;
639     }
640     if ( wszProperty == NULL )
641     {
642     Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == NULL");
643     dwReturn = SCARD_E_INVALID_PARAMETER;
644     __leave;
645     }
646 vletoux 10 dwReturn = CheckContext(pCardData);
647     if (dwReturn)
648     {
649     __leave;
650     }
651     pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
652 vletoux 1 if (wcscmp(wszProperty,CP_CARD_FREE_SPACE) == 0
653     || wcscmp(wszProperty,CP_CARD_CAPABILITIES) == 0
654     || wcscmp(wszProperty,CP_CARD_KEYSIZES) == 0
655     || wcscmp(wszProperty,CP_CARD_LIST_PINS) == 0
656     || wcscmp(wszProperty,CP_CARD_AUTHENTICATED_STATE) == 0
657     || wcscmp(wszProperty,CP_KEY_IMPORT_SUPPORT) == 0
658     || wcscmp(wszProperty,CP_ENUM_ALGORITHMS) == 0
659     || wcscmp(wszProperty,CP_PADDING_SCHEMES) == 0
660 vletoux 8 || wcscmp(wszProperty,CP_CHAINING_MODES) == 0
661     || wcscmp(wszProperty,CP_SUPPORTS_WIN_X509_ENROLLMENT) == 0
662     || wcscmp(wszProperty,CP_CARD_CACHE_MODE) == 0
663     || wcscmp(wszProperty,CP_CARD_SERIAL_NO) == 0
664 vletoux 9 || wcscmp(wszProperty,CP_CARD_GUID) == 0)
665     {
666     if (dwFlags)
667     {
668     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
669     dwReturn = SCARD_E_INVALID_PARAMETER;
670     __leave;
671     }
672     if ( pbData == NULL )
673     {
674     Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
675     dwReturn = SCARD_E_INVALID_PARAMETER;
676     __leave;
677     }
678     Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s SCARD_E_UNSUPPORTED_FEATURE", wszProperty);
679     dwReturn = SCARD_E_UNSUPPORTED_FEATURE ;
680     __leave;
681     }
682     else if (wcscmp(wszProperty,CP_CARD_PIN_INFO) == 0
683 vletoux 8 || wcscmp(wszProperty,CP_CARD_PIN_STRENGTH_VERIFY) == 0)
684 vletoux 1 {
685 vletoux 9 if (dwFlags > ContainerMax)
686     {
687     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
688     dwReturn = SCARD_E_INVALID_PARAMETER;
689     __leave;
690     }
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 vletoux 1 Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s SCARD_E_UNSUPPORTED_FEATURE", wszProperty);
698     dwReturn = SCARD_E_UNSUPPORTED_FEATURE ;
699     __leave;
700     }
701     else if (wcscmp(wszProperty,CP_CARD_READ_ONLY) == 0)
702     {
703 vletoux 9 if (dwFlags)
704     {
705     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
706     dwReturn = SCARD_E_INVALID_PARAMETER;
707     __leave;
708     }
709 vletoux 8 if ( pbData == NULL )
710     {
711     Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
712     dwReturn = SCARD_E_INVALID_PARAMETER;
713     __leave;
714     }
715 vletoux 10 if ( cbDataLen != sizeof(BOOL) )
716     {
717     Trace(WINEVENT_LEVEL_ERROR, L"cbDataLen == %d", cbDataLen);
718     dwReturn = SCARD_E_INVALID_PARAMETER ;
719     __leave;
720     }
721     if (pContext->fDoesTheAdminHasBeenAuthenticatedAtLeastOnce)
722     {
723     pContext->fIsReadOnly = *((PBOOL) pbData);
724     dwReturn = 0;
725     }
726     else
727     {
728     dwReturn = SCARD_W_SECURITY_VIOLATION;
729     }
730 vletoux 1 }
731 vletoux 8 else if (wcscmp(wszProperty,CP_PARENT_WINDOW) == 0)
732 vletoux 1 {
733 vletoux 9 if (dwFlags)
734     {
735     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
736     dwReturn = SCARD_E_INVALID_PARAMETER;
737     __leave;
738     }
739 vletoux 8 if ( pbData == NULL )
740     {
741     Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
742     dwReturn = SCARD_E_INVALID_PARAMETER;
743     __leave;
744     }
745     if ( cbDataLen != sizeof(HWND) )
746     {
747     Trace(WINEVENT_LEVEL_ERROR, L"cbDataLen == %d", cbDataLen);
748     dwReturn = SCARD_E_INVALID_PARAMETER ;
749     __leave;
750     }
751 vletoux 10 if ( *((HWND*)pbData) != 0)
752 vletoux 8 {
753 vletoux 9 if (IsWindow( *((HWND*)pbData)) == 0)
754     {
755     Trace(WINEVENT_LEVEL_ERROR, L"*pbData == %d GetLastError == %d", *((HWND*)pbData), GetLastError());
756     dwReturn = SCARD_E_INVALID_PARAMETER ;
757     __leave;
758     }
759 vletoux 8 }
760 vletoux 9 Trace(WINEVENT_LEVEL_VERBOSE, L"CP_PARENT_WINDOW = %d", *((HWND*)pbData));
761 vletoux 8 dwReturn = 0;
762 vletoux 1 }
763 vletoux 8 else if (wcscmp(wszProperty,CP_PIN_CONTEXT_STRING) == 0)
764 vletoux 1 {
765 vletoux 9 if (dwFlags)
766 vletoux 8 {
767 vletoux 9 Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
768 vletoux 8 dwReturn = SCARD_E_INVALID_PARAMETER;
769     __leave;
770     }
771     dwReturn = 0;
772 vletoux 1 }
773     else
774     {
775 vletoux 8 Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s Unknown", wszProperty);
776 vletoux 1 dwReturn = SCARD_E_INVALID_PARAMETER;
777     __leave;
778     }
779     }
780     __finally
781     {
782     }
783     Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
784     return dwReturn;
785     }
786    

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26