dssenh: Implement CPGetUserKey.

Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hans Leidekker 2020-10-19 11:24:13 +02:00 committed by Alexandre Julliard
parent 320b9eb474
commit 248d27ea2d
3 changed files with 75 additions and 1 deletions

View File

@ -13,7 +13,7 @@
@ stdcall CPGetHashParam(ptr ptr long ptr ptr long)
@ stub CPGetKeyParam
@ stdcall CPGetProvParam(ptr long ptr ptr long)
@ stub CPGetUserKey
@ stdcall CPGetUserKey(ptr long ptr)
@ stdcall CPHashData(ptr ptr ptr long long)
@ stub CPHashSessionKey
@ stdcall CPImportKey(ptr ptr long ptr long ptr)

View File

@ -615,6 +615,35 @@ BOOL WINAPI CPDuplicateKey( HCRYPTPROV hprov, HCRYPTKEY hkey, DWORD *reserved, D
return TRUE;
}
BOOL WINAPI CPGetUserKey( HCRYPTPROV hprov, DWORD keyspec, HCRYPTKEY *ret_key )
{
struct container *container = (struct container *)hprov;
BOOL ret = FALSE;
TRACE( "%p, %08x, %p\n", (void *)hprov, keyspec, ret_key );
if (container->magic != MAGIC_CONTAINER) return FALSE;
switch (keyspec)
{
case AT_KEYEXCHANGE:
if (!container->exch_key) SetLastError( NTE_NO_KEY );
else if ((*ret_key = (HCRYPTKEY)duplicate_key( container->exch_key ))) ret = TRUE;
break;
case AT_SIGNATURE:
if (!container->sign_key) SetLastError( NTE_NO_KEY );
else if ((*ret_key = (HCRYPTKEY)duplicate_key( container->sign_key ))) ret = TRUE;
break;
default:
SetLastError( NTE_NO_KEY );
return FALSE;
}
return ret;
}
BOOL WINAPI CPGenRandom( HCRYPTPROV hprov, DWORD len, BYTE *buffer )
{
struct container *container = (struct container *)hprov;

View File

@ -1470,6 +1470,50 @@ static void test_duplicate_hash(void)
ok(result, "got %08x\n", GetLastError());
}
static void test_userkey(void)
{
HCRYPTPROV hprov;
HCRYPTKEY hkey;
BOOL result;
CryptAcquireContextA(&hprov, "winetest", MS_ENH_DSS_DH_PROV_A, PROV_DSS_DH, CRYPT_DELETEKEYSET);
result = CryptAcquireContextA(&hprov, "winetest", MS_ENH_DSS_DH_PROV_A, PROV_DSS_DH, CRYPT_NEWKEYSET);
ok(result, "got %08x\n", GetLastError());
SetLastError(0xdeadbeef);
result = CryptGetUserKey(hprov, AT_KEYEXCHANGE, &hkey);
ok(!result, "success\n");
ok(GetLastError() == NTE_NO_KEY, "got %08x\n", GetLastError());
SetLastError(0xdeadbeef);
result = CryptGetUserKey(hprov, AT_SIGNATURE, &hkey);
ok(!result, "success\n");
ok(GetLastError() == NTE_NO_KEY, "got %08x\n", GetLastError());
result = CryptGenKey(hprov, AT_SIGNATURE, 1024 << 16, &hkey);
ok(result, "got %08x\n", GetLastError());
result = CryptDestroyKey(hkey);
ok(result, "got %08x\n", GetLastError());
result = CryptGetUserKey(hprov, AT_SIGNATURE, &hkey);
ok(result, "got %08x\n", GetLastError());
result = CryptDestroyKey(hkey);
ok(result, "got %08x\n", GetLastError());
SetLastError(0xdeadbeef);
result = CryptGetUserKey(hprov, AT_KEYEXCHANGE, &hkey);
ok(!result, "success\n");
ok(GetLastError() == NTE_NO_KEY, "got %08x\n", GetLastError());
result = CryptReleaseContext(hprov, 0);
ok(result, "got %08x\n", GetLastError());
hprov = 0xdeadbeef;
result = CryptAcquireContextA(&hprov, "winetest", MS_ENH_DSS_DH_PROV_A, PROV_DSS_DH, CRYPT_DELETEKEYSET);
ok(result, "got %08x\n", GetLastError());
ok(!hprov, "got %08x\n", (DWORD)hprov);
}
START_TEST(dssenh)
{
test_acquire_context();
@ -1480,4 +1524,5 @@ START_TEST(dssenh)
test_verify_signature();
test_key_exchange();
test_duplicate_hash();
test_userkey();
}