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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Mar 18 17:03:40 CET 2010


Author: vletoux
Date: 2010-03-18 17:03:39 +0100 (Thu, 18 Mar 2010)
New Revision: 11

Modified:
   trunk/OpenPGPminidriver/CardAndContainerProperties.c
   trunk/OpenPGPminidriver/CardPinOperation.c
   trunk/OpenPGPminidriver/ContextManagement.c
   trunk/OpenPGPminidriver/CryptoOperations.c
   trunk/OpenPGPminidriver/PinOperations.c
   trunk/OpenPGPminidriver/PinOperations.h
   trunk/OpenPGPminidriver/PublicDataOperations.c
   trunk/OpenPGPminidriver/PublicDataOperations.h
   trunk/OpenPGPminidriver/SmartCard.c
   trunk/OpenPGPminidriver/openpgpmdrv.inf
   trunk/OpenPGPminidriverTest/Dialog.h
   trunk/OpenPGPminidriverTest/Dialog.rc
   trunk/OpenPGPminidriverTest/OpenPGPminidriverTest.vcproj
   trunk/OpenPGPminidriverTest/PINOperations.cpp
   trunk/OpenPGPminidriverTest/PublicDataOperations.cpp
   trunk/OpenPGPminidriverTest/global.h
   trunk/OpenPGPminidriverTest/main.cpp
Log:
first working & stable version

Modified: trunk/OpenPGPminidriver/CardAndContainerProperties.c
===================================================================
--- trunk/OpenPGPminidriver/CardAndContainerProperties.c	2010-03-15 18:23:17 UTC (rev 10)
+++ trunk/OpenPGPminidriver/CardAndContainerProperties.c	2010-03-18 16:03:39 UTC (rev 11)
@@ -64,7 +64,7 @@
 		}
 		pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
 		pCardCapabilities->fKeyGen = !pContext->fIsReadOnly;
-		pCardCapabilities->fCertificateCompression = FALSE;		
+		pCardCapabilities->fCertificateCompression = TRUE;		
 		dwReturn = 0;
 	}
 	__finally
@@ -464,7 +464,6 @@
 			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);
 		}
@@ -485,7 +484,6 @@
 			{
 			case ROLE_SIGNATURE:
 			case ROLE_AUTHENTICATION:
-			case ROLE_CONFIDENTIALITY:
 			case ROLE_ADMIN:
 			case ROLE_PUK:
 				break;

Modified: trunk/OpenPGPminidriver/CardPinOperation.c
===================================================================
--- trunk/OpenPGPminidriver/CardPinOperation.c	2010-03-15 18:23:17 UTC (rev 10)
+++ trunk/OpenPGPminidriver/CardPinOperation.c	2010-03-18 16:03:39 UTC (rev 11)
@@ -488,6 +488,12 @@
 			Trace(WINEVENT_LEVEL_ERROR, L"dwFlags = 0x%08X", dwFlags);
 			__leave;
 		}
+		if (cRetryCount)
+		{
+			dwReturn = SCARD_E_INVALID_PARAMETER;
+			Trace(WINEVENT_LEVEL_ERROR, L"cRetryCount = %d", cRetryCount);
+			__leave;
+		}
 		dwReturn = CheckContext(pCardData);
 		if (dwReturn )
 		{
@@ -577,6 +583,12 @@
 			Trace(WINEVENT_LEVEL_ERROR, L"dwFlags = 0x%08X", dwFlags);
 			__leave;
 		}
+		if (cRetryCount)
+		{
+			dwReturn = SCARD_E_INVALID_PARAMETER;
+			Trace(WINEVENT_LEVEL_ERROR, L"cRetryCount = %d", cRetryCount);
+			__leave;
+		}
 		dwReturn = CheckContext(pCardData);
 		if ( dwReturn )
 		{
@@ -595,7 +607,8 @@
 			}
 		}
 		else if ( (dwAuthenticatingPinId == ROLE_ADMIN || dwAuthenticatingPinId == ROLE_PUK )
-					&&  dwTargetPinId == ROLE_USER  && dwFlags == PIN_CHANGE_FLAG_UNBLOCK) 
+					&&  (dwTargetPinId == ROLE_USER || dwTargetPinId == ROLE_AUTHENTICATION)
+					&& dwFlags == PIN_CHANGE_FLAG_UNBLOCK) 
 		{
 			dwReturn = ResetUserPIN(pCardData, dwAuthenticatingPinId,
 								pbAuthenticatingPinData, cbAuthenticatingPinData,

Modified: trunk/OpenPGPminidriver/ContextManagement.c
===================================================================
--- trunk/OpenPGPminidriver/ContextManagement.c	2010-03-15 18:23:17 UTC (rev 10)
+++ trunk/OpenPGPminidriver/ContextManagement.c	2010-03-18 16:03:39 UTC (rev 11)
@@ -175,12 +175,13 @@
 		}
 		else
 		{
-			if (pCardData->pvVendorSpecific)
+			/*if (pCardData->pvVendorSpecific)
 			{
 				Trace(WINEVENT_LEVEL_ERROR, L"pContext != NULL");
 				dwReturn = SCARD_E_UNEXPECTED;
 				__leave;
-			}
+			}*/
+			pCardData->pvVendorSpecific = NULL;
 		}
 		dwReturn = 0;
 	}

Modified: trunk/OpenPGPminidriver/CryptoOperations.c
===================================================================
--- trunk/OpenPGPminidriver/CryptoOperations.c	2010-03-15 18:23:17 UTC (rev 10)
+++ trunk/OpenPGPminidriver/CryptoOperations.c	2010-03-18 16:03:39 UTC (rev 11)
@@ -36,7 +36,7 @@
 OPENPGP_CONTAINER_INFO Containers[] = 
 {
 	{ROLE_SIGNATURE, AT_SIGNATURE},
-	{ROLE_CONFIDENTIALITY, AT_KEYEXCHANGE},
+	{ROLE_AUTHENTICATION, AT_KEYEXCHANGE},
 	{ROLE_AUTHENTICATION, AT_SIGNATURE}
 };
 typedef struct _OPENPGP_SUPPORTED_SIGNATURE_ALGORITHM
@@ -833,7 +833,7 @@
 			__leave;
 		}
 		// key len
-		Attributes.wModulusLengthInBit = (unsigned short)dwBitLen * 8;
+		Attributes.wModulusLengthInBit = (unsigned short)dwBitLen;
 		Attributes.wExponentLengthInBit = 4 * 8;
 		Attributes.bAlgoId = 1;
 		Attributes.bFormat = 0;
@@ -1104,6 +1104,12 @@
 			dwReturn = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
+		if (pInfo->cbData > 256)
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"Error failure pInfo->cbData = %d",pInfo->cbData);
+			dwReturn = SCARD_E_INVALID_PARAMETER;
+			__leave;
+		}
 		if (pInfo->dwSigningFlags & CARD_PADDING_INFO_PRESENT)
 		{
 			if ( pInfo->dwPaddingType == CARD_PADDING_PKCS1)

Modified: trunk/OpenPGPminidriver/PinOperations.c
===================================================================
--- trunk/OpenPGPminidriver/PinOperations.c	2010-03-15 18:23:17 UTC (rev 10)
+++ trunk/OpenPGPminidriver/PinOperations.c	2010-03-18 16:03:39 UTC (rev 11)
@@ -38,15 +38,17 @@
 		{
 		case ROLE_SIGNATURE:
 		case ROLE_AUTHENTICATION:
-		case ROLE_CONFIDENTIALITY:
 			dwMinPinSize = 6;
+			break;
 		case ROLE_PUK:
-			dwMinPinSize = 1;
+			// undocumented
+			dwMinPinSize = 8;
 			break;
 		case ROLE_ADMIN:
 			dwMinPinSize = 8;
 			break;
 		default:
+			Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_INVALID_PARAMETER PinId = %d",PinId);
 			dwReturn = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
@@ -66,7 +68,6 @@
 		{
 		case ROLE_SIGNATURE:
 		case ROLE_AUTHENTICATION:
-		case ROLE_CONFIDENTIALITY:
 			dwMaxPinSize = pbResponse[1];
 			break;
 		case ROLE_PUK:
@@ -107,7 +108,6 @@
 		{
 		case ROLE_SIGNATURE:
 		case ROLE_AUTHENTICATION:
-		case ROLE_CONFIDENTIALITY:
 			*pdwCounter = pbResponse[4];
 			break;
 		case ROLE_PUK:
@@ -150,7 +150,6 @@
 			pbCmd[3] = 0x81;
 			break;
 		case ROLE_AUTHENTICATION:
-		case ROLE_CONFIDENTIALITY:
 			pbCmd[3] = 0x82;
 			break;
 		case ROLE_ADMIN:
@@ -163,6 +162,12 @@
 			dwReturn = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
+		if (cbPin > 256)
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"Error failure PinId=%d cbPin = %d",PinId, cbPin);
+			dwReturn = SCARD_E_INVALID_PARAMETER;
+			__leave;
+		}
 		pbCmd[4] = (BYTE) cbPin;
 		memcpy(pbCmd + 5, pbPin, cbPin);
 		dwReturn = OCardSendCommand(pCardData, pbCmd, 5 + cbPin);
@@ -217,7 +222,6 @@
 		{
 		case ROLE_SIGNATURE:
 		case ROLE_AUTHENTICATION:
-		case ROLE_CONFIDENTIALITY:
 			pbCmd[3] = 0x81;
 			break;
 		case ROLE_ADMIN:
@@ -230,6 +234,12 @@
 			dwReturn = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
+		if (cbOldPin + cbNewPin > 256)
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"Error failure PinId=%d cbOldPin = %d cbNewPin = %d",PinId, cbOldPin, cbNewPin);
+			dwReturn = SCARD_E_INVALID_PARAMETER;
+			__leave;
+		}
 		pbCmd[4] = (BYTE) (cbOldPin + cbNewPin);
 		memcpy(pbCmd + 5, pbOldPin, cbOldPin);
 		memcpy(pbCmd + 5 + cbOldPin, pbNewPin, cbNewPin);
@@ -267,6 +277,12 @@
 			dwReturn = SCARD_E_INVALID_PARAMETER;
 			__leave;
 		}
+		if (cbNewPin + cbAuthenticator> 256)
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"Error failure PinId=%d cbNewPin = %d cbAuthenticator = %d",PinId, cbNewPin, cbAuthenticator);
+			dwReturn = SCARD_E_INVALID_PARAMETER;
+			__leave;
+		}
 		switch(PinId)
 		{
 		case ROLE_ADMIN:
@@ -381,7 +397,6 @@
 			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;
@@ -393,25 +408,12 @@
 			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;

Modified: trunk/OpenPGPminidriver/PinOperations.h
===================================================================
--- trunk/OpenPGPminidriver/PinOperations.h	2010-03-15 18:23:17 UTC (rev 10)
+++ trunk/OpenPGPminidriver/PinOperations.h	2010-03-18 16:03:39 UTC (rev 11)
@@ -18,8 +18,7 @@
 
 #define ROLE_SIGNATURE ROLE_USER
 #define ROLE_AUTHENTICATION 3
-#define ROLE_CONFIDENTIALITY 4
-#define ROLE_PUK 5
+#define ROLE_PUK 4
 
 DWORD CheckPinLength(__in PCARD_DATA  pCardData, __in PIN_ID  PinId, __in DWORD  cbPin);
 DWORD GetRemainingPin(__in PCARD_DATA  pCardData, __in PIN_ID  PinId, __out PDWORD pdwCounter);

Modified: trunk/OpenPGPminidriver/PublicDataOperations.c
===================================================================
--- trunk/OpenPGPminidriver/PublicDataOperations.c	2010-03-15 18:23:17 UTC (rev 10)
+++ trunk/OpenPGPminidriver/PublicDataOperations.c	2010-03-18 16:03:39 UTC (rev 11)
@@ -54,6 +54,7 @@
 {
 	{szOpenPGPDir, szOpenPGPFingerprint, StoredOnSmartCard, 0x6E, 0xC5, EveryoneReadAdminWriteAc},
 	{szOpenPGPDir, szOpenPGPStatus, StoredOnSmartCard, 0xC4, 0, EveryoneReadAdminWriteAc},
+	{szOpenPGPDir, szOpenPGPStatusPW1, StoredOnSmartCard, 0xC4, 0, EveryoneReadAdminWriteAc, OPENPGP_FILE_WRITE_ONLY},
 	{szOpenPGPDir, szOpenPGPApplicationIdentifier, StoredOnSmartCard, 0x4F, 0, UnknownAc},
 	{szOpenPGPDir, szOpenPGPLogin, StoredOnSmartCard, 0x5E, 0, EveryoneReadAdminWriteAc},
 	{szOpenPGPDir, szOpenPGPName, StoredOnSmartCard, 0x65, 0x5B, EveryoneReadAdminWriteAc},
@@ -61,7 +62,7 @@
 	{szOpenPGPDir, szOpenPGPSex, StoredOnSmartCard, 0x65, 0x5F35,EveryoneReadAdminWriteAc},
 	{szOpenPGPDir, szOpenPGPUrl, StoredOnSmartCard, 0x5F50, 0, EveryoneReadAdminWriteAc},
 	{szOpenPGPDir, szOpenPGPHistoricalBytes, StoredOnSmartCard, 0x5F52, 0, UnknownAc},
-	{szOpenPGPDir, szOpenPGPCertificate, StoredOnSmartCard, 0x7F21, 0, EveryoneReadAdminWriteAc, OPENPGP_FILE_NULL_LENGHT_EQUALS_MISSING},
+	{szOpenPGPDir, szOpenPGPCertificate, StoredOnSmartCard, 0x7F21, 0, EveryoneReadAdminWriteAc},
 	{szOpenPGPDir, szOpenPGPExtendedCap, StoredOnSmartCard, 0x6E, 0xC0, UnknownAc},
 	{szOpenPGPDir, szOpenPGPAlgoAttributesSignature, StoredOnSmartCard, 0x6E, 0xC1, UnknownAc},
 	{szOpenPGPDir, szOpenPGPAlgoAttributesDecryption, StoredOnSmartCard, 0x6E, 0xC2,UnknownAc},
@@ -71,8 +72,8 @@
 	{NULL, szCARD_APPLICATION_FILE, Virtual, 0, 0, EveryoneReadAdminWriteAc},
 	{NULL, szCACHE_FILE, Virtual, 0, 0, EveryoneReadUserWriteAc},
 	{szBASE_CSP_DIR, szCONTAINER_MAP_FILE, Virtual, 0, 0, EveryoneReadUserWriteAc},
-	{szBASE_CSP_DIR, "ksc1", StoredOnSmartCard, 0x7F21, 0, EveryoneReadAdminWriteAc, OPENPGP_FILE_NULL_LENGHT_EQUALS_MISSING | OPENPGP_FILE_CONF_IS_AUTH},
-	{szBASE_CSP_DIR, "ksc2", StoredOnSmartCard, 0x7F21, 0, EveryoneReadAdminWriteAc, OPENPGP_FILE_NULL_LENGHT_EQUALS_MISSING},
+	{szBASE_CSP_DIR, "kxc01", StoredOnSmartCard, 0x7F21, 0, EveryoneReadAdminWriteAc, OPENPGP_FILE_NULL_LENGHT_EQUALS_MISSING | OPENPGP_FILE_CONF_IS_AUTH},
+	{szBASE_CSP_DIR, "ksc02", StoredOnSmartCard, 0x7F21, 0, EveryoneReadAdminWriteAc, OPENPGP_FILE_NULL_LENGHT_EQUALS_MISSING},
 
 };
 
@@ -102,7 +103,7 @@
 	DWORD dwReturn = 0;
 	BOOL fDirectoryFound = FALSE;
 	BOOL fFileFound = FALSE;
-	BYTE pbCmd[] = {0x00, 0xCA, 0x00, 0x00, 0x00};
+	BYTE pbCmd[] = {0x00, 0xCA, 0x00, 0x00, 0x00, 0x00,0x00};
 	DWORD dwCmdSize = ARRAYSIZE(pbCmd);
 	POPENPGP_CONTEXT pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
 	PBYTE pbData = NULL;
@@ -164,6 +165,7 @@
 					{
 						Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_MEMORY");
 						dwReturn = SCARD_E_NO_MEMORY;
+						__leave;
 					}
 					memcpy(*ppbResponse, pbPointer, *pdwResponseSize);
 				}
