ReactOS 0.4.16-dev-2491-g3dc6630
crypt.c
Go to the documentation of this file.
1/* Unit test suite for wintrust crypt functions
2 *
3 * Copyright 2007 Paul Vriens
4 * Copyright 2008 Hans Leidekker for CodeWeavers
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
22#include <stdarg.h>
23#include <stdio.h>
24
25#include "windows.h"
26#include "wincrypt.h"
27#include "mscat.h"
28
29#include "wine/test.h"
30
31static char selfname[MAX_PATH];
35
36static const WCHAR hashmeW[] = {'h','a','s','h','m','e',0};
37static const WCHAR attr1W[] = {'a','t','t','r','1',0};
38static const WCHAR attr2W[] = {'a','t','t','r','2',0};
39
40/*
41 * Minimalistic catalog file. To reconstruct, save text below as winetest.cdf,
42 * convert to DOS line endings and run 'makecat /cat winetest.cdf'
43 */
44
45/*
46[CatalogHeader]
47Name=winetest.cat
48ResultDir=.\
49PublicVersion=0x00000001
50EncodingType=
51CATATTR1=0x10010001:attr1:value1
52CATATTR2=0x10010001:attr2:value2
53
54[CatalogFiles]
55hashme=.\winetest.cdf
56*/
57
58static const CHAR test_cdf[] =
59 "[CatalogHeader]\r\n"
60 "Name=winetest.cat\r\n"
61 "ResultDir=.\\\r\n"
62 "PublicVersion=0x00000001\r\n"
63 "EncodingType=\r\n"
64 "CATATTR1=0x10010001:attr1:value1\r\n"
65 "CATATTR2=0x10010001:attr2:value2\r\n"
66 "\r\n"
67 "[CatalogFiles]\r\n"
68 "hashme=.\\winetest.cdf\r\n";
69
70static const BYTE test_catalog[] = {
71 0x30, 0x82, 0x01, 0xbc, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0,
72 0x82, 0x01, 0xad, 0x30, 0x82, 0x01, 0xa9, 0x02, 0x01, 0x01, 0x31, 0x00, 0x30, 0x82, 0x01, 0x9e,
73 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0a, 0x01, 0xa0, 0x82, 0x01, 0x8f, 0x30,
74 0x82, 0x01, 0x8b, 0x30, 0x0c, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x01,
75 0x01, 0x04, 0x10, 0xfa, 0x55, 0x2c, 0xc2, 0xf6, 0xcc, 0xdd, 0x11, 0x2a, 0x9c, 0x00, 0x14, 0x22,
76 0xec, 0x8f, 0x3b, 0x17, 0x0d, 0x30, 0x38, 0x31, 0x32, 0x31, 0x38, 0x31, 0x31, 0x32, 0x36, 0x34,
77 0x38, 0x5a, 0x30, 0x0e, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x01, 0x02,
78 0x05, 0x00, 0x30, 0x81, 0xdd, 0x30, 0x81, 0xda, 0x04, 0x0e, 0x68, 0x00, 0x61, 0x00, 0x73, 0x00,
79 0x68, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x00, 0x00, 0x31, 0x81, 0xc7, 0x30, 0x61, 0x06, 0x0a, 0x2b,
80 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x04, 0x31, 0x53, 0x30, 0x51, 0x30, 0x2c, 0x06,
81 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x19, 0xa2, 0x1e, 0x80, 0x1c, 0x00,
82 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x4f, 0x00, 0x62, 0x00, 0x73, 0x00, 0x6f, 0x00, 0x6c, 0x00,
83 0x65, 0x00, 0x74, 0x00, 0x65, 0x00, 0x3e, 0x00, 0x3e, 0x00, 0x3e, 0x30, 0x21, 0x30, 0x09, 0x06,
84 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14, 0xed, 0xd6, 0x9c, 0x9c, 0xb2, 0xfc,
85 0xaa, 0x03, 0xe8, 0xd3, 0x20, 0xf6, 0xab, 0x28, 0xc3, 0xff, 0xbd, 0x07, 0x36, 0xf5, 0x30, 0x62,
86 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x02, 0x02, 0x31, 0x54, 0x30, 0x52,
87 0x1e, 0x4c, 0x00, 0x7b, 0x00, 0x44, 0x00, 0x45, 0x00, 0x33, 0x00, 0x35, 0x00, 0x31, 0x00, 0x41,
88 0x00, 0x34, 0x00, 0x32, 0x00, 0x2d, 0x00, 0x38, 0x00, 0x45, 0x00, 0x35, 0x00, 0x39, 0x00, 0x2d,
89 0x00, 0x31, 0x00, 0x31, 0x00, 0x44, 0x00, 0x30, 0x00, 0x2d, 0x00, 0x38, 0x00, 0x43, 0x00, 0x34,
90 0x00, 0x37, 0x00, 0x2d, 0x00, 0x30, 0x00, 0x30, 0x00, 0x43, 0x00, 0x30, 0x00, 0x34, 0x00, 0x46,
91 0x00, 0x43, 0x00, 0x32, 0x00, 0x39, 0x00, 0x35, 0x00, 0x45, 0x00, 0x45, 0x00, 0x7d, 0x02, 0x02,
92 0x02, 0x00, 0xa0, 0x6a, 0x30, 0x68, 0x30, 0x32, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82,
93 0x37, 0x0c, 0x02, 0x01, 0x04, 0x24, 0x30, 0x22, 0x1e, 0x0a, 0x00, 0x61, 0x00, 0x74, 0x00, 0x74,
94 0x00, 0x72, 0x00, 0x32, 0x02, 0x04, 0x10, 0x01, 0x00, 0x01, 0x04, 0x0e, 0x76, 0x00, 0x61, 0x00,
95 0x6c, 0x00, 0x75, 0x00, 0x65, 0x00, 0x32, 0x00, 0x00, 0x00, 0x30, 0x32, 0x06, 0x0a, 0x2b, 0x06,
96 0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x02, 0x01, 0x04, 0x24, 0x30, 0x22, 0x1e, 0x0a, 0x00, 0x61,
97 0x00, 0x74, 0x00, 0x74, 0x00, 0x72, 0x00, 0x31, 0x02, 0x04, 0x10, 0x01, 0x00, 0x01, 0x04, 0x0e,
98 0x76, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x75, 0x00, 0x65, 0x00, 0x31, 0x00, 0x00, 0x00, 0x31, 0x00,
99};
100
101static BOOL (WINAPI * pCryptCATAdminAcquireContext)(HCATADMIN*, const GUID*, DWORD);
102static BOOL (WINAPI * pCryptCATAdminAcquireContext2)(HCATADMIN*, const GUID*, const WCHAR *, const CERT_STRONG_SIGN_PARA *, DWORD);
103static BOOL (WINAPI * pCryptCATAdminReleaseContext)(HCATADMIN, DWORD);
104static BOOL (WINAPI * pCryptCATAdminCalcHashFromFileHandle)(HANDLE hFile, DWORD*, BYTE*, DWORD);
105static BOOL (WINAPI * pCryptCATAdminCalcHashFromFileHandle2)(HCATADMIN, HANDLE hFile, DWORD*, BYTE*, DWORD);
106static HCATINFO (WINAPI * pCryptCATAdminAddCatalog)(HCATADMIN, PWSTR, PWSTR, DWORD);
107static BOOL (WINAPI * pCryptCATAdminRemoveCatalog)(HCATADMIN, LPCWSTR, DWORD);
108static BOOL (WINAPI * pCryptCATAdminReleaseCatalogContext)(HCATADMIN, HCATINFO, DWORD);
109static HANDLE (WINAPI * pCryptCATOpen)(LPWSTR, DWORD, HCRYPTPROV, DWORD, DWORD);
110static BOOL (WINAPI * pCryptCATCatalogInfoFromContext)(HCATINFO, CATALOG_INFO *, DWORD);
111static BOOL (WINAPI * pCryptCATCDFClose)(CRYPTCATCDF *);
114static LPWSTR (WINAPI * pCryptCATCDFEnumMembersByCDFTagEx)(CRYPTCATCDF *, LPWSTR, PFN_CDF_PARSE_ERROR_CALLBACK,
120static BOOL (WINAPI * pCryptCATClose)(HANDLE);
123
124static void InitFunctionPtrs(void)
125{
126 HMODULE hWintrust = GetModuleHandleA("wintrust.dll");
127
128#define WINTRUST_GET_PROC(func) \
129 p ## func = (void*)GetProcAddress(hWintrust, #func); \
130 if(!p ## func) { \
131 trace("GetProcAddress(%s) failed\n", #func); \
132 }
133
152
153#undef WINTRUST_GET_PROC
154
155 pGetSignedDataMsg = (void*)GetProcAddress(hWintrust, "CryptSIPGetSignedDataMsg");
157 trace("GetProcAddress(CryptSIPGetSignedDataMsg) failed\n");
158
159 pPutSignedDataMsg = (void*)GetProcAddress(hWintrust, "CryptSIPPutSignedDataMsg");
161 trace("GetProcAddress(CryptSIPPutSignedDataMsg) failed\n");
162}
163
164static GUID dummy = {0xdeadbeef,0xdead,0xbeef,{0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
165
166static void test_context(void)
167{
168 BOOL ret;
169 HCATADMIN hca;
170 static GUID unknown = { 0xC689AABA, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }}; /* WINTRUST.DLL */
171 static const WCHAR unknown_alg[] = {'A', 'L', 'G', '-', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\0'};
172 CHAR dummydir[MAX_PATH];
173 DWORD attrs;
174
175 /* When CryptCATAdminAcquireContext is successful it will create
176 * several directories if they don't exist:
177 *
178 * ...\system32\CatRoot\{GUID}, this directory holds the .cat files
179 * ...\system32\CatRoot2\{GUID} (WinXP and up), here we find the catalog database for that GUID
180 *
181 * Windows Vista uses lowercase catroot and catroot2.
182 *
183 * When passed a NULL GUID it will create the following directories although on
184 * WinXP and up these directories are already present when Windows is installed:
185 *
186 * ...\system32\CatRoot\{127D0A1D-4EF2-11D1-8608-00C04FC295EE}
187 * ...\system32\CatRoot2\{127D0A1D-4EF2-11D1-8608-00C04FC295EE} (WinXP up)
188 *
189 * TODO: Find out what this GUID is/does.
190 *
191 * On WinXP and up there is also a TimeStamp file in some of directories that
192 * seem to indicate the last change to the catalog database for that GUID.
193 *
194 * On Windows 2000 some files are created/updated:
195 *
196 * ...\system32\CatRoot\SYSMAST.cbk
197 * ...\system32\CatRoot\SYSMAST.cbd
198 * ...\system32\CatRoot\{GUID}\CATMAST.cbk
199 * ...\system32\CatRoot\{GUID}\CATMAST.cbd
200 *
201 */
202
203 /* All NULL */
204 SetLastError(0xdeadbeef);
205 ret = pCryptCATAdminAcquireContext(NULL, NULL, 0);
206 ok(!ret, "Expected failure\n");
208 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
209
210 /* NULL GUID */
211 if (0) { /* crashes on 64-bit win10 */
212 ret = pCryptCATAdminAcquireContext(&hca, NULL, 0);
213 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
214 ok(hca != NULL, "Expected a context handle, got NULL\n");
215
216 /* Proper release */
217 SetLastError(0xdeadbeef);
218 ret = pCryptCATAdminReleaseContext(hca, 0);
219 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
220
221 /* Try to release a second time */
222 SetLastError(0xdeadbeef);
223 ret = pCryptCATAdminReleaseContext(hca, 0);
224 ok(!ret, "Expected failure\n");
226 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
227 }
228
229 /* All NULL */
230 SetLastError(0xdeadbeef);
231 ret = pCryptCATAdminReleaseContext(NULL, 0);
232 ok(!ret, "Expected failure\n");
234 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
235
236 /* NULL context handle and dummy GUID */
237 SetLastError(0xdeadbeef);
238 ret = pCryptCATAdminAcquireContext(NULL, &dummy, 0);
239 ok(!ret, "Expected failure\n");
241 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
242
243 /* Correct context handle and dummy GUID
244 *
245 * The tests run in the past unfortunately made sure that some directories were created.
246 *
247 * FIXME:
248 * We don't want to mess too much with these for now so we should delete only the ones
249 * that shouldn't be there like the deadbeef ones. We first have to figure out if it's
250 * safe to remove files and directories from CatRoot/CatRoot2.
251 */
252
253 ret = pCryptCATAdminAcquireContext(&hca, &dummy, 0);
254 ok(ret || GetLastError() == ERROR_ACCESS_DENIED, "CryptCATAdminAcquireContext failed %lu\n", GetLastError());
256 {
257 win_skip("Not running as administrator\n");
258 return;
259 }
260 ok(hca != NULL, "Expected a context handle, got NULL\n");
261
263 ok(attrs != INVALID_FILE_ATTRIBUTES, "Expected the CatRoot directory to exist\n");
264
265 /* Windows creates the GUID directory in capitals */
266 lstrcpyA(dummydir, catroot);
267 lstrcatA(dummydir, "\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}");
268 attrs = GetFileAttributesA(dummydir);
270 "Expected CatRoot\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF} directory to exist\n");
271
272 /* Only present on XP or higher. */
274 if (attrs != INVALID_FILE_ATTRIBUTES)
275 {
276 lstrcpyA(dummydir, catroot2);
277 lstrcatA(dummydir, "\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}");
278 attrs = GetFileAttributesA(dummydir);
280 "Expected CatRoot2\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF} directory to exist\n");
281 }
282
283 ret = pCryptCATAdminReleaseContext(hca, 0);
284 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
285
286 /* Correct context handle and GUID */
287 ret = pCryptCATAdminAcquireContext(&hca, &unknown, 0);
288 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
289 ok(hca != NULL, "Expected a context handle, got NULL\n");
290
291 ret = pCryptCATAdminReleaseContext(hca, 0);
292 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
293
294 hca = (void *) 0xdeadbeef;
295 SetLastError(0xdeadbeef);
296 /* Flags is documented as unused, but the parameter is checked since win8 */
297 ret = pCryptCATAdminAcquireContext(&hca, &unknown, 1);
298 ok((!ret && (GetLastError() == ERROR_INVALID_PARAMETER) && (hca == (void *) 0xdeadbeef)) ||
299 broken(ret && hca != NULL && hca != (void *) 0xdeadbeef),
300 "Expected FALSE and ERROR_INVALID_PARAMETER with untouched handle, got %d and %lu with %p\n",
301 ret, GetLastError(), hca);
302
303 if (ret && hca)
304 {
305 SetLastError(0xdeadbeef);
306 ret = pCryptCATAdminReleaseContext(hca, 0);
307 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
308 }
309
310 /* Specify SHA-1 algorithm */
311 ret = pCryptCATAdminAcquireContext2(&hca, &unknown, BCRYPT_SHA1_ALGORITHM, NULL, 0);
312 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
313 ok(hca != NULL, "Expected a context handle, got NULL\n");
314
315 ret = pCryptCATAdminReleaseContext(hca, 0);
316 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
317
318 /* Specify SHA-256 algorithm */
319 ret = pCryptCATAdminAcquireContext2(&hca, &unknown, BCRYPT_SHA256_ALGORITHM, NULL, 0);
320 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
321 ok(hca != NULL, "Expected a context handle, got NULL\n");
322
323 ret = pCryptCATAdminReleaseContext(hca, 0);
324 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
325
326 /* Set unknown algorithm - should return failure */
327 ret = pCryptCATAdminAcquireContext2(&hca, &unknown, unknown_alg, NULL, 0);
328 ok(!ret, "Expected failure\n");
329 ok(GetLastError() == NTE_BAD_ALGID, "Expected NTE_BAD_ALGID, got %ld\n", GetLastError());
330
331}
332
333/* TODO: Check whether SHA-1 is the algorithm that's always used */
334static void test_calchash(void)
335{
336 BOOL ret;
337 HCATADMIN hca_sha1, hca_sha256;
338 HANDLE file;
339 DWORD hashsize = 0;
340 BYTE* hash;
341 BYTE expectedhash[20] = {0x3a,0xa1,0x19,0x08,0xec,0xa6,0x0d,0x2e,0x7e,0xcc,0x7a,0xca,0xf5,0xb8,0x2e,0x62,0x6a,0xda,0xf0,0x19};
342 BYTE expectedhash_sha256[32] = { 0x8a, 0xfd, 0x8c, 0xec, 0xdd, 0xe3, 0x0b, 0xaa, 0x2f, 0x1c, 0x3f, 0x61, 0xaf, 0xdf, 0x24, 0x84, 0x99, 0x8b, 0xe3, 0xcf, 0xda, 0xff, 0x0c, 0x5e, 0xa8, 0x68, 0xe8, 0xea, 0x94, 0x1e, 0x90, 0xe2};
344 DWORD written;
345
346 /* All NULL */
347 SetLastError(0xdeadbeef);
348 ret = pCryptCATAdminCalcHashFromFileHandle(NULL, NULL, NULL, 0);
349 ok(!ret, "Expected failure\n");
351 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
352
353 /* NULL filehandle, rest is legal */
354 SetLastError(0xdeadbeef);
355 ret = pCryptCATAdminCalcHashFromFileHandle(NULL, &hashsize, NULL, 0);
356 ok(!ret, "Expected failure\n");
358 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
359
360 /* Correct filehandle, rest is NULL */
362 SetLastError(0xdeadbeef);
363 ret = pCryptCATAdminCalcHashFromFileHandle(file, NULL, NULL, 0);
364 ok(!ret, "Expected failure\n");
366 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
368
369 /* Correct catadmin, rest is NULL */
370 ret = pCryptCATAdminAcquireContext2(&hca_sha1, NULL, BCRYPT_SHA1_ALGORITHM, NULL, 0);
371 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
372
373 ret = pCryptCATAdminCalcHashFromFileHandle2(hca_sha1, NULL, NULL, NULL, 0);
374 ok(!ret, "Expected failure\n");
376 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
377
378 /* All OK, but dwFlags set to 1 */
380 SetLastError(0xdeadbeef);
381 ret = pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, NULL, 1);
382 ok(!ret, "Expected failure\n");
384 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
386
387 /* All OK, requesting the size of the hash */
389 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed %lu\n", GetLastError());
390 SetLastError(0xdeadbeef);
391 ret = pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, NULL, 0);
392 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
393 ok(hashsize == 20," Expected a hash size of 20, got %ld\n", hashsize);
395 "Expected ERROR_INSUFFICIENT_BUFFER, got %ld\n", GetLastError());
397
398 /* All OK, retrieve the hash
399 * Double the hash buffer to see what happens to the size parameter
400 */
402 hashsize *= 2;
403 hash = HeapAlloc(GetProcessHeap(), 0, hashsize);
404 SetLastError(0xdeadbeef);
405 ret = pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, hash, 0);
406 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
407 ok(hashsize == 20," Expected a hash size of 20, got %ld\n", hashsize);
409 "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
412
413 /* Do the same test with a file created and filled by ourselves (and we thus
414 * have a known hash for).
415 */
416 GetTempFileNameA(CURR_DIR, "hsh", 0, temp);
418 WriteFile(file, "Text in this file is needed to create a know hash", 49, &written, NULL);
420
421 /* All OK, first request the size and then retrieve the hash */
423 hashsize = 0;
424 pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, NULL, 0);
425 hash = HeapAlloc(GetProcessHeap(), 0, hashsize);
426 SetLastError(0xdeadbeef);
427 ret = pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, hash, 0);
428 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
430 "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
431 ok(hashsize == sizeof(expectedhash) &&
432 !memcmp(hash, expectedhash, sizeof(expectedhash)),
433 "Hashes didn't match\n");
436
437 /* Calculate hash with SHA-1 specified as algorithm */
439 SetLastError(0xdeadbeef);
440 hashsize = 0;
441 ret = pCryptCATAdminCalcHashFromFileHandle2(hca_sha1, file, &hashsize, NULL, 0);
442 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
443 ok(hashsize == 20," Expected a hash size of 20, got %ld\n", hashsize);
445 "Expected ERROR_INSUFFICIENT_BUFFER, got %ld\n", GetLastError());
446 hash = HeapAlloc(GetProcessHeap(), 0, hashsize);
447 SetLastError(0xdeadbeef);
448 ret = pCryptCATAdminCalcHashFromFileHandle2(hca_sha1, file, &hashsize, hash, 0);
449 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
450 ok(hashsize == 20," Expected a hash size of 20, got %ld\n", hashsize);
452 "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
455
456 /* Check SHA1-hash for file with known hash */
458 hashsize = 0;
459 pCryptCATAdminCalcHashFromFileHandle2(hca_sha1, file, &hashsize, NULL, 0);
460 hash = HeapAlloc(GetProcessHeap(), 0, hashsize);
461 SetLastError(0xdeadbeef);
462 ret = pCryptCATAdminCalcHashFromFileHandle2(hca_sha1, file, &hashsize, hash, 0);
463 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
465 "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
466 ok(hashsize == sizeof(expectedhash) &&
467 !memcmp(hash, expectedhash, sizeof(expectedhash)),
468 "Hashes didn't match\n");
471 pCryptCATAdminReleaseContext(hca_sha1, 0);
472
473 /* Calculate hash with SHA-256 specified as algorithm */
474 ret = pCryptCATAdminAcquireContext2(&hca_sha256, NULL, BCRYPT_SHA256_ALGORITHM, NULL, 0);
475 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
477 hashsize = 0;
478 ret = pCryptCATAdminCalcHashFromFileHandle2(hca_sha256, file, &hashsize, NULL, 0);
479 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
480 ok(hashsize == 32," Expected a hash size of 32, got %ld\n", hashsize);
482 "Expected ERROR_INSUFFICIENT_BUFFER, got %ld\n", GetLastError());
483 hash = HeapAlloc(GetProcessHeap(), 0, hashsize);
484 SetLastError(0xdeadbeef);
485 ret = pCryptCATAdminCalcHashFromFileHandle2(hca_sha256, file, &hashsize, hash, 0);
486 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
487 ok(hashsize == 32," Expected a hash size of 32, got %ld\n", hashsize);
489 "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
492
493 /* All OK, first request the size and then retrieve the SHA256 hash */
494 /* Check SHA256-hash for file with known hash */
496 hashsize = 0;
497 ret = pCryptCATAdminCalcHashFromFileHandle2(hca_sha256, file, &hashsize, NULL, 0);
498 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
499 hash = HeapAlloc(GetProcessHeap(), 0, hashsize);
500 SetLastError(0xdeadbeef);
501 ret = pCryptCATAdminCalcHashFromFileHandle2(hca_sha256, file, &hashsize, hash, 0);
502 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
504 "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
505 ok(hashsize == sizeof(expectedhash_sha256) &&
506 !memcmp(hash, expectedhash_sha256, sizeof(expectedhash_sha256)),
507 "Hashes didn't match\n");
510 pCryptCATAdminReleaseContext(hca_sha256, 0);
512}
513
514static void test_CryptCATOpen(void)
515{
517 HANDLE cat;
518 DWORD flags;
519 BOOL ret;
520 FILE *file;
521 char buffer[10];
522
525
526 SetLastError(0xdeadbeef);
527 cat = pCryptCATOpen(NULL, 0, 0, 0, 0);
528 ok(cat == INVALID_HANDLE_VALUE, "expected failure\n");
529 ok(GetLastError() == ERROR_INVALID_PARAMETER, "got error %lu\n", GetLastError());
530
531 for (flags = 0; flags < 8; ++flags)
532 {
533 SetLastError(0xdeadbeef);
534 cat = pCryptCATOpen(filename, flags, 0, 0, 0);
536 {
537 ok(cat == INVALID_HANDLE_VALUE, "flags %#lx: expected failure\n", flags);
538 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "flags %#lx: got error %lu\n", flags, GetLastError());
540 ok(!ret, "flags %#lx: expected failure\n", flags);
541 }
542 else
543 {
544 ok(cat != INVALID_HANDLE_VALUE, "flags %#lx: expected success\n", flags);
545 ok(!GetLastError(), "flags %#lx: got error %lu\n", flags, GetLastError());
546 ret = pCryptCATClose(cat);
547 ok(ret, "flags %#lx: failed to close file\n", flags);
549 ok(ret, "flags %#lx: failed to delete file, error %lu\n", flags, GetLastError());
550 }
551
552 file = _wfopen(filename, L"w");
553 fputs("test text", file);
554 fclose(file);
555
556 SetLastError(0xdeadbeef);
557 cat = pCryptCATOpen(filename, flags, 0, 0, 0);
558 ok(cat != INVALID_HANDLE_VALUE, "flags %#lx: expected success\n", flags);
559 ok(!GetLastError(), "flags %#lx: got error %lu\n", flags, GetLastError());
560 ret = pCryptCATClose(cat);
561 ok(ret, "flags %#lx: failed to close file\n", flags);
562
563 file = _wfopen(filename, L"r");
564 ret = fread(buffer, 1, sizeof(buffer), file);
566 ok(!ret, "flags %#lx: got %s\n", flags, debugstr_an(buffer, ret));
567 else
568 ok(ret == 9 && !strncmp(buffer, "test text", ret), "flags %#lx: got %s\n", flags, debugstr_an(buffer, ret));
569 fclose(file);
570
572 ok(ret, "flags %#lx: failed to delete file, error %lu\n", flags, GetLastError());
573 }
574}
575
578
580{
581 ok(error_area != -2, "Didn't expect cdf_callback() to be called (%08lx, %08lx)\n",
582 area, error);
583
586}
587
588static void test_CryptCATCDF_params(void)
589{
590 static WCHAR nonexistent[] = {'d','e','a','d','b','e','e','f','.','c','d','f',0};
591 CRYPTCATCDF *catcdf;
592 BOOL ret;
593
594 if (!pCryptCATCDFOpen)
595 {
596 win_skip("CryptCATCDFOpen is not available\n");
597 return;
598 }
599
600 SetLastError(0xdeadbeef);
601 catcdf = pCryptCATCDFOpen(NULL, NULL);
602 ok(catcdf == NULL, "CryptCATCDFOpen succeeded\n");
604 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
605
606 SetLastError(0xdeadbeef);
608 ok(catcdf == NULL, "CryptCATCDFOpen succeeded\n");
610 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
611
612 /* File doesn't exist */
613 SetLastError(0xdeadbeef);
615 ok(catcdf == NULL, "CryptCATCDFOpen succeeded\n");
617 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
618
619 SetLastError(0xdeadbeef);
620 ret = pCryptCATCDFClose(NULL);
621 ok(!ret, "Expected failure\n");
623 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
624
625 catcdf = NULL;
626 SetLastError(0xdeadbeef);
627 ret = pCryptCATCDFClose(catcdf);
628 ok(!ret, "Expected failure\n");
630 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
631}
632
633/* FIXME: Once Wine can create catalog files we should use the created catalog file in this test */
635{
636 static WCHAR basenameW[] = {'w','i','n','e','t','e','s','t','.','c','a','t',0};
637 static const char basename[] = "winetest.cat";
638 HCATADMIN hcatadmin;
639 HCATINFO hcatinfo;
641 WCHAR tmpfileW[MAX_PATH];
642 char tmpfile[MAX_PATH];
643 char catfile[MAX_PATH], catfilepath[MAX_PATH], *p;
644 WCHAR catfileW[MAX_PATH];
645 HANDLE file;
646 DWORD error, written;
647 BOOL ret;
648 DWORD attrs;
649
650 if (!pCryptCATAdminRemoveCatalog)
651 {
652 /* NT4 and W2K do have CryptCATAdminAddCatalog !! */
653 win_skip("CryptCATAdminRemoveCatalog is not available\n");
654 return;
655 }
656
657 if (!GetTempFileNameA(CURR_DIR, "cat", 0, tmpfile)) return;
660 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %lu\n", GetLastError());
662
663 ret = pCryptCATAdminAcquireContext(&hcatadmin, &dummy, 0);
664 ok(ret || GetLastError() == ERROR_ACCESS_DENIED, "CryptCATAdminAcquireContext failed %lu\n", GetLastError());
666 {
667 win_skip("Not running as administrator\n");
668 return;
669 }
670
671 SetLastError(0xdeadbeef);
672 hcatinfo = pCryptCATAdminAddCatalog(NULL, NULL, NULL, 0);
674 ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n");
675 ok(error == ERROR_INVALID_PARAMETER, "got %lu expected ERROR_INVALID_PARAMETER\n", GetLastError());
676
677 SetLastError(0xdeadbeef);
678 hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, NULL, NULL, 0);
680 ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n");
681 ok(error == ERROR_INVALID_PARAMETER, "got %lu expected ERROR_INVALID_PARAMETER\n", GetLastError());
682
683 MultiByteToWideChar(CP_ACP, 0, tmpfile, -1, tmpfileW, MAX_PATH);
684
685 SetLastError(0xdeadbeef);
686 hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, basenameW, 0);
688 todo_wine {
689 ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n");
690 ok(error == ERROR_BAD_FORMAT, "got %lu expected ERROR_BAD_FORMAT\n", GetLastError());
691 }
692 if (hcatinfo != NULL)
693 pCryptCATAdminReleaseCatalogContext(hcatadmin, hcatinfo, 0);
694
695 SetLastError(0xdeadbeef);
696 hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, basenameW, 1);
698 ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n");
700 error == ERROR_BAD_FORMAT, /* win 8 */
701 "got %lu\n", GetLastError());
702
703 SetLastError(0xdeadbeef);
704 hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, NULL, 0);
706 ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n");
707 todo_wine ok(error == ERROR_BAD_FORMAT, "got %lu expected ERROR_BAD_FORMAT\n", GetLastError());
708
711 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %lu\n", GetLastError());
712 WriteFile(file, test_catalog, sizeof(test_catalog), &written, NULL);
714
715 /* Unique name will be created */
716 hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, NULL, 0);
717 if (!hcatinfo && (GetLastError() == ERROR_ACCESS_DENIED))
718 {
719 win_skip("Not enough rights\n");
720 goto cleanup;
721 }
722 todo_wine ok(hcatinfo != NULL, "CryptCATAdminAddCatalog failed %lu\n", GetLastError());
723
724 info.cbStruct = sizeof(info);
725 info.wszCatalogFile[0] = 0;
726 ret = pCryptCATCatalogInfoFromContext(hcatinfo, &info, 0);
728 {
729 ok(ret, "CryptCATCatalogInfoFromContext failed %lu\n", GetLastError());
730 ok(info.wszCatalogFile[0] != 0, "Expected a filename\n");
731 }
732 WideCharToMultiByte(CP_ACP, 0, info.wszCatalogFile, -1, catfile, MAX_PATH, NULL, NULL);
733 if ((p = strrchr(catfile, '\\'))) p++;
734 memset(catfileW, 0, sizeof(catfileW));
735 MultiByteToWideChar(CP_ACP, 0, p, -1, catfileW, MAX_PATH);
736
737 /* Set the file attributes so we can check what happens with them during the 'copy' */
740 ok(ret, "SetFileAttributesA failed : %lu\n", GetLastError());
741
742 /* winetest.cat will be created */
743 hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, basenameW, 0);
744 ok(hcatinfo != NULL, "CryptCATAdminAddCatalog failed %lu\n", GetLastError());
745
746 lstrcpyA(catfilepath, catroot);
747 lstrcatA(catfilepath, "\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}\\winetest.cat");
748 attrs = GetFileAttributesA(catfilepath);
749 ok(attrs != INVALID_FILE_ATTRIBUTES, "Expected %s to exist\n", catfilepath);
751 ok(attrs == FILE_ATTRIBUTE_SYSTEM ||
753 "File has wrong attributes : %08lx\n", attrs);
754
755 info.cbStruct = sizeof(info);
756 info.wszCatalogFile[0] = 0;
757 ret = pCryptCATCatalogInfoFromContext(hcatinfo, &info, 0);
758 ok(ret, "CryptCATCatalogInfoFromContext failed %lu\n", GetLastError());
759 ok(info.wszCatalogFile[0] != 0, "Expected a filename\n");
760 WideCharToMultiByte(CP_ACP, 0, info.wszCatalogFile, -1, catfile, MAX_PATH, NULL, NULL);
761 if ((p = strrchr(catfile, '\\'))) p++;
762 ok(!lstrcmpA(basename, p), "Expected %s, got %s\n", basename, p);
763
764 ret = pCryptCATAdminReleaseCatalogContext(hcatadmin, hcatinfo, 0);
765 ok(ret, "CryptCATAdminReleaseCatalogContext failed %lu\n", GetLastError());
766
767 /* Remove the catalog file with the unique name */
768 ret = pCryptCATAdminRemoveCatalog(hcatadmin, catfileW, 0);
769 ok(ret, "CryptCATAdminRemoveCatalog failed %lu\n", GetLastError());
770
771 /* Remove the winetest.cat catalog file, first with the full path. This should not succeed
772 * according to MSDN */
773 ret = pCryptCATAdminRemoveCatalog(hcatadmin, info.wszCatalogFile, 0);
774 ok(ret, "CryptCATAdminRemoveCatalog failed %lu\n", GetLastError());
775 /* The call succeeded with the full path but the file is not removed */
776 attrs = GetFileAttributesA(catfilepath);
777 ok(attrs != INVALID_FILE_ATTRIBUTES, "Expected %s to exist\n", catfilepath);
778 /* Given only the filename the file is removed */
779 ret = pCryptCATAdminRemoveCatalog(hcatadmin, basenameW, 0);
780 ok(ret, "CryptCATAdminRemoveCatalog failed %lu\n", GetLastError());
781 attrs = GetFileAttributesA(catfilepath);
782 ok(attrs == INVALID_FILE_ATTRIBUTES, "Expected %s to be removed\n", catfilepath);
783
784cleanup:
785 ret = pCryptCATAdminReleaseContext(hcatadmin, 0);
786 ok(ret, "CryptCATAdminReleaseContext failed %lu\n", GetLastError());
787
788 /* Set the attributes so we can delete the file */
789 attrs = FILE_ATTRIBUTE_NORMAL;
791 ok(ret, "SetFileAttributesA failed %lu\n", GetLastError());
793}
794
795static void test_catalog_properties(const char *catfile, int attributes, int members)
796{
797 static const GUID subject = {0xde351a42,0x8e59,0x11d0,{0x8c,0x47,0x00,0xc0,0x4f,0xc2,0x95,0xee}};
798
799 HANDLE hcat;
802 char catalog[MAX_PATH];
803 WCHAR catalogW[MAX_PATH];
804 DWORD attrs;
805 BOOL ret;
806 int attrcount = 0, membercount = 0;
807
808 /* FIXME: Wine can't create catalog files out of catalog definition files yet. Remove this piece
809 * once wine is fixed
810 */
811 attrs = GetFileAttributesA(catfile);
812 if (attrs == INVALID_FILE_ATTRIBUTES)
813 {
814 HANDLE file;
815 DWORD written;
816
817 trace("Creating the catalog file\n");
818 if (!GetTempFileNameA(CURR_DIR, "cat", 0, catalog)) return;
820 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %lu\n", GetLastError());
821 WriteFile(file, test_catalog, sizeof(test_catalog), &written, NULL);
823
824 attributes = 2;
825 members = 1;
826 MultiByteToWideChar(CP_ACP, 0, catalog, -1, catalogW, MAX_PATH);
827 }
828 else
829 {
830 MultiByteToWideChar(CP_ACP, 0, catfile, -1, catalogW, MAX_PATH);
831 catalog[0] = 0;
832 }
833
834 hcat = pCryptCATOpen(catalogW, 0, 0, 0, 0);
835 if (hcat == INVALID_HANDLE_VALUE && members == 0)
836 {
837 win_skip("CryptCATOpen on W2K can't handle catalog files with no members\n");
838 return;
839 }
840 ok(hcat != INVALID_HANDLE_VALUE, "CryptCATOpen failed %lu\n", GetLastError());
841
843 ok(m == NULL, "CryptCATEnumerateMember succeeded\n");
844
845 m = NULL;
846 while ((m = pCryptCATEnumerateMember(hcat, m)))
847 {
848 ok(m->cbStruct == sizeof(CRYPTCATMEMBER), "unexpected size %lu\n", m->cbStruct);
849 todo_wine ok(!lstrcmpW(m->pwszReferenceTag, hashmeW), "unexpected tag\n");
850 ok(!memcmp(&m->gSubjectType, &subject, sizeof(subject)), "guid differs\n");
851 ok(!m->fdwMemberFlags, "got %lx expected 0\n", m->fdwMemberFlags);
852 ok(m->dwCertVersion == 0x200, "got %lx expected 0x200\n", m->dwCertVersion);
853 ok(!m->dwReserved, "got %lx expected 0\n", m->dwReserved);
854 ok(m->hReserved == NULL, "got %p expected NULL\n", m->hReserved);
855
857 ok(attr == NULL, "CryptCATEnumerateAttr succeeded\n");
858
859 membercount++;
860 }
861 ok(membercount == members, "Expected %d members, got %d\n", members, membercount);
862
864 ok(attr == NULL, "CryptCATEnumerateAttr succeeded\n");
865
867 ok(attr == NULL, "CryptCATEnumerateAttr succeeded\n");
868
869 attr = NULL;
870 while ((attr = pCryptCATEnumerateCatAttr(hcat, attr)))
871 {
872 ok(!lstrcmpW(attr->pwszReferenceTag, attr1W) ||
873 !lstrcmpW(attr->pwszReferenceTag, attr2W),
874 "Expected 'attr1' or 'attr2'\n");
875
876 attrcount++;
877 }
879 ok(attrcount == attributes, "Expected %d catalog attributes, got %d\n", attributes, attrcount);
880
881 ret = pCryptCATClose(hcat);
882 ok(ret, "CryptCATClose failed\n");
883 if (catalog[0]) DeleteFileA( catalog );
884}
885
887{
888 static const char catfileA[] = "winetest.cat";
889 static const char cdffileA[] = "winetest.cdf";
890 static WCHAR cdffileW[] = {'w','i','n','e','t','e','s','t','.','c','d','f',0};
891 CRYPTCATCDF *catcdf;
892 CRYPTCATATTRIBUTE *catattr;
893 CRYPTCATMEMBER *catmember;
894 WCHAR *catmembertag;
895 DWORD written, attrs;
896 HANDLE file;
897 BOOL ret;
898 int attrcount, membercount;
899
900 if (!pCryptCATCDFOpen)
901 {
902 win_skip("CryptCATCDFOpen is not available\n");
903 return;
904 }
905
906 /* Create the cdf file */
908 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %lu\n", GetLastError());
909 WriteFile(file, test_cdf, sizeof(test_cdf) - 1, &written, NULL);
911
912 /* Don't enumerate attributes and members */
913 trace("No attribs and members\n");
914 SetLastError(0xdeadbeef);
915 catcdf = pCryptCATCDFOpen(cdffileW, NULL);
917 {
918 ok(catcdf != NULL, "CryptCATCDFOpen failed\n");
919 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
920 }
921
922 ret = pCryptCATCDFClose(catcdf);
924 {
925 ok(ret, "Expected success, got FALSE with %ld\n", GetLastError());
926 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
927 }
928
929 attrs = GetFileAttributesA(catfileA);
931 ok(attrs != INVALID_FILE_ATTRIBUTES, "Expected the catalog file to exist\n");
932
933 test_catalog_properties(catfileA, 0, 0);
934 DeleteFileA(catfileA);
935
936 /* Only enumerate the attributes */
937 trace("Only attributes\n");
938 attrcount = 0;
939 catcdf = pCryptCATCDFOpen(cdffileW, NULL);
940
941 catattr = NULL;
942 while ((catattr = pCryptCATCDFEnumCatAttributes(catcdf, catattr, NULL)))
943 {
944 ok(!lstrcmpW(catattr->pwszReferenceTag, attr1W) ||
945 !lstrcmpW(catattr->pwszReferenceTag, attr2W),
946 "Expected 'attr1' or 'attr2'\n");
947
948 attrcount++;
949 }
951 ok(attrcount == 2, "Expected 2 attributes, got %d\n", attrcount);
952
953 pCryptCATCDFClose(catcdf);
954 /* Even though the resulting catalog file shows the attributes, they will not be enumerated */
955 test_catalog_properties(catfileA, 0, 0);
956 DeleteFileA(catfileA);
957
958 /* Only enumerate the members */
959 trace("Only members\n");
960 membercount = 0;
961 catcdf = pCryptCATCDFOpen(cdffileW, NULL);
962
963 catmember = NULL;
964 catmembertag = NULL;
965 while ((catmembertag = pCryptCATCDFEnumMembersByCDFTagEx(catcdf, catmembertag, NULL, &catmember, FALSE, NULL)))
966 {
967 ok(!lstrcmpW(catmembertag, hashmeW), "Expected 'hashme'\n");
968 membercount++;
969 }
971 ok(membercount == 1, "Expected 1 member, got %d\n", membercount);
972
973 pCryptCATCDFClose(catcdf);
974 test_catalog_properties(catfileA, 0, 1);
975 DeleteFileA(catfileA);
976
977 /* Enumerate members and attributes */
978 trace("Attributes and members\n");
979 attrcount = membercount = 0;
980 catcdf = pCryptCATCDFOpen(cdffileW, NULL);
981
982 catattr = NULL;
983 while ((catattr = pCryptCATCDFEnumCatAttributes(catcdf, catattr, NULL)))
984 attrcount++;
986 ok(attrcount == 2, "Expected 2 attributes, got %d\n", attrcount);
987
988 catmember = NULL;
989 catmembertag = NULL;
990 while ((catmembertag = pCryptCATCDFEnumMembersByCDFTagEx(catcdf, catmembertag, NULL, &catmember, FALSE, NULL)))
991 membercount++;
993 ok(membercount == 1, "Expected 1 member, got %d\n", membercount);
994
995 pCryptCATCDFClose(catcdf);
996 test_catalog_properties(catfileA, 2, 1);
997 DeleteFileA(catfileA);
998
999 DeleteFileA(cdffileA);
1000}
1001
1002static void create_cdf_file(const CHAR *filename, const CHAR *contents)
1003{
1004 HANDLE file;
1005 DWORD written;
1006
1008 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %lu\n", GetLastError());
1011}
1012
1013#define CHECK_EXPECT(a, b) \
1014 do { \
1015 ok(a == error_area, "Expected %08x, got %08lx\n", a, error_area); \
1016 ok(b == local_error, "Expected %08x, got %08lx\n", b, local_error); \
1017 } while (0)
1018
1019/* Clear the variables (can't use 0) */
1020#define CLEAR_EXPECT \
1021 error_area = local_error = -1
1022
1023/* Set both variables so the callback routine can check if a call to it was unexpected */
1024#define SET_UNEXPECTED \
1025 error_area = local_error = -2
1026
1027static void test_cdf_parsing(void)
1028{
1029 static const char catfileA[] = "tempfile.cat";
1030 static const char cdffileA[] = "tempfile.cdf";
1031 static WCHAR cdffileW[] = {'t','e','m','p','f','i','l','e','.','c','d','f',0};
1032 CHAR cdf_contents[4096];
1033 CRYPTCATCDF *catcdf;
1034 CRYPTCATATTRIBUTE *catattr;
1035 CRYPTCATMEMBER *catmember;
1036 WCHAR *catmembertag;
1037
1038 if (!pCryptCATCDFOpen)
1039 {
1040 win_skip("CryptCATCDFOpen is not available\n");
1041 return;
1042 }
1043
1044 /* Empty file */
1045 DeleteFileA(cdffileA);
1046 create_cdf_file(cdffileA, "");
1047
1049 SetLastError(0xdeadbeef);
1050 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback);
1051 todo_wine
1053 ok(catcdf == NULL, "CryptCATCDFOpen succeeded\n");
1054 todo_wine
1055 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
1056 DeleteFileA(cdffileA);
1057 ok(!DeleteFileA(catfileA), "Didn't expect a catalog file to be created\n");
1058
1059 /* Just the header */
1060 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n");
1061 create_cdf_file(cdffileA, cdf_contents);
1062
1064 SetLastError(0xdeadbeef);
1065 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback);
1066 ok(catcdf == NULL, "CryptCATCDFOpen succeeded\n");
1067 todo_wine
1069 "Expected ERROR_SHARING_VIOLATION, got %ld\n", GetLastError());
1070 DeleteFileA(cdffileA);
1071
1072 /* Header and member only */
1073 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n");
1074 lstrcatA(cdf_contents, "[CatalogFiles]\r\n");
1075 lstrcatA(cdf_contents, "hashme=.\\tempfile.cdf\r\n");
1076 create_cdf_file(cdffileA, cdf_contents);
1077
1079 SetLastError(0xdeadbeef);
1080 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback);
1081 ok(catcdf == NULL, "CryptCATCDFOpen succeeded\n");
1082 todo_wine
1084 "Expected ERROR_SHARING_VIOLATION, got %ld\n", GetLastError());
1085 DeleteFileA(cdffileA);
1086 ok(!DeleteFileA(catfileA), "Didn't expect a catalog file to be created\n");
1087
1088 /* Header and Name (no value) */
1089 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n");
1090 lstrcatA(cdf_contents, "Name=\r\n");
1091 create_cdf_file(cdffileA, cdf_contents);
1092
1094 SetLastError(0xdeadbeef);
1095 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback);
1096 ok(catcdf == NULL, "CryptCATCDFOpen succeeded\n");
1097 todo_wine
1099 "Expected ERROR_SHARING_VIOLATION, got %ld\n", GetLastError());
1100 DeleteFileA(cdffileA);
1101 ok(!DeleteFileA(catfileA), "Didn't expect a catalog file to be created\n");
1102
1103 /* Header and Name */
1104 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n");
1105 lstrcatA(cdf_contents, "Name=tempfile.cat\r\n");
1106 create_cdf_file(cdffileA, cdf_contents);
1107
1109 SetLastError(0xdeadbeef);
1110 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback);
1111 todo_wine
1112 {
1113 ok(catcdf != NULL, "CryptCATCDFOpen failed\n");
1114 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
1115 }
1116 pCryptCATCDFClose(catcdf);
1117 DeleteFileA(cdffileA);
1118 todo_wine
1119 ok(DeleteFileA(catfileA), "Expected a catalog file to be created\n");
1120
1121 /* Header and nonexistent member */
1122 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n");
1123 lstrcatA(cdf_contents, "Name=tempfile.cat\r\n");
1124 lstrcatA(cdf_contents, "[CatalogFiles]\r\n");
1125 lstrcatA(cdf_contents, "hashme=.\\deadbeef.cdf\r\n");
1126 create_cdf_file(cdffileA, cdf_contents);
1127
1129 SetLastError(0xdeadbeef);
1130 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback);
1131 todo_wine
1132 {
1133 ok(catcdf != NULL, "CryptCATCDFOpen failed\n");
1134 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
1135 }
1136 /* Loop through the members */
1138 catmember = NULL;
1139 catmembertag = NULL;
1140 while ((catmembertag = pCryptCATCDFEnumMembersByCDFTagEx(catcdf, catmembertag, cdf_callback, &catmember, FALSE, NULL))) ;
1141 todo_wine
1143 pCryptCATCDFClose(catcdf);
1144 DeleteFileA(cdffileA);
1145 todo_wine
1146 ok(DeleteFileA(catfileA), "Expected a catalog file to be created\n");
1147
1148 /* Header, correct member but no explicit newline */
1149 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n");
1150 lstrcatA(cdf_contents, "Name=tempfile.cat\r\n");
1151 lstrcatA(cdf_contents, "[CatalogFiles]\r\n");
1152 lstrcatA(cdf_contents, "hashme=.\\tempfile.cdf\r");
1153 create_cdf_file(cdffileA, cdf_contents);
1154
1156 SetLastError(0xdeadbeef);
1157 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback);
1158 todo_wine
1159 {
1160 ok(catcdf != NULL, "CryptCATCDFOpen failed\n");
1161 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
1162 }
1163 /* Loop through the members */
1165 catmember = NULL;
1166 catmembertag = NULL;
1167 while ((catmembertag = pCryptCATCDFEnumMembersByCDFTagEx(catcdf, catmembertag, cdf_callback, &catmember, FALSE, NULL))) ;
1168 ok(error_area == 0xffffffff || broken(error_area == CRYPTCAT_E_AREA_MEMBER) /* < win81 */,
1169 "Expected area 0xffffffff, got %08lx\n", error_area);
1170 ok(local_error == 0xffffffff || broken(local_error == CRYPTCAT_E_CDF_MEMBER_FILE_PATH) /* < win81 */,
1171 "Expected error 0xffffffff, got %08lx\n", local_error);
1172
1173 pCryptCATCDFClose(catcdf);
1174 DeleteFileA(cdffileA);
1175 todo_wine
1176 ok(DeleteFileA(catfileA), "Expected a catalog file to be created\n");
1177
1178 /* Header and 2 duplicate members */
1179 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n");
1180 lstrcatA(cdf_contents, "Name=tempfile.cat\r\n");
1181 lstrcatA(cdf_contents, "[CatalogFiles]\r\n");
1182 lstrcatA(cdf_contents, "hashme=.\\tempfile.cdf\r\n");
1183 lstrcatA(cdf_contents, "hashme=.\\tempfile.cdf\r\n");
1184 create_cdf_file(cdffileA, cdf_contents);
1185
1187 SetLastError(0xdeadbeef);
1188 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback);
1189 todo_wine
1190 {
1191 ok(catcdf != NULL, "CryptCATCDFOpen failed\n");
1192 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
1193 }
1194 /* Loop through the members */
1196 catmember = NULL;
1197 catmembertag = NULL;
1198 while ((catmembertag = pCryptCATCDFEnumMembersByCDFTagEx(catcdf, catmembertag, cdf_callback, &catmember, FALSE, NULL))) ;
1199 pCryptCATCDFClose(catcdf);
1200 test_catalog_properties(catfileA, 0, 1);
1201 DeleteFileA(cdffileA);
1202 todo_wine
1203 ok(DeleteFileA(catfileA), "Expected a catalog file to be created\n");
1204
1205 /* Wrong attribute */
1206 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n");
1207 lstrcatA(cdf_contents, "Name=tempfile.cat\r\n");
1208 lstrcatA(cdf_contents, "CATATTR1=0x10010001:attr1\r\n");
1209 create_cdf_file(cdffileA, cdf_contents);
1210
1212 SetLastError(0xdeadbeef);
1213 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback);
1214 todo_wine
1215 {
1216 ok(catcdf != NULL, "CryptCATCDFOpen failed\n");
1217 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
1218 }
1219 /* Loop through the attributes */
1221 catattr = NULL;
1222 while ((catattr = pCryptCATCDFEnumCatAttributes(catcdf, catattr, cdf_callback))) ;
1223 todo_wine
1225 pCryptCATCDFClose(catcdf);
1226 DeleteFileA(cdffileA);
1227 todo_wine
1228 ok(DeleteFileA(catfileA), "Expected a catalog file to be created\n");
1229
1230 /* Two identical attributes */
1231 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n");
1232 lstrcatA(cdf_contents, "Name=tempfile.cat\r\n");
1233 lstrcatA(cdf_contents, "CATATTR1=0x10010001:attr1:value1\r\n");
1234 lstrcatA(cdf_contents, "CATATTR1=0x10010001:attr1:value1\r\n");
1235 lstrcatA(cdf_contents, "[CatalogFiles]\r\n");
1236 lstrcatA(cdf_contents, "hashme=.\\tempfile.cdf\r\n");
1237 create_cdf_file(cdffileA, cdf_contents);
1238
1240 SetLastError(0xdeadbeef);
1241 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback);
1242 todo_wine
1243 {
1244 ok(catcdf != NULL, "CryptCATCDFOpen failed\n");
1245 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
1246 }
1247 /* Loop through the members */
1249 catmember = NULL;
1250 catmembertag = NULL;
1251 while ((catmembertag = pCryptCATCDFEnumMembersByCDFTagEx(catcdf, catmembertag, cdf_callback, &catmember, FALSE, NULL))) ;
1252 /* Loop through the attributes */
1254 catattr = NULL;
1255 while ((catattr = pCryptCATCDFEnumCatAttributes(catcdf, catattr, cdf_callback))) ;
1256 pCryptCATCDFClose(catcdf);
1257 test_catalog_properties(catfileA, 1, 1);
1258 DeleteFileA(cdffileA);
1259 todo_wine
1260 ok(DeleteFileA(catfileA), "Expected a catalog file to be created\n");
1261
1262 /* Two different attribute values with the same tag */
1263 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n");
1264 lstrcatA(cdf_contents, "Name=tempfile.cat\r\n");
1265 lstrcatA(cdf_contents, "CATATTR1=0x10010001:attr1:value1\r\n");
1266 lstrcatA(cdf_contents, "CATATTR1=0x10010001:attr2:value2\r\n");
1267 lstrcatA(cdf_contents, "[CatalogFiles]\r\n");
1268 lstrcatA(cdf_contents, "hashme=.\\tempfile.cdf\r\n");
1269 create_cdf_file(cdffileA, cdf_contents);
1270
1272 SetLastError(0xdeadbeef);
1273 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback);
1274 todo_wine
1275 {
1276 ok(catcdf != NULL, "CryptCATCDFOpen failed\n");
1277 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", GetLastError());
1278 }
1279 /* Loop through the members */
1281 catmember = NULL;
1282 catmembertag = NULL;
1283 while ((catmembertag = pCryptCATCDFEnumMembersByCDFTagEx(catcdf, catmembertag, cdf_callback, &catmember, FALSE, NULL))) ;
1284 /* Loop through the attributes */
1286 catattr = NULL;
1287 while ((catattr = pCryptCATCDFEnumCatAttributes(catcdf, catattr, cdf_callback))) ;
1288 pCryptCATCDFClose(catcdf);
1289 test_catalog_properties(catfileA, 1, 1);
1290 DeleteFileA(cdffileA);
1291 todo_wine
1292 ok(DeleteFileA(catfileA), "Expected a catalog file to be created\n");
1293}
1294
1295static const struct
1296{
1297 WORD e_magic; /* 00: MZ Header signature */
1299 DWORD e_lfanew; /* 3c: Offset to extended header */
1300} dos_header =
1301{
1302 IMAGE_DOS_SIGNATURE, { 0 }, sizeof(dos_header)
1304
1306{
1307 IMAGE_NT_SIGNATURE, /* Signature */
1308 {
1309 IMAGE_FILE_MACHINE_I386, /* Machine */
1310 1, /* NumberOfSections */
1311 0, /* TimeDateStamp */
1312 0, /* PointerToSymbolTable */
1313 0, /* NumberOfSymbols */
1314 sizeof(IMAGE_OPTIONAL_HEADER), /* SizeOfOptionalHeader */
1315 IMAGE_FILE_EXECUTABLE_IMAGE /* Characteristics */
1316 },
1317 {
1318 IMAGE_NT_OPTIONAL_HDR_MAGIC, /* Magic */
1319 2, /* MajorLinkerVersion */
1320 15, /* MinorLinkerVersion */
1321 0, /* SizeOfCode */
1322 0, /* SizeOfInitializedData */
1323 0, /* SizeOfUninitializedData */
1324 0, /* AddressOfEntryPoint */
1325 0x10, /* BaseOfCode, also serves as e_lfanew in the truncated MZ header */
1326#ifndef _WIN64
1327 0, /* BaseOfData */
1328#endif
1329 0x10000000, /* ImageBase */
1330 0, /* SectionAlignment */
1331 0, /* FileAlignment */
1332 4, /* MajorOperatingSystemVersion */
1333 0, /* MinorOperatingSystemVersion */
1334 1, /* MajorImageVersion */
1335 0, /* MinorImageVersion */
1336 4, /* MajorSubsystemVersion */
1337 0, /* MinorSubsystemVersion */
1338 0, /* Win32VersionValue */
1339 0x200, /* SizeOfImage */
1340 sizeof(dos_header) + sizeof(nt_header), /* SizeOfHeaders */
1341 0, /* CheckSum */
1342 IMAGE_SUBSYSTEM_WINDOWS_CUI, /* Subsystem */
1343 0, /* DllCharacteristics */
1344 0, /* SizeOfStackReserve */
1345 0, /* SizeOfStackCommit */
1346 0, /* SizeOfHeapReserve */
1347 3, /* SizeOfHeapCommit */
1348 2, /* LoaderFlags */
1349 1, /* NumberOfRvaAndSizes */
1350 { { 0 } } /* DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES] */
1351 }
1352};
1353
1354static void test_sip(void)
1355{
1356 static const WCHAR nameW[] = {'t','e','s','t','.','e','x','e',0};
1358 DWORD index, encoding, size;
1359 HANDLE file;
1360 GUID guid;
1361 BOOL ret;
1362 char buf[1024];
1363
1365 ok(file != INVALID_HANDLE_VALUE, "can't create file\n");
1367 return;
1369 WriteFile(file, &nt_header, sizeof(nt_header), &size, NULL);
1370 memset(buf, 0, sizeof(buf));
1371 WriteFile(file, buf, 0x200 - sizeof(dos_header) - sizeof(nt_header), &size, NULL);
1373
1375 ok(file != INVALID_HANDLE_VALUE, "can't open file\n");
1376
1377 memset(&info, 0, sizeof(SIP_SUBJECTINFO));
1378 info.cbSize = sizeof(SIP_SUBJECTINFO);
1379 info.pgSubjectType = &guid;
1380 ret = CryptSIPRetrieveSubjectGuid(NULL, file, info.pgSubjectType);
1381 ok(ret, "CryptSIPRetrieveSubjectGuid failed (%lx)\n", GetLastError());
1382
1384 ok(!ret, "CryptSIPPutSignedDataMsg succeeded\n");
1385 index = GetLastError();
1386 ok(index == ERROR_PATH_NOT_FOUND, "GetLastError returned %lx\n", index);
1387
1388 info.hFile = file;
1389 info.pwsFileName = nameW;
1391 ok(!ret, "CryptSIPPutSignedDataMsg succeeded\n");
1392 index = GetLastError();
1393 todo_wine ok(index == ERROR_INVALID_PARAMETER, "GetLastError returned %lx\n", index);
1394
1395 info.hFile = INVALID_HANDLE_VALUE;
1396 info.pwsFileName = nameW;
1398 ok(!ret, "CryptSIPPutSignedDataMsg succeeded\n");
1399 index = GetLastError();
1400 ok(index == ERROR_SHARING_VIOLATION, "GetLastError returned %lx\n", index);
1401
1404
1405 info.hFile = file;
1406 info.pwsFileName = (void*)0xdeadbeef;
1408 ok(ret, "CryptSIPPutSignedDataMsg failed (%lx)\n", GetLastError());
1409 ok(index == 0, "index = %lx\n", index);
1410
1413
1414 info.hFile = INVALID_HANDLE_VALUE;
1415 info.pwsFileName = nameW;
1416 ret = pPutSignedDataMsg(&info, X509_ASN_ENCODING, &index, 14, (BYTE*)"longer message");
1417 ok(ret, "CryptSIPPutSignedDataMsg failed (%lx)\n", GetLastError());
1418 ok(index == 1, "index = %lx\n", index);
1419
1420 size = 0;
1421 encoding = 0xdeadbeef;
1422 ret = pGetSignedDataMsg(&info, &encoding, 0, &size, NULL);
1423 ok(ret, "CryptSIPGetSignedDataMsg failed (%lx)\n", GetLastError());
1424 ok(encoding == 0xdeadbeef, "encoding = %lx\n", encoding);
1425 ok(size == 16, "size = %ld\n", size);
1426
1427 ret = pGetSignedDataMsg(&info, &encoding, 0, &size, (BYTE*)buf);
1428 ok(ret, "CryptSIPGetSignedDataMsg failed (%lx)\n", GetLastError());
1429 ok(encoding == (X509_ASN_ENCODING|PKCS_7_ASN_ENCODING), "encoding = %lx\n", encoding);
1430 ok(size == 8, "size = %ld\n", size);
1431 ok(!memcmp(buf, "test\0\0\0\0", 8), "buf = %s\n", buf);
1432
1433 size = 0;
1434 encoding = 0xdeadbeef;
1435 ret = pGetSignedDataMsg(&info, &encoding, 1, &size, NULL);
1436 ok(ret, "CryptSIPGetSignedDataMsg failed (%lx)\n", GetLastError());
1437 ok(encoding == 0xdeadbeef, "encoding = %lx\n", encoding);
1438 ok(size == 24, "size = %ld\n", size);
1439
1440 ret = pGetSignedDataMsg(&info, &encoding, 1, &size, (BYTE*)buf);
1441 ok(ret, "CryptSIPGetSignedDataMsg failed (%lx)\n", GetLastError());
1442 ok(encoding == (X509_ASN_ENCODING|PKCS_7_ASN_ENCODING), "encoding = %lx\n", encoding);
1443 ok(size == 16, "size = %ld\n", size);
1444 ok(!strcmp(buf, "longer message"), "buf = %s\n", buf);
1445
1446 CryptReleaseContext(info.hProv, 0);
1449}
1450
1452{
1453 char** myARGV;
1454 char sysdir[MAX_PATH];
1455
1457
1458 if (!pCryptCATAdminAcquireContext)
1459 {
1460 win_skip("CryptCATAdmin functions are not available\n");
1461 return;
1462 }
1463
1465 lstrcpyA(catroot, sysdir);
1466 lstrcatA(catroot, "\\CatRoot");
1467 lstrcpyA(catroot2, sysdir);
1468 lstrcatA(catroot2, "\\CatRoot2");
1469
1471 strcpy(selfname, myARGV[0]);
1472
1474
1475 test_context();
1476 test_calchash();
1478 /* Parameter checking only */
1480 /* Test the parsing of a cdf file */
1482 /* Create a catalog file out of our own catalog definition file */
1485 test_sip();
1486}
static LPSTR * myARGV
Definition: FindFiles.c:30
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define broken(x)
Definition: atltest.h:178
#define START_TEST(x)
Definition: atltest.h:75
static const WCHAR nameW[]
Definition: main.c:49
#define index(s, c)
Definition: various.h:29
#define ARRAY_SIZE(A)
Definition: main.h:20
#define BCRYPT_SHA256_ALGORITHM
Definition: bcrypt.h:75
#define BCRYPT_SHA1_ALGORITHM
Definition: bcrypt.h:74
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
BOOL WINAPI CryptReleaseContext(HCRYPTPROV hProv, DWORD dwFlags)
Definition: crypt.c:661
BOOL WINAPI CryptSIPRetrieveSubjectGuid(LPCWSTR FileName, HANDLE hFileIn, GUID *pgSubject)
Definition: sip.c:310
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:109
#define OPEN_EXISTING
Definition: compat.h:775
#define SetLastError(x)
Definition: compat.h:752
#define GetProcAddress(x, y)
Definition: compat.h:753
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
static __inline const char * debugstr_an(const char *s, int n)
Definition: compat.h:55
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define WideCharToMultiByte
Definition: compat.h:111
#define MultiByteToWideChar
Definition: compat.h:110
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define FILE_SHARE_READ
Definition: compat.h:136
static void cleanup(void)
Definition: main.c:1335
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI SetFileAttributesA(LPCSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:760
DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName)
Definition: fileinfo.c:620
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
DWORD WINAPI GetCurrentDirectoryA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2065
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:1999
UINT WINAPI GetSystemDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2202
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
int WINAPI lstrcmpA(LPCSTR str1, LPCSTR str2)
Definition: locale.c:4104
GUID guid
Definition: version.c:147
static void basename(LPCWSTR path, LPWSTR name)
Definition: profile.c:38
int CDECL fclose(FILE *file)
Definition: file.c:3757
size_t CDECL fread(void *ptr, size_t size, size_t nmemb, FILE *file)
Definition: file.c:4406
FILE *CDECL _wfopen(const wchar_t *path, const wchar_t *mode)
Definition: file.c:4335
int CDECL fputs(const char *s, FILE *file)
Definition: file.c:4769
FILE *CDECL tmpfile(void)
Definition: file.c:5199
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3319
_ACRTIMP int __cdecl strncmp(const char *, const char *, size_t)
Definition: string.c:3330
_ACRTIMP char *__cdecl strrchr(const char *, int)
Definition: string.c:3298
BOOL WINAPI CryptCATAdminReleaseContext(HCATADMIN hCatAdmin, DWORD dwFlags)
Definition: crypt.c:632
CRYPTCATCDF *WINAPI CryptCATCDFOpen(LPWSTR pwszFilePath, PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError)
Definition: crypt.c:1270
CRYPTCATATTRIBUTE *WINAPI CryptCATCDFEnumCatAttributes(CRYPTCATCDF *pCDF, CRYPTCATATTRIBUTE *pPrevAttr, PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError)
Definition: crypt.c:1244
BOOL WINAPI CryptCATClose(HANDLE hCatalog)
Definition: crypt.c:730
CRYPTCATMEMBER *WINAPI CryptCATEnumerateMember(HANDLE hCatalog, CRYPTCATMEMBER *prev)
Definition: crypt.c:841
BOOL WINAPI CryptCATCatalogInfoFromContext(HCATINFO hcatinfo, CATALOG_INFO *info, DWORD flags)
Definition: crypt.c:1023
BOOL WINAPI CryptCATAdminCalcHashFromFileHandle(HANDLE hFile, DWORD *pcbHash, BYTE *pbHash, DWORD dwFlags)
Definition: crypt.c:424
static const GUID unknown
Definition: crypt.c:1615
BOOL WINAPI CryptCATCDFClose(CRYPTCATCDF *pCDF)
Definition: crypt.c:1234
BOOL WINAPI CryptCATAdminAcquireContext2(HCATADMIN *catAdmin, const GUID *sys, const WCHAR *algorithm, const CERT_STRONG_SIGN_PARA *policy, DWORD dwFlags)
Definition: crypt.c:124
LPWSTR WINAPI CryptCATCDFEnumMembersByCDFTagEx(CRYPTCATCDF *pCDF, LPWSTR pwszPrevCDFTag, PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError, CRYPTCATMEMBER **ppMember, BOOL fContinueOnError, LPVOID pvReserved)
Definition: crypt.c:1256
BOOL WINAPI CryptCATAdminCalcHashFromFileHandle2(HCATADMIN catAdmin, HANDLE hFile, DWORD *pcbHash, BYTE *pbHash, DWORD dwFlags)
Definition: crypt.c:448
HCATINFO WINAPI CryptCATAdminAddCatalog(HCATADMIN catAdmin, PWSTR catalogFile, PWSTR selectBaseName, DWORD flags)
Definition: crypt.c:207
BOOL WINAPI CryptCATAdminReleaseCatalogContext(HCATADMIN hCatAdmin, HCATINFO hCatInfo, DWORD dwFlags)
Definition: crypt.c:598
BOOL WINAPI CryptCATAdminRemoveCatalog(HCATADMIN hCatAdmin, LPCWSTR pwszCatalogFile, DWORD dwFlags)
Definition: crypt.c:665
CRYPTCATATTRIBUTE *WINAPI CryptCATEnumerateCatAttr(HANDLE hCatalog, CRYPTCATATTRIBUTE *prev)
Definition: crypt.c:823
BOOL WINAPI CryptCATAdminAcquireContext(HCATADMIN *catAdmin, const GUID *sys, DWORD dwFlags)
Definition: crypt.c:101
CRYPTCATATTRIBUTE *WINAPI CryptCATEnumerateAttr(HANDLE hCatalog, CRYPTCATMEMBER *member, CRYPTCATATTRIBUTE *prev)
Definition: crypt.c:805
HANDLE WINAPI CryptCATOpen(WCHAR *filename, DWORD flags, HCRYPTPROV hProv, DWORD dwPublicVersion, DWORD dwEncodingType)
Definition: crypt.c:1092
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
UINT WINAPI GetTempFileNameA(IN LPCSTR lpPathName, IN LPCSTR lpPrefixString, IN UINT uUnique, OUT LPSTR lpTempFileName)
Definition: filename.c:26
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919
GLuint index
Definition: glext.h:6031
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLbitfield flags
Definition: glext.h:7161
GLfloat GLfloat p
Definition: glext.h:8902
const GLfloat * m
Definition: glext.h:10848
const char * filename
Definition: ioapi.h:137
LPSTR WINAPI lstrcpyA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:100
LPSTR WINAPI lstrcatA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:123
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
#define win_skip
Definition: minitest.h:67
#define todo_wine
Definition: minitest.h:80
#define error(str)
Definition: mkdosfs.c:1605
#define CREATE_ALWAYS
Definition: disk.h:72
#define CREATE_NEW
Definition: disk.h:69
#define OPEN_ALWAYS
Definition: disk.h:70
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static LPCWSTR
Definition: crypt.c:44
static const WCHAR nonexistent[]
Definition: font.c:33
static const char * contents
Definition: parser.c:511
static CHAR CURR_DIR[MAX_PATH]
Definition: crypt.c:32
DWORD e_lfanew
Definition: crypt.c:1299
WORD unused[29]
Definition: crypt.c:1298
static void test_CryptCATAdminAddRemoveCatalog(void)
Definition: crypt.c:634
static CHAR catroot2[MAX_PATH]
Definition: crypt.c:34
static pCryptSIPPutSignedDataMsg pPutSignedDataMsg
Definition: crypt.c:122
static void test_cdf_parsing(void)
Definition: crypt.c:1027
static DWORD local_error
Definition: crypt.c:577
static void test_catalog_properties(const char *catfile, int attributes, int members)
Definition: crypt.c:795
static const BYTE test_catalog[]
Definition: crypt.c:70
static IMAGE_NT_HEADERS nt_header
Definition: crypt.c:1305
static CHAR catroot[MAX_PATH]
Definition: crypt.c:33
static LPWSTR
Definition: crypt.c:114
static HCATINFO
Definition: crypt.c:108
#define WINTRUST_GET_PROC(func)
static CRYPTCATATTRIBUTE *WINAPI * pCryptCATEnumerateAttr(HANDLE, CRYPTCATMEMBER *, CRYPTCATATTRIBUTE *)
static DWORD error_area
Definition: crypt.c:576
static CRYPTCATMEMBER *WINAPI * pCryptCATEnumerateMember(HANDLE, CRYPTCATMEMBER *)
static void test_calchash(void)
Definition: crypt.c:334
static void test_context(void)
Definition: crypt.c:166
static pCryptSIPGetSignedDataMsg pGetSignedDataMsg
Definition: crypt.c:121
static const WCHAR attr2W[]
Definition: crypt.c:38
static void InitFunctionPtrs(void)
Definition: crypt.c:124
static const WCHAR attr1W[]
Definition: crypt.c:37
static void WINAPI cdf_callback(DWORD area, DWORD error, WCHAR *line)
Definition: crypt.c:579
static void test_CryptCATCDF_params(void)
Definition: crypt.c:588
static const WCHAR hashmeW[]
Definition: crypt.c:36
WORD e_magic
Definition: crypt.c:1297
static void test_CryptCATOpen(void)
Definition: crypt.c:514
static CRYPTCATCDF *WINAPI * pCryptCATCDFOpen(LPWSTR, PFN_CDF_PARSE_ERROR_CALLBACK)
static PWSTR
Definition: crypt.c:106
static const CHAR test_cdf[]
Definition: crypt.c:58
static HANDLE hFile
Definition: crypt.c:105
static CRYPTCATATTRIBUTE *WINAPI * pCryptCATCDFEnumCatAttributes(CRYPTCATCDF *, CRYPTCATATTRIBUTE *, PFN_CDF_PARSE_ERROR_CALLBACK)
#define CHECK_EXPECT(a, b)
Definition: crypt.c:1013
static const struct @1870 dos_header
#define SET_UNEXPECTED
Definition: crypt.c:1024
static CRYPTCATATTRIBUTE *WINAPI * pCryptCATEnumerateCatAttr(HANDLE, CRYPTCATATTRIBUTE *)
static CRYPTCATMEMBER LPVOID
Definition: crypt.c:115
static void test_sip(void)
Definition: crypt.c:1354
static char selfname[MAX_PATH]
Definition: crypt.c:31
#define CLEAR_EXPECT
Definition: crypt.c:1020
static void create_cdf_file(const CHAR *filename, const CHAR *contents)
Definition: crypt.c:1002
static void test_create_catalog_file(void)
Definition: crypt.c:886
#define CRYPTCAT_E_CDF_TAGNOTFOUND
Definition: mscat.h:56
#define CRYPTCAT_E_AREA_ATTRIBUTE
Definition: mscat.h:52
#define CRYPTCAT_OPEN_CREATENEW
Definition: mscat.h:40
#define CRYPTCAT_E_CDF_MEMBER_FILENOTFOUND
Definition: mscat.h:60
#define CRYPTCAT_E_AREA_MEMBER
Definition: mscat.h:51
#define CRYPTCAT_E_AREA_HEADER
Definition: mscat.h:50
#define CRYPTCAT_E_CDF_MEMBER_FILE_PATH
Definition: mscat.h:58
#define CRYPTCAT_E_CDF_ATTR_TOOFEWVALUES
Definition: mscat.h:63
void(WINAPI * PFN_CDF_PARSE_ERROR_CALLBACK)(DWORD, DWORD, WCHAR *)
Definition: mscat.h:115
HANDLE HCATADMIN
Definition: mscat.h:24
#define CRYPTCAT_OPEN_EXISTING
Definition: mscat.h:42
char temp_path[MAX_PATH]
Definition: mspatcha.c:123
BOOL(WINAPI * pCryptSIPGetSignedDataMsg)(SIP_SUBJECTINFO *, DWORD *, DWORD, DWORD *, BYTE *)
Definition: mssip.h:117
BOOL(WINAPI * pCryptSIPPutSignedDataMsg)(SIP_SUBJECTINFO *, DWORD, DWORD *, DWORD, BYTE *)
Definition: mssip.h:118
struct SIP_SUBJECTINFO_ SIP_SUBJECTINFO
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define FILE_ATTRIBUTE_SYSTEM
Definition: nt_native.h:704
#define BOOL
Definition: nt_native.h:43
#define DWORD
Definition: nt_native.h:44
#define GENERIC_WRITE
Definition: nt_native.h:90
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
Definition: ntifs_ex.h:384
#define IMAGE_SUBSYSTEM_WINDOWS_CUI
Definition: ntimage.h:438
#define IMAGE_NT_OPTIONAL_HDR_MAGIC
Definition: ntimage.h:387
#define IMAGE_FILE_EXECUTABLE_IMAGE
Definition: pedump.c:160
#define IMAGE_FILE_MACHINE_I386
Definition: pedump.c:174
struct _IMAGE_OPTIONAL_HEADER IMAGE_OPTIONAL_HEADER
#define IMAGE_NT_SIGNATURE
Definition: pedump.c:93
#define IMAGE_DOS_SIGNATURE
Definition: pedump.c:89
static Real area(Real A[2], Real B[2], Real C[2])
Definition: polyDBG.cc:50
static calc_node_t temp
Definition: rpn_ieee.c:38
strcpy
Definition: string.h:131
int winetest_get_mainargs(char ***pargv)
#define memset(x, y, z)
Definition: compat.h:39
LPWSTR pwszReferenceTag
Definition: mscat.h:74
Definition: cookie.c:202
Definition: fci.c:127
Definition: _hash_fun.h:40
Definition: parser.c:49
PVOID HANDLE
Definition: typedefs.h:73
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
ULONG_PTR HCRYPTPROV
Definition: wincrypt.h:55
#define X509_ASN_ENCODING
Definition: wincrypt.h:2501
#define PKCS_7_ASN_ENCODING
Definition: wincrypt.h:2503
#define WINAPI
Definition: msvc.h:6
#define ERROR_SHARING_VIOLATION
Definition: winerror.h:257
#define NTE_BAD_ALGID
Definition: winerror.h:4255
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:228
#define ERROR_BAD_FORMAT
Definition: winerror.h:236
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
char CHAR
Definition: xmlstorage.h:175
unsigned char BYTE
Definition: xxhash.c:193