wbemprox: Add support for enumerating class properties.
[wine] / dlls / dssenh / tests / dssenh.c
1 /*
2  * Unit tests for dss functions
3  *
4  * Copyright (c) 2012 Marek Kamil Chmiel
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <string.h>
22 #include <stdio.h>
23 #include "wine/test.h"
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27 #include "wincrypt.h"
28
29 static void test_acquire_context(void)
30 {   /* failure tests common between all four CSP providers */
31
32     HCRYPTPROV hProv = 0;
33     BOOL result;
34
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());
40
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());
45
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());
51
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);
55     todo_wine
56     ok(!result && GetLastError() == NTE_PROV_TYPE_NO_MATCH,
57         "Expected NTE_PROV_TYPE_NO_MATCH, got %08x\n", GetLastError());
58
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());
64
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());
70
71     /* test base DSS provider (PROV_DSS) */
72
73     result = CryptAcquireContextA(
74         &hProv, NULL, MS_DEF_DSS_PROV_A, PROV_DSS, CRYPT_VERIFYCONTEXT);
75     if(!result)
76     {
77         skip("DSS csp is currently not available, skipping tests.\n");
78         return;
79     }
80     ok(result, "Expected no errors.\n");
81
82     result = CryptReleaseContext(hProv, 0);
83     ok(result, "Expected release of the provider.\n");
84
85     result = CryptAcquireContextA(
86         &hProv, NULL, MS_DEF_DSS_DH_PROV_A, PROV_DSS_DH, CRYPT_NEWKEYSET);
87     ok(result, "Expected no errors.\n");
88
89     result = CryptReleaseContext(hProv, 0);
90     ok(result, "Expected release of the provider.\n");
91
92     result = CryptAcquireContextA(&hProv, NULL, NULL, PROV_DSS, 0);
93     ok(result, "Expected no errors.\n");
94
95     result = CryptReleaseContext(hProv, 0);
96     ok(result, "Expected release of the provider.\n");
97
98     result = CryptAcquireContextA(&hProv, NULL, MS_DEF_DSS_PROV_A, PROV_DSS, 0);
99     ok(result, "Expected no errors.\n");
100
101     /* test DSS Diffie Hellman provider (PROV_DSS_DH) */
102
103     result = CryptAcquireContextA(
104         &hProv, NULL, MS_DEF_DSS_DH_PROV, PROV_DSS_DH, CRYPT_VERIFYCONTEXT);
105     ok(result, "Expected no errors.\n");
106
107     result = CryptReleaseContext(hProv, 0);
108     ok(result, "Expected release of the provider.\n");
109
110     result = CryptAcquireContextA(&hProv, NULL, NULL, PROV_DSS_DH, 0);
111     ok(result, "Expected no errors.\n");
112
113     result = CryptReleaseContext(hProv, 0);
114     ok(result, "Expected release of the provider.\n");
115
116     result = CryptAcquireContextA(&hProv, NULL, MS_DEF_DSS_DH_PROV, PROV_DSS_DH, 0);
117     ok(result, "Expected no errors.\n");
118
119     /* test DSS Enhanced provider (MS_ENH_DSS_DH_PROV) */
120
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)
125     {
126         win_skip("DSSENH and Schannel provider is broken on WinNT4\n");
127         return;
128     }
129     ok(result, "Expected no errors.\n");
130
131     result = CryptReleaseContext(hProv, 0);
132     ok(result, "Expected release of the provider.\n");
133
134     result = CryptAcquireContextA(&hProv, NULL, MS_ENH_DSS_DH_PROV, PROV_DSS_DH, 0);
135     ok(result, "Expected no errors.\n");
136
137     result = CryptReleaseContext(hProv, 0);
138     ok(result, "Expected release of the provider.\n");
139
140     /* test DSS Schannel provider (PROV_DH_SCHANNEL) */
141
142     result = CryptAcquireContextA(
143         &hProv, NULL, MS_DEF_DH_SCHANNEL_PROV, PROV_DH_SCHANNEL, CRYPT_VERIFYCONTEXT);
144     ok(result, "Expected no errors.\n");
145
146     result = CryptReleaseContext(hProv, 0);
147     ok(result, "Expected release of the provider.\n");
148
149     result = CryptAcquireContextA(&hProv, NULL, NULL, PROV_DH_SCHANNEL, 0);
150     ok(result, "Expected no errors.\n");
151
152     result = CryptReleaseContext(hProv, 0);
153     ok(result, "Expected release of the provider.\n");
154
155     result = CryptAcquireContextA(
156         &hProv, NULL, MS_DEF_DH_SCHANNEL_PROV, PROV_DH_SCHANNEL, 0);
157     ok(result, "Expected no errors.\n");
158
159     result = CryptReleaseContext(hProv, 0);
160     ok(result, "Expected release of the provider.\n");
161
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());
168
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());
174
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());
180 }
181
182 START_TEST(dssenh)
183 {
184     test_acquire_context();
185 }