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
28 #include "wine/test.h"
30 static char selfname
[MAX_PATH
];
31 static CHAR CURR_DIR
[MAX_PATH
];
32 static CHAR catroot
[MAX_PATH
];
33 static CHAR catroot2
[MAX_PATH
];
35 static const WCHAR hashmeW
[] = {'h','a','s','h','m','e',0};
36 static const WCHAR attr1W
[] = {'a','t','t','r','1',0};
37 static const WCHAR attr2W
[] = {'a','t','t','r','2',0};
40 * Minimalistic catalog file. To reconstruct, save text below as winetest.cdf,
41 * convert to DOS line endings and run 'makecat /cat winetest.cdf'
48 PublicVersion=0x00000001
50 CATATTR1=0x10010001:attr1:value1
51 CATATTR2=0x10010001:attr2:value2
57 static const CHAR test_cdf
[] =
59 "Name=winetest.cat\r\n"
61 "PublicVersion=0x00000001\r\n"
63 "CATATTR1=0x10010001:attr1:value1\r\n"
64 "CATATTR2=0x10010001:attr2:value2\r\n"
67 "hashme=.\\winetest.cdf\r\n";
69 static const BYTE test_catalog
[] = {
70 0x30, 0x82, 0x01, 0xbc, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0,
71 0x82, 0x01, 0xad, 0x30, 0x82, 0x01, 0xa9, 0x02, 0x01, 0x01, 0x31, 0x00, 0x30, 0x82, 0x01, 0x9e,
72 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0a, 0x01, 0xa0, 0x82, 0x01, 0x8f, 0x30,
73 0x82, 0x01, 0x8b, 0x30, 0x0c, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x01,
74 0x01, 0x04, 0x10, 0xfa, 0x55, 0x2c, 0xc2, 0xf6, 0xcc, 0xdd, 0x11, 0x2a, 0x9c, 0x00, 0x14, 0x22,
75 0xec, 0x8f, 0x3b, 0x17, 0x0d, 0x30, 0x38, 0x31, 0x32, 0x31, 0x38, 0x31, 0x31, 0x32, 0x36, 0x34,
76 0x38, 0x5a, 0x30, 0x0e, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x01, 0x02,
77 0x05, 0x00, 0x30, 0x81, 0xdd, 0x30, 0x81, 0xda, 0x04, 0x0e, 0x68, 0x00, 0x61, 0x00, 0x73, 0x00,
78 0x68, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x00, 0x00, 0x31, 0x81, 0xc7, 0x30, 0x61, 0x06, 0x0a, 0x2b,
79 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x04, 0x31, 0x53, 0x30, 0x51, 0x30, 0x2c, 0x06,
80 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x19, 0xa2, 0x1e, 0x80, 0x1c, 0x00,
81 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x4f, 0x00, 0x62, 0x00, 0x73, 0x00, 0x6f, 0x00, 0x6c, 0x00,
82 0x65, 0x00, 0x74, 0x00, 0x65, 0x00, 0x3e, 0x00, 0x3e, 0x00, 0x3e, 0x30, 0x21, 0x30, 0x09, 0x06,
83 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14, 0xed, 0xd6, 0x9c, 0x9c, 0xb2, 0xfc,
84 0xaa, 0x03, 0xe8, 0xd3, 0x20, 0xf6, 0xab, 0x28, 0xc3, 0xff, 0xbd, 0x07, 0x36, 0xf5, 0x30, 0x62,
85 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x02, 0x02, 0x31, 0x54, 0x30, 0x52,
86 0x1e, 0x4c, 0x00, 0x7b, 0x00, 0x44, 0x00, 0x45, 0x00, 0x33, 0x00, 0x35, 0x00, 0x31, 0x00, 0x41,
87 0x00, 0x34, 0x00, 0x32, 0x00, 0x2d, 0x00, 0x38, 0x00, 0x45, 0x00, 0x35, 0x00, 0x39, 0x00, 0x2d,
88 0x00, 0x31, 0x00, 0x31, 0x00, 0x44, 0x00, 0x30, 0x00, 0x2d, 0x00, 0x38, 0x00, 0x43, 0x00, 0x34,
89 0x00, 0x37, 0x00, 0x2d, 0x00, 0x30, 0x00, 0x30, 0x00, 0x43, 0x00, 0x30, 0x00, 0x34, 0x00, 0x46,
90 0x00, 0x43, 0x00, 0x32, 0x00, 0x39, 0x00, 0x35, 0x00, 0x45, 0x00, 0x45, 0x00, 0x7d, 0x02, 0x02,
91 0x02, 0x00, 0xa0, 0x6a, 0x30, 0x68, 0x30, 0x32, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82,
92 0x37, 0x0c, 0x02, 0x01, 0x04, 0x24, 0x30, 0x22, 0x1e, 0x0a, 0x00, 0x61, 0x00, 0x74, 0x00, 0x74,
93 0x00, 0x72, 0x00, 0x32, 0x02, 0x04, 0x10, 0x01, 0x00, 0x01, 0x04, 0x0e, 0x76, 0x00, 0x61, 0x00,
94 0x6c, 0x00, 0x75, 0x00, 0x65, 0x00, 0x32, 0x00, 0x00, 0x00, 0x30, 0x32, 0x06, 0x0a, 0x2b, 0x06,
95 0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x02, 0x01, 0x04, 0x24, 0x30, 0x22, 0x1e, 0x0a, 0x00, 0x61,
96 0x00, 0x74, 0x00, 0x74, 0x00, 0x72, 0x00, 0x31, 0x02, 0x04, 0x10, 0x01, 0x00, 0x01, 0x04, 0x0e,
97 0x76, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x75, 0x00, 0x65, 0x00, 0x31, 0x00, 0x00, 0x00, 0x31, 0x00,
100 static BOOL (WINAPI
* pCryptCATAdminAcquireContext
)(HCATADMIN
*, const GUID
*, DWORD
);
101 static BOOL (WINAPI
* pCryptCATAdminReleaseContext
)(HCATADMIN
, DWORD
);
102 static BOOL (WINAPI
* pCryptCATAdminCalcHashFromFileHandle
)(HANDLE hFile
, DWORD
*, BYTE
*, DWORD
);
103 static HCATINFO (WINAPI
* pCryptCATAdminAddCatalog
)(HCATADMIN
, PWSTR
, PWSTR
, DWORD
);
104 static BOOL (WINAPI
* pCryptCATAdminRemoveCatalog
)(HCATADMIN
, LPCWSTR
, DWORD
);
105 static BOOL (WINAPI
* pCryptCATAdminReleaseCatalogContext
)(HCATADMIN
, HCATINFO
, DWORD
);
106 static HANDLE (WINAPI
* pCryptCATOpen
)(LPWSTR
, DWORD
, HCRYPTPROV
, DWORD
, DWORD
);
107 static BOOL (WINAPI
* pCryptCATCatalogInfoFromContext
)(HCATINFO
, CATALOG_INFO
*, DWORD
);
108 static BOOL (WINAPI
* pCryptCATCDFClose
)(CRYPTCATCDF
*);
109 static CRYPTCATATTRIBUTE
* (WINAPI
* pCryptCATCDFEnumCatAttributes
)(CRYPTCATCDF
*, CRYPTCATATTRIBUTE
*,
110 PFN_CDF_PARSE_ERROR_CALLBACK
);
111 static LPWSTR (WINAPI
* pCryptCATCDFEnumMembersByCDFTagEx
)(CRYPTCATCDF
*, LPWSTR
, PFN_CDF_PARSE_ERROR_CALLBACK
,
112 CRYPTCATMEMBER
**, BOOL
, LPVOID
);
113 static CRYPTCATCDF
* (WINAPI
* pCryptCATCDFOpen
)(LPWSTR
, PFN_CDF_PARSE_ERROR_CALLBACK
);
114 static CRYPTCATATTRIBUTE
* (WINAPI
* pCryptCATEnumerateCatAttr
)(HANDLE
, CRYPTCATATTRIBUTE
*);
115 static CRYPTCATMEMBER
* (WINAPI
* pCryptCATEnumerateMember
)(HANDLE
, CRYPTCATMEMBER
*);
116 static CRYPTCATATTRIBUTE
* (WINAPI
* pCryptCATEnumerateAttr
)(HANDLE
, CRYPTCATMEMBER
*, CRYPTCATATTRIBUTE
*);
117 static BOOL (WINAPI
* pCryptCATClose
)(HANDLE
);
118 static pCryptSIPGetSignedDataMsg pGetSignedDataMsg
;
119 static pCryptSIPPutSignedDataMsg pPutSignedDataMsg
;
121 static void InitFunctionPtrs(void)
123 HMODULE hWintrust
= GetModuleHandleA("wintrust.dll");
125 #define WINTRUST_GET_PROC(func) \
126 p ## func = (void*)GetProcAddress(hWintrust, #func); \
128 trace("GetProcAddress(%s) failed\n", #func); \
131 WINTRUST_GET_PROC(CryptCATAdminAcquireContext
)
132 WINTRUST_GET_PROC(CryptCATAdminReleaseContext
)
133 WINTRUST_GET_PROC(CryptCATAdminCalcHashFromFileHandle
)
134 WINTRUST_GET_PROC(CryptCATAdminAddCatalog
)
135 WINTRUST_GET_PROC(CryptCATAdminRemoveCatalog
)
136 WINTRUST_GET_PROC(CryptCATAdminReleaseCatalogContext
)
137 WINTRUST_GET_PROC(CryptCATOpen
)
138 WINTRUST_GET_PROC(CryptCATCatalogInfoFromContext
)
139 WINTRUST_GET_PROC(CryptCATCDFClose
)
140 WINTRUST_GET_PROC(CryptCATCDFEnumCatAttributes
)
141 WINTRUST_GET_PROC(CryptCATCDFEnumMembersByCDFTagEx
)
142 WINTRUST_GET_PROC(CryptCATCDFOpen
)
143 WINTRUST_GET_PROC(CryptCATEnumerateCatAttr
)
144 WINTRUST_GET_PROC(CryptCATEnumerateMember
)
145 WINTRUST_GET_PROC(CryptCATEnumerateAttr
)
146 WINTRUST_GET_PROC(CryptCATClose
)
148 #undef WINTRUST_GET_PROC
150 pGetSignedDataMsg
= (void*)GetProcAddress(hWintrust
, "CryptSIPGetSignedDataMsg");
151 if(!pGetSignedDataMsg
)
152 trace("GetProcAddress(CryptSIPGetSignedDataMsg) failed\n");
154 pPutSignedDataMsg
= (void*)GetProcAddress(hWintrust
, "CryptSIPPutSignedDataMsg");
155 if(!pPutSignedDataMsg
)
156 trace("GetProcAddress(CryptSIPPutSignedDataMsg) failed\n");
159 static GUID dummy
= {0xdeadbeef,0xdead,0xbeef,{0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
161 static void test_context(void)
165 static GUID unknown
= { 0xC689AABA, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }}; /* WINTRUST.DLL */
166 CHAR dummydir
[MAX_PATH
];
169 /* When CryptCATAdminAcquireContext is successful it will create
170 * several directories if they don't exist:
172 * ...\system32\CatRoot\{GUID}, this directory holds the .cat files
173 * ...\system32\CatRoot2\{GUID} (WinXP and up), here we find the catalog database for that GUID
175 * Windows Vista uses lowercase catroot and catroot2.
177 * When passed a NULL GUID it will create the following directories although on
178 * WinXP and up these directories are already present when Windows is installed:
180 * ...\system32\CatRoot\{127D0A1D-4EF2-11D1-8608-00C04FC295EE}
181 * ...\system32\CatRoot2\{127D0A1D-4EF2-11D1-8608-00C04FC295EE} (WinXP up)
183 * TODO: Find out what this GUID is/does.
185 * On WinXP and up there is also a TimeStamp file in some of directories that
186 * seem to indicate the last change to the catalog database for that GUID.
188 * On Windows 2000 some files are created/updated:
190 * ...\system32\CatRoot\SYSMAST.cbk
191 * ...\system32\CatRoot\SYSMAST.cbd
192 * ...\system32\CatRoot\{GUID}\CATMAST.cbk
193 * ...\system32\CatRoot\{GUID}\CATMAST.cbd
198 SetLastError(0xdeadbeef);
199 ret
= pCryptCATAdminAcquireContext(NULL
, NULL
, 0);
200 ok(!ret
, "Expected failure\n");
201 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
202 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
205 ret
= pCryptCATAdminAcquireContext(&hca
, NULL
, 0);
206 ok(ret
, "Expected success, got FALSE with %d\n", GetLastError());
207 ok(hca
!= NULL
, "Expected a context handle, got NULL\n");
210 SetLastError(0xdeadbeef);
211 ret
= pCryptCATAdminReleaseContext(NULL
, 0);
212 ok(!ret
, "Expected failure\n");
213 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
214 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
217 SetLastError(0xdeadbeef);
218 ret
= pCryptCATAdminReleaseContext(hca
, 0);
219 ok(ret
, "Expected success, got FALSE with %d\n", GetLastError());
221 /* Try to release a second time */
222 SetLastError(0xdeadbeef);
223 ret
= pCryptCATAdminReleaseContext(hca
, 0);
224 ok(!ret
, "Expected failure\n");
225 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
226 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
228 /* NULL context handle and dummy GUID */
229 SetLastError(0xdeadbeef);
230 ret
= pCryptCATAdminAcquireContext(NULL
, &dummy
, 0);
231 ok(!ret
, "Expected failure\n");
232 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
233 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
235 /* Correct context handle and dummy GUID
237 * The tests run in the past unfortunately made sure that some directories were created.
240 * We don't want to mess too much with these for now so we should delete only the ones
241 * that shouldn't be there like the deadbeef ones. We first have to figure out if it's
242 * save to remove files and directories from CatRoot/CatRoot2.
245 ret
= pCryptCATAdminAcquireContext(&hca
, &dummy
, 0);
246 ok(ret
|| GetLastError() == ERROR_ACCESS_DENIED
, "CryptCATAdminAcquireContext failed %u\n", GetLastError());
247 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
249 win_skip("Not running as administrator\n");
252 ok(hca
!= NULL
, "Expected a context handle, got NULL\n");
254 attrs
= GetFileAttributesA(catroot
);
255 ok(attrs
!= INVALID_FILE_ATTRIBUTES
, "Expected the CatRoot directory to exist\n");
257 /* Windows creates the GUID directory in capitals */
258 lstrcpyA(dummydir
, catroot
);
259 lstrcatA(dummydir
, "\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}");
260 attrs
= GetFileAttributesA(dummydir
);
261 ok(attrs
!= INVALID_FILE_ATTRIBUTES
,
262 "Expected CatRoot\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF} directory to exist\n");
264 /* Only present on XP or higher. */
265 attrs
= GetFileAttributesA(catroot2
);
266 if (attrs
!= INVALID_FILE_ATTRIBUTES
)
268 lstrcpyA(dummydir
, catroot2
);
269 lstrcatA(dummydir
, "\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}");
270 attrs
= GetFileAttributesA(dummydir
);
271 ok(attrs
!= INVALID_FILE_ATTRIBUTES
,
272 "Expected CatRoot2\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF} directory to exist\n");
275 ret
= pCryptCATAdminReleaseContext(hca
, 0);
276 ok(ret
, "Expected success, got FALSE with %d\n", GetLastError());
278 /* Correct context handle and GUID */
279 ret
= pCryptCATAdminAcquireContext(&hca
, &unknown
, 0);
280 ok(ret
, "Expected success, got FALSE with %d\n", GetLastError());
281 ok(hca
!= NULL
, "Expected a context handle, got NULL\n");
283 ret
= pCryptCATAdminReleaseContext(hca
, 0);
284 ok(ret
, "Expected success, got FALSE with %d\n", GetLastError());
286 hca
= (void *) 0xdeadbeef;
287 SetLastError(0xdeadbeef);
288 /* Flags is documented as unused, but the parameter is checked since win8 */
289 ret
= pCryptCATAdminAcquireContext(&hca
, &unknown
, 1);
290 ok((!ret
&& (GetLastError() == ERROR_INVALID_PARAMETER
) && (hca
== (void *) 0xdeadbeef)) ||
291 broken(ret
&& hca
!= NULL
&& hca
!= (void *) 0xdeadbeef),
292 "Expected FALSE and ERROR_INVALID_PARAMETER with untouched handle, got %d and %u with %p\n",
293 ret
, GetLastError(), hca
);
297 SetLastError(0xdeadbeef);
298 ret
= pCryptCATAdminReleaseContext(hca
, 0);
299 ok(ret
, "Expected success, got FALSE with %d\n", GetLastError());
303 /* TODO: Check whether SHA-1 is the algorithm that's always used */
304 static void test_calchash(void)
310 BYTE expectedhash
[20] = {0x3a,0xa1,0x19,0x08,0xec,0xa6,0x0d,0x2e,0x7e,0xcc,0x7a,0xca,0xf5,0xb8,0x2e,0x62,0x6a,0xda,0xf0,0x19};
315 SetLastError(0xdeadbeef);
316 ret
= pCryptCATAdminCalcHashFromFileHandle(NULL
, NULL
, NULL
, 0);
317 ok(!ret
, "Expected failure\n");
318 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
319 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
321 /* NULL filehandle, rest is legal */
322 SetLastError(0xdeadbeef);
323 ret
= pCryptCATAdminCalcHashFromFileHandle(NULL
, &hashsize
, NULL
, 0);
324 ok(!ret
, "Expected failure\n");
325 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
326 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
328 /* Correct filehandle, rest is NULL */
329 file
= CreateFileA(selfname
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
330 SetLastError(0xdeadbeef);
331 ret
= pCryptCATAdminCalcHashFromFileHandle(file
, NULL
, NULL
, 0);
332 ok(!ret
, "Expected failure\n");
333 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
334 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
337 /* All OK, but dwFlags set to 1 */
338 file
= CreateFileA(selfname
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
339 SetLastError(0xdeadbeef);
340 ret
= pCryptCATAdminCalcHashFromFileHandle(file
, &hashsize
, NULL
, 1);
341 ok(!ret
, "Expected failure\n");
342 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
343 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
346 /* All OK, requesting the size of the hash */
347 file
= CreateFileA(selfname
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, NULL
);
348 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed %u\n", GetLastError());
349 SetLastError(0xdeadbeef);
350 ret
= pCryptCATAdminCalcHashFromFileHandle(file
, &hashsize
, NULL
, 0);
351 ok(ret
, "Expected success, got FALSE with %d\n", GetLastError());
352 ok(hashsize
== 20," Expected a hash size of 20, got %d\n", hashsize
);
353 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
354 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
357 /* All OK, retrieve the hash
358 * Double the hash buffer to see what happens to the size parameter
360 file
= CreateFileA(selfname
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, NULL
);
362 hash
= HeapAlloc(GetProcessHeap(), 0, hashsize
);
363 SetLastError(0xdeadbeef);
364 ret
= pCryptCATAdminCalcHashFromFileHandle(file
, &hashsize
, hash
, 0);
365 ok(ret
, "Expected success, got FALSE with %d\n", GetLastError());
366 ok(hashsize
== 20," Expected a hash size of 20, got %d\n", hashsize
);
367 ok(GetLastError() == ERROR_SUCCESS
,
368 "Expected ERROR_SUCCESS, got %d\n", GetLastError());
370 HeapFree(GetProcessHeap(), 0, hash
);
372 /* Do the same test with a file created and filled by ourselves (and we thus
373 * have a known hash for).
375 GetTempFileNameA(CURR_DIR
, "hsh", 0, temp
);
376 file
= CreateFileA(temp
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
377 WriteFile(file
, "Text in this file is needed to create a know hash", 49, &written
, NULL
);
380 /* All OK, first request the size and then retrieve the hash */
381 file
= CreateFileA(temp
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
383 pCryptCATAdminCalcHashFromFileHandle(file
, &hashsize
, NULL
, 0);
384 hash
= HeapAlloc(GetProcessHeap(), 0, hashsize
);
385 SetLastError(0xdeadbeef);
386 ret
= pCryptCATAdminCalcHashFromFileHandle(file
, &hashsize
, hash
, 0);
387 ok(ret
, "Expected success, got FALSE with %d\n", GetLastError());
388 ok(GetLastError() == ERROR_SUCCESS
,
389 "Expected ERROR_SUCCESS, got %d\n", GetLastError());
390 ok(hashsize
== sizeof(expectedhash
) &&
391 !memcmp(hash
, expectedhash
, sizeof(expectedhash
)),
392 "Hashes didn't match\n");
395 HeapFree(GetProcessHeap(), 0, hash
);
399 static void test_CryptCATOpen(void)
402 char empty
[MAX_PATH
];
403 WCHAR emptyW
[MAX_PATH
];
407 SetLastError(0xdeadbeef);
408 hcat
= pCryptCATOpen(NULL
, 0, 0, 0, 0);
409 ok(hcat
== INVALID_HANDLE_VALUE
, "CryptCATOpen succeeded\n");
410 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
411 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
413 if (!GetTempFileNameA(CURR_DIR
, "cat", 0, empty
)) return;
415 file
= CreateFileA(empty
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
416 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFileA failed %u\n", GetLastError());
418 MultiByteToWideChar(CP_ACP
, 0, empty
, -1, emptyW
, MAX_PATH
);
420 hcat
= pCryptCATOpen(emptyW
, 0, 0, 0, 0);
422 ok(hcat
!= INVALID_HANDLE_VALUE
, "Expected a correct handle\n");
424 ret
= pCryptCATClose(hcat
);
426 ok(ret
, "CryptCATClose failed\n");
430 static DWORD error_area
;
431 static DWORD local_error
;
433 static void WINAPI
cdf_callback(DWORD area
, DWORD error
, WCHAR
* line
)
435 ok(error_area
!= -2, "Didn't expect cdf_callback() to be called (%08x, %08x)\n",
442 static void test_CryptCATCDF_params(void)
444 static WCHAR nonexistent
[] = {'d','e','a','d','b','e','e','f','.','c','d','f',0};
448 if (!pCryptCATCDFOpen
)
450 win_skip("CryptCATCDFOpen is not available\n");
454 SetLastError(0xdeadbeef);
455 catcdf
= pCryptCATCDFOpen(NULL
, NULL
);
456 ok(catcdf
== NULL
, "CryptCATCDFOpen succeeded\n");
458 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
460 SetLastError(0xdeadbeef);
461 catcdf
= pCryptCATCDFOpen(NULL
, cdf_callback
);
462 ok(catcdf
== NULL
, "CryptCATCDFOpen succeeded\n");
464 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
466 /* File doesn't exist */
467 SetLastError(0xdeadbeef);
468 catcdf
= pCryptCATCDFOpen(nonexistent
, cdf_callback
);
469 ok(catcdf
== NULL
, "CryptCATCDFOpen succeeded\n");
471 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
473 SetLastError(0xdeadbeef);
474 ret
= pCryptCATCDFClose(NULL
);
475 ok(!ret
, "Expected failure\n");
477 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
480 SetLastError(0xdeadbeef);
481 ret
= pCryptCATCDFClose(catcdf
);
482 ok(!ret
, "Expected failure\n");
484 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
487 /* FIXME: Once Wine can create catalog files we should use the created catalog file in this test */
488 static void test_CryptCATAdminAddRemoveCatalog(void)
490 static WCHAR basenameW
[] = {'w','i','n','e','t','e','s','t','.','c','a','t',0};
491 static const char basename
[] = "winetest.cat";
495 WCHAR tmpfileW
[MAX_PATH
];
496 char tmpfile
[MAX_PATH
];
497 char catfile
[MAX_PATH
], catfilepath
[MAX_PATH
], *p
;
498 WCHAR catfileW
[MAX_PATH
];
500 DWORD error
, written
;
504 if (!pCryptCATAdminRemoveCatalog
)
506 /* NT4 and W2K do have CryptCATAdminAddCatalog !! */
507 win_skip("CryptCATAdminRemoveCatalog is not available\n");
511 if (!GetTempFileNameA(CURR_DIR
, "cat", 0, tmpfile
)) return;
512 DeleteFileA(tmpfile
);
513 file
= CreateFileA(tmpfile
, GENERIC_WRITE
, 0, NULL
, CREATE_NEW
, 0, NULL
);
514 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFileA failed %u\n", GetLastError());
517 ret
= pCryptCATAdminAcquireContext(&hcatadmin
, &dummy
, 0);
518 ok(ret
|| GetLastError() == ERROR_ACCESS_DENIED
, "CryptCATAdminAcquireContext failed %u\n", GetLastError());
519 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
521 win_skip("Not running as administrator\n");
525 SetLastError(0xdeadbeef);
526 hcatinfo
= pCryptCATAdminAddCatalog(NULL
, NULL
, NULL
, 0);
527 error
= GetLastError();
528 ok(hcatinfo
== NULL
, "CryptCATAdminAddCatalog succeeded\n");
529 ok(error
== ERROR_INVALID_PARAMETER
, "got %u expected ERROR_INVALID_PARAMETER\n", GetLastError());
531 SetLastError(0xdeadbeef);
532 hcatinfo
= pCryptCATAdminAddCatalog(hcatadmin
, NULL
, NULL
, 0);
533 error
= GetLastError();
534 ok(hcatinfo
== NULL
, "CryptCATAdminAddCatalog succeeded\n");
535 ok(error
== ERROR_INVALID_PARAMETER
, "got %u expected ERROR_INVALID_PARAMETER\n", GetLastError());
537 MultiByteToWideChar(CP_ACP
, 0, tmpfile
, -1, tmpfileW
, MAX_PATH
);
539 SetLastError(0xdeadbeef);
540 hcatinfo
= pCryptCATAdminAddCatalog(hcatadmin
, tmpfileW
, basenameW
, 0);
541 error
= GetLastError();
543 ok(hcatinfo
== NULL
, "CryptCATAdminAddCatalog succeeded\n");
544 ok(error
== ERROR_BAD_FORMAT
, "got %u expected ERROR_BAD_FORMAT\n", GetLastError());
546 if (hcatinfo
!= NULL
)
547 pCryptCATAdminReleaseCatalogContext(hcatadmin
, hcatinfo
, 0);
549 SetLastError(0xdeadbeef);
550 hcatinfo
= pCryptCATAdminAddCatalog(hcatadmin
, tmpfileW
, basenameW
, 1);
551 error
= GetLastError();
552 ok(hcatinfo
== NULL
, "CryptCATAdminAddCatalog succeeded\n");
553 ok(error
== ERROR_INVALID_PARAMETER
, "got %u expected ERROR_INVALID_PARAMETER\n", GetLastError());
555 SetLastError(0xdeadbeef);
556 hcatinfo
= pCryptCATAdminAddCatalog(hcatadmin
, tmpfileW
, NULL
, 0);
557 error
= GetLastError();
558 ok(hcatinfo
== NULL
, "CryptCATAdminAddCatalog succeeded\n");
559 todo_wine
ok(error
== ERROR_BAD_FORMAT
, "got %u expected ERROR_BAD_FORMAT\n", GetLastError());
561 DeleteFileA(tmpfile
);
562 file
= CreateFileA(tmpfile
, GENERIC_WRITE
, 0, NULL
, CREATE_NEW
, 0, NULL
);
563 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFileA failed %u\n", GetLastError());
564 WriteFile(file
, test_catalog
, sizeof(test_catalog
), &written
, NULL
);
567 /* Unique name will be created */
568 hcatinfo
= pCryptCATAdminAddCatalog(hcatadmin
, tmpfileW
, NULL
, 0);
569 if (!hcatinfo
&& (GetLastError() == ERROR_ACCESS_DENIED
))
571 win_skip("Not enough rights\n");
574 todo_wine
ok(hcatinfo
!= NULL
, "CryptCATAdminAddCatalog failed %u\n", GetLastError());
576 info
.cbStruct
= sizeof(info
);
577 info
.wszCatalogFile
[0] = 0;
578 ret
= pCryptCATCatalogInfoFromContext(hcatinfo
, &info
, 0);
581 ok(ret
, "CryptCATCatalogInfoFromContext failed %u\n", GetLastError());
582 ok(info
.wszCatalogFile
[0] != 0, "Expected a filename\n");
584 WideCharToMultiByte(CP_ACP
, 0, info
.wszCatalogFile
, -1, catfile
, MAX_PATH
, NULL
, NULL
);
585 if ((p
= strrchr(catfile
, '\\'))) p
++;
586 memset(catfileW
, 0, sizeof(catfileW
));
587 MultiByteToWideChar(CP_ACP
, 0, p
, -1, catfileW
, MAX_PATH
);
589 /* Set the file attributes so we can check what happens with them during the 'copy' */
590 attrs
= FILE_ATTRIBUTE_READONLY
;
591 ret
= SetFileAttributesA(tmpfile
, attrs
);
592 ok(ret
, "SetFileAttributesA failed : %u\n", GetLastError());
594 /* winetest.cat will be created */
595 hcatinfo
= pCryptCATAdminAddCatalog(hcatadmin
, tmpfileW
, basenameW
, 0);
596 ok(hcatinfo
!= NULL
, "CryptCATAdminAddCatalog failed %u\n", GetLastError());
598 lstrcpyA(catfilepath
, catroot
);
599 lstrcatA(catfilepath
, "\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}\\winetest.cat");
600 attrs
= GetFileAttributesA(catfilepath
);
601 ok(attrs
!= INVALID_FILE_ATTRIBUTES
, "Expected %s to exist\n", catfilepath
);
603 ok(attrs
== FILE_ATTRIBUTE_SYSTEM
||
604 attrs
== (FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
| FILE_ATTRIBUTE_SYSTEM
), /* Vista */
605 "File has wrong attributes : %08x\n", attrs
);
607 info
.cbStruct
= sizeof(info
);
608 info
.wszCatalogFile
[0] = 0;
609 ret
= pCryptCATCatalogInfoFromContext(hcatinfo
, &info
, 0);
610 ok(ret
, "CryptCATCatalogInfoFromContext failed %u\n", GetLastError());
611 ok(info
.wszCatalogFile
[0] != 0, "Expected a filename\n");
612 WideCharToMultiByte(CP_ACP
, 0, info
.wszCatalogFile
, -1, catfile
, MAX_PATH
, NULL
, NULL
);
613 if ((p
= strrchr(catfile
, '\\'))) p
++;
614 ok(!lstrcmpA(basename
, p
), "Expected %s, got %s\n", basename
, p
);
616 ret
= pCryptCATAdminReleaseCatalogContext(hcatadmin
, hcatinfo
, 0);
617 ok(ret
, "CryptCATAdminReleaseCatalogContext failed %u\n", GetLastError());
619 /* Remove the catalog file with the unique name */
620 ret
= pCryptCATAdminRemoveCatalog(hcatadmin
, catfileW
, 0);
621 ok(ret
, "CryptCATAdminRemoveCatalog failed %u\n", GetLastError());
623 /* Remove the winetest.cat catalog file, first with the full path. This should not succeed
624 * according to MSDN */
625 ret
= pCryptCATAdminRemoveCatalog(hcatadmin
, info
.wszCatalogFile
, 0);
626 ok(ret
, "CryptCATAdminRemoveCatalog failed %u\n", GetLastError());
627 /* The call succeeded with the full path but the file is not removed */
628 attrs
= GetFileAttributesA(catfilepath
);
629 ok(attrs
!= INVALID_FILE_ATTRIBUTES
, "Expected %s to exist\n", catfilepath
);
630 /* Given only the filename the file is removed */
631 ret
= pCryptCATAdminRemoveCatalog(hcatadmin
, basenameW
, 0);
632 ok(ret
, "CryptCATAdminRemoveCatalog failed %u\n", GetLastError());
633 attrs
= GetFileAttributesA(catfilepath
);
634 ok(attrs
== INVALID_FILE_ATTRIBUTES
, "Expected %s to be removed\n", catfilepath
);
637 ret
= pCryptCATAdminReleaseContext(hcatadmin
, 0);
638 ok(ret
, "CryptCATAdminReleaseContext failed %u\n", GetLastError());
640 /* Set the attributes so we can delete the file */
641 attrs
= FILE_ATTRIBUTE_NORMAL
;
642 ret
= SetFileAttributesA(tmpfile
, attrs
);
643 ok(ret
, "SetFileAttributesA failed %u\n", GetLastError());
644 DeleteFileA(tmpfile
);
647 static void test_catalog_properties(const char *catfile
, int attributes
, int members
)
649 static const GUID subject
= {0xde351a42,0x8e59,0x11d0,{0x8c,0x47,0x00,0xc0,0x4f,0xc2,0x95,0xee}};
653 CRYPTCATATTRIBUTE
*attr
;
654 char catalog
[MAX_PATH
];
655 WCHAR catalogW
[MAX_PATH
];
658 int attrcount
= 0, membercount
= 0;
660 /* FIXME: Wine can't create catalog files out of catalog definition files yet. Remove this piece
663 attrs
= GetFileAttributesA(catfile
);
664 if (attrs
== INVALID_FILE_ATTRIBUTES
)
669 trace("Creating the catalog file\n");
670 if (!GetTempFileNameA(CURR_DIR
, "cat", 0, catalog
)) return;
671 file
= CreateFileA(catalog
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
672 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFileA failed %u\n", GetLastError());
673 WriteFile(file
, test_catalog
, sizeof(test_catalog
), &written
, NULL
);
678 MultiByteToWideChar(CP_ACP
, 0, catalog
, -1, catalogW
, MAX_PATH
);
682 MultiByteToWideChar(CP_ACP
, 0, catfile
, -1, catalogW
, MAX_PATH
);
686 hcat
= pCryptCATOpen(catalogW
, 0, 0, 0, 0);
687 if (hcat
== INVALID_HANDLE_VALUE
&& members
== 0)
689 win_skip("CryptCATOpen on W2K can't handle catalog files with no members\n");
692 ok(hcat
!= INVALID_HANDLE_VALUE
, "CryptCATOpen failed %u\n", GetLastError());
694 m
= pCryptCATEnumerateMember(NULL
, NULL
);
695 ok(m
== NULL
, "CryptCATEnumerateMember succeeded\n");
698 while ((m
= pCryptCATEnumerateMember(hcat
, m
)))
700 ok(m
->cbStruct
== sizeof(CRYPTCATMEMBER
), "unexpected size %u\n", m
->cbStruct
);
701 todo_wine
ok(!lstrcmpW(m
->pwszReferenceTag
, hashmeW
), "unexpected tag\n");
702 ok(!memcmp(&m
->gSubjectType
, &subject
, sizeof(subject
)), "guid differs\n");
703 ok(!m
->fdwMemberFlags
, "got %x expected 0\n", m
->fdwMemberFlags
);
704 ok(m
->dwCertVersion
== 0x200, "got %x expected 0x200\n", m
->dwCertVersion
);
705 ok(!m
->dwReserved
, "got %x expected 0\n", m
->dwReserved
);
706 ok(m
->hReserved
== NULL
, "got %p expected NULL\n", m
->hReserved
);
708 attr
= pCryptCATEnumerateAttr(hcat
, m
, NULL
);
709 ok(attr
== NULL
, "CryptCATEnumerateAttr succeeded\n");
713 ok(membercount
== members
, "Expected %d members, got %d\n", members
, membercount
);
715 attr
= pCryptCATEnumerateAttr(NULL
, NULL
, NULL
);
716 ok(attr
== NULL
, "CryptCATEnumerateAttr succeeded\n");
718 attr
= pCryptCATEnumerateAttr(hcat
, NULL
, NULL
);
719 ok(attr
== NULL
, "CryptCATEnumerateAttr succeeded\n");
722 while ((attr
= pCryptCATEnumerateCatAttr(hcat
, attr
)))
724 ok(!lstrcmpW(attr
->pwszReferenceTag
, attr1W
) ||
725 !lstrcmpW(attr
->pwszReferenceTag
, attr2W
),
726 "Expected 'attr1' or 'attr2'\n");
731 ok(attrcount
== attributes
, "Expected %d catalog attributes, got %d\n", attributes
, attrcount
);
733 ret
= pCryptCATClose(hcat
);
734 ok(ret
, "CryptCATClose failed\n");
735 if (catalog
[0]) DeleteFileA( catalog
);
738 static void test_create_catalog_file(void)
740 static const char catfileA
[] = "winetest.cat";
741 static const char cdffileA
[] = "winetest.cdf";
742 static WCHAR cdffileW
[] = {'w','i','n','e','t','e','s','t','.','c','d','f',0};
744 CRYPTCATATTRIBUTE
*catattr
;
745 CRYPTCATMEMBER
*catmember
;
747 DWORD written
, attrs
;
750 int attrcount
, membercount
;
752 if (!pCryptCATCDFOpen
)
754 win_skip("CryptCATCDFOpen is not available\n");
758 /* Create the cdf file */
759 file
= CreateFileA(cdffileA
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
760 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFileA failed %u\n", GetLastError());
761 WriteFile(file
, test_cdf
, sizeof(test_cdf
) - 1, &written
, NULL
);
764 /* Don't enumerate attributes and members */
765 trace("No attribs and members\n");
766 SetLastError(0xdeadbeef);
767 catcdf
= pCryptCATCDFOpen(cdffileW
, NULL
);
770 ok(catcdf
!= NULL
, "CryptCATCDFOpen failed\n");
771 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
774 ret
= pCryptCATCDFClose(catcdf
);
777 ok(ret
, "Expected success, got FALSE with %d\n", GetLastError());
778 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
781 attrs
= GetFileAttributesA(catfileA
);
783 ok(attrs
!= INVALID_FILE_ATTRIBUTES
, "Expected the catalog file to exist\n");
785 test_catalog_properties(catfileA
, 0, 0);
786 DeleteFileA(catfileA
);
788 /* Only enumerate the attributes */
789 trace("Only attributes\n");
790 attrcount
= membercount
= 0;
791 catcdf
= pCryptCATCDFOpen(cdffileW
, NULL
);
794 while ((catattr
= pCryptCATCDFEnumCatAttributes(catcdf
, catattr
, NULL
)))
796 ok(!lstrcmpW(catattr
->pwszReferenceTag
, attr1W
) ||
797 !lstrcmpW(catattr
->pwszReferenceTag
, attr2W
),
798 "Expected 'attr1' or 'attr2'\n");
803 ok(attrcount
== 2, "Expected 2 attributes, got %d\n", attrcount
);
805 pCryptCATCDFClose(catcdf
);
806 /* Even though the resulting catalog file shows the attributes, they will not be enumerated */
807 test_catalog_properties(catfileA
, 0, 0);
808 DeleteFileA(catfileA
);
810 /* Only enumerate the members */
811 trace("Only members\n");
813 catcdf
= pCryptCATCDFOpen(cdffileW
, NULL
);
817 while ((catmembertag
= pCryptCATCDFEnumMembersByCDFTagEx(catcdf
, catmembertag
, NULL
, &catmember
, FALSE
, NULL
)))
819 ok(!lstrcmpW(catmembertag
, hashmeW
), "Expected 'hashme'\n");
823 ok(membercount
== 1, "Expected 1 member, got %d\n", membercount
);
825 pCryptCATCDFClose(catcdf
);
826 test_catalog_properties(catfileA
, 0, 1);
827 DeleteFileA(catfileA
);
829 /* Enumerate members and attributes */
830 trace("Attributes and members\n");
831 attrcount
= membercount
= 0;
832 catcdf
= pCryptCATCDFOpen(cdffileW
, NULL
);
835 while ((catattr
= pCryptCATCDFEnumCatAttributes(catcdf
, catattr
, NULL
)))
838 ok(attrcount
== 2, "Expected 2 attributes, got %d\n", attrcount
);
842 while ((catmembertag
= pCryptCATCDFEnumMembersByCDFTagEx(catcdf
, catmembertag
, NULL
, &catmember
, FALSE
, NULL
)))
845 ok(membercount
== 1, "Expected 1 member, got %d\n", membercount
);
847 pCryptCATCDFClose(catcdf
);
848 test_catalog_properties(catfileA
, 2, 1);
849 DeleteFileA(catfileA
);
851 DeleteFileA(cdffileA
);
854 static void create_cdf_file(const CHAR
*filename
, const CHAR
*contents
)
859 file
= CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
860 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFileA failed %u\n", GetLastError());
861 WriteFile(file
, contents
, lstrlenA(contents
), &written
, NULL
);
865 #define CHECK_EXPECT(a, b) \
867 ok(a == error_area, "Expected %08x, got %08x\n", a, error_area); \
868 ok(b == local_error, "Expected %08x, got %08x\n", b, local_error); \
871 /* Clear the variables (can't use 0) */
872 #define CLEAR_EXPECT \
873 error_area = local_error = -1
875 /* Set both variables so the callback routine can check if a call to it was unexpected */
876 #define SET_UNEXPECTED \
877 error_area = local_error = -2
879 static void test_cdf_parsing(void)
881 static const char catfileA
[] = "tempfile.cat";
882 static const char cdffileA
[] = "tempfile.cdf";
883 static WCHAR cdffileW
[] = {'t','e','m','p','f','i','l','e','.','c','d','f',0};
884 CHAR cdf_contents
[4096];
886 CRYPTCATATTRIBUTE
*catattr
;
887 CRYPTCATMEMBER
*catmember
;
890 if (!pCryptCATCDFOpen
)
892 win_skip("CryptCATCDFOpen is not available\n");
897 DeleteFileA(cdffileA
);
898 create_cdf_file(cdffileA
, "");
901 SetLastError(0xdeadbeef);
902 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
904 CHECK_EXPECT(CRYPTCAT_E_AREA_HEADER
, CRYPTCAT_E_CDF_TAGNOTFOUND
);
905 ok(catcdf
== NULL
, "CryptCATCDFOpen succeeded\n");
907 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
908 DeleteFileA(cdffileA
);
909 ok(!DeleteFileA(catfileA
), "Didn't expect a catalog file to be created\n");
911 /* Just the header */
912 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
913 create_cdf_file(cdffileA
, cdf_contents
);
916 SetLastError(0xdeadbeef);
917 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
918 ok(catcdf
== NULL
, "CryptCATCDFOpen succeeded\n");
920 ok(GetLastError() == ERROR_SHARING_VIOLATION
,
921 "Expected ERROR_SHARING_VIOLATION, got %d\n", GetLastError());
922 DeleteFileA(cdffileA
);
924 /* Header and member only */
925 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
926 lstrcatA(cdf_contents
, "[CatalogFiles]\r\n");
927 lstrcatA(cdf_contents
, "hashme=.\\tempfile.cdf\r\n");
928 create_cdf_file(cdffileA
, cdf_contents
);
931 SetLastError(0xdeadbeef);
932 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
933 ok(catcdf
== NULL
, "CryptCATCDFOpen succeeded\n");
935 ok(GetLastError() == ERROR_SHARING_VIOLATION
,
936 "Expected ERROR_SHARING_VIOLATION, got %d\n", GetLastError());
937 DeleteFileA(cdffileA
);
938 ok(!DeleteFileA(catfileA
), "Didn't expect a catalog file to be created\n");
940 /* Header and Name (no value) */
941 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
942 lstrcatA(cdf_contents
, "Name=\r\n");
943 create_cdf_file(cdffileA
, cdf_contents
);
946 SetLastError(0xdeadbeef);
947 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
948 ok(catcdf
== NULL
, "CryptCATCDFOpen succeeded\n");
950 ok(GetLastError() == ERROR_SHARING_VIOLATION
,
951 "Expected ERROR_SHARING_VIOLATION, got %d\n", GetLastError());
952 DeleteFileA(cdffileA
);
953 ok(!DeleteFileA(catfileA
), "Didn't expect a catalog file to be created\n");
955 /* Header and Name */
956 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
957 lstrcatA(cdf_contents
, "Name=tempfile.cat\r\n");
958 create_cdf_file(cdffileA
, cdf_contents
);
961 SetLastError(0xdeadbeef);
962 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
965 ok(catcdf
!= NULL
, "CryptCATCDFOpen failed\n");
966 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
968 pCryptCATCDFClose(catcdf
);
969 DeleteFileA(cdffileA
);
971 ok(DeleteFileA(catfileA
), "Expected a catalog file to be created\n");
973 /* Header and nonexistent member */
974 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
975 lstrcatA(cdf_contents
, "Name=tempfile.cat\r\n");
976 lstrcatA(cdf_contents
, "[CatalogFiles]\r\n");
977 lstrcatA(cdf_contents
, "hashme=.\\deadbeef.cdf\r\n");
978 create_cdf_file(cdffileA
, cdf_contents
);
981 SetLastError(0xdeadbeef);
982 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
985 ok(catcdf
!= NULL
, "CryptCATCDFOpen failed\n");
986 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
988 /* Loop through the members */
992 while ((catmembertag
= pCryptCATCDFEnumMembersByCDFTagEx(catcdf
, catmembertag
, cdf_callback
, &catmember
, FALSE
, NULL
))) ;
994 CHECK_EXPECT(CRYPTCAT_E_AREA_MEMBER
, CRYPTCAT_E_CDF_MEMBER_FILENOTFOUND
);
995 pCryptCATCDFClose(catcdf
);
996 DeleteFileA(cdffileA
);
998 ok(DeleteFileA(catfileA
), "Expected a catalog file to be created\n");
1000 /* Header, correct member but no explicit newline */
1001 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
1002 lstrcatA(cdf_contents
, "Name=tempfile.cat\r\n");
1003 lstrcatA(cdf_contents
, "[CatalogFiles]\r\n");
1004 lstrcatA(cdf_contents
, "hashme=.\\tempfile.cdf\r");
1005 create_cdf_file(cdffileA
, cdf_contents
);
1008 SetLastError(0xdeadbeef);
1009 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
1012 ok(catcdf
!= NULL
, "CryptCATCDFOpen failed\n");
1013 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
1015 /* Loop through the members */
1018 catmembertag
= NULL
;
1019 while ((catmembertag
= pCryptCATCDFEnumMembersByCDFTagEx(catcdf
, catmembertag
, cdf_callback
, &catmember
, FALSE
, NULL
))) ;
1021 CHECK_EXPECT(CRYPTCAT_E_AREA_MEMBER
, CRYPTCAT_E_CDF_MEMBER_FILE_PATH
);
1022 pCryptCATCDFClose(catcdf
);
1023 DeleteFileA(cdffileA
);
1025 ok(DeleteFileA(catfileA
), "Expected a catalog file to be created\n");
1027 /* Header and 2 duplicate members */
1028 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
1029 lstrcatA(cdf_contents
, "Name=tempfile.cat\r\n");
1030 lstrcatA(cdf_contents
, "[CatalogFiles]\r\n");
1031 lstrcatA(cdf_contents
, "hashme=.\\tempfile.cdf\r\n");
1032 lstrcatA(cdf_contents
, "hashme=.\\tempfile.cdf\r\n");
1033 create_cdf_file(cdffileA
, cdf_contents
);
1036 SetLastError(0xdeadbeef);
1037 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
1040 ok(catcdf
!= NULL
, "CryptCATCDFOpen failed\n");
1041 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
1043 /* Loop through the members */
1046 catmembertag
= NULL
;
1047 while ((catmembertag
= pCryptCATCDFEnumMembersByCDFTagEx(catcdf
, catmembertag
, cdf_callback
, &catmember
, FALSE
, NULL
))) ;
1048 pCryptCATCDFClose(catcdf
);
1049 test_catalog_properties(catfileA
, 0, 1);
1050 DeleteFileA(cdffileA
);
1052 ok(DeleteFileA(catfileA
), "Expected a catalog file to be created\n");
1054 /* Wrong attribute */
1055 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
1056 lstrcatA(cdf_contents
, "Name=tempfile.cat\r\n");
1057 lstrcatA(cdf_contents
, "CATATTR1=0x10010001:attr1\r\n");
1058 create_cdf_file(cdffileA
, cdf_contents
);
1061 SetLastError(0xdeadbeef);
1062 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
1065 ok(catcdf
!= NULL
, "CryptCATCDFOpen failed\n");
1066 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
1068 /* Loop through the attributes */
1071 while ((catattr
= pCryptCATCDFEnumCatAttributes(catcdf
, catattr
, cdf_callback
))) ;
1073 CHECK_EXPECT(CRYPTCAT_E_AREA_ATTRIBUTE
, CRYPTCAT_E_CDF_ATTR_TOOFEWVALUES
);
1074 pCryptCATCDFClose(catcdf
);
1075 DeleteFileA(cdffileA
);
1077 ok(DeleteFileA(catfileA
), "Expected a catalog file to be created\n");
1079 /* Two identical attributes */
1080 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
1081 lstrcatA(cdf_contents
, "Name=tempfile.cat\r\n");
1082 lstrcatA(cdf_contents
, "CATATTR1=0x10010001:attr1:value1\r\n");
1083 lstrcatA(cdf_contents
, "CATATTR1=0x10010001:attr1:value1\r\n");
1084 lstrcatA(cdf_contents
, "[CatalogFiles]\r\n");
1085 lstrcatA(cdf_contents
, "hashme=.\\tempfile.cdf\r\n");
1086 create_cdf_file(cdffileA
, cdf_contents
);
1089 SetLastError(0xdeadbeef);
1090 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
1093 ok(catcdf
!= NULL
, "CryptCATCDFOpen failed\n");
1094 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
1096 /* Loop through the members */
1099 catmembertag
= NULL
;
1100 while ((catmembertag
= pCryptCATCDFEnumMembersByCDFTagEx(catcdf
, catmembertag
, cdf_callback
, &catmember
, FALSE
, NULL
))) ;
1101 /* Loop through the attributes */
1104 while ((catattr
= pCryptCATCDFEnumCatAttributes(catcdf
, catattr
, cdf_callback
))) ;
1105 pCryptCATCDFClose(catcdf
);
1106 test_catalog_properties(catfileA
, 1, 1);
1107 DeleteFileA(cdffileA
);
1109 ok(DeleteFileA(catfileA
), "Expected a catalog file to be created\n");
1111 /* Two different attribute values with the same tag */
1112 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
1113 lstrcatA(cdf_contents
, "Name=tempfile.cat\r\n");
1114 lstrcatA(cdf_contents
, "CATATTR1=0x10010001:attr1:value1\r\n");
1115 lstrcatA(cdf_contents
, "CATATTR1=0x10010001:attr2:value2\r\n");
1116 lstrcatA(cdf_contents
, "[CatalogFiles]\r\n");
1117 lstrcatA(cdf_contents
, "hashme=.\\tempfile.cdf\r\n");
1118 create_cdf_file(cdffileA
, cdf_contents
);
1121 SetLastError(0xdeadbeef);
1122 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
1125 ok(catcdf
!= NULL
, "CryptCATCDFOpen failed\n");
1126 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
1128 /* Loop through the members */
1131 catmembertag
= NULL
;
1132 while ((catmembertag
= pCryptCATCDFEnumMembersByCDFTagEx(catcdf
, catmembertag
, cdf_callback
, &catmember
, FALSE
, NULL
))) ;
1133 /* Loop through the attributes */
1136 while ((catattr
= pCryptCATCDFEnumCatAttributes(catcdf
, catattr
, cdf_callback
))) ;
1137 pCryptCATCDFClose(catcdf
);
1138 test_catalog_properties(catfileA
, 1, 1);
1139 DeleteFileA(cdffileA
);
1141 ok(DeleteFileA(catfileA
), "Expected a catalog file to be created\n");
1146 WORD e_magic
; /* 00: MZ Header signature */
1148 DWORD e_lfanew
; /* 3c: Offset to extended header */
1151 IMAGE_DOS_SIGNATURE
, { 0 }, sizeof(dos_header
)
1154 static IMAGE_NT_HEADERS nt_header
=
1156 IMAGE_NT_SIGNATURE
, /* Signature */
1158 IMAGE_FILE_MACHINE_I386
, /* Machine */
1159 1, /* NumberOfSections */
1160 0, /* TimeDateStamp */
1161 0, /* PointerToSymbolTable */
1162 0, /* NumberOfSymbols */
1163 sizeof(IMAGE_OPTIONAL_HEADER
), /* SizeOfOptionalHeader */
1164 IMAGE_FILE_EXECUTABLE_IMAGE
/* Characteristics */
1167 IMAGE_NT_OPTIONAL_HDR_MAGIC
, /* Magic */
1168 2, /* MajorLinkerVersion */
1169 15, /* MinorLinkerVersion */
1171 0, /* SizeOfInitializedData */
1172 0, /* SizeOfUninitializedData */
1173 0, /* AddressOfEntryPoint */
1174 0x10, /* BaseOfCode, also serves as e_lfanew in the truncated MZ header */
1178 0x10000000, /* ImageBase */
1179 0, /* SectionAlignment */
1180 0, /* FileAlignment */
1181 4, /* MajorOperatingSystemVersion */
1182 0, /* MinorOperatingSystemVersion */
1183 1, /* MajorImageVersion */
1184 0, /* MinorImageVersion */
1185 4, /* MajorSubsystemVersion */
1186 0, /* MinorSubsystemVersion */
1187 0, /* Win32VersionValue */
1188 0x200, /* SizeOfImage */
1189 sizeof(dos_header
) + sizeof(nt_header
), /* SizeOfHeaders */
1191 IMAGE_SUBSYSTEM_WINDOWS_CUI
, /* Subsystem */
1192 0, /* DllCharacteristics */
1193 0, /* SizeOfStackReserve */
1194 0, /* SizeOfStackCommit */
1195 0, /* SizeOfHeapReserve */
1196 3, /* SizeOfHeapCommit */
1197 2, /* LoaderFlags */
1198 1, /* NumberOfRvaAndSizes */
1199 { { 0 } } /* DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES] */
1203 static void test_sip(void)
1205 static const WCHAR nameW
[] = {'t','e','s','t','.','e','x','e',0};
1206 SIP_SUBJECTINFO info
;
1207 DWORD index
, encoding
, size
;
1213 file
= CreateFileW(nameW
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1214 ok(file
!= INVALID_HANDLE_VALUE
, "can't create file\n");
1215 if(file
== INVALID_HANDLE_VALUE
)
1217 WriteFile(file
, &dos_header
, sizeof(dos_header
), &size
, NULL
);
1218 WriteFile(file
, &nt_header
, sizeof(nt_header
), &size
, NULL
);
1219 memset(buf
, 0, sizeof(buf
));
1220 WriteFile(file
, buf
, 0x200 - sizeof(dos_header
) - sizeof(nt_header
), &size
, NULL
);
1223 file
= CreateFileW(nameW
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1224 ok(file
!= INVALID_HANDLE_VALUE
, "can't open file\n");
1226 memset(&info
, 0, sizeof(SIP_SUBJECTINFO
));
1227 info
.cbSize
= sizeof(SIP_SUBJECTINFO
);
1228 info
.pgSubjectType
= &guid
;
1229 ret
= CryptSIPRetrieveSubjectGuid(NULL
, file
, info
.pgSubjectType
);
1230 ok(ret
, "CryptSIPRetrieveSubjectGuid failed (%x)\n", GetLastError());
1232 ret
= pPutSignedDataMsg(&info
, X509_ASN_ENCODING
, &index
, 4, (BYTE
*)"test");
1233 ok(!ret
, "CryptSIPPutSignedDataMsg succeedded\n");
1234 index
= GetLastError();
1235 ok(index
== ERROR_PATH_NOT_FOUND
, "GetLastError returned %x\n", index
);
1238 info
.pwsFileName
= nameW
;
1239 ret
= pPutSignedDataMsg(&info
, X509_ASN_ENCODING
, &index
, 4, (BYTE
*)"test");
1240 ok(!ret
, "CryptSIPPutSignedDataMsg succeedded\n");
1241 index
= GetLastError();
1242 todo_wine
ok(index
== ERROR_INVALID_PARAMETER
, "GetLastError returned %x\n", index
);
1244 info
.hFile
= INVALID_HANDLE_VALUE
;
1245 info
.pwsFileName
= nameW
;
1246 ret
= pPutSignedDataMsg(&info
, X509_ASN_ENCODING
, &index
, 4, (BYTE
*)"test");
1247 ok(!ret
, "CryptSIPPutSignedDataMsg succeedded\n");
1248 index
= GetLastError();
1249 ok(index
== ERROR_SHARING_VIOLATION
, "GetLastError returned %x\n", index
);
1252 file
= CreateFileW(nameW
, GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1255 info
.pwsFileName
= (void*)0xdeadbeef;
1256 ret
= pPutSignedDataMsg(&info
, X509_ASN_ENCODING
, &index
, 4, (BYTE
*)"test");
1257 ok(ret
, "CryptSIPPutSignedDataMsg failed (%x)\n", GetLastError());
1258 ok(index
== 0, "index = %x\n", index
);
1261 file
= CreateFileW(nameW
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1263 info
.hFile
= INVALID_HANDLE_VALUE
;
1264 info
.pwsFileName
= nameW
;
1265 ret
= pPutSignedDataMsg(&info
, X509_ASN_ENCODING
, &index
, 14, (BYTE
*)"longer message");
1266 ok(ret
, "CryptSIPPutSignedDataMsg failed (%x)\n", GetLastError());
1267 ok(index
== 1, "index = %x\n", index
);
1270 encoding
= 0xdeadbeef;
1271 ret
= pGetSignedDataMsg(&info
, &encoding
, 0, &size
, NULL
);
1272 ok(ret
, "CryptSIPGetSignedDataMsg failed (%x)\n", GetLastError());
1273 ok(encoding
== 0xdeadbeef, "encoding = %x\n", encoding
);
1274 ok(size
== 16, "size = %d\n", size
);
1276 ret
= pGetSignedDataMsg(&info
, &encoding
, 0, &size
, (BYTE
*)buf
);
1277 ok(ret
, "CryptSIPGetSignedDataMsg failed (%x)\n", GetLastError());
1278 ok(encoding
== (X509_ASN_ENCODING
|PKCS_7_ASN_ENCODING
), "encoding = %x\n", encoding
);
1279 ok(size
== 8, "size = %d\n", size
);
1280 ok(!memcmp(buf
, "test\0\0\0\0", 8), "buf = %s\n", buf
);
1283 encoding
= 0xdeadbeef;
1284 ret
= pGetSignedDataMsg(&info
, &encoding
, 1, &size
, NULL
);
1285 ok(ret
, "CryptSIPGetSignedDataMsg failed (%x)\n", GetLastError());
1286 ok(encoding
== 0xdeadbeef, "encoding = %x\n", encoding
);
1287 ok(size
== 24, "size = %d\n", size
);
1289 ret
= pGetSignedDataMsg(&info
, &encoding
, 1, &size
, (BYTE
*)buf
);
1290 ok(ret
, "CryptSIPGetSignedDataMsg failed (%x)\n", GetLastError());
1291 ok(encoding
== (X509_ASN_ENCODING
|PKCS_7_ASN_ENCODING
), "encoding = %x\n", encoding
);
1292 ok(size
== 16, "size = %d\n", size
);
1293 ok(!strcmp(buf
, "longer message"), "buf = %s\n", buf
);
1295 CryptReleaseContext(info
.hProv
, 0);
1303 char sysdir
[MAX_PATH
];
1307 if (!pCryptCATAdminAcquireContext
)
1309 win_skip("CryptCATAdmin functions are not available\n");
1313 GetSystemDirectoryA(sysdir
, MAX_PATH
);
1314 lstrcpyA(catroot
, sysdir
);
1315 lstrcatA(catroot
, "\\CatRoot");
1316 lstrcpyA(catroot2
, sysdir
);
1317 lstrcatA(catroot2
, "\\CatRoot2");
1319 winetest_get_mainargs(&myARGV
);
1320 strcpy(selfname
, myARGV
[0]);
1322 GetCurrentDirectoryA(MAX_PATH
, CURR_DIR
);
1326 test_CryptCATOpen();
1327 /* Parameter checking only */
1328 test_CryptCATCDF_params();
1329 /* Test the parsing of a cdf file */
1331 /* Create a catalog file out of our own catalog definition file */
1332 test_create_catalog_file();
1333 test_CryptCATAdminAddRemoveCatalog();