@@ -171,6 +173,7 @@
 				{
 					dwReturn = SCARD_E_FILE_NOT_FOUND;
 					Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_FILE_NOT_FOUND %S",szFile);
+					__leave;
 				}
 			}
 			else
@@ -179,6 +182,31 @@
 				// do not free the data !
 				pbData = NULL;
 			}
+			if (Files[dwI].dwFlag & OPENPGP_FILE_NULL_LENGHT_EQUALS_MISSING)
+			{
+				if (*pdwResponseSize == 0)
+				{
+					pCardData->pfnCspFree(*ppbResponse);
+					*pdwResponseSize = 0;
+					*ppbResponse = NULL;
+					dwReturn = SCARD_E_FILE_NOT_FOUND;
+					Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_FILE_NOT_FOUND %S OPENPGP_FILE_NULL_LENGHT_EQUALS_MISSING",szFile);
+					__leave;
+				}
+			}
+			if (Files[dwI].dwFlag & OPENPGP_FILE_CONF_IS_AUTH)
+			{
+				DWORD dwTempReturn = OCardIsConfidentialityKeyTheSameThanAuthentication(pCardData);
+				if (dwTempReturn)
+				{
+					pCardData->pfnCspFree(*ppbResponse);
+					*pdwResponseSize = 0;
+					*ppbResponse = NULL;
+					dwReturn = SCARD_E_FILE_NOT_FOUND;
+					Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_FILE_NOT_FOUND %S OPENPGP_FILE_CONF_IS_AUTH",szFile);
+					__leave;
+				}
+			}
 		}
 		else
 		{
@@ -311,7 +339,7 @@
 				if (fAddToOuput && (Files[dwI].dwFlag & OPENPGP_FILE_CONF_IS_AUTH))
 				{
 					dwTempReturn = OCardIsConfidentialityKeyTheSameThanAuthentication(pCardData);
-					if (dwReturn)
+					if (dwTempReturn)
 					{
 						fAddToOuput = FALSE;
 					}
@@ -387,25 +415,98 @@
 	return dwReturn;	
 }
 
-DWORD OCardWriteFile(__in PCARD_DATA  pCardData, 
-					__in_opt PSTR szDirectory, __in PSTR szFile,
+DWORD OCardWriteFileOnSmartCard(__in PCARD_DATA  pCardData, 
+					__in OPENPGP_FILE File,
 					__in PBYTE pbData, __in DWORD dwSize)
 {
-	DWORD dwI;
 	DWORD dwReturn = 0;
-	BOOL fDirectoryFound = FALSE;
-	BOOL fFileFound = FALSE;
 	BYTE pbCmd[5 + 256] = {0x00, 0xDA, 0x00, 0x00, 0x00};
 	DWORD dwCmdSize = 0;
+	PBYTE pbCmdExtended = NULL;
 	__try
 	{
-		if (dwSize > 255)
+		if (dwSize > 0xFFFF)
 		{
 			dwReturn = SCARD_E_INVALID_PARAMETER;
 			Trace(WINEVENT_LEVEL_ERROR, L"dwSize %d",dwSize);
 			__leave;
 		}
+		if (dwSize < 256)
+		{
+			if (File.dwTlv > 0)
+			{
+				pbCmd[2] = (BYTE) (File.dwTlv / 0x100);
+				pbCmd[3] = (BYTE) (File.dwTlv % 0x100);
+			}
+			else
+			{
+				pbCmd[2] = (BYTE) (File.dwTag / 0x100);
+				pbCmd[3] = (BYTE) (File.dwTag % 0x100);
+			}
+			pbCmd[4] = (BYTE) dwSize;
+			if (dwSize)
+			{
+				memcpy(pbCmd + 5, pbData, dwSize);
+			}
+			dwCmdSize = dwSize + 5;
+			dwReturn = OCardSendCommand(pCardData, pbCmd, dwCmdSize);
+			if (dwReturn)
+			{
+				__leave;
+			}
+		}
+		else
+		{
+			dwCmdSize = dwSize + 7;
+			pbCmdExtended = pCardData->pfnCspAlloc(dwCmdSize);
+			if (!pbCmdExtended)
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_MEMORY");
+				dwReturn = SCARD_E_NO_MEMORY;
+				__leave;
+			}
+			pbCmdExtended[0] = 0;
+			pbCmdExtended[1] = 0xDA;
+			if (File.dwTlv > 0)
+			{
+				pbCmdExtended[2] = (BYTE) (File.dwTlv / 0x100);
+				pbCmdExtended[3] = (BYTE) (File.dwTlv % 0x100);
+			}
+			else
+			{
+				pbCmdExtended[2] = (BYTE) (File.dwTag / 0x100);
+				pbCmdExtended[3] = (BYTE) (File.dwTag % 0x100);
+			}
+			pbCmdExtended[4] = 0;
+			pbCmdExtended[5] = (BYTE)(dwSize / 0x100);
+			pbCmdExtended[6] = (BYTE)(dwSize % 0x100);
+			memcpy(pbCmdExtended + 7, pbData, dwSize);
+			dwReturn = OCardSendCommand(pCardData, pbCmdExtended, dwCmdSize);
+			if (dwReturn)
+			{
+				__leave;
+			}
+		}
+	}
+	__finally
+	{
+		if(pbCmdExtended)
+			pCardData->pfnCspFree(pbCmdExtended);
+	}
+	Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
+	return dwReturn;
+}
 
+DWORD OCardWriteFile(__in PCARD_DATA  pCardData, 
+					__in_opt PSTR szDirectory, __in PSTR szFile,
+					__in PBYTE pbData, __in DWORD dwSize)
+{
+	DWORD dwI;
+	DWORD dwReturn = 0;
+	BOOL fDirectoryFound = FALSE;
+	BOOL fFileFound = FALSE;
+	__try
+	{
 
 		for(dwI = 0; dwI < dwFileCount; dwI++)
 		{
@@ -444,27 +545,7 @@
 		}
 		if (Files[dwI].dwFileType == StoredOnSmartCard)
 		{
-			if (Files[dwI].dwTlv > 0)
-			{
-				pbCmd[2] = (BYTE) (Files[dwI].dwTlv / 0x100);
-				pbCmd[3] = (BYTE) (Files[dwI].dwTlv % 0x100);
-			}
-			else
-			{
-				pbCmd[2] = (BYTE) (Files[dwI].dwTag / 0x100);
-				pbCmd[3] = (BYTE) (Files[dwI].dwTag % 0x100);
-			}
-			pbCmd[4] = (BYTE) dwSize;
-			if (dwSize)
-			{
-				memcpy(pbCmd + 5, pbData, dwSize);
-			}
-			dwCmdSize = dwSize + 5;
-			dwReturn = OCardSendCommand(pCardData, pbCmd, dwCmdSize);
-			if (dwReturn)
-			{
-				__leave;
-			}
+			dwReturn = OCardWriteFileOnSmartCard(pCardData, Files[dwI], pbData, dwSize);
 		}
 		else
 		{
@@ -472,8 +553,6 @@
 			Trace(WINEVENT_LEVEL_ERROR, L"SCARD_W_SECURITY_VIOLATION %S",szFile);
 			__leave;
 		}
-
-		
 	}
 	__finally
 	{

Modified: trunk/OpenPGPminidriver/PublicDataOperations.h
===================================================================
--- trunk/OpenPGPminidriver/PublicDataOperations.h	2010-03-15 18:23:17 UTC (rev 10)
+++ trunk/OpenPGPminidriver/PublicDataOperations.h	2010-03-18 16:03:39 UTC (rev 11)
@@ -19,6 +19,7 @@
 #define szOpenPGPDir "openpgp"
 #define szOpenPGPFingerprint "fingerpr"
 #define szOpenPGPStatus "status"
+#define szOpenPGPStatusPW1 "statusP1"
 #define szOpenPGPApplicationIdentifier "aid"
 #define szOpenPGPLogin "logindat"
 #define szOpenPGPName "name"

Modified: trunk/OpenPGPminidriver/SmartCard.c
===================================================================
--- trunk/OpenPGPminidriver/SmartCard.c	2010-03-15 18:23:17 UTC (rev 10)
+++ trunk/OpenPGPminidriver/SmartCard.c	2010-03-18 16:03:39 UTC (rev 11)
@@ -124,6 +124,12 @@
 			dwReturn = SCARD_W_CHV_BLOCKED;
 			__leave;
 		}
+		else if ( (SW1 == 0x69) && (SW2 == 0x85) )
+		{
+			Trace(WINEVENT_LEVEL_ERROR, L"SCARD_W_SECURITY_VIOLATION");
+			dwReturn = SCARD_W_SECURITY_VIOLATION;
+			__leave;
+		}
 		else
 		{
 			TraceDump(WINEVENT_LEVEL_ERROR, pbCmd,dwCmdSize);
@@ -264,6 +270,12 @@
 				dwReturn = SCARD_W_CHV_BLOCKED;
 				__leave;
 			}
+			else if ( (SW1 == 0x69) && (SW2 == 0x85) )
+			{
+				Trace(WINEVENT_LEVEL_ERROR, L"SCARD_W_SECURITY_VIOLATION");
+				dwReturn = SCARD_W_SECURITY_VIOLATION;
+				__leave;
+			}
 			else
 			{
 				TraceDump(WINEVENT_LEVEL_ERROR, pbCmd,dwCmdSize);

Modified: trunk/OpenPGPminidriver/openpgpmdrv.inf
===================================================================
--- trunk/OpenPGPminidriver/openpgpmdrv.inf	2010-03-15 18:23:17 UTC (rev 10)
+++ trunk/OpenPGPminidriver/openpgpmdrv.inf	2010-03-18 16:03:39 UTC (rev 11)
@@ -8,7 +8,7 @@
 ClassGuid={990A2BD7-E738-46c7-B26F-1CF8FB9F1391}
 Provider=%OPENPGP%
 CatalogFile=delta.cat
-DriverVer=02/23/2010,0.0.0.1
+DriverVer=03/18/2010,0.0.0.1
 
 [Manufacturer]
 %OPENPGP%=OpenPGP,NTamd64,NTamd64.6.1,NTx86,NTx86.6.1

Modified: trunk/OpenPGPminidriverTest/Dialog.h
===================================================================
--- trunk/OpenPGPminidriverTest/Dialog.h	2010-03-15 18:23:17 UTC (rev 10)
+++ trunk/OpenPGPminidriverTest/Dialog.h	2010-03-18 16:03:39 UTC (rev 11)
@@ -14,7 +14,8 @@
 #define IDC_TXTPIN2 1205
 #define IDC_CHANGEPIN 1206
 #define IDC_UNBLOCKPIN 1207
-#define IDC_BTN1 1209
+#define IDC_SETPUK 1209
+#define IDC_PERSONNALIZE 1210
 #define IDD_CRYPTO 1300
 #define IDC_SAMEKEY 1301
 #define IDC_IMPORTKEY 1302

Modified: trunk/OpenPGPminidriverTest/Dialog.rc
===================================================================
--- trunk/OpenPGPminidriverTest/Dialog.rc	2010-03-15 18:23:17 UTC (rev 10)
+++ trunk/OpenPGPminidriverTest/Dialog.rc	2010-03-18 16:03:39 UTC (rev 11)
@@ -33,7 +33,8 @@
   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
+  CONTROL "Set Puk",IDC_SETPUK,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,267,66,54,21
+  CONTROL "Personnalize after the admin pin to succeed ms test for the driver",IDC_PERSONNALIZE,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,12,228,345,27
 END
 
 IDD_CRYPTO DIALOGEX 0,0,400,300

Modified: trunk/OpenPGPminidriverTest/OpenPGPminidriverTest.vcproj
===================================================================
--- trunk/OpenPGPminidriverTest/OpenPGPminidriverTest.vcproj	2010-03-15 18:23:17 UTC (rev 10)
+++ trunk/OpenPGPminidriverTest/OpenPGPminidriverTest.vcproj	2010-03-18 16:03:39 UTC (rev 11)
@@ -337,6 +337,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\Personnalize.cpp"
+				>
+			</File>
+			<File
 				RelativePath=".\PINOperations.cpp"
 				>
 			</File>

Modified: trunk/OpenPGPminidriverTest/PINOperations.cpp
===================================================================
--- trunk/OpenPGPminidriverTest/PINOperations.cpp	2010-03-15 18:23:17 UTC (rev 10)
+++ trunk/OpenPGPminidriverTest/PINOperations.cpp	2010-03-18 16:03:39 UTC (rev 11)
@@ -22,7 +22,7 @@
 
 DWORD Authenticate(PSTR szPin, PWSTR wszUserId, PDWORD pcAttemptsRemaining)
 {
-    DWORD cbPin = strlen(szPin);
+    DWORD cbPin = (DWORD) strlen(szPin);
 	DWORD dwReturn;
     __try
     {
@@ -48,8 +48,8 @@
 
 DWORD ChangePin(PSTR szPin, PSTR szPin2, PWSTR wszUserId, PDWORD pcAttemptsRemaining)
 {
-	WORD cbPin = strlen(szPin);
-	DWORD cbPin2 = strlen(szPin2);
+	DWORD cbPin = (DWORD) strlen(szPin);
+	DWORD cbPin2 = (DWORD) strlen(szPin2);
 	DWORD dwReturn;
     __try
     {
@@ -75,10 +75,42 @@
 
     return dwReturn;
 }
+
+DWORD SetPuk(PSTR szPin, PSTR szPin2, PDWORD pcAttemptsRemaining)
+{
+	DWORD cbPin = (DWORD) strlen(szPin);
+	DWORD cbPin2 = (DWORD) strlen(szPin2);
+	DWORD dwReturn;
+    __try
+    {
+        if (!pCardData)
+		{
+			dwReturn = SCARD_E_COMM_DATA_LOST;
+			__leave;
+		}
+
+        dwReturn = pCardData->pfnCardChangeAuthenticatorEx(
+            pCardData,
+            PIN_CHANGE_FLAG_CHANGEPIN, ROLE_ADMIN,
+            (PBYTE) szPin,
+            cbPin,
+			4,
+			(PBYTE) szPin2,
+            cbPin2,
+			0,
+            pcAttemptsRemaining);
+    }
+    __finally
+    {
+    }
+
+    return dwReturn;
+}
+
 DWORD ResetPin(PSTR szPin, PSTR szPin2, BOOL fIsPUK, PDWORD pcAttemptsRemaining)
 {
-	DWORD cbPin = strlen(szPin);
-	DWORD cbPin2 = strlen(szPin2);
+	DWORD cbPin = (DWORD) strlen(szPin);
+	DWORD cbPin2 = (DWORD) strlen(szPin2);
 	DWORD dwReturn;
     __try
     {

Modified: trunk/OpenPGPminidriverTest/PublicDataOperations.cpp
===================================================================
--- trunk/OpenPGPminidriverTest/PublicDataOperations.cpp	2010-03-15 18:23:17 UTC (rev 10)
+++ trunk/OpenPGPminidriverTest/PublicDataOperations.cpp	2010-03-18 16:03:39 UTC (rev 11)
@@ -106,6 +106,7 @@
 			__leave;
 		}
 		SendMessageA( GetDlgItem(hWnd,IDC_FILES), LB_GETTEXT,iItem,(LPARAM)szFileName);
+
 		szFile = strchr(szFileName,'\\');
 		if (szFile)
 		{
@@ -123,16 +124,30 @@
 		{
 			__leave;
 		}
-		for(DWORD dwI = 0; dwI < dwSize; dwI++)
+		if (strcmp(szDirectory, "openpgp") == 0 && strcmp(szFile, "certific") == 0 )
 		{
-			_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;
-				);
+			PCCERT_CONTEXT pCertContext = CertCreateCertificateContext( X509_ASN_ENCODING , pbData, dwSize);
+			if (!pCertContext)
+			{
+				dwReturn = GetLastError();
+				__leave;
+			}
+			ViewCertificate(hWnd, pCertContext);
+			CertFreeCertificateContext(pCertContext);
+		}
+		else
+		{
+			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
@@ -140,5 +155,5 @@
 		if (pbData)
 			pCardData->pfnCspFree(pbData);
 	}
-	return 0;
+	return dwReturn;
 }

Modified: trunk/OpenPGPminidriverTest/global.h
===================================================================
--- trunk/OpenPGPminidriverTest/global.h	2010-03-15 18:23:17 UTC (rev 10)
+++ trunk/OpenPGPminidriverTest/global.h	2010-03-18 16:03:39 UTC (rev 11)
@@ -21,6 +21,7 @@
 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 SetPuk(PSTR szPin, PSTR szPin2, PDWORD pcAttemptsRemaining);
 DWORD ListFiles(HWND hWnd);
 DWORD ViewFile(HWND hWnd);
 DWORD ListContainer(HWND hWnd);
@@ -31,4 +32,6 @@
 DWORD ImportKey(DWORD dwIndex);
 DWORD SetTheSameKeyForAllContainers();
 DWORD SetReadOnly(BOOL fSet);
+void ViewCertificate(HWND hWnd, PCCERT_CONTEXT pCertContext);
+DWORD Personnalize();
 #define OPENPGP_TEST_CONTAINER TEXT("Test_OPENPGPG")
\ No newline at end of file

Modified: trunk/OpenPGPminidriverTest/main.cpp
===================================================================
--- trunk/OpenPGPminidriverTest/main.cpp	2010-03-15 18:23:17 UTC (rev 10)
+++ trunk/OpenPGPminidriverTest/main.cpp	2010-03-18 16:03:39 UTC (rev 11)
@@ -19,6 +19,7 @@
 #include <tchar.h>
 #include <cardmod.h>
 #include <commctrl.h>
+#include <Cryptuiapi.h>
 #include "dialog.h"
 #include "global.h"
 
@@ -123,6 +124,34 @@
 	LocalFree(Error);
 }
 
+
+void ViewCertificate(HWND hWnd, PCCERT_CONTEXT pCertContext)
+{
+	CRYPTUI_VIEWCERTIFICATE_STRUCT certViewInfo;
+	BOOL fPropertiesChanged = FALSE;
+	certViewInfo.dwSize = sizeof(CRYPTUI_VIEWCERTIFICATE_STRUCT);
+	certViewInfo.hwndParent = hWnd;
+	certViewInfo.dwFlags = CRYPTUI_DISABLE_EDITPROPERTIES | CRYPTUI_DISABLE_ADDTOSTORE | CRYPTUI_DISABLE_EXPORT | CRYPTUI_DISABLE_HTMLLINK;
+	certViewInfo.szTitle = TEXT("Info");
+	certViewInfo.pCertContext = pCertContext;
+	certViewInfo.cPurposes = 0;
+	certViewInfo.rgszPurposes = 0;
+	certViewInfo.pCryptProviderData = NULL;
+	certViewInfo.hWVTStateData = NULL;
+	certViewInfo.fpCryptProviderDataTrustedUsage = FALSE;
+	certViewInfo.idxSigner = 0;
+	certViewInfo.idxCert = 0;
+	certViewInfo.fCounterSigner = FALSE;
+	certViewInfo.idxCounterSigner = 0;
+	certViewInfo.cStores = 0;
+	certViewInfo.rghStores = NULL;
+	certViewInfo.cPropSheetPages = 0;
+	certViewInfo.rgPropSheetPages = NULL;
+	certViewInfo.nStartPage = 0;
+	
+	CryptUIDlgViewCertificate(&certViewInfo,&fPropertiesChanged);
+}
+
 #define C_PAGES 5
  
 typedef struct tag_dlghdr { 
@@ -262,6 +291,16 @@
 				}
 				MessageBoxWin32(dwReturn);
 				break;
+			case IDC_SETPUK:
+				GetDlgItemTextA(hWnd,IDC_TXTPIN,szPin,ARRAYSIZE(szPin));
+				GetDlgItemTextA(hWnd,IDC_TXTPIN2,szPin2,ARRAYSIZE(szPin2));
+				dwReturn = SetPuk(szPin, szPin2, &dwRemaining);
+				MessageBoxWin32(dwReturn);
+				break;
+			case IDC_PERSONNALIZE:
+				dwReturn = Personnalize();
+				MessageBoxWin32(dwReturn);
+				break;
 		}
 		break;
 	}



More information about the Openpgpmdrv-commits mailing list