Changeset 44cf3d0 in OpenSC
- Timestamp:
- 04/12/11 07:40:12 (14 months ago)
- Branches:
- master, staging
- Children:
- 7c17247
- Parents:
- 577ccdbf
- git-author:
- martin <martin@…> (04/12/11 07:40:12)
- git-committer:
- martin <martin@…> (04/12/11 07:40:12)
- Files:
-
- 1 added
- 1 deleted
- 9 edited
- 5 moved
-
configure.ac (modified) (6 diffs)
-
etc/opensc.conf.in (modified) (2 diffs)
-
src/Makefile.am (modified) (1 diff)
-
src/Makefile.mak (modified) (1 diff)
-
src/cardmod/Makefile.am (deleted)
-
src/libopensc/ctx.c (modified) (2 diffs)
-
src/libopensc/opensc.h (modified) (1 diff)
-
src/libopensc/reader-pcsc.c (modified) (1 diff)
-
src/minidriver/Makefile.am (added)
-
src/minidriver/Makefile.mak (moved) (moved from src/cardmod/Makefile.mak) (2 diffs)
-
src/minidriver/minidriver-westcos.reg (moved) (moved from src/cardmod/cardmod-westcos.reg) (1 diff)
-
src/minidriver/minidriver.c (moved) (moved from src/cardmod/cardmod.c) (119 diffs)
-
src/minidriver/minidriver.exports (moved) (moved from src/cardmod/cardmod.exports)
-
src/minidriver/opensc-minidriver.inf.in (moved) (moved from src/cardmod/cardmod.inf.in) (1 diff)
-
win32/Make.rules.mak (modified) (1 diff)
-
win32/OpenSC.wxs.in (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
configure.ac
rdb3ebb1 r44cf3d0 129 129 130 130 AC_ARG_ENABLE( 131 [ cardmod],132 [AS_HELP_STRING([--enable- cardmod],[enable cardmod moduleon Windows @<:@disabled@:>@])],133 , 134 [enable_ cardmod="no"]131 [minidriver], 132 [AS_HELP_STRING([--enable-minidriver],[enable minidriver on Windows @<:@disabled@:>@])], 133 , 134 [enable_minidriver="no"] 135 135 ) 136 136 … … 294 294 fi 295 295 296 if test "${enable_ cardmod}" = "yes"; then296 if test "${enable_minidriver}" = "yes"; then 297 297 dnl win32 special test for minidriver 298 298 AC_CHECK_HEADER( 299 299 [cardmod.h], 300 300 , 301 [AC_MSG_ERROR([cardmod.h is not found and required for cardmod])]301 [AC_MSG_ERROR([cardmod.h is not found and required for minidriver])] 302 302 ) 303 AC_DEFINE([ENABLE_ CARDMOD], [1], [Enable cardmodsupport])303 AC_DEFINE([ENABLE_MINIDRIVER], [1], [Enable minidriver support]) 304 304 fi 305 305 … … 523 523 if test "${enable_ctapi}" = "yes"; then 524 524 OPENSC_FEATURES="${OPENSC_FEATURES} ctapi" 525 fi526 if test "${enable_cardmod}" = "yes"; then527 OPENSC_FEATURES="${OPENSC_FEATURES} cardmod"528 525 fi 529 526 … … 565 562 AM_CONDITIONAL([WIN32], [test "${WIN32}" = "yes"]) 566 563 AM_CONDITIONAL([CYGWIN], [test "${CYGWIN}" = "yes"]) 567 AM_CONDITIONAL([ENABLE_ CARDMOD], [test "${enable_cardmod}" = "yes"])564 AM_CONDITIONAL([ENABLE_MINIDRIVER], [test "${enable_minidriver}" = "yes"]) 568 565 569 566 if test "${enable_pedantic}" = "yes"; then … … 593 590 src/tests/regression/Makefile 594 591 src/tools/Makefile 595 src/ cardmod/Makefile596 src/ cardmod/cardmod.inf592 src/minidriver/Makefile 593 src/minidriver/opensc-minidriver.inf 597 594 win32/Makefile 598 595 win32/versioninfo.rc … … 621 618 OpenCT support: ${enable_openct} 622 619 CT-API support: ${enable_ctapi} 623 cardmod support: ${enable_cardmod}620 minidriver support: ${enable_minidriver} 624 621 625 622 PC/SC default provider: ${DEFAULT_PCSC_PROVIDER} -
etc/opensc.conf.in
r69c846f r44cf3d0 448 448 } 449 449 450 # XXX: remove cardmod pseudodriver 450 451 app cardmod { 451 452 # cardmod app name use special pcsc reader subset … … 458 459 } 459 460 } 460 -
src/Makefile.am
rd22a248 r44cf3d0 4 4 # Order IS important 5 5 SUBDIRS = common scconf pkcs15init libopensc pkcs11 \ 6 tools tests cardmod6 tools tests minidriver -
src/Makefile.mak
rc5b2b02 r44cf3d0 5 5 SUBDIRS = common scconf pkcs15init libopensc pkcs11 tools tests 6 6 7 !IF "$(MINIDRIVER_DEF)" == "/DENABLE_CARDMOD" 8 SUBDIRS = $(SUBDIRS) cardmod 9 !ENDIF 10 11 !IF "$(WIX_MSI_DEF)" == "/DBUILD_MSI" 12 SUBDIRS = $(SUBDIRS) "$(TOPDIR)\etc" 13 SUBDIRS = $(SUBDIRS) "$(TOPDIR)\win32\opensc-msi" 7 !IF "$(MINIDRIVER_DEF)" == "/DENABLE_MINIDRIVER" 8 SUBDIRS = $(SUBDIRS) minidriver 14 9 !ENDIF 15 10 -
src/libopensc/ctx.c
r383d6e8 r44cf3d0 655 655 #ifdef ENABLE_PCSC 656 656 ctx->reader_driver = sc_get_pcsc_driver(); 657 #ifdef ENABLE_CARDMOD 657 /* XXX: remove cardmod pseudoreader driver */ 658 #ifdef ENABLE_MINIDRIVER 658 659 if(strcmp(ctx->app_name, "cardmod") == 0) { 659 660 ctx->reader_driver = sc_get_cardmod_driver(); 660 661 } 661 #endif662 #endif 662 663 #elif ENABLE_CTAPI 663 664 ctx->reader_driver = sc_get_ctapi_driver(); … … 682 683 } 683 684 684 /* use by cardmodto pass in provided handles to reader-pcsc */685 int sc_ctx_use_reader(sc_context_t *ctx, void * pcsc_context_handle, void *pcsc_card_handle)685 /* Used by minidriver to pass in provided handles to reader-pcsc */ 686 int sc_ctx_use_reader(sc_context_t *ctx, void *pcsc_context_handle, void *pcsc_card_handle) 686 687 { 687 688 SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_NORMAL); -
src/libopensc/opensc.h
r69c846f r44cf3d0 389 389 /* Reset a reader */ 390 390 int (*reset)(struct sc_reader *, int); 391 /* used to pass in reader handles in cardmod mode*/392 int (*use_reader)(struct sc_context *ctx, void * pcsc_context_handle, void *pcsc_card_handle);391 /* Used to pass in PC/SC handles to minidriver */ 392 int (*use_reader)(struct sc_context *ctx, void *pcsc_context_handle, void *pcsc_card_handle); 393 393 }; 394 394 -
src/libopensc/reader-pcsc.c
rcd3012f r44cf3d0 1552 1552 } 1553 1553 1554 #ifdef ENABLE_ CARDMOD1554 #ifdef ENABLE_MINIDRIVER 1555 1555 1556 1556 #define SCARD_CLASS_SYSTEM 0x7fff -
src/minidriver/Makefile.mak
rc5b2b02 r44cf3d0 1 1 TOPDIR = ..\.. 2 2 3 TARGET = opensc- cardmod.dll4 OBJECTS = cardmod.obj3 TARGET = opensc-minidriver.dll 4 OBJECTS = opensc-minidriver.obj 5 5 6 6 !INCLUDE $(TOPDIR)\win32\Make.rules.mak … … 11 11 echo LIBRARY $* > $*.def 12 12 echo EXPORTS >> $*.def 13 type cardmod.exports >> $*.def13 type minidriver.exports >> $*.def 14 14 link /dll $(LINKFLAGS) /def:$*.def /out:$(TARGET) $(OBJECTS) ..\libopensc\opensc_a.lib $(ZLIB_LIB) $(OPENSSL_LIB) ..\common\libscdl.lib ws2_32.lib gdi32.lib advapi32.lib winscard.lib Crypt32.lib User32.lib 15 15 if EXIST $(TARGET).manifest mt -manifest $(TARGET).manifest -outputresource:$(TARGET);2 -
src/minidriver/minidriver-westcos.reg
r0e03c6d r44cf3d0 1 Windows Registry Editor Version 5.001 Windows Registry Editor Version 5.00 2 2 3 3 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\Calais\SmartCards\CEV WESTCOS] 4 "80000001"="opensc- cardmod.dll"4 "80000001"="opensc-minidriver.dll" 5 5 "ATR"=hex:3f,69,00,00,00,64,01,00,00,00,80,90,00 6 6 "ATRMask"=hex:ff,ff,ff,ff,ff,ff,ff,00,00,00,f0,ff,ff 7 7 "Crypto Provider"="Microsoft Base Smart Card Crypto Provider" 8 -
src/minidriver/minidriver.c
r6c1862e r44cf3d0 1 1 /* 2 * cardmod.c: card module support for opensc2 * minidriver.c: OpenSC minidriver 3 3 * 4 * Copyright (C) 2009,2010 francois.leblanc@cev-sa.com 4 * Copyright (C) 2009,2010 francois.leblanc@cev-sa.com 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 20 20 21 21 /* 22 * This module require "cardmod.h" from CNG SDK or plattform SDK to 23 * be build. 22 * This module requires "cardmod.h" from CNG SDK or platform SDK to build. 24 23 */ 24 25 #include "config.h" 26 #ifdef ENABLE_MINIDRIVER 25 27 26 28 #ifdef _MANAGED 27 29 #pragma managed(push, off) 28 30 #endif 29 30 #include "config.h"31 31 32 32 #include <stdio.h> … … 64 64 { 65 65 char *pin; 66 66 67 67 sc_pkcs15_object_t *cert_objs[32]; 68 68 int cert_count; … … 71 71 sc_pkcs15_object_t *pin_objs[8]; 72 72 int pin_count; 73 73 74 74 sc_context_t *ctx; 75 75 sc_reader_t *reader; … … 86 86 SCARDCONTEXT hSCardCtx; 87 87 SCARDHANDLE hScard; 88 88 89 89 }VENDOR_SPECIFIC; 90 90 … … 98 98 /* #define CARDMOD_LOW_LEVEL_DEBUG 1 */ 99 99 #ifdef CARDMOD_LOW_LEVEL_DEBUG 100 /* Use a simplied log to get all messages including messages 100 /* Use a simplied log to get all messages including messages 101 101 * before opensc is loaded. The file must be modifiable by all 102 * users as we maybe called under lsa or user. Note data from 102 * users as we maybe called under lsa or user. Note data from 103 103 * multiple process and threads may get intermingled. 104 104 * flush to get last message before ann crash … … 119 119 return; 120 120 } 121 #endif 121 #endif 122 122 123 123 va_start(arg, format); … … 140 140 } 141 141 va_end(arg); 142 } 142 } 143 143 144 144 static void loghex(PCARD_DATA pCardData, int level, PBYTE data, int len) … … 148 148 int i, a; 149 149 unsigned char * p; 150 150 151 151 logprintf(pCardData, level, "--- %p:%d\n", data, len); 152 152 … … 176 176 if (i%32 != 0) 177 177 logprintf(pCardData, level, " %04X %s\n", a, line); 178 } 178 } 179 179 180 static void print_werror(PCARD_DATA pCardData, char *str) 180 181 { … … 191 192 192 193 /* 193 * check if the card has been removed, or the 194 * check if the card has been removed, or the 194 195 * caller has changed the handles. 195 196 * if so, then free up all previous card info … … 205 206 if(!pCardData) 206 207 return SCARD_E_INVALID_PARAMETER; 207 208 208 209 vs = (VENDOR_SPECIFIC*)(pCardData->pvVendorSpecific); 209 210 if(!vs) … … 212 213 logprintf(pCardData, 7, "pCardData->hSCardCtx:0x%08X hScard:0x%08X\n", 213 214 pCardData->hSCardCtx, pCardData->hScard); 214 215 216 if (pCardData->hSCardCtx != vs->hSCardCtx 215 216 if (pCardData->hSCardCtx != vs->hSCardCtx 217 217 || pCardData->hScard != vs->hScard) { 218 logprintf (pCardData, 1, "HANDLES CHANGED from 0x%08X 0x%08X\n", vs->hSCardCtx, vs->hScard); 218 logprintf (pCardData, 1, "HANDLES CHANGED from 0x%08X 0x%08X\n", vs->hSCardCtx, vs->hScard); 219 219 220 220 r = disassociate_card(pCardData); … … 222 222 r = associate_card(pCardData); /* need to check return codes */ 223 223 logprintf(pCardData, 1, "associate_card r = 0x%08X\n"); 224 225 224 } else 226 225 … … 229 228 r = sc_detect_card_presence(vs->reader); 230 229 logprintf(pCardData, 2, "check_reader_status r=%d flags 0x%08X\n", 231 r, vs->reader->flags); 230 r, vs->reader->flags); 232 231 } 233 232 return SCARD_S_SUCCESS; … … 256 255 int i; 257 256 258 if (!pCardData) 257 if (!pCardData) 259 258 return SCARD_E_INVALID_PARAMETER; 260 259 … … 328 327 loghex(pCardData, 5, prkey_info->subject.value, prkey_info->subject.len); 329 328 } 330 329 331 330 for(i = 0; i < vs->cert_count; i++) 332 331 { … … 337 336 sc_pkcs15_free_certificate(cert); 338 337 } 339 338 340 339 for(i = 0; i < vs->pin_count; i++) 341 340 { 342 const char *pin_flags[] = 341 const char *pin_flags[] = 343 342 { 344 343 "case-sensitive", "local", "change-disabled", … … 349 348 }; 350 349 const char *pin_types[] = {"bcd", "ascii-numeric", "UTF-8", 351 "halfnibble bcd", "iso 9664-1"}; 350 "halfnibble bcd", "iso 9664-1"}; 352 351 const struct sc_pkcs15_object *obj = vs->pin_objs[i]; 353 352 const struct sc_pkcs15_pin_info *pin = (const struct sc_pkcs15_pin_info *) (obj->data); … … 391 390 392 391 vs = (VENDOR_SPECIFIC*)(pCardData->pvVendorSpecific); 393 392 394 393 if(!vs) 395 394 return SCARD_E_INVALID_PARAMETER; 396 395 397 396 disassociate_card(pCardData); 398 397 399 398 if(vs->ctx) 400 399 { … … 413 412 } 414 413 415 DWORD WINAPI CardQueryCapabilities(__in PCARD_DATA pCardData, 414 DWORD WINAPI CardQueryCapabilities(__in PCARD_DATA pCardData, 416 415 __in PCARD_CAPABILITIES pCardCapabilities) 417 416 { … … 426 425 && pCardCapabilities->dwVersion != 0) 427 426 return ERROR_REVISION_MISMATCH; 428 427 429 428 pCardCapabilities->dwVersion = CARD_CAPABILITIES_CURRENT_VERSION; 430 429 pCardCapabilities->fCertificateCompression = TRUE; … … 470 469 sc_pkcs15_cert_t *cert = NULL; 471 470 VENDOR_SPECIFIC *vs = NULL; 472 471 473 472 PUBKEYSTRUCT_BASE *oh = NULL; 474 473 PUBKEYSTRUCT_BASE *oh2 = NULL; … … 479 478 DWORD ret; 480 479 sc_pkcs15_pubkey_t *pubkey = NULL; 481 480 482 481 logprintf(pCardData, 1, "\nP:%d T:%d pCardData:%p ",GetCurrentProcessId(), GetCurrentThreadId(), pCardData); 483 482 logprintf(pCardData, 1, "CardGetContainerInfo bContainerIndex=%u, dwFlags=0x%08X, " \ … … 489 488 if (!pContainerInfo) SCARD_E_INVALID_PARAMETER; 490 489 if (dwFlags) return SCARD_E_INVALID_PARAMETER; 491 if (pContainerInfo->dwVersion < 0 492 || pContainerInfo->dwVersion > CONTAINER_INFO_CURRENT_VERSION) 490 if (pContainerInfo->dwVersion < 0 491 || pContainerInfo->dwVersion > CONTAINER_INFO_CURRENT_VERSION) 493 492 return ERROR_REVISION_MISMATCH; 494 493 495 494 vs = (VENDOR_SPECIFIC*)(pCardData->pvVendorSpecific); 496 495 497 496 check_reader_status(pCardData); 498 497 499 498 if(bContainerIndex>=vs->cert_count) 500 499 return SCARD_E_INVALID_PARAMETER; 501 500 502 501 r = sc_pkcs15_read_certificate(vs->p15card, \ 503 502 (struct sc_pkcs15_cert_info *)(vs->cert_objs[bContainerIndex]->data), \ … … 514 513 { 515 514 int modulus = compute_keybits(&(pubkey->u.rsa.modulus)); 516 515 517 516 PCCERT_CONTEXT cer = CertCreateCertificateContext(X509_ASN_ENCODING \ 518 517 | PKCS_7_ASN_ENCODING, cert->data, cert->data_len); … … 524 523 RSA_CSP_PUBLICKEYBLOB, pinf->PublicKey.pbData, \ 525 524 pinf->PublicKey.cbData , 0, oh, &sz); 526 sz2 = sz; 525 sz2 = sz; 527 526 528 527 oh = (PUBKEYSTRUCT_BASE*)pCardData->pfnCspAlloc(sz); … … 533 532 RSA_CSP_PUBLICKEYBLOB, pinf->PublicKey.pbData, \ 534 533 pinf->PublicKey.cbData , 0, oh, &sz); 535 534 536 535 oh->publickeystruc.aiKeyAlg = CALG_RSA_SIGN; 537 536 pContainerInfo->cbSigPublicKey = sz; … … 577 576 578 577 if(!pCardData) return SCARD_E_INVALID_PARAMETER; 579 578 580 579 vs = (VENDOR_SPECIFIC*)(pCardData->pvVendorSpecific); 581 580 … … 594 593 if (cbPin < 4 || cbPin > 12) return SCARD_W_WRONG_CHV; 595 594 596 if (wcscmp(wszCARD_USER_ADMIN,pwszUserId) == 0) 595 if (wcscmp(wszCARD_USER_ADMIN,pwszUserId) == 0) 597 596 { 598 597 return SCARD_W_WRONG_CHV; 599 598 } 600 599 601 600 wcstombs(type, pwszUserId, 100); 602 601 type[10] = 0; 603 602 604 603 logprintf(pCardData, 1, "CardAuthenticatePin %.20s, %d, %d\n", NULLSTR(type), \ 605 604 cbPin, (pcAttemptsRemaining==NULL?-2:*pcAttemptsRemaining)); 606 605 607 606 pin_obj = vs->pin_objs[0]; 608 607 r = sc_pkcs15_verify_pin(vs->p15card, pin_obj, (const u8 *) pbPin, cbPin); 609 if (r) 608 if (r) 610 609 { 611 610 logprintf(pCardData, 1, "PIN code verification failed: %s\n", sc_strerror(r)); 612 613 if(pcAttemptsRemaining) 611 612 if(pcAttemptsRemaining) 614 613 { 615 614 (*pcAttemptsRemaining) = -1; … … 617 616 return SCARD_W_WRONG_CHV; 618 617 } 619 618 620 619 logprintf(pCardData, 3, "Pin code correct.\n"); 621 620 622 621 SET_PIN(vs->cardFiles.file_cardcf.bPinsFreshness, ROLE_USER); 623 622 logprintf(pCardData, 3, "PinsFreshness = %d\n", 624 623 vs->cardFiles.file_cardcf.bPinsFreshness); 625 626 return SCARD_S_SUCCESS; 624 625 return SCARD_S_SUCCESS; 627 626 } 628 627 … … 684 683 logprintf(pCardData, 1, "\nP:%d T:%d pCardData:%p ",GetCurrentProcessId(), GetCurrentThreadId(), pCardData); 685 684 logprintf(pCardData, 1, "CardDeauthenticate%S %d\n", NULLWSTR(pwszUserId), 686 dwFlags); 685 dwFlags); 687 686 688 687 if(!pCardData) return SCARD_E_INVALID_PARAMETER; … … 763 762 if(pszDirectoryName == NULL) 764 763 { 765 if(strcmp(pszFileName, "cardid") == 0) 764 if(strcmp(pszFileName, "cardid") == 0) 766 765 { 767 766 *pcbData = strlen(vs->p15card->tokeninfo->serial_number) + 10; … … 771 770 return SCARD_E_NO_MEMORY; 772 771 } 773 772 774 773 strcpy(*ppbData, vs->p15card->tokeninfo->serial_number); 775 774 776 775 logprintf(pCardData, 7, "return cardid "); 777 776 loghex(pCardData, 7, *ppbData, *pcbData); … … 780 779 } 781 780 782 if(strcmp(pszFileName, "cardcf") == 0) 781 if(strcmp(pszFileName, "cardcf") == 0) 783 782 { 784 783 *pcbData = sizeof(vs->cardFiles.file_cardcf); … … 788 787 return SCARD_E_NO_MEMORY; 789 788 } 790 789 791 790 memcpy(*ppbData, &(vs->cardFiles.file_cardcf), *pcbData); 792 791 … … 798 797 799 798 } 800 799 801 800 if(pszDirectoryName != NULL && strcmp(pszDirectoryName, "mscp") == 0) 802 801 { … … 804 803 sc_pkcs15_cert_t *cert = NULL; 805 804 806 if(strcmp(pszFileName, "cmapfile") == 0) 805 if(strcmp(pszFileName, "cmapfile") == 0) 807 806 { 808 807 PCONTAINER_MAP_RECORD p; 809 808 sc_pkcs15_pubkey_t *pubkey = NULL; 810 809 811 810 *pcbData = 32*sizeof(CONTAINER_MAP_RECORD); 812 811 *ppbData = pCardData->pfnCspAlloc(*pcbData); … … 815 814 return SCARD_E_NO_MEMORY; 816 815 } 817 816 818 817 memset(*ppbData, 0, *pcbData); 819 818 820 819 for(i = 0, p = (PCONTAINER_MAP_RECORD)*ppbData; \ 821 820 i < vs->cert_count; i++,p++) … … 823 822 struct sc_pkcs15_cert_info *cert_info = (sc_pkcs15_cert_info_t *)vs->cert_objs[i]->data; 824 823 sc_pkcs15_cert_t *cert = NULL; 825 824 826 825 r = sc_pkcs15_read_certificate(vs->p15card, cert_info, &cert); 827 826 logprintf(pCardData, 2, "sc_pkcs15_read_certificate return %d\n", r); … … 835 834 struct sc_card *card = vs->p15card->card; 836 835 char guid[MAX_CONTAINER_NAME_LEN + 1]; 837 836 838 837 r = sc_pkcs15_get_guid(vs->p15card, vs->cert_objs[i], guid, sizeof(guid)); 839 838 if (r) … … 841 840 842 841 logprintf(pCardData, 7, "Guid=%s\n", guid); 843 842 844 843 mbstowcs(p->wszGuid, guid, MAX_CONTAINER_NAME_LEN + 1); 845 844 846 845 p->bFlags += CONTAINER_MAP_VALID_CONTAINER; 847 846 if(i == 0) … … 865 864 return SCARD_S_SUCCESS; 866 865 } 867 866 868 867 if(sscanf(pszFileName, "ksc%d", &n) <= 0) 869 868 { … … 873 872 } 874 873 } 875 874 876 875 logprintf(pCardData, 7, "n = %d\n", n); 877 876 878 877 if(n>=0 && n<vs->cert_count) 879 878 { 880 879 sc_pkcs15_cert_t *cert = NULL; 881 880 882 881 r = sc_pkcs15_read_certificate(vs->p15card, \ 883 882 (struct sc_pkcs15_cert_info *)(vs->cert_objs[n]->data), \ … … 888 887 return SCARD_E_FILE_NOT_FOUND; 889 888 } 890 889 891 890 *pcbData = cert->data_len; 892 891 *ppbData = pCardData->pfnCspAlloc(*pcbData); 893 892 894 893 if(*ppbData == NULL) 895 894 { … … 897 896 return SCARD_E_NO_MEMORY; 898 897 } 899 898 900 899 CopyMemory(*ppbData, cert->data, *pcbData); 901 900 … … 907 906 908 907 sc_pkcs15_free_certificate(cert); 909 908 910 909 return SCARD_S_SUCCESS; 911 910 } 912 911 } 913 912 914 913 logprintf(pCardData, 5, "File not found\n"); 915 914 return SCARD_E_FILE_NOT_FOUND; … … 928 927 if(!pCardData) 929 928 return SCARD_E_INVALID_PARAMETER; 930 929 931 930 if(pszDirectoryName == NULL) 932 931 { 933 if(strcmp(pszFileName, "cardcf") == 0) 932 if(strcmp(pszFileName, "cardcf") == 0) 934 933 { 935 934 logprintf(pCardData, 2, "write cardcf ok.\n"); … … 938 937 } 939 938 } 940 939 941 940 return SCARD_E_FILE_NOT_FOUND; 942 941 } … … 960 959 const char root_files[] = "cardapps\0cardcf\0cardid\0\0"; 961 960 const char mscp_files[] = "kxc00\0kxc01\0cmapfile\0\0"; 962 961 963 962 logprintf(pCardData, 1, "\nP:%d T:%d pCardData:%p ",GetCurrentProcessId(), GetCurrentThreadId(), pCardData); 964 963 logprintf(pCardData, 1, "CardEnumFiles\n"); 965 964 966 965 if (!pCardData) return SCARD_E_INVALID_PARAMETER; 967 966 if (!pmszFileNames) return SCARD_E_INVALID_PARAMETER; … … 969 968 if (dwFlags) return SCARD_E_INVALID_PARAMETER; 970 969 971 if (!pszDirectoryName || !strlen(pszDirectoryName)) 970 if (!pszDirectoryName || !strlen(pszDirectoryName)) 972 971 { 973 972 DWORD sz = sizeof(root_files) - 1; … … 979 978 return SCARD_S_SUCCESS; 980 979 } 981 if (strcmpi(pszDirectoryName,"mscp") == 0) 980 if (strcmpi(pszDirectoryName,"mscp") == 0) 982 981 { 983 982 DWORD sz = sizeof(mscp_files) - 1; … … 989 988 return SCARD_S_SUCCESS; 990 989 } 991 990 992 991 return SCARD_E_FILE_NOT_FOUND; 993 992 } … … 1008 1007 { 1009 1008 VENDOR_SPECIFIC *vs; 1010 1009 1011 1010 logprintf(pCardData, 1, "\nP:%d T:%d pCardData:%p ",GetCurrentProcessId(), GetCurrentThreadId(), pCardData); 1012 1011 logprintf(pCardData, 1, "CardQueryFreeSpace %X, dwFlags=%X, version=%X\n", \ … … 1022 1021 pCardFreeSpaceInfo->dwBytesAvailable = -1; 1023 1022 pCardFreeSpaceInfo->dwMaxKeyContainers = vs->cert_count; 1024 1023 1025 1024 pCardFreeSpaceInfo->dwKeyContainersAvailable = vs->cert_count; /*TODO should this be 0 */ 1026 1025 … … 1040 1039 if (!pCardData) return SCARD_E_INVALID_PARAMETER; 1041 1040 if (!pKeySizes) return SCARD_E_INVALID_PARAMETER; 1042 1041 1043 1042 pKeySizes->dwVersion = CARD_KEY_SIZES_CURRENT_VERSION; 1044 1043 pKeySizes->dwMinimumBitlen = 512; … … 1084 1083 1085 1084 if (!(pInfo->bContainerIndex < vs->cert_count)) 1086 { 1085 { 1087 1086 return SCARD_E_INVALID_PARAMETER; 1088 1087 } … … 1091 1090 cert_info = (struct sc_pkcs15_cert_info *) \ 1092 1091 (vs->cert_objs[pInfo->bContainerIndex]->data); 1093 1092 1094 1093 for(i = 0; i < vs->prkey_count; i++) 1095 { 1094 { 1096 1095 sc_pkcs15_object_t *obj = (sc_pkcs15_object_t *)vs->prkey_objs[i]; 1097 1096 if(sc_pkcs15_compare_id(&((struct sc_pkcs15_prkey_info *) obj->data)->id, &(cert_info->id))) … … 1107 1106 return SCARD_E_INVALID_PARAMETER; 1108 1107 } 1109 1108 1110 1109 prkey_info = (sc_pkcs15_prkey_info_t*)(vs->pkey->data); 1111 1110 1112 1111 1113 1112 /* input and output buffers are always the same size */ 1114 1113 pbuf = pCardData->pfnCspAlloc(pInfo->cbData); … … 1125 1124 for(ui = 0; ui < pInfo->cbData; ui++) pbuf[ui] = pInfo->pbData[pInfo->cbData-ui-1]; 1126 1125 1127 r = sc_pkcs15_decipher(vs->p15card, vs->pkey, 1126 r = sc_pkcs15_decipher(vs->p15card, vs->pkey, 1128 1127 opt_crypt_flags, pbuf, pInfo->cbData, pbuf2, pInfo->cbData); 1129 1128 logprintf(pCardData, 2, "sc_pkcs15_decipher return %d\n", r); … … 1132 1131 sc_strerror(r)); 1133 1132 } 1134 1133 1135 1134 /*inversion donnees */ 1136 1135 for(ui = 0; ui < pInfo->cbData; ui++) pInfo->pbData[ui] = pbuf2[pInfo->cbData-ui-1]; … … 1152 1151 int r, opt_crypt_flags = 0, opt_hash_flags = 0; 1153 1152 size_t dataToSignLen = sizeof(dataToSign); 1154 1153 1155 1154 logprintf(pCardData, 1, "\nP:%d T:%d pCardData:%p ",GetCurrentProcessId(), GetCurrentThreadId(), pCardData); 1156 1155 logprintf(pCardData, 1, "CardSignData\n"); … … 1163 1162 pInfo->dwVersion,pInfo->bContainerIndex ,pInfo->dwKeySpec, \ 1164 1163 pInfo->dwSigningFlags, pInfo->aiHashAlg); 1165 1164 1166 1165 logprintf(pCardData, 7, "pInfo->pbData(%i) ", pInfo->cbData); 1167 1166 loghex(pCardData, 7, pInfo->pbData, pInfo->cbData); … … 1174 1173 1175 1174 vs->pkey = NULL; 1176 1175 1177 1176 logprintf(pCardData, 2, "pInfo->dwVersion = %d\n", pInfo->dwVersion); 1178 1177 … … 1181 1180 dataToSignLen = pInfo->cbData; 1182 1181 1183 if (CARD_PADDING_INFO_PRESENT & pInfo->dwSigningFlags) 1182 if (CARD_PADDING_INFO_PRESENT & pInfo->dwSigningFlags) 1184 1183 { 1185 1184 BCRYPT_PKCS1_PADDING_INFO *pinf = (BCRYPT_PKCS1_PADDING_INFO *)pInfo->pPaddingInfo; 1186 if (CARD_PADDING_PKCS1 != pInfo->dwPaddingType) 1185 if (CARD_PADDING_PKCS1 != pInfo->dwPaddingType) 1187 1186 { 1188 1187 logprintf(pCardData, 0, "unsupported paddingtype\n"); 1189 1188 return SCARD_E_UNSUPPORTED_FEATURE; 1190 1189 } 1191 if (!pinf->pszAlgId) 1190 if (!pinf->pszAlgId) 1192 1191 { 1193 1192 /* hashAlg = CALG_SSL3_SHAMD5; */ … … 1195 1194 opt_hash_flags = SC_ALGORITHM_RSA_HASH_MD5_SHA1; 1196 1195 } 1197 else 1198 { 1199 1196 else 1197 { 1198 1200 1199 if (wcscmp(pinf->pszAlgId, L"MD5") == 0) opt_hash_flags = SC_ALGORITHM_RSA_HASH_MD5; 1201 1200 else if (wcscmp(pinf->pszAlgId, L"SHA1") == 0) opt_hash_flags = SC_ALGORITHM_RSA_HASH_SHA1; 1202 1201 else if (wcscmp(pinf->pszAlgId, L"SHAMD5") == 0) opt_hash_flags = SC_ALGORITHM_RSA_HASH_MD5_SHA1; 1203 else 1202 else 1204 1203 logprintf(pCardData, 0,"unknown AlgId %S\n",NULLWSTR(pinf->pszAlgId)); 1205 1204 } … … 1208 1207 { 1209 1208 logprintf(pCardData, 3, "CARD_PADDING_INFO_PRESENT not set\n"); 1210 1211 if (GET_ALG_CLASS(hashAlg) != ALG_CLASS_HASH) 1209 1210 if (GET_ALG_CLASS(hashAlg) != ALG_CLASS_HASH) 1212 1211 { 1213 1212 logprintf(pCardData, 0, "bogus aiHashAlg\n"); … … 1215 1214 } 1216 1215 1217 if (hashAlg == CALG_MD5) 1216 if (hashAlg == CALG_MD5) 1218 1217 opt_hash_flags = SC_ALGORITHM_RSA_HASH_MD5; 1219 else if (hashAlg == CALG_SHA1) 1218 else if (hashAlg == CALG_SHA1) 1220 1219 opt_hash_flags = SC_ALGORITHM_RSA_HASH_SHA1; 1221 1220 else if (hashAlg == CALG_SSL3_SHAMD5) … … 1226 1225 1227 1226 /* From sc-minidriver_specs_v7.docx pp.76: 1228 * 'The Base CSP/KSP performs the hashing operation on the data before passing it 1227 * 'The Base CSP/KSP performs the hashing operation on the data before passing it 1229 1228 * to CardSignData for signature.' 1230 * So, the SC_ALGORITHM_RSA_HASH_* flags should not be passed to pkcs15 library 1229 * So, the SC_ALGORITHM_RSA_HASH_* flags should not be passed to pkcs15 library 1231 1230 * when calculating the signature . 1232 1231 * 1233 1232 * From sc-minidriver_specs_v7.docx pp.76: 1234 * 'If the aiHashAlg member is nonzero, it specifies the hash algorithm’s object identifier (OID) 1233 * 'If the aiHashAlg member is nonzero, it specifies the hash algorithm’s object identifier (OID) 1235 1234 * that is encoded in the PKCS padding.' 1236 1235 * So, the digest info has be included into the data to be signed. … … 1247 1246 } 1248 1247 opt_crypt_flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE; 1249 1248 1250 1249 if(!(pInfo->bContainerIndex < vs->cert_count)) 1251 1250 { 1252 1251 return SCARD_E_INVALID_PARAMETER; 1253 1252 } 1254 1253 1255 1254 cert_info = (struct sc_pkcs15_cert_info *) \ 1256 1255 (vs->cert_objs[pInfo->bContainerIndex]->data); … … 1264 1263 pInfo->cbSignedData = prkey_info->modulus_length / 8; 1265 1264 logprintf(pCardData, 3, "pInfo->cbSignedData = %d\n", pInfo->cbSignedData); 1266 1265 1267 1266 if(!(pInfo->dwSigningFlags&CARD_BUFFER_SIZE_ONLY)) 1268 1267 { … … 1270 1269 BYTE *pbuf = NULL; 1271 1270 DWORD lg; 1272 1271 1273 1272 lg = pInfo->cbSignedData; 1274 1273 logprintf(pCardData, 3, "lg = %d\n", lg); 1275 1274 pbuf = pCardData->pfnCspAlloc(lg); 1276 if (!pbuf) 1275 if (!pbuf) 1277 1276 { 1278 1277 return SCARD_E_NO_MEMORY; 1279 1278 } 1280 1279 1281 1280 logprintf(pCardData, 7, "Data to sign: "); 1282 1281 loghex(pCardData, 7, dataToSign, dataToSignLen); 1283 1282 1284 1283 pInfo->pbSignedData = pCardData->pfnCspAlloc(pInfo->cbSignedData); 1285 if (!pInfo->pbSignedData) 1284 if (!pInfo->pbSignedData) 1286 1285 { 1287 1286 pCardData->pfnCspFree(pbuf); 1288 1287 return SCARD_E_NO_MEMORY; 1289 1288 } 1290 1289 1291 1290 r = sc_pkcs15_compute_signature(vs->p15card, vs->pkey, \ 1292 1291 opt_crypt_flags, dataToSign, dataToSignLen, pbuf, lg); … … 1299 1298 1300 1299 pInfo->cbSignedData = r; 1301 1300 1302 1301 /*inversion donnees*/ 1303 1302 for(i = 0; i < r; i++) pInfo->pbSignedData[i] = pbuf[r-i-1]; … … 1310 1309 logprintf(pCardData, 7, "pInfo->pbSignedData "); 1311 1310 loghex(pCardData, 7, pInfo->pbSignedData, pInfo->cbSignedData); 1312 1313 } 1314 1311 1312 } 1313 1315 1314 logprintf(pCardData, 3, "CardSignData, dwVersion=%u, name=%S, hScard=0x%08X," \ 1316 1315 "hSCardCtx=0x%08X\n", pCardData->dwVersion, \ … … 1382 1381 logprintf(pCardData, 1, "\nP:%d T:%d pCardData:%p ",GetCurrentProcessId(), GetCurrentThreadId(), pCardData); 1383 1382 logprintf(pCardData, 1, "CardAuthenticateEx\n"); 1384 1383 1385 1384 if (!pCardData) return SCARD_E_INVALID_PARAMETER; 1386 1385 1387 1386 logprintf(pCardData, 2, "CardAuthenticateEx: PinId=%u, dwFlags=0x%08X, cbPinData=%u, Attempts %s\n", 1388 1387 PinId,dwFlags,cbPinData,pcAttemptsRemaining ? "YES" : "NO"); … … 1395 1394 dwFlags == CARD_AUTHENTICATE_SESSION_PIN) 1396 1395 return SCARD_E_UNSUPPORTED_FEATURE; 1397 if (dwFlags && dwFlags != CARD_PIN_SILENT_CONTEXT) 1396 if (dwFlags && dwFlags != CARD_PIN_SILENT_CONTEXT) 1398 1397 return SCARD_E_INVALID_PARAMETER; 1399 1398 1400 1399 if (NULL == pbPinData) return SCARD_E_INVALID_PARAMETER; 1401 1400 1402 1401 if (PinId != ROLE_USER) return SCARD_E_INVALID_PARAMETER; 1403 1402 1404 1403 r = get_pin_by_role(pCardData, ROLE_USER, &pin_obj); 1405 1404 if (r != SCARD_S_SUCCESS) … … 1410 1409 1411 1410 r = sc_pkcs15_verify_pin(vs->p15card, pin_obj, (const u8 *) pbPinData, cbPinData); 1412 if (r) 1411 if (r) 1413 1412 { 1414 1413 logprintf(pCardData, 2, "PIN code verification failed: %s\n", sc_strerror(r)); 1415 1416 if(pcAttemptsRemaining) 1414 1415 if(pcAttemptsRemaining) 1417 1416 { 1418 1417 (*pcAttemptsRemaining) = -1; … … 1420 1419 return SCARD_W_WRONG_CHV; 1421 1420 } 1422 1421 1423 1422 logprintf(pCardData, 2, "Pin code correct.\n"); 1424 1423 1425 1424 SET_PIN(vs->cardFiles.file_cardcf.bPinsFreshness, ROLE_USER); 1426 1425 logprintf(pCardData, 7, "PinsFreshness = %d\n", … … 1454 1453 logprintf(pCardData, 1, "\nP:%d T:%d pCardData:%p ",GetCurrentProcessId(), GetCurrentThreadId(), pCardData); 1455 1454 logprintf(pCardData, 1, "CardDeauthenticateEx PinId=%d dwFlags=0x%08X\n",PinId, dwFlags); 1456 1455 1457 1456 if (!pCardData) return SCARD_E_INVALID_PARAMETER; 1458 1457 1459 1458 vs = (VENDOR_SPECIFIC*)(pCardData->pvVendorSpecific); 1460 1459 … … 1481 1480 1482 1481 check_reader_status(pCardData); 1483 1482 1484 1483 if (!pCardData) return SCARD_E_INVALID_PARAMETER; 1485 1484 logprintf(pCardData, 2, "CardGetContainerProperty bContainerIndex=%u, wszProperty=%S," \ … … 1495 1494 if (pdwDataLen) *pdwDataLen = sizeof(*p); 1496 1495 if (cbData >= sizeof(DWORD)) 1497 if (p->dwVersion != CONTAINER_INFO_CURRENT_VERSION && 1496 if (p->dwVersion != CONTAINER_INFO_CURRENT_VERSION && 1498 1497 p->dwVersion != 0 ) return ERROR_REVISION_MISMATCH; 1499 1498 if (cbData < sizeof(*p)) return ERROR_INSUFFICIENT_BUFFER; 1500 1499 return CardGetContainerInfo(pCardData,bContainerIndex,0,p); 1501 1500 } 1502 1503 if (wcscmp(CCP_PIN_IDENTIFIER,wszProperty) == 0) 1501 1502 if (wcscmp(CCP_PIN_IDENTIFIER,wszProperty) == 0) 1504 1503 { 1505 1504 PPIN_ID p = (PPIN_ID) pbData; … … 1510 1509 return SCARD_S_SUCCESS; 1511 1510 } 1512 1511 1513 1512 return SCARD_E_INVALID_PARAMETER; 1514 1513 } … … 1543 1542 if (!pbData) return SCARD_E_INVALID_PARAMETER; 1544 1543 if (!pdwDataLen) return SCARD_E_INVALID_PARAMETER; 1545 1544 1546 1545 vs = (VENDOR_SPECIFIC*)(pCardData->pvVendorSpecific); 1547 1546 … … 1553 1552 if (pdwDataLen) *pdwDataLen = sizeof(*pCardFreeSpaceInfo); 1554 1553 if (cbData < sizeof(*pCardFreeSpaceInfo)) return SCARD_E_NO_MEMORY; 1555 if (pCardFreeSpaceInfo->dwVersion > CARD_FREE_SPACE_INFO_CURRENT_VERSION ) 1554 if (pCardFreeSpaceInfo->dwVersion > CARD_FREE_SPACE_INFO_CURRENT_VERSION ) 1556 1555 return ERROR_REVISION_MISMATCH; 1557 1556 … … 1573 1572 if (pCardCapabilities->dwVersion != CARD_CAPABILITIES_CURRENT_VERSION && 1574 1573 pCardCapabilities->dwVersion != 0) return ERROR_REVISION_MISMATCH; 1575 1574 1576 1575 pCardCapabilities->dwVersion = CARD_CAPABILITIES_CURRENT_VERSION; 1577 1576 pCardCapabilities->fCertificateCompression = TRUE; … … 1590 1589 if (pKeySizes->dwVersion != CARD_KEY_SIZES_CURRENT_VERSION && 1591 1590 pKeySizes->dwVersion != 0) return ERROR_REVISION_MISMATCH; 1592 1591 1593 1592 pKeySizes->dwVersion = CARD_KEY_SIZES_CURRENT_VERSION; 1594 1593 pKeySizes->dwMinimumBitlen = 512; … … 1596 1595 pKeySizes->dwMaximumBitlen = 16384; 1597 1596 pKeySizes->dwIncrementalBitlen = 64; 1598 1597 1599 1598 logprintf(pCardData, 7, "pKeySizes "); 1600 1599 loghex(pCardData, 7, pbData, *pdwDataLen); 1601 1600 1602 1601 return SCARD_S_SUCCESS; 1603 1602 } … … 1635 1634 return SCARD_S_SUCCESS; 1636 1635 } 1637 if (wcscmp(CP_CARD_GUID,wszProperty) == 0) 1636 if (wcscmp(CP_CARD_GUID,wszProperty) == 0) 1638 1637 { 1639 1638 if (pdwDataLen) *pdwDataLen = sizeof(vs->cardFiles.file_cardid); … … 1652 1651 1653 1652 CopyMemory(pbData,vs->p15card->tokeninfo->serial_number,sizeof(vs->p15card->tokeninfo->serial_number)); 1654 1653 1655 1654 logprintf(pCardData, 7, "SerialNumber "); 1656 1655 loghex(pCardData, 7, pbData, *pdwDataLen); … … 1665 1664 p->PinType = AlphaNumericPinType; 1666 1665 p->dwFlags = 0; 1667 switch (dwFlags) 1666 switch (dwFlags) 1668 1667 { 1669 1668 case ROLE_USER: … … 1674 1673 p->PinCachePolicy.PinCachePolicyType = PinCacheNormal; 1675 1674 p->dwChangePermission = 0; 1676 p->dwUnblockPermission = 0; 1675 p->dwUnblockPermission = 0; 1677 1676 break; 1678 1677 default: … … 1683 1682 loghex(pCardData, 7, pbData, *pdwDataLen); 1684 1683 1685 1684 1686 1685 return SCARD_S_SUCCESS; 1687 1686 } … … 1694 1693 logprintf(pCardData, 7, "CARD_LIST_PINS "); 1695 1694 loghex(pCardData, 7, pbData, *pdwDataLen); 1696 1695 1697 1696 return SCARD_S_SUCCESS; 1698 1697 } … … 1739 1738 logprintf(pCardData, 1, "\nP:%d T:%d pCardData:%p ",GetCurrentProcessId(), GetCurrentThreadId(), pCardData); 1740 1739 logprintf(pCardData, 1, "CardSetProperty\n"); 1741 1740 1742 1741 if (!pCardData) return SCARD_E_INVALID_PARAMETER; 1743 1742 1744 1743 logprintf(pCardData, 2, "CardSetProperty wszProperty=%S, cbDataLen=%u, dwFlags=%u",\ 1745 1744 NULLWSTR(wszProperty),cbDataLen,dwFlags); … … 1755 1754 return SCARD_S_SUCCESS; 1756 1755 1757 if (wcscmp(CP_CARD_CACHE_MODE, wszProperty) == 0 || 1756 if (wcscmp(CP_CARD_CACHE_MODE, wszProperty) == 0 || 1758 1757 wcscmp(CP_SUPPORTS_WIN_X509_ENROLLMENT, wszProperty) == 0 || 1759 1758 wcscmp(CP_CARD_GUID, wszProperty) == 0 || … … 1766 1765 1767 1766 if (wcscmp(CP_PARENT_WINDOW, wszProperty) == 0) { 1768 if (cbDataLen != sizeof(DWORD)) 1767 if (cbDataLen != sizeof(DWORD)) 1769 1768 return SCARD_E_INVALID_PARAMETER; 1770 1769 else … … 1788 1787 DWORD suppliedVersion = 0; 1789 1788 u8 challenge[8]; 1790 1791 if (!pCardData) 1789 1790 if (!pCardData) 1792 1791 return SCARD_E_INVALID_PARAMETER; 1793 if (dwFlags) 1792 if (dwFlags) 1794 1793 return SCARD_E_INVALID_PARAMETER; 1795 1794 1796 1795 suppliedVersion = pCardData->dwVersion; 1797 1796 … … 1812 1811 vs->hScard = pCardData->hScard; 1813 1812 vs->hSCardCtx = pCardData->hSCardCtx; 1814 1813 1815 1814 /* The lowest supported version is 4. */ 1816 1815 if (pCardData->dwVersion < MINIMUM_VERSION_SUPPORTED) … … 1818 1817 return (DWORD) ERROR_REVISION_MISMATCH; 1819 1818 } 1820 1819 1821 1820 if( pCardData->hScard == 0) 1822 1821 { … … 1824 1823 return SCARD_E_INVALID_HANDLE; 1825 1824 } 1826 1825 1827 1826 logprintf(pCardData, 2, "request version pCardData->dwVersion = %d\n", pCardData->dwVersion); 1828 1827 … … 1835 1834 int r; 1836 1835 sc_context_param_t ctx_param; 1837 1836 1838 1837 vs->ctx = NULL; 1839 1838 1840 1839 logprintf(pCardData, 3, "create ctx\n"); 1841 1840 1842 1841 memset(&ctx_param, 0, sizeof(ctx_param)); 1843 1842 ctx_param.ver = 1; 1844 1843 ctx_param.app_name = "cardmod"; 1845 1844 1846 1845 r = sc_context_create(&(vs->ctx), &ctx_param); 1847 1846 logprintf(pCardData, 3, "sc_context_create passed r = %d\n", r); 1848 if (r) 1847 if (r) 1849 1848 { 1850 1849 logprintf(pCardData, 0, "Failed to establish context: %s\n", \ … … 1853 1852 } 1854 1853 } 1855 1854 1856 1855 pCardData->pfnCardDeleteContext = CardDeleteContext; 1857 1856 pCardData->pfnCardQueryCapabilities = CardQueryCapabilities; … … 1880 1879 pCardData->pfnCardRSADecrypt = CardRSADecrypt; 1881 1880 pCardData->pfnCardConstructDHAgreement = CardConstructDHAgreement; 1882 1881 1883 1882 associate_card(pCardData); 1884 1885 logprintf(pCardData, 1, "Open scinit done.\n");1883 1884 logprintf(pCardData, 1, "OpenSC init done.\n"); 1886 1885 1887 1886 if(sc_get_challenge(vs->p15card->card, challenge, sizeof(challenge))) … … 1895 1894 vs->cardFiles.file_cardcf.wFilesFreshness = challenge[3]*256+challenge[4]; 1896 1895 } 1897 1896 1898 1897 if (suppliedVersion > 4) { 1899 pCardData->pfnCardDeriveKey = CardDeriveKey; 1900 pCardData->pfnCardDestroyDHAgreement = CardDestroyDHAgreement; 1901 pCardData->pfnCspGetDHAgreement = CspGetDHAgreement; 1902 1898 pCardData->pfnCardDeriveKey = CardDeriveKey; 1899 pCardData->pfnCardDestroyDHAgreement = CardDestroyDHAgreement; 1900 pCardData->pfnCspGetDHAgreement = CspGetDHAgreement; 1901 1903 1902 if (suppliedVersion > 5 ) { 1904 1903 pCardData->pfnCardGetChallengeEx = CardGetChallengeEx; … … 1923 1922 BYTE empty_cardcf[6]={0,0,0,0,0,0}; 1924 1923 BYTE empty_cardid[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; 1925 1924 1926 1925 logprintf(pCardData, 1, "associate_card\n"); 1927 vs = (VENDOR_SPECIFIC*)(pCardData->pvVendorSpecific);1926 vs = (VENDOR_SPECIFIC*)(pCardData->pvVendorSpecific); 1928 1927 /* 1929 1928 * set the addresses of the reader and card handles 1930 * Our cardmod pcsc code will use these when we call sc_ctx_use_reader 1929 * Our cardmod pcsc code will use these when we call sc_ctx_use_reader 1931 1930 * We use the address of the handles as provided in the pCardData 1932 1931 */ … … 1941 1940 logprintf(pCardData, 5, "cardmod_use_handles %d\n", \ 1942 1941 sc_ctx_use_reader(vs->ctx, &vs->hSCardCtx, &vs->hScard)); 1943 1942 1944 1943 /* should be only one reader */ 1945 1944 logprintf(pCardData, 5, "sc_ctx_get_reader_count(ctx): %d\n", \ … … 1950 1949 { 1951 1950 logprintf(pCardData, 3, "%s\n", NULLSTR(vs->reader->name)); 1952 1951 1953 1952 r = sc_connect_card(vs->reader, &(vs->card)); 1954 1953 logprintf(pCardData, 2, "sc_connect_card result = %d, %s\n", \ … … 1970 1969 /* 1971 1970 * We want a 16 byte unique serial number 1972 * PKCS15 gives us a char string, that 1971 * PKCS15 gives us a char string, that 1973 1972 * appears to have been formated with %02x or %02X 1974 * so as to make it printable. 1973 * so as to make it printable. 1975 1974 * So for now we will try and convert back to bin, 1976 1975 * and use the last 32 bytes of the vs-p15card->tokeninfo->serial_number … … 1981 1980 size_t len1, len2; 1982 1981 char * cserial; 1983 1982 1984 1983 len1 = strlen(vs->p15card->tokeninfo->serial_number); 1985 1984 cserial = vs->p15card->tokeninfo->serial_number; 1986 1985 len2 = sizeof(vs->cardFiles.file_cardid) * 2; 1987 1986 if ( len1 > len2) { 1988 cserial += len1 - len2; 1987 cserial += len1 - len2; 1989 1988 len1 = len2; 1990 1989 } … … 1994 1993 loghex(pCardData, 7, vs->cardFiles.file_cardid, sizeof(vs->cardFiles.file_cardid)); 1995 1994 } 1996 1997 1995 1996 1998 1997 r = sc_pkcs15_get_objects(vs->p15card, SC_PKCS15_TYPE_CERT_X509, \ 1999 1998 vs->cert_objs, 32); 2000 if (r < 0) 1999 if (r < 0) 2001 2000 { 2002 2001 logprintf(pCardData, 0, "Certificate enumeration failed: %s\n", \ … … 2004 2003 return SCARD_F_UNKNOWN_ERROR; 2005 2004 } 2006 2005 2007 2006 vs->cert_count = r; 2008 2007 logprintf(pCardData, 2, "Found %d certificat(s) in the card.\n", \ 2009 2008 vs->cert_count); 2010 2009 2011 2010 r = sc_pkcs15_get_objects(vs->p15card, SC_PKCS15_TYPE_PRKEY_RSA, \ 2012 2011 vs->prkey_objs, 32); 2013 if (r < 0) 2012 if (r < 0) 2014 2013 { 2015 2014 logprintf(pCardData, 0, "Private key enumeration failed: %s\n", \ … … 2017 2016 return SCARD_F_UNKNOWN_ERROR; 2018 2017 } 2019 2018 2020 2019 vs->prkey_count = r; 2021 2020 logprintf(pCardData, 2, "Found %d private key(s) in the card.\n", \ … … 2024 2023 r = sc_pkcs15_get_objects(vs->p15card, SC_PKCS15_TYPE_AUTH_PIN, \ 2025 2024 vs->pin_objs, 8); 2026 if (r < 0) 2025 if (r < 0) 2027 2026 { 2028 2027 logprintf(pCardData, 2, "Pin object enumeration failed: %s\n", \ … … 2030 2029 return SCARD_F_UNKNOWN_ERROR; 2031 2030 } 2032 2031 2033 2032 vs->pin_count = r; 2034 2033 logprintf(pCardData, 2, "Found %d pin(s) in the card.\n", \ 2035 2034 vs->pin_count); 2036 2035 2037 #if 1 2036 #if 1 2038 2037 dump_objects(pCardData); 2039 2038 #endif … … 2045 2044 static int disassociate_card(PCARD_DATA pCardData) 2046 2045 { 2047 2046 2048 2047 VENDOR_SPECIFIC *vs; 2049 2048 int i; … … 2051 2050 vs = (VENDOR_SPECIFIC*)(pCardData->pvVendorSpecific); 2052 2051 logprintf(pCardData, 1, "disassociate_card\n"); 2053 2052 2054 2053 if(vs->pin != NULL) 2055 { 2054 { 2056 2055 free(vs->pin); 2057 2056 vs->pin = NULL; … … 2062 2061 } 2063 2062 vs->cert_count = 0; 2064 2063 2065 2064 for (i = 0; i < vs->prkey_count; i++) { 2066 2065 vs->prkey_objs[i] = NULL; 2067 2066 } 2068 2067 vs->prkey_count = 0; 2069 2068 2070 2069 for (i = 0; i < vs->pin_count; i++) { 2071 2070 vs->pin_objs[i] = NULL; 2072 2071 } 2073 2072 vs->pin_count = 0; 2074 2073 2075 2074 2076 2075 if(vs->p15card) … … 2106 2105 hModule, ul_reason_for_call, lpReserved, GetCurrentProcessId(), GetCurrentThreadId()); 2107 2106 #endif 2108 switch (ul_reason_for_call) 2107 switch (ul_reason_for_call) 2109 2108 { 2110 2109 case DLL_PROCESS_ATTACH: … … 2129 2128 #pragma managed(pop) 2130 2129 #endif 2130 #endif -
src/minidriver/opensc-minidriver.inf.in
rf636cc1 r44cf3d0 141 141 142 142 [Strings] 143 ProviderName ="Open sc"144 MediaDescription="Open scSmart Card Minidriver Installation Disk"145 CardDeviceName="Open sc Minidriver for Smart Card"143 ProviderName ="OpenSC" 144 MediaDescription="OpenSC Smart Card Minidriver Installation Disk" 145 CardDeviceName="OpenSC Minidriver" 146 146 SmartCardName="SOFTWARE\Microsoft\Cryptography\Calais\SmartCards\Cev Westcos" 147 147 SmartCardNameWOW64="SOFTWARE\Wow6432Node\Microsoft\Cryptography\Calais\SmartCards\Cev Westcos" 148 SmartCardCardModule="opensc-cardmod32.dll" 149 SmartCardCardModule64="opensc-cardmod64.dll" 148 SmartCardCardModule="opensc-minidriver.dll" -
win32/Make.rules.mak
r639ca65 r44cf3d0 1 1 OPENSC_FEATURES = pcsc 2 2 3 #Include support of minidriver 'cardmod'4 MINIDRIVER_DEF = /DENABLE_ CARDMOD3 #Include support for minidriver 4 MINIDRIVER_DEF = /DENABLE_MINIDRIVER 5 5 6 6 #Build MSI with the Windows Installer XML (WIX) toolkit, requires WIX >= 3.6 -
win32/OpenSC.wxs.in
r4ec415f r44cf3d0 32 32 </Component> 33 33 <Component Id="opensc_minidriver.dll" Guid="*"> 34 <File Source="$(var.SOURCE_DIR)\src\ cardmod\opensc-cardmod.dll" Vital="yes"/>34 <File Source="$(var.SOURCE_DIR)\src\minidriver\opensc-minidriver.dll" Vital="yes"/> 35 35 </Component> 36 36 </Directory>
Note: See TracChangeset
for help on using the changeset viewer.
