Commit 559a83a8 authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

crypt32: CryptAcquireCertificatePrivateKey() should reset last error code on success.

One of Chrome crypto plugins depends on this. Signed-off-by: 's avatarDmitry Timoshkov <dmitry@baikal.ru> Signed-off-by: 's avatarHans Leidekker <hans@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 0044e527
......@@ -1006,6 +1006,7 @@ BOOL WINAPI CryptAcquireCertificatePrivateKey(PCCERT_CONTEXT pCert,
CryptMemFree(info);
if (cert_in_store)
CertFreeCertificateContext(cert_in_store);
if (ret) SetLastError(0);
return ret;
}
......
......@@ -4305,45 +4305,42 @@ static void testAcquireCertPrivateKey(void)
CERT_KEY_CONTEXT keyContext;
/* Don't cache provider */
SetLastError(0xdeadbeef);
ret = CryptAcquireCertificatePrivateKey(cert, 0, NULL, &certCSP,
&keySpec, &callerFree);
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n",
GetLastError());
if (ret)
{
ok(callerFree, "Expected callerFree to be TRUE\n");
CryptReleaseContext(certCSP, 0);
}
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n", GetLastError());
ok(GetLastError() == ERROR_SUCCESS, "got %08lx\n", GetLastError());
ok(callerFree, "Expected callerFree to be TRUE\n");
CryptReleaseContext(certCSP, 0);
SetLastError(0xdeadbeef);
ret = CryptAcquireCertificatePrivateKey(cert, 0, NULL, &certCSP,
NULL, NULL);
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n",
GetLastError());
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n", GetLastError());
ok(GetLastError() == ERROR_SUCCESS, "got %08lx\n", GetLastError());
CryptReleaseContext(certCSP, 0);
/* Use the key prov info's caching (there shouldn't be any) */
SetLastError(0xdeadbeef);
ret = CryptAcquireCertificatePrivateKey(cert,
CRYPT_ACQUIRE_USE_PROV_INFO_FLAG, NULL, &certCSP, &keySpec,
&callerFree);
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n",
GetLastError());
if (ret)
{
ok(callerFree, "Expected callerFree to be TRUE\n");
CryptReleaseContext(certCSP, 0);
}
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n", GetLastError());
ok(GetLastError() == ERROR_SUCCESS, "got %08lx\n", GetLastError());
ok(callerFree, "Expected callerFree to be TRUE\n");
CryptReleaseContext(certCSP, 0);
/* Cache it (and check that it's cached) */
SetLastError(0xdeadbeef);
ret = CryptAcquireCertificatePrivateKey(cert,
CRYPT_ACQUIRE_CACHE_FLAG, NULL, &certCSP, &keySpec, &callerFree);
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n",
GetLastError());
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n", GetLastError());
ok(GetLastError() == ERROR_SUCCESS, "got %08lx\n", GetLastError());
ok(!callerFree, "Expected callerFree to be FALSE\n");
size = sizeof(keyContext);
ret = CertGetCertificateContextProperty(cert, CERT_KEY_CONTEXT_PROP_ID,
&keyContext, &size);
ok(ret, "CertGetCertificateContextProperty failed: %08lx\n",
GetLastError());
ok(ret, "CertGetCertificateContextProperty failed: %08lx\n", GetLastError());
/* Remove the cached provider */
CryptReleaseContext(keyContext.hCryptProv, 0);
......@@ -4354,17 +4351,17 @@ static void testAcquireCertPrivateKey(void)
CertSetCertificateContextProperty(cert, CERT_KEY_PROV_INFO_PROP_ID, 0,
&keyProvInfo);
/* Now use the key prov info's caching */
SetLastError(0xdeadbeef);
ret = CryptAcquireCertificatePrivateKey(cert,
CRYPT_ACQUIRE_USE_PROV_INFO_FLAG, NULL, &certCSP, &keySpec,
&callerFree);
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n",
GetLastError());
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n", GetLastError());
ok(GetLastError() == ERROR_SUCCESS, "got %08lx\n", GetLastError());
ok(!callerFree, "Expected callerFree to be FALSE\n");
size = sizeof(keyContext);
ret = CertGetCertificateContextProperty(cert, CERT_KEY_CONTEXT_PROP_ID,
&keyContext, &size);
ok(ret, "CertGetCertificateContextProperty failed: %08lx\n",
GetLastError());
ok(ret, "CertGetCertificateContextProperty failed: %08lx\n", GetLastError());
CryptReleaseContext(certCSP, 0);
CryptDestroyKey(key);
......
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