[Openpgpmdrv-commits] r4 - in trunk: OpenPGPminidriver OpenPGPminidriverTest
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Sun Feb 28 10:39:35 CET 2010
Author: vletoux
Date: 2010-02-28 10:39:34 +0100 (Sun, 28 Feb 2010)
New Revision: 4
Modified:
trunk/OpenPGPminidriver/CryptoOperations.c
trunk/OpenPGPminidriverTest/BaseCSP.cpp
Log:
decryption is now working !
Modified: trunk/OpenPGPminidriver/CryptoOperations.c
===================================================================
--- trunk/OpenPGPminidriver/CryptoOperations.c 2010-02-25 22:09:17 UTC (rev 3)
+++ trunk/OpenPGPminidriver/CryptoOperations.c 2010-02-28 09:39:34 UTC (rev 4)
@@ -1050,7 +1050,7 @@
pbCmd[dwCmdSize++] = (BYTE)((pInfo->cbData +1) % 0x100);
}
pbCmd[dwCmdSize++] = 0;
- //memcpy(pbCmd + dwCmdSize, pInfo->pbData, pInfo->cbData);
+ //little endian => big endian
for(dwI = 0; dwI < pInfo->cbData; dwI++)
{
pbCmd[dwCmdSize + dwI] = pInfo->pbData[pInfo->cbData -1 -dwI];
@@ -1070,14 +1070,29 @@
{
__leave;
}
- if ( pInfo->cbData < dwResponseSize)
+
+ // CryptDecrypt expects the data decrypted using rsa (only the mathematical computation)
+ // this means the data with the padding (removed by the card)
+ // and in little endian (while the card return the data in big endian)
+ // so we rebuilt the padding in reverse order
+
+ if ( pInfo->cbData < dwResponseSize + 3 + 11)
{
dwReturn = SCARD_E_INSUFFICIENT_BUFFER;
Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_INSUFFICIENT_BUFFER %d expected = %d", pInfo->cbData, dwResponseSize);
__leave;
}
- pInfo->cbData = dwResponseSize;
- memcpy( pInfo->pbData, pbData, dwResponseSize);
+
+ pInfo->pbData[pInfo->cbData - 1] = 0; // start byte
+ pInfo->pbData[pInfo->cbData - 2] = 02; // block type
+ // padding
+ memset(pInfo->pbData + dwResponseSize + 1,1,pInfo->cbData - 3 - dwResponseSize);
+ pInfo->pbData[dwResponseSize] = 0; // separator
+ // data field in reverse order
+ for(dwI = 0; dwI < dwResponseSize; dwI++)
+ {
+ pInfo->pbData[dwI] = pbData[dwResponseSize - 1 - dwI];
+ }
}
__finally
{
Modified: trunk/OpenPGPminidriverTest/BaseCSP.cpp
===================================================================
--- trunk/OpenPGPminidriverTest/BaseCSP.cpp 2010-02-25 22:09:17 UTC (rev 3)
+++ trunk/OpenPGPminidriverTest/BaseCSP.cpp 2010-02-28 09:39:34 UTC (rev 4)
@@ -398,7 +398,7 @@
HCRYPTHASH hHash = NULL;
PBYTE pbCrypt = NULL;
DWORD dwCryptSize = 0, dwBufferSize;
- BYTE pbChallenge[20] = "test";
+ BYTE pbChallenge[20] = "test1234567890";
__try
{
bStatus = CryptAcquireContext(&hProv,szContainer, MS_SCARD_PROV, PROV_RSA_FULL, 0);
@@ -413,12 +413,12 @@
dwReturn = GetLastError();
__leave;
}
- bStatus = CryptGenRandom(hProv,ARRAYSIZE(pbChallenge),pbChallenge);
+ /*bStatus = CryptGenRandom(hProv,ARRAYSIZE(pbChallenge),pbChallenge);
if (!bStatus)
{
dwReturn = GetLastError();
__leave;
- }
+ }*/
dwCryptSize = 0;
dwBufferSize = ARRAYSIZE(pbChallenge);
if (!CryptEncrypt(hKey,NULL, TRUE, 0, NULL, &dwBufferSize,0))
@@ -439,7 +439,7 @@
dwReturn = GetLastError();
__leave;
}
- if (!CryptDecrypt(hKey, NULL, TRUE, 0, pbCrypt, &dwCryptSize))
+ if (!CryptDecrypt(hKey, NULL, FALSE, 0, pbCrypt, &dwCryptSize))
{
dwReturn = GetLastError();
__leave;
More information about the Openpgpmdrv-commits
mailing list