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, ...@@ -1006,6 +1006,7 @@ BOOL WINAPI CryptAcquireCertificatePrivateKey(PCCERT_CONTEXT pCert,
CryptMemFree(info); CryptMemFree(info);
if (cert_in_store) if (cert_in_store)
CertFreeCertificateContext(cert_in_store); CertFreeCertificateContext(cert_in_store);
if (ret) SetLastError(0);
return ret; return ret;
} }
......
...@@ -4305,45 +4305,42 @@ static void testAcquireCertPrivateKey(void) ...@@ -4305,45 +4305,42 @@ static void testAcquireCertPrivateKey(void)
CERT_KEY_CONTEXT keyContext; CERT_KEY_CONTEXT keyContext;
/* Don't cache provider */ /* Don't cache provider */
SetLastError(0xdeadbeef);
ret = CryptAcquireCertificatePrivateKey(cert, 0, NULL, &certCSP, ret = CryptAcquireCertificatePrivateKey(cert, 0, NULL, &certCSP,
&keySpec, &callerFree); &keySpec, &callerFree);
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n", ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n", GetLastError());
GetLastError()); ok(GetLastError() == ERROR_SUCCESS, "got %08lx\n", GetLastError());
if (ret)
{
ok(callerFree, "Expected callerFree to be TRUE\n"); ok(callerFree, "Expected callerFree to be TRUE\n");
CryptReleaseContext(certCSP, 0); CryptReleaseContext(certCSP, 0);
}
SetLastError(0xdeadbeef);
ret = CryptAcquireCertificatePrivateKey(cert, 0, NULL, &certCSP, ret = CryptAcquireCertificatePrivateKey(cert, 0, NULL, &certCSP,
NULL, NULL); NULL, NULL);
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n", ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n", GetLastError());
GetLastError()); ok(GetLastError() == ERROR_SUCCESS, "got %08lx\n", GetLastError());
CryptReleaseContext(certCSP, 0); CryptReleaseContext(certCSP, 0);
/* Use the key prov info's caching (there shouldn't be any) */ /* Use the key prov info's caching (there shouldn't be any) */
SetLastError(0xdeadbeef);
ret = CryptAcquireCertificatePrivateKey(cert, ret = CryptAcquireCertificatePrivateKey(cert,
CRYPT_ACQUIRE_USE_PROV_INFO_FLAG, NULL, &certCSP, &keySpec, CRYPT_ACQUIRE_USE_PROV_INFO_FLAG, NULL, &certCSP, &keySpec,
&callerFree); &callerFree);
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n", ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n", GetLastError());
GetLastError()); ok(GetLastError() == ERROR_SUCCESS, "got %08lx\n", GetLastError());
if (ret)
{
ok(callerFree, "Expected callerFree to be TRUE\n"); ok(callerFree, "Expected callerFree to be TRUE\n");
CryptReleaseContext(certCSP, 0); CryptReleaseContext(certCSP, 0);
}
/* Cache it (and check that it's cached) */ /* Cache it (and check that it's cached) */
SetLastError(0xdeadbeef);
ret = CryptAcquireCertificatePrivateKey(cert, ret = CryptAcquireCertificatePrivateKey(cert,
CRYPT_ACQUIRE_CACHE_FLAG, NULL, &certCSP, &keySpec, &callerFree); CRYPT_ACQUIRE_CACHE_FLAG, NULL, &certCSP, &keySpec, &callerFree);
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n", ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n", GetLastError());
GetLastError()); ok(GetLastError() == ERROR_SUCCESS, "got %08lx\n", GetLastError());
ok(!callerFree, "Expected callerFree to be FALSE\n"); ok(!callerFree, "Expected callerFree to be FALSE\n");
size = sizeof(keyContext); size = sizeof(keyContext);
ret = CertGetCertificateContextProperty(cert, CERT_KEY_CONTEXT_PROP_ID, ret = CertGetCertificateContextProperty(cert, CERT_KEY_CONTEXT_PROP_ID,
&keyContext, &size); &keyContext, &size);
ok(ret, "CertGetCertificateContextProperty failed: %08lx\n", ok(ret, "CertGetCertificateContextProperty failed: %08lx\n", GetLastError());
GetLastError());
/* Remove the cached provider */ /* Remove the cached provider */
CryptReleaseContext(keyContext.hCryptProv, 0); CryptReleaseContext(keyContext.hCryptProv, 0);
...@@ -4354,17 +4351,17 @@ static void testAcquireCertPrivateKey(void) ...@@ -4354,17 +4351,17 @@ static void testAcquireCertPrivateKey(void)
CertSetCertificateContextProperty(cert, CERT_KEY_PROV_INFO_PROP_ID, 0, CertSetCertificateContextProperty(cert, CERT_KEY_PROV_INFO_PROP_ID, 0,
&keyProvInfo); &keyProvInfo);
/* Now use the key prov info's caching */ /* Now use the key prov info's caching */
SetLastError(0xdeadbeef);
ret = CryptAcquireCertificatePrivateKey(cert, ret = CryptAcquireCertificatePrivateKey(cert,
CRYPT_ACQUIRE_USE_PROV_INFO_FLAG, NULL, &certCSP, &keySpec, CRYPT_ACQUIRE_USE_PROV_INFO_FLAG, NULL, &certCSP, &keySpec,
&callerFree); &callerFree);
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n", ok(ret, "CryptAcquireCertificatePrivateKey failed: %08lx\n", GetLastError());
GetLastError()); ok(GetLastError() == ERROR_SUCCESS, "got %08lx\n", GetLastError());
ok(!callerFree, "Expected callerFree to be FALSE\n"); ok(!callerFree, "Expected callerFree to be FALSE\n");
size = sizeof(keyContext); size = sizeof(keyContext);
ret = CertGetCertificateContextProperty(cert, CERT_KEY_CONTEXT_PROP_ID, ret = CertGetCertificateContextProperty(cert, CERT_KEY_CONTEXT_PROP_ID,
&keyContext, &size); &keyContext, &size);
ok(ret, "CertGetCertificateContextProperty failed: %08lx\n", ok(ret, "CertGetCertificateContextProperty failed: %08lx\n", GetLastError());
GetLastError());
CryptReleaseContext(certCSP, 0); CryptReleaseContext(certCSP, 0);
CryptDestroyKey(key); 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