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

Contents of /trunk/OpenPGPminidriver/CardInitializationAndDeconstruct.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Tue Feb 23 19:18:59 2010 UTC (15 years, 2 months ago) by vletoux
File MIME type: text/plain
File size: 6169 byte(s)


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 dwReturn = CreateContext(pCardData);
56 if (dwReturn)
57 {
58 __leave;
59 }
60 if (!(dwFlags & CARD_SECURE_KEY_INJECTION_NO_CARD_MODE))
61 {
62 if (pCardData->hSCardCtx == 0)
63 {
64 Trace(WINEVENT_LEVEL_ERROR, L"pCardData->hSCardCtx == NULL");
65 dwReturn = SCARD_E_INVALID_PARAMETER;
66 __leave;
67 }
68 if (pCardData->hScard == 0)
69 {
70 Trace(WINEVENT_LEVEL_ERROR, L"pCardData->hScard == NULL");
71 dwReturn = SCARD_E_INVALID_PARAMETER;
72 __leave;
73 }
74 }
75
76 dwReturn = CheckContext(pCardData);
77 if (dwReturn)
78 {
79 __leave;
80 }
81 // select the application on the card
82 dwReturn = SelectOpenPGPApplication(pCardData);
83 if (dwReturn)
84 {
85 __leave;
86 }
87
88 /* CardInitializationAndDeconstruct.c */
89 pCardData->pfnCardDeleteContext = CardDeleteContext;
90
91 /* CardPinOperation.c */
92 pCardData->pfnCardAuthenticatePin = CardAuthenticatePin;
93 pCardData->pfnCardGetChallenge = CardGetChallenge;
94 pCardData->pfnCardAuthenticateChallenge = CardAuthenticateChallenge;
95 // CardDeauthenticate not implemented
96 pCardData->pfnCardDeauthenticate = CardDeauthenticate;
97 pCardData->pfnCardAuthenticateEx = CardAuthenticateEx;
98 pCardData->pfnCardGetChallengeEx = CardGetChallengeEx;
99 pCardData->pfnCardDeauthenticateEx = CardDeauthenticateEx;
100 pCardData->pfnCardChangeAuthenticatorEx = CardChangeAuthenticatorEx;
101 pCardData->pfnCardUnblockPin = CardUnblockPin;
102 pCardData->pfnCardChangeAuthenticator = CardChangeAuthenticator;
103
104 /* CardPublicDataOperation.c */
105 pCardData->pfnCardCreateDirectory = CardCreateDirectory;
106 pCardData->pfnCardDeleteDirectory = CardDeleteDirectory;
107 pCardData->pfnCardReadFile = CardReadFile;
108 pCardData->pfnCardCreateFile = CardCreateFile;
109 pCardData->pfnCardGetFileInfo = CardGetFileInfo;
110 pCardData->pfnCardWriteFile = CardWriteFile;
111 pCardData->pfnCardDeleteFile = CardDeleteFile;
112 pCardData->pfnCardEnumFiles = CardEnumFiles;
113 pCardData->pfnCardQueryFreeSpace = CardQueryFreeSpace;
114
115 /* CardCapabilities.c */
116 pCardData->pfnCardQueryCapabilities = CardQueryCapabilities;
117
118 /* CardAndContainerProperties.c */
119 pCardData->pfnCardGetContainerProperty = CardGetContainerProperty;
120 pCardData->pfnCardSetContainerProperty = CardSetContainerProperty;
121 pCardData->pfnCardGetProperty = CardGetProperty;
122 pCardData->pfnCardSetProperty = CardSetProperty;
123
124 /* CardKeyContainer.c */
125 pCardData->pfnCardCreateContainer = CardCreateContainer;
126 pCardData->pfnCardCreateContainerEx = CardCreateContainerEx;
127 pCardData->pfnCardDeleteContainer = CardDeleteContainer;
128 pCardData->pfnCardGetContainerInfo = CardGetContainerInfo;
129
130 /* CardCryptographicOperations.c */
131 pCardData->pfnCardRSADecrypt = CardRSADecrypt;
132 pCardData->pfnCardSignData = CardSignData;
133
134 // should be null for RSA only card
135 pCardData->pfnCardConstructDHAgreement = NULL; //CardConstructDHAgreement;
136 pCardData->pfnCardDeriveKey = NULL; //CardDeriveKey;
137 pCardData->pfnCardDestroyDHAgreement = NULL; //CardDestroyDHAgreement;
138
139 pCardData->pfnCardSignData = CardSignData;
140 pCardData->pfnCardQueryKeySizes = CardQueryKeySizes;
141
142 /* Not found :
143 The pfnCardDeriveKey, pfnCardDestroyDHAgreement, and pfnCspGetDHAgreement
144 members of the CARD_DATA structure are described in later sections.
145 Starting with Version 5 of this specification, the necessary modifications
146 to the pfnCardConstructDHAgreement function are handled through versioning
147 the structure that is associated with that function.
148 => what's the prototype for this function ?
149 */
150
151 pCardData->pfnCspGetDHAgreement = NULL;
152 }
153 __finally
154 {
155 if (dwReturn)
156 {
157 CleanContext(pCardData);
158 }
159 }
160 Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
161 return dwReturn;
162 }
163
164 /** The CardDeleteContext function reverses the effect of CardAcquireContext
165 and severs the communication between the Base CSP/KSP and the card minidriver.
166 This function also performs any needed deallocations and cleanup.
167 */
168
169 DWORD WINAPI CardDeleteContext(
170 __inout PCARD_DATA pCardData
171 )
172 {
173 Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
174 CleanContext(pCardData);
175 return 0;
176 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26