Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/ntoskrnl.exe/tests/ntoskrnl.c | 33 ++++++++++++++---------------- 1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/dlls/ntoskrnl.exe/tests/ntoskrnl.c b/dlls/ntoskrnl.exe/tests/ntoskrnl.c index ee8194fd1d0..c8c6354b793 100644 --- a/dlls/ntoskrnl.exe/tests/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/tests/ntoskrnl.c @@ -87,7 +87,6 @@ static void load_resource(const WCHAR *name, WCHAR *filename)
struct testsign_context { - HCRYPTPROV provider; const CERT_CONTEXT *cert, *root_cert, *publisher_cert; HCERTSTORE root_store, publisher_store; }; @@ -105,26 +104,27 @@ static BOOL testsign_create_cert(struct testsign_context *ctx) CERT_INFO cert_info = {0}; WCHAR provider_nameW[100]; CERT_EXTENSION extension; + HCRYPTPROV provider; HCRYPTKEY key; DWORD size; BOOL ret;
memset(ctx, 0, sizeof(*ctx));
- ret = CryptAcquireContextW(&ctx->provider, container_name, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET); + ret = CryptAcquireContextW(&provider, container_name, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET); if (!ret && GetLastError() == NTE_EXISTS) { - ret = CryptAcquireContextW(&ctx->provider, container_name, NULL, PROV_RSA_FULL, CRYPT_DELETEKEYSET); + ret = CryptAcquireContextW(&provider, container_name, NULL, PROV_RSA_FULL, CRYPT_DELETEKEYSET); ok(ret, "Failed to delete container, error %#x\n", GetLastError()); - ret = CryptAcquireContextW(&ctx->provider, container_name, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET); + ret = CryptAcquireContextW(&provider, container_name, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET); } ok(ret, "Failed to create container, error %#x\n", GetLastError());
- ret = CryptGenKey(ctx->provider, AT_SIGNATURE, CRYPT_EXPORTABLE, &key); + ret = CryptGenKey(provider, AT_SIGNATURE, CRYPT_EXPORTABLE, &key); ok(ret, "Failed to create key, error %#x\n", GetLastError()); ret = CryptDestroyKey(key); ok(ret, "Failed to destroy key, error %#x\n", GetLastError()); - ret = CryptGetUserKey(ctx->provider, AT_SIGNATURE, &key); + ret = CryptGetUserKey(provider, AT_SIGNATURE, &key); ok(ret, "Failed to get user key, error %#x\n", GetLastError()); ret = CryptDestroyKey(key); ok(ret, "Failed to destroy key, error %#x\n", GetLastError()); @@ -136,12 +136,12 @@ static BOOL testsign_create_cert(struct testsign_context *ctx) key_info.CertIssuer.pbData = encoded_name;
size = sizeof(public_key_info_buffer); - ret = CryptExportPublicKeyInfo(ctx->provider, AT_SIGNATURE, X509_ASN_ENCODING, public_key_info, &size); + ret = CryptExportPublicKeyInfo(provider, AT_SIGNATURE, X509_ASN_ENCODING, public_key_info, &size); ok(ret, "Failed to export public key, error %#x\n", GetLastError()); cert_info.SubjectPublicKeyInfo = *public_key_info;
size = sizeof(hash_buffer); - ret = CryptHashPublicKeyInfo(ctx->provider, CALG_MD5, 0, X509_ASN_ENCODING, public_key_info, hash_buffer, &size); + ret = CryptHashPublicKeyInfo(provider, CALG_MD5, 0, X509_ASN_ENCODING, public_key_info, hash_buffer, &size); ok(ret, "Failed to hash public key, error %#x\n", GetLastError());
key_info.KeyId.cbData = size; @@ -172,7 +172,7 @@ static BOOL testsign_create_cert(struct testsign_context *ctx) cert_info.rgExtension = &extension; algid.pszObjId = (char *)szOID_RSA_SHA1RSA; size = sizeof(cert_buffer); - ret = CryptSignAndEncodeCertificate(ctx->provider, AT_SIGNATURE, X509_ASN_ENCODING, + ret = CryptSignAndEncodeCertificate(provider, AT_SIGNATURE, X509_ASN_ENCODING, X509_CERT_TO_BE_SIGNED, &cert_info, &algid, NULL, cert_buffer, &size); ok(ret, "Failed to create certificate, error %#x\n", GetLastError());
@@ -180,7 +180,7 @@ static BOOL testsign_create_cert(struct testsign_context *ctx) ok(!!ctx->cert, "Failed to create context, error %#x\n", GetLastError());
size = sizeof(provider_nameA); - ret = CryptGetProvParam(ctx->provider, PP_NAME, provider_nameA, &size, 0); + ret = CryptGetProvParam(provider, PP_NAME, provider_nameA, &size, 0); ok(ret, "Failed to get prov param, error %#x\n", GetLastError()); MultiByteToWideChar(CP_ACP, 0, (char *)provider_nameA, -1, provider_nameW, ARRAY_SIZE(provider_nameW));
@@ -191,6 +191,9 @@ static BOOL testsign_create_cert(struct testsign_context *ctx) ret = CertSetCertificateContextProperty(ctx->cert, CERT_KEY_PROV_INFO_PROP_ID, 0, &provider_info); ok(ret, "Failed to set provider info, error %#x\n", GetLastError());
+ ret = CryptReleaseContext(provider, 0); + ok(ret, "failed to release context, error %u\n", GetLastError()); + ctx->root_store = CertOpenStore(CERT_STORE_PROV_SYSTEM_REGISTRY_A, 0, 0, CERT_SYSTEM_STORE_LOCAL_MACHINE, "root"); if (!ctx->root_store && GetLastError() == ERROR_ACCESS_DENIED) { @@ -198,8 +201,6 @@ static BOOL testsign_create_cert(struct testsign_context *ctx)
ret = CertFreeCertificateContext(ctx->cert); ok(ret, "Failed to free certificate, error %u\n", GetLastError()); - ret = CryptReleaseContext(ctx->provider, 0); - ok(ret, "failed to release context, error %u\n", GetLastError());
return FALSE; } @@ -213,8 +214,6 @@ static BOOL testsign_create_cert(struct testsign_context *ctx) ok(ret, "Failed to free certificate, error %u\n", GetLastError()); ret = CertCloseStore(ctx->root_store, CERT_CLOSE_STORE_CHECK_FLAG); ok(ret, "Failed to close store, error %u\n", GetLastError()); - ret = CryptReleaseContext(ctx->provider, 0); - ok(ret, "failed to release context, error %u\n", GetLastError());
return FALSE; } @@ -232,6 +231,7 @@ static BOOL testsign_create_cert(struct testsign_context *ctx)
static void testsign_cleanup(struct testsign_context *ctx) { + HCRYPTPROV provider; BOOL ret;
ret = CertFreeCertificateContext(ctx->cert); @@ -247,10 +247,7 @@ static void testsign_cleanup(struct testsign_context *ctx) ret = CertCloseStore(ctx->publisher_store, CERT_CLOSE_STORE_CHECK_FLAG); ok(ret, "Failed to close store, error %u\n", GetLastError());
- ret = CryptReleaseContext(ctx->provider, 0); - ok(ret, "failed to release context, error %u\n", GetLastError()); - - ret = CryptAcquireContextW(&ctx->provider, container_name, NULL, PROV_RSA_FULL, CRYPT_DELETEKEYSET); + ret = CryptAcquireContextW(&provider, container_name, NULL, PROV_RSA_FULL, CRYPT_DELETEKEYSET); ok(ret, "Failed to delete container, error %#x\n", GetLastError()); }