[Openpgpmdrv-commits] r9 - trunk/OpenPGPminidriver
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Mar 15 10:47:32 CET 2010
Author: vletoux
Date: 2010-03-15 10:47:30 +0100 (Mon, 15 Mar 2010)
New Revision: 9
Modified:
trunk/OpenPGPminidriver/CardAndContainerProperties.c
trunk/OpenPGPminidriver/CardCryptographicOperations.c
trunk/OpenPGPminidriver/CardInitializationAndDeconstruct.c
trunk/OpenPGPminidriver/CardKeyContainer.c
trunk/OpenPGPminidriver/CardPinOperation.c
trunk/OpenPGPminidriver/Context.h
trunk/OpenPGPminidriver/ContextManagement.c
trunk/OpenPGPminidriver/CryptoOperations.c
trunk/OpenPGPminidriver/CryptoOperations.h
trunk/OpenPGPminidriver/OpenPGPminidriver.vcproj
trunk/OpenPGPminidriver/PinOperations.c
trunk/OpenPGPminidriver/PublicDataOperations.c
trunk/OpenPGPminidriver/SmartCard.c
trunk/OpenPGPminidriver/openpgpmdrv.inf
Log:
more test success
Modified: trunk/OpenPGPminidriver/CardAndContainerProperties.c
===================================================================
--- trunk/OpenPGPminidriver/CardAndContainerProperties.c 2010-03-11 20:32:26 UTC (rev 8)
+++ trunk/OpenPGPminidriver/CardAndContainerProperties.c 2010-03-15 09:47:30 UTC (rev 9)
@@ -124,7 +124,7 @@
dwReturn = SCARD_E_INVALID_PARAMETER;
__leave;
}
- if (bContainerIndex >= MaxContainer)
+ if (bContainerIndex >= ContainerMax)
{
Trace(WINEVENT_LEVEL_ERROR, L"bContainerIndex == %d", bContainerIndex);
dwReturn = SCARD_E_NO_KEY_CONTAINER ;
@@ -150,7 +150,7 @@
__leave;
}
*pdwDataLen = cbData;
- if(bContainerIndex >= MaxContainer)
+ if(bContainerIndex >= ContainerMax)
{
dwReturn = SCARD_E_NO_KEY_CONTAINER;
Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", bContainerIndex);
@@ -644,12 +644,6 @@
dwReturn = SCARD_E_INVALID_PARAMETER;
__leave;
}
- if (dwFlags)
- {
- Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
- dwReturn = SCARD_E_INVALID_PARAMETER;
- __leave;
- }
if (wcscmp(wszProperty,CP_CARD_FREE_SPACE) == 0
|| wcscmp(wszProperty,CP_CARD_CAPABILITIES) == 0
|| wcscmp(wszProperty,CP_CARD_KEYSIZES) == 0
@@ -662,10 +656,33 @@
|| 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_GUID) == 0)
+ {
+ if (dwFlags)
+ {
+ Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
+ dwReturn = SCARD_E_INVALID_PARAMETER;
+ __leave;
+ }
+ 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_PIN_INFO) == 0
|| wcscmp(wszProperty,CP_CARD_PIN_STRENGTH_VERIFY) == 0)
{
+ if (dwFlags > ContainerMax)
+ {
+ Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
+ dwReturn = SCARD_E_INVALID_PARAMETER;
+ __leave;
+ }
if ( pbData == NULL )
{
Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
@@ -678,6 +695,12 @@
}
else if (wcscmp(wszProperty,CP_CARD_READ_ONLY) == 0)
{
+ if (dwFlags)
+ {
+ Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
+ dwReturn = SCARD_E_INVALID_PARAMETER;
+ __leave;
+ }
if ( pbData == NULL )
{
Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
@@ -688,6 +711,12 @@
}
else if (wcscmp(wszProperty,CP_PARENT_WINDOW) == 0)
{
+ if (dwFlags)
+ {
+ Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
+ dwReturn = SCARD_E_INVALID_PARAMETER;
+ __leave;
+ }
if ( pbData == NULL )
{
Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
@@ -700,19 +729,23 @@
dwReturn = SCARD_E_INVALID_PARAMETER ;
__leave;
}
- if ( *pbData != 0 && !IsWindow((HWND) *pbData) )
+ if ( *pbData != 0)
{
- Trace(WINEVENT_LEVEL_ERROR, L"*pbData == %d GetLastError == %d", *pbData, GetLastError());
- dwReturn = SCARD_E_INVALID_PARAMETER ;
- __leave;
+ if (IsWindow( *((HWND*)pbData)) == 0)
+ {
+ Trace(WINEVENT_LEVEL_ERROR, L"*pbData == %d GetLastError == %d", *((HWND*)pbData), GetLastError());
+ dwReturn = SCARD_E_INVALID_PARAMETER ;
+ __leave;
+ }
}
+ Trace(WINEVENT_LEVEL_VERBOSE, L"CP_PARENT_WINDOW = %d", *((HWND*)pbData));
dwReturn = 0;
}
else if (wcscmp(wszProperty,CP_PIN_CONTEXT_STRING) == 0)
{
- if ( pbData == NULL )
+ if (dwFlags)
{
- Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
+ Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
dwReturn = SCARD_E_INVALID_PARAMETER;
__leave;
}
Modified: trunk/OpenPGPminidriver/CardCryptographicOperations.c
===================================================================
--- trunk/OpenPGPminidriver/CardCryptographicOperations.c 2010-03-11 20:32:26 UTC (rev 8)
+++ trunk/OpenPGPminidriver/CardCryptographicOperations.c 2010-03-15 09:47:30 UTC (rev 9)
@@ -71,7 +71,7 @@
dwReturn = SCARD_E_INVALID_PARAMETER ;
__leave;
}
- if (pInfo->bContainerIndex != Confidentiality)
+ if (pInfo->bContainerIndex != ContainerConfidentiality)
{
Trace(WINEVENT_LEVEL_ERROR, L"Confidentiality %d", pInfo->bContainerIndex);
dwReturn = SCARD_E_NO_KEY_CONTAINER ;
@@ -155,10 +155,10 @@
}
switch(pInfo->bContainerIndex)
{
- case Authentication:
+ case ContainerAuthentication:
dwReturn = OCardAuthenticate(pCardData, pInfo);
break;
- case Signature:
+ case ContainerSignature:
dwReturn = OCardSign(pCardData, pInfo);
break;
default:
Modified: trunk/OpenPGPminidriver/CardInitializationAndDeconstruct.c
===================================================================
--- trunk/OpenPGPminidriver/CardInitializationAndDeconstruct.c 2010-03-11 20:32:26 UTC (rev 8)
+++ trunk/OpenPGPminidriver/CardInitializationAndDeconstruct.c 2010-03-15 09:47:30 UTC (rev 9)
@@ -67,7 +67,7 @@
pCardData->pfnCardGetChallenge = CardGetChallenge;
pCardData->pfnCardAuthenticateChallenge = CardAuthenticateChallenge;
- pCardData->pfnCardDeauthenticate = CardDeauthenticate;
+ pCardData->pfnCardDeauthenticate = NULL; //CardDeauthenticate;
pCardData->pfnCardAuthenticateEx = CardAuthenticateEx;
pCardData->pfnCardGetChallengeEx = CardGetChallengeEx;
pCardData->pfnCardDeauthenticateEx = CardDeauthenticateEx;
Modified: trunk/OpenPGPminidriver/CardKeyContainer.c
===================================================================
--- trunk/OpenPGPminidriver/CardKeyContainer.c 2010-03-11 20:32:26 UTC (rev 8)
+++ trunk/OpenPGPminidriver/CardKeyContainer.c 2010-03-15 09:47:30 UTC (rev 9)
@@ -49,18 +49,12 @@
dwReturn = SCARD_E_INVALID_PARAMETER;
__leave;
}
- if (bContainerIndex >= MaxContainer)
+ if (bContainerIndex >= ContainerMax)
{
Trace(WINEVENT_LEVEL_ERROR, L"bContainerIndex == %d",bContainerIndex);
dwReturn = SCARD_E_NO_KEY_CONTAINER;
__leave;
}
- if (Containers[bContainerIndex].dwKeySpec != dwKeySpec)
- {
- Trace(WINEVENT_LEVEL_ERROR, L"dwKeySpec == %d",dwKeySpec);
- dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
- __leave;
- }
// controls are done in CardCreateContainerEx
dwReturn = CardCreateContainerEx(pCardData,
bContainerIndex,
@@ -109,7 +103,7 @@
dwReturn = SCARD_E_INVALID_PARAMETER;
__leave;
}
- if (bContainerIndex >= MaxContainer)
+ if (bContainerIndex >= ContainerMax)
{
Trace(WINEVENT_LEVEL_ERROR, L"bContainerIndex == %d",bContainerIndex);
dwReturn = SCARD_E_NO_KEY_CONTAINER;
@@ -220,7 +214,7 @@
dwReturn = SCARD_E_INVALID_PARAMETER;
__leave;
}
- if (bContainerIndex >= MaxContainer)
+ if (bContainerIndex >= ContainerMax)
{
Trace(WINEVENT_LEVEL_ERROR, L"bContainerIndex == %d",bContainerIndex);
dwReturn = SCARD_E_NO_KEY_CONTAINER;
@@ -237,12 +231,12 @@
pContainerInfo->cbKeyExPublicKey = 0;
switch(bContainerIndex)
{
- case Signature:
- case Authentication:
+ case ContainerSignature:
+ case ContainerAuthentication:
dwReturn = OCardReadPublicKey(pCardData, bContainerIndex,
&(pContainerInfo->pbSigPublicKey),&(pContainerInfo->cbSigPublicKey));
break;
- case Confidentiality:
+ case ContainerConfidentiality:
dwReturn = OCardReadPublicKey(pCardData, bContainerIndex,
&(pContainerInfo->pbKeyExPublicKey),&(pContainerInfo->cbKeyExPublicKey));
break;
Modified: trunk/OpenPGPminidriver/CardPinOperation.c
===================================================================
--- trunk/OpenPGPminidriver/CardPinOperation.c 2010-03-11 20:32:26 UTC (rev 8)
+++ trunk/OpenPGPminidriver/CardPinOperation.c 2010-03-15 09:47:30 UTC (rev 9)
@@ -161,7 +161,7 @@
)
{
DWORD dwReturn = 0;
- Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
+ Trace(WINEVENT_LEVEL_VERBOSE, L"Enter %s", pwszUserId);
__try
{
if ( pCardData == NULL )
@@ -194,7 +194,7 @@
__finally
{
}
- Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
+ Trace(WINEVENT_LEVEL_VERBOSE, L"%s dwReturn = 0x%08X", pwszUserId,dwReturn);
return dwReturn;
}
@@ -227,12 +227,6 @@
dwReturn = SCARD_E_INVALID_PARAMETER;
__leave;
}
- if ( pbPinData == NULL )
- {
- Trace(WINEVENT_LEVEL_ERROR, L"pbPinData == NULL");
- dwReturn = SCARD_E_INVALID_PARAMETER;
- __leave;
- }
if ((dwFlags & CARD_AUTHENTICATE_GENERATE_SESSION_PIN)
|| (dwFlags & CARD_AUTHENTICATE_SESSION_PIN))
{
@@ -250,6 +244,12 @@
__leave;
}
}
+ if ( pbPinData == NULL )
+ {
+ Trace(WINEVENT_LEVEL_ERROR, L"pbPinData == NULL");
+ dwReturn = SCARD_E_INVALID_PARAMETER;
+ __leave;
+ }
dwReturn = CheckContext(pCardData);
if ( dwReturn )
{
@@ -308,7 +308,7 @@
)
{
DWORD dwReturn = 0;
- Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
+ Trace(WINEVENT_LEVEL_VERBOSE, L"Enter PinId = %d", PinId);
__try
{
if ( pCardData == NULL )
@@ -335,7 +335,7 @@
__finally
{
}
- Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
+ Trace(WINEVENT_LEVEL_VERBOSE, L"PinId = %d dwReturn = 0x%08X",PinId, dwReturn);
return dwReturn;
}
Modified: trunk/OpenPGPminidriver/Context.h
===================================================================
--- trunk/OpenPGPminidriver/Context.h 2010-03-11 20:32:26 UTC (rev 8)
+++ trunk/OpenPGPminidriver/Context.h 2010-03-15 09:47:30 UTC (rev 9)
@@ -50,6 +50,7 @@
DWORD GET_KEY_PRESSED;
} FEATURES, *PFEATURES;
+#define KEYMAX 3
typedef struct _OPENPGP_CONTEXT
{
OPENPGP_AID Aid;
@@ -61,10 +62,11 @@
DWORD dwMaxCertificateLength;
DWORD dwMaxCommandDataLength;
DWORD dwMaxResponseLength;
- BOOL fHasSignature;
- BOOL fHasDecryption;
- BOOL fHasAuthentication;
+ BOOL fHasKey[KEYMAX];
BOOL fIsReadOnly;
+ BYTE bFingerPrint[60];
+ PBYTE pbKeyCache[KEYMAX];
+ DWORD dwKeyCacheSize[KEYMAX];
} OPENPGP_CONTEXT, *POPENPGP_CONTEXT ;
DWORD CreateContext(__in PCARD_DATA pCardData, __in DWORD dwFlags);
Modified: trunk/OpenPGPminidriver/ContextManagement.c
===================================================================
--- trunk/OpenPGPminidriver/ContextManagement.c 2010-03-11 20:32:26 UTC (rev 8)
+++ trunk/OpenPGPminidriver/ContextManagement.c 2010-03-15 09:47:30 UTC (rev 9)
@@ -21,6 +21,7 @@
#include "Context.h"
#include "Smartcard.h"
#include "PublicDataOperations.h"
+#include "CryptoOperations.h"
SCARD_ATRMASK SupportedATR [] =
{
@@ -237,7 +238,7 @@
dwApplicationIdentifierSize,
dwExtendedCapabilitiesSize,
dwFingerPrintSize;
- DWORD dwI;
+ DWORD dwI, dwJ;
BYTE bCategoryIndicator, bStatusIndicator;
POPENPGP_CONTEXT pContext;
__try
@@ -348,33 +349,19 @@
dwReturn = SCARD_E_UNEXPECTED;
__leave;
}
- pContext->fHasSignature = FALSE;
- for( dwI = 0; dwI < 20; dwI++)
+ memcpy(pContext->bFingerPrint, pbFingerPrint, 60);
+ for(dwJ = 0; dwJ < KeyMax; dwJ++)
{
- if (pbFingerPrint[dwI] != 0)
+ pContext->fHasKey[dwJ] = FALSE;
+ for( dwI = dwJ * 20; dwI < dwJ * 20 + 20; dwI++)
{
- pContext->fHasSignature = TRUE;
- break;
+ if (pbFingerPrint[dwI] != 0)
+ {
+ pContext->fHasKey[dwJ] = TRUE;
+ break;
+ }
}
}
- pContext->fHasDecryption = FALSE;
- for( dwI = 20; dwI < 40; dwI++)
- {
- if (pbFingerPrint[dwI] != 0)
- {
- pContext->fHasDecryption = TRUE;
- break;
- }
- }
- pContext->fHasAuthentication = FALSE;
- for( dwI = 40; dwI < 60; dwI++)
- {
- if (pbFingerPrint[dwI] != 0)
- {
- pContext->fHasAuthentication = TRUE;
- break;
- }
- }
dwReturn = CCIDgetFeatures(pCardData);
if (dwReturn)
{
Modified: trunk/OpenPGPminidriver/CryptoOperations.c
===================================================================
--- trunk/OpenPGPminidriver/CryptoOperations.c 2010-03-11 20:32:26 UTC (rev 8)
+++ trunk/OpenPGPminidriver/CryptoOperations.c 2010-03-15 09:47:30 UTC (rev 9)
@@ -26,20 +26,26 @@
#include "PublicDataOperations.h"
#include "tlv.h"
-OPENPGP_CONTAINER_INFO Containers[] =
+OPENPGP_KEY_INFO Keys[] =
{
- {0xB6, 0xCE, 0xC7, CALG_RSA_SIGN, AT_SIGNATURE, ROLE_SIGNATURE},
- {0xA4, 0xD0, 0xC9, CALG_RSA_SIGN, AT_SIGNATURE, ROLE_AUTHENTICATION},
- {0xB8, 0xCF, 0xC8, CALG_RSA_KEYX, AT_KEYEXCHANGE, ROLE_CONFIDENTIALITY}
-
+ {0xB6, 0xCE, 0xC7, CALG_RSA_SIGN}, // signature
+ {0xA4, 0xD0, 0xC9, CALG_RSA_SIGN}, // authentication
+ {0xB8, 0xCF, 0xC8, CALG_RSA_KEYX} // confidentiality
};
+OPENPGP_CONTAINER_INFO Containers[] =
+{
+ {ROLE_SIGNATURE, AT_SIGNATURE},
+ {ROLE_AUTHENTICATION, AT_SIGNATURE},
+ {ROLE_CONFIDENTIALITY, AT_KEYEXCHANGE}
+};
typedef struct _OPENPGP_SUPPORTED_SIGNATURE_ALGORITHM
{
ALG_ID aiHashAlg;
DWORD dwHashSize;
PBYTE pbEncodedOid;
DWORD dwEncodedOidSize;
+ PWSTR szAlgId;
} OPENPGP_SUPPORTED_SIGNATURE_ALGORITHM, *POPENPGP_SUPPORTED_SIGNATURE_ALGORITHM;
BYTE dwSHA1EncodedOid[] = {0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03,
@@ -55,16 +61,16 @@
{
{CALG_SHA1,20,
dwSHA1EncodedOid,
- ARRAYSIZE(dwSHA1EncodedOid)},
+ ARRAYSIZE(dwSHA1EncodedOid), BCRYPT_SHA1_ALGORITHM},
{CALG_SHA-256,32,
dwSHA256EncodedOid,
- ARRAYSIZE(dwSHA256EncodedOid)},
+ ARRAYSIZE(dwSHA256EncodedOid), BCRYPT_SHA256_ALGORITHM},
{CALG_SHA-384,48,
dwSHA384EncodedOid,
- ARRAYSIZE(dwSHA384EncodedOid)},
+ ARRAYSIZE(dwSHA384EncodedOid), BCRYPT_SHA384_ALGORITHM},
{CALG_SHA-512,64,
dwSHA512EncodedOid,
- ARRAYSIZE(dwSHA512EncodedOid)},
+ ARRAYSIZE(dwSHA512EncodedOid), BCRYPT_SHA512_ALGORITHM},
};
DWORD dwSignatureAlgorithmCount = ARRAYSIZE(SignatureAlgorithm);
@@ -80,7 +86,7 @@
DWORD OCardGetKeyAlgorithmAttributes(__in PCARD_DATA pCardData,
- __in OPENPGP_CONTAINER dwContainer,
+ __in OPENPGP_KEY dwKey,
__out POPENPGP_ALGORITHM_ATTRIBUTE pAttributes)
{
DWORD dwReturn;
@@ -90,21 +96,21 @@
WORD wTemp;
__try
{
- Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",dwContainer);
- switch(dwContainer)
+ Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",dwKey);
+ switch(dwKey)
{
- case Signature:
+ case KeySignature:
szAlgorithmAttributes = szOpenPGPAlgoAttributesSignature;
break;
- case Authentication:
+ case KeyAuthentication:
szAlgorithmAttributes = szOpenPGPAlgoAttributesDecryption;
break;
- case Confidentiality:
+ case KeyConfidentiality:
szAlgorithmAttributes = szOpenPGPAlgoAttributesAuthentication;
break;
default:
dwReturn = SCARD_E_NO_KEY_CONTAINER;
- Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", dwContainer);
+ Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", dwKey);
__leave;
}
dwReturn = OCardReadFile(pCardData, szOpenPGPDir, szAlgorithmAttributes, &pbData, &dwResponseSize);
@@ -137,7 +143,7 @@
}
DWORD OCardSetKeyAlgorithmAttributes(__in PCARD_DATA pCardData,
- __in OPENPGP_CONTAINER dwContainer,
+ __in OPENPGP_KEY dwKey,
__out POPENPGP_ALGORITHM_ATTRIBUTE pAttributes)
{
DWORD dwReturn;
@@ -146,21 +152,21 @@
WORD wTemp;
__try
{
- Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",dwContainer);
- switch(dwContainer)
+ Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",dwKey);
+ switch(dwKey)
{
- case Signature:
+ case KeySignature:
szAlgorithmAttributes = szOpenPGPAlgoAttributesSignature;
break;
- case Authentication:
+ case KeyAuthentication:
szAlgorithmAttributes = szOpenPGPAlgoAttributesDecryption;
break;
- case Confidentiality:
+ case KeyConfidentiality:
szAlgorithmAttributes = szOpenPGPAlgoAttributesAuthentication;
break;
default:
dwReturn = SCARD_E_NO_KEY_CONTAINER;
- Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", dwContainer);
+ Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", dwKey);
__leave;
}
memcpy(&TempAttributes, pAttributes, sizeof(OPENPGP_ALGORITHM_ATTRIBUTE));
@@ -211,7 +217,7 @@
}
DWORD BuildPrivateKeyTlv(__in PCARD_DATA pCardData, __in PRSAPUBLICKEYBLOB pbPublicKeyBlob,
- __in OPENPGP_CONTAINER dwContainer, __in BYTE bFormat,
+ __in OPENPGP_KEY dwKey, __in BYTE bFormat,
__out PBYTE * ppbTlv, __out PDWORD pdwTlvSize)
{
// structure of the keyblob
@@ -298,7 +304,7 @@
memcpy(*ppbTlv + dwOffset, b4DHeader, dw4DHeaderSize);
dwOffset += dw4DHeaderSize;
// control reference templace
- (*ppbTlv)[dwOffset++] = Containers[dwContainer].bKeyTag;
+ (*ppbTlv)[dwOffset++] = Keys[dwKey].bKeyTag;
(*ppbTlv)[dwOffset++] = 0;
// cardholder private key template
memcpy(*ppbTlv + dwOffset, b7F48Header, dw7F48HeaderSize);
@@ -368,7 +374,7 @@
return dwReturn;
}
-DWORD UpdateGenerationDateTime(__in PCARD_DATA pCardData, __in OPENPGP_CONTAINER dwContainer,
+DWORD UpdateGenerationDateTime(__in PCARD_DATA pCardData, __in OPENPGP_KEY dwKey,
__out PDWORD pdwSecondsSince1970)
{
DWORD dwReturn = 0;
@@ -395,7 +401,7 @@
WindowsTime.LowPart = WindowsFileTime.dwLowDateTime;
*pdwSecondsSince1970 = (DWORD)((WindowsTime.QuadPart - UnixZeroTime.QuadPart) / 10000000);
- pbCommand[3] = Containers[dwContainer].bDateTimeTag;
+ pbCommand[3] = Keys[dwKey].bDateTimeTag;
pbCommand[5] = (BYTE) (*pdwSecondsSince1970 / 0x1000000);
pbCommand[6] = (BYTE) ((*pdwSecondsSince1970 % 0x1000000) / 0x10000);
pbCommand[7] = (BYTE) ((*pdwSecondsSince1970 % 0x10000) / 0x100);
@@ -409,7 +415,7 @@
return dwReturn;
}
-DWORD UpdateFingerPrint(__in PCARD_DATA pCardData, __in OPENPGP_CONTAINER dwContainer,
+DWORD UpdateFingerPrint(__in PCARD_DATA pCardData, __in OPENPGP_KEY dwKey,
__in DWORD dwSecondsSince1970,
__in PBYTE pbModulus, __in DWORD dwModulusSizeInBit,
__in BOOL fIsModulusInBigEndian,
@@ -498,7 +504,7 @@
Trace(WINEVENT_LEVEL_ERROR, L"CryptGetHashParam 0x%08X", dwReturn);
__leave;
}
- pbCommand[3] = Containers[dwContainer].bSignatureTag;
+ pbCommand[3] = Keys[dwKey].bSignatureTag;
dwReturn = OCardSendCommand(pCardData, pbCommand, dwCommandSize);
}
@@ -517,7 +523,7 @@
}
-DWORD OCardReadPublicKey(PCARD_DATA pCardData, OPENPGP_CONTAINER dwContainer, PBYTE *pbPublicKey, PDWORD pdwPublicKeySize)
+DWORD OCardReadPublicKey(PCARD_DATA pCardData, OPENPGP_KEY dwKey, PBYTE *pbPublicKey, PDWORD pdwPublicKeySize)
{
DWORD dwReturn;
PBYTE pbData = NULL;
@@ -543,15 +549,15 @@
DWORD dwTotalTlvSize, dwOffset;
__try
{
- Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",dwContainer);
- if (dwContainer >= MaxContainer)
+ Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwKey=%d",dwKey);
+ if (dwKey >= KeyMax)
{
dwReturn = SCARD_E_NO_KEY_CONTAINER;
- Trace(WINEVENT_LEVEL_INFO, L"SCARD_E_NO_KEY_CONTAINER %d", dwContainer);
+ Trace(WINEVENT_LEVEL_INFO, L"SCARD_E_NO_KEY_CONTAINER %d", dwKey);
__leave;
}
pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
- pbCmd[7] = Containers[dwContainer].bKeyTag;
+ pbCmd[7] = Keys[dwKey].bKeyTag;
dwCmdSize = 9;
if (pContext->fExtentedLeLcFields)
{
@@ -588,7 +594,7 @@
if (!*pbPublicKey)
{
dwReturn = SCARD_E_NO_MEMORY;
- Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_MEMORY %d", dwContainer);
+ Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_MEMORY %d", dwKey);
__leave;
}
pbBlob = (PRSAPUBLICKEYBLOB) *pbPublicKey;
@@ -596,7 +602,7 @@
pbBlob->blobheader.bType = PUBLICKEYBLOB;
pbBlob->blobheader.bVersion = CUR_BLOB_VERSION;
pbBlob->blobheader.reserved = 0;
- pbBlob->blobheader.aiKeyAlg = Containers[dwContainer].aiKeyAlg;
+ pbBlob->blobheader.aiKeyAlg = Keys[dwKey].aiKeyAlg;
pbBlob->rsapubkey.magic = 0x31415352; //'RSA1';
pbBlob->rsapubkey.bitlen = dwModulusSize*8;
pbBlob->rsapubkey.pubexp = pbExponent[0] * 0x1000000 + pbExponent[1] * 0x10000 + pbExponent[2] * 0x100 + pbExponent[3];
@@ -611,12 +617,14 @@
}
__finally
{
+ if (pbData)
+ pCardData->pfnCspFree(pbData);
}
Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
return dwReturn;
}
-DWORD OCardCreateKey(PCARD_DATA pCardData, OPENPGP_CONTAINER dwContainer, DWORD dwBitLen)
+DWORD OCardCreateKey(PCARD_DATA pCardData, OPENPGP_KEY dwKey, DWORD dwBitLen)
{
DWORD dwReturn;
PBYTE pbData = NULL;
@@ -641,28 +649,28 @@
DWORD dwTotalTlvSize, dwOffset;
__try
{
- Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",dwContainer);
- if (dwContainer >= MaxContainer)
+ Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwKey=%d",dwKey);
+ if (dwKey >= KeyMax)
{
dwReturn = SCARD_E_NO_KEY_CONTAINER;
- Trace(WINEVENT_LEVEL_INFO, L"SCARD_E_NO_KEY_CONTAINER %d", dwContainer);
+ Trace(WINEVENT_LEVEL_INFO, L"SCARD_E_NO_KEY_CONTAINER %d", dwKey);
__leave;
}
// key len
- dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, dwContainer, &Attributes);
+ dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, dwKey, &Attributes);
if (dwReturn)
{
__leave;
}
Attributes.wModulusLengthInBit = (WORD) dwBitLen;
- dwReturn = OCardSetKeyAlgorithmAttributes(pCardData, dwContainer, &Attributes);
+ dwReturn = OCardSetKeyAlgorithmAttributes(pCardData, dwKey, &Attributes);
if (dwReturn)
{
__leave;
}
pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
- pbCmd[7] = Containers[dwContainer].bKeyTag;
+ pbCmd[7] = Keys[dwKey].bKeyTag;
dwCmdSize = 9;
if (pContext->fExtentedLeLcFields)
{
@@ -694,12 +702,12 @@
__leave;
}
dwExponent = pbExponent[0] * 0x1000000 + pbExponent[1] * 0x10000 + pbExponent[2] * 0x100 + pbExponent[3];
- dwReturn = UpdateGenerationDateTime(pCardData, dwContainer, &dwSecondsSince1970);
+ dwReturn = UpdateGenerationDateTime(pCardData, dwKey, &dwSecondsSince1970);
if (dwReturn)
{
__leave;
}
- dwReturn = UpdateFingerPrint(pCardData, dwContainer, dwSecondsSince1970,
+ dwReturn = UpdateFingerPrint(pCardData, dwKey, dwSecondsSince1970,
pbModulus,
dwModulusSize * 8,
TRUE,
@@ -709,18 +717,7 @@
{
__leave;
}
- switch(dwContainer)
- {
- case Signature:
- pContext->fHasSignature = TRUE;
- break;
- case Authentication:
- pContext->fHasAuthentication = TRUE;
- break;
- case Confidentiality:
- pContext->fHasDecryption = TRUE;
- break;
- }
+ pContext->fHasKey[dwKey] = TRUE;
}
__finally
{
@@ -732,7 +729,7 @@
}
DWORD OCardImportKey(PCARD_DATA pCardData,
- OPENPGP_CONTAINER dwContainer,
+ OPENPGP_KEY dwKey,
PBYTE pBlob,
DWORD dwKeySize)
{
@@ -746,9 +743,10 @@
PRSAPUBLICKEYBLOB pbPublicKeyBlob = (PRSAPUBLICKEYBLOB) pBlob;
BYTE bCommand[] = {0x00,0xDB,0x3F,0xFF};
DWORD dwSecondsSince1970;
+ POPENPGP_CONTEXT pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
__try
{
- Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",dwContainer);
+ Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",dwKey);
// check blob
if (pbPublicKeyBlob->blobheader.aiKeyAlg != CALG_RSA_SIGN &&
pbPublicKeyBlob->blobheader.aiKeyAlg != CALG_RSA_KEYX)
@@ -770,18 +768,18 @@
__leave;
}
- dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, dwContainer, &Attributes);
+ dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, dwKey, &Attributes);
if (dwReturn)
{
__leave;
}
Attributes.wModulusLengthInBit = (WORD) pbPublicKeyBlob->rsapubkey.bitlen;
- dwReturn = OCardSetKeyAlgorithmAttributes(pCardData, dwContainer, &Attributes);
+ dwReturn = OCardSetKeyAlgorithmAttributes(pCardData, dwKey, &Attributes);
if (dwReturn)
{
__leave;
}
- dwReturn = BuildPrivateKeyTlv(pCardData, pbPublicKeyBlob, dwContainer, Attributes.bFormat, &pbTlv, &dwTlvSize);
+ dwReturn = BuildPrivateKeyTlv(pCardData, pbPublicKeyBlob, dwKey, Attributes.bFormat, &pbTlv, &dwTlvSize);
if (dwReturn)
{
__leave;
@@ -820,12 +818,12 @@
{
__leave;
}
- dwReturn = UpdateGenerationDateTime(pCardData, dwContainer, &dwSecondsSince1970);
+ dwReturn = UpdateGenerationDateTime(pCardData, dwKey, &dwSecondsSince1970);
if (dwReturn)
{
__leave;
}
- dwReturn = UpdateFingerPrint(pCardData, dwContainer, dwSecondsSince1970,
+ dwReturn = UpdateFingerPrint(pCardData, dwKey, dwSecondsSince1970,
pbPublicKeyBlob->modulus,
pbPublicKeyBlob->rsapubkey.bitlen,
FALSE,
@@ -835,18 +833,7 @@
{
__leave;
}
- switch(dwContainer)
- {
- case Signature:
- pContext->fHasSignature = TRUE;
- break;
- case Authentication:
- pContext->fHasAuthentication = TRUE;
- break;
- case Confidentiality:
- pContext->fHasDecryption = TRUE;
- break;
- }
+ pContext->fHasKey[dwKey] = TRUE;
}
__finally
{
@@ -865,24 +852,11 @@
return dwReturn;
}
-DWORD OCardSign(PCARD_DATA pCardData,
- PCARD_SIGNING_INFO pInfo)
+DWORD OCardCheckSigningInfo(__in PCARD_SIGNING_INFO pInfo, __out PDWORD pdwIndex)
{
- DWORD dwReturn;
- PBYTE pbData = NULL;
- DWORD dwCmdSize = 0, dwI;
- POPENPGP_CONTEXT pContext;
- OPENPGP_ALGORITHM_ATTRIBUTE Attributes;
- BYTE pbCmd[6 + 256 + 256] = {0x00,
- 0x2A,
- 0x9E,
- 0x9A,
- 0x00,
- 0x00,
- };
+ DWORD dwReturn, dwI;
__try
{
- Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",pInfo->bContainerIndex);
if (pInfo->dwSigningFlags & ~(CARD_PADDING_INFO_PRESENT | CARD_BUFFER_SIZE_ONLY | CRYPT_NOHASHOID | CRYPT_TYPE2_FORMAT))
{
Trace(WINEVENT_LEVEL_ERROR, L"wrong flag %d", pInfo->dwSigningFlags);
@@ -893,9 +867,21 @@
{
if ( pInfo->dwPaddingType == CARD_PADDING_PKCS1)
{
- dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
- Trace(WINEVENT_LEVEL_ERROR, L"CARD_PADDING_PKCS1");
- __leave;
+ BCRYPT_PKCS1_PADDING_INFO* padding = (BCRYPT_PKCS1_PADDING_INFO*) pInfo->pPaddingInfo;
+ for(dwI = 0 ; dwI < dwSignatureAlgorithmCount ; dwI++)
+ {
+ if (wcscmp(SignatureAlgorithm[dwI].szAlgId,padding->pszAlgId) == 0)
+ {
+ // found
+ break;
+ }
+ }
+ if (dwI >= dwSignatureAlgorithmCount)
+ {
+ Trace(WINEVENT_LEVEL_ERROR, L"alg not found %s", padding->pszAlgId);
+ dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
+ __leave;
+ }
}
else if (pInfo->dwPaddingType == CARD_PADDING_PSS)
{
@@ -910,34 +896,69 @@
__leave;
}
}
- if (!(pInfo->aiHashAlg & ALG_CLASS_HASH))
+ else
{
- dwReturn = SCARD_E_INVALID_PARAMETER;
- Trace(WINEVENT_LEVEL_ERROR, L"pInfo->aiHashAlg == %d", pInfo->aiHashAlg);
- __leave;
- }
- for(dwI = 0 ; dwI < dwSignatureAlgorithmCount ; dwI++)
- {
- if (SignatureAlgorithm[dwI].aiHashAlg == pInfo->aiHashAlg)
+ if (!(pInfo->aiHashAlg & ALG_CLASS_HASH))
{
- // found
- break;
+ dwReturn = SCARD_E_INVALID_PARAMETER;
+ Trace(WINEVENT_LEVEL_ERROR, L"pInfo->aiHashAlg == %d", pInfo->aiHashAlg);
+ __leave;
}
+ for(dwI = 0 ; dwI < dwSignatureAlgorithmCount ; dwI++)
+ {
+ if (SignatureAlgorithm[dwI].aiHashAlg == pInfo->aiHashAlg)
+ {
+ // found
+ break;
+ }
+ }
+ if (dwI >= dwSignatureAlgorithmCount)
+ {
+ Trace(WINEVENT_LEVEL_ERROR, L"alg not found %d", pInfo->aiHashAlg);
+ dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
+ __leave;
+ }
}
- 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)
+ *pdwIndex = dwI;
+ dwReturn = 0;
+ }
+ __finally
+ {
+ }
+ return dwReturn;
+}
+
+DWORD OCardSign(PCARD_DATA pCardData,
+ PCARD_SIGNING_INFO pInfo)
+{
+ DWORD dwReturn;
+ PBYTE pbData = NULL;
+ DWORD dwCmdSize = 0, dwIndex, dwI;
+ POPENPGP_CONTEXT pContext;
+ OPENPGP_ALGORITHM_ATTRIBUTE Attributes;
+ BYTE pbCmd[6 + 256 + 256] = {0x00,
+ 0x2A,
+ 0x9E,
+ 0x9A,
+ 0x00,
+ 0x00,
+ };
+ __try
+ {
+ Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",pInfo->bContainerIndex);
+ dwReturn = OCardCheckSigningInfo(pInfo, &dwIndex);
+ if (dwReturn)
{
+ __leave;
+ }
+ if (pInfo->bContainerIndex != ContainerSignature)
+ {
dwReturn = SCARD_E_NO_KEY_CONTAINER;
Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", pInfo->bContainerIndex);
__leave;
@@ -946,7 +967,7 @@
{
// optimisation :
// return the buffer size only
- dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, Signature, &Attributes);
+ dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, KeySignature, &Attributes);
if (dwReturn)
{
__leave;
@@ -963,9 +984,9 @@
{
dwCmdSize++;
}
- pbCmd[dwCmdSize++] = (BYTE) (SignatureAlgorithm[dwI].dwEncodedOidSize + pInfo->cbData);
- memcpy(pbCmd + dwCmdSize , SignatureAlgorithm[dwI].pbEncodedOid,SignatureAlgorithm[dwI].dwEncodedOidSize);
- dwCmdSize += SignatureAlgorithm[dwI].dwEncodedOidSize;
+ pbCmd[dwCmdSize++] = (BYTE) (SignatureAlgorithm[dwIndex].dwEncodedOidSize + pInfo->cbData);
+ memcpy(pbCmd + dwCmdSize , SignatureAlgorithm[dwIndex].pbEncodedOid,SignatureAlgorithm[dwIndex].dwEncodedOidSize);
+ dwCmdSize += SignatureAlgorithm[dwIndex].dwEncodedOidSize;
/*for(dwI = 0 ; dwI < pInfo->cbData ; dwI++)
{
pbCmd[dwCmdSize + dwI] = pInfo->pbData[pInfo->cbData - dwI -1];
@@ -1018,7 +1039,7 @@
{
DWORD dwReturn;
PBYTE pbData = NULL;
- DWORD dwCmdSize = 0, dwI;
+ DWORD dwCmdSize = 0, dwIndex, dwI;
POPENPGP_CONTEXT pContext;
OPENPGP_ALGORITHM_ATTRIBUTE Attributes;
BYTE pbCmd[6 + 256 + 256] = {0x00,
@@ -1031,53 +1052,13 @@
__try
{
Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",pInfo->bContainerIndex);
- if (pInfo->dwSigningFlags & ~(CARD_PADDING_INFO_PRESENT | CARD_BUFFER_SIZE_ONLY | CRYPT_NOHASHOID | CRYPT_TYPE2_FORMAT))
+ dwReturn = OCardCheckSigningInfo(pInfo, &dwIndex);
+ if (dwReturn)
{
- Trace(WINEVENT_LEVEL_ERROR, L"wrong flag %d", pInfo->dwSigningFlags);
- dwReturn = SCARD_E_INVALID_PARAMETER;
__leave;
}
- if (pInfo->dwSigningFlags & CARD_PADDING_INFO_PRESENT)
+ if (pInfo->bContainerIndex != ContainerAuthentication)
{
- 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;
- }
- }
- for(dwI = 0 ; dwI < dwSignatureAlgorithmCount ; dwI++)
- {
- if (SignatureAlgorithm[dwI].aiHashAlg == pInfo->aiHashAlg)
- {
- // found
- break;
- }
- }
- if (dwI >= dwSignatureAlgorithmCount)
- {
- Trace(WINEVENT_LEVEL_ERROR, L"alg not found %d", pInfo->aiHashAlg);
- __leave;
- }
- if (SignatureAlgorithm[dwI].dwHashSize != pInfo->cbData)
- {
- 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;
@@ -1086,7 +1067,7 @@
{
// optimisation :
// return the buffer size only
- dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, Signature, &Attributes);
+ dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, KeyAuthentication, &Attributes);
if (dwReturn)
{
__leave;
@@ -1103,9 +1084,9 @@
{
dwCmdSize++;
}
- pbCmd[dwCmdSize++] = (BYTE) (SignatureAlgorithm[dwI].dwEncodedOidSize + pInfo->cbData);
- memcpy(pbCmd + dwCmdSize , SignatureAlgorithm[dwI].pbEncodedOid,SignatureAlgorithm[dwI].dwEncodedOidSize);
- dwCmdSize += SignatureAlgorithm[dwI].dwEncodedOidSize;
+ pbCmd[dwCmdSize++] = (BYTE) (SignatureAlgorithm[dwIndex].dwEncodedOidSize + pInfo->cbData);
+ memcpy(pbCmd + dwCmdSize , SignatureAlgorithm[dwIndex].pbEncodedOid,SignatureAlgorithm[dwIndex].dwEncodedOidSize);
+ dwCmdSize += SignatureAlgorithm[dwIndex].dwEncodedOidSize;
/*for(dwI = 0 ; dwI < pInfo->cbData ; dwI++)
{
pbCmd[dwCmdSize + dwI] = pInfo->pbData[pInfo->cbData - dwI -1];
@@ -1171,20 +1152,20 @@
__try
{
Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",pInfo->bContainerIndex);
- if (pInfo->bContainerIndex >= MaxContainer)
+ if (pInfo->bContainerIndex >= ContainerMax)
{
dwReturn = SCARD_E_NO_KEY_CONTAINER;
Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", pInfo->bContainerIndex);
__leave;
}
- if (pInfo->bContainerIndex != Confidentiality)
+ if (pInfo->bContainerIndex != ContainerConfidentiality)
{
dwReturn = SCARD_E_NO_KEY_CONTAINER;
Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", pInfo->bContainerIndex);
__leave;
}
// check the buffer size
- dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, Confidentiality, &Attributes);
+ dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, KeyConfidentiality, &Attributes);
if (dwReturn)
{
__leave;
@@ -1274,7 +1255,7 @@
{
PCONTAINER_MAP_RECORD pContainer = NULL;
BOOL fIsDefaultContainerSet = FALSE;
- *pdwResponseSize = sizeof(CONTAINER_MAP_RECORD) * MaxContainer;
+ *pdwResponseSize = sizeof(CONTAINER_MAP_RECORD) * ContainerMax;
*ppbResponse = pCardData->pfnCspAlloc(*pdwResponseSize);
if (! *ppbResponse )
{
@@ -1283,66 +1264,66 @@
__leave;
}
pContainer = (PCONTAINER_MAP_RECORD) *ppbResponse;
- memset(pContainer,0,sizeof(CONTAINER_MAP_RECORD) * 3);
+ memset(pContainer,0,sizeof(CONTAINER_MAP_RECORD) * ContainerMax);
- dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, Authentication, &Attributes);
+ dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, KeyAuthentication, &Attributes);
if (dwReturn)
{
__leave;
}
- pContainer[Authentication].wSigKeySizeBits = Attributes.wModulusLengthInBit;
- swprintf_s(pContainer[Authentication].wszGuid,MAX_CONTAINER_NAME_LEN + 1,
+ pContainer[ContainerAuthentication].wSigKeySizeBits = Attributes.wModulusLengthInBit;
+ swprintf_s(pContainer[ContainerAuthentication].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)
+ if (pContext->fHasKey[KeyAuthentication])
{
- pContainer[Authentication].bFlags = CONTAINER_MAP_VALID_CONTAINER | CONTAINER_MAP_DEFAULT_CONTAINER;
+ pContainer[ContainerAuthentication].bFlags = CONTAINER_MAP_VALID_CONTAINER | CONTAINER_MAP_DEFAULT_CONTAINER;
fIsDefaultContainerSet = TRUE;
}
- dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, Signature, &Attributes);
+
+ dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, KeyConfidentiality, &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",
+ pContainer[ContainerConfidentiality].wKeyExchangeKeySizeBits = Attributes.wModulusLengthInBit;
+ swprintf_s(pContainer[ContainerConfidentiality].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->fHasSignature)
+ if (pContext->fHasKey[KeyConfidentiality])
{
- pContainer[Signature].bFlags = CONTAINER_MAP_VALID_CONTAINER;
+ pContainer[ContainerConfidentiality].bFlags = CONTAINER_MAP_VALID_CONTAINER;
if (!fIsDefaultContainerSet)
{
- pContainer[Signature].bFlags |= CONTAINER_MAP_DEFAULT_CONTAINER;
+ pContainer[ContainerConfidentiality].bFlags |= CONTAINER_MAP_DEFAULT_CONTAINER;
fIsDefaultContainerSet = TRUE;
}
}
-
- dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, Confidentiality, &Attributes);
+
+ dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, KeySignature, &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",
+ pContainer[ContainerSignature].wSigKeySizeBits = Attributes.wModulusLengthInBit;
+ swprintf_s(pContainer[ContainerSignature].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->fHasDecryption)
+ if (pContext->fHasKey[KeySignature])
{
- pContainer[Confidentiality].bFlags = CONTAINER_MAP_VALID_CONTAINER;
+ pContainer[ContainerSignature].bFlags = CONTAINER_MAP_VALID_CONTAINER;
if (!fIsDefaultContainerSet)
{
- pContainer[Confidentiality].bFlags |= CONTAINER_MAP_DEFAULT_CONTAINER;
+ pContainer[ContainerSignature].bFlags |= CONTAINER_MAP_DEFAULT_CONTAINER;
fIsDefaultContainerSet = TRUE;
}
}
Modified: trunk/OpenPGPminidriver/CryptoOperations.h
===================================================================
--- trunk/OpenPGPminidriver/CryptoOperations.h 2010-03-11 20:32:26 UTC (rev 8)
+++ trunk/OpenPGPminidriver/CryptoOperations.h 2010-03-15 09:47:30 UTC (rev 9)
@@ -17,20 +17,34 @@
typedef enum _OPENPGP_CONTAINER
{
- Signature,
- Authentication,
- Confidentiality,
- MaxContainer
+ ContainerSignature,
+ ContainerAuthentication,
+ ContainerConfidentiality,
+ ContainerMax
} OPENPGP_CONTAINER;
-typedef struct _OPENPGP_CONTAINER_INFO
+typedef enum _OPENPGP_KEY
{
+ KeySignature,
+ KeyAuthentication,
+ KeyConfidentiality,
+ KeyMax
+} OPENPGP_KEY;
+
+typedef struct _OPENPGP_KEY_INFO
+{
BYTE bKeyTag;
BYTE bDateTimeTag;
BYTE bSignatureTag;
ALG_ID aiKeyAlg;
- DWORD dwKeySpec;
+} OPENPGP_KEY_INFO, *POPENPGP_KEY_INFO;
+
+extern OPENPGP_KEY_INFO Keys[];
+
+typedef struct _OPENPGP_CONTAINER_INFO
+{
PIN_ID PinId;
+ DWORD dwKeySpec;
} OPENPGP_CONTAINER_INFO, *POPENPGP_CONTAINER_INFO;
extern OPENPGP_CONTAINER_INFO Containers[];
@@ -49,13 +63,13 @@
#pragma pack(pop)
DWORD OCardReadPublicKey(PCARD_DATA pCardData,
- OPENPGP_CONTAINER dwContainer,
+ OPENPGP_KEY dwKey,
PBYTE *pbPublicKey, PDWORD pdwPublicKeySize);
-DWORD OCardCreateKey(PCARD_DATA pCardData, OPENPGP_CONTAINER dwContainer, DWORD dwBitLen);
+DWORD OCardCreateKey(PCARD_DATA pCardData, OPENPGP_KEY dwKey, DWORD dwBitLen);
DWORD OCardImportKey(PCARD_DATA pCardData,
- OPENPGP_CONTAINER dwContainer,
+ OPENPGP_KEY dwKey,
PBYTE pBlob,
DWORD dwKeySize);
@@ -68,3 +82,5 @@
DWORD OCardDecrypt(PCARD_DATA pCardData,
PCARD_RSA_DECRYPT_INFO pInfo);
+DWORD OCardReadContainerMapFile(__in PCARD_DATA pCardData,
+ __in PBYTE* ppbResponse, __in PDWORD pdwResponseSize);
\ No newline at end of file
Modified: trunk/OpenPGPminidriver/OpenPGPminidriver.vcproj
===================================================================
--- trunk/OpenPGPminidriver/OpenPGPminidriver.vcproj 2010-03-11 20:32:26 UTC (rev 8)
+++ trunk/OpenPGPminidriver/OpenPGPminidriver.vcproj 2010-03-15 09:47:30 UTC (rev 9)
@@ -415,7 +415,7 @@
Name="Resources Files"
>
<File
- RelativePath=".\driver.inf"
+ RelativePath=".\openpgpmdrv.inf"
>
</File>
<File
Modified: trunk/OpenPGPminidriver/PinOperations.c
===================================================================
--- trunk/OpenPGPminidriver/PinOperations.c 2010-03-11 20:32:26 UTC (rev 8)
+++ trunk/OpenPGPminidriver/PinOperations.c 2010-03-15 09:47:30 UTC (rev 9)
@@ -332,34 +332,27 @@
DWORD Deauthenticate(__in PCARD_DATA pCardData)
{
- DWORD dwAP;
+ /*DWORD dwCode, dwSize;
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_RESET_CARD,
- &dwAP );
- if (dwReturn)
+ dwCode = SCARD_COLD_RESET;
+ dwReturn = SCardControl(pCardData->hScard, IOCTL_SMARTCARD_POWER,&dwCode,4,NULL,0,&dwSize);
+ if (dwReturn && dwReturn != SCARD_W_RESET_CARD)
{
- Trace(WINEVENT_LEVEL_ERROR, L"SCardReconnect 0x%08X", dwReturn);
+ Trace(WINEVENT_LEVEL_ERROR, L"SCardControl 0x%08X", dwReturn);
__leave;
}
- dwReturn = SCardBeginTransaction(pCardData->hScard);
- if (dwReturn)
- {
- Trace(WINEVENT_LEVEL_ERROR, L"SCardBeginTransaction 0x%08X", dwReturn);
- __leave;
- }
+ Sleep(200);
dwReturn = SelectOpenPGPApplication(pCardData);
}
__finally
{
}
- return dwReturn;
+ return dwReturn;*/
+ return SCARD_E_UNSUPPORTED_FEATURE;
}
Modified: trunk/OpenPGPminidriver/PublicDataOperations.c
===================================================================
--- trunk/OpenPGPminidriver/PublicDataOperations.c 2010-03-11 20:32:26 UTC (rev 8)
+++ trunk/OpenPGPminidriver/PublicDataOperations.c 2010-03-15 09:47:30 UTC (rev 9)
@@ -31,6 +31,10 @@
Virtual,
} OPENPGP_FILE_TYPE;
+#define OPENPGP_FILE_OPTIONAL 1
+#define OPENPGP_FILE_WRITE_ONLY 2
+#define OPENPGP_FILE_NULL_LENGHT_EQUALS_MISSING 4
+
typedef struct _OPENPGP_FILE
{
PCHAR szDirectory;
@@ -39,6 +43,7 @@
DWORD dwTag;
DWORD dwTlv;
CARD_FILE_ACCESS_CONDITION dwAccess;
+ DWORD dwFlag;
} OPENPGP_FILE, *POPENPGP_FILE;
@@ -55,17 +60,17 @@
{szOpenPGPDir, szOpenPGPSex, StoredOnSmartCard, 0x65, 0x5F35,EveryoneReadAdminWriteAc},
{szOpenPGPDir, szOpenPGPUrl, StoredOnSmartCard, 0x5F50, 0, EveryoneReadAdminWriteAc},
{szOpenPGPDir, szOpenPGPHistoricalBytes, StoredOnSmartCard, 0x5F52, 0, UnknownAc},
- {szOpenPGPDir, szOpenPGPCertificate, StoredOnSmartCard, 0x7F21, 0, EveryoneReadAdminWriteAc},
+ {szOpenPGPDir, szOpenPGPCertificate, StoredOnSmartCard, 0x7F21, 0, EveryoneReadAdminWriteAc, OPENPGP_FILE_NULL_LENGHT_EQUALS_MISSING},
{szOpenPGPDir, szOpenPGPExtendedCap, StoredOnSmartCard, 0x6E, 0xC0, UnknownAc},
{szOpenPGPDir, szOpenPGPAlgoAttributesSignature, StoredOnSmartCard, 0x6E, 0xC1, UnknownAc},
{szOpenPGPDir, szOpenPGPAlgoAttributesDecryption, StoredOnSmartCard, 0x6E, 0xC2,UnknownAc},
{szOpenPGPDir, szOpenPGPAlgoAttributesAuthentication, StoredOnSmartCard, 0x6E, 0xC3, UnknownAc },
- {szOpenPGPDir, szOpenPGPPUK, StoredOnSmartCard, 0xD3, 0, UnknownAc },
+ {szOpenPGPDir, szOpenPGPPUK, StoredOnSmartCard, 0xD3, 0, UnknownAc, OPENPGP_FILE_WRITE_ONLY },
{NULL, szCARD_IDENTIFIER_FILE, StoredOnSmartCard, 0x4F, 0, EveryoneReadAdminWriteAc},
{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},
+ {szBASE_CSP_DIR, "ksc1", StoredOnSmartCard, 0x7F21, 0, EveryoneReadAdminWriteAc, OPENPGP_FILE_NULL_LENGHT_EQUALS_MISSING},
};
@@ -232,14 +237,17 @@
__in_opt PSTR szDirectory,
__in PBYTE* pbResponse, __in PDWORD pdwResponseSize)
{
- DWORD dwReturn = 0, dwNotExists;
+ DWORD dwReturn = 0, dwReadFileReturn;
DWORD dwI, dwSize;
BOOL fDirectoryFound = FALSE;
-
+ BOOL fAddToOuput;
__try
{
*pbResponse = NULL;
*pdwResponseSize = 0;
+
+ // compute the max size of the buffer
+ dwSize = 0;
for(dwI = 0; dwI < dwFileCount; dwI++)
{
BOOL fMatch = FALSE;
@@ -251,38 +259,56 @@
{
if (Files[dwI].szDirectory && _stricmp(szDirectory, Files[dwI].szDirectory) == 0) fMatch = TRUE;
}
+ if (fMatch && !(Files[dwI].dwFileType & OPENPGP_FILE_WRITE_ONLY))
+ {
+ dwSize += (DWORD) strlen( Files[dwI].szFile) + 1;
+ }
+ }
+ dwSize += 1;
+ *pbResponse = pCardData->pfnCspAlloc(dwSize);
+ if (!*pbResponse)
+ {
+ dwReturn = SCARD_E_NO_MEMORY;
+ __leave;
+ }
+ for(dwI = 0; dwI < dwFileCount; dwI++)
+ {
+ BOOL fMatch = FALSE;
+ if (szDirectory == NULL)
+ {
+ if (!Files[dwI].szDirectory) fMatch = TRUE;
+ }
+ else
+ {
+ if (Files[dwI].szDirectory && _stricmp(szDirectory, Files[dwI].szDirectory) == 0) fMatch = TRUE;
+ }
if (fMatch)
{
fDirectoryFound = TRUE;
- dwNotExists = 0;
- if (StoredOnSmartCard == Files[dwI].dwFileType)
+ fAddToOuput = TRUE;
+ if (Files[dwI].dwFlag & OPENPGP_FILE_WRITE_ONLY)
{
+ fAddToOuput = FALSE;
+ }
+ if (fAddToOuput && (Files[dwI].dwFlag & OPENPGP_FILE_NULL_LENGHT_EQUALS_MISSING))
+ {
PBYTE pbData = NULL;
DWORD dwSize;
+ fAddToOuput = FALSE;
// check if the file exists and be read
- dwNotExists = OCardReadFile(pCardData, szDirectory, Files[dwI].szFile, &pbData, &dwSize);
- if (!dwNotExists)
+ dwReadFileReturn = OCardReadFile(pCardData, szDirectory, Files[dwI].szFile, &pbData, &dwSize);
+ if (!dwReadFileReturn)
{
pCardData->pfnCspFree(pbData);
+ if (dwSize > 0)
+ {
+ fAddToOuput = TRUE;
+ }
}
}
- if (!dwNotExists)
+ if (fAddToOuput)
{
dwSize = (DWORD) strlen( Files[dwI].szFile) + 1;
- // + 1 to add the final \0
- if (*pbResponse)
- {
- *pbResponse = pCardData->pfnCspReAlloc(*pbResponse, *pdwResponseSize + dwSize + 1);
- }
- else
- {
- *pbResponse = pCardData->pfnCspAlloc(*pdwResponseSize + dwSize + 1);
- }
- if (!*pbResponse)
- {
- dwReturn = SCARD_E_NO_MEMORY;
- __leave;
- }
memcpy(*pbResponse + *pdwResponseSize, Files[dwI].szFile, dwSize);
*pdwResponseSize += dwSize;
}
Modified: trunk/OpenPGPminidriver/SmartCard.c
===================================================================
--- trunk/OpenPGPminidriver/SmartCard.c 2010-03-11 20:32:26 UTC (rev 8)
+++ trunk/OpenPGPminidriver/SmartCard.c 2010-03-15 09:47:30 UTC (rev 9)
@@ -89,6 +89,25 @@
}
SW1 = recvbuf[recvlen-2];
SW2 = recvbuf[recvlen-1];
+ if ( (SW1 == 0x6A) && (SW2 == 0x88) )
+ {
+ Trace(WINEVENT_LEVEL_ERROR, L"card reset");
+ recvlen = sizeof(recvbuf);
+ dwReturn = SelectOpenPGPApplication(pCardData);
+ if (dwReturn)
+ {
+ __leave;
+ }
+ dwReturn = SCardTransmit(pCardData->hScard,
+ SCARD_PCI_T1,
+ pbCmd,
+ dwCmdSize,
+ NULL,
+ recvbuf,
+ &recvlen);
+ SW1 = recvbuf[recvlen-2];
+ SW2 = recvbuf[recvlen-1];
+ }
if ( ( SW1 == 0x90 ) && ( SW2 == 0x00 ) )
{
@@ -182,6 +201,25 @@
}
SW1 = recvbuf[recvlen-2];
SW2 = recvbuf[recvlen-1];
+ if ( (SW1 == 0x6A) && (SW2 == 0x88) )
+ {
+ Trace(WINEVENT_LEVEL_ERROR, L"card reset");
+ recvlen = sizeof(recvbuf);
+ dwReturn = SelectOpenPGPApplication(pCardData);
+ if (dwReturn)
+ {
+ __leave;
+ }
+ dwReturn = SCardTransmit(pCardData->hScard,
+ SCARD_PCI_T1,
+ pbCmd,
+ dwCmdSize,
+ NULL,
+ recvbuf,
+ &recvlen);
+ SW1 = recvbuf[recvlen-2];
+ SW2 = recvbuf[recvlen-1];
+ }
if ( ( SW1 == 0x90 ) && ( SW2 == 0x00 ) )
{
dwDataSize = recvlen-2;
@@ -226,12 +264,6 @@
dwReturn = SCARD_W_CHV_BLOCKED;
__leave;
}
- else if ( (SW1 == 0x6A) && (SW2 == 0x88) )
- {
- Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_FILE_NOT_FOUND");
- dwReturn = SCARD_E_FILE_NOT_FOUND;
- __leave;
- }
else
{
TraceDump(WINEVENT_LEVEL_ERROR, pbCmd,dwCmdSize);
Modified: trunk/OpenPGPminidriver/openpgpmdrv.inf
===================================================================
--- trunk/OpenPGPminidriver/openpgpmdrv.inf 2010-03-11 20:32:26 UTC (rev 8)
+++ trunk/OpenPGPminidriver/openpgpmdrv.inf 2010-03-15 09:47:30 UTC (rev 9)
@@ -32,6 +32,20 @@
[SourceDisksNames]
1 = %MediaDescription%
+[DefaultInstall.NTamd64]
+CopyFiles=amd64_CopyFiles
+CopyFiles=wow64_CopyFiles
+AddReg=AddRegWOW64
+AddReg=AddReg64
+
+[DefaultInstall.NTamd64.6.1]
+CopyFiles=amd64_CopyFiles
+CopyFiles=wow64_CopyFiles
+AddReg=AddRegWOW64
+AddReg=AddReg64
+Include=umpass.inf
+Needs=UmPass
+
[OpenPGP64_Install.NT]
CopyFiles=amd64_CopyFiles
CopyFiles=wow64_CopyFiles
@@ -46,6 +60,16 @@
Include=umpass.inf
Needs=UmPass
+[DefaultInstall.NTx86]
+CopyFiles=x86_CopyFiles
+AddReg=AddReg32
+
+[DefaultInstall.NTx86.6.1]
+CopyFiles=x86_CopyFiles
+AddReg=AddReg32
+Include=umpass.inf
+Needs=UmPass
+
[OpenPGP32_Install.NT]
CopyFiles=x86_CopyFiles
AddReg=AddReg32
More information about the Openpgpmdrv-commits
mailing list