[Openpgpmdrv-commits] r6 - trunk/OpenPGPminidriver
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Mar 4 22:17:53 CET 2010
Author: vletoux
Date: 2010-03-04 22:17:51 +0100 (Thu, 04 Mar 2010)
New Revision: 6
Added:
trunk/OpenPGPminidriver/tlv.c
trunk/OpenPGPminidriver/tlv.h
Modified:
trunk/OpenPGPminidriver/Context.h
trunk/OpenPGPminidriver/ContextManagement.c
trunk/OpenPGPminidriver/CryptoOperations.c
trunk/OpenPGPminidriver/OpenPGPminidriver.vcproj
trunk/OpenPGPminidriver/PinOperations.c
trunk/OpenPGPminidriver/PublicDataOperations.c
trunk/OpenPGPminidriver/PublicDataOperations.h
trunk/OpenPGPminidriver/SmartCard.c
Log:
Everything is working except the certificate
Modified: trunk/OpenPGPminidriver/Context.h
===================================================================
--- trunk/OpenPGPminidriver/Context.h 2010-03-02 18:54:34 UTC (rev 5)
+++ trunk/OpenPGPminidriver/Context.h 2010-03-04 21:17:51 UTC (rev 6)
@@ -56,7 +56,11 @@
FEATURES SmartCardReaderFeatures;
BOOL fSupportCommandChaining;
BOOL fExtentedLeLcFields;
- DWORD dwMaxLength;
+ BYTE bSecureMessagingAlgorithm;
+ DWORD dwMaxChallengeLength;
+ DWORD dwMaxCertificateLength;
+ DWORD dwMaxCommandDataLength;
+ DWORD dwMaxResponseLength;
BOOL fHasSignature;
BOOL fHasDecryption;
BOOL fHasAuthentication;
Modified: trunk/OpenPGPminidriver/ContextManagement.c
===================================================================
--- trunk/OpenPGPminidriver/ContextManagement.c 2010-03-02 18:54:34 UTC (rev 5)
+++ trunk/OpenPGPminidriver/ContextManagement.c 2010-03-04 21:17:51 UTC (rev 6)
@@ -81,7 +81,8 @@
PBYTE pbApplicationIdentifier = NULL;
DWORD dwCapabilitiesSize,
dwCardCapabilitiesSize,
- dwApplicationIdentifierSize;
+ dwApplicationIdentifierSize,
+ dwExtendedCapabilitiesSize;
BYTE bCategoryIndicator, bStatusIndicator;
__try
{
@@ -152,14 +153,18 @@
dwReturn = SCARD_E_UNEXPECTED;
__leave;
}
- //dwReturn = SCardReadFile(pCardData, szOpenPGPDir, szOpenPGPExtendedCap, &pbExtendedCapabilities, &dwExtendedCapabilitiesSize);
+ dwReturn = SCardReadFile(pCardData, szOpenPGPDir, szOpenPGPExtendedCap, &pbExtendedCapabilities, &dwExtendedCapabilitiesSize);
if (dwReturn)
{
- //__leave;
+ __leave;
}
pContext->fExtentedLeLcFields = ((pbCardCapabilities[2] & 0x40)?TRUE:FALSE);
pContext->fSupportCommandChaining = ((pbCardCapabilities[2] & 0x80)?TRUE:FALSE);
- pContext->dwMaxLength = 0x0800;// pbCapabilities[8] * 256 + pbCapabilities[9];
+ pContext->bSecureMessagingAlgorithm = pbExtendedCapabilities[1];
+ pContext->dwMaxChallengeLength = pbExtendedCapabilities[2] * 0x100 + pbExtendedCapabilities[3];
+ pContext->dwMaxCertificateLength = pbExtendedCapabilities[4] * 0x100 + pbExtendedCapabilities[5];
+ pContext->dwMaxCommandDataLength = pbExtendedCapabilities[6] * 0x100 + pbExtendedCapabilities[7];
+ pContext->dwMaxResponseLength = pbExtendedCapabilities[8] * 0x100 + pbExtendedCapabilities[9];
dwReturn = CCIDgetFeatures(pCardData);
if (dwReturn)
{
Modified: trunk/OpenPGPminidriver/CryptoOperations.c
===================================================================
--- trunk/OpenPGPminidriver/CryptoOperations.c 2010-03-02 18:54:34 UTC (rev 5)
+++ trunk/OpenPGPminidriver/CryptoOperations.c 2010-03-04 21:17:51 UTC (rev 6)
@@ -23,6 +23,7 @@
#include "CryptoOperations.h"
#include "PinOperations.h"
#include "PublicDataOperations.h"
+#include "tlv.h"
OPENPGP_CONTAINER_INFO Containers[] =
{
@@ -84,57 +85,7 @@
BYTE modulus[sizeof(DWORD)];
} RSAPUBLICKEYBLOB, *PRSAPUBLICKEYBLOB;
-DWORD getTlvSize(__in PBYTE pbPointer, __in PDWORD pdwOffset)
-{
- DWORD dwSize;
- switch(*pbPointer)
- {
- case 0x81:
- *pdwOffset+=2;
- dwSize = pbPointer[1];
- break;
- case 0x82:
- *pdwOffset+=3;
- dwSize = pbPointer[1] * 0x100 + pbPointer[2];
- break;
- default:
- dwSize = *pbPointer;
- *pdwOffset+=1;
- break;
- }
- return dwSize;
-}
-BOOL find_tlv(__in PBYTE pbData, __in BYTE bCode, __out PBYTE *pbDataOut, __out_opt PDWORD pdwSize)
-{
- DWORD dwOffset = 2;
- DWORD dwSize;
- DWORD dwTotalSize = getTlvSize(pbData + 2,&dwOffset) + 2;
- while (dwOffset < dwTotalSize)
- {
- if (bCode == pbData[dwOffset])
- {
- dwOffset++;
- // size sequence
- dwSize = getTlvSize(pbData + dwOffset,&dwOffset);
- if (pdwSize)
- {
- *pdwSize = dwSize;
- }
- *pbDataOut = pbData + dwOffset;
- return TRUE;
- }
- else
- {
- dwOffset++;
- dwSize = getTlvSize(pbData + dwOffset,&dwOffset);
- dwOffset += dwSize;
- }
- }
- return FALSE;
-}
-
-
DWORD GetKeyAlgorithmAttributes(__in PCARD_DATA pCardData,
__in OPENPGP_CONTAINER dwContainer,
__out POPENPGP_ALGORITHM_ATTRIBUTE pAttributes)
@@ -596,6 +547,7 @@
DWORD dwModulusSize, dwI;
PBYTE pbExponent;
PRSAPUBLICKEYBLOB pbBlob = NULL;
+ DWORD dwTotalTlvSize, dwOffset;
__try
{
Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",dwContainer);
@@ -610,8 +562,8 @@
dwCmdSize = 9;
if (pContext->fExtentedLeLcFields)
{
- pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxLength / 0x100);
- pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxLength % 0x100);
+ pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxCommandDataLength / 0x100);
+ pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxCommandDataLength % 0x100);
}
else
{
@@ -623,13 +575,15 @@
{
__leave;
}
- if (!find_tlv(pbData,0x81,&pbModulus,&dwModulusSize))
+ dwOffset = 2;
+ dwTotalTlvSize = getTlvSize(pbData + 2,&dwOffset) + 2;
+ if (!find_tlv(pbData + dwOffset,0x81,dwTotalTlvSize,&pbModulus,&dwModulusSize))
{
dwReturn = SCARD_E_UNEXPECTED;
Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_UNEXPECTED 0x81");
__leave;
}
- if (!find_tlv(pbData,0x82,(PBYTE*)&pbExponent,NULL))
+ if (!find_tlv(pbData + dwOffset,0x82,dwTotalTlvSize, (PBYTE*)&pbExponent,NULL))
{
dwReturn = SCARD_E_UNEXPECTED;
Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_UNEXPECTED 0x81");
@@ -691,6 +645,7 @@
0x00,
0x00
};
+ DWORD dwTotalTlvSize, dwOffset;
__try
{
Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",dwContainer);
@@ -702,14 +657,8 @@
}
// key len
dwReturn = GetKeyAlgorithmAttributes(pCardData, dwContainer, &Attributes);
- if (dwReturn == SCARD_E_FILE_NOT_FOUND)
+ if (dwReturn)
{
- Attributes.bAlgoId = 0x01;
- Attributes.bFormat = 0;
- Attributes.wExponentLength = 0x20;
- }
- else if (dwReturn)
- {
__leave;
}
Attributes.wModulusLength = (WORD) dwBitLen;
@@ -724,8 +673,8 @@
dwCmdSize = 9;
if (pContext->fExtentedLeLcFields)
{
- pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxLength / 0x100);
- pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxLength % 0x100);
+ pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxCommandDataLength / 0x100);
+ pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxCommandDataLength % 0x100);
}
else
{
@@ -737,13 +686,15 @@
{
__leave;
}
- if (!find_tlv(pbData,0x81,&pbModulus,&dwModulusSize))
+ dwOffset = 2;
+ dwTotalTlvSize = getTlvSize(pbData + 2,&dwOffset) + 2;
+ if (!find_tlv(pbData + dwOffset,0x81,dwTotalTlvSize, &pbModulus,&dwModulusSize))
{
dwReturn = SCARD_E_UNEXPECTED;
Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_UNEXPECTED 0x81");
__leave;
}
- if (!find_tlv(pbData,0x82,(PBYTE*)&pbExponent,NULL))
+ if (!find_tlv(pbData + dwOffset,0x82,dwTotalTlvSize, (PBYTE*)&pbExponent,NULL))
{
dwReturn = SCARD_E_UNEXPECTED;
Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_UNEXPECTED 0x81");
@@ -811,14 +762,8 @@
}
dwReturn = GetKeyAlgorithmAttributes(pCardData, dwContainer, &Attributes);
- if (dwReturn == SCARD_E_FILE_NOT_FOUND)
+ if (dwReturn)
{
- Attributes.bAlgoId = 0x01;
- Attributes.bFormat = 0;
- Attributes.wExponentLength = 0x20;
- }
- else if (dwReturn)
- {
__leave;
}
Attributes.wModulusLength = (WORD) pbPublicKeyBlob->rsapubkey.bitlen;
@@ -968,8 +913,8 @@
if (pContext->fExtentedLeLcFields)
{
- pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxLength / 0x100);
- pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxLength % 0x100);
+ pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxCommandDataLength / 0x100);
+ pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxCommandDataLength % 0x100);
}
else
{
@@ -1078,8 +1023,8 @@
if (pContext->fExtentedLeLcFields)
{
- pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxLength / 0x100);
- pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxLength % 0x100);
+ pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxCommandDataLength / 0x100);
+ pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxCommandDataLength % 0x100);
}
else
{
@@ -1164,8 +1109,8 @@
dwCmdSize += pInfo->cbData;
if (pContext->fExtentedLeLcFields)
{
- pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxLength / 0x100);
- pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxLength % 0x100);
+ pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxCommandDataLength / 0x100);
+ pbCmd[dwCmdSize++] = (BYTE)(pContext->dwMaxCommandDataLength % 0x100);
}
else
{
Modified: trunk/OpenPGPminidriver/OpenPGPminidriver.vcproj
===================================================================
--- trunk/OpenPGPminidriver/OpenPGPminidriver.vcproj 2010-03-02 18:54:34 UTC (rev 5)
+++ trunk/OpenPGPminidriver/OpenPGPminidriver.vcproj 2010-03-04 21:17:51 UTC (rev 6)
@@ -391,6 +391,10 @@
>
</File>
<File
+ RelativePath=".\tlv.h"
+ >
+ </File>
+ <File
RelativePath=".\Tracing.h"
>
</File>
@@ -402,6 +406,10 @@
RelativePath=".\SmartCard.c"
>
</File>
+ <File
+ RelativePath=".\tlv.c"
+ >
+ </File>
</Filter>
<Filter
Name="Resources Files"
Modified: trunk/OpenPGPminidriver/PinOperations.c
===================================================================
--- trunk/OpenPGPminidriver/PinOperations.c 2010-03-02 18:54:34 UTC (rev 5)
+++ trunk/OpenPGPminidriver/PinOperations.c 2010-03-04 21:17:51 UTC (rev 6)
@@ -28,7 +28,7 @@
{
DWORD dwReturn;
PBYTE pbResponse = NULL;
- DWORD dwMinPinSize = 0, dwMaxPinSize;
+ DWORD dwMinPinSize = 0, dwMaxPinSize, dwSize;
__try
{
Trace(WINEVENT_LEVEL_VERBOSE, L"Enter PinId=%d",PinId);
@@ -56,7 +56,7 @@
__leave;
}
// check in status DO
- dwReturn = SCardReadFile(pCardData, szOpenPGPDir, szOpenPGPStatus, &pbResponse, NULL);
+ dwReturn = SCardReadFile(pCardData, szOpenPGPDir, szOpenPGPStatus, &pbResponse, &dwSize);
switch(PinId)
{
case ROLE_SIGNATURE:
@@ -92,12 +92,12 @@
DWORD GetRemainingPin(__in PCARD_DATA pCardData, __in PIN_ID PinId, __out PDWORD pdwCounter)
{
- DWORD dwReturn;
+ DWORD dwReturn, dwSize;
PBYTE pbResponse = NULL;
__try
{
Trace(WINEVENT_LEVEL_VERBOSE, L"Enter PinId=%d",PinId);
- dwReturn = SCardReadFile(pCardData, szOpenPGPDir, szOpenPGPStatus, &pbResponse, NULL);
+ dwReturn = SCardReadFile(pCardData, szOpenPGPDir, szOpenPGPStatus, &pbResponse, &dwSize);
switch(PinId)
{
case ROLE_SIGNATURE:
Modified: trunk/OpenPGPminidriver/PublicDataOperations.c
===================================================================
--- trunk/OpenPGPminidriver/PublicDataOperations.c 2010-03-02 18:54:34 UTC (rev 5)
+++ trunk/OpenPGPminidriver/PublicDataOperations.c 2010-03-04 21:17:51 UTC (rev 6)
@@ -23,6 +23,7 @@
#include "SmartCard.h"
#include "PublicDataOperations.h"
#include "CryptoOperations.h"
+#include "tlv.h"
typedef enum _OPENPGP_FILE_TYPE
{
@@ -35,8 +36,8 @@
PCHAR szDirectory;
PCHAR szFile;
OPENPGP_FILE_TYPE dwFileType;
- BYTE bP1;
- BYTE bP2;
+ DWORD dwTag;
+ DWORD dwTlv;
CARD_FILE_ACCESS_CONDITION dwAccess;
} OPENPGP_FILE, *POPENPGP_FILE;
@@ -45,24 +46,25 @@
OPENPGP_FILE Files[] =
{
- {szOpenPGPDir, szOpenPGPFingerprint, StoredOnSmartCard, 0x00, 0xC5, EveryoneReadAdminWriteAc},
- {szOpenPGPDir, szOpenPGPStatus, StoredOnSmartCard, 0x00, 0xC4, EveryoneReadAdminWriteAc},
- {szOpenPGPDir, szOpenPGPApplicationIdentifier, StoredOnSmartCard, 0x00, 0x4F, UnknownAc},
- {szOpenPGPDir, szOpenPGPLogin, StoredOnSmartCard, 0x00, 0x5E, EveryoneReadAdminWriteAc},
- {szOpenPGPDir, szOpenPGPName, StoredOnSmartCard, 0x00, 0x5B, EveryoneReadAdminWriteAc},
- {szOpenPGPDir, szOpenPGPLanguage, StoredOnSmartCard, 0x5F, 0x2D, EveryoneReadAdminWriteAc},
- {szOpenPGPDir, szOpenPGPSex, StoredOnSmartCard, 0x5F, 0x35, EveryoneReadAdminWriteAc},
- {szOpenPGPDir, szOpenPGPUrl, StoredOnSmartCard, 0x5F, 0x50, EveryoneReadAdminWriteAc},
- {szOpenPGPDir, szOpenPGPHistoricalBytes, StoredOnSmartCard, 0x5F, 0x52, UnknownAc},
- {szOpenPGPDir, szOpenPGPCertificate, StoredOnSmartCard, 0x7F, 0x21, EveryoneReadAdminWriteAc},
- {szOpenPGPDir, szOpenPGPExtendedCap, StoredOnSmartCard, 0x00, 0xC0, UnknownAc},
- {szOpenPGPDir, szOpenPGPAlgoAttributesSignature, StoredOnSmartCard, 0x00, 0xC1, UnknownAc},
- {szOpenPGPDir, szOpenPGPAlgoAttributesDecryption, StoredOnSmartCard, 0x00, 0xC2, UnknownAc},
- {szOpenPGPDir, szOpenPGPAlgoAttributesAuthentication, StoredOnSmartCard, 0x00, 0xC3, UnknownAc },
- {NULL, szCARD_IDENTIFIER_FILE, StoredOnSmartCard, 0x00, 0x4F, EveryoneReadAdminWriteAc},
+ {szOpenPGPDir, szOpenPGPFingerprint, StoredOnSmartCard, 0x6E, 0xC5, EveryoneReadAdminWriteAc},
+ {szOpenPGPDir, szOpenPGPStatus, StoredOnSmartCard, 0xC4, 0, EveryoneReadAdminWriteAc},
+ {szOpenPGPDir, szOpenPGPApplicationIdentifier, StoredOnSmartCard, 0x4F, 0, UnknownAc},
+ {szOpenPGPDir, szOpenPGPLogin, StoredOnSmartCard, 0x5E, 0, EveryoneReadAdminWriteAc},
+ {szOpenPGPDir, szOpenPGPName, StoredOnSmartCard, 0x65, 0x5B, EveryoneReadAdminWriteAc},
+ {szOpenPGPDir, szOpenPGPLanguage, StoredOnSmartCard, 0x65, 0x5F2D, EveryoneReadAdminWriteAc},
+ {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, szOpenPGPExtendedCap, StoredOnSmartCard, 0x6E, 0xC0, UnknownAc},
+ {szOpenPGPDir, szOpenPGPAlgoAttributesSignature, StoredOnSmartCard, 0x6E, 0xC1, UnknownAc},
+ {szOpenPGPDir, szOpenPGPAlgoAttributesDecryption, StoredOnSmartCard, 0x6E, 0xC2,UnknownAc},
+ {szOpenPGPDir, szOpenPGPAlgoAttributesAuthentication, StoredOnSmartCard, 0x6E, 0xC3, UnknownAc },
+ {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},
};
@@ -85,7 +87,7 @@
// read file
DWORD SCardReadFile(__in PCARD_DATA pCardData,
__in_opt PSTR szDirectory, __in PSTR szFile,
- __in PBYTE* pbResponse, __in_opt PDWORD pdwResponseSize)
+ __in PBYTE* ppbResponse, __in PDWORD pdwResponseSize)
{
DWORD dwI;
DWORD dwReturn = 0;
@@ -94,8 +96,10 @@
BYTE pbCmd[] = {0x00, 0xCA, 0x00, 0x00, 0x00};
DWORD dwCmdSize = ARRAYSIZE(pbCmd);
POPENPGP_CONTEXT pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
+ PBYTE pbData = NULL;
__try
{
+ *pdwResponseSize = 0;
for(dwI = 0; dwI < dwFileCount; dwI++)
{
BOOL fMatch = FALSE;
@@ -133,9 +137,39 @@
}
if (Files[dwI].dwFileType == StoredOnSmartCard)
{
- pbCmd[2] = Files[dwI].bP1;
- pbCmd[3] = Files[dwI].bP2;
- dwReturn = SCardGetData(pCardData, pbCmd, dwCmdSize, pbResponse, pdwResponseSize);
+ pbCmd[2] = (BYTE) (Files[dwI].dwTag / 0x100);
+ pbCmd[3] = (BYTE) (Files[dwI].dwTag % 0x100);
+ dwReturn = SCardGetData(pCardData, pbCmd, dwCmdSize, &pbData, pdwResponseSize);
+ if (dwReturn)
+ {
+ __leave;
+ }
+ if (Files[dwI].dwTlv)
+ {
+ PBYTE pbPointer;
+ //TraceDump(0,pbData,*pdwResponseSize);
+ if (find_tlv(pbData, Files[dwI].dwTlv, *pdwResponseSize, &pbPointer, pdwResponseSize))
+ {
+ *ppbResponse = pCardData->pfnCspAlloc(*pdwResponseSize);
+ if (!*ppbResponse )
+ {
+ Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_MEMORY");
+ dwReturn = SCARD_E_NO_MEMORY;
+ }
+ memcpy(*ppbResponse, pbPointer, *pdwResponseSize);
+ }
+ else
+ {
+ dwReturn = SCARD_E_FILE_NOT_FOUND;
+ Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_FILE_NOT_FOUND %S",szFile);
+ }
+ }
+ else
+ {
+ *ppbResponse = pbData;
+ // do not free the data !
+ pbData = NULL;
+ }
}
else
{
@@ -143,13 +177,13 @@
{
if (strcmp(szFile, szCARD_APPLICATION_FILE) == 0)
{
- dwReturn = SCardDirectoryList(pCardData, pbResponse, pdwResponseSize);
+ dwReturn = SCardDirectoryList(pCardData, ppbResponse, pdwResponseSize);
}
else if (strcmp(szFile, szCACHE_FILE) == 0)
{
*pdwResponseSize = sizeof(CARD_CACHE_FILE_FORMAT);
- *pbResponse = pCardData->pfnCspAlloc(*pdwResponseSize);
- memset(*pbResponse,0,*pdwResponseSize);
+ *ppbResponse = pCardData->pfnCspAlloc(*pdwResponseSize);
+ memset(*ppbResponse,0,*pdwResponseSize);
}
else
{
@@ -163,14 +197,14 @@
{
PCONTAINER_MAP_RECORD pContainer = NULL;
*pdwResponseSize = sizeof(CONTAINER_MAP_RECORD) * MaxContainer;
- *pbResponse = pCardData->pfnCspAlloc(*pdwResponseSize);
- if (! *pbResponse )
+ *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) *pbResponse;
+ 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",
@@ -219,8 +253,10 @@
}
__finally
{
+ if( pbData)
+ pCardData->pfnCspFree(pbData);
}
- Trace(WINEVENT_LEVEL_VERBOSE, L"%S\\%S dwReturn = 0x%08X",szDirectory, szFile, dwReturn);
+ Trace(WINEVENT_LEVEL_VERBOSE, L"%S\\%S dwReturn = 0x%08X size = %d",szDirectory, szFile, dwReturn, *pdwResponseSize);
return dwReturn;
}
@@ -396,14 +432,16 @@
}
if (Files[dwI].dwFileType == StoredOnSmartCard)
{
- // fail because the PUT DO doesn't work => too much data
- if (Files[dwI].bP1 != 0)
+ if (Files[dwI].dwTlv > 0)
{
- dwReturn = SCARD_E_WRITE_TOO_MANY ;
- Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_WRITE_TOO_MANY %S",szFile);
- __leave;
+ pbCmd[2] = (BYTE) (Files[dwI].dwTlv / 0x100);
+ pbCmd[3] = (BYTE) (Files[dwI].dwTlv % 0x100);
}
- pbCmd[3] = Files[dwI].bP2;
+ else
+ {
+ pbCmd[2] = (BYTE) (Files[dwI].dwTag / 0x100);
+ pbCmd[3] = (BYTE) (Files[dwI].dwTag % 0x100);
+ }
pbCmd[4] = (BYTE) dwSize;
if (dwSize)
{
Modified: trunk/OpenPGPminidriver/PublicDataOperations.h
===================================================================
--- trunk/OpenPGPminidriver/PublicDataOperations.h 2010-03-02 18:54:34 UTC (rev 5)
+++ trunk/OpenPGPminidriver/PublicDataOperations.h 2010-03-04 21:17:51 UTC (rev 6)
@@ -35,7 +35,7 @@
DWORD SCardReadFile(__in PCARD_DATA pCardData,
__in_opt PSTR szDirectory, __in PSTR file,
- __in PBYTE* pbResponse, __in_opt PDWORD pdwResponseSize);
+ __in PBYTE* pbResponse, __in PDWORD pdwResponseSize);
DWORD SCardEnumFile(__in PCARD_DATA pCardData,
__in_opt PSTR szDirectory,
Modified: trunk/OpenPGPminidriver/SmartCard.c
===================================================================
--- trunk/OpenPGPminidriver/SmartCard.c 2010-03-02 18:54:34 UTC (rev 5)
+++ trunk/OpenPGPminidriver/SmartCard.c 2010-03-04 21:17:51 UTC (rev 6)
@@ -138,6 +138,12 @@
{
dwDataSize = recvlen-2;
*pbResponse = pCardData->pfnCspAlloc(dwDataSize);
+ if (! *pbResponse)
+ {
+ Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_MEMORY");
+ dwReturn = SCARD_E_NO_MEMORY;
+ __leave;
+ }
memcpy(*pbResponse, recvbuf, dwDataSize);
}
else if (SW1 == 0x61)
Added: trunk/OpenPGPminidriver/tlv.c
===================================================================
--- trunk/OpenPGPminidriver/tlv.c 2010-03-02 18:54:34 UTC (rev 5)
+++ trunk/OpenPGPminidriver/tlv.c 2010-03-04 21:17:51 UTC (rev 6)
@@ -0,0 +1,65 @@
+#include <windows.h>
+
+DWORD getTlvSize(__in PBYTE pbPointer, __in PDWORD pdwOffset)
+{
+ DWORD dwSize;
+ switch(*pbPointer)
+ {
+ case 0x81:
+ *pdwOffset+=2;
+ dwSize = pbPointer[1];
+ break;
+ case 0x82:
+ *pdwOffset+=3;
+ dwSize = pbPointer[1] * 0x100 + pbPointer[2];
+ break;
+ default:
+ dwSize = *pbPointer;
+ *pdwOffset+=1;
+ break;
+ }
+ return dwSize;
+}
+
+BOOL find_tlv(__in PBYTE pbData, __in DWORD dwTlvSearched, __in DWORD dwTotalSize, __out PBYTE *pbDataOut, __out_opt PDWORD pdwSize)
+{
+ DWORD dwOffset = 0, dwTlv ;
+ DWORD dwSize;
+ BOOL bFound = FALSE;
+ while (dwOffset < dwTotalSize)
+ {
+ // check the tlv
+ // if it begins with 0x5F => tlv of 2 bytes.
+ // else 1 byte
+ dwTlv = 0;
+ if (pbData[dwOffset] == 0x5F)
+ {
+ dwTlv = pbData[dwOffset] * 0x100;
+ dwOffset++;
+ }
+ dwTlv += pbData[dwOffset];
+ dwOffset++;
+
+
+ if (dwTlv == dwTlvSearched)
+ {
+ // size sequence
+ dwSize = getTlvSize(pbData + dwOffset,&dwOffset);
+ if (pdwSize)
+ {
+ *pdwSize = dwSize;
+ }
+ *pbDataOut = pbData + dwOffset;
+ return TRUE;
+ }
+ else
+ {
+ dwSize = getTlvSize(pbData + dwOffset,&dwOffset);
+ if (dwTlv != 0x73)
+ {
+ dwOffset += dwSize;
+ }
+ }
+ }
+ return FALSE;
+}
Added: trunk/OpenPGPminidriver/tlv.h
===================================================================
--- trunk/OpenPGPminidriver/tlv.h 2010-03-02 18:54:34 UTC (rev 5)
+++ trunk/OpenPGPminidriver/tlv.h 2010-03-04 21:17:51 UTC (rev 6)
@@ -0,0 +1,2 @@
+DWORD getTlvSize(__in PBYTE pbPointer, __in PDWORD pdwOffset);
+BOOL find_tlv(__in PBYTE pbData, __in DWORD dwTlv, __in DWORD dwTotalSize, __out PBYTE *pbDataOut, __out_opt PDWORD pdwSize);
More information about the Openpgpmdrv-commits
mailing list