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 |
POPENPGP_CONTEXT pContext = NULL; |
38 |
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 |
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 |
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 |
if ( pbData == NULL ) |
104 |
{ |
105 |
Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL"); |
106 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
107 |
__leave; |
108 |
} |
109 |
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 >= ContainerMax) |
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 |
if(bContainerIndex >= ContainerMax) |
154 |
{ |
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 |
POPENPGP_CONTEXT pContext = NULL; |
264 |
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 |
if ( pbData == NULL ) |
280 |
{ |
281 |
Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL"); |
282 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
283 |
__leave; |
284 |
} |
285 |
if ( pdwDataLen == NULL ) |
286 |
{ |
287 |
Trace(WINEVENT_LEVEL_ERROR, L"pdwDataLen == NULL"); |
288 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
289 |
__leave; |
290 |
} |
291 |
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 |
if (wcscmp(wszProperty,CP_CARD_FREE_SPACE) == 0) |
300 |
{ |
301 |
if (dwFlags) |
302 |
{ |
303 |
Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0"); |
304 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
305 |
__leave; |
306 |
} |
307 |
*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 |
if (dwFlags) |
319 |
{ |
320 |
Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0"); |
321 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
322 |
__leave; |
323 |
} |
324 |
*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 |
if (dwFlags) |
347 |
{ |
348 |
Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0"); |
349 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
350 |
__leave; |
351 |
} |
352 |
*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 |
*((PBOOL)pbData) = pContext->fIsReadOnly; |
360 |
} |
361 |
else if (wcscmp(wszProperty,CP_CARD_CACHE_MODE) == 0) |
362 |
{ |
363 |
if (dwFlags) |
364 |
{ |
365 |
Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0"); |
366 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
367 |
__leave; |
368 |
} |
369 |
*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 |
if (dwFlags) |
381 |
{ |
382 |
Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0"); |
383 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
384 |
__leave; |
385 |
} |
386 |
*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 |
if (dwFlags) |
398 |
{ |
399 |
Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0"); |
400 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
401 |
__leave; |
402 |
} |
403 |
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 |
if (dwFlags) |
420 |
{ |
421 |
Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0"); |
422 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
423 |
__leave; |
424 |
} |
425 |
*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 |
if (dwFlags) |
452 |
{ |
453 |
Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0"); |
454 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
455 |
__leave; |
456 |
} |
457 |
*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 |
*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 |
} |
471 |
else if (wcscmp(wszProperty,CP_CARD_AUTHENTICATED_STATE) == 0) |
472 |
{ |
473 |
if (dwFlags) |
474 |
{ |
475 |
Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0"); |
476 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
477 |
__leave; |
478 |
} |
479 |
dwReturn = SCARD_E_UNSUPPORTED_FEATURE; |
480 |
} |
481 |
else if (wcscmp(wszProperty,CP_CARD_PIN_STRENGTH_VERIFY) == 0) |
482 |
{ |
483 |
PPIN_SET pPinSet; |
484 |
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 |
*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 |
if (dwFlags) |
510 |
{ |
511 |
Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0"); |
512 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
513 |
__leave; |
514 |
} |
515 |
*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 |
if (pContext->fIsReadOnly) |
523 |
{ |
524 |
*((PDWORD)pbData) = 0; |
525 |
} |
526 |
else |
527 |
{ |
528 |
*((PDWORD)pbData) = CARD_KEY_IMPORT_RSA_KEYEST; |
529 |
} |
530 |
} |
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 |
Trace(WINEVENT_LEVEL_ERROR, L"CARD_CIPHER_OPERATION", wszProperty); |
566 |
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 |
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 |
dwReturn = SCARD_E_UNSUPPORTED_FEATURE; |
596 |
} |
597 |
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 |
else |
604 |
{ |
605 |
Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s SCARD_E_INVALID_PARAMETER", wszProperty); |
606 |
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 |
POPENPGP_CONTEXT pContext = NULL; |
633 |
Trace(WINEVENT_LEVEL_VERBOSE, L"Enter wszProperty = %s", wszProperty); |
634 |
__try |
635 |
{ |
636 |
if ( pCardData == NULL ) |
637 |
{ |
638 |
Trace(WINEVENT_LEVEL_ERROR, L"pCardData == NULL"); |
639 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
640 |
__leave; |
641 |
} |
642 |
if ( wszProperty == NULL ) |
643 |
{ |
644 |
Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == NULL"); |
645 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
646 |
__leave; |
647 |
} |
648 |
dwReturn = CheckContext(pCardData); |
649 |
if (dwReturn) |
650 |
{ |
651 |
__leave; |
652 |
} |
653 |
pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific; |
654 |
if (wcscmp(wszProperty,CP_CARD_FREE_SPACE) == 0 |
655 |
|| wcscmp(wszProperty,CP_CARD_CAPABILITIES) == 0 |
656 |
|| wcscmp(wszProperty,CP_CARD_KEYSIZES) == 0 |
657 |
|| wcscmp(wszProperty,CP_CARD_LIST_PINS) == 0 |
658 |
|| wcscmp(wszProperty,CP_CARD_AUTHENTICATED_STATE) == 0 |
659 |
|| wcscmp(wszProperty,CP_KEY_IMPORT_SUPPORT) == 0 |
660 |
|| wcscmp(wszProperty,CP_ENUM_ALGORITHMS) == 0 |
661 |
|| wcscmp(wszProperty,CP_PADDING_SCHEMES) == 0 |
662 |
|| wcscmp(wszProperty,CP_CHAINING_MODES) == 0 |
663 |
|| wcscmp(wszProperty,CP_SUPPORTS_WIN_X509_ENROLLMENT) == 0 |
664 |
|| wcscmp(wszProperty,CP_CARD_CACHE_MODE) == 0 |
665 |
|| wcscmp(wszProperty,CP_CARD_SERIAL_NO) == 0 |
666 |
|| wcscmp(wszProperty,CP_CARD_GUID) == 0) |
667 |
{ |
668 |
if (dwFlags) |
669 |
{ |
670 |
Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags); |
671 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
672 |
__leave; |
673 |
} |
674 |
if ( pbData == NULL ) |
675 |
{ |
676 |
Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL"); |
677 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
678 |
__leave; |
679 |
} |
680 |
Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s SCARD_E_UNSUPPORTED_FEATURE", wszProperty); |
681 |
dwReturn = SCARD_E_UNSUPPORTED_FEATURE ; |
682 |
__leave; |
683 |
} |
684 |
else if (wcscmp(wszProperty,CP_CARD_PIN_INFO) == 0 |
685 |
|| wcscmp(wszProperty,CP_CARD_PIN_STRENGTH_VERIFY) == 0) |
686 |
{ |
687 |
if (dwFlags > ContainerMax) |
688 |
{ |
689 |
Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags); |
690 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
691 |
__leave; |
692 |
} |
693 |
if ( pbData == NULL ) |
694 |
{ |
695 |
Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL"); |
696 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
697 |
__leave; |
698 |
} |
699 |
Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s SCARD_E_UNSUPPORTED_FEATURE", wszProperty); |
700 |
dwReturn = SCARD_E_UNSUPPORTED_FEATURE ; |
701 |
__leave; |
702 |
} |
703 |
else if (wcscmp(wszProperty,CP_CARD_READ_ONLY) == 0) |
704 |
{ |
705 |
if (dwFlags) |
706 |
{ |
707 |
Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags); |
708 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
709 |
__leave; |
710 |
} |
711 |
if ( pbData == NULL ) |
712 |
{ |
713 |
Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL"); |
714 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
715 |
__leave; |
716 |
} |
717 |
if ( cbDataLen != sizeof(BOOL) ) |
718 |
{ |
719 |
Trace(WINEVENT_LEVEL_ERROR, L"cbDataLen == %d", cbDataLen); |
720 |
dwReturn = SCARD_E_INVALID_PARAMETER ; |
721 |
__leave; |
722 |
} |
723 |
if (pContext->fDoesTheAdminHasBeenAuthenticatedAtLeastOnce) |
724 |
{ |
725 |
pContext->fIsReadOnly = *((PBOOL) pbData); |
726 |
dwReturn = 0; |
727 |
} |
728 |
else |
729 |
{ |
730 |
dwReturn = SCARD_W_SECURITY_VIOLATION; |
731 |
} |
732 |
} |
733 |
else if (wcscmp(wszProperty,CP_PARENT_WINDOW) == 0) |
734 |
{ |
735 |
if (dwFlags) |
736 |
{ |
737 |
Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags); |
738 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
739 |
__leave; |
740 |
} |
741 |
if ( pbData == NULL ) |
742 |
{ |
743 |
Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL"); |
744 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
745 |
__leave; |
746 |
} |
747 |
if ( cbDataLen != sizeof(HWND) ) |
748 |
{ |
749 |
Trace(WINEVENT_LEVEL_ERROR, L"cbDataLen == %d", cbDataLen); |
750 |
dwReturn = SCARD_E_INVALID_PARAMETER ; |
751 |
__leave; |
752 |
} |
753 |
if ( *((HWND*)pbData) != 0) |
754 |
{ |
755 |
if (IsWindow( *((HWND*)pbData)) == 0) |
756 |
{ |
757 |
Trace(WINEVENT_LEVEL_ERROR, L"*pbData == %d GetLastError == %d", *((HWND*)pbData), GetLastError()); |
758 |
dwReturn = SCARD_E_INVALID_PARAMETER ; |
759 |
__leave; |
760 |
} |
761 |
} |
762 |
Trace(WINEVENT_LEVEL_VERBOSE, L"CP_PARENT_WINDOW = %d", *((HWND*)pbData)); |
763 |
dwReturn = 0; |
764 |
} |
765 |
else if (wcscmp(wszProperty,CP_PIN_CONTEXT_STRING) == 0) |
766 |
{ |
767 |
if (dwFlags) |
768 |
{ |
769 |
Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags); |
770 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
771 |
__leave; |
772 |
} |
773 |
dwReturn = 0; |
774 |
} |
775 |
else |
776 |
{ |
777 |
Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s Unknown", wszProperty); |
778 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
779 |
__leave; |
780 |
} |
781 |
} |
782 |
__finally |
783 |
{ |
784 |
} |
785 |
Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn); |
786 |
return dwReturn; |
787 |
} |
788 |
|