41 |
case ROLE_CONFIDENTIALITY: |
case ROLE_CONFIDENTIALITY: |
42 |
dwMinPinSize = 6; |
dwMinPinSize = 6; |
43 |
case ROLE_PUK: |
case ROLE_PUK: |
44 |
|
dwMinPinSize = 1; |
45 |
break; |
break; |
46 |
case ROLE_ADMIN: |
case ROLE_ADMIN: |
47 |
dwMinPinSize = 8; |
dwMinPinSize = 8; |
57 |
__leave; |
__leave; |
58 |
} |
} |
59 |
// check in status DO |
// check in status DO |
60 |
dwReturn = SCardReadFile(pCardData, szOpenPGPDir, szOpenPGPStatus, &pbResponse, &dwSize); |
dwReturn = OCardReadFile(pCardData, szOpenPGPDir, szOpenPGPStatus, &pbResponse, &dwSize); |
61 |
|
if (dwReturn) |
62 |
|
{ |
63 |
|
__leave; |
64 |
|
} |
65 |
switch(PinId) |
switch(PinId) |
66 |
{ |
{ |
67 |
case ROLE_SIGNATURE: |
case ROLE_SIGNATURE: |
102 |
__try |
__try |
103 |
{ |
{ |
104 |
Trace(WINEVENT_LEVEL_VERBOSE, L"Enter PinId=%d",PinId); |
Trace(WINEVENT_LEVEL_VERBOSE, L"Enter PinId=%d",PinId); |
105 |
dwReturn = SCardReadFile(pCardData, szOpenPGPDir, szOpenPGPStatus, &pbResponse, &dwSize); |
dwReturn = OCardReadFile(pCardData, szOpenPGPDir, szOpenPGPStatus, &pbResponse, &dwSize); |
106 |
switch(PinId) |
switch(PinId) |
107 |
{ |
{ |
108 |
case ROLE_SIGNATURE: |
case ROLE_SIGNATURE: |
164 |
} |
} |
165 |
pbCmd[4] = (BYTE) cbPin; |
pbCmd[4] = (BYTE) cbPin; |
166 |
memcpy(pbCmd + 5, pbPin, cbPin); |
memcpy(pbCmd + 5, pbPin, cbPin); |
167 |
dwReturn = SCardSendCommand(pCardData, pbCmd, 5 + cbPin); |
dwReturn = OCardSendCommand(pCardData, pbCmd, 5 + cbPin); |
168 |
if (dwReturn) |
if (dwReturn) |
169 |
{ |
{ |
170 |
|
Trace(WINEVENT_LEVEL_VERBOSE, L"Authentication failed"); |
171 |
__leave; |
__leave; |
172 |
} |
} |
173 |
/*switch(PinId) |
Trace(WINEVENT_LEVEL_VERBOSE, L"Authentication successfull"); |
|
{ |
|
|
case ROLE_AUTHENTICATION: |
|
|
case ROLE_CONFIDENTIALITY: |
|
|
dwReturn = VerifyPIN(pCardData, ROLE_SIGNATURE, pbPin, cbPin); |
|
|
break; |
|
|
}*/ |
|
174 |
|
|
175 |
} |
} |
176 |
__finally |
__finally |
197 |
__try |
__try |
198 |
{ |
{ |
199 |
Trace(WINEVENT_LEVEL_VERBOSE, L"Enter PinId=%d",PinId); |
Trace(WINEVENT_LEVEL_VERBOSE, L"Enter PinId=%d",PinId); |
200 |
|
dwReturn = CheckPinLength(pCardData, PinId, cbNewPin); |
201 |
|
if (dwReturn) |
202 |
|
{ |
203 |
|
Trace(WINEVENT_LEVEL_ERROR, L"Invalid len %d",cbNewPin); |
204 |
|
dwReturn = SCARD_E_INVALID_PARAMETER; |
205 |
|
__leave; |
206 |
|
} |
207 |
dwReturn = CheckPinLength(pCardData, PinId, cbOldPin); |
dwReturn = CheckPinLength(pCardData, PinId, cbOldPin); |
208 |
if (dwReturn) |
if (dwReturn) |
209 |
{ |
{ |
229 |
pbCmd[4] = (BYTE) (cbOldPin + cbNewPin); |
pbCmd[4] = (BYTE) (cbOldPin + cbNewPin); |
230 |
memcpy(pbCmd + 5, pbOldPin, cbOldPin); |
memcpy(pbCmd + 5, pbOldPin, cbOldPin); |
231 |
memcpy(pbCmd + 5 + cbOldPin, pbNewPin, cbNewPin); |
memcpy(pbCmd + 5 + cbOldPin, pbNewPin, cbNewPin); |
232 |
dwReturn = SCardSendCommand(pCardData, pbCmd, 5 + cbOldPin + cbNewPin); |
dwReturn = OCardSendCommand(pCardData, pbCmd, 5 + cbOldPin + cbNewPin); |
233 |
} |
} |
234 |
__finally |
__finally |
235 |
{ |
{ |
256 |
__try |
__try |
257 |
{ |
{ |
258 |
Trace(WINEVENT_LEVEL_VERBOSE, L"Enter PinId=%d",PinId); |
Trace(WINEVENT_LEVEL_VERBOSE, L"Enter PinId=%d",PinId); |
259 |
|
dwReturn = CheckPinLength(pCardData, ROLE_USER, cbNewPin); |
260 |
|
if (dwReturn) |
261 |
|
{ |
262 |
|
Trace(WINEVENT_LEVEL_ERROR, L"Invalid len %d",cbNewPin); |
263 |
|
dwReturn = SCARD_E_INVALID_PARAMETER; |
264 |
|
__leave; |
265 |
|
} |
266 |
switch(PinId) |
switch(PinId) |
267 |
{ |
{ |
268 |
case ROLE_ADMIN: |
case ROLE_ADMIN: |
269 |
// authenticate the admin |
// authenticate the admin |
270 |
dwReturn = VerifyPIN(pCardData, PinId, pbAuthenticator, cbAuthenticator); |
dwReturn = VerifyPIN(pCardData, PinId, pbAuthenticator, cbAuthenticator); |
271 |
if (!dwReturn) |
if (dwReturn) |
272 |
{ |
{ |
273 |
return dwReturn; |
__leave; |
274 |
} |
} |
275 |
pbCmd[4] = (BYTE) cbAuthenticator; |
pbCmd[4] = (BYTE) cbNewPin; |
276 |
memcpy(pbCmd + 5, pbNewPin, cbNewPin); |
memcpy(pbCmd + 5, pbNewPin, cbNewPin); |
277 |
dwCmdSize = 5 + cbNewPin; |
dwCmdSize = 5 + cbNewPin; |
278 |
break; |
break; |
281 |
if (dwReturn) |
if (dwReturn) |
282 |
{ |
{ |
283 |
__leave; |
__leave; |
284 |
} |
} |
285 |
pbCmd[2] = 0x00; |
pbCmd[2] = 0x00; |
286 |
pbCmd[4] = (BYTE) (cbAuthenticator + cbNewPin); |
pbCmd[4] = (BYTE) (cbAuthenticator + cbNewPin); |
287 |
memcpy(pbCmd + 5, pbAuthenticator, cbAuthenticator); |
memcpy(pbCmd + 5, pbAuthenticator, cbAuthenticator); |
292 |
dwReturn = SCARD_E_INVALID_PARAMETER; |
dwReturn = SCARD_E_INVALID_PARAMETER; |
293 |
__leave; |
__leave; |
294 |
} |
} |
295 |
dwReturn = SCardSendCommand(pCardData, pbCmd, dwCmdSize); |
dwReturn = OCardSendCommand(pCardData, pbCmd, dwCmdSize); |
296 |
} |
} |
297 |
__finally |
__finally |
298 |
{ |
{ |
301 |
return dwReturn; |
return dwReturn; |
302 |
} |
} |
303 |
|
|
304 |
|
DWORD SetPUK(__in PCARD_DATA pCardData, |
305 |
|
__in_bcount(cbPin) PBYTE pbAdminPin, __in DWORD cbAdminPin, |
306 |
|
__in_bcount(cbPin) PBYTE pbPuk, __in DWORD cbPuk |
307 |
|
) |
308 |
|
{ |
309 |
|
DWORD dwReturn; |
310 |
|
Trace(WINEVENT_LEVEL_VERBOSE, L"Enter"); |
311 |
|
__try |
312 |
|
{ |
313 |
|
dwReturn = CheckPinLength(pCardData, ROLE_PUK, cbPuk); |
314 |
|
if (dwReturn) |
315 |
|
{ |
316 |
|
Trace(WINEVENT_LEVEL_ERROR, L"Invalid len %d",cbPuk); |
317 |
|
dwReturn = SCARD_E_INVALID_PARAMETER; |
318 |
|
__leave; |
319 |
|
} |
320 |
|
dwReturn = VerifyPIN(pCardData, ROLE_ADMIN, pbAdminPin, cbAdminPin); |
321 |
|
if (dwReturn) |
322 |
|
{ |
323 |
|
__leave; |
324 |
|
} |
325 |
|
dwReturn = OCardWriteFile(pCardData, szOpenPGPDir, szOpenPGPPUK, pbPuk, cbPuk); |
326 |
|
} |
327 |
|
__finally |
328 |
|
{ |
329 |
|
} |
330 |
|
return dwReturn; |
331 |
|
} |
332 |
|
|
333 |
DWORD Deauthenticate(__in PCARD_DATA pCardData) |
DWORD Deauthenticate(__in PCARD_DATA pCardData) |
334 |
{ |
{ |
335 |
DWORD dwAP; |
DWORD dwAP; |
341 |
dwReturn = SCardReconnect(pCardData->hScard, |
dwReturn = SCardReconnect(pCardData->hScard, |
342 |
SCARD_SHARE_SHARED, |
SCARD_SHARE_SHARED, |
343 |
SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, |
SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, |
344 |
SCARD_LEAVE_CARD, |
SCARD_RESET_CARD, |
345 |
&dwAP ); |
&dwAP ); |
346 |
if (dwReturn) |
if (dwReturn) |
347 |
{ |
{ |
348 |
Trace(WINEVENT_LEVEL_ERROR, L"SCardControl 0x%08X", dwReturn); |
Trace(WINEVENT_LEVEL_ERROR, L"SCardReconnect 0x%08X", dwReturn); |
349 |
__leave; |
__leave; |
350 |
} |
} |
|
// regain the ownership of a transaction |
|
351 |
dwReturn = SCardBeginTransaction(pCardData->hScard); |
dwReturn = SCardBeginTransaction(pCardData->hScard); |
352 |
if (dwReturn) |
if (dwReturn) |
353 |
{ |
{ |
360 |
{ |
{ |
361 |
} |
} |
362 |
return dwReturn; |
return dwReturn; |
363 |
|
} |
364 |
|
|
365 |
|
|
366 |
|
DWORD GetPinInfo(DWORD __in dwPinIndex, __inout PPIN_INFO pPinInfo) |
367 |
|
{ |
368 |
|
DWORD dwReturn=0, dwVersion; |
369 |
|
__try |
370 |
|
{ |
371 |
|
Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwPinIndex=%d",dwPinIndex); |
372 |
|
dwVersion = (pPinInfo->dwVersion == 0) ? PIN_INFO_CURRENT_VERSION : pPinInfo->dwVersion; |
373 |
|
if ( dwVersion != PIN_INFO_CURRENT_VERSION ) |
374 |
|
{ |
375 |
|
Trace(WINEVENT_LEVEL_ERROR, L"dwVersion %d", dwVersion); |
376 |
|
dwReturn = ERROR_REVISION_MISMATCH; |
377 |
|
__leave; |
378 |
|
} |
379 |
|
pPinInfo->dwVersion = dwVersion; |
380 |
|
switch(dwPinIndex) |
381 |
|
{ |
382 |
|
case ROLE_SIGNATURE: |
383 |
|
pPinInfo->PinType = AlphaNumericPinType; |
384 |
|
pPinInfo->PinPurpose = DigitalSignaturePin; |
385 |
|
pPinInfo->dwChangePermission = CREATE_PIN_SET(ROLE_SIGNATURE); |
386 |
|
SET_PIN(pPinInfo->dwChangePermission, ROLE_AUTHENTICATION); |
387 |
|
SET_PIN(pPinInfo->dwChangePermission, ROLE_CONFIDENTIALITY); |
388 |
|
pPinInfo->dwUnblockPermission = CREATE_PIN_SET(ROLE_ADMIN); |
389 |
|
SET_PIN(pPinInfo->dwUnblockPermission, ROLE_PUK); |
390 |
|
pPinInfo->PinCachePolicy.dwVersion = PIN_CACHE_POLICY_CURRENT_VERSION; |
391 |
|
pPinInfo->PinCachePolicy.PinCachePolicyType = PinCacheNormal; |
392 |
|
pPinInfo->dwFlags = 0; |
393 |
|
break; |
394 |
|
case ROLE_AUTHENTICATION: |
395 |
|
pPinInfo->PinType = AlphaNumericPinType; |
396 |
|
pPinInfo->PinPurpose = AuthenticationPin; |
397 |
|
pPinInfo->dwChangePermission = CREATE_PIN_SET(ROLE_SIGNATURE); |
398 |
|
SET_PIN(pPinInfo->dwChangePermission, ROLE_AUTHENTICATION); |
399 |
|
SET_PIN(pPinInfo->dwChangePermission, ROLE_CONFIDENTIALITY); |
400 |
|
pPinInfo->dwUnblockPermission = CREATE_PIN_SET(ROLE_ADMIN); |
401 |
|
SET_PIN(pPinInfo->dwUnblockPermission, ROLE_PUK); |
402 |
|
pPinInfo->PinCachePolicy.dwVersion = PIN_CACHE_POLICY_CURRENT_VERSION; |
403 |
|
pPinInfo->PinCachePolicy.PinCachePolicyType = PinCacheNormal; |
404 |
|
pPinInfo->dwFlags = 0; |
405 |
|
break; |
406 |
|
case ROLE_CONFIDENTIALITY: |
407 |
|
pPinInfo->PinType = AlphaNumericPinType; |
408 |
|
pPinInfo->PinPurpose = EncryptionPin; |
409 |
|
pPinInfo->dwChangePermission = CREATE_PIN_SET(ROLE_SIGNATURE); |
410 |
|
SET_PIN(pPinInfo->dwChangePermission, ROLE_AUTHENTICATION); |
411 |
|
SET_PIN(pPinInfo->dwChangePermission, ROLE_CONFIDENTIALITY); |
412 |
|
pPinInfo->dwUnblockPermission = CREATE_PIN_SET(ROLE_ADMIN); |
413 |
|
SET_PIN(pPinInfo->dwUnblockPermission, ROLE_PUK); |
414 |
|
pPinInfo->PinCachePolicy.dwVersion = PIN_CACHE_POLICY_CURRENT_VERSION; |
415 |
|
pPinInfo->PinCachePolicy.PinCachePolicyType = PinCacheNormal; |
416 |
|
pPinInfo->dwFlags = 0; |
417 |
|
break; |
418 |
|
case ROLE_ADMIN: |
419 |
|
pPinInfo->PinType = AlphaNumericPinType; |
420 |
|
pPinInfo->PinPurpose = AdministratorPin; |
421 |
|
pPinInfo->dwChangePermission = CREATE_PIN_SET(ROLE_ADMIN); |
422 |
|
pPinInfo->dwUnblockPermission = 0; |
423 |
|
pPinInfo->PinCachePolicy.dwVersion = PIN_CACHE_POLICY_CURRENT_VERSION; |
424 |
|
pPinInfo->PinCachePolicy.PinCachePolicyType = PinCacheNormal; |
425 |
|
pPinInfo->dwFlags = 0; |
426 |
|
break; |
427 |
|
case ROLE_PUK: |
428 |
|
pPinInfo->PinType = AlphaNumericPinType; |
429 |
|
pPinInfo->PinPurpose = UnblockOnlyPin; |
430 |
|
pPinInfo->dwChangePermission = CREATE_PIN_SET(ROLE_ADMIN); |
431 |
|
pPinInfo->dwUnblockPermission = 0; |
432 |
|
pPinInfo->PinCachePolicy.dwVersion = PIN_CACHE_POLICY_CURRENT_VERSION; |
433 |
|
pPinInfo->PinCachePolicy.PinCachePolicyType = PinCacheNormal; |
434 |
|
pPinInfo->dwFlags = 0; |
435 |
|
break; |
436 |
|
default: |
437 |
|
Trace(WINEVENT_LEVEL_ERROR, L"dwPinIndex == %d", dwPinIndex); |
438 |
|
dwReturn = SCARD_E_INVALID_PARAMETER ; |
439 |
|
__leave; |
440 |
|
} |
441 |
|
} |
442 |
|
__finally |
443 |
|
{ |
444 |
|
} |
445 |
|
Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn); |
446 |
|
return dwReturn; |
447 |
} |
} |