[Openpgpmdrv-commits] r8 - in trunk: OpenPGPminidriver OpenPGPminidriverTest

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Mar 11 21:32:28 CET 2010


Author: vletoux
Date: 2010-03-11 21:32:26 +0100 (Thu, 11 Mar 2010)
New Revision: 8

Added:
   trunk/OpenPGPminidriver/openpgpmdrv.inf
Removed:
   trunk/OpenPGPminidriver/driver.inf
Modified:
   trunk/OpenPGPminidriver/CardAndContainerProperties.c
   trunk/OpenPGPminidriver/CardCryptographicOperations.c
   trunk/OpenPGPminidriver/CardInitializationAndDeconstruct.c
   trunk/OpenPGPminidriver/CardKeyContainer.c
   trunk/OpenPGPminidriver/CardPinOperation.c
   trunk/OpenPGPminidriver/CardPublicDataOperation.c
   trunk/OpenPGPminidriver/Context.h
   trunk/OpenPGPminidriver/ContextManagement.c
   trunk/OpenPGPminidriver/CryptoOperations.c
   trunk/OpenPGPminidriver/CryptoOperations.h
   trunk/OpenPGPminidriver/PinOperations.c
   trunk/OpenPGPminidriver/PinOperations.h
   trunk/OpenPGPminidriver/PublicDataOperations.c
   trunk/OpenPGPminidriver/PublicDataOperations.h
   trunk/OpenPGPminidriver/SmartCard.c
   trunk/OpenPGPminidriver/SmartCard.h
   trunk/OpenPGPminidriver/Tracing.c
   trunk/OpenPGPminidriverTest/BaseCSP.cpp
   trunk/OpenPGPminidriverTest/Dialog.h
   trunk/OpenPGPminidriverTest/Dialog.rc
   trunk/OpenPGPminidriverTest/InitializationAndDeconstruct.cpp
   trunk/OpenPGPminidriverTest/PINOperations.cpp
   trunk/OpenPGPminidriverTest/PublicDataOperations.cpp
   trunk/OpenPGPminidriverTest/global.h
   trunk/OpenPGPminidriverTest/main.cpp
Log:
improvement of the quality of the project.
More test for the qualification of the driver success but not all ...


Modified: trunk/OpenPGPminidriver/CardAndContainerProperties.c
===================================================================
--- trunk/OpenPGPminidriver/CardAndContainerProperties.c	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriver/CardAndContainerProperties.c	2010-03-11 20:32:26 UTC (rev 8)
@@ -34,6 +34,7 @@
 )
 {
 	DWORD dwReturn = 0, dwVersion;	
+	POPENPGP_CONTEXT pContext = NULL;
 	Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
 	__try
 	{
@@ -56,8 +57,14 @@
 			dwReturn  = ERROR_REVISION_MISMATCH;
 			__leave;
 		}
-		pCardCapabilities->fCertificateCompression = TRUE;
-		pCardCapabilities->fKeyGen = TRUE;
+		dwReturn = CheckContext(pCardData);
+		if ( dwReturn)
+		{
+			__leave;
+		}
+		pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
+		pCardCapabilities->fKeyGen = !pContext->fIsReadOnly;
+		pCardCapabilities->fCertificateCompression = FALSE;		
 		dwReturn = 0;
 	}
 	__finally
@@ -93,6 +100,12 @@
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
+		if ( pbData == NULL )
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
+			dwReturn  = SCARD_E_INVALID_PARAMETER;
+			__leave;
+		}
 		if ( pdwDataLen == NULL )
 		{
 			Trace(WINEVENT_LEVEL_ERROR, L"pdwDataLen == NULL");
@@ -247,6 +260,7 @@
 	DWORD dwReturn = 0;	
 	PBYTE pbTempData = NULL;
 	DWORD dwTempSize = 0;
+	POPENPGP_CONTEXT pContext = NULL;
 	Trace(WINEVENT_LEVEL_VERBOSE, L"Enter wszProperty = %s", wszProperty);
 	__try
 	{
@@ -262,14 +276,34 @@
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
+		if ( pbData == NULL )
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
+			dwReturn  = SCARD_E_INVALID_PARAMETER;
+			__leave;
+		}
 		if ( pdwDataLen == NULL )
 		{
 			Trace(WINEVENT_LEVEL_ERROR, L"pdwDataLen == NULL");
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
+		dwReturn = CheckContext(pCardData);
+		if ( dwReturn )
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"GetContext dwReturn == 0x%08X", dwReturn);
+			dwReturn  = SCARD_E_INVALID_PARAMETER;
+			__leave;
+		}
+		pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
 		if (wcscmp(wszProperty,CP_CARD_FREE_SPACE) == 0)
 		{
+			if (dwFlags)
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
+				dwReturn  = SCARD_E_INVALID_PARAMETER;
+				__leave;
+			}
 			*pdwDataLen = sizeof(CARD_FREE_SPACE_INFO);
 			if (cbData < *pdwDataLen)
 			{
@@ -281,6 +315,12 @@
 		}
 		else if (wcscmp(wszProperty,CP_CARD_CAPABILITIES) == 0)
 		{
+			if (dwFlags)
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
+				dwReturn  = SCARD_E_INVALID_PARAMETER;
+				__leave;
+			}
 			*pdwDataLen = sizeof(CARD_CAPABILITIES);
 			if (cbData < *pdwDataLen)
 			{
@@ -303,6 +343,12 @@
 		}
 		else if (wcscmp(wszProperty,CP_CARD_READ_ONLY) == 0)
 		{
+			if (dwFlags)
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
+				dwReturn  = SCARD_E_INVALID_PARAMETER;
+				__leave;
+			}
 			*pdwDataLen = sizeof(BOOL);
 			if (cbData < *pdwDataLen)
 			{
@@ -310,10 +356,16 @@
 				dwReturn  = ERROR_INSUFFICIENT_BUFFER;
 				__leave;
 			}
-			*((PBOOL)pbData) = TRUE;
+			*((PBOOL)pbData) = pContext->fIsReadOnly;
 		}
 		else if (wcscmp(wszProperty,CP_CARD_CACHE_MODE) == 0)
 		{
+			if (dwFlags)
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
+				dwReturn  = SCARD_E_INVALID_PARAMETER;
+				__leave;
+			}
 			*pdwDataLen = sizeof(DWORD);
 			if (cbData < *pdwDataLen)
 			{
@@ -325,6 +377,12 @@
 		}
 		else if (wcscmp(wszProperty,CP_SUPPORTS_WIN_X509_ENROLLMENT) == 0)
 		{
+			if (dwFlags)
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
+				dwReturn  = SCARD_E_INVALID_PARAMETER;
+				__leave;
+			}
 			*pdwDataLen = sizeof(BOOL);
 			if (cbData < *pdwDataLen)
 			{
@@ -336,6 +394,12 @@
 		}
 		else if (wcscmp(wszProperty,CP_CARD_GUID) == 0)
 		{
+			if (dwFlags)
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
+				dwReturn  = SCARD_E_INVALID_PARAMETER;
+				__leave;
+			}
 			dwReturn = CardReadFile(pCardData, NULL, szCARD_IDENTIFIER_FILE, 0, &pbTempData, &dwTempSize);
 			if (dwReturn)
 			{
@@ -352,6 +416,12 @@
 		}
 		else if (wcscmp(wszProperty,CP_CARD_SERIAL_NO) == 0)
 		{
+			if (dwFlags)
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
+				dwReturn  = SCARD_E_INVALID_PARAMETER;
+				__leave;
+			}
 			*pdwDataLen = sizeof(OPENPGP_AID);
 			if (cbData < *pdwDataLen)
 			{
@@ -378,6 +448,12 @@
 		else if (wcscmp(wszProperty,CP_CARD_LIST_PINS) == 0)
 		{
 			PPIN_SET pPinSet;
+			if (dwFlags)
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
+				dwReturn  = SCARD_E_INVALID_PARAMETER;
+				__leave;
+			}
 			*pdwDataLen = sizeof(PIN_SET);
 			if (cbData < *pdwDataLen)
 			{
@@ -386,14 +462,38 @@
 				__leave;
 			}
 			pPinSet = (PPIN_SET) pbData;
+			*pPinSet = CREATE_PIN_SET(ROLE_SIGNATURE);
+			SET_PIN(*pPinSet, ROLE_AUTHENTICATION);
+			SET_PIN(*pPinSet, ROLE_CONFIDENTIALITY);
+			SET_PIN(*pPinSet, ROLE_PUK);
+			SET_PIN(*pPinSet, ROLE_ADMIN);
 		}
 		else if (wcscmp(wszProperty,CP_CARD_AUTHENTICATED_STATE) == 0)
 		{
+			if (dwFlags)
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
+				dwReturn  = SCARD_E_INVALID_PARAMETER;
+				__leave;
+			}
 			dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
 		}
 		else if (wcscmp(wszProperty,CP_CARD_PIN_STRENGTH_VERIFY) == 0)
 		{
 			PPIN_SET pPinSet;
+			switch(dwFlags)
+			{
+			case ROLE_SIGNATURE:
+			case ROLE_AUTHENTICATION:
+			case ROLE_CONFIDENTIALITY:
+			case ROLE_ADMIN:
+			case ROLE_PUK:
+				break;
+			default:
+				Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
+				dwReturn  = SCARD_E_INVALID_PARAMETER;
+				__leave;
+			}
 			*pdwDataLen = sizeof(PIN_SET);
 			if (cbData < *pdwDataLen)
 			{
@@ -406,6 +506,12 @@
 		}
 		else if (wcscmp(wszProperty,CP_KEY_IMPORT_SUPPORT) == 0)
 		{
+			if (dwFlags)
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
+				dwReturn  = SCARD_E_INVALID_PARAMETER;
+				__leave;
+			}
 			*pdwDataLen = sizeof(DWORD);
 			if (cbData < *pdwDataLen)
 			{
@@ -413,7 +519,14 @@
 				dwReturn  = ERROR_INSUFFICIENT_BUFFER;
 				__leave;
 			}
-			*((PDWORD)pbData) = CARD_KEY_IMPORT_RSA_KEYEST;
+			if (pContext->fIsReadOnly)
+			{
+				*((PDWORD)pbData) = 0;
+			}
+			else
+			{
+				*((PDWORD)pbData) = CARD_KEY_IMPORT_RSA_KEYEST;
+			}
 		}
 		else if (wcscmp(wszProperty,CP_ENUM_ALGORITHMS ) == 0)
 		{
@@ -449,6 +562,7 @@
 		{
 			if (dwFlags == CARD_CIPHER_OPERATION)
 			{
+				Trace(WINEVENT_LEVEL_ERROR, L"CARD_CIPHER_OPERATION", wszProperty);
 				dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
 			}
 			else if (dwFlags == CARD_ASYMMETRIC_OPERATION   )
@@ -471,11 +585,24 @@
 		}
 		else if (wcscmp(wszProperty,CP_CHAINING_MODES ) == 0)
 		{
+			if (dwFlags)
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
+				dwReturn  = SCARD_E_INVALID_PARAMETER;
+				__leave;
+			}
+			Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s", wszProperty);
 			dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
 		}
+		else if ( wcscmp(wszProperty,CP_CARD_PIN_STRENGTH_CHANGE ) == 0
+			|| wcscmp(wszProperty,CP_CARD_PIN_STRENGTH_UNBLOCK ) == 0)
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s SCARD_E_UNSUPPORTED_FEATURE", wszProperty);
+			dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
+		}
 		else
 		{
-			Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s", wszProperty);
+			Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s SCARD_E_INVALID_PARAMETER", wszProperty);
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
@@ -531,47 +658,72 @@
 			|| wcscmp(wszProperty,CP_KEY_IMPORT_SUPPORT) == 0
 			|| wcscmp(wszProperty,CP_ENUM_ALGORITHMS) == 0
 			|| wcscmp(wszProperty,CP_PADDING_SCHEMES) == 0
-			|| wcscmp(wszProperty,CP_CHAINING_MODES) == 0)
+			|| wcscmp(wszProperty,CP_CHAINING_MODES) == 0
+			|| wcscmp(wszProperty,CP_SUPPORTS_WIN_X509_ENROLLMENT) == 0
+			|| wcscmp(wszProperty,CP_CARD_CACHE_MODE) == 0
+			|| wcscmp(wszProperty,CP_CARD_SERIAL_NO) == 0
+			|| wcscmp(wszProperty,CP_CARD_GUID) == 0
+			|| wcscmp(wszProperty,CP_CARD_PIN_INFO) == 0
+			|| wcscmp(wszProperty,CP_CARD_PIN_STRENGTH_VERIFY) == 0)
 		{
+			if ( pbData == NULL )
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
+				dwReturn  = SCARD_E_INVALID_PARAMETER;
+				__leave;
+			}
 			Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s SCARD_E_UNSUPPORTED_FEATURE", wszProperty);
 			dwReturn  = SCARD_E_UNSUPPORTED_FEATURE ;
 			__leave;
 		}
 		else if (wcscmp(wszProperty,CP_CARD_READ_ONLY) == 0)
 		{
-			dwReturn  = SCARD_E_UNSUPPORTED_FEATURE ;
+			if ( pbData == NULL )
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
+				dwReturn  = SCARD_E_INVALID_PARAMETER;
+				__leave;
+			}
+			dwReturn  = SCARD_W_SECURITY_VIOLATION;
 		}
-		else if (wcscmp(wszProperty,CP_CARD_CACHE_MODE) == 0)
+		else  if (wcscmp(wszProperty,CP_PARENT_WINDOW) == 0)
 		{
-			dwReturn  = SCARD_E_UNSUPPORTED_FEATURE ;
+			if ( pbData == NULL )
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
+				dwReturn  = SCARD_E_INVALID_PARAMETER;
+				__leave;
+			}
+			if ( cbDataLen != sizeof(HWND) )
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"cbDataLen == %d", cbDataLen);
+				dwReturn  = SCARD_E_INVALID_PARAMETER ;
+				__leave;
+			}
+			if ( *pbData != 0 && !IsWindow((HWND) *pbData) )
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"*pbData == %d GetLastError == %d", *pbData, GetLastError());
+				dwReturn  = SCARD_E_INVALID_PARAMETER ;
+				__leave;
+			}
+			dwReturn  = 0;
 		}
-		else if (wcscmp(wszProperty,CP_SUPPORTS_WIN_X509_ENROLLMENT) == 0)
+		else  if (wcscmp(wszProperty,CP_PIN_CONTEXT_STRING) == 0)
 		{
-			dwReturn  = SCARD_E_UNSUPPORTED_FEATURE ;
+			if ( pbData == NULL )
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
+				dwReturn  = SCARD_E_INVALID_PARAMETER;
+				__leave;
+			}
+			dwReturn  = 0;
 		}
-		else if (wcscmp(wszProperty,CP_CARD_GUID) == 0)
-		{
-			dwReturn  = SCARD_E_UNSUPPORTED_FEATURE ;
-		}
-		else if (wcscmp(wszProperty,CP_CARD_SERIAL_NO) == 0)
-		{
-			dwReturn  = SCARD_E_UNSUPPORTED_FEATURE ;
-		}
-		else if (wcscmp(wszProperty,CP_CARD_PIN_INFO) == 0)
-		{
-			dwReturn  = SCARD_E_UNSUPPORTED_FEATURE ;
-		}
-		else if (wcscmp(wszProperty,CP_CARD_PIN_STRENGTH_VERIFY) == 0)
-		{
-			dwReturn  = SCARD_E_UNSUPPORTED_FEATURE ;
-		}
 		else
 		{
-			Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s", wszProperty);
+			Trace(WINEVENT_LEVEL_ERROR, L"wszProperty == %s Unknown", wszProperty);
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
-		dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
 	}
 	__finally
 	{

Modified: trunk/OpenPGPminidriver/CardCryptographicOperations.c
===================================================================
--- trunk/OpenPGPminidriver/CardCryptographicOperations.c	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriver/CardCryptographicOperations.c	2010-03-11 20:32:26 UTC (rev 8)
@@ -58,8 +58,8 @@
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
-		if (pInfo->dwVersion < CARD_RSA_KEY_DECRYPT_INFO_CURRENT_VERSION 
-			&& pCardData->dwVersion == CARD_DATA_CURRENT_VERSION)
+		if (pInfo->dwVersion != CARD_RSA_KEY_DECRYPT_INFO_VERSION_ONE 
+			&& pInfo->dwVersion != CARD_RSA_KEY_DECRYPT_INFO_VERSION_TWO)
 		{
 			Trace(WINEVENT_LEVEL_ERROR, L"ERROR_REVISION_MISMATCH");
 			dwReturn  = ERROR_REVISION_MISMATCH;
@@ -68,7 +68,7 @@
 		if (pInfo->dwKeySpec != AT_KEYEXCHANGE)
 		{
 			Trace(WINEVENT_LEVEL_ERROR, L"AT_KEYEXCHANGE %d", pInfo->dwKeySpec);
-			dwReturn  = SCARD_E_NO_KEY_CONTAINER ;
+			dwReturn  = SCARD_E_INVALID_PARAMETER ;
 			__leave;
 		}
 		if (pInfo->bContainerIndex != Confidentiality)
@@ -82,7 +82,11 @@
 		{
 			__leave;
 		}
-		dwReturn = SCardDecrypt(pCardData, pInfo);
+		dwReturn = OCardDecrypt(pCardData, pInfo);
+		if (dwReturn == SCARD_W_WRONG_CHV)
+		{
+			dwReturn = SCARD_W_SECURITY_VIOLATION;
+		}
 	}
 	__finally
 	{
@@ -119,12 +123,31 @@
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
+		if ( ( pInfo->dwVersion != CARD_SIGNING_INFO_BASIC_VERSION   ) &&
+			( pInfo->dwVersion != CARD_SIGNING_INFO_CURRENT_VERSION ) )
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"dwVersion == %d", pInfo->dwVersion);
+			dwReturn  = ERROR_REVISION_MISMATCH;
+			__leave;
+		}
 		if ( pInfo->pbData == NULL )
 		{
 			Trace(WINEVENT_LEVEL_ERROR, L"pInfo->pbData == NULL");
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
+		if (pInfo->dwKeySpec == AT_KEYEXCHANGE)
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"AT_KEYEXCHANGE %d", pInfo->dwKeySpec);
+			dwReturn  = SCARD_E_NO_KEY_CONTAINER ;
+			__leave;
+		}
+		if (pInfo->dwKeySpec != AT_SIGNATURE)
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"AT_SIGNATURE %d", pInfo->dwKeySpec);
+			dwReturn  = SCARD_E_INVALID_PARAMETER ;
+			__leave;
+		}
 		dwReturn = CheckContext(pCardData);
 		if ( dwReturn)
 		{
@@ -133,16 +156,20 @@
 		switch(pInfo->bContainerIndex)
 		{
 		case Authentication:
-			dwReturn = SCardAuthenticate(pCardData, pInfo);
+			dwReturn = OCardAuthenticate(pCardData, pInfo);
 			break;
 		case Signature:
-			dwReturn = SCardSign(pCardData, pInfo);
+			dwReturn = OCardSign(pCardData, pInfo);
 			break;
 		default:
 			dwReturn = SCARD_E_NO_KEY_CONTAINER;
 			Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", pInfo->bContainerIndex);
 			__leave;
 		}
+		if (dwReturn == SCARD_W_WRONG_CHV)
+		{
+			dwReturn = SCARD_W_SECURITY_VIOLATION;
+		}
 	}
 	__finally
 	{
@@ -189,7 +216,11 @@
 			dwReturn  = ERROR_REVISION_MISMATCH;
 			__leave;
 		}
-
+		dwReturn = CheckContext(pCardData);
+		if ( dwReturn)
+		{
+			__leave;
+		}
 		switch(dwKeySpec)
 		{
 			case AT_ECDHE_P256 :

Modified: trunk/OpenPGPminidriver/CardInitializationAndDeconstruct.c
===================================================================
--- trunk/OpenPGPminidriver/CardInitializationAndDeconstruct.c	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriver/CardInitializationAndDeconstruct.c	2010-03-11 20:32:26 UTC (rev 8)
@@ -52,38 +52,12 @@
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
-		dwReturn = CreateContext(pCardData);
+		dwReturn = CreateContext(pCardData, dwFlags);
 		if (dwReturn)
 		{
 			__leave;
 		}
-		if (!(dwFlags & CARD_SECURE_KEY_INJECTION_NO_CARD_MODE))
-		{
-			if (pCardData->hSCardCtx == 0)
-			{
-				Trace(WINEVENT_LEVEL_ERROR, L"pCardData->hSCardCtx == NULL");
-				dwReturn  = SCARD_E_INVALID_PARAMETER;
-				__leave;
-			}
-			if (pCardData->hScard == 0)
-			{
-				Trace(WINEVENT_LEVEL_ERROR, L"pCardData->hScard == NULL");
-				dwReturn  = SCARD_E_INVALID_PARAMETER;
-				__leave;
-			}
-		}
 
-		dwReturn = CheckContext(pCardData);
-		if (dwReturn)
-		{
-			__leave;
-		}
-		// select the application on the card
-		dwReturn = SelectOpenPGPApplication(pCardData);
-		if (dwReturn)
-		{
-			__leave;
-		}
 
 		/* CardInitializationAndDeconstruct.c */
 		pCardData->pfnCardDeleteContext           = CardDeleteContext;
@@ -92,7 +66,7 @@
 		pCardData->pfnCardAuthenticatePin         = CardAuthenticatePin;
 		pCardData->pfnCardGetChallenge            = CardGetChallenge;
 		pCardData->pfnCardAuthenticateChallenge   = CardAuthenticateChallenge;
-		// CardDeauthenticate not implemented
+		
 		pCardData->pfnCardDeauthenticate          = CardDeauthenticate;
 		pCardData->pfnCardAuthenticateEx          = CardAuthenticateEx;
 		pCardData->pfnCardGetChallengeEx          = CardGetChallengeEx;
@@ -170,7 +144,9 @@
     __inout PCARD_DATA pCardData
      )
 {
+	DWORD dwReturn;
 	Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
-	CleanContext(pCardData);
-	return 0;
+	dwReturn = CleanContext(pCardData);
+	Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
+	return dwReturn;
 }
\ No newline at end of file

Modified: trunk/OpenPGPminidriver/CardKeyContainer.c
===================================================================
--- trunk/OpenPGPminidriver/CardKeyContainer.c	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriver/CardKeyContainer.c	2010-03-11 20:32:26 UTC (rev 8)
@@ -39,6 +39,7 @@
 )
 {
 	DWORD dwReturn = 0;	
+	POPENPGP_CONTEXT pContext = NULL;
 	Trace(WINEVENT_LEVEL_VERBOSE, L"Enter bContainerIndex=%d",bContainerIndex);
 	__try
 	{
@@ -60,6 +61,7 @@
 			dwReturn  = SCARD_E_UNSUPPORTED_FEATURE;
 			__leave; 
 		}
+		// controls are done in CardCreateContainerEx
 		dwReturn = CardCreateContainerEx(pCardData, 
 								bContainerIndex,
 								dwFlags,
@@ -97,6 +99,7 @@
 )
 {
 	DWORD dwReturn = 0;	
+	POPENPGP_CONTEXT pContext = NULL;
 	Trace(WINEVENT_LEVEL_VERBOSE, L"Enter bContainerIndex=%d",bContainerIndex);
 	__try
 	{
@@ -129,19 +132,26 @@
 		{
 			__leave;
 		}
-		if ((dwFlags & CARD_CREATE_CONTAINER_KEY_GEN) == CARD_CREATE_CONTAINER_KEY_GEN )
+		pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
+		if (pContext->fIsReadOnly)
 		{
-			dwReturn = SCardCreateKey(pCardData, bContainerIndex, dwKeySize);
+			dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
+			Trace(WINEVENT_LEVEL_ERROR, L"Readonly card");
+			__leave;
 		}
-		else if ((dwFlags & CARD_CREATE_CONTAINER_KEY_IMPORT ) == CARD_CREATE_CONTAINER_KEY_IMPORT  )
+		if (dwFlags == CARD_CREATE_CONTAINER_KEY_GEN)
 		{
+			dwReturn = OCardCreateKey(pCardData, bContainerIndex, dwKeySize);
+		}
+		else if (dwFlags == CARD_CREATE_CONTAINER_KEY_IMPORT)
+		{
 			if (pbKeyData == NULL)
 			{
 				Trace(WINEVENT_LEVEL_ERROR, L"pbKeyData == NULL");
 				dwReturn  = SCARD_E_INVALID_PARAMETER;
 				__leave;
 			}
-			dwReturn = SCardImportKey(pCardData, bContainerIndex, pbKeyData, dwKeySize);
+			dwReturn = OCardImportKey(pCardData, bContainerIndex, pbKeyData, dwKeySize);
 		}
 		else
 		{
@@ -181,7 +191,7 @@
     __inout PCONTAINER_INFO  pContainerInfo
 )
 {
-	DWORD dwReturn = 0;	
+	DWORD dwReturn = 0, dwVersion;	
 	Trace(WINEVENT_LEVEL_VERBOSE, L"Enter bContainerIndex=%d",bContainerIndex);
 	__try
 	{
@@ -197,6 +207,13 @@
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
+		dwVersion = (pContainerInfo->dwVersion == 0) ? 1 : pContainerInfo->dwVersion;
+		if ( dwVersion != CONTAINER_INFO_CURRENT_VERSION )
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"dwVersion == %d", pContainerInfo->dwVersion);
+			dwReturn  = ERROR_REVISION_MISMATCH;
+			__leave;
+		}
 		if ( dwFlags )
 		{
 			Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
@@ -222,11 +239,11 @@
 		{
 			case Signature:
 			case Authentication:
-				dwReturn = SCardReadPublicKey(pCardData, bContainerIndex, 
+				dwReturn = OCardReadPublicKey(pCardData, bContainerIndex, 
 					&(pContainerInfo->pbSigPublicKey),&(pContainerInfo->cbSigPublicKey));
 				break;
 			case Confidentiality:
-				dwReturn = SCardReadPublicKey(pCardData, bContainerIndex, 
+				dwReturn = OCardReadPublicKey(pCardData, bContainerIndex, 
 					&(pContainerInfo->pbKeyExPublicKey),&(pContainerInfo->cbKeyExPublicKey));
 				break;
 		}

Modified: trunk/OpenPGPminidriver/CardPinOperation.c
===================================================================
--- trunk/OpenPGPminidriver/CardPinOperation.c	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriver/CardPinOperation.c	2010-03-11 20:32:26 UTC (rev 8)
@@ -76,7 +76,7 @@
 				__leave;
 			}
 			dwReturn = VerifyPIN(pCardData, ROLE_USER, pbPin, cbPin);
-			if (pcAttemptsRemaining)
+			if (dwReturn && pcAttemptsRemaining)
 			{
 				GetRemainingPin(pCardData, ROLE_USER, pcAttemptsRemaining);
 			}
@@ -89,7 +89,7 @@
 				__leave;
 			}
 			dwReturn = VerifyPIN(pCardData, ROLE_ADMIN, pbPin, cbPin);
-			if (pcAttemptsRemaining)
+			if (dwReturn && pcAttemptsRemaining)
 			{
 				GetRemainingPin(pCardData, ROLE_ADMIN, pcAttemptsRemaining);
 			}
@@ -263,7 +263,7 @@
 			__leave;
 		}
 		dwReturn = VerifyPIN(pCardData, PinId, pbPinData, cbPinData);
-		if (pcAttemptsRemaining)
+		if (dwReturn && pcAttemptsRemaining)
 		{
 			GetRemainingPin(pCardData, PinId, pcAttemptsRemaining);
 		}
@@ -385,12 +385,18 @@
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
-		if (!(dwFlags & CARD_AUTHENTICATE_PIN_PIN))
+		if (dwFlags == CARD_AUTHENTICATE_PIN_CHALLENGE_RESPONSE)
 		{
 			dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
-			Trace(WINEVENT_LEVEL_ERROR, L"dwFlags = 0x%08X", dwFlags);
+			Trace(WINEVENT_LEVEL_ERROR, L"CARD_AUTHENTICATE_PIN_CHALLENGE_RESPONSE SCARD_E_UNSUPPORTED_FEATURE");
 			__leave;
 		}
+		if (dwFlags != CARD_AUTHENTICATE_PIN_PIN)
+		{
+			dwReturn = SCARD_E_INVALID_PARAMETER;
+			Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_INVALID_PARAMETER dwFlags = 0x%08X", dwFlags);
+			__leave;
+		}
 		dwReturn = CheckContext(pCardData);
 		if ( !dwReturn )
 		{
@@ -470,14 +476,20 @@
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
-		if (!(dwFlags & CARD_AUTHENTICATE_PIN_PIN))
+		if (dwFlags == CARD_AUTHENTICATE_PIN_CHALLENGE_RESPONSE)
 		{
 			dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
 			Trace(WINEVENT_LEVEL_ERROR, L"dwFlags = 0x%08X", dwFlags);
 			__leave;
 		}
+		if (dwFlags != CARD_AUTHENTICATE_PIN_PIN)
+		{
+			dwReturn = SCARD_E_INVALID_PARAMETER;
+			Trace(WINEVENT_LEVEL_ERROR, L"dwFlags = 0x%08X", dwFlags);
+			__leave;
+		}
 		dwReturn = CheckContext(pCardData);
-		if ( !dwReturn )
+		if (dwReturn )
 		{
 			Trace(WINEVENT_LEVEL_ERROR, L"GetContext dwReturn == 0x%08X", dwReturn);
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
@@ -488,7 +500,7 @@
 			dwReturn = ChangePIN(pCardData, ROLE_USER,
 								pbCurrentAuthenticator, cbCurrentAuthenticator,
 								pbNewAuthenticator, cbNewAuthenticator);
-			if (pcAttemptsRemaining)
+			if (dwReturn && pcAttemptsRemaining)
 			{
 				GetRemainingPin(pCardData, ROLE_USER, pcAttemptsRemaining);
 			}
@@ -498,7 +510,7 @@
 			dwReturn = ChangePIN(pCardData, ROLE_ADMIN,
 								pbCurrentAuthenticator, cbCurrentAuthenticator,
 								pbNewAuthenticator, cbNewAuthenticator);
-			if (pcAttemptsRemaining)
+			if (dwReturn && pcAttemptsRemaining)
 			{
 				GetRemainingPin(pCardData,ROLE_ADMIN, pcAttemptsRemaining);
 			}
@@ -559,39 +571,51 @@
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
-		if (!(dwFlags & CARD_AUTHENTICATE_PIN_PIN))
+		if (dwFlags != PIN_CHANGE_FLAG_UNBLOCK && dwFlags != PIN_CHANGE_FLAG_CHANGEPIN)
 		{
-			dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
+			dwReturn = SCARD_E_INVALID_PARAMETER;
 			Trace(WINEVENT_LEVEL_ERROR, L"dwFlags = 0x%08X", dwFlags);
 			__leave;
 		}
 		dwReturn = CheckContext(pCardData);
-		if ( !dwReturn )
+		if ( dwReturn )
 		{
 			Trace(WINEVENT_LEVEL_ERROR, L"GetContext dwReturn == 0x%08X", dwReturn);
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
-		if ( dwAuthenticatingPinId == dwTargetPinId) 
+		if ( dwAuthenticatingPinId == dwTargetPinId && dwFlags == PIN_CHANGE_FLAG_CHANGEPIN) 
 		{
 			dwReturn = ChangePIN(pCardData, dwAuthenticatingPinId,
 								pbAuthenticatingPinData, cbAuthenticatingPinData,
 								pbTargetData, cbTargetData);
-			if (pcAttemptsRemaining)
+			if (dwReturn && pcAttemptsRemaining)
 			{
 				GetRemainingPin(pCardData, dwAuthenticatingPinId, pcAttemptsRemaining);
 			}
 		}
-		else if ( dwAuthenticatingPinId == ROLE_ADMIN &&  dwTargetPinId == ROLE_USER) 
+		else if ( (dwAuthenticatingPinId == ROLE_ADMIN || dwAuthenticatingPinId == ROLE_PUK )
+					&&  dwTargetPinId == ROLE_USER  && dwFlags == PIN_CHANGE_FLAG_UNBLOCK) 
 		{
-			dwReturn = ResetUserPIN(pCardData, ROLE_ADMIN,
+			dwReturn = ResetUserPIN(pCardData, dwAuthenticatingPinId,
 								pbAuthenticatingPinData, cbAuthenticatingPinData,
 								pbTargetData, cbTargetData);
-			if (pcAttemptsRemaining)
+			if (dwReturn && pcAttemptsRemaining)
 			{
-				GetRemainingPin(pCardData,dwTargetPinId, pcAttemptsRemaining);
+				GetRemainingPin(pCardData,dwAuthenticatingPinId, pcAttemptsRemaining);
 			}
 		}
+		else if ( dwAuthenticatingPinId == ROLE_ADMIN
+					&&  dwTargetPinId == ROLE_PUK  && dwFlags == PIN_CHANGE_FLAG_CHANGEPIN) 
+		{
+			dwReturn = SetPUK(pCardData,
+								pbAuthenticatingPinData, cbAuthenticatingPinData,
+								pbTargetData, cbTargetData);
+			if (dwReturn && pcAttemptsRemaining)
+			{
+				GetRemainingPin(pCardData,dwAuthenticatingPinId, pcAttemptsRemaining);
+			}
+		}
 		else
 		{
 			Trace(WINEVENT_LEVEL_ERROR, L"unknown role match: %d %d", dwAuthenticatingPinId, dwTargetPinId);

Modified: trunk/OpenPGPminidriver/CardPublicDataOperation.c
===================================================================
--- trunk/OpenPGPminidriver/CardPublicDataOperation.c	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriver/CardPublicDataOperation.c	2010-03-11 20:32:26 UTC (rev 8)
@@ -79,6 +79,12 @@
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
+		if ( *pszFileName == 0 )
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"pszFileName empty");
+			dwReturn  = SCARD_E_INVALID_PARAMETER;
+			__leave;
+		}
 		if (ppbData == NULL)
 		{
 			Trace(WINEVENT_LEVEL_ERROR, L"ppbData == NULL");
@@ -102,7 +108,7 @@
 		{
 			__leave;
 		}
-		dwReturn = SCardReadFile(pCardData, pszDirectoryName, pszFileName, ppbData, pcbData);
+		dwReturn = OCardReadFile(pCardData, pszDirectoryName, pszFileName, ppbData, pcbData);
 	}
 	__finally
 	{
@@ -123,7 +129,7 @@
 )
 {
 	DWORD dwReturn = 0;	
-	
+	POPENPGP_CONTEXT pContext = NULL;
 	Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
 	__try
 	{
@@ -144,7 +150,14 @@
 		{
 			__leave;
 		}
-		dwReturn = SCardCreateFile(pCardData, pszDirectoryName, pszFileName);
+		pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
+		if (pContext->fIsReadOnly)
+		{
+			dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
+			Trace(WINEVENT_LEVEL_ERROR, L"Readonly card");
+			__leave;
+		}
+		dwReturn = OCardCreateFile(pCardData, pszDirectoryName, pszFileName);
 	}
 	__finally
 	{
@@ -162,7 +175,7 @@
     __inout PCARD_FILE_INFO  pCardFileInfo
 )
 {
-	DWORD dwReturn = 0;	
+	DWORD dwReturn = 0, dwVersion;	
 	
 	Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
 	__try
@@ -185,12 +198,19 @@
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
+		dwVersion = (pCardFileInfo->dwVersion == 0) ? 1 : pCardFileInfo->dwVersion;
+		if ( dwVersion != CARD_CAPABILITIES_CURRENT_VERSION )
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"dwVersion %d", dwVersion);
+			dwReturn  = ERROR_REVISION_MISMATCH;
+			__leave;
+		}
 		dwReturn = CheckContext(pCardData);
 		if (dwReturn)
 		{
 			__leave;
 		}
-		dwReturn = SCardGetFileInfo(pCardData, pszDirectoryName, pszFileName, pCardFileInfo);
+		dwReturn = OCardGetFileInfo(pCardData, pszDirectoryName, pszFileName, pCardFileInfo);
 
 	}
 	__finally
@@ -214,7 +234,7 @@
 )
 {
 	DWORD dwReturn = 0;	
-	
+	POPENPGP_CONTEXT pContext = NULL;
 	Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
 	__try
 	{
@@ -253,7 +273,14 @@
 		{
 			__leave;
 		}
-		dwReturn = SCardWriteFile(pCardData, pszDirectoryName, pszFileName, pbData, cbData);
+		pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
+		if (pContext->fIsReadOnly)
+		{
+			dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
+			Trace(WINEVENT_LEVEL_ERROR, L"Readonly card");
+			__leave;
+		}
+		dwReturn = OCardWriteFile(pCardData, pszDirectoryName, pszFileName, pbData, cbData);
 	}
 	__finally
 	{
@@ -273,7 +300,7 @@
 )
 {
 	DWORD dwReturn = 0;	
-	
+	POPENPGP_CONTEXT pContext = NULL;
 	PBYTE pbData = NULL;
 	DWORD dwSize = 0;
 	Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
@@ -297,13 +324,19 @@
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
-		// try to read the file to see if it exists and return the right error code
 		dwReturn = CheckContext(pCardData);
 		if (dwReturn)
 		{
 			__leave;
 		}
-		dwReturn = SCardDeleteFile(pCardData, pszDirectoryName, pszFileName);
+		pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
+		if (pContext->fIsReadOnly)
+		{
+			dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
+			Trace(WINEVENT_LEVEL_ERROR, L"Readonly card");
+			__leave;
+		}
+		dwReturn = OCardDeleteFile(pCardData, pszDirectoryName, pszFileName);
 	}
 	__finally
 	{
@@ -325,7 +358,6 @@
 {
 	DWORD dwReturn = 0;	
 	PSTR szFiles = NULL;
-	
 	Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
 	__try
 	{
@@ -341,7 +373,7 @@
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
-		if ( pmszFileNames == NULL )
+		if ( pdwcbFileName == NULL )
 		{
 			Trace(WINEVENT_LEVEL_ERROR, L"pmszFileNames == NULL");
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
@@ -368,7 +400,7 @@
 		{
 			__leave;
 		}
-		dwReturn = SCardEnumFile(pCardData, pszDirectoryName, pmszFileNames, pdwcbFileName);
+		dwReturn = OCardEnumFile(pCardData, pszDirectoryName, pmszFileNames, pdwcbFileName);
 	}
 	__finally
 	{
@@ -384,7 +416,7 @@
     __inout PCARD_FREE_SPACE_INFO  pCardFreeSpaceInfo
 )
 {
-	DWORD dwReturn = 0;	
+	DWORD dwReturn = 0, dwVersion;	
 	Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
 	__try
 	{
@@ -400,6 +432,13 @@
 			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
+		dwVersion = (pCardFreeSpaceInfo->dwVersion == 0) ? 1 : pCardFreeSpaceInfo->dwVersion;
+		if ( dwVersion != CARD_FREE_SPACE_INFO_CURRENT_VERSION )
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"dwVersion %d", dwVersion);
+			dwReturn  = ERROR_REVISION_MISMATCH;
+			__leave;
+		}
 		if (dwFlags)
 		{
 			Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");

Modified: trunk/OpenPGPminidriver/Context.h
===================================================================
--- trunk/OpenPGPminidriver/Context.h	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriver/Context.h	2010-03-11 20:32:26 UTC (rev 8)
@@ -64,8 +64,9 @@
 	BOOL					fHasSignature;
 	BOOL					fHasDecryption;
 	BOOL					fHasAuthentication;
+	BOOL					fIsReadOnly;
 } OPENPGP_CONTEXT, *POPENPGP_CONTEXT ;
 
-DWORD CreateContext(__in PCARD_DATA pCardData);
+DWORD CreateContext(__in PCARD_DATA pCardData, __in DWORD dwFlags);
 DWORD CheckContext(__in PCARD_DATA pCardData);
 DWORD CleanContext(__in PCARD_DATA pCardData);
\ No newline at end of file

Modified: trunk/OpenPGPminidriver/ContextManagement.c
===================================================================
--- trunk/OpenPGPminidriver/ContextManagement.c	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriver/ContextManagement.c	2010-03-11 20:32:26 UTC (rev 8)
@@ -73,26 +73,197 @@
 }
 
 
-DWORD CreateContext(__in PCARD_DATA pCardData)
+
+DWORD CheckContextEx(__in PCARD_DATA pCardData, __in BOOL fOpenPGPContextShouldBeNotNull)
 {
 	DWORD dwReturn;
+	DWORD dwI, dwJ;
+	BOOL fFound = FALSE;
+	BOOL fRightATRLenFound = FALSE;
+	__try
+	{
+		if ( pCardData == NULL )
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"pCardData == NULL");
+			dwReturn  = SCARD_E_INVALID_PARAMETER;
+			__leave;
+		}
+		if (pCardData->pbAtr == NULL)
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"pCardData->pbAtr == NULL");
+			dwReturn  = SCARD_E_INVALID_PARAMETER;
+			__leave;
+		}
+
+		if (pCardData->dwVersion < CARD_DATA_VERSION_SIX)
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"pCardData->dwVersion(%d) < CARD_DATA_VERSION_SIX", pCardData->dwVersion);
+			dwReturn  = ERROR_REVISION_MISMATCH;
+			__leave;
+		}
+		pCardData->dwVersion = min(pCardData->dwVersion, CARD_DATA_VERSION_SIX);
+		for (dwI = 0; dwI < dwSupportedATRCount; dwI++)
+		{
+			if (SupportedATR[dwI].cbAtr == pCardData->cbAtr)
+			{
+				BYTE pbAtr[36];
+				fRightATRLenFound = TRUE;
+				memcpy(pbAtr, pCardData->pbAtr, SupportedATR[dwI].cbAtr);
+				for( dwJ = 0; dwJ < SupportedATR[dwI].cbAtr; dwJ++)
+				{
+					pbAtr[dwJ] &= SupportedATR[dwI].rgbMask[dwJ];
+				}
+				if (memcmp(pbAtr, SupportedATR[dwI].rgbAtr, SupportedATR[dwI].cbAtr) == 0)
+				{
+					fFound = TRUE;
+					//Trace(WINEVENT_LEVEL_VERBOSE, L"card match ATR %d", dwI);
+					break;
+				}
+
+			}
+		}
+		if (!fRightATRLenFound)
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"card doesn't match ATR len %d",pCardData->cbAtr);
+			dwReturn  = SCARD_E_INVALID_PARAMETER;
+			__leave;
+		}
+		if (!fFound)
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"card doesn't match ATR");
+			dwReturn  = SCARD_E_UNKNOWN_CARD;
+			__leave;
+		}
+
+		if ( pCardData->pwszCardName == NULL )
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"pCardData->pwszCardName");
+			dwReturn  = SCARD_E_INVALID_PARAMETER;
+			__leave;
+		}
+		/* Memory management functions */
+		if ( ( pCardData->pfnCspAlloc   == NULL ) ||
+			( pCardData->pfnCspReAlloc == NULL ) ||
+			( pCardData->pfnCspFree    == NULL ) )
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"Memory functions null");
+			dwReturn  = SCARD_E_INVALID_PARAMETER;
+			__leave;
+		}
+		if (fOpenPGPContextShouldBeNotNull)
+		{
+			if (!pCardData->pvVendorSpecific)
+			{
+				// not found =>
+				Trace(WINEVENT_LEVEL_ERROR, L"pCardData->pvVendorSpecific == NULL");
+				dwReturn = SCARD_E_UNEXPECTED;
+				__leave;
+			}
+			if (pCardData->hSCardCtx == 0)
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"pCardData->hSCardCtx == NULL");
+				dwReturn  = SCARD_E_INVALID_PARAMETER;
+				__leave;
+			}
+			if (pCardData->hScard == 0)
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"pCardData->hScard == NULL");
+				dwReturn  = SCARD_E_INVALID_PARAMETER;
+				__leave;
+			}
+		}
+		else
+		{
+			if (pCardData->pvVendorSpecific)
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"pContext != NULL");
+				dwReturn = SCARD_E_UNEXPECTED;
+				__leave;
+			}
+		}
+		dwReturn = 0;
+	}
+	__finally
+	{
+	}
+	return dwReturn;
+}
+
+DWORD CheckContext(__in PCARD_DATA pCardData)
+{
+	return CheckContextEx(pCardData, TRUE);
+}
+
+DWORD CleanContext(__in PCARD_DATA pCardData)
+{
+	DWORD dwReturn = 0;
+	__try
+	{
+		if (pCardData)
+		{
+			if ( pCardData->pvVendorSpecific)
+			{
+				pCardData->pfnCspFree( pCardData->pvVendorSpecific);
+				pCardData->pvVendorSpecific = NULL;
+			}
+			else
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"pCardData->pvVendorSpecific == NULL");
+			}
+		}
+		else
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"pCardData == NULL");
+			dwReturn = SCARD_E_INVALID_PARAMETER;
+			__leave;
+		}
+	}
+	__finally
+	{
+	}
+	return dwReturn;
+}
+
+
+DWORD CreateContext(__in PCARD_DATA pCardData, __in DWORD dwFlags)
+{
+	DWORD dwReturn;
 	PBYTE					pbCapabilities = NULL, pbCardCapabilities;
 	PBYTE					pbExtendedCapabilities = NULL;
 	PBYTE					pbApplicationIdentifier = NULL;
+	PBYTE					pbFingerPrint = NULL;
 	DWORD					dwCapabilitiesSize, 
 							dwCardCapabilitiesSize,
 							dwApplicationIdentifierSize,
-							dwExtendedCapabilitiesSize;
+							dwExtendedCapabilitiesSize,
+							dwFingerPrintSize;
+	DWORD dwI;
 	BYTE bCategoryIndicator, bStatusIndicator;
+	POPENPGP_CONTEXT pContext;
 	__try
 	{
-		POPENPGP_CONTEXT pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
-		if (pContext)
+		dwReturn = CheckContextEx(pCardData, FALSE);
+		if (dwReturn)
 		{
-			Trace(WINEVENT_LEVEL_ERROR, L"pContext != NULL");
-			dwReturn = SCARD_E_UNEXPECTED;
+			Trace(WINEVENT_LEVEL_ERROR, L"CheckContext");
 			__leave;
 		}
+		if (!(dwFlags & CARD_SECURE_KEY_INJECTION_NO_CARD_MODE))
+		{
+			if (pCardData->hSCardCtx == 0)
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"pCardData->hSCardCtx == NULL");
+				dwReturn  = SCARD_E_INVALID_HANDLE;
+				__leave;
+			}
+			if (pCardData->hScard == 0)
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"pCardData->hScard == NULL");
+				dwReturn  = SCARD_E_INVALID_HANDLE;
+				__leave;
+			}
+		}
+		
 		// not found => initialize context
 		pContext = pCardData->pfnCspAlloc(sizeof(OPENPGP_CONTEXT));
 		if (!pContext)
@@ -110,7 +281,7 @@
 			Trace(WINEVENT_LEVEL_ERROR, L"No SelectOpenPGPApplication");
 			__leave;
 		}
-		dwReturn = SCardReadFile(pCardData, szOpenPGPDir, szOpenPGPApplicationIdentifier, &pbApplicationIdentifier, &dwApplicationIdentifierSize);
+		dwReturn = OCardReadFile(pCardData, szOpenPGPDir, szOpenPGPApplicationIdentifier, &pbApplicationIdentifier, &dwApplicationIdentifierSize);
 		if (dwReturn)
 		{
 			__leave;
@@ -122,7 +293,7 @@
 			__leave;
 		}
 		memcpy(&(pContext->Aid),pbApplicationIdentifier,sizeof(OPENPGP_AID));
-		dwReturn = SCardReadFile(pCardData, szOpenPGPDir, szOpenPGPHistoricalBytes, &pbCapabilities, &dwCapabilitiesSize);
+		dwReturn = OCardReadFile(pCardData, szOpenPGPDir, szOpenPGPHistoricalBytes, &pbCapabilities, &dwCapabilitiesSize);
 		if (dwReturn)
 		{
 			__leave;
@@ -153,7 +324,7 @@
 			dwReturn = SCARD_E_UNEXPECTED;
 			__leave;
 		}
-		dwReturn = SCardReadFile(pCardData, szOpenPGPDir, szOpenPGPExtendedCap, &pbExtendedCapabilities, &dwExtendedCapabilitiesSize);
+		dwReturn = OCardReadFile(pCardData, szOpenPGPDir, szOpenPGPExtendedCap, &pbExtendedCapabilities, &dwExtendedCapabilitiesSize);
 		if (dwReturn)
 		{
 			__leave;
@@ -165,132 +336,62 @@
 		pContext->dwMaxCertificateLength = pbExtendedCapabilities[4] * 0x100 + pbExtendedCapabilities[5];
 		pContext->dwMaxCommandDataLength = pbExtendedCapabilities[6] * 0x100 + pbExtendedCapabilities[7];
 		pContext->dwMaxResponseLength = pbExtendedCapabilities[8] * 0x100 + pbExtendedCapabilities[9];
-		dwReturn = CCIDgetFeatures(pCardData);
+		pContext->fIsReadOnly = TRUE;
+		dwReturn = OCardReadFile(pCardData, szOpenPGPDir, szOpenPGPFingerprint, &pbFingerPrint, &dwFingerPrintSize);
 		if (dwReturn)
 		{
 			__leave;
 		}
-		dwReturn = 0;
-	}
-	__finally
-	{
-		if (pbApplicationIdentifier)
-			pCardData->pfnCspFree(pbApplicationIdentifier);
-		if (pbCapabilities)
-			pCardData->pfnCspFree(pbCapabilities);
-		if (pbExtendedCapabilities)
-			pCardData->pfnCspFree(pbExtendedCapabilities);
-	}
-	return dwReturn;
-}
-
-
-DWORD CheckContext(__in PCARD_DATA pCardData)
-{
-	DWORD dwReturn;
-	DWORD dwI, dwJ;
-	BOOL fFound = FALSE;
-	BOOL fRightATRLenFound = FALSE;
-	__try
-	{
-		if ( pCardData == NULL )
+		if (dwFingerPrintSize != 60)
 		{
-			Trace(WINEVENT_LEVEL_ERROR, L"pCardData == NULL");
-			dwReturn  = SCARD_E_INVALID_PARAMETER;
+			Trace(WINEVENT_LEVEL_ERROR, L"dwFingerPrintSize = %02X", dwFingerPrintSize);
+			dwReturn = SCARD_E_UNEXPECTED;
 			__leave;
 		}
-		if (pCardData->pbAtr == NULL)
+		pContext->fHasSignature = FALSE;
+		for( dwI = 0; dwI < 20; dwI++)
 		{
-			Trace(WINEVENT_LEVEL_ERROR, L"pCardData->pbAtr == NULL");
-			dwReturn  = SCARD_E_INVALID_PARAMETER;
-			__leave;
+			if (pbFingerPrint[dwI] != 0)
+			{
+				pContext->fHasSignature = TRUE;
+				break;
+			}
 		}
-
-		if (pCardData->dwVersion < CARD_DATA_VERSION_SIX)
+		pContext->fHasDecryption = FALSE;
+		for( dwI = 20; dwI < 40; dwI++)
 		{
-			Trace(WINEVENT_LEVEL_ERROR, L"pCardData->dwVersion(%d) < CARD_DATA_VERSION_SIX", pCardData->dwVersion);
-			dwReturn  = ERROR_REVISION_MISMATCH;
-			__leave;
+			if (pbFingerPrint[dwI] != 0)
+			{
+				pContext->fHasDecryption = TRUE;
+				break;
+			}
 		}
-		pCardData->dwVersion = min(pCardData->dwVersion, CARD_DATA_VERSION_SIX);
-		for (dwI = 0; dwI < dwSupportedATRCount; dwI++)
+		pContext->fHasAuthentication = FALSE;
+		for( dwI = 40; dwI < 60; dwI++)
 		{
-			if (SupportedATR[dwI].cbAtr == pCardData->cbAtr)
+			if (pbFingerPrint[dwI] != 0)
 			{
-				BYTE pbAtr[36];
-				fRightATRLenFound = TRUE;
-				memcpy(pbAtr, pCardData->pbAtr, SupportedATR[dwI].cbAtr);
-				for( dwJ = 0; dwJ < SupportedATR[dwI].cbAtr; dwJ++)
-				{
-					pbAtr[dwJ] &= SupportedATR[dwI].rgbMask[dwJ];
-				}
-				if (memcmp(pbAtr, pCardData->pbAtr, SupportedATR[dwI].cbAtr) == 0)
-				{
-					fFound = TRUE;
-					//Trace(WINEVENT_LEVEL_VERBOSE, L"card match ATR %d", dwI);
-					break;
-				}
-
+				pContext->fHasAuthentication = TRUE;
+				break;
 			}
 		}
-		if (!fRightATRLenFound)
+		dwReturn = CCIDgetFeatures(pCardData);
+		if (dwReturn)
 		{
-			Trace(WINEVENT_LEVEL_ERROR, L"card doesn't match ATR len %d",pCardData->cbAtr);
-			dwReturn  = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
-		if (!fFound)
-		{
-			Trace(WINEVENT_LEVEL_ERROR, L"card doesn't match ATR");
-			dwReturn  = SCARD_E_UNKNOWN_CARD;
-			__leave;
-		}
-
-		if ( pCardData->pwszCardName == NULL )
-		{
-			Trace(WINEVENT_LEVEL_ERROR, L"pCardData->pwszCardName");
-			dwReturn  = SCARD_E_INVALID_PARAMETER;
-			__leave;
-		}
-		/* Memory management functions */
-		if ( ( pCardData->pfnCspAlloc   == NULL ) ||
-			( pCardData->pfnCspReAlloc == NULL ) ||
-			( pCardData->pfnCspFree    == NULL ) )
-		{
-			Trace(WINEVENT_LEVEL_ERROR, L"Memory functions null");
-			dwReturn  = SCARD_E_INVALID_PARAMETER;
-			__leave;
-		}
-		if (!pCardData->pvVendorSpecific)
-		{
-			// not found =>
-			dwReturn = SCARD_E_UNEXPECTED;
-			__leave;
-		}
 		dwReturn = 0;
 	}
 	__finally
 	{
+		if (pbFingerPrint)
+			pCardData->pfnCspFree(pbFingerPrint);
+		if (pbApplicationIdentifier)
+			pCardData->pfnCspFree(pbApplicationIdentifier);
+		if (pbCapabilities)
+			pCardData->pfnCspFree(pbCapabilities);
+		if (pbExtendedCapabilities)
+			pCardData->pfnCspFree(pbExtendedCapabilities);
 	}
 	return dwReturn;
 }
-
-DWORD CleanContext(__in PCARD_DATA pCardData)
-{
-	DWORD dwReturn = 0;
-	__try
-	{
-		if (pCardData)
-		{
-			if ( pCardData->pvVendorSpecific)
-			{
-				pCardData->pfnCspFree( pCardData->pvVendorSpecific);
-				pCardData->pvVendorSpecific = NULL;
-			}
-		}
-	}
-	__finally
-	{
-	}
-	return dwReturn;
-}
\ No newline at end of file

Modified: trunk/OpenPGPminidriver/CryptoOperations.c
===================================================================
--- trunk/OpenPGPminidriver/CryptoOperations.c	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriver/CryptoOperations.c	2010-03-11 20:32:26 UTC (rev 8)
@@ -16,6 +16,7 @@
 */
 
 #include <windows.h>
+#include <stdio.h>
 #include <cardmod.h>
 #include "Tracing.h"
 #include "Context.h"
@@ -68,16 +69,8 @@
 
 DWORD dwSignatureAlgorithmCount = ARRAYSIZE(SignatureAlgorithm);
 
-#pragma pack(push,1)
-typedef struct _OPENPGP_ALGORITHM_ATTRIBUTE
-{
-	BYTE bAlgoId;
-	unsigned short wModulusLength;
-	unsigned short wExponentLength;
-	BYTE bFormat;
-} OPENPGP_ALGORITHM_ATTRIBUTE, *POPENPGP_ALGORITHM_ATTRIBUTE;
-#pragma pack(pop)
 
+
 typedef struct _RSAPUBLICKEYBLOB
 {
 	BLOBHEADER blobheader;
@@ -86,7 +79,7 @@
 } RSAPUBLICKEYBLOB, *PRSAPUBLICKEYBLOB;
 
 
-DWORD GetKeyAlgorithmAttributes(__in PCARD_DATA pCardData, 
+DWORD OCardGetKeyAlgorithmAttributes(__in PCARD_DATA pCardData, 
 								__in OPENPGP_CONTAINER dwContainer,
 								__out POPENPGP_ALGORITHM_ATTRIBUTE pAttributes)
 {
@@ -114,7 +107,7 @@
 			Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", dwContainer);
 			__leave;
 		}
-		dwReturn = SCardReadFile(pCardData, szOpenPGPDir, szAlgorithmAttributes, &pbData, &dwResponseSize);
+		dwReturn = OCardReadFile(pCardData, szOpenPGPDir, szAlgorithmAttributes, &pbData, &dwResponseSize);
 		if (dwReturn)
 		{
 			__leave;
@@ -127,10 +120,10 @@
 		}
 		memcpy(pAttributes, pbData, dwResponseSize);
 		// big endian, little endian ...
-		wTemp = pAttributes->wExponentLength;
-		pAttributes->wExponentLength = (wTemp % 0x100) * 0x100 + (wTemp / 0x100);
-		wTemp = pAttributes->wModulusLength;
-		pAttributes->wModulusLength = (wTemp % 0x100) * 0x100 + (wTemp / 0x100);
+		wTemp = pAttributes->wExponentLengthInBit;
+		pAttributes->wExponentLengthInBit = (wTemp % 0x100) * 0x100 + (wTemp / 0x100);
+		wTemp = pAttributes->wModulusLengthInBit;
+		pAttributes->wModulusLengthInBit = (wTemp % 0x100) * 0x100 + (wTemp / 0x100);
 		
 		dwReturn = 0;
 	}
@@ -143,7 +136,7 @@
 	return dwReturn;
 }
 
-DWORD SetKeyAlgorithmAttributes(__in PCARD_DATA pCardData, 
+DWORD OCardSetKeyAlgorithmAttributes(__in PCARD_DATA pCardData, 
 								__in OPENPGP_CONTAINER dwContainer,
 								__out POPENPGP_ALGORITHM_ATTRIBUTE pAttributes)
 {
@@ -171,12 +164,12 @@
 			__leave;
 		}
 		memcpy(&TempAttributes, pAttributes, sizeof(OPENPGP_ALGORITHM_ATTRIBUTE));
-		wTemp = TempAttributes.wExponentLength;
-		TempAttributes.wExponentLength = (wTemp % 0x100) * 0x100 + (wTemp / 0x100);
-		wTemp = TempAttributes.wModulusLength;
-		TempAttributes.wModulusLength = (wTemp % 0x100) * 0x100 + (wTemp / 0x100);
+		wTemp = TempAttributes.wExponentLengthInBit;
+		TempAttributes.wExponentLengthInBit = (wTemp % 0x100) * 0x100 + (wTemp / 0x100);
+		wTemp = TempAttributes.wModulusLengthInBit;
+		TempAttributes.wModulusLengthInBit = (wTemp % 0x100) * 0x100 + (wTemp / 0x100);
 
-		dwReturn = SCardWriteFile(pCardData, szOpenPGPDir, szAlgorithmAttributes, (PBYTE) &TempAttributes, sizeof(OPENPGP_ALGORITHM_ATTRIBUTE));
+		dwReturn = OCardWriteFile(pCardData, szOpenPGPDir, szAlgorithmAttributes, (PBYTE) &TempAttributes, sizeof(OPENPGP_ALGORITHM_ATTRIBUTE));
 		if (dwReturn)
 		{
 			__leave;
@@ -407,7 +400,7 @@
 		pbCommand[6] = (BYTE) ((*pdwSecondsSince1970 % 0x1000000) / 0x10000);
 		pbCommand[7] = (BYTE) ((*pdwSecondsSince1970 % 0x10000) / 0x100);
 		pbCommand[8] = (BYTE) ((*pdwSecondsSince1970 % 0x100) / 0x1);
-		dwReturn = SCardSendCommand(pCardData, pbCommand, dwCommandSize);
+		dwReturn = OCardSendCommand(pCardData, pbCommand, dwCommandSize);
 	}
 	__finally
 	{
@@ -506,7 +499,7 @@
 			__leave;
 		}
 		pbCommand[3] = Containers[dwContainer].bSignatureTag;
-		dwReturn = SCardSendCommand(pCardData, pbCommand, dwCommandSize);
+		dwReturn = OCardSendCommand(pCardData, pbCommand, dwCommandSize);
 
 	}
 	__finally
@@ -524,7 +517,7 @@
 
 }
 
-DWORD SCardReadPublicKey(PCARD_DATA pCardData, OPENPGP_CONTAINER dwContainer, PBYTE *pbPublicKey, PDWORD pdwPublicKeySize)
+DWORD OCardReadPublicKey(PCARD_DATA pCardData, OPENPGP_CONTAINER dwContainer, PBYTE *pbPublicKey, PDWORD pdwPublicKeySize)
 {
 	DWORD dwReturn;
 	PBYTE pbData = NULL;
@@ -570,7 +563,7 @@
 			pbCmd[dwCmdSize++] = 0xFF;
 		}
 
-		dwReturn = SCardGetData(pCardData, pbCmd, dwCmdSize, &pbData, &dwResponseSize);
+		dwReturn = OCardGetData(pCardData, pbCmd, dwCmdSize, &pbData, &dwResponseSize);
 		if (dwReturn)
 		{
 			__leave;
@@ -623,7 +616,7 @@
 	return dwReturn;
 }
 
-DWORD SCardCreateKey(PCARD_DATA pCardData, OPENPGP_CONTAINER dwContainer, DWORD dwBitLen)
+DWORD OCardCreateKey(PCARD_DATA pCardData, OPENPGP_CONTAINER dwContainer, DWORD dwBitLen)
 {
 	DWORD dwReturn;
 	PBYTE pbData = NULL;
@@ -656,13 +649,13 @@
 			__leave;
 		}
 		// key len
-		dwReturn = GetKeyAlgorithmAttributes(pCardData, dwContainer, &Attributes);
+		dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, dwContainer, &Attributes);
 		if (dwReturn)
 		{
 			__leave;
 		}
-		Attributes.wModulusLength = (WORD) dwBitLen;
-		dwReturn = SetKeyAlgorithmAttributes(pCardData, dwContainer, &Attributes);
+		Attributes.wModulusLengthInBit = (WORD) dwBitLen;
+		dwReturn = OCardSetKeyAlgorithmAttributes(pCardData, dwContainer, &Attributes);
 		if (dwReturn)
 		{
 			__leave;
@@ -681,7 +674,7 @@
 			pbCmd[dwCmdSize++] = 0xFF;
 		}
 		
-		dwReturn = SCardGetData(pCardData, pbCmd, dwCmdSize, &pbData, &dwResponseSize);
+		dwReturn = OCardGetData(pCardData, pbCmd, dwCmdSize, &pbData, &dwResponseSize);
 		if (dwReturn)
 		{
 			__leave;
@@ -712,6 +705,22 @@
 										TRUE,
 										dwExponent
 										);
+		if (dwReturn)
+		{
+			__leave;
+		}
+		switch(dwContainer)
+		{
+		case Signature:
+			pContext->fHasSignature = TRUE;
+			break;
+		case Authentication:
+			pContext->fHasAuthentication = TRUE;
+			break;
+		case Confidentiality:
+			pContext->fHasDecryption = TRUE;
+			break;
+		}
 	}
 	__finally
 	{
@@ -722,7 +731,7 @@
 	return dwReturn;
 }
 
-DWORD SCardImportKey(PCARD_DATA pCardData, 
+DWORD OCardImportKey(PCARD_DATA pCardData, 
 					 OPENPGP_CONTAINER dwContainer,
 					 PBYTE pBlob,
 					 DWORD dwKeySize)
@@ -761,13 +770,13 @@
 			__leave;
 		}
 		
-		dwReturn = GetKeyAlgorithmAttributes(pCardData, dwContainer, &Attributes);
+		dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, dwContainer, &Attributes);
 		if (dwReturn)
 		{
 			__leave;
 		}
-		Attributes.wModulusLength = (WORD) pbPublicKeyBlob->rsapubkey.bitlen;
-		dwReturn = SetKeyAlgorithmAttributes(pCardData, dwContainer, &Attributes);
+		Attributes.wModulusLengthInBit = (WORD) pbPublicKeyBlob->rsapubkey.bitlen;
+		dwReturn = OCardSetKeyAlgorithmAttributes(pCardData, dwContainer, &Attributes);
 		if (dwReturn)
 		{
 			__leave;
@@ -806,7 +815,7 @@
 			pbCommand[4] = (BYTE) dwTlvSize;
 			memcpy(pbCommand + 5, pbTlv, dwTlvSize);
 		}
-		dwReturn = SCardSendCommand(pCardData, pbCommand, dwCommandSize);
+		dwReturn = OCardSendCommand(pCardData, pbCommand, dwCommandSize);
 		if (dwReturn)
 		{
 			__leave;
@@ -822,6 +831,22 @@
 										FALSE,
 										pbPublicKeyBlob->rsapubkey.pubexp
 										);
+		if (dwReturn)
+		{
+			__leave;
+		}
+		switch(dwContainer)
+		{
+		case Signature:
+			pContext->fHasSignature = TRUE;
+			break;
+		case Authentication:
+			pContext->fHasAuthentication = TRUE;
+			break;
+		case Confidentiality:
+			pContext->fHasDecryption = TRUE;
+			break;
+		}
 	}
 	__finally
 	{
@@ -840,13 +865,14 @@
 	return dwReturn;
 }
 
-DWORD SCardSign(PCARD_DATA pCardData,
+DWORD OCardSign(PCARD_DATA pCardData,
 				PCARD_SIGNING_INFO  pInfo)
 {
 	DWORD dwReturn;
 	PBYTE pbData = NULL;
 	DWORD dwCmdSize = 0, dwI;
 	POPENPGP_CONTEXT pContext;
+	OPENPGP_ALGORITHM_ATTRIBUTE Attributes;
 	BYTE pbCmd[6 + 256 + 256] = {0x00, 
 				    0x2A,
 					0x9E,
@@ -857,22 +883,37 @@
 	__try
 	{
 		Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",pInfo->bContainerIndex);
-		if (pInfo->bContainerIndex != Signature)
+		if (pInfo->dwSigningFlags & ~(CARD_PADDING_INFO_PRESENT | CARD_BUFFER_SIZE_ONLY | CRYPT_NOHASHOID | CRYPT_TYPE2_FORMAT))
 		{
-			dwReturn = SCARD_E_NO_KEY_CONTAINER;
-			Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", pInfo->bContainerIndex);
+			Trace(WINEVENT_LEVEL_ERROR, L"wrong flag %d", pInfo->dwSigningFlags);
+			dwReturn = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
-		if (CARD_PADDING_PKCS1 & pInfo->dwPaddingType)
+		if (pInfo->dwSigningFlags & CARD_PADDING_INFO_PRESENT)
 		{
-			dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
-			Trace(WINEVENT_LEVEL_ERROR, L"CARD_PADDING_PKCS1");
-			__leave;
+			if ( pInfo->dwPaddingType == CARD_PADDING_PKCS1)
+			{
+				dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
+				Trace(WINEVENT_LEVEL_ERROR, L"CARD_PADDING_PKCS1");
+				__leave;
+			}
+			else if (pInfo->dwPaddingType == CARD_PADDING_PSS)
+			{
+				dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
+				Trace(WINEVENT_LEVEL_ERROR, L"CARD_PADDING_PSS");
+				__leave;
+			}
+			else
+			{
+				dwReturn = SCARD_E_INVALID_PARAMETER;
+				Trace(WINEVENT_LEVEL_ERROR, L"pInfo->dwPaddingType = %d", pInfo->dwPaddingType);
+				__leave;
+			}
 		}
-		else if (CARD_PADDING_PSS & pInfo->dwPaddingType)
+		if (!(pInfo->aiHashAlg & ALG_CLASS_HASH))
 		{
-			dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
-			Trace(WINEVENT_LEVEL_ERROR, L"CARD_PADDING_PSS");
+			dwReturn = SCARD_E_INVALID_PARAMETER;
+			Trace(WINEVENT_LEVEL_ERROR, L"pInfo->aiHashAlg == %d", pInfo->aiHashAlg);
 			__leave;
 		}
 		for(dwI = 0 ; dwI < dwSignatureAlgorithmCount ; dwI++)
@@ -886,13 +927,35 @@
 		if (dwI >= dwSignatureAlgorithmCount)
 		{
 			Trace(WINEVENT_LEVEL_ERROR, L"alg not found %d", pInfo->aiHashAlg);
+			dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
 			__leave;
 		}
 		if (SignatureAlgorithm[dwI].dwHashSize != pInfo->cbData)
 		{
 			Trace(WINEVENT_LEVEL_ERROR, L"wrong hash size %d", pInfo->cbData);
+			dwReturn = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
+		if (pInfo->bContainerIndex != Signature)
+		{
+			dwReturn = SCARD_E_NO_KEY_CONTAINER;
+			Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", pInfo->bContainerIndex);
+			__leave;
+		}
+		if (pInfo->dwSigningFlags & CARD_BUFFER_SIZE_ONLY)
+		{
+			// optimisation :
+			// return the buffer size only
+			dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, Signature, &Attributes);
+			if (dwReturn)
+			{
+				__leave;
+			}
+			pInfo->cbSignedData = Attributes.wModulusLengthInBit/8;
+			dwReturn = 0;
+			__leave;
+		}
+
 		pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
 
 		dwCmdSize = 5;
@@ -920,7 +983,7 @@
 		{
 			pbCmd[dwCmdSize++] = 0;
 		}
-		dwReturn = SCardGetData(pCardData, pbCmd, dwCmdSize, &(pInfo->pbSignedData), &(pInfo->cbSignedData));
+		dwReturn = OCardGetData(pCardData, pbCmd, dwCmdSize, &(pInfo->pbSignedData), &(pInfo->cbSignedData));
 		if (dwReturn == SCARD_W_WRONG_CHV)
 		{
 			dwReturn = SCARD_W_SECURITY_VIOLATION;
@@ -950,13 +1013,14 @@
 	return dwReturn;
 }
 
-DWORD SCardAuthenticate(PCARD_DATA pCardData,
+DWORD OCardAuthenticate(PCARD_DATA pCardData,
 				PCARD_SIGNING_INFO  pInfo)
 {
 	DWORD dwReturn;
 	PBYTE pbData = NULL;
 	DWORD dwCmdSize = 0, dwI;
 	POPENPGP_CONTEXT pContext;
+	OPENPGP_ALGORITHM_ATTRIBUTE Attributes;
 	BYTE pbCmd[6 + 256 + 256] = {0x00, 
 				    0x88,
 					0x00,
@@ -967,24 +1031,33 @@
 	__try
 	{
 		Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",pInfo->bContainerIndex);
-		if (pInfo->bContainerIndex != Authentication)
+		if (pInfo->dwSigningFlags & ~(CARD_PADDING_INFO_PRESENT | CARD_BUFFER_SIZE_ONLY | CRYPT_NOHASHOID | CRYPT_TYPE2_FORMAT))
 		{
-			dwReturn = SCARD_E_NO_KEY_CONTAINER;
-			Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", pInfo->bContainerIndex);
+			Trace(WINEVENT_LEVEL_ERROR, L"wrong flag %d", pInfo->dwSigningFlags);
+			dwReturn = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
-		if (CARD_PADDING_PKCS1 & pInfo->dwPaddingType)
+		if (pInfo->dwSigningFlags & CARD_PADDING_INFO_PRESENT)
 		{
-			dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
-			Trace(WINEVENT_LEVEL_ERROR, L"CARD_PADDING_PKCS1");
-			__leave;
+			if ( pInfo->dwPaddingType == CARD_PADDING_PKCS1)
+			{
+				dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
+				Trace(WINEVENT_LEVEL_ERROR, L"CARD_PADDING_PKCS1");
+				__leave;
+			}
+			else if (pInfo->dwPaddingType == CARD_PADDING_PSS)
+			{
+				dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
+				Trace(WINEVENT_LEVEL_ERROR, L"CARD_PADDING_PSS");
+				__leave;
+			}
+			else
+			{
+				dwReturn = SCARD_E_INVALID_PARAMETER;
+				Trace(WINEVENT_LEVEL_ERROR, L"pInfo->dwPaddingType = %d", pInfo->dwPaddingType);
+				__leave;
+			}
 		}
-		else if (CARD_PADDING_PSS & pInfo->dwPaddingType)
-		{
-			dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
-			Trace(WINEVENT_LEVEL_ERROR, L"CARD_PADDING_PSS");
-			__leave;
-		}
 		for(dwI = 0 ; dwI < dwSignatureAlgorithmCount ; dwI++)
 		{
 			if (SignatureAlgorithm[dwI].aiHashAlg == pInfo->aiHashAlg)
@@ -1003,6 +1076,26 @@
 			Trace(WINEVENT_LEVEL_ERROR, L"wrong hash size %d", pInfo->cbData);
 			__leave;
 		}
+		if (pInfo->bContainerIndex != Authentication)
+		{
+			dwReturn = SCARD_E_NO_KEY_CONTAINER;
+			Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", pInfo->bContainerIndex);
+			__leave;
+		}
+		if (pInfo->dwSigningFlags & CARD_BUFFER_SIZE_ONLY)
+		{
+			// optimisation :
+			// return the buffer size only
+			dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, Signature, &Attributes);
+			if (dwReturn)
+			{
+				__leave;
+			}
+			pInfo->cbSignedData = Attributes.wModulusLengthInBit/8;
+			dwReturn = 0;
+			__leave;
+		}
+
 		pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
 
 		dwCmdSize = 5;
@@ -1030,7 +1123,7 @@
 		{
 			pbCmd[dwCmdSize++] = 0;
 		}
-		dwReturn = SCardGetData(pCardData, pbCmd, dwCmdSize, &(pInfo->pbSignedData), &(pInfo->cbSignedData));
+		dwReturn = OCardGetData(pCardData, pbCmd, dwCmdSize, &(pInfo->pbSignedData), &(pInfo->cbSignedData));
 		if (dwReturn == SCARD_W_WRONG_CHV)
 		{
 			dwReturn = SCARD_W_SECURITY_VIOLATION;
@@ -1060,7 +1153,7 @@
 	return dwReturn;
 }
 
-DWORD SCardDecrypt(PCARD_DATA pCardData,
+DWORD OCardDecrypt(PCARD_DATA pCardData,
 				PCARD_RSA_DECRYPT_INFO  pInfo)
 {
 	DWORD dwReturn;
@@ -1074,6 +1167,7 @@
 					};
 	POPENPGP_CONTEXT pContext;
 	DWORD dwI;
+	OPENPGP_ALGORITHM_ATTRIBUTE Attributes;
 	__try
 	{
 		Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",pInfo->bContainerIndex);
@@ -1089,6 +1183,18 @@
 			Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", pInfo->bContainerIndex);
 			__leave;
 		}
+		// check the buffer size
+		dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, Confidentiality, &Attributes);
+		if (dwReturn)
+		{
+			__leave;
+		}
+		if (pInfo->cbData < (DWORD)(Attributes.wModulusLengthInBit/8))
+		{
+			dwReturn = SCARD_E_INSUFFICIENT_BUFFER;
+			Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_INSUFFICIENT_BUFFER %d", pInfo->cbData);
+			__leave;
+		}
 		pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
 		dwCmdSize = 5;
 		if (pContext->fExtentedLeLcFields)
@@ -1116,7 +1222,7 @@
 		{
 			pbCmd[dwCmdSize++] = 0;
 		}
-		dwReturn = SCardGetData(pCardData, pbCmd, dwCmdSize, &pbData, &dwResponseSize);
+		dwReturn = OCardGetData(pCardData, pbCmd, dwCmdSize, &pbData, &dwResponseSize);
 		if (dwReturn)
 		{
 			__leave;
@@ -1158,44 +1264,91 @@
 }
 
 
-DWORD GetPinInfo(DWORD __in dwPinIndex, __inout PPIN_INFO pPinInfo)
+DWORD OCardReadContainerMapFile(__in PCARD_DATA  pCardData, 
+					__in PBYTE* ppbResponse, __in PDWORD pdwResponseSize)
 {
-	DWORD dwReturn=0;
+	DWORD dwReturn = 0;
+	POPENPGP_CONTEXT pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
+	OPENPGP_ALGORITHM_ATTRIBUTE Attributes;
 	__try
 	{
-		Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwPinIndex=%d",dwPinIndex);
-		switch(dwPinIndex)
+		PCONTAINER_MAP_RECORD pContainer = NULL;
+		BOOL fIsDefaultContainerSet = FALSE;
+		*pdwResponseSize = sizeof(CONTAINER_MAP_RECORD) * MaxContainer;
+		*ppbResponse = pCardData->pfnCspAlloc(*pdwResponseSize);
+		if (! *ppbResponse )
 		{
-		case ROLE_SIGNATURE:
-			pPinInfo->PinType = AlphaNumericPinType;
-			pPinInfo->PinPurpose = DigitalSignaturePin;
-			pPinInfo->dwChangePermission = PIN_CHANGE_FLAG_CHANGEPIN;
-			pPinInfo->PinCachePolicy.dwVersion = PIN_CACHE_POLICY_CURRENT_VERSION;
-			pPinInfo->PinCachePolicy.PinCachePolicyType = PinCacheAlwaysPrompt;
-			break;
-		case ROLE_AUTHENTICATION:
-			pPinInfo->PinType = AlphaNumericPinType;
-			pPinInfo->PinPurpose = AuthenticationPin;
-			pPinInfo->dwChangePermission = PIN_CHANGE_FLAG_CHANGEPIN;
-			pPinInfo->PinCachePolicy.dwVersion = PIN_CACHE_POLICY_CURRENT_VERSION;
-			pPinInfo->PinCachePolicy.PinCachePolicyType = PinCacheAlwaysPrompt;
-			break;
-		case ROLE_CONFIDENTIALITY:
-			pPinInfo->PinType = AlphaNumericPinType;
-			pPinInfo->PinPurpose = EncryptionPin;
-			pPinInfo->dwChangePermission = PIN_CHANGE_FLAG_CHANGEPIN;
-			pPinInfo->PinCachePolicy.dwVersion = PIN_CACHE_POLICY_CURRENT_VERSION;
-			pPinInfo->PinCachePolicy.PinCachePolicyType = PinCacheAlwaysPrompt;
-			break;
-		default:
-			Trace(WINEVENT_LEVEL_ERROR, L"dwPinIndex == %d", dwPinIndex);
-			dwReturn  = SCARD_E_INVALID_PARAMETER ;
+			dwReturn = SCARD_E_NO_MEMORY;
+			Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_MEMORY");
 			__leave;
 		}
+		pContainer = (PCONTAINER_MAP_RECORD) *ppbResponse;
+		memset(pContainer,0,sizeof(CONTAINER_MAP_RECORD) * 3);
+		
+		dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, Authentication, &Attributes);
+		if (dwReturn)
+		{
+			__leave;
+		}
+		pContainer[Authentication].wSigKeySizeBits = Attributes.wModulusLengthInBit;
+		swprintf_s(pContainer[Authentication].wszGuid,MAX_CONTAINER_NAME_LEN + 1,
+			L"OPENPGP_%02X%02X_%02X%02X_%02X%02X%02X%02X_Authenticate",
+			pContext->Aid.AidVersion[0],pContext->Aid.AidVersion[1],
+			pContext->Aid.AidManufacturer[0],pContext->Aid.AidManufacturer[1],
+			pContext->Aid.AidSerialNumber[0],pContext->Aid.AidSerialNumber[1],
+			pContext->Aid.AidSerialNumber[2],pContext->Aid.AidSerialNumber[3]);
+		if (pContext->fHasAuthentication)
+		{
+			pContainer[Authentication].bFlags = CONTAINER_MAP_VALID_CONTAINER | CONTAINER_MAP_DEFAULT_CONTAINER;
+			fIsDefaultContainerSet = TRUE;
+		}
+		dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, Signature, &Attributes);
+		if (dwReturn)
+		{
+			__leave;
+		}
+		pContainer[Signature].wSigKeySizeBits = Attributes.wModulusLengthInBit;
+		swprintf_s(pContainer[Signature].wszGuid,MAX_CONTAINER_NAME_LEN + 1,
+			L"OPENPGP_%02X%02X_%02X%02X_%02X%02X%02X%02X_Signature",
+			pContext->Aid.AidVersion[0],pContext->Aid.AidVersion[1],
+			pContext->Aid.AidManufacturer[0],pContext->Aid.AidManufacturer[1],
+			pContext->Aid.AidSerialNumber[0],pContext->Aid.AidSerialNumber[1],
+			pContext->Aid.AidSerialNumber[2],pContext->Aid.AidSerialNumber[3]);
+		if (pContext->fHasSignature)
+		{
+			pContainer[Signature].bFlags = CONTAINER_MAP_VALID_CONTAINER;
+			if (!fIsDefaultContainerSet)
+			{
+				pContainer[Signature].bFlags |= CONTAINER_MAP_DEFAULT_CONTAINER;
+				fIsDefaultContainerSet = TRUE;
+			}
+		}
+		
+		dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, Confidentiality, &Attributes);
+		if (dwReturn)
+		{
+			__leave;
+		}
+		pContainer[Confidentiality].wKeyExchangeKeySizeBits = Attributes.wModulusLengthInBit;
+		
+		swprintf_s(pContainer[Confidentiality].wszGuid,MAX_CONTAINER_NAME_LEN + 1,
+			L"OPENPGP_%02X%02X_%02X%02X_%02X%02X%02X%02X_Confidential",
+			pContext->Aid.AidVersion[0],pContext->Aid.AidVersion[1],
+			pContext->Aid.AidManufacturer[0],pContext->Aid.AidManufacturer[1],
+			pContext->Aid.AidSerialNumber[0],pContext->Aid.AidSerialNumber[1],
+			pContext->Aid.AidSerialNumber[2],pContext->Aid.AidSerialNumber[3]);
+		if (pContext->fHasDecryption)
+		{
+			pContainer[Confidentiality].bFlags = CONTAINER_MAP_VALID_CONTAINER;
+			if (!fIsDefaultContainerSet)
+			{
+				pContainer[Confidentiality].bFlags |= CONTAINER_MAP_DEFAULT_CONTAINER;
+				fIsDefaultContainerSet = TRUE;
+			}
+		}
 	}
 	__finally
 	{
 	}
-	Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
 	return dwReturn;
 }
\ No newline at end of file

Modified: trunk/OpenPGPminidriver/CryptoOperations.h
===================================================================
--- trunk/OpenPGPminidriver/CryptoOperations.h	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriver/CryptoOperations.h	2010-03-11 20:32:26 UTC (rev 8)
@@ -38,24 +38,33 @@
 #define OPENPGP_SUPPORTED_CYPHER_ALGORITHM L"\0"
 #define OPENPGP_SUPPORTED_ASYMETRIC_ALGORITHM L"RSA\0"
 
-DWORD SCardReadPublicKey(PCARD_DATA  pCardData, 
+#pragma pack(push,1)
+typedef struct _OPENPGP_ALGORITHM_ATTRIBUTE
+{
+	BYTE bAlgoId;
+	unsigned short wModulusLengthInBit;
+	unsigned short wExponentLengthInBit;
+	BYTE bFormat;
+} OPENPGP_ALGORITHM_ATTRIBUTE, *POPENPGP_ALGORITHM_ATTRIBUTE;
+#pragma pack(pop)
+
+DWORD OCardReadPublicKey(PCARD_DATA  pCardData, 
 						 OPENPGP_CONTAINER dwContainer, 
 						 PBYTE *pbPublicKey, PDWORD pdwPublicKeySize);
 
-DWORD SCardCreateKey(PCARD_DATA pCardData, OPENPGP_CONTAINER dwContainer, DWORD dwBitLen);
+DWORD OCardCreateKey(PCARD_DATA pCardData, OPENPGP_CONTAINER dwContainer, DWORD dwBitLen);
 
-DWORD SCardImportKey(PCARD_DATA pCardData, 
+DWORD OCardImportKey(PCARD_DATA pCardData, 
 					 OPENPGP_CONTAINER dwContainer,
 					 PBYTE pBlob,
 					 DWORD dwKeySize);
 
-DWORD SCardSign(PCARD_DATA  pCardData,
+DWORD OCardSign(PCARD_DATA  pCardData,
 				PCARD_SIGNING_INFO  pInfo);
 
-DWORD SCardAuthenticate(PCARD_DATA pCardData,
+DWORD OCardAuthenticate(PCARD_DATA pCardData,
 				PCARD_SIGNING_INFO  pInfo);
 
-DWORD SCardDecrypt(PCARD_DATA  pCardData,
+DWORD OCardDecrypt(PCARD_DATA  pCardData,
 				PCARD_RSA_DECRYPT_INFO  pInfo);
 
-DWORD GetPinInfo(DWORD __in bContainerIndex, __inout PPIN_INFO pPinInfo);
\ No newline at end of file

Modified: trunk/OpenPGPminidriver/PinOperations.c
===================================================================
--- trunk/OpenPGPminidriver/PinOperations.c	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriver/PinOperations.c	2010-03-11 20:32:26 UTC (rev 8)
@@ -41,6 +41,7 @@
 		case ROLE_CONFIDENTIALITY:
 			dwMinPinSize = 6;
 		case ROLE_PUK:
+			dwMinPinSize = 1;
 			break;
 		case ROLE_ADMIN:
 			dwMinPinSize = 8;
@@ -56,7 +57,11 @@
 			__leave;
 		}
 		// check in status DO
-		dwReturn = SCardReadFile(pCardData, szOpenPGPDir, szOpenPGPStatus, &pbResponse, &dwSize);
+		dwReturn = OCardReadFile(pCardData, szOpenPGPDir, szOpenPGPStatus, &pbResponse, &dwSize);
+		if (dwReturn)
+		{
+			__leave;
+		}
 		switch(PinId)
 		{
 		case ROLE_SIGNATURE:
@@ -97,7 +102,7 @@
 	__try
 	{
 		Trace(WINEVENT_LEVEL_VERBOSE, L"Enter PinId=%d",PinId);
-		dwReturn = SCardReadFile(pCardData, szOpenPGPDir, szOpenPGPStatus, &pbResponse, &dwSize);
+		dwReturn = OCardReadFile(pCardData, szOpenPGPDir, szOpenPGPStatus, &pbResponse, &dwSize);
 		switch(PinId)
 		{
 		case ROLE_SIGNATURE:
@@ -159,18 +164,13 @@
 		}
 		pbCmd[4] = (BYTE) cbPin;
 		memcpy(pbCmd + 5, pbPin, cbPin);
-		dwReturn = SCardSendCommand(pCardData, pbCmd, 5 + cbPin);
+		dwReturn = OCardSendCommand(pCardData, pbCmd, 5 + cbPin);
 		if (dwReturn)
 		{
+			Trace(WINEVENT_LEVEL_VERBOSE, L"Authentication failed");
 			__leave;
 		}
-		/*switch(PinId)
-		{
-			case ROLE_AUTHENTICATION:
-			case ROLE_CONFIDENTIALITY:
-				dwReturn = VerifyPIN(pCardData, ROLE_SIGNATURE, pbPin, cbPin);
-				break;
-		}*/
+		Trace(WINEVENT_LEVEL_VERBOSE, L"Authentication successfull");
 			
 	}
 	__finally
@@ -197,6 +197,13 @@
 	__try
 	{
 		Trace(WINEVENT_LEVEL_VERBOSE, L"Enter PinId=%d",PinId);
+		dwReturn = CheckPinLength(pCardData, PinId, cbNewPin);
+		if (dwReturn)
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"Invalid len %d",cbNewPin);
+			dwReturn = SCARD_E_INVALID_PARAMETER;
+			__leave;
+		}
 		dwReturn = CheckPinLength(pCardData, PinId, cbOldPin);
 		if (dwReturn)
 		{
@@ -222,7 +229,7 @@
 		pbCmd[4] = (BYTE) (cbOldPin + cbNewPin);
 		memcpy(pbCmd + 5, pbOldPin, cbOldPin);
 		memcpy(pbCmd + 5 + cbOldPin, pbNewPin, cbNewPin);
-		dwReturn = SCardSendCommand(pCardData, pbCmd, 5 + cbOldPin + cbNewPin);
+		dwReturn = OCardSendCommand(pCardData, pbCmd, 5 + cbOldPin + cbNewPin);
 	}
 	__finally
 	{
@@ -249,16 +256,23 @@
 	__try
 	{
 		Trace(WINEVENT_LEVEL_VERBOSE, L"Enter PinId=%d",PinId);
+		dwReturn = CheckPinLength(pCardData, ROLE_USER, cbNewPin);
+		if (dwReturn)
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"Invalid len %d",cbNewPin);
+			dwReturn = SCARD_E_INVALID_PARAMETER;
+			__leave;
+		}
 		switch(PinId)
 		{
 		case ROLE_ADMIN:
 			// authenticate the admin
 			dwReturn = VerifyPIN(pCardData, PinId, pbAuthenticator, cbAuthenticator);
-			if (!dwReturn)
+			if (dwReturn)
 			{
-				return dwReturn;
+				__leave;
 			}
-			pbCmd[4] = (BYTE) cbAuthenticator;
+			pbCmd[4] = (BYTE) cbNewPin;
 			memcpy(pbCmd + 5, pbNewPin, cbNewPin);
 			dwCmdSize = 5 + cbNewPin;
 			break;
@@ -267,7 +281,7 @@
 			if (dwReturn)
 			{
 				__leave;
-			}
+			}	
 			pbCmd[2] = 0x00;
 			pbCmd[4] = (BYTE) (cbAuthenticator + cbNewPin);
 			memcpy(pbCmd + 5, pbAuthenticator, cbAuthenticator);
@@ -278,7 +292,7 @@
 			dwReturn = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
-		dwReturn = SCardSendCommand(pCardData, pbCmd, dwCmdSize);
+		dwReturn = OCardSendCommand(pCardData, pbCmd, dwCmdSize);
 	}
 	__finally
 	{
@@ -287,6 +301,35 @@
 	return dwReturn;
 }
 
+DWORD SetPUK(__in PCARD_DATA  pCardData,
+				__in_bcount(cbPin) PBYTE  pbAdminPin, __in DWORD  cbAdminPin,
+				__in_bcount(cbPin) PBYTE  pbPuk, __in DWORD  cbPuk
+				)
+{
+	DWORD dwReturn;
+	Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
+	__try
+	{
+		dwReturn = CheckPinLength(pCardData, ROLE_PUK, cbPuk);
+		if (dwReturn)
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"Invalid len %d",cbPuk);
+			dwReturn = SCARD_E_INVALID_PARAMETER;
+			__leave;
+		}
+		dwReturn = VerifyPIN(pCardData, ROLE_ADMIN, pbAdminPin, cbAdminPin);
+		if (dwReturn)
+		{
+			__leave;
+		}
+		dwReturn = OCardWriteFile(pCardData, szOpenPGPDir, szOpenPGPPUK, pbPuk, cbPuk);
+	}
+	__finally
+	{
+	}
+	return dwReturn;
+}
+
 DWORD Deauthenticate(__in PCARD_DATA  pCardData)
 {
 	DWORD     dwAP;
@@ -298,14 +341,13 @@
 		dwReturn = SCardReconnect(pCardData->hScard,
                          SCARD_SHARE_SHARED,
                          SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1,
-                         SCARD_LEAVE_CARD,
+                         SCARD_RESET_CARD,
                          &dwAP );
 		if (dwReturn)
 		{
-			Trace(WINEVENT_LEVEL_ERROR, L"SCardControl 0x%08X", dwReturn);
+			Trace(WINEVENT_LEVEL_ERROR, L"SCardReconnect 0x%08X", dwReturn);
 			__leave;
 		}
-		// regain the ownership of a transaction
 		dwReturn = SCardBeginTransaction(pCardData->hScard);
 		if (dwReturn)
 		{
@@ -318,4 +360,88 @@
 	{
 	}
 	return dwReturn;
+}
+
+
+DWORD GetPinInfo(DWORD __in dwPinIndex, __inout PPIN_INFO pPinInfo)
+{
+	DWORD dwReturn=0, dwVersion;
+	__try
+	{
+		Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwPinIndex=%d",dwPinIndex);
+		dwVersion = (pPinInfo->dwVersion == 0) ? PIN_INFO_CURRENT_VERSION : pPinInfo->dwVersion;
+		if ( dwVersion != PIN_INFO_CURRENT_VERSION )
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"dwVersion %d", dwVersion);
+			dwReturn  = ERROR_REVISION_MISMATCH;
+			__leave;
+		}
+		pPinInfo->dwVersion = dwVersion;
+		switch(dwPinIndex)
+		{
+		case ROLE_SIGNATURE:
+			pPinInfo->PinType = AlphaNumericPinType;
+			pPinInfo->PinPurpose = DigitalSignaturePin;
+			pPinInfo->dwChangePermission = CREATE_PIN_SET(ROLE_SIGNATURE);
+			SET_PIN(pPinInfo->dwChangePermission, ROLE_AUTHENTICATION);
+			SET_PIN(pPinInfo->dwChangePermission, ROLE_CONFIDENTIALITY);
+			pPinInfo->dwUnblockPermission = CREATE_PIN_SET(ROLE_ADMIN);
+			SET_PIN(pPinInfo->dwUnblockPermission, ROLE_PUK);
+			pPinInfo->PinCachePolicy.dwVersion = PIN_CACHE_POLICY_CURRENT_VERSION;
+			pPinInfo->PinCachePolicy.PinCachePolicyType = PinCacheNormal;
+			pPinInfo->dwFlags = 0;
+			break;
+		case ROLE_AUTHENTICATION:
+			pPinInfo->PinType = AlphaNumericPinType;
+			pPinInfo->PinPurpose = AuthenticationPin;
+			pPinInfo->dwChangePermission = CREATE_PIN_SET(ROLE_SIGNATURE);
+			SET_PIN(pPinInfo->dwChangePermission, ROLE_AUTHENTICATION);
+			SET_PIN(pPinInfo->dwChangePermission, ROLE_CONFIDENTIALITY);
+			pPinInfo->dwUnblockPermission = CREATE_PIN_SET(ROLE_ADMIN);
+			SET_PIN(pPinInfo->dwUnblockPermission, ROLE_PUK);
+			pPinInfo->PinCachePolicy.dwVersion = PIN_CACHE_POLICY_CURRENT_VERSION;
+			pPinInfo->PinCachePolicy.PinCachePolicyType = PinCacheNormal;
+			pPinInfo->dwFlags = 0;
+			break;
+		case ROLE_CONFIDENTIALITY:
+			pPinInfo->PinType = AlphaNumericPinType;
+			pPinInfo->PinPurpose = EncryptionPin;
+			pPinInfo->dwChangePermission = CREATE_PIN_SET(ROLE_SIGNATURE);
+			SET_PIN(pPinInfo->dwChangePermission, ROLE_AUTHENTICATION);
+			SET_PIN(pPinInfo->dwChangePermission, ROLE_CONFIDENTIALITY);
+			pPinInfo->dwUnblockPermission = CREATE_PIN_SET(ROLE_ADMIN);
+			SET_PIN(pPinInfo->dwUnblockPermission, ROLE_PUK);
+			pPinInfo->PinCachePolicy.dwVersion = PIN_CACHE_POLICY_CURRENT_VERSION;
+			pPinInfo->PinCachePolicy.PinCachePolicyType = PinCacheNormal;
+			pPinInfo->dwFlags = 0;
+			break;
+		case ROLE_ADMIN:
+			pPinInfo->PinType = AlphaNumericPinType;
+			pPinInfo->PinPurpose = AdministratorPin;
+			pPinInfo->dwChangePermission = CREATE_PIN_SET(ROLE_ADMIN);
+			pPinInfo->dwUnblockPermission = 0;
+			pPinInfo->PinCachePolicy.dwVersion = PIN_CACHE_POLICY_CURRENT_VERSION;
+			pPinInfo->PinCachePolicy.PinCachePolicyType = PinCacheNormal;
+			pPinInfo->dwFlags = 0;
+			break;
+		case ROLE_PUK:
+			pPinInfo->PinType = AlphaNumericPinType;
+			pPinInfo->PinPurpose = UnblockOnlyPin;
+			pPinInfo->dwChangePermission = CREATE_PIN_SET(ROLE_ADMIN);
+			pPinInfo->dwUnblockPermission = 0;
+			pPinInfo->PinCachePolicy.dwVersion = PIN_CACHE_POLICY_CURRENT_VERSION;
+			pPinInfo->PinCachePolicy.PinCachePolicyType = PinCacheNormal;
+			pPinInfo->dwFlags = 0;
+			break;
+		default:
+			Trace(WINEVENT_LEVEL_ERROR, L"dwPinIndex == %d", dwPinIndex);
+			dwReturn  = SCARD_E_INVALID_PARAMETER ;
+			__leave;
+		}
+	}
+	__finally
+	{
+	}
+	Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
+	return dwReturn;
 }
\ No newline at end of file

Modified: trunk/OpenPGPminidriver/PinOperations.h
===================================================================
--- trunk/OpenPGPminidriver/PinOperations.h	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriver/PinOperations.h	2010-03-11 20:32:26 UTC (rev 8)
@@ -34,4 +34,9 @@
 				__in_bcount(cbPin) PBYTE  pbAuthenticator, __in DWORD  cbAuthenticator,
 				__in_bcount(cbPin) PBYTE  pbNewPin, __in DWORD  cbNewPin
 				);
-DWORD Deauthenticate(__in PCARD_DATA  pCardData);
\ No newline at end of file
+DWORD SetPUK(__in PCARD_DATA  pCardData, 
+				__in_bcount(cbPin) PBYTE  pbAdminPin, __in DWORD  cbAdminPin,
+				__in_bcount(cbPin) PBYTE  pbPuk, __in DWORD  cbPuk
+				);
+DWORD Deauthenticate(__in PCARD_DATA  pCardData);
+DWORD GetPinInfo(DWORD __in bContainerIndex, __inout PPIN_INFO pPinInfo);

Modified: trunk/OpenPGPminidriver/PublicDataOperations.c
===================================================================
--- trunk/OpenPGPminidriver/PublicDataOperations.c	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriver/PublicDataOperations.c	2010-03-11 20:32:26 UTC (rev 8)
@@ -60,6 +60,7 @@
 	{szOpenPGPDir, szOpenPGPAlgoAttributesSignature, StoredOnSmartCard, 0x6E, 0xC1, UnknownAc},
 	{szOpenPGPDir, szOpenPGPAlgoAttributesDecryption, StoredOnSmartCard, 0x6E, 0xC2,UnknownAc},
 	{szOpenPGPDir, szOpenPGPAlgoAttributesAuthentication, StoredOnSmartCard, 0x6E, 0xC3, UnknownAc },
+	{szOpenPGPDir, szOpenPGPPUK, StoredOnSmartCard, 0xD3, 0, UnknownAc },
 	{NULL, szCARD_IDENTIFIER_FILE, StoredOnSmartCard, 0x4F, 0, EveryoneReadAdminWriteAc},
 	{NULL, szCARD_APPLICATION_FILE, Virtual, 0, 0, EveryoneReadAdminWriteAc},
 	{NULL, szCACHE_FILE, Virtual, 0, 0, EveryoneReadUserWriteAc},
@@ -70,7 +71,7 @@
 
 DWORD dwFileCount = ARRAYSIZE(Files);
 
-DWORD SCardDirectoryList(__in PCARD_DATA  pCardData, 
+DWORD OCardDirectoryList(__in PCARD_DATA  pCardData, 
 					__in PBYTE* pbResponse, __in_opt PDWORD pdwResponseSize)
 {
 	// hardcoded
@@ -84,8 +85,9 @@
 	return 0;
 }
 
+
 // read file
-DWORD SCardReadFile(__in PCARD_DATA  pCardData, 
+DWORD OCardReadFile(__in PCARD_DATA  pCardData, 
 					__in_opt PSTR szDirectory, __in PSTR szFile,
 					__in PBYTE* ppbResponse, __in PDWORD pdwResponseSize)
 {
@@ -109,12 +111,12 @@
 			}
 			else
 			{
-				if (Files[dwI].szDirectory && strcmp(szDirectory, Files[dwI].szDirectory) == 0) fMatch = TRUE;
+				if (Files[dwI].szDirectory && _stricmp(szDirectory, Files[dwI].szDirectory) == 0) fMatch = TRUE;
 			}
 			if (fMatch)
 			{
 				fDirectoryFound = TRUE;
-				if (strcmp(szFile, Files[dwI].szFile) == 0)
+				if (_stricmp(szFile, Files[dwI].szFile) == 0)
 				{
 					fFileFound = TRUE;
 					break;
@@ -139,7 +141,7 @@
 		{
 			pbCmd[2] = (BYTE) (Files[dwI].dwTag / 0x100);
 			pbCmd[3] = (BYTE) (Files[dwI].dwTag % 0x100);
-			dwReturn = SCardGetData(pCardData, pbCmd, dwCmdSize, &pbData, pdwResponseSize);
+			dwReturn = OCardGetData(pCardData, pbCmd, dwCmdSize, &pbData, pdwResponseSize);
 			if (dwReturn)
 			{
 				__leave;
@@ -175,11 +177,11 @@
 		{
 			if (szDirectory == NULL)
 			{
-				if (strcmp(szFile, szCARD_APPLICATION_FILE) == 0)
+				if (_stricmp(szFile, szCARD_APPLICATION_FILE) == 0)
 				{
-					dwReturn = SCardDirectoryList(pCardData, ppbResponse, pdwResponseSize);
+					dwReturn = OCardDirectoryList(pCardData, ppbResponse, pdwResponseSize);
 				}
-				else if (strcmp(szFile, szCACHE_FILE) == 0)
+				else if (_stricmp(szFile, szCACHE_FILE) == 0)
 				{
 					*pdwResponseSize = sizeof(CARD_CACHE_FILE_FORMAT);
 					*ppbResponse = pCardData->pfnCspAlloc(*pdwResponseSize);
@@ -191,45 +193,11 @@
 					Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_FILE_NOT_FOUND %S",szFile);
 				}
 			}
-			else if (strcmp(szDirectory,szBASE_CSP_DIR) == 0)
+			else if (_stricmp(szDirectory,szBASE_CSP_DIR) == 0)
 			{
-				if (strcmp(szFile, szCONTAINER_MAP_FILE) == 0)
+				if (_stricmp(szFile, szCONTAINER_MAP_FILE) == 0)
 				{
-					PCONTAINER_MAP_RECORD pContainer = NULL;
-					*pdwResponseSize = sizeof(CONTAINER_MAP_RECORD) * MaxContainer;
-					*ppbResponse = pCardData->pfnCspAlloc(*pdwResponseSize);
-					if (! *ppbResponse )
-					{
-						dwReturn = SCARD_E_NO_MEMORY;
-						Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_MEMORY");
-						__leave;
-					}
-					pContainer = (PCONTAINER_MAP_RECORD) *ppbResponse;
-					memset(pContainer,0,sizeof(CONTAINER_MAP_RECORD) * 3);
-					swprintf_s(pContainer[Signature].wszGuid,MAX_CONTAINER_NAME_LEN + 1,
-						L"OPENPGP_%02X%02X_%02X%02X_%02X%02X%02X%02X_Signature",
-						pContext->Aid.AidVersion[0],pContext->Aid.AidVersion[1],
-						pContext->Aid.AidManufacturer[0],pContext->Aid.AidManufacturer[1],
-						pContext->Aid.AidSerialNumber[0],pContext->Aid.AidSerialNumber[1],
-						pContext->Aid.AidSerialNumber[2],pContext->Aid.AidSerialNumber[3]);
-					pContainer[Signature].bFlags = CONTAINER_MAP_VALID_CONTAINER;
-					pContainer[Signature].wSigKeySizeBits = 1024;
-					swprintf_s(pContainer[Authentication].wszGuid,MAX_CONTAINER_NAME_LEN + 1,
-						L"OPENPGP_%02X%02X_%02X%02X_%02X%02X%02X%02X_Authenticate",
-						pContext->Aid.AidVersion[0],pContext->Aid.AidVersion[1],
-						pContext->Aid.AidManufacturer[0],pContext->Aid.AidManufacturer[1],
-						pContext->Aid.AidSerialNumber[0],pContext->Aid.AidSerialNumber[1],
-						pContext->Aid.AidSerialNumber[2],pContext->Aid.AidSerialNumber[3]);
-					pContainer[Authentication].bFlags = CONTAINER_MAP_VALID_CONTAINER | CONTAINER_MAP_DEFAULT_CONTAINER;
-					pContainer[Authentication].wSigKeySizeBits = 1024;
-					swprintf_s(pContainer[Confidentiality].wszGuid,MAX_CONTAINER_NAME_LEN + 1,
-						L"OPENPGP_%02X%02X_%02X%02X_%02X%02X%02X%02X_Confidential",
-						pContext->Aid.AidVersion[0],pContext->Aid.AidVersion[1],
-						pContext->Aid.AidManufacturer[0],pContext->Aid.AidManufacturer[1],
-						pContext->Aid.AidSerialNumber[0],pContext->Aid.AidSerialNumber[1],
-						pContext->Aid.AidSerialNumber[2],pContext->Aid.AidSerialNumber[3]);
-					pContainer[Confidentiality].bFlags = CONTAINER_MAP_VALID_CONTAINER;
-					pContainer[Confidentiality].wKeyExchangeKeySizeBits = 1024;
+					dwReturn = OCardReadContainerMapFile(pCardData, ppbResponse, pdwResponseSize);
 				}
 				else
 				{
@@ -260,7 +228,7 @@
 	return dwReturn;
 }
 
-DWORD SCardEnumFile(__in PCARD_DATA  pCardData, 
+DWORD OCardEnumFile(__in PCARD_DATA  pCardData, 
 					__in_opt PSTR szDirectory,
 					__in PBYTE* pbResponse, __in PDWORD pdwResponseSize)
 {
@@ -281,7 +249,7 @@
 			}
 			else
 			{
-				if (Files[dwI].szDirectory && strcmp(szDirectory, Files[dwI].szDirectory) == 0) fMatch = TRUE;
+				if (Files[dwI].szDirectory && _stricmp(szDirectory, Files[dwI].szDirectory) == 0) fMatch = TRUE;
 			}
 			if (fMatch)
 			{
@@ -292,7 +260,7 @@
 					PBYTE pbData = NULL;
 					DWORD dwSize;
 					// check if the file exists and be read
-					dwNotExists = SCardReadFile(pCardData, szDirectory, Files[dwI].szFile, &pbData, &dwSize);
+					dwNotExists = OCardReadFile(pCardData, szDirectory, Files[dwI].szFile, &pbData, &dwSize);
 					if (!dwNotExists)
 					{
 						pCardData->pfnCspFree(pbData);
@@ -337,7 +305,7 @@
 }
 
 // read file
-DWORD SCardGetFileInfo(__in PCARD_DATA  pCardData, 
+DWORD OCardGetFileInfo(__in PCARD_DATA  pCardData, 
 					__in_opt PSTR szDirectory, __in PSTR szFile,
 					 __inout PCARD_FILE_INFO  pCardFileInfo)
 {
@@ -346,7 +314,7 @@
 	DWORD dwSize, dwI;
 	__try
 	{
-		dwReturn = SCardReadFile(pCardData, szDirectory, szFile, &pbData, &dwSize);
+		dwReturn = OCardReadFile(pCardData, szDirectory, szFile, &pbData, &dwSize);
 		if (dwReturn)
 		{
 			__leave;
@@ -356,10 +324,18 @@
 		pCardFileInfo->AccessCondition = InvalidAc;
 		for(dwI = 0; dwI < dwFileCount; dwI++)
 		{
-			if ((strcmp(szDirectory, Files[dwI].szDirectory) == 0)
-				|| (!szDirectory && !Files[dwI].szDirectory) )
+			BOOL fMatch = FALSE;
+			if (szDirectory == NULL)
 			{
-				if (strcmp(szFile, Files[dwI].szFile) == 0)
+				if (!Files[dwI].szDirectory) fMatch = TRUE;
+			}
+			else
+			{
+				if (Files[dwI].szDirectory && _stricmp(szDirectory, Files[dwI].szDirectory) == 0) fMatch = TRUE;
+			}
+			if (fMatch)
+			{
+				if (_stricmp(szFile, Files[dwI].szFile) == 0)
 				{
 					pCardFileInfo->AccessCondition = Files[dwI].dwAccess;
 					break;
@@ -375,7 +351,7 @@
 	return dwReturn;	
 }
 
-DWORD SCardWriteFile(__in PCARD_DATA  pCardData, 
+DWORD OCardWriteFile(__in PCARD_DATA  pCardData, 
 					__in_opt PSTR szDirectory, __in PSTR szFile,
 					__in PBYTE pbData, __in DWORD dwSize)
 {
@@ -404,12 +380,12 @@
 			}
 			else
 			{
-				if (Files[dwI].szDirectory && strcmp(szDirectory, Files[dwI].szDirectory) == 0) fMatch = TRUE;
+				if (Files[dwI].szDirectory && _stricmp(szDirectory, Files[dwI].szDirectory) == 0) fMatch = TRUE;
 			}
 			if (fMatch)
 			{
 				fDirectoryFound = TRUE;
-				if (strcmp(szFile, Files[dwI].szFile) == 0)
+				if (_stricmp(szFile, Files[dwI].szFile) == 0)
 				{
 					fFileFound = TRUE;
 					break;
@@ -448,7 +424,7 @@
 				memcpy(pbCmd + 5, pbData, dwSize);
 			}
 			dwCmdSize = dwSize + 5;
-			dwReturn = SCardSendCommand(pCardData, pbCmd, dwCmdSize);
+			dwReturn = OCardSendCommand(pCardData, pbCmd, dwCmdSize);
 			if (dwReturn)
 			{
 				__leave;
@@ -470,14 +446,14 @@
 	return dwReturn;
 }
 
-DWORD SCardDeleteFile(__in PCARD_DATA  pCardData, 
+DWORD OCardDeleteFile(__in PCARD_DATA  pCardData, 
 					__in_opt PSTR szDirectory, __in PSTR szFile)
 {
-	return SCardWriteFile(pCardData, szDirectory, szFile, NULL, 0);
+	return OCardWriteFile(pCardData, szDirectory, szFile, NULL, 0);
 }
 
 // just change the flag in Files
-DWORD SCardCreateFile(__in PCARD_DATA  pCardData, 
+DWORD OCardCreateFile(__in PCARD_DATA  pCardData, 
 					__in_opt PSTR szDirectory, __in PSTR szFile)
 {
 	DWORD dwI;
@@ -495,12 +471,12 @@
 			}
 			else
 			{
-				if (Files[dwI].szDirectory && strcmp(szDirectory, Files[dwI].szDirectory) == 0) fMatch = TRUE;
+				if (Files[dwI].szDirectory && _stricmp(szDirectory, Files[dwI].szDirectory) == 0) fMatch = TRUE;
 			}
 			if (fMatch)
 			{
 				fDirectoryFound = TRUE;
-				if (strcmp(szFile, Files[dwI].szFile) == 0)
+				if (_stricmp(szFile, Files[dwI].szFile) == 0)
 				{
 					fFileFound = TRUE;
 					break;

Modified: trunk/OpenPGPminidriver/PublicDataOperations.h
===================================================================
--- trunk/OpenPGPminidriver/PublicDataOperations.h	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriver/PublicDataOperations.h	2010-03-11 20:32:26 UTC (rev 8)
@@ -31,26 +31,27 @@
 #define szOpenPGPAlgoAttributesSignature "algsign"
 #define szOpenPGPAlgoAttributesDecryption "algcryp"
 #define szOpenPGPAlgoAttributesAuthentication "algauth"
+#define szOpenPGPPUK "puk"
 
 
-DWORD SCardReadFile(__in PCARD_DATA  pCardData, 
+DWORD OCardReadFile(__in PCARD_DATA  pCardData, 
 					__in_opt PSTR szDirectory, __in PSTR file,
 					__in PBYTE* pbResponse, __in PDWORD pdwResponseSize);
 
-DWORD SCardEnumFile(__in PCARD_DATA  pCardData, 
+DWORD OCardEnumFile(__in PCARD_DATA  pCardData, 
 					__in_opt PSTR szDirectory,
 					__in PBYTE* pbResponse, __in PDWORD pdwResponseSize);
 
-DWORD SCardGetFileInfo(__in PCARD_DATA  pCardData, 
+DWORD OCardGetFileInfo(__in PCARD_DATA  pCardData, 
 					__in_opt PSTR szDirectory, __in PSTR szFile,
 					 __inout PCARD_FILE_INFO  pCardFileInfo);
 
-DWORD SCardWriteFile(__in PCARD_DATA  pCardData, 
+DWORD OCardWriteFile(__in PCARD_DATA  pCardData, 
 					__in_opt PSTR szDirectory, __in PSTR szFile,
 					__in PBYTE pbData, __in DWORD dwSize);
 
-DWORD SCardDeleteFile(__in PCARD_DATA  pCardData, 
+DWORD OCardDeleteFile(__in PCARD_DATA  pCardData, 
 					__in_opt PSTR szDirectory, __in PSTR szFile);
 
-DWORD SCardCreateFile(__in PCARD_DATA  pCardData, 
+DWORD OCardCreateFile(__in PCARD_DATA  pCardData, 
 					__in_opt PSTR szDirectory, __in PSTR szFile);
\ No newline at end of file

Modified: trunk/OpenPGPminidriver/SmartCard.c
===================================================================
--- trunk/OpenPGPminidriver/SmartCard.c	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriver/SmartCard.c	2010-03-11 20:32:26 UTC (rev 8)
@@ -24,9 +24,37 @@
 
 #pragma comment(lib,"Winscard")
 
+DWORD SelectOpenPGPApplication(__in PCARD_DATA  pCardData);
 
-DWORD SCardSendCommand(__in PCARD_DATA  pCardData, __in PBYTE pbCmd, __in DWORD dwCmdSize)
+DWORD OCardReconnect(__in PCARD_DATA  pCardData)
 {
+	DWORD     dwAP;
+	DWORD dwReturn;
+	__try
+	{
+		// reset the card
+		Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
+		dwReturn = SCardReconnect(pCardData->hScard,
+                         SCARD_SHARE_SHARED,
+                         SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1,
+                         SCARD_LEAVE_CARD,
+                         &dwAP );
+		if (dwReturn)
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"SCardReconnect 0x%08X", dwReturn);
+			__leave;
+		}
+
+		dwReturn = SelectOpenPGPApplication(pCardData);
+	}
+	__finally
+	{
+	}
+	return dwReturn;
+}
+
+DWORD OCardSendCommand(__in PCARD_DATA  pCardData, __in PBYTE pbCmd, __in DWORD dwCmdSize)
+{
 	DWORD             dwReturn = 0;
 
 	SCARD_IO_REQUEST  ioSendPci = {1, sizeof(SCARD_IO_REQUEST)};
@@ -46,6 +74,16 @@
 									&recvlen);
 		if ( dwReturn != SCARD_S_SUCCESS )
 		{
+			if (dwReturn == SCARD_W_RESET_CARD)
+			{
+				dwReturn = OCardReconnect(pCardData);
+				if (dwReturn)
+				{
+					__leave;
+				}
+				dwReturn = OCardSendCommand(pCardData,pbCmd, dwCmdSize);
+				__leave;
+			}
 			Trace(WINEVENT_LEVEL_ERROR, L"SCardTransmit errorcode: [0x%02X]", dwReturn);
 			__leave;
 		}
@@ -92,11 +130,11 @@
 					0x00
 					};
 	
-	return SCardSendCommand(pCardData, pbCmd, sizeof(pbCmd));
+	return OCardSendCommand(pCardData, pbCmd, sizeof(pbCmd));
 }
 
 
-DWORD SCardGetData(__in PCARD_DATA  pCardData, 
+DWORD OCardGetData(__in PCARD_DATA  pCardData, 
 					__in PBYTE pbCmd, __in DWORD dwCmdSize,
 					__in PBYTE* pbResponse, __in_opt PDWORD pdwResponseSize)
 {
@@ -129,6 +167,16 @@
 		{
 			if ( dwReturn != SCARD_S_SUCCESS )
 			{
+				if (dwReturn == SCARD_W_RESET_CARD)
+				{
+					dwReturn = OCardReconnect(pCardData);
+					if (dwReturn)
+					{
+						__leave;
+					}
+					dwReturn = OCardGetData(pCardData,pbCmd, dwCmdSize,pbResponse, pdwResponseSize);
+					__leave;
+				}
 				Trace(WINEVENT_LEVEL_ERROR, L"SCardTransmit errorcode: [0x%02X]", dwReturn);
 				__leave;
 			}

Modified: trunk/OpenPGPminidriver/SmartCard.h
===================================================================
--- trunk/OpenPGPminidriver/SmartCard.h	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriver/SmartCard.h	2010-03-11 20:32:26 UTC (rev 8)
@@ -15,10 +15,10 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
-DWORD SCardSendCommand(__in PCARD_DATA  pCardData, __in PBYTE pbCmd, __in DWORD dwCmdSize);
+DWORD OCardSendCommand(__in PCARD_DATA  pCardData, __in PBYTE pbCmd, __in DWORD dwCmdSize);
 DWORD SelectOpenPGPApplication(__in PCARD_DATA  pCardData);
 
-DWORD SCardGetData(__in PCARD_DATA  pCardData, 
+DWORD OCardGetData(__in PCARD_DATA  pCardData, 
 					__in PBYTE pbCmd, __in DWORD dwCmdSize,
 					__in PBYTE* pbResponse, __in_opt PDWORD pdwResponseSize);
 

Modified: trunk/OpenPGPminidriver/Tracing.c
===================================================================
--- trunk/OpenPGPminidriver/Tracing.c	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriver/Tracing.c	2010-03-11 20:32:26 UTC (rev 8)
@@ -62,7 +62,7 @@
 	if (!hPub) TracingRegister();
 
 	va_start (ap, szFormat);
-	ret = _vsnwprintf_s (Buffer, 256, 256, szFormat, ap);
+	ret = _vsnwprintf_s (Buffer, 256, _TRUNCATE, szFormat, ap);
 	va_end (ap);
 	if (ret <= 0) return;
 	if (ret > 256) ret = 255;

Deleted: trunk/OpenPGPminidriver/driver.inf
===================================================================
--- trunk/OpenPGPminidriver/driver.inf	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriver/driver.inf	2010-03-11 20:32:26 UTC (rev 8)
@@ -1,142 +0,0 @@
-;
-;OpenPGP Smartcard Minidriver for an x86 and x64 based package.
-;
-
-[Version]
-Signature="$Windows NT$"
-Class=SmartCard
-ClassGuid={990A2BD7-E738-46c7-B26F-1CF8FB9F1391}
-Provider=%OPENPGP%
-CatalogFile=delta.cat
-DriverVer=02/23/2010,0.0.0.1
-
-[Manufacturer]
-%OPENPGP%=OpenPGP,NTamd64,NTamd64.6.1,NTx86,NTx86.6.1
-
-[OpenPGP.NTamd64]
-%OpenPGPCardDeviceName%=OpenPGP64_Install,SCFILTER\CID_0031c573c00140009000
-
-[OpenPGP.NTx86]
-%OpenPGPCardDeviceName%=OpenPGP32_Install,SCFILTER\CID_0031c573c00140009000
-
-[OpenPGP.NTamd64.6.1]
-%OpenPGPCardDeviceName%=OpenPGP64_61_Install,SCFILTER\CID_0031c573c00140009000
-
-[OpenPGP.NTx86.6.1]
-%OpenPGPCardDeviceName%=OpenPGP32_61_Install,SCFILTER\CID_0031c573c00140009000
-
-[SourceDisksFiles]
-openpgpmdrv64.dll=1
-openpgpmdrv32.dll=1
-
-[SourceDisksNames]
-1 = %MediaDescription%
-
-[OpenPGP64_Install.NT]
-CopyFiles=amd64_CopyFiles
-CopyFiles=wow64_CopyFiles
-AddReg=AddRegWOW64
-AddReg=AddReg64
-
-[OpenPGP64_61_Install.NT]
-CopyFiles=amd64_CopyFiles
-CopyFiles=wow64_CopyFiles
-AddReg=AddRegWOW64
-AddReg=AddReg64
-Include=umpass.inf
-Needs=UmPass
-
-[OpenPGP32_Install.NT]
-CopyFiles=x86_CopyFiles
-AddReg=AddReg32
-
-[OpenPGP32_61_Install.NT]
-CopyFiles=x86_CopyFiles
-AddReg=AddReg32
-Include=umpass.inf
-Needs=UmPass
-
-[OpenPGP64_61_Install.NT.Services]
-Include=umpass.inf
-Needs=UmPass.Services
-
-[OpenPGP32_61_Install.NT.Services]
-Include=umpass.inf
-Needs=UmPass.Services
-
-
-[OpenPGP64_61_Install.NT.HW]
-Include=umpass.inf
-Needs=UmPass.HW
-
-[OpenPGP64_61_Install.NT.CoInstallers]
-Include=umpass.inf
-Needs=UmPass.CoInstallers
-
-
-[OpenPGP64_61_Install.NT.Interfaces]
-Include=umpass.inf
-Needs=UmPass.Interfaces
-
-
-[OpenPGP32_61_Install.NT.HW]
-Include=umpass.inf
-Needs=UmPass.HW
-
-[OpenPGP32_61_Install.NT.CoInstallers]
-Include=umpass.inf
-Needs=UmPass.CoInstallers
-
-
-[OpenPGP32_61_Install.NT.Interfaces]
-Include=umpass.inf
-Needs=UmPass.Interfaces
-
-
-[amd64_CopyFiles]
-%SmartCardCardModule64%
-
-[x86_CopyFiles]
-%SmartCardCardModule32%
-
-[wow64_CopyFiles]
-%SmartCardCardModule32%
-
-[AddRegWOW64]
-HKLM, %SmartCardNameWOW64%,"ATR",0x00000001,3B,DA,18,FF,81,B1,FE,75,1F,03,00,31,C5,73,C0,01,40,00,90,00,0C
-HKLM, %SmartCardNameWOW64%,"ATRMask",0x00000001,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff
-HKLM, %SmartCardNameWOW64%,"Crypto Provider",0x00000000,"Microsoft Base Smart Card Crypto Provider"
-HKLM, %SmartCardNameWOW64%,"Smart Card Key Storage Provider",0x00000000,"Microsoft Smart Card Key Storage Provider"
-HKLM, %SmartCardNameWOW64%,"80000001",0x00000000,%SmartCardCardModule32%
-
-[AddReg32]
-HKLM, %SmartCardName%,"ATR",0x00000001,3B,DA,18,FF,81,B1,FE,75,1F,03,00,31,C5,73,C0,01,40,00,90,00,0C
-HKLM, %SmartCardName%,"ATRMask",0x00000001,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff
-HKLM, %SmartCardName%,"Crypto Provider",0x00000000,"Microsoft Base Smart Card Crypto Provider"
-HKLM, %SmartCardName%,"Smart Card Key Storage Provider",0x00000000,"Microsoft Smart Card Key Storage Provider"
-HKLM, %SmartCardName%,"80000001",0x00000000,%SmartCardCardModule32%
-
-[AddReg64]
-HKLM, %SmartCardName%,"ATR",0x00000001,3B,DA,18,FF,81,B1,FE,75,1F,03,00,31,C5,73,C0,01,40,00,90,00,0C
-HKLM, %SmartCardName%,"ATRMask",0x00000001,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff
-HKLM, %SmartCardName%,"Crypto Provider",0x00000000,"Microsoft Base Smart Card Crypto Provider"
-HKLM, %SmartCardName%,"Smart Card Key Storage Provider",0x00000000,"Microsoft Smart Card Key Storage Provider"
-HKLM, %SmartCardName%,"80000001",0x00000000,%SmartCardCardModule64%
-
-
-[DestinationDirs]
-amd64_CopyFiles=10,system32
-x86_CopyFiles=10,system32
-wow64_CopyFiles=10,syswow64
-
-
-; =================== Generic ==================================
-
-[Strings]
-OPENPGP ="OpenPGP"
-MediaDescription="OpenPGP Smart Card Minidriver Installation Disk"
-OpenPGPCardDeviceName="OpenPGP Minidriver for Smart Card"
-SmartCardName="SOFTWARE\Microsoft\Cryptography\Calais\SmartCards\OpenPGP"
-SmartCardNameWOW64="SOFTWARE\Wow6432Node\Microsoft\Cryptography\Calais\SmartCards\OpenPGP"
-SmartCardCardModule32="openpgpmdrv32.dll"
-SmartCardCardModule64="openpgpmdrv64.dll"

Copied: trunk/OpenPGPminidriver/openpgpmdrv.inf (from rev 2, trunk/OpenPGPminidriver/driver.inf)

Modified: trunk/OpenPGPminidriverTest/BaseCSP.cpp
===================================================================
--- trunk/OpenPGPminidriverTest/BaseCSP.cpp	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriverTest/BaseCSP.cpp	2010-03-11 20:32:26 UTC (rev 8)
@@ -25,7 +25,6 @@
 #pragma comment(lib,"Cryptui")
 #pragma comment(lib,"Crypt32")
 
-extern HWND hMainWnd;
 
 BOOL SchGetProviderNameFromCardName(__in LPCTSTR szCardName, __out LPTSTR szProviderName, __out PDWORD pdwProviderNameLen)
 {
@@ -52,7 +51,7 @@
 	return TRUE;
 }
 
-DWORD ListContainer()
+DWORD ListContainer(HWND hWnd)
 {
 	HCRYPTPROV HMainCryptProv = NULL;
 	BOOL bStatus = FALSE;
@@ -81,7 +80,7 @@
 	__try
 	{
 		
-		SendMessage(GetDlgItem(hMainWnd, IDC_LSTCONTAINER),LB_RESETCONTENT,0,0);
+		SendMessage(GetDlgItem(hWnd, IDC_LSTCONTAINER),LB_RESETCONTENT,0,0);
 		dwReturn = SCardEstablishContext(SCARD_SCOPE_USER,
 										NULL,
 										NULL,
@@ -184,7 +183,7 @@
 					{
 						TCHAR szText[256];
 						_stprintf_s(szText, ARRAYSIZE(szText), TEXT("%s %d"),szWideContainerName,pKeySpecs[i]);
-						SendDlgItemMessage(hMainWnd,IDC_LSTCONTAINER,LB_ADDSTRING,0,(LPARAM)szText);
+						SendDlgItemMessage(hWnd,IDC_LSTCONTAINER,LB_ADDSTRING,0,(LPARAM)szText);
 						CryptDestroyKey(hKey);
 						hKey = NULL;
 					}
@@ -214,7 +213,7 @@
 }
 
 
-DWORD ViewCertificate(PTSTR szContainer, DWORD dwKeySpec)
+DWORD ViewCertificate(HWND hWnd, PTSTR szContainer, DWORD dwKeySpec)
 {
 	BOOL bStatus;
 	DWORD dwReturn = 0;
@@ -276,7 +275,7 @@
 		}
 						
 		certViewInfo.dwSize = sizeof(CRYPTUI_VIEWCERTIFICATE_STRUCT);
-		certViewInfo.hwndParent = hMainWnd;
+		certViewInfo.hwndParent = hWnd;
 		certViewInfo.dwFlags = CRYPTUI_DISABLE_EDITPROPERTIES | CRYPTUI_DISABLE_ADDTOSTORE | CRYPTUI_DISABLE_EXPORT | CRYPTUI_DISABLE_HTMLLINK;
 		certViewInfo.szTitle = TEXT("Info");
 		certViewInfo.pCertContext = pCertContext;

Modified: trunk/OpenPGPminidriverTest/Dialog.h
===================================================================
--- trunk/OpenPGPminidriverTest/Dialog.h	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriverTest/Dialog.h	2010-03-11 20:32:26 UTC (rev 8)
@@ -1,20 +1,33 @@
-#define IDD_DLG 1000
-#define IDC_CONNECT 1001
-#define IDC_CurrentDll 1002
-#define IDC_SystemDll 1003
-#define IDC_DISCONNECT 1004
-#define IDC_TXTPIN 1005
-#define IDC_PIN 1006
-#define IDC_FILES 1007
-#define IDC_LISTFILES 1008
-#define IDC_PINADMIN 1009
-#define IDC_PINUSER 1010
-#define IDC_LSTCONTAINER 1011
-#define IDC_CONTAINER 1012
-#define IDC_STC1 1013
-#define IDC_SIGN 1014
-#define IDC_DECRYPT 1015
-#define IDC_CONTAINERINDEX 1016
-#define IDC_NEWKEY 1017
-#define IDC_IMPORTKEY 1018
-#define IDC_SAMEKEY 1019
+#define IDD_MAIN 1000
+#define IDC_TAB1 1001
+#define IDD_CONNECT 1100
+#define IDC_SystemDll 1101
+#define IDC_CurrentDll 1102
+#define IDC_CONNECT 1103
+#define IDC_DISCONNECT 1104
+#define IDD_PIN 1200
+#define IDC_PINUSER 1201
+#define IDC_PINADMIN 1202
+#define IDC_CHECKPIN 1203
+#define IDC_TXTPIN 1204
+#define IDC_TXTPIN2 1205
+#define IDC_CHANGEPIN 1206
+#define IDC_UNBLOCKPIN 1207
+#define IDC_PUK 1208
+#define IDC_BTN1 1209
+#define IDD_CRYPTO 1300
+#define IDC_SAMEKEY 1301
+#define IDC_IMPORTKEY 1302
+#define IDC_NEWKEY 1303
+#define IDC_CONTAINERINDEX 1304
+#define IDD_FILE 1400
+#define IDC_LISTFILES 1401
+#define IDC_STC2 1402
+#define IDC_CONTENT 1403
+#define IDC_FILES 1404
+#define IDD_CRYPTOAPI 1500
+#define IDC_DECRYPT 1501
+#define IDC_SIGN 1502
+#define IDC_STC1 1503
+#define IDC_CONTAINER 1504
+#define IDC_LSTCONTAINER 1505

Modified: trunk/OpenPGPminidriverTest/Dialog.rc
===================================================================
--- trunk/OpenPGPminidriverTest/Dialog.rc	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriverTest/Dialog.rc	2010-03-11 20:32:26 UTC (rev 8)
@@ -1,29 +1,72 @@
 #include <Windows.h>
 #include "Dialog.h"
 
-IDD_DLG DIALOGEX -4,-16,475,385
-CAPTION "IDD_DLG"
+IDD_MAIN DIALOGEX -4,-16,475,385
+CAPTION "IDD_MAIN"
 FONT 8,"MS Sans Serif",0,0,0
 STYLE WS_VISIBLE|WS_OVERLAPPEDWINDOW
 BEGIN
+  CONTROL "",IDC_TAB1,"SysTabControl32",WS_CHILD|WS_VISIBLE|WS_TABSTOP|TCS_FOCUSNEVER,0,3,474,381
+END
+
+IDD_CONNECT DIALOGEX 10,10,400,300
+CAPTION "IDD_MAIN"
+FONT 8,"MS Sans Serif",0,0,0
+STYLE WS_CHILDWINDOW|WS_VISIBLE
+BEGIN
+  CONTROL "System Driver",IDC_SystemDll,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON,12,6,96,12
+  CONTROL "Normal",IDC_CurrentDll,"Button",WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP|BS_AUTORADIOBUTTON,12,21,96,12
   CONTROL "Connect",IDC_CONNECT,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,9,39,54,21
-  CONTROL "Normal",IDC_CurrentDll,"Button",WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP|BS_AUTORADIOBUTTON,12,21,96,12
-  CONTROL "System Driver",IDC_SystemDll,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON,12,6,96,12
   CONTROL "Disconnect",IDC_DISCONNECT,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,69,39,57,21
-  CONTROL "",IDC_TXTPIN,"Edit",WS_CHILD|WS_VISIBLE|WS_TABSTOP,12,90,93,21,WS_EX_CLIENTEDGE
-  CONTROL "Check PIN",IDC_PIN,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,123,90,45,21
-  CONTROL "",IDC_FILES,"ListBox",WS_CHILD|WS_VISIBLE|WS_TABSTOP|LBS_NOINTEGRALHEIGHT|LBS_HASSTRINGS|LBS_NOTIFY,186,9,153,108,WS_EX_CLIENTEDGE
-  CONTROL "List Files",IDC_LISTFILES,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,345,22,48,21
-  CONTROL "Admin",IDC_PINADMIN,"Button",WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP|BS_AUTORADIOBUTTON,57,75,36,12
-  CONTROL "User",IDC_PINUSER,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON,12,75,33,13
-  CONTROL "",IDC_LSTCONTAINER,"ListBox",WS_CHILD|WS_VISIBLE|WS_TABSTOP|LBS_NOINTEGRALHEIGHT|LBS_HASSTRINGS|LBS_NOTIFY,15,237,396,93,WS_EX_CLIENTEDGE
-  CONTROL "List container",IDC_CONTAINER,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,351,213,57,21
-  CONTROL "Double clic = show certificate",IDC_STC1,"Static",WS_CHILD|WS_VISIBLE,15,225,282,9
-  CONTROL "Sign",IDC_SIGN,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,15,336,57,21
-  CONTROL "Decrypt",IDC_DECRYPT,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,87,336,57,21
-  CONTROL "",IDC_CONTAINERINDEX,"ComboBox",WS_CHILD|WS_VISIBLE|WS_TABSTOP|CBS_DROPDOWNLIST,15,126,90,15
-  CONTROL "Generate new key",IDC_NEWKEY,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,129,123,72,21
-  CONTROL "Import key",IDC_IMPORTKEY,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,129,147,72,21
-  CONTROL "Set same key",IDC_SAMEKEY,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,210,123,72,21
 END
 
+IDD_PIN DIALOGEX 0,0,400,300
+CAPTION "IDD_MAIN"
+FONT 8,"MS Sans Serif",0,0,0
+STYLE NOT WS_VISIBLE|WS_CHILDWINDOW
+BEGIN
+  CONTROL "User",IDC_PINUSER,"Button",WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP|BS_AUTORADIOBUTTON,6,15,33,13
+  CONTROL "Admin",IDC_PINADMIN,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON,51,15,36,12
+  CONTROL "Puk",IDC_PUK,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON,93,15,36,12
+  CONTROL "Check PIN",IDC_CHECKPIN,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,132,36,54,21
+  CONTROL "",IDC_TXTPIN,"Edit",WS_CHILD|WS_VISIBLE|WS_TABSTOP,9,36,93,21,WS_EX_CLIENTEDGE
+  CONTROL "",IDC_TXTPIN2,"Edit",WS_CHILD|WS_VISIBLE|WS_TABSTOP,9,66,93,21,WS_EX_CLIENTEDGE
+  CONTROL "Change Pin",IDC_CHANGEPIN,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,132,66,54,21
+  CONTROL "Unblock Pin",IDC_UNBLOCKPIN,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,201,66,54,22
+  CONTROL "Set Puk",IDC_BTN1,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,267,66,54,21
+END
+
+IDD_CRYPTO DIALOGEX 10,10,400,300
+CAPTION "IDD_MAIN"
+FONT 8,"MS Sans Serif",0,0,0
+STYLE NOT WS_VISIBLE|WS_CHILDWINDOW
+BEGIN
+  CONTROL "Set same key",IDC_SAMEKEY,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,123,39,72,21
+  CONTROL "Import key",IDC_IMPORTKEY,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,42,63,72,21
+  CONTROL "Generate new key",IDC_NEWKEY,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,42,39,72,21
+  CONTROL "",IDC_CONTAINERINDEX,"ComboBox",WS_CHILD|WS_VISIBLE|WS_TABSTOP|CBS_DROPDOWNLIST,39,18,90,15
+END
+
+IDD_FILE DIALOGEX 10,10,400,300
+CAPTION "IDD_MAIN"
+FONT 8,"MS Sans Serif",0,0,0
+STYLE NOT WS_VISIBLE|WS_CHILDWINDOW
+BEGIN
+  CONTROL "List Files",IDC_LISTFILES,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,177,18,48,21
+  CONTROL "File content :",IDC_STC2,"Static",WS_CHILD|WS_VISIBLE,15,132,118,9
+  CONTROL "",IDC_CONTENT,"Edit",WS_CHILD|WS_VISIBLE|WS_DISABLED|WS_TABSTOP|ES_MULTILINE,15,144,154,64,WS_EX_CLIENTEDGE
+  CONTROL "",IDC_FILES,"ListBox",WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP|LBS_NOINTEGRALHEIGHT|LBS_HASSTRINGS|LBS_NOTIFY,15,21,153,108,WS_EX_CLIENTEDGE
+END
+
+IDD_CRYPTOAPI DIALOGEX 0,0,400,300
+CAPTION "IDD_MAIN"
+FONT 8,"MS Sans Serif",0,0,0
+STYLE NOT WS_VISIBLE|WS_CHILDWINDOW
+BEGIN
+  CONTROL "Decrypt",IDC_DECRYPT,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,78,132,57,21
+  CONTROL "Sign",IDC_SIGN,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,6,132,57,21
+  CONTROL "Double clic = show certificate",IDC_STC1,"Static",WS_CHILD|WS_VISIBLE,6,21,282,9
+  CONTROL "List container",IDC_CONTAINER,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,321,9,57,21
+  CONTROL "",IDC_LSTCONTAINER,"ListBox",WS_CHILD|WS_VISIBLE|WS_TABSTOP|LBS_NOINTEGRALHEIGHT|LBS_HASSTRINGS|LBS_NOTIFY,6,33,378,93,WS_EX_CLIENTEDGE
+END
+

Modified: trunk/OpenPGPminidriverTest/InitializationAndDeconstruct.cpp
===================================================================
--- trunk/OpenPGPminidriverTest/InitializationAndDeconstruct.cpp	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriverTest/InitializationAndDeconstruct.cpp	2010-03-11 20:32:26 UTC (rev 8)
@@ -161,7 +161,7 @@
 		}
 		else
 		{
-#ifdef WIN64
+#ifdef _M_X64
 			_tcscpy_s(szCardModule, dwCardModuleSize, TEXT("openpgpmdrv64.dll"));
 #else
 			_tcscpy_s(szCardModule, dwCardModuleSize, TEXT("openpgpmdrv32.dll"));
@@ -211,7 +211,7 @@
 		pCardData->cbAtr = atr.cbAtr;
 		pCardData->pbAtr = atr.rgbAtr;
 		pCardData->pwszCardName = szCard;
-		dwReturn = SCardBeginTransaction(hSCardHandle);
+		//dwReturn = SCardBeginTransaction(hSCardHandle);
 		if ( SCARD_S_SUCCESS != dwReturn )
 		{
 			__leave;

Modified: trunk/OpenPGPminidriverTest/PINOperations.cpp
===================================================================
--- trunk/OpenPGPminidriverTest/PINOperations.cpp	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriverTest/PINOperations.cpp	2010-03-11 20:32:26 UTC (rev 8)
@@ -20,10 +20,9 @@
 #include <cardmod.h>
 #include "global.h"
 
-DWORD Authenticate(PWSTR wszPin, PWSTR wszUserId, PDWORD pcAttemptsRemaining)
+DWORD Authenticate(PSTR szPin, PWSTR wszUserId, PDWORD pcAttemptsRemaining)
 {
-	LPSTR szPin = NULL;
-    DWORD cbPin = 0;
+    DWORD cbPin = strlen(szPin);
 	DWORD dwReturn;
     __try
     {
@@ -32,44 +31,84 @@
 			dwReturn = SCARD_E_COMM_DATA_LOST;
 			__leave;
 		}
-		//
-        // Convert the PIN to ANSI
-        //
-        if (0 == (cbPin = WideCharToMultiByte(CP_ACP,0,wszPin,-1,NULL,0,NULL,NULL)))
-        {
-            dwReturn = GetLastError();
-            __leave;
-        }
 
-        szPin = (LPSTR) LocalAlloc(0,cbPin);
-		if (szPin == NULL)
+        dwReturn = pCardData->pfnCardAuthenticatePin(
+            pCardData,
+            wszUserId,
+            (PBYTE) szPin,
+            cbPin - 1,
+            pcAttemptsRemaining);
+    }
+    __finally
+    {
+    }
+
+    return dwReturn;
+}
+
+DWORD ChangePin(PSTR szPin, PSTR szPin2, PWSTR wszUserId, PDWORD pcAttemptsRemaining)
+{
+	WORD cbPin = strlen(szPin);
+	DWORD cbPin2 = strlen(szPin2);
+	DWORD dwReturn;
+    __try
+    {
+        if (!pCardData)
 		{
-			dwReturn = GetLastError();
-            __leave;
+			dwReturn = SCARD_E_COMM_DATA_LOST;
+			__leave;
 		}
 
-        if (0 == (cbPin = WideCharToMultiByte(CP_ACP,0,wszPin,-1,szPin,cbPin,NULL,NULL)))
-        {
-            dwReturn = GetLastError();
-            __leave;
-        }
-
-        //
-        // Call the card module
-        //
-
-        dwReturn = pCardData->pfnCardAuthenticatePin(
+        dwReturn = pCardData->pfnCardChangeAuthenticator(
             pCardData,
             wszUserId,
             (PBYTE) szPin,
-            cbPin - 1,
+            cbPin,
+			(PBYTE) szPin2,
+            cbPin2,
+			0,CARD_AUTHENTICATE_PIN_PIN,
             pcAttemptsRemaining);
     }
     __finally
     {
-        if (NULL != szPin)
-            LocalFree(szPin);
     }
 
     return dwReturn;
+}
+DWORD ResetPin(PSTR szPin, PSTR szPin2, BOOL fIsPUK, PDWORD pcAttemptsRemaining)
+{
+	DWORD cbPin = strlen(szPin);
+	DWORD cbPin2 = strlen(szPin2);
+	DWORD dwReturn;
+    __try
+    {
+        if (!pCardData)
+		{
+			dwReturn = SCARD_E_COMM_DATA_LOST;
+			__leave;
+		}
+		if (fIsPUK)
+		{
+			dwReturn = pCardData->pfnCardChangeAuthenticatorEx(
+				pCardData,
+				PIN_CHANGE_FLAG_UNBLOCK, 5,
+				(PBYTE) szPin,cbPin,
+				ROLE_USER, (PBYTE)szPin2, cbPin2, 0,
+				pcAttemptsRemaining);
+		}
+		else
+		{
+			dwReturn = pCardData->pfnCardChangeAuthenticatorEx(
+				pCardData,
+				PIN_CHANGE_FLAG_UNBLOCK, ROLE_ADMIN,
+				(PBYTE) szPin,cbPin,
+				ROLE_USER, (PBYTE)szPin2, cbPin2, 0,
+				pcAttemptsRemaining);
+		}
+    }
+    __finally
+    {
+    }
+
+    return dwReturn;
 }
\ No newline at end of file

Modified: trunk/OpenPGPminidriverTest/PublicDataOperations.cpp
===================================================================
--- trunk/OpenPGPminidriverTest/PublicDataOperations.cpp	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriverTest/PublicDataOperations.cpp	2010-03-11 20:32:26 UTC (rev 8)
@@ -22,9 +22,8 @@
 #include "global.h"
 #include "dialog.h"
 
-extern HWND hMainWnd;
 
-DWORD ListFiles(PSTR szDirectory)
+DWORD ListFiles(HWND hWnd, PSTR szDirectory)
 {
 	DWORD dwReturn = 0, dwSize;
 	LPSTR pszFiles = NULL;
@@ -45,8 +44,8 @@
 			{
 				sprintf_s(szText, ARRAYSIZE(szText),"%s",szCurrentFile);
 			}
-			SendDlgItemMessageA(hMainWnd,IDC_FILES,LB_ADDSTRING,0,(LPARAM)szText);
-			if (strcmp(szCurrentFile,"cardapps") == 0)
+			SendDlgItemMessageA(hWnd,IDC_FILES,LB_ADDSTRING,0,(LPARAM)szText);
+			if (_stricmp(szCurrentFile,"cardapps") == 0)
 			{
 				PBYTE pbData = NULL;
 				dwSize = 0;
@@ -58,7 +57,7 @@
 					{
 						memcpy(szDirectory, pbData + dwI, 8);
 						szDirectory[8] = 0;
-						ListFiles(szDirectory);
+						ListFiles(hWnd, szDirectory);
 					}
 
 					pCardData->pfnCspFree(pbData);
@@ -72,12 +71,74 @@
 	return dwReturn;
 }
 
-DWORD ListFiles()
+DWORD ListFiles(HWND hWnd)
 {
 	if (!pCardData)
 	{
 		return SCARD_E_COMM_DATA_LOST;
 	}
-	SendMessage(GetDlgItem(hMainWnd, IDC_FILES),LB_RESETCONTENT,0,0);
-	return ListFiles(NULL);
-}
\ No newline at end of file
+	SendMessage(GetDlgItem(hWnd, IDC_FILES),LB_RESETCONTENT,0,0);
+	return ListFiles(hWnd, NULL);
+}
+
+DWORD ViewFile(HWND hWnd)
+{
+	CHAR szFileName[256];
+	PSTR szFile, szDirectory;
+	DWORD dwReturn;
+	PBYTE pbData = NULL;
+	DWORD dwSize;
+	TCHAR szData[10];
+	__try
+	{
+		// clear text
+		SendMessage( GetDlgItem(hWnd, IDC_CONTENT), WM_SETTEXT,0,(LPARAM) "");
+
+		DWORD iItem = (DWORD)SendMessage(GetDlgItem(hWnd, IDC_FILES),LB_GETCURSEL,0,0);
+		if (iItem == LB_ERR) 
+		{
+			dwReturn = SCARD_E_COMM_DATA_LOST;
+			__leave;
+		}
+		if (!pCardData)
+		{
+			dwReturn = SCARD_E_COMM_DATA_LOST;
+			__leave;
+		}
+		SendMessageA( GetDlgItem(hWnd,IDC_FILES), LB_GETTEXT,iItem,(LPARAM)szFileName);
+		szFile = strchr(szFileName,'\\');
+		if (szFile)
+		{
+			*szFile = 0;
+			szFile++;
+			szDirectory = szFileName;
+		}
+		else
+		{
+			szDirectory = NULL;
+			szFile = szFileName;
+		}
+		dwReturn = pCardData->pfnCardReadFile(pCardData,szDirectory,szFile, 0, &pbData, &dwSize);
+		if (dwReturn)
+		{
+			__leave;
+		}
+		for(DWORD dwI = 0; dwI < dwSize; dwI++)
+		{
+			_stprintf_s(szData,ARRAYSIZE(szData),TEXT("%02X "),pbData[dwI]);
+			SendMessage(    // returns LRESULT in lResult
+				   GetDlgItem(hWnd, IDC_CONTENT),           // (HWND) handle to destination control
+				   EM_REPLACESEL,         // (UINT) message ID
+				   FALSE,                // = () wParam; 
+				   (LPARAM)szData                 // = (LPARAM)(LPCTSTR) lParam;
+				);
+
+		}
+	}
+	__finally
+	{
+		if (pbData)
+			pCardData->pfnCspFree(pbData);
+	}
+	return 0;
+}

Modified: trunk/OpenPGPminidriverTest/global.h
===================================================================
--- trunk/OpenPGPminidriverTest/global.h	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriverTest/global.h	2010-03-11 20:32:26 UTC (rev 8)
@@ -18,10 +18,13 @@
 extern PCARD_DATA pCardData;
 DWORD Connect(BOOL fSystemDll);
 DWORD Disconnect();
-DWORD Authenticate(PWSTR wszPin, PWSTR wszUserId, PDWORD pcAttemptsRemaining);
-DWORD ListFiles();
-DWORD ListContainer();
-DWORD ViewCertificate(PTSTR szContainer, DWORD dwKeySpec);
+DWORD Authenticate(PSTR wszPin, PWSTR wszUserId, PDWORD pcAttemptsRemaining);
+DWORD ResetPin(PSTR wszPin, PSTR wszPin2, BOOL fIsPUK, PDWORD pcAttemptsRemaining);
+DWORD ChangePin(PSTR szPin, PSTR szPin2, PWSTR wszUserId, PDWORD pcAttemptsRemaining);
+DWORD ListFiles(HWND hWnd);
+DWORD ViewFile(HWND hWnd);
+DWORD ListContainer(HWND hWnd);
+DWORD ViewCertificate(HWND hWnd, PTSTR szContainer, DWORD dwKeySpec);
 DWORD Sign(PTSTR szContainer, DWORD dwKeySpec);
 DWORD Decrypt(PTSTR szContainer, DWORD dwKeySpec);
 DWORD GenerateNewKey(DWORD dwIndex);

Modified: trunk/OpenPGPminidriverTest/main.cpp
===================================================================
--- trunk/OpenPGPminidriverTest/main.cpp	2010-03-04 21:50:46 UTC (rev 7)
+++ trunk/OpenPGPminidriverTest/main.cpp	2010-03-11 20:32:26 UTC (rev 8)
@@ -22,6 +22,8 @@
 #include "dialog.h"
 #include "global.h"
 
+#pragma comment(lib,"comctl32")
+
 #ifdef UNICODE
 #if defined _M_IX86
 #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
@@ -35,10 +37,13 @@
 #endif
 
 // Variables globales :
-HINSTANCE hInst;								// instance actuelle
-HWND hMainWnd;
+HINSTANCE g_hinst;								// instance actuelle
 
-INT_PTR CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
+INT_PTR CALLBACK	WndProcConnect(HWND, UINT, WPARAM, LPARAM);
+INT_PTR CALLBACK	WndProcPin(HWND, UINT, WPARAM, LPARAM);
+INT_PTR CALLBACK	WndProcFile(HWND, UINT, WPARAM, LPARAM);
+INT_PTR CALLBACK	WndProcCrypto(HWND, UINT, WPARAM, LPARAM);
+INT_PTR CALLBACK	WndProcCryptoApi(HWND, UINT, WPARAM, LPARAM);
 
 int APIENTRY _tWinMain(HINSTANCE hInstance,
                      HINSTANCE hPrevInstance,
@@ -47,9 +52,65 @@
 {
 	UNREFERENCED_PARAMETER(hPrevInstance);
 	UNREFERENCED_PARAMETER(lpCmdLine);
-	hInst = hInstance;
-	
-    DialogBox (hInst, MAKEINTRESOURCE (IDD_DLG), 0, WndProc);
+	g_hinst = hInstance;
+    PROPSHEETPAGE psp[5];
+    PROPSHEETHEADER psh;
+    psp[0].dwSize = sizeof(PROPSHEETPAGE);
+    psp[0].dwFlags = PSP_USETITLE;
+    psp[0].hInstance = g_hinst;
+    psp[0].pszTemplate = MAKEINTRESOURCE(IDD_CONNECT);
+    psp[0].pszIcon = NULL;
+    psp[0].pfnDlgProc = WndProcConnect;
+    psp[0].pszTitle = TEXT("Connect");
+    psp[0].lParam = 0;
+    psp[0].pfnCallback = NULL;
+    psp[1].dwSize = sizeof(PROPSHEETPAGE);
+    psp[1].dwFlags = PSP_USETITLE;
+    psp[1].hInstance = g_hinst;
+    psp[1].pszTemplate = MAKEINTRESOURCE(IDD_PIN);
+    psp[1].pszIcon = NULL;
+    psp[1].pfnDlgProc = WndProcPin;
+    psp[1].pszTitle = TEXT("Pin");
+    psp[1].lParam = 0;
+    psp[2].pfnCallback = NULL;
+	psp[2].dwSize = sizeof(PROPSHEETPAGE);
+    psp[2].dwFlags = PSP_USETITLE;
+    psp[2].hInstance = g_hinst;
+    psp[2].pszTemplate = MAKEINTRESOURCE(IDD_FILE);
+    psp[2].pszIcon = NULL;
+    psp[2].pfnDlgProc = WndProcFile;
+    psp[2].pszTitle = TEXT("File");
+    psp[2].lParam = 0;
+    psp[2].pfnCallback = NULL;
+	psp[3].dwSize = sizeof(PROPSHEETPAGE);
+    psp[3].dwFlags = PSP_USETITLE;
+    psp[3].hInstance = g_hinst;
+    psp[3].pszTemplate = MAKEINTRESOURCE(IDD_CRYPTO);
+    psp[3].pszIcon = NULL;
+    psp[3].pfnDlgProc = WndProcCrypto;
+    psp[3].pszTitle = TEXT("Crypto");
+    psp[3].lParam = 0;
+    psp[3].pfnCallback = NULL;
+	psp[4].dwSize = sizeof(PROPSHEETPAGE);
+    psp[4].dwFlags = PSP_USETITLE;
+    psp[4].hInstance = g_hinst;
+    psp[4].pszTemplate = MAKEINTRESOURCE(IDD_CRYPTOAPI);
+    psp[4].pszIcon = NULL;
+    psp[4].pfnDlgProc = WndProcCryptoApi;
+    psp[4].pszTitle = TEXT("CryptoApi");
+    psp[4].lParam = 0;
+    psp[4].pfnCallback = NULL;
+    psh.dwSize = sizeof(PROPSHEETHEADER);
+    psh.dwFlags = PSH_USEICONID | PSH_PROPSHEETPAGE;
+    psh.hwndParent = NULL;
+    psh.hInstance = g_hinst;
+    psh.pszIcon =NULL;
+    psh.pszCaption = TEXT("Test");
+    psh.nPages = ARRAYSIZE(psp);
+    psh.nStartPage = 0;
+    psh.ppsp = (LPCPROPSHEETPAGE) &psp;
+    psh.pfnCallback = NULL;
+    PropertySheet(&psh);
     return 0;
 
 }
@@ -62,38 +123,37 @@
 	LocalFree(Error);
 }
 
-BOOL GetContainerName(PWSTR szContainer, PDWORD pdwKeySpec)
+#define C_PAGES 5
+ 
+typedef struct tag_dlghdr { 
+    HWND hwndTab;       // tab control 
+    HWND hwndDisplay;   // current child dialog box 
+    RECT rcDisplay;     // display rectangle for the tab control 
+    DLGTEMPLATE *apRes[C_PAGES]; 
+	DLGPROC pDialogFunc[C_PAGES];
+} DLGHDR; 
+
+
+BOOL GetContainerName(HWND hWnd, PWSTR szContainer, PDWORD pdwKeySpec)
 {
-	DWORD iItem = (DWORD)SendMessage(GetDlgItem(hMainWnd, IDC_LSTCONTAINER),LB_GETCURSEL,0,0);
+	DWORD iItem = (DWORD)SendMessage(GetDlgItem(hWnd, IDC_LSTCONTAINER),LB_GETCURSEL,0,0);
 	if (iItem == LB_ERR) return FALSE;
-	SendMessage( GetDlgItem(hMainWnd,IDC_LSTCONTAINER), LB_GETTEXT,iItem,(LPARAM)szContainer);
+	SendMessage( GetDlgItem(hWnd,IDC_LSTCONTAINER), LB_GETTEXT,iItem,(LPARAM)szContainer);
 	*pdwKeySpec = _tstoi(szContainer + _tcslen(szContainer) - 1);
 	szContainer[ _tcslen(szContainer) - 2] = 0;
 	return TRUE;
 }
 
-INT_PTR CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+ 
+INT_PTR CALLBACK WndProcConnect(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
 	int wmId, wmEvent;
 	DWORD dwReturn;
-	TCHAR szPin[256];
-	TCHAR szContainer[256];
-	DWORD dwKeySpec;
 	switch (message)
 	{
 	case WM_INITDIALOG:
-		hMainWnd = hWnd;
 		CheckDlgButton(hWnd,IDC_CurrentDll,BST_CHECKED);
-		CheckDlgButton(hWnd,IDC_PINUSER,BST_CHECKED);
-		SendDlgItemMessage(hMainWnd,IDC_CONTAINERINDEX,CB_ADDSTRING,0,(LPARAM)TEXT("Signature"));
-		SendDlgItemMessage(hMainWnd,IDC_CONTAINERINDEX,CB_ADDSTRING,0,(LPARAM)TEXT("Authentication"));
-		SendDlgItemMessage(hMainWnd,IDC_CONTAINERINDEX,CB_ADDSTRING,0,(LPARAM)TEXT("Confidentiality"));
-		SendDlgItemMessage(hMainWnd,IDC_CONTAINERINDEX, CB_SETCURSEL, 0, 0);
 		break;
-
-	case WM_CLOSE:
-		EndDialog(hWnd, IDOK);
-		return TRUE;
 	case WM_COMMAND:
 		wmId    = LOWORD(wParam);
 		wmEvent = HIWORD(wParam);
@@ -121,9 +181,43 @@
 					MessageBoxWin32(dwReturn);
 				}
 				break;
-			case IDC_PIN:
-				GetDlgItemText(hWnd,IDC_TXTPIN,szPin,ARRAYSIZE(szPin));
-				DWORD dwRemaining;
+		}
+		break;
+	}
+	return FALSE;
+}
+
+INT_PTR CALLBACK WndProcPin(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+	int wmId, wmEvent;
+	DWORD dwReturn;
+	CHAR szPin[256];
+	CHAR szPin2[256];
+	DWORD dwRemaining;
+	switch (message)
+	{
+	case WM_INITDIALOG:
+		CheckDlgButton(hWnd,IDC_PINUSER,BST_CHECKED);
+		SendMessage( GetDlgItem(hWnd, IDC_TXTPIN), WM_SETTEXT,0,(LPARAM) TEXT("123456"));
+		break;
+	case WM_COMMAND:
+		wmId    = LOWORD(wParam);
+		wmEvent = HIWORD(wParam);
+		
+		switch (wmId)
+		{
+			case IDC_PINUSER:
+				SendMessage( GetDlgItem(hWnd, IDC_TXTPIN), WM_SETTEXT,0,(LPARAM) TEXT("123456"));
+			break;
+			case IDC_PINADMIN:
+				SendMessage( GetDlgItem(hWnd, IDC_TXTPIN), WM_SETTEXT,0,(LPARAM) TEXT("12345678"));
+			break;
+			case IDC_PUK:
+				SendMessage( GetDlgItem(hWnd, IDC_TXTPIN), WM_SETTEXT,0,(LPARAM) TEXT("000000"));
+			break;
+			case IDC_CHECKPIN:
+				GetDlgItemTextA(hWnd,IDC_TXTPIN,szPin,ARRAYSIZE(szPin));
+
 				if (IsDlgButtonChecked(hWnd,IDC_PINADMIN))
 				{
 					dwReturn = Authenticate(szPin, wszCARD_USER_ADMIN, &dwRemaining);
@@ -134,42 +228,153 @@
 				}
 				MessageBoxWin32(dwReturn);
 				break;
+			case IDC_UNBLOCKPIN:
+				GetDlgItemTextA(hWnd,IDC_TXTPIN,szPin,ARRAYSIZE(szPin));
+				GetDlgItemTextA(hWnd,IDC_TXTPIN2,szPin2,ARRAYSIZE(szPin2));
+				if (IsDlgButtonChecked(hWnd,IDC_PINADMIN))
+				{
+					dwReturn = ResetPin(szPin, szPin2, FALSE, &dwRemaining);
+				}
+				else if (IsDlgButtonChecked(hWnd,IDC_PUK))
+				{
+					dwReturn = ResetPin(szPin, szPin2, TRUE, &dwRemaining);
+				}
+				else
+				{
+					dwReturn = E_INVALIDARG;
+				}
+				MessageBoxWin32(dwReturn);
+				break;
+			case IDC_CHANGEPIN:
+				GetDlgItemTextA(hWnd,IDC_TXTPIN,szPin,ARRAYSIZE(szPin));
+				GetDlgItemTextA(hWnd,IDC_TXTPIN2,szPin2,ARRAYSIZE(szPin2));
+				if (IsDlgButtonChecked(hWnd,IDC_PINADMIN))
+				{
+					dwReturn = ChangePin(szPin, szPin2, wszCARD_USER_ADMIN, &dwRemaining);
+				}
+				else if (IsDlgButtonChecked(hWnd,IDC_PINUSER))
+				{
+					dwReturn = ChangePin(szPin, szPin2, wszCARD_USER_USER, &dwRemaining);
+				}
+				else
+				{
+					dwReturn = E_INVALIDARG;
+				}
+				MessageBoxWin32(dwReturn);
+				break;
+		}
+		break;
+	}
+	return FALSE;
+}
+
+INT_PTR CALLBACK WndProcFile(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+	int wmId, wmEvent;
+	DWORD dwReturn;
+	switch (message)
+	{
+	case WM_INITDIALOG:
+		break;
+	case WM_COMMAND:
+		wmId    = LOWORD(wParam);
+		wmEvent = HIWORD(wParam);
+		
+		switch (wmId)
+		{
 			case IDC_LISTFILES:
-				dwReturn = ListFiles();
+				dwReturn = ListFiles(hWnd);
 				if (dwReturn)
 				{
 					MessageBoxWin32(dwReturn);
 				}
 				break;
+			case IDC_FILES:
+				switch(wmEvent)
+				{
+					case LBN_SELCHANGE:
+						dwReturn = ViewFile(hWnd);
+						if (dwReturn)
+						{
+							MessageBoxWin32(dwReturn);
+						}
+						break;
+				}
+				break;
+		}
+		break;
+	}
+	return FALSE;
+}
+
+INT_PTR CALLBACK WndProcCrypto(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+	int wmId, wmEvent;
+	DWORD dwReturn;
+	switch (message)
+	{
+	case WM_INITDIALOG:
+		SendDlgItemMessage(hWnd,IDC_CONTAINERINDEX,CB_ADDSTRING,0,(LPARAM)TEXT("Signature"));
+		SendDlgItemMessage(hWnd,IDC_CONTAINERINDEX,CB_ADDSTRING,0,(LPARAM)TEXT("Authentication"));
+		SendDlgItemMessage(hWnd,IDC_CONTAINERINDEX,CB_ADDSTRING,0,(LPARAM)TEXT("Confidentiality"));
+		SendDlgItemMessage(hWnd,IDC_CONTAINERINDEX, CB_SETCURSEL, 0, 0);
+		break;
+	case WM_COMMAND:
+		wmId    = LOWORD(wParam);
+		wmEvent = HIWORD(wParam);
+		
+		switch (wmId)
+		{
 			case IDC_NEWKEY:
-				dwReturn = GenerateNewKey((DWORD)SendDlgItemMessage(hMainWnd,IDC_CONTAINERINDEX, CB_GETCURSEL, 0, 0));
+				dwReturn = GenerateNewKey((DWORD)SendDlgItemMessage(hWnd,IDC_CONTAINERINDEX, CB_GETCURSEL, 0, 0));
 				MessageBoxWin32(dwReturn);
 				break;
 			case IDC_IMPORTKEY:
-				dwReturn = ImportKey((DWORD)SendDlgItemMessage(hMainWnd,IDC_CONTAINERINDEX, CB_GETCURSEL, 0, 0));
+				dwReturn = ImportKey((DWORD)SendDlgItemMessage(hWnd,IDC_CONTAINERINDEX, CB_GETCURSEL, 0, 0));
 				MessageBoxWin32(dwReturn);
 				break;
 			case IDC_SAMEKEY:
 				dwReturn = SetTheSameKeyForAllContainers();
 				MessageBoxWin32(dwReturn);
 				break;
-				////////// base CSP
+		}
+		break;
+	}
+	return FALSE;
+}
+
+INT_PTR CALLBACK WndProcCryptoApi(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+	int wmId, wmEvent;
+	DWORD dwReturn;
+	TCHAR szContainer[256];
+	DWORD dwKeySpec;
+	switch (message)
+	{
+	case WM_INITDIALOG:
+		break;
+	case WM_COMMAND:
+		wmId    = LOWORD(wParam);
+		wmEvent = HIWORD(wParam);
+		
+		switch (wmId)
+		{
 			case IDC_CONTAINER:
-				dwReturn = ListContainer();
+				dwReturn = ListContainer(hWnd);
 				if (dwReturn)
 				{
 					MessageBoxWin32(dwReturn);
 				}
 				break;
 			case IDC_SIGN:
-				if (GetContainerName(szContainer, &dwKeySpec))
+				if (GetContainerName(hWnd, szContainer, &dwKeySpec))
 				{
 					dwReturn = Sign(szContainer, dwKeySpec);
 					MessageBoxWin32(dwReturn);
 				}
 				break;
 			case IDC_DECRYPT:
-				if (GetContainerName(szContainer, &dwKeySpec))
+				if (GetContainerName(hWnd, szContainer, &dwKeySpec))
 				{
 					dwReturn = Decrypt(szContainer, dwKeySpec);
 					MessageBoxWin32(dwReturn);
@@ -179,9 +384,9 @@
 				switch(wmEvent)
 				{
 					case LBN_DBLCLK:
-						if (GetContainerName(szContainer, &dwKeySpec))
+						if (GetContainerName(hWnd, szContainer, &dwKeySpec))
 						{
-							dwReturn = ViewCertificate(szContainer, dwKeySpec);
+							dwReturn = ViewCertificate(hWnd, szContainer, dwKeySpec);
 							if (dwReturn)
 							{
 								MessageBoxWin32(dwReturn);



More information about the Openpgpmdrv-commits mailing list