Module: wine Branch: master Commit: e647719eb0f13fb7abb63a86c59477a53310f28d URL: https://gitlab.winehq.org/wine/wine/-/commit/e647719eb0f13fb7abb63a86c59477a...
Author: Paul Gofman pgofman@codeweavers.com Date: Mon Jun 26 16:32:35 2023 -0600
crypt32/tests: Test CertCreateSelfSignCertificate() without provider info.
---
dlls/crypt32/tests/cert.c | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-)
diff --git a/dlls/crypt32/tests/cert.c b/dlls/crypt32/tests/cert.c index 83594560efa..ac0987e76bd 100644 --- a/dlls/crypt32/tests/cert.c +++ b/dlls/crypt32/tests/cert.c @@ -2167,17 +2167,44 @@ static void testCreateSelfSignCert(void) HCRYPTPROV csp; BOOL ret; HCRYPTKEY key; - CRYPT_KEY_PROV_INFO info; + CRYPT_KEY_PROV_INFO info, *ret_info; + DWORD size;
/* This crashes: - context = CertCreateSelfSignCertificate(0, NULL, 0, NULL, NULL, NULL, NULL, - NULL); - * Calling this with no first parameter creates a new key container, which - * lasts beyond the test, so I don't test that. Nb: the generated key - * name is a GUID. - context = CertCreateSelfSignCertificate(0, &name, 0, NULL, NULL, NULL, NULL, - NULL); - */ + context = CertCreateSelfSignCertificate(0, NULL, 0, NULL, NULL, NULL, NULL, NULL); */ + + /* Test CSP created by implementation without CSP or CSP parameters provided. */ + context = CertCreateSelfSignCertificate(0, &name, 0, NULL, NULL, NULL, NULL, NULL); + ok(!!context, "failed, error %#lx.\n", GetLastError()); + size = 0; + ret = CertGetCertificateContextProperty(context, CERT_KEY_PROV_INFO_PROP_ID, NULL, &size); + ok(ret, "failed, error %#lx.\n", GetLastError()); + ret_info = malloc(size); + ok(!!ret_info, "memory allocation failed.\n"); + ret = CertGetCertificateContextProperty(context, CERT_KEY_PROV_INFO_PROP_ID, ret_info, &size); + ok(ret, "failed, error %#lx.\n", GetLastError()); + CertFreeCertificateContext(context); + ok(ret_info->dwKeySpec == AT_SIGNATURE, "got %#lx.\n", ret_info->dwKeySpec); + ok(!ret_info->dwFlags, "got %#lx.\n", ret_info->dwFlags); + ok(ret_info->pwszContainerName && *ret_info->pwszContainerName, "got %s.\n", + debugstr_w(ret_info->pwszContainerName)); + ret = CryptAcquireContextW(&csp, ret_info->pwszContainerName, ret_info->pwszProvName, ret_info->dwProvType, 0); + ok(ret, "failed, error %#lx.\n", GetLastError()); + ret = CryptGetUserKey(csp, AT_SIGNATURE, &key); + ok(ret, "failed, error %#lx.\n", GetLastError()); + ret = CryptDestroyKey(key); + ok(ret, "failed, error %#lx.\n", GetLastError()); + ret = CryptGetUserKey(csp, AT_KEYEXCHANGE, &key); + ok(!ret && GetLastError() == NTE_NO_KEY, "got ret %d, error %#lx.\n", ret, GetLastError()); + CryptReleaseContext(csp, 0); + csp = 0xdeadbeef; + ret = CryptAcquireContextW(&csp, ret_info->pwszContainerName, ret_info->pwszProvName, + ret_info->dwProvType, CRYPT_DELETEKEYSET); + ok(ret, "failed, error %#lx.\n", GetLastError()); + ok(!csp, "got %p.\n", (void *)csp); + ret = CryptAcquireContextW(&csp, ret_info->pwszContainerName, ret_info->pwszProvName, ret_info->dwProvType, 0); + ok(!ret && GetLastError() == NTE_BAD_KEYSET, "got ret %d, error %#lx.\n", ret, GetLastError()); + free(ret_info);
/* Acquire a CSP */ CryptAcquireContextA(&csp, cspNameA, MS_DEF_PROV_A, PROV_RSA_FULL,