From: Benoît Legat <benoit.legat@gmail.com> --- dlls/secur32/tests/Makefile.in | 2 +- dlls/secur32/tests/schannel.c | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/dlls/secur32/tests/Makefile.in b/dlls/secur32/tests/Makefile.in index caeac7e47e1..06518618639 100644 --- a/dlls/secur32/tests/Makefile.in +++ b/dlls/secur32/tests/Makefile.in @@ -1,5 +1,5 @@ TESTDLL = secur32.dll -IMPORTS = secur32 crypt32 advapi32 ws2_32 +IMPORTS = secur32 crypt32 ncrypt advapi32 ws2_32 SOURCES = \ main.c \ diff --git a/dlls/secur32/tests/schannel.c b/dlls/secur32/tests/schannel.c index 3bfde3be406..58089b451d7 100644 --- a/dlls/secur32/tests/schannel.c +++ b/dlls/secur32/tests/schannel.c @@ -27,6 +27,11 @@ #include <security.h> #define SCHANNEL_USE_BLACKLISTS #include <schannel.h> +#include <ncrypt.h> + +#ifndef CRYPT_ACQUIRE_ALLOW_NCRYPT_KEY_FLAG +#define CRYPT_ACQUIRE_ALLOW_NCRYPT_KEY_FLAG 0x00010000 +#endif #include "wine/test.h" @@ -2059,13 +2064,14 @@ static void test_ncrypt_key_credentials(void) CRYPT_DATA_BLOB pfx; HCERTSTORE store; const CERT_CONTEXT *cert; - CERT_KEY_CONTEXT key_ctx; - DWORD size; + NCRYPT_KEY_HANDLE ncrypt_key = 0; + DWORD key_spec = 0; + BOOL free_key = FALSE; BOOL ret; pfx.pbData = (BYTE *)pfxdata; pfx.cbData = sizeof(pfxdata); - store = PFXImportCertStore(&pfx, NULL, CRYPT_EXPORTABLE | PKCS12_NO_PERSIST_KEY | PKCS12_ALWAYS_CNG_KSP); + store = PFXImportCertStore(&pfx, NULL, CRYPT_EXPORTABLE | PKCS12_ALWAYS_CNG_KSP); ok(store != NULL, "PFXImportCertStore failed: %lu\n", GetLastError()); if (!store) return; @@ -2078,13 +2084,12 @@ static void test_ncrypt_key_credentials(void) } /* Verify the key is NCrypt. */ - size = sizeof(key_ctx); - key_ctx.hCryptProv = key_ctx.dwKeySpec = 0; - ret = CertGetCertificateContextProperty(cert, CERT_KEY_CONTEXT_PROP_ID, &key_ctx, &size); - ok(ret, "CertGetCertificateContextProperty failed: %lu\n", GetLastError()); + ret = CryptAcquireCertificatePrivateKey(cert, CRYPT_ACQUIRE_ALLOW_NCRYPT_KEY_FLAG, NULL, + &ncrypt_key, &key_spec, &free_key); + ok(ret, "CryptAcquireCertificatePrivateKey failed: %lu\n", GetLastError()); todo_wine - ok(key_ctx.dwKeySpec == CERT_NCRYPT_KEY_SPEC, - "expected CERT_NCRYPT_KEY_SPEC, got %lu\n", key_ctx.dwKeySpec); + ok(key_spec == CERT_NCRYPT_KEY_SPEC, + "expected CERT_NCRYPT_KEY_SPEC, got %lu\n", key_spec); /* AcquireCredentialsHandle should succeed with an NCrypt key. */ init_cred(&schanCred); @@ -2100,6 +2105,12 @@ static void test_ncrypt_key_credentials(void) ok(st == SEC_E_OK, "AcquireCredentialsHandleA inbound with NCrypt key failed: %08lx\n", st); if (st == SEC_E_OK) FreeCredentialsHandle(&cred); + /* Clean up the key handle. */ + if (ret && key_spec == CERT_NCRYPT_KEY_SPEC) + NCryptFreeObject(ncrypt_key); + else if (ret && free_key) + CryptReleaseContext(ncrypt_key, 0); + CertFreeCertificateContext(cert); CertCloseStore(store, 0); } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10561