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

Annotation of /trunk/OpenPGPminidriver/CardInitializationAndDeconstruct.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (hide annotations)
Wed Mar 31 08:58:46 2010 UTC (15 years, 1 month ago) by vletoux
File MIME type: text/plain
File size: 5701 byte(s)
first msi Release
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 "SmartCard.h"
23    
24     // 4.1 Initialization and Deconstruct
25    
26    
27    
28     /** The CardAcquireContext function, defined by a smart card module,
29     initializes communication between the smart card module and either the
30     Microsoft Base Smart Card Cryptographic Service Provider (CSP) or smart
31     card key storage provider (KSP).
32     */
33     DWORD WINAPI CardAcquireContext(
34     __in PCARD_DATA pCardData,
35     __in DWORD dwFlags
36     )
37     {
38     DWORD dwReturn = 0;
39     __try
40     {
41     Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
42     if ( pCardData == NULL )
43     {
44     Trace(WINEVENT_LEVEL_ERROR, L"pCardData == NULL");
45     dwReturn = SCARD_E_INVALID_PARAMETER;
46     __leave;
47     }
48    
49     if ( dwFlags != 0 )
50     {
51     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags != 0");
52     dwReturn = SCARD_E_INVALID_PARAMETER;
53     __leave;
54     }
55 vletoux 8 dwReturn = CreateContext(pCardData, dwFlags);
56 vletoux 1 if (dwReturn)
57     {
58     __leave;
59     }
60    
61     pCardData->pfnCardDeleteContext = CardDeleteContext;
62     pCardData->pfnCardAuthenticatePin = CardAuthenticatePin;
63     pCardData->pfnCardGetChallenge = CardGetChallenge;
64     pCardData->pfnCardAuthenticateChallenge = CardAuthenticateChallenge;
65 vletoux 9 pCardData->pfnCardDeauthenticate = NULL; //CardDeauthenticate;
66 vletoux 1 pCardData->pfnCardUnblockPin = CardUnblockPin;
67     pCardData->pfnCardChangeAuthenticator = CardChangeAuthenticator;
68     pCardData->pfnCardCreateDirectory = CardCreateDirectory;
69     pCardData->pfnCardDeleteDirectory = CardDeleteDirectory;
70     pCardData->pfnCardReadFile = CardReadFile;
71     pCardData->pfnCardCreateFile = CardCreateFile;
72     pCardData->pfnCardGetFileInfo = CardGetFileInfo;
73     pCardData->pfnCardWriteFile = CardWriteFile;
74     pCardData->pfnCardDeleteFile = CardDeleteFile;
75     pCardData->pfnCardEnumFiles = CardEnumFiles;
76     pCardData->pfnCardQueryFreeSpace = CardQueryFreeSpace;
77     pCardData->pfnCardQueryCapabilities = CardQueryCapabilities;
78     pCardData->pfnCardCreateContainer = CardCreateContainer;
79     pCardData->pfnCardDeleteContainer = CardDeleteContainer;
80     pCardData->pfnCardGetContainerInfo = CardGetContainerInfo;
81     pCardData->pfnCardRSADecrypt = CardRSADecrypt;
82     pCardData->pfnCardSignData = CardSignData;
83 vletoux 12 pCardData->pfnCardSignData = CardSignData;
84     pCardData->pfnCardQueryKeySizes = CardQueryKeySizes;
85 vletoux 1
86     // should be null for RSA only card
87     pCardData->pfnCardConstructDHAgreement = NULL; //CardConstructDHAgreement;
88 vletoux 12
89     if (pCardData->dwVersion >= CARD_DATA_VERSION_FIVE)
90     {
91     pCardData->pfnCardDeriveKey = NULL; //CardDeriveKey;
92     pCardData->pfnCardDestroyDHAgreement = NULL; //CardDestroyDHAgreement;
93     }
94     if (pCardData->dwVersion >= CARD_DATA_VERSION_SIX)
95     {
96     pCardData->pfnCardGetChallengeEx = CardGetChallengeEx;
97     pCardData->pfnCardAuthenticateEx = CardAuthenticateEx;
98     pCardData->pfnCardChangeAuthenticatorEx = CardChangeAuthenticatorEx;
99     pCardData->pfnCardDeauthenticateEx = CardDeauthenticateEx;
100     pCardData->pfnCardGetContainerProperty = CardGetContainerProperty;
101     pCardData->pfnCardSetContainerProperty = CardSetContainerProperty;
102     pCardData->pfnCardGetProperty = CardGetProperty;
103     pCardData->pfnCardSetProperty = CardSetProperty;
104     }
105     if (pCardData->dwVersion >= CARD_DATA_VERSION_SEVEN)
106     {
107     pCardData->pfnMDImportSessionKey = MDImportSessionKey;
108     pCardData->pfnMDEncryptData = MDEncryptData;
109     pCardData->pfnCardImportSessionKey = CardImportSessionKey;
110     pCardData->pfnCardGetSharedKeyHandle = CardGetSharedKeyHandle;
111     pCardData->pfnCardGetAlgorithmProperty = CardGetAlgorithmProperty;
112     pCardData->pfnCardGetKeyProperty = CardGetKeyProperty;
113     pCardData->pfnCardSetKeyProperty = CardSetKeyProperty;
114     pCardData->pfnCardProcessEncryptedData = CardProcessEncryptedData;
115     pCardData->pfnCardDestroyKey = CardDestroyKey;
116     pCardData->pfnCardCreateContainerEx = CardCreateContainerEx;
117     }
118 vletoux 1 }
119     __finally
120     {
121     if (dwReturn)
122     {
123     CleanContext(pCardData);
124     }
125     }
126     Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
127     return dwReturn;
128     }
129    
130     /** The CardDeleteContext function reverses the effect of CardAcquireContext
131     and severs the communication between the Base CSP/KSP and the card minidriver.
132     This function also performs any needed deallocations and cleanup.
133     */
134    
135     DWORD WINAPI CardDeleteContext(
136     __inout PCARD_DATA pCardData
137     )
138     {
139 vletoux 8 DWORD dwReturn;
140 vletoux 1 Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
141 vletoux 8 dwReturn = CleanContext(pCardData);
142     Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
143     return dwReturn;
144 vletoux 1 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26