2 * Unit tests for dss functions
4 * Copyright (c) 2012 Marek Kamil Chmiel
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/test.h"
29 static void test_acquire_context(void)
30 { /* failure tests common between all four CSP providers */
35 /* cannot acquire provider with 0 as Prov Type and NULL as CSP name */
36 SetLastError(0xdeadbeef);
37 result = CryptAcquireContextA(&hProv, NULL, NULL, 0, 0);
38 ok(!result && GetLastError() == NTE_BAD_PROV_TYPE,
39 "Expected NTE_BAD_PROV_TYPE, got %08x\n", GetLastError());
41 SetLastError(0xdeadbeef);
42 result = CryptAcquireContextA(&hProv, NULL, NULL, 0, CRYPT_VERIFYCONTEXT);
43 ok(!result && GetLastError() == NTE_BAD_PROV_TYPE,
44 "Expected NTE_BAD_PROV_TYPE, got %08x\n", GetLastError());
46 /* flag allows us to delete a keyset, but not of an unknown provider */
47 SetLastError(0xdeadbeef);
48 result = CryptAcquireContextA(&hProv, NULL, NULL, 0, CRYPT_DELETEKEYSET);
49 ok(!result && GetLastError() == NTE_BAD_PROV_TYPE,
50 "Expected NTE_BAD_PROV_TYPE, got %08x\n", GetLastError());
52 /* cannot acquire along with PROV_RSA_SIG, not compatible */
53 SetLastError(0xdeadbeef);
54 result = CryptAcquireContextA(&hProv, NULL, MS_DEF_DSS_PROV_A, PROV_RSA_SIG, 0);
56 ok(!result && GetLastError() == NTE_PROV_TYPE_NO_MATCH,
57 "Expected NTE_PROV_TYPE_NO_MATCH, got %08x\n", GetLastError());
59 /* cannot acquire along with MS_DEF_RSA_SIG_PROV, not compatible */
60 SetLastError(0xdeadbeef);
61 result = CryptAcquireContextA(&hProv, NULL, MS_DEF_RSA_SIG_PROV, PROV_DSS, 0);
62 ok(!result && GetLastError() == NTE_KEYSET_NOT_DEF,
63 "Expected NTE_KEYSET_NOT_DEF, got %08x\n", GetLastError());
65 /* cannot acquire provider with 0 as Prov Type */
66 SetLastError(0xdeadbeef);
67 result = CryptAcquireContextA(&hProv, NULL, MS_DEF_DSS_PROV_A, 0, 0);
68 ok(!result && GetLastError() == NTE_BAD_PROV_TYPE,
69 "Expected NTE_BAD_PROV_TYPE, got %08x\n", GetLastError());
71 /* test base DSS provider (PROV_DSS) */
73 result = CryptAcquireContextA(
74 &hProv, NULL, MS_DEF_DSS_PROV_A, PROV_DSS, CRYPT_VERIFYCONTEXT);
77 skip("DSS csp is currently not available, skipping tests.\n");
80 ok(result, "Expected no errors.\n");
82 result = CryptReleaseContext(hProv, 0);
83 ok(result, "Expected release of the provider.\n");
85 result = CryptAcquireContextA(
86 &hProv, NULL, MS_DEF_DSS_DH_PROV_A, PROV_DSS_DH, CRYPT_NEWKEYSET);
87 ok(result, "Expected no errors.\n");
89 result = CryptReleaseContext(hProv, 0);
90 ok(result, "Expected release of the provider.\n");
92 result = CryptAcquireContextA(&hProv, NULL, NULL, PROV_DSS, 0);
93 ok(result, "Expected no errors.\n");
95 result = CryptReleaseContext(hProv, 0);
96 ok(result, "Expected release of the provider.\n");
98 result = CryptAcquireContextA(&hProv, NULL, MS_DEF_DSS_PROV_A, PROV_DSS, 0);
99 ok(result, "Expected no errors.\n");
101 /* test DSS Diffie Hellman provider (PROV_DSS_DH) */
103 result = CryptAcquireContextA(
104 &hProv, NULL, MS_DEF_DSS_DH_PROV, PROV_DSS_DH, CRYPT_VERIFYCONTEXT);
105 ok(result, "Expected no errors.\n");
107 result = CryptReleaseContext(hProv, 0);
108 ok(result, "Expected release of the provider.\n");
110 result = CryptAcquireContextA(&hProv, NULL, NULL, PROV_DSS_DH, 0);
111 ok(result, "Expected no errors.\n");
113 result = CryptReleaseContext(hProv, 0);
114 ok(result, "Expected release of the provider.\n");
116 result = CryptAcquireContextA(&hProv, NULL, MS_DEF_DSS_DH_PROV, PROV_DSS_DH, 0);
117 ok(result, "Expected no errors.\n");
119 /* test DSS Enhanced provider (MS_ENH_DSS_DH_PROV) */
121 SetLastError(0xdeadbeef);
122 result = CryptAcquireContextA(
123 &hProv, NULL, MS_ENH_DSS_DH_PROV, PROV_DSS_DH, CRYPT_VERIFYCONTEXT);
124 if(!result && GetLastError() == NTE_KEYSET_NOT_DEF)
126 win_skip("DSSENH and Schannel provider is broken on WinNT4\n");
129 ok(result, "Expected no errors.\n");
131 result = CryptReleaseContext(hProv, 0);
132 ok(result, "Expected release of the provider.\n");
134 result = CryptAcquireContextA(&hProv, NULL, MS_ENH_DSS_DH_PROV, PROV_DSS_DH, 0);
135 ok(result, "Expected no errors.\n");
137 result = CryptReleaseContext(hProv, 0);
138 ok(result, "Expected release of the provider.\n");
140 /* test DSS Schannel provider (PROV_DH_SCHANNEL) */
142 result = CryptAcquireContextA(
143 &hProv, NULL, MS_DEF_DH_SCHANNEL_PROV, PROV_DH_SCHANNEL, CRYPT_VERIFYCONTEXT);
144 ok(result, "Expected no errors.\n");
146 result = CryptReleaseContext(hProv, 0);
147 ok(result, "Expected release of the provider.\n");
149 result = CryptAcquireContextA(&hProv, NULL, NULL, PROV_DH_SCHANNEL, 0);
150 ok(result, "Expected no errors.\n");
152 result = CryptReleaseContext(hProv, 0);
153 ok(result, "Expected release of the provider.\n");
155 result = CryptAcquireContextA(
156 &hProv, NULL, MS_DEF_DH_SCHANNEL_PROV, PROV_DH_SCHANNEL, 0);
157 ok(result, "Expected no errors.\n");
159 result = CryptReleaseContext(hProv, 0);
160 ok(result, "Expected release of the provider.\n");
162 /* failure tests, cannot acquire context because the key container already exists */
163 SetLastError(0xdeadbeef);
164 result = CryptAcquireContextA(
165 &hProv, NULL, MS_DEF_DSS_DH_PROV, PROV_DSS_DH, CRYPT_NEWKEYSET);
166 ok(!result && GetLastError() == NTE_EXISTS,
167 "Expected NTE_EXISTS, got %08x\n", GetLastError());
169 SetLastError(0xdeadbeef);
170 result = CryptAcquireContextA(
171 &hProv, NULL, MS_ENH_DSS_DH_PROV, PROV_DSS_DH, CRYPT_NEWKEYSET);
172 ok(!result && GetLastError() == NTE_EXISTS,
173 "Expected NTE_EXISTS, got %08x\n", GetLastError());
175 SetLastError(0xdeadbeef);
176 result = CryptAcquireContextA(
177 &hProv, NULL, MS_DEF_DH_SCHANNEL_PROV, PROV_DH_SCHANNEL, CRYPT_NEWKEYSET);
178 ok(!result && GetLastError() == NTE_EXISTS,
179 "Expected NTE_EXISTS, got %08x\n", GetLastError());
184 test_acquire_context();