wintrust/tests: Don't crash on NT4 and W2K.
[wine/multimedia.git] / dlls / wintrust / tests / crypt.c
blob99f30666fd8cb3048cc683a432a3dfc589c8decb
1 /* Unit test suite for wintrust crypt functions
3 * Copyright 2007 Paul Vriens
4 * Copyright 2008 Hans Leidekker for CodeWeavers
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
22 #include <stdarg.h>
23 #include <stdio.h>
25 #include "windows.h"
26 #include "mscat.h"
28 #include "wine/test.h"
30 static char selfname[MAX_PATH];
31 static CHAR CURR_DIR[MAX_PATH];
34 * Minimalistic catalog file. To reconstruct, save text below as winetest.cdf,
35 * convert to DOS line endings and run 'makecat /cat winetest.cdf'
39 [CatalogHeader]
40 Name=winetest.cat
41 ResultDir=.\
42 PublicVersion=0x00000001
43 EncodingType=
44 CATATTR1=0x10010001:attr1:value1
45 CATATTR2=0x10010001:attr2:value2
47 [CatalogFiles]
48 hashme=.\winetest.cdf
51 const BYTE test_catalog[] = {
52 0x30, 0x82, 0x01, 0xbc, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0,
53 0x82, 0x01, 0xad, 0x30, 0x82, 0x01, 0xa9, 0x02, 0x01, 0x01, 0x31, 0x00, 0x30, 0x82, 0x01, 0x9e,
54 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0a, 0x01, 0xa0, 0x82, 0x01, 0x8f, 0x30,
55 0x82, 0x01, 0x8b, 0x30, 0x0c, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x01,
56 0x01, 0x04, 0x10, 0xfa, 0x55, 0x2c, 0xc2, 0xf6, 0xcc, 0xdd, 0x11, 0x2a, 0x9c, 0x00, 0x14, 0x22,
57 0xec, 0x8f, 0x3b, 0x17, 0x0d, 0x30, 0x38, 0x31, 0x32, 0x31, 0x38, 0x31, 0x31, 0x32, 0x36, 0x34,
58 0x38, 0x5a, 0x30, 0x0e, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x01, 0x02,
59 0x05, 0x00, 0x30, 0x81, 0xdd, 0x30, 0x81, 0xda, 0x04, 0x0e, 0x68, 0x00, 0x61, 0x00, 0x73, 0x00,
60 0x68, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x00, 0x00, 0x31, 0x81, 0xc7, 0x30, 0x61, 0x06, 0x0a, 0x2b,
61 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x04, 0x31, 0x53, 0x30, 0x51, 0x30, 0x2c, 0x06,
62 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x19, 0xa2, 0x1e, 0x80, 0x1c, 0x00,
63 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x4f, 0x00, 0x62, 0x00, 0x73, 0x00, 0x6f, 0x00, 0x6c, 0x00,
64 0x65, 0x00, 0x74, 0x00, 0x65, 0x00, 0x3e, 0x00, 0x3e, 0x00, 0x3e, 0x30, 0x21, 0x30, 0x09, 0x06,
65 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14, 0xed, 0xd6, 0x9c, 0x9c, 0xb2, 0xfc,
66 0xaa, 0x03, 0xe8, 0xd3, 0x20, 0xf6, 0xab, 0x28, 0xc3, 0xff, 0xbd, 0x07, 0x36, 0xf5, 0x30, 0x62,
67 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x02, 0x02, 0x31, 0x54, 0x30, 0x52,
68 0x1e, 0x4c, 0x00, 0x7b, 0x00, 0x44, 0x00, 0x45, 0x00, 0x33, 0x00, 0x35, 0x00, 0x31, 0x00, 0x41,
69 0x00, 0x34, 0x00, 0x32, 0x00, 0x2d, 0x00, 0x38, 0x00, 0x45, 0x00, 0x35, 0x00, 0x39, 0x00, 0x2d,
70 0x00, 0x31, 0x00, 0x31, 0x00, 0x44, 0x00, 0x30, 0x00, 0x2d, 0x00, 0x38, 0x00, 0x43, 0x00, 0x34,
71 0x00, 0x37, 0x00, 0x2d, 0x00, 0x30, 0x00, 0x30, 0x00, 0x43, 0x00, 0x30, 0x00, 0x34, 0x00, 0x46,
72 0x00, 0x43, 0x00, 0x32, 0x00, 0x39, 0x00, 0x35, 0x00, 0x45, 0x00, 0x45, 0x00, 0x7d, 0x02, 0x02,
73 0x02, 0x00, 0xa0, 0x6a, 0x30, 0x68, 0x30, 0x32, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82,
74 0x37, 0x0c, 0x02, 0x01, 0x04, 0x24, 0x30, 0x22, 0x1e, 0x0a, 0x00, 0x61, 0x00, 0x74, 0x00, 0x74,
75 0x00, 0x72, 0x00, 0x32, 0x02, 0x04, 0x10, 0x01, 0x00, 0x01, 0x04, 0x0e, 0x76, 0x00, 0x61, 0x00,
76 0x6c, 0x00, 0x75, 0x00, 0x65, 0x00, 0x32, 0x00, 0x00, 0x00, 0x30, 0x32, 0x06, 0x0a, 0x2b, 0x06,
77 0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x02, 0x01, 0x04, 0x24, 0x30, 0x22, 0x1e, 0x0a, 0x00, 0x61,
78 0x00, 0x74, 0x00, 0x74, 0x00, 0x72, 0x00, 0x31, 0x02, 0x04, 0x10, 0x01, 0x00, 0x01, 0x04, 0x0e,
79 0x76, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x75, 0x00, 0x65, 0x00, 0x31, 0x00, 0x00, 0x00, 0x31, 0x00,
82 static BOOL (WINAPI * pCryptCATAdminAcquireContext)(HCATADMIN*, const GUID*, DWORD);
83 static BOOL (WINAPI * pCryptCATAdminReleaseContext)(HCATADMIN, DWORD);
84 static BOOL (WINAPI * pCryptCATAdminCalcHashFromFileHandle)(HANDLE hFile, DWORD*, BYTE*, DWORD);
85 static HCATINFO (WINAPI * pCryptCATAdminAddCatalog)(HCATADMIN, PWSTR, PWSTR, DWORD);
86 static BOOL (WINAPI * pCryptCATAdminRemoveCatalog)(HCATADMIN, LPCWSTR, DWORD);
87 static BOOL (WINAPI * pCryptCATAdminReleaseCatalogContext)(HCATADMIN, HCATINFO, DWORD);
89 static void InitFunctionPtrs(void)
91 HMODULE hWintrust = GetModuleHandleA("wintrust.dll");
93 #define WINTRUST_GET_PROC(func) \
94 p ## func = (void*)GetProcAddress(hWintrust, #func); \
95 if(!p ## func) { \
96 trace("GetProcAddress(%s) failed\n", #func); \
99 WINTRUST_GET_PROC(CryptCATAdminAcquireContext)
100 WINTRUST_GET_PROC(CryptCATAdminReleaseContext)
101 WINTRUST_GET_PROC(CryptCATAdminCalcHashFromFileHandle)
102 WINTRUST_GET_PROC(CryptCATAdminAddCatalog)
103 WINTRUST_GET_PROC(CryptCATAdminRemoveCatalog)
104 WINTRUST_GET_PROC(CryptCATAdminReleaseCatalogContext)
106 #undef WINTRUST_GET_PROC
109 static GUID dummy = {0xdeadbeef,0xdead,0xbeef,{0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
111 static void test_context(void)
113 BOOL ret;
114 HCATADMIN hca;
115 static GUID unknown = { 0xC689AABA, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }}; /* WINTRUST.DLL */
116 CHAR windir[MAX_PATH], catroot[MAX_PATH], catroot2[MAX_PATH], dummydir[MAX_PATH];
117 DWORD attrs;
119 /* When CryptCATAdminAcquireContext is successful it will create
120 * several directories if they don't exist:
122 * ...\system32\CatRoot\{GUID}, this directory holds the .cat files
123 * ...\system32\CatRoot2\{GUID} (WinXP and up), here we find the catalog database for that GUID
125 * Windows Vista uses lowercase catroot and catroot2.
127 * When passed a NULL GUID it will create the following directories although on
128 * WinXP and up these directories are already present when Windows is installed:
130 * ...\system32\CatRoot\{127D0A1D-4EF2-11D1-8608-00C04FC295EE}
131 * ...\system32\CatRoot2\{127D0A1D-4EF2-11D1-8608-00C04FC295EE} (WinXP up)
133 * TODO: Find out what this GUID is/does.
135 * On WinXP and up there is also a TimeStamp file in some of directories that
136 * seem to indicate the last change to the catalog database for that GUID.
138 * On Windows 2000 some files are created/updated:
140 * ...\system32\CatRoot\SYSMAST.cbk
141 * ...\system32\CatRoot\SYSMAST.cbd
142 * ...\system32\CatRoot\{GUID}\CATMAST.cbk
143 * ...\system32\CatRoot\{GUID}\CATMAST.cbd
147 /* All NULL */
148 SetLastError(0xdeadbeef);
149 ret = pCryptCATAdminAcquireContext(NULL, NULL, 0);
150 ok(!ret, "Expected failure\n");
151 ok(GetLastError() == ERROR_INVALID_PARAMETER,
152 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
154 /* NULL GUID */
155 ret = pCryptCATAdminAcquireContext(&hca, NULL, 0);
156 ok(ret, "Expected success\n");
157 ok(hca != NULL, "Expected a context handle, got NULL\n");
159 /* All NULL */
160 SetLastError(0xdeadbeef);
161 ret = pCryptCATAdminReleaseContext(NULL, 0);
162 ok(!ret, "Expected failure\n");
163 ok(GetLastError() == ERROR_INVALID_PARAMETER,
164 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
166 /* Proper release */
167 SetLastError(0xdeadbeef);
168 ret = pCryptCATAdminReleaseContext(hca, 0);
169 ok(ret, "Expected success\n");
170 ok(GetLastError() == 0xdeadbeef,
171 "Expected no change in last error, got %d\n", GetLastError());
173 /* Try to release a second time */
174 SetLastError(0xdeadbeef);
175 ret = pCryptCATAdminReleaseContext(hca, 0);
176 ok(!ret, "Expected failure\n");
177 ok(GetLastError() == ERROR_INVALID_PARAMETER,
178 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
180 /* NULL context handle and dummy GUID */
181 SetLastError(0xdeadbeef);
182 ret = pCryptCATAdminAcquireContext(NULL, &dummy, 0);
183 ok(!ret, "Expected failure\n");
184 ok(GetLastError() == ERROR_INVALID_PARAMETER,
185 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
187 /* Correct context handle and dummy GUID
189 * The tests run in the past unfortunately made sure that some directories were created.
191 * FIXME:
192 * We don't want to mess too much with these for now so we should delete only the ones
193 * that shouldn't be there like the deadbeef ones. We first have to figure out if it's
194 * save to remove files and directories from CatRoot/CatRoot2.
197 ret = pCryptCATAdminAcquireContext(&hca, &dummy, 0);
198 ok(ret, "Expected success\n");
199 ok(hca != NULL, "Expected a context handle, got NULL\n");
201 GetWindowsDirectoryA(windir, MAX_PATH);
202 lstrcpyA(catroot, windir);
203 lstrcatA(catroot, "\\system32\\CatRoot");
204 lstrcpyA(catroot2, windir);
205 lstrcatA(catroot2, "\\system32\\CatRoot2");
207 attrs = GetFileAttributes(catroot);
208 ok(attrs != INVALID_FILE_ATTRIBUTES, "Expected the CatRoot directory to exist\n");
210 /* Windows creates the GUID directory in capitals */
211 lstrcpyA(dummydir, catroot);
212 lstrcatA(dummydir, "\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}");
213 attrs = GetFileAttributes(dummydir);
214 ok(attrs != INVALID_FILE_ATTRIBUTES,
215 "Expected CatRoot\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF} directory to exist\n");
217 /* Only present on XP or higher. */
218 attrs = GetFileAttributes(catroot2);
219 if (attrs != INVALID_FILE_ATTRIBUTES)
221 lstrcpyA(dummydir, catroot2);
222 lstrcatA(dummydir, "\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}");
223 attrs = GetFileAttributes(dummydir);
224 ok(attrs != INVALID_FILE_ATTRIBUTES,
225 "Expected CatRoot2\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF} directory to exist\n");
228 ret = pCryptCATAdminReleaseContext(hca, 0);
229 ok(ret, "Expected success\n");
231 /* Correct context handle and GUID */
232 ret = pCryptCATAdminAcquireContext(&hca, &unknown, 0);
233 ok(ret, "Expected success\n");
234 ok(hca != NULL, "Expected a context handle, got NULL\n");
236 ret = pCryptCATAdminReleaseContext(hca, 0);
237 ok(ret, "Expected success\n");
239 /* Flags not equal to 0 */
240 ret = pCryptCATAdminAcquireContext(&hca, &unknown, 1);
241 ok(ret, "Expected success\n");
242 ok(hca != NULL, "Expected a context handle, got NULL\n");
244 ret = pCryptCATAdminReleaseContext(hca, 0);
245 ok(ret, "Expected success\n");
248 /* TODO: Check whether SHA-1 is the algorithm that's always used */
249 static void test_calchash(void)
251 BOOL ret;
252 HANDLE file;
253 DWORD hashsize = 0;
254 BYTE* hash;
255 BYTE expectedhash[20] = {0x3a,0xa1,0x19,0x08,0xec,0xa6,0x0d,0x2e,0x7e,0xcc,0x7a,0xca,0xf5,0xb8,0x2e,0x62,0x6a,0xda,0xf0,0x19};
256 CHAR temp[MAX_PATH];
257 DWORD written;
259 /* All NULL */
260 SetLastError(0xdeadbeef);
261 ret = pCryptCATAdminCalcHashFromFileHandle(NULL, NULL, NULL, 0);
262 ok(!ret, "Expected failure\n");
263 ok(GetLastError() == ERROR_INVALID_PARAMETER,
264 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
266 /* NULL filehandle, rest is legal */
267 SetLastError(0xdeadbeef);
268 ret = pCryptCATAdminCalcHashFromFileHandle(NULL, &hashsize, NULL, 0);
269 ok(!ret, "Expected failure\n");
270 ok(GetLastError() == ERROR_INVALID_PARAMETER,
271 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
273 /* Correct filehandle, rest is NULL */
274 file = CreateFileA(selfname, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
275 SetLastError(0xdeadbeef);
276 ret = pCryptCATAdminCalcHashFromFileHandle(file, NULL, NULL, 0);
277 ok(!ret, "Expected failure\n");
278 ok(GetLastError() == ERROR_INVALID_PARAMETER,
279 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
280 CloseHandle(file);
282 /* All OK, but dwFlags set to 1 */
283 file = CreateFileA(selfname, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
284 SetLastError(0xdeadbeef);
285 ret = pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, NULL, 1);
286 ok(!ret, "Expected failure\n");
287 ok(GetLastError() == ERROR_INVALID_PARAMETER,
288 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
289 CloseHandle(file);
291 /* All OK, requesting the size of the hash */
292 file = CreateFileA(selfname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
293 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed %u\n", GetLastError());
294 SetLastError(0xdeadbeef);
295 ret = pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, NULL, 0);
296 ok(ret, "Expected success %u\n", GetLastError());
297 ok(hashsize == 20," Expected a hash size of 20, got %d\n", hashsize);
298 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
299 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
300 CloseHandle(file);
302 /* All OK, retrieve the hash
303 * Double the hash buffer to see what happens to the size parameter
305 file = CreateFileA(selfname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
306 hashsize *= 2;
307 hash = HeapAlloc(GetProcessHeap(), 0, hashsize);
308 SetLastError(0xdeadbeef);
309 ret = pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, hash, 0);
310 ok(ret, "Expected success %u\n", GetLastError());
311 ok(hashsize == 20," Expected a hash size of 20, got %d\n", hashsize);
312 ok(GetLastError() == ERROR_SUCCESS,
313 "Expected ERROR_SUCCESS, got %d\n", GetLastError());
314 CloseHandle(file);
315 HeapFree(GetProcessHeap(), 0, hash);
317 /* Do the same test with a file created and filled by ourselves (and we thus
318 * have a known hash for).
320 GetTempFileNameA(CURR_DIR, "hsh", 0, temp);
321 file = CreateFileA(temp, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
322 WriteFile(file, "Text in this file is needed to create a know hash", 49, &written, NULL);
323 CloseHandle(file);
325 /* All OK, first request the size and then retrieve the hash */
326 file = CreateFileA(temp, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
327 hashsize = 0;
328 pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, NULL, 0);
329 hash = HeapAlloc(GetProcessHeap(), 0, hashsize);
330 SetLastError(0xdeadbeef);
331 ret = pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, hash, 0);
332 ok(ret, "Expected success\n");
333 ok(GetLastError() == ERROR_SUCCESS,
334 "Expected ERROR_SUCCESS, got %d\n", GetLastError());
335 ok(hashsize == sizeof(expectedhash) &&
336 !memcmp(hash, expectedhash, sizeof(expectedhash)),
337 "Hashes didn't match\n");
338 CloseHandle(file);
340 HeapFree(GetProcessHeap(), 0, hash);
341 DeleteFileA(temp);
344 static void test_CryptCATAdminAddRemoveCatalog(void)
346 static WCHAR basenameW[] = {'w','i','n','e','t','e','s','t','.','c','a','t',0};
347 HCATADMIN hcatadmin;
348 HCATINFO hcatinfo;
349 WCHAR tmpfileW[MAX_PATH];
350 char tmpfile[MAX_PATH];
351 HANDLE file;
352 DWORD error, written;
353 BOOL ret;
355 if (!pCryptCATAdminRemoveCatalog)
357 /* NT4 and W2K do have CryptCATAdminAddCatalog !! */
358 win_skip("CryptCATAdminRemoveCatalog is not available\n");
359 return;
362 if (!GetTempFileNameA(CURR_DIR, "cat", 0, tmpfile)) return;
363 DeleteFileA(tmpfile);
364 file = CreateFileA(tmpfile, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
365 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %u", GetLastError());
366 CloseHandle(file);
368 ret = pCryptCATAdminAcquireContext(&hcatadmin, &dummy, 0);
369 ok(ret, "CryptCATAdminAcquireContext failed %u\n", GetLastError());
371 SetLastError(0xdeadbeef);
372 hcatinfo = pCryptCATAdminAddCatalog(NULL, NULL, NULL, 0);
373 error = GetLastError();
374 ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n");
375 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMTER\n", GetLastError());
377 SetLastError(0xdeadbeef);
378 hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, NULL, NULL, 0);
379 error = GetLastError();
380 ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n");
381 ok(error == ERROR_INVALID_PARAMETER, "got %u expected INVALID_PARAMTER\n", GetLastError());
383 MultiByteToWideChar(0, 0, tmpfile, -1, tmpfileW, MAX_PATH);
385 SetLastError(0xdeadbeef);
386 hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, basenameW, 0);
387 error = GetLastError();
388 todo_wine {
389 ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n");
390 ok(error == ERROR_BAD_FORMAT, "got %u expected ERROR_BAD_FORMAT\n", GetLastError());
393 SetLastError(0xdeadbeef);
394 hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, basenameW, 1);
395 error = GetLastError();
396 ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n");
397 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMTER\n", GetLastError());
399 SetLastError(0xdeadbeef);
400 hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, NULL, 0);
401 error = GetLastError();
402 ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n");
403 todo_wine ok(error == ERROR_BAD_FORMAT, "got %u expected ERROR_BAD_FORMAT\n", GetLastError());
405 DeleteFileA(tmpfile);
406 file = CreateFileA(tmpfile, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
407 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %u", GetLastError());
408 WriteFile(file, test_catalog, sizeof(test_catalog), &written, NULL);
409 CloseHandle(file);
411 hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, NULL, 0);
412 todo_wine ok(hcatinfo != NULL, "CryptCATAdminAddCatalog failed %u\n", GetLastError());
414 hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, basenameW, 0);
415 ok(hcatinfo != NULL, "CryptCATAdminAddCatalog failed %u\n", GetLastError());
417 ret = pCryptCATAdminReleaseCatalogContext(hcatadmin, hcatinfo, 0);
418 ok(ret, "CryptCATAdminReleaseCatalogContext failed %u\n", GetLastError());
420 ret = pCryptCATAdminRemoveCatalog(hcatadmin, tmpfileW, 0);
421 ok(ret, "CryptCATAdminRemoveCatalog failed %u\n", GetLastError());
423 ret = pCryptCATAdminReleaseContext(hcatadmin, 0);
424 ok(ret, "CryptCATAdminReleaseContext failed %u\n", GetLastError());
426 DeleteFileA(tmpfile);
429 START_TEST(crypt)
431 int myARGC;
432 char** myARGV;
434 InitFunctionPtrs();
436 if (!pCryptCATAdminAcquireContext)
438 win_skip("CryptCATAdmin functions are not available\n");
439 return;
442 myARGC = winetest_get_mainargs(&myARGV);
443 strcpy(selfname, myARGV[0]);
445 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
447 test_context();
448 test_calchash();
449 test_CryptCATAdminAddRemoveCatalog();