Commit a7d897d7 authored by Mounir IDRASSI's avatar Mounir IDRASSI Committed by Alexandre Julliard

rsaenh: Fix read_key_container bug that prevents CryptAcquireContext from…

rsaenh: Fix read_key_container bug that prevents CryptAcquireContext from correctly loading the keys.
parent 12f4acce
...@@ -1050,6 +1050,7 @@ static HCRYPTPROV read_key_container(PCHAR pszContainerName, DWORD dwFlags, PVTa ...@@ -1050,6 +1050,7 @@ static HCRYPTPROV read_key_container(PCHAR pszContainerName, DWORD dwFlags, PVTa
KEYCONTAINER *pKeyContainer; KEYCONTAINER *pKeyContainer;
HCRYPTPROV hKeyContainer; HCRYPTPROV hKeyContainer;
DATA_BLOB blobIn, blobOut; DATA_BLOB blobIn, blobOut;
HCRYPTKEY hCryptKey;
sprintf(szRSABase, RSAENH_REGKEY, pszContainerName); sprintf(szRSABase, RSAENH_REGKEY, pszContainerName);
...@@ -1089,8 +1090,9 @@ static HCRYPTPROV read_key_container(PCHAR pszContainerName, DWORD dwFlags, PVTa ...@@ -1089,8 +1090,9 @@ static HCRYPTPROV read_key_container(PCHAR pszContainerName, DWORD dwFlags, PVTa
if (CryptUnprotectData(&blobIn, NULL, NULL, NULL, NULL, if (CryptUnprotectData(&blobIn, NULL, NULL, NULL, NULL,
(dwFlags & CRYPT_MACHINE_KEYSET) ? CRYPTPROTECT_LOCAL_MACHINE : 0, &blobOut)) (dwFlags & CRYPT_MACHINE_KEYSET) ? CRYPTPROTECT_LOCAL_MACHINE : 0, &blobOut))
{ {
RSAENH_CPImportKey(hKeyContainer, blobOut.pbData, blobOut.cbData, 0, 0, if(RSAENH_CPImportKey(hKeyContainer, blobOut.pbData, blobOut.cbData, 0, 0,
&pKeyContainer->hKeyExchangeKeyPair); &hCryptKey))
pKeyContainer->hKeyExchangeKeyPair = hCryptKey;
HeapFree(GetProcessHeap(), 0, blobOut.pbData); HeapFree(GetProcessHeap(), 0, blobOut.pbData);
} }
} }
...@@ -1113,8 +1115,9 @@ static HCRYPTPROV read_key_container(PCHAR pszContainerName, DWORD dwFlags, PVTa ...@@ -1113,8 +1115,9 @@ static HCRYPTPROV read_key_container(PCHAR pszContainerName, DWORD dwFlags, PVTa
if (CryptUnprotectData(&blobIn, NULL, NULL, NULL, NULL, if (CryptUnprotectData(&blobIn, NULL, NULL, NULL, NULL,
(dwFlags & CRYPT_MACHINE_KEYSET) ? CRYPTPROTECT_LOCAL_MACHINE : 0, &blobOut)) (dwFlags & CRYPT_MACHINE_KEYSET) ? CRYPTPROTECT_LOCAL_MACHINE : 0, &blobOut))
{ {
RSAENH_CPImportKey(hKeyContainer, blobOut.pbData, blobOut.cbData, 0, 0, if(RSAENH_CPImportKey(hKeyContainer, blobOut.pbData, blobOut.cbData, 0, 0,
&pKeyContainer->hSignatureKeyPair); &hCryptKey))
pKeyContainer->hSignatureKeyPair = hCryptKey;
HeapFree(GetProcessHeap(), 0, blobOut.pbData); HeapFree(GetProcessHeap(), 0, blobOut.pbData);
} }
} }
......
...@@ -1603,6 +1603,26 @@ static void test_null_provider(void) ...@@ -1603,6 +1603,26 @@ static void test_null_provider(void)
CryptAcquireContext(&prov, szContainer, NULL, PROV_RSA_FULL, CryptAcquireContext(&prov, szContainer, NULL, PROV_RSA_FULL,
CRYPT_DELETEKEYSET); CRYPT_DELETEKEYSET);
/* test for the bug in accessing the user key in a container
*/
result = CryptAcquireContext(&prov, szContainer, NULL, PROV_RSA_FULL,
CRYPT_NEWKEYSET);
ok(result, "CryptAcquireContext failed: %08x\n", GetLastError());
result = CryptGenKey(prov, AT_KEYEXCHANGE, 0, &key);
ok(result, "CryptGenKey with AT_KEYEXCHANGE failed with error %08x\n", GetLastError());
CryptDestroyKey(key);
CryptReleaseContext(prov,0);
result = CryptAcquireContext(&prov, szContainer, NULL, PROV_RSA_FULL,0);
ok(result, "CryptAcquireContext failed: 0x%08x\n", GetLastError());
result = CryptGetUserKey(prov, AT_KEYEXCHANGE, &key);
ok (result, "CryptGetUserKey failed with error %08x\n", GetLastError());
CryptDestroyKey(key);
CryptAcquireContext(&prov, szContainer, NULL, PROV_RSA_FULL,
CRYPT_DELETEKEYSET);
} }
START_TEST(rsaenh) START_TEST(rsaenh)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment