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 * safe 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
||
554 error
== ERROR_BAD_FORMAT
, /* win 8 */
555 "got %u\n", GetLastError());
557 SetLastError(0xdeadbeef);
558 hcatinfo
= pCryptCATAdminAddCatalog(hcatadmin
, tmpfileW
, NULL
, 0);
559 error
= GetLastError();
560 ok(hcatinfo
== NULL
, "CryptCATAdminAddCatalog succeeded\n");
561 todo_wine
ok(error
== ERROR_BAD_FORMAT
, "got %u expected ERROR_BAD_FORMAT\n", GetLastError());
563 DeleteFileA(tmpfile
);
564 file
= CreateFileA(tmpfile
, GENERIC_WRITE
, 0, NULL
, CREATE_NEW
, 0, NULL
);
565 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFileA failed %u\n", GetLastError());
566 WriteFile(file
, test_catalog
, sizeof(test_catalog
), &written
, NULL
);
569 /* Unique name will be created */
570 hcatinfo
= pCryptCATAdminAddCatalog(hcatadmin
, tmpfileW
, NULL
, 0);
571 if (!hcatinfo
&& (GetLastError() == ERROR_ACCESS_DENIED
))
573 win_skip("Not enough rights\n");
576 todo_wine
ok(hcatinfo
!= NULL
, "CryptCATAdminAddCatalog failed %u\n", GetLastError());
578 info
.cbStruct
= sizeof(info
);
579 info
.wszCatalogFile
[0] = 0;
580 ret
= pCryptCATCatalogInfoFromContext(hcatinfo
, &info
, 0);
583 ok(ret
, "CryptCATCatalogInfoFromContext failed %u\n", GetLastError());
584 ok(info
.wszCatalogFile
[0] != 0, "Expected a filename\n");
586 WideCharToMultiByte(CP_ACP
, 0, info
.wszCatalogFile
, -1, catfile
, MAX_PATH
, NULL
, NULL
);
587 if ((p
= strrchr(catfile
, '\\'))) p
++;
588 memset(catfileW
, 0, sizeof(catfileW
));
589 MultiByteToWideChar(CP_ACP
, 0, p
, -1, catfileW
, MAX_PATH
);
591 /* Set the file attributes so we can check what happens with them during the 'copy' */
592 attrs
= FILE_ATTRIBUTE_READONLY
;
593 ret
= SetFileAttributesA(tmpfile
, attrs
);
594 ok(ret
, "SetFileAttributesA failed : %u\n", GetLastError());
596 /* winetest.cat will be created */
597 hcatinfo
= pCryptCATAdminAddCatalog(hcatadmin
, tmpfileW
, basenameW
, 0);
598 ok(hcatinfo
!= NULL
, "CryptCATAdminAddCatalog failed %u\n", GetLastError());
600 lstrcpyA(catfilepath
, catroot
);
601 lstrcatA(catfilepath
, "\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}\\winetest.cat");
602 attrs
= GetFileAttributesA(catfilepath
);
603 ok(attrs
!= INVALID_FILE_ATTRIBUTES
, "Expected %s to exist\n", catfilepath
);
605 ok(attrs
== FILE_ATTRIBUTE_SYSTEM
||
606 attrs
== (FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
| FILE_ATTRIBUTE_SYSTEM
), /* Vista */
607 "File has wrong attributes : %08x\n", attrs
);
609 info
.cbStruct
= sizeof(info
);
610 info
.wszCatalogFile
[0] = 0;
611 ret
= pCryptCATCatalogInfoFromContext(hcatinfo
, &info
, 0);
612 ok(ret
, "CryptCATCatalogInfoFromContext failed %u\n", GetLastError());
613 ok(info
.wszCatalogFile
[0] != 0, "Expected a filename\n");
614 WideCharToMultiByte(CP_ACP
, 0, info
.wszCatalogFile
, -1, catfile
, MAX_PATH
, NULL
, NULL
);
615 if ((p
= strrchr(catfile
, '\\'))) p
++;
616 ok(!lstrcmpA(basename
, p
), "Expected %s, got %s\n", basename
, p
);
618 ret
= pCryptCATAdminReleaseCatalogContext(hcatadmin
, hcatinfo
, 0);
619 ok(ret
, "CryptCATAdminReleaseCatalogContext failed %u\n", GetLastError());
621 /* Remove the catalog file with the unique name */
622 ret
= pCryptCATAdminRemoveCatalog(hcatadmin
, catfileW
, 0);
623 ok(ret
, "CryptCATAdminRemoveCatalog failed %u\n", GetLastError());
625 /* Remove the winetest.cat catalog file, first with the full path. This should not succeed
626 * according to MSDN */
627 ret
= pCryptCATAdminRemoveCatalog(hcatadmin
, info
.wszCatalogFile
, 0);
628 ok(ret
, "CryptCATAdminRemoveCatalog failed %u\n", GetLastError());
629 /* The call succeeded with the full path but the file is not removed */
630 attrs
= GetFileAttributesA(catfilepath
);
631 ok(attrs
!= INVALID_FILE_ATTRIBUTES
, "Expected %s to exist\n", catfilepath
);
632 /* Given only the filename the file is removed */
633 ret
= pCryptCATAdminRemoveCatalog(hcatadmin
, basenameW
, 0);
634 ok(ret
, "CryptCATAdminRemoveCatalog failed %u\n", GetLastError());
635 attrs
= GetFileAttributesA(catfilepath
);
636 ok(attrs
== INVALID_FILE_ATTRIBUTES
, "Expected %s to be removed\n", catfilepath
);
639 ret
= pCryptCATAdminReleaseContext(hcatadmin
, 0);
640 ok(ret
, "CryptCATAdminReleaseContext failed %u\n", GetLastError());
642 /* Set the attributes so we can delete the file */
643 attrs
= FILE_ATTRIBUTE_NORMAL
;
644 ret
= SetFileAttributesA(tmpfile
, attrs
);
645 ok(ret
, "SetFileAttributesA failed %u\n", GetLastError());
646 DeleteFileA(tmpfile
);
649 static void test_catalog_properties(const char *catfile
, int attributes
, int members
)
651 static const GUID subject
= {0xde351a42,0x8e59,0x11d0,{0x8c,0x47,0x00,0xc0,0x4f,0xc2,0x95,0xee}};
655 CRYPTCATATTRIBUTE
*attr
;
656 char catalog
[MAX_PATH
];
657 WCHAR catalogW
[MAX_PATH
];
660 int attrcount
= 0, membercount
= 0;
662 /* FIXME: Wine can't create catalog files out of catalog definition files yet. Remove this piece
665 attrs
= GetFileAttributesA(catfile
);
666 if (attrs
== INVALID_FILE_ATTRIBUTES
)
671 trace("Creating the catalog file\n");
672 if (!GetTempFileNameA(CURR_DIR
, "cat", 0, catalog
)) return;
673 file
= CreateFileA(catalog
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
674 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFileA failed %u\n", GetLastError());
675 WriteFile(file
, test_catalog
, sizeof(test_catalog
), &written
, NULL
);
680 MultiByteToWideChar(CP_ACP
, 0, catalog
, -1, catalogW
, MAX_PATH
);
684 MultiByteToWideChar(CP_ACP
, 0, catfile
, -1, catalogW
, MAX_PATH
);
688 hcat
= pCryptCATOpen(catalogW
, 0, 0, 0, 0);
689 if (hcat
== INVALID_HANDLE_VALUE
&& members
== 0)
691 win_skip("CryptCATOpen on W2K can't handle catalog files with no members\n");
694 ok(hcat
!= INVALID_HANDLE_VALUE
, "CryptCATOpen failed %u\n", GetLastError());
696 m
= pCryptCATEnumerateMember(NULL
, NULL
);
697 ok(m
== NULL
, "CryptCATEnumerateMember succeeded\n");
700 while ((m
= pCryptCATEnumerateMember(hcat
, m
)))
702 ok(m
->cbStruct
== sizeof(CRYPTCATMEMBER
), "unexpected size %u\n", m
->cbStruct
);
703 todo_wine
ok(!lstrcmpW(m
->pwszReferenceTag
, hashmeW
), "unexpected tag\n");
704 ok(!memcmp(&m
->gSubjectType
, &subject
, sizeof(subject
)), "guid differs\n");
705 ok(!m
->fdwMemberFlags
, "got %x expected 0\n", m
->fdwMemberFlags
);
706 ok(m
->dwCertVersion
== 0x200, "got %x expected 0x200\n", m
->dwCertVersion
);
707 ok(!m
->dwReserved
, "got %x expected 0\n", m
->dwReserved
);
708 ok(m
->hReserved
== NULL
, "got %p expected NULL\n", m
->hReserved
);
710 attr
= pCryptCATEnumerateAttr(hcat
, m
, NULL
);
711 ok(attr
== NULL
, "CryptCATEnumerateAttr succeeded\n");
715 ok(membercount
== members
, "Expected %d members, got %d\n", members
, membercount
);
717 attr
= pCryptCATEnumerateAttr(NULL
, NULL
, NULL
);
718 ok(attr
== NULL
, "CryptCATEnumerateAttr succeeded\n");
720 attr
= pCryptCATEnumerateAttr(hcat
, NULL
, NULL
);
721 ok(attr
== NULL
, "CryptCATEnumerateAttr succeeded\n");
724 while ((attr
= pCryptCATEnumerateCatAttr(hcat
, attr
)))
726 ok(!lstrcmpW(attr
->pwszReferenceTag
, attr1W
) ||
727 !lstrcmpW(attr
->pwszReferenceTag
, attr2W
),
728 "Expected 'attr1' or 'attr2'\n");
733 ok(attrcount
== attributes
, "Expected %d catalog attributes, got %d\n", attributes
, attrcount
);
735 ret
= pCryptCATClose(hcat
);
736 ok(ret
, "CryptCATClose failed\n");
737 if (catalog
[0]) DeleteFileA( catalog
);
740 static void test_create_catalog_file(void)
742 static const char catfileA
[] = "winetest.cat";
743 static const char cdffileA
[] = "winetest.cdf";
744 static WCHAR cdffileW
[] = {'w','i','n','e','t','e','s','t','.','c','d','f',0};
746 CRYPTCATATTRIBUTE
*catattr
;
747 CRYPTCATMEMBER
*catmember
;
749 DWORD written
, attrs
;
752 int attrcount
, membercount
;
754 if (!pCryptCATCDFOpen
)
756 win_skip("CryptCATCDFOpen is not available\n");
760 /* Create the cdf file */
761 file
= CreateFileA(cdffileA
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
762 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFileA failed %u\n", GetLastError());
763 WriteFile(file
, test_cdf
, sizeof(test_cdf
) - 1, &written
, NULL
);
766 /* Don't enumerate attributes and members */
767 trace("No attribs and members\n");
768 SetLastError(0xdeadbeef);
769 catcdf
= pCryptCATCDFOpen(cdffileW
, NULL
);
772 ok(catcdf
!= NULL
, "CryptCATCDFOpen failed\n");
773 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
776 ret
= pCryptCATCDFClose(catcdf
);
779 ok(ret
, "Expected success, got FALSE with %d\n", GetLastError());
780 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
783 attrs
= GetFileAttributesA(catfileA
);
785 ok(attrs
!= INVALID_FILE_ATTRIBUTES
, "Expected the catalog file to exist\n");
787 test_catalog_properties(catfileA
, 0, 0);
788 DeleteFileA(catfileA
);
790 /* Only enumerate the attributes */
791 trace("Only attributes\n");
792 attrcount
= membercount
= 0;
793 catcdf
= pCryptCATCDFOpen(cdffileW
, NULL
);
796 while ((catattr
= pCryptCATCDFEnumCatAttributes(catcdf
, catattr
, NULL
)))
798 ok(!lstrcmpW(catattr
->pwszReferenceTag
, attr1W
) ||
799 !lstrcmpW(catattr
->pwszReferenceTag
, attr2W
),
800 "Expected 'attr1' or 'attr2'\n");
805 ok(attrcount
== 2, "Expected 2 attributes, got %d\n", attrcount
);
807 pCryptCATCDFClose(catcdf
);
808 /* Even though the resulting catalog file shows the attributes, they will not be enumerated */
809 test_catalog_properties(catfileA
, 0, 0);
810 DeleteFileA(catfileA
);
812 /* Only enumerate the members */
813 trace("Only members\n");
815 catcdf
= pCryptCATCDFOpen(cdffileW
, NULL
);
819 while ((catmembertag
= pCryptCATCDFEnumMembersByCDFTagEx(catcdf
, catmembertag
, NULL
, &catmember
, FALSE
, NULL
)))
821 ok(!lstrcmpW(catmembertag
, hashmeW
), "Expected 'hashme'\n");
825 ok(membercount
== 1, "Expected 1 member, got %d\n", membercount
);
827 pCryptCATCDFClose(catcdf
);
828 test_catalog_properties(catfileA
, 0, 1);
829 DeleteFileA(catfileA
);
831 /* Enumerate members and attributes */
832 trace("Attributes and members\n");
833 attrcount
= membercount
= 0;
834 catcdf
= pCryptCATCDFOpen(cdffileW
, NULL
);
837 while ((catattr
= pCryptCATCDFEnumCatAttributes(catcdf
, catattr
, NULL
)))
840 ok(attrcount
== 2, "Expected 2 attributes, got %d\n", attrcount
);
844 while ((catmembertag
= pCryptCATCDFEnumMembersByCDFTagEx(catcdf
, catmembertag
, NULL
, &catmember
, FALSE
, NULL
)))
847 ok(membercount
== 1, "Expected 1 member, got %d\n", membercount
);
849 pCryptCATCDFClose(catcdf
);
850 test_catalog_properties(catfileA
, 2, 1);
851 DeleteFileA(catfileA
);
853 DeleteFileA(cdffileA
);
856 static void create_cdf_file(const CHAR
*filename
, const CHAR
*contents
)
861 file
= CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
862 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFileA failed %u\n", GetLastError());
863 WriteFile(file
, contents
, lstrlenA(contents
), &written
, NULL
);
867 #define CHECK_EXPECT(a, b) \
869 ok(a == error_area, "Expected %08x, got %08x\n", a, error_area); \
870 ok(b == local_error, "Expected %08x, got %08x\n", b, local_error); \
873 /* Clear the variables (can't use 0) */
874 #define CLEAR_EXPECT \
875 error_area = local_error = -1
877 /* Set both variables so the callback routine can check if a call to it was unexpected */
878 #define SET_UNEXPECTED \
879 error_area = local_error = -2
881 static void test_cdf_parsing(void)
883 static const char catfileA
[] = "tempfile.cat";
884 static const char cdffileA
[] = "tempfile.cdf";
885 static WCHAR cdffileW
[] = {'t','e','m','p','f','i','l','e','.','c','d','f',0};
886 CHAR cdf_contents
[4096];
888 CRYPTCATATTRIBUTE
*catattr
;
889 CRYPTCATMEMBER
*catmember
;
892 if (!pCryptCATCDFOpen
)
894 win_skip("CryptCATCDFOpen is not available\n");
899 DeleteFileA(cdffileA
);
900 create_cdf_file(cdffileA
, "");
903 SetLastError(0xdeadbeef);
904 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
906 CHECK_EXPECT(CRYPTCAT_E_AREA_HEADER
, CRYPTCAT_E_CDF_TAGNOTFOUND
);
907 ok(catcdf
== NULL
, "CryptCATCDFOpen succeeded\n");
909 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
910 DeleteFileA(cdffileA
);
911 ok(!DeleteFileA(catfileA
), "Didn't expect a catalog file to be created\n");
913 /* Just the header */
914 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
915 create_cdf_file(cdffileA
, cdf_contents
);
918 SetLastError(0xdeadbeef);
919 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
920 ok(catcdf
== NULL
, "CryptCATCDFOpen succeeded\n");
922 ok(GetLastError() == ERROR_SHARING_VIOLATION
,
923 "Expected ERROR_SHARING_VIOLATION, got %d\n", GetLastError());
924 DeleteFileA(cdffileA
);
926 /* Header and member only */
927 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
928 lstrcatA(cdf_contents
, "[CatalogFiles]\r\n");
929 lstrcatA(cdf_contents
, "hashme=.\\tempfile.cdf\r\n");
930 create_cdf_file(cdffileA
, cdf_contents
);
933 SetLastError(0xdeadbeef);
934 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
935 ok(catcdf
== NULL
, "CryptCATCDFOpen succeeded\n");
937 ok(GetLastError() == ERROR_SHARING_VIOLATION
,
938 "Expected ERROR_SHARING_VIOLATION, got %d\n", GetLastError());
939 DeleteFileA(cdffileA
);
940 ok(!DeleteFileA(catfileA
), "Didn't expect a catalog file to be created\n");
942 /* Header and Name (no value) */
943 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
944 lstrcatA(cdf_contents
, "Name=\r\n");
945 create_cdf_file(cdffileA
, cdf_contents
);
948 SetLastError(0xdeadbeef);
949 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
950 ok(catcdf
== NULL
, "CryptCATCDFOpen succeeded\n");
952 ok(GetLastError() == ERROR_SHARING_VIOLATION
,
953 "Expected ERROR_SHARING_VIOLATION, got %d\n", GetLastError());
954 DeleteFileA(cdffileA
);
955 ok(!DeleteFileA(catfileA
), "Didn't expect a catalog file to be created\n");
957 /* Header and Name */
958 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
959 lstrcatA(cdf_contents
, "Name=tempfile.cat\r\n");
960 create_cdf_file(cdffileA
, cdf_contents
);
963 SetLastError(0xdeadbeef);
964 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
967 ok(catcdf
!= NULL
, "CryptCATCDFOpen failed\n");
968 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
970 pCryptCATCDFClose(catcdf
);
971 DeleteFileA(cdffileA
);
973 ok(DeleteFileA(catfileA
), "Expected a catalog file to be created\n");
975 /* Header and nonexistent member */
976 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
977 lstrcatA(cdf_contents
, "Name=tempfile.cat\r\n");
978 lstrcatA(cdf_contents
, "[CatalogFiles]\r\n");
979 lstrcatA(cdf_contents
, "hashme=.\\deadbeef.cdf\r\n");
980 create_cdf_file(cdffileA
, cdf_contents
);
983 SetLastError(0xdeadbeef);
984 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
987 ok(catcdf
!= NULL
, "CryptCATCDFOpen failed\n");
988 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
990 /* Loop through the members */
994 while ((catmembertag
= pCryptCATCDFEnumMembersByCDFTagEx(catcdf
, catmembertag
, cdf_callback
, &catmember
, FALSE
, NULL
))) ;
996 CHECK_EXPECT(CRYPTCAT_E_AREA_MEMBER
, CRYPTCAT_E_CDF_MEMBER_FILENOTFOUND
);
997 pCryptCATCDFClose(catcdf
);
998 DeleteFileA(cdffileA
);
1000 ok(DeleteFileA(catfileA
), "Expected a catalog file to be created\n");
1002 /* Header, correct member but no explicit newline */
1003 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
1004 lstrcatA(cdf_contents
, "Name=tempfile.cat\r\n");
1005 lstrcatA(cdf_contents
, "[CatalogFiles]\r\n");
1006 lstrcatA(cdf_contents
, "hashme=.\\tempfile.cdf\r");
1007 create_cdf_file(cdffileA
, cdf_contents
);
1010 SetLastError(0xdeadbeef);
1011 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
1014 ok(catcdf
!= NULL
, "CryptCATCDFOpen failed\n");
1015 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
1017 /* Loop through the members */
1020 catmembertag
= NULL
;
1021 while ((catmembertag
= pCryptCATCDFEnumMembersByCDFTagEx(catcdf
, catmembertag
, cdf_callback
, &catmember
, FALSE
, NULL
))) ;
1023 CHECK_EXPECT(CRYPTCAT_E_AREA_MEMBER
, CRYPTCAT_E_CDF_MEMBER_FILE_PATH
);
1024 pCryptCATCDFClose(catcdf
);
1025 DeleteFileA(cdffileA
);
1027 ok(DeleteFileA(catfileA
), "Expected a catalog file to be created\n");
1029 /* Header and 2 duplicate members */
1030 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
1031 lstrcatA(cdf_contents
, "Name=tempfile.cat\r\n");
1032 lstrcatA(cdf_contents
, "[CatalogFiles]\r\n");
1033 lstrcatA(cdf_contents
, "hashme=.\\tempfile.cdf\r\n");
1034 lstrcatA(cdf_contents
, "hashme=.\\tempfile.cdf\r\n");
1035 create_cdf_file(cdffileA
, cdf_contents
);
1038 SetLastError(0xdeadbeef);
1039 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
1042 ok(catcdf
!= NULL
, "CryptCATCDFOpen failed\n");
1043 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
1045 /* Loop through the members */
1048 catmembertag
= NULL
;
1049 while ((catmembertag
= pCryptCATCDFEnumMembersByCDFTagEx(catcdf
, catmembertag
, cdf_callback
, &catmember
, FALSE
, NULL
))) ;
1050 pCryptCATCDFClose(catcdf
);
1051 test_catalog_properties(catfileA
, 0, 1);
1052 DeleteFileA(cdffileA
);
1054 ok(DeleteFileA(catfileA
), "Expected a catalog file to be created\n");
1056 /* Wrong attribute */
1057 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
1058 lstrcatA(cdf_contents
, "Name=tempfile.cat\r\n");
1059 lstrcatA(cdf_contents
, "CATATTR1=0x10010001:attr1\r\n");
1060 create_cdf_file(cdffileA
, cdf_contents
);
1063 SetLastError(0xdeadbeef);
1064 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
1067 ok(catcdf
!= NULL
, "CryptCATCDFOpen failed\n");
1068 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
1070 /* Loop through the attributes */
1073 while ((catattr
= pCryptCATCDFEnumCatAttributes(catcdf
, catattr
, cdf_callback
))) ;
1075 CHECK_EXPECT(CRYPTCAT_E_AREA_ATTRIBUTE
, CRYPTCAT_E_CDF_ATTR_TOOFEWVALUES
);
1076 pCryptCATCDFClose(catcdf
);
1077 DeleteFileA(cdffileA
);
1079 ok(DeleteFileA(catfileA
), "Expected a catalog file to be created\n");
1081 /* Two identical attributes */
1082 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
1083 lstrcatA(cdf_contents
, "Name=tempfile.cat\r\n");
1084 lstrcatA(cdf_contents
, "CATATTR1=0x10010001:attr1:value1\r\n");
1085 lstrcatA(cdf_contents
, "CATATTR1=0x10010001:attr1:value1\r\n");
1086 lstrcatA(cdf_contents
, "[CatalogFiles]\r\n");
1087 lstrcatA(cdf_contents
, "hashme=.\\tempfile.cdf\r\n");
1088 create_cdf_file(cdffileA
, cdf_contents
);
1091 SetLastError(0xdeadbeef);
1092 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
1095 ok(catcdf
!= NULL
, "CryptCATCDFOpen failed\n");
1096 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
1098 /* Loop through the members */
1101 catmembertag
= NULL
;
1102 while ((catmembertag
= pCryptCATCDFEnumMembersByCDFTagEx(catcdf
, catmembertag
, cdf_callback
, &catmember
, FALSE
, NULL
))) ;
1103 /* Loop through the attributes */
1106 while ((catattr
= pCryptCATCDFEnumCatAttributes(catcdf
, catattr
, cdf_callback
))) ;
1107 pCryptCATCDFClose(catcdf
);
1108 test_catalog_properties(catfileA
, 1, 1);
1109 DeleteFileA(cdffileA
);
1111 ok(DeleteFileA(catfileA
), "Expected a catalog file to be created\n");
1113 /* Two different attribute values with the same tag */
1114 lstrcpyA(cdf_contents
, "[CatalogHeader]\r\n");
1115 lstrcatA(cdf_contents
, "Name=tempfile.cat\r\n");
1116 lstrcatA(cdf_contents
, "CATATTR1=0x10010001:attr1:value1\r\n");
1117 lstrcatA(cdf_contents
, "CATATTR1=0x10010001:attr2:value2\r\n");
1118 lstrcatA(cdf_contents
, "[CatalogFiles]\r\n");
1119 lstrcatA(cdf_contents
, "hashme=.\\tempfile.cdf\r\n");
1120 create_cdf_file(cdffileA
, cdf_contents
);
1123 SetLastError(0xdeadbeef);
1124 catcdf
= pCryptCATCDFOpen(cdffileW
, cdf_callback
);
1127 ok(catcdf
!= NULL
, "CryptCATCDFOpen failed\n");
1128 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
1130 /* Loop through the members */
1133 catmembertag
= NULL
;
1134 while ((catmembertag
= pCryptCATCDFEnumMembersByCDFTagEx(catcdf
, catmembertag
, cdf_callback
, &catmember
, FALSE
, NULL
))) ;
1135 /* Loop through the attributes */
1138 while ((catattr
= pCryptCATCDFEnumCatAttributes(catcdf
, catattr
, cdf_callback
))) ;
1139 pCryptCATCDFClose(catcdf
);
1140 test_catalog_properties(catfileA
, 1, 1);
1141 DeleteFileA(cdffileA
);
1143 ok(DeleteFileA(catfileA
), "Expected a catalog file to be created\n");
1148 WORD e_magic
; /* 00: MZ Header signature */
1150 DWORD e_lfanew
; /* 3c: Offset to extended header */
1153 IMAGE_DOS_SIGNATURE
, { 0 }, sizeof(dos_header
)
1156 static IMAGE_NT_HEADERS nt_header
=
1158 IMAGE_NT_SIGNATURE
, /* Signature */
1160 IMAGE_FILE_MACHINE_I386
, /* Machine */
1161 1, /* NumberOfSections */
1162 0, /* TimeDateStamp */
1163 0, /* PointerToSymbolTable */
1164 0, /* NumberOfSymbols */
1165 sizeof(IMAGE_OPTIONAL_HEADER
), /* SizeOfOptionalHeader */
1166 IMAGE_FILE_EXECUTABLE_IMAGE
/* Characteristics */
1169 IMAGE_NT_OPTIONAL_HDR_MAGIC
, /* Magic */
1170 2, /* MajorLinkerVersion */
1171 15, /* MinorLinkerVersion */
1173 0, /* SizeOfInitializedData */
1174 0, /* SizeOfUninitializedData */
1175 0, /* AddressOfEntryPoint */
1176 0x10, /* BaseOfCode, also serves as e_lfanew in the truncated MZ header */
1180 0x10000000, /* ImageBase */
1181 0, /* SectionAlignment */
1182 0, /* FileAlignment */
1183 4, /* MajorOperatingSystemVersion */
1184 0, /* MinorOperatingSystemVersion */
1185 1, /* MajorImageVersion */
1186 0, /* MinorImageVersion */
1187 4, /* MajorSubsystemVersion */
1188 0, /* MinorSubsystemVersion */
1189 0, /* Win32VersionValue */
1190 0x200, /* SizeOfImage */
1191 sizeof(dos_header
) + sizeof(nt_header
), /* SizeOfHeaders */
1193 IMAGE_SUBSYSTEM_WINDOWS_CUI
, /* Subsystem */
1194 0, /* DllCharacteristics */
1195 0, /* SizeOfStackReserve */
1196 0, /* SizeOfStackCommit */
1197 0, /* SizeOfHeapReserve */
1198 3, /* SizeOfHeapCommit */
1199 2, /* LoaderFlags */
1200 1, /* NumberOfRvaAndSizes */
1201 { { 0 } } /* DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES] */
1205 static void test_sip(void)
1207 static const WCHAR nameW
[] = {'t','e','s','t','.','e','x','e',0};
1208 SIP_SUBJECTINFO info
;
1209 DWORD index
, encoding
, size
;
1215 file
= CreateFileW(nameW
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1216 ok(file
!= INVALID_HANDLE_VALUE
, "can't create file\n");
1217 if(file
== INVALID_HANDLE_VALUE
)
1219 WriteFile(file
, &dos_header
, sizeof(dos_header
), &size
, NULL
);
1220 WriteFile(file
, &nt_header
, sizeof(nt_header
), &size
, NULL
);
1221 memset(buf
, 0, sizeof(buf
));
1222 WriteFile(file
, buf
, 0x200 - sizeof(dos_header
) - sizeof(nt_header
), &size
, NULL
);
1225 file
= CreateFileW(nameW
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1226 ok(file
!= INVALID_HANDLE_VALUE
, "can't open file\n");
1228 memset(&info
, 0, sizeof(SIP_SUBJECTINFO
));
1229 info
.cbSize
= sizeof(SIP_SUBJECTINFO
);
1230 info
.pgSubjectType
= &guid
;
1231 ret
= CryptSIPRetrieveSubjectGuid(NULL
, file
, info
.pgSubjectType
);
1232 ok(ret
, "CryptSIPRetrieveSubjectGuid failed (%x)\n", GetLastError());
1234 ret
= pPutSignedDataMsg(&info
, X509_ASN_ENCODING
, &index
, 4, (BYTE
*)"test");
1235 ok(!ret
, "CryptSIPPutSignedDataMsg succeedded\n");
1236 index
= GetLastError();
1237 ok(index
== ERROR_PATH_NOT_FOUND
, "GetLastError returned %x\n", index
);
1240 info
.pwsFileName
= nameW
;
1241 ret
= pPutSignedDataMsg(&info
, X509_ASN_ENCODING
, &index
, 4, (BYTE
*)"test");
1242 ok(!ret
, "CryptSIPPutSignedDataMsg succeedded\n");
1243 index
= GetLastError();
1244 todo_wine
ok(index
== ERROR_INVALID_PARAMETER
, "GetLastError returned %x\n", index
);
1246 info
.hFile
= INVALID_HANDLE_VALUE
;
1247 info
.pwsFileName
= nameW
;
1248 ret
= pPutSignedDataMsg(&info
, X509_ASN_ENCODING
, &index
, 4, (BYTE
*)"test");
1249 ok(!ret
, "CryptSIPPutSignedDataMsg succeedded\n");
1250 index
= GetLastError();
1251 ok(index
== ERROR_SHARING_VIOLATION
, "GetLastError returned %x\n", index
);
1254 file
= CreateFileW(nameW
, GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1257 info
.pwsFileName
= (void*)0xdeadbeef;
1258 ret
= pPutSignedDataMsg(&info
, X509_ASN_ENCODING
, &index
, 4, (BYTE
*)"test");
1259 ok(ret
, "CryptSIPPutSignedDataMsg failed (%x)\n", GetLastError());
1260 ok(index
== 0, "index = %x\n", index
);
1263 file
= CreateFileW(nameW
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1265 info
.hFile
= INVALID_HANDLE_VALUE
;
1266 info
.pwsFileName
= nameW
;
1267 ret
= pPutSignedDataMsg(&info
, X509_ASN_ENCODING
, &index
, 14, (BYTE
*)"longer message");
1268 ok(ret
, "CryptSIPPutSignedDataMsg failed (%x)\n", GetLastError());
1269 ok(index
== 1, "index = %x\n", index
);
1272 encoding
= 0xdeadbeef;
1273 ret
= pGetSignedDataMsg(&info
, &encoding
, 0, &size
, NULL
);
1274 ok(ret
, "CryptSIPGetSignedDataMsg failed (%x)\n", GetLastError());
1275 ok(encoding
== 0xdeadbeef, "encoding = %x\n", encoding
);
1276 ok(size
== 16, "size = %d\n", size
);
1278 ret
= pGetSignedDataMsg(&info
, &encoding
, 0, &size
, (BYTE
*)buf
);
1279 ok(ret
, "CryptSIPGetSignedDataMsg failed (%x)\n", GetLastError());
1280 ok(encoding
== (X509_ASN_ENCODING
|PKCS_7_ASN_ENCODING
), "encoding = %x\n", encoding
);
1281 ok(size
== 8, "size = %d\n", size
);
1282 ok(!memcmp(buf
, "test\0\0\0\0", 8), "buf = %s\n", buf
);
1285 encoding
= 0xdeadbeef;
1286 ret
= pGetSignedDataMsg(&info
, &encoding
, 1, &size
, NULL
);
1287 ok(ret
, "CryptSIPGetSignedDataMsg failed (%x)\n", GetLastError());
1288 ok(encoding
== 0xdeadbeef, "encoding = %x\n", encoding
);
1289 ok(size
== 24, "size = %d\n", size
);
1291 ret
= pGetSignedDataMsg(&info
, &encoding
, 1, &size
, (BYTE
*)buf
);
1292 ok(ret
, "CryptSIPGetSignedDataMsg failed (%x)\n", GetLastError());
1293 ok(encoding
== (X509_ASN_ENCODING
|PKCS_7_ASN_ENCODING
), "encoding = %x\n", encoding
);
1294 ok(size
== 16, "size = %d\n", size
);
1295 ok(!strcmp(buf
, "longer message"), "buf = %s\n", buf
);
1297 CryptReleaseContext(info
.hProv
, 0);
1305 char sysdir
[MAX_PATH
];
1309 if (!pCryptCATAdminAcquireContext
)
1311 win_skip("CryptCATAdmin functions are not available\n");
1315 GetSystemDirectoryA(sysdir
, MAX_PATH
);
1316 lstrcpyA(catroot
, sysdir
);
1317 lstrcatA(catroot
, "\\CatRoot");
1318 lstrcpyA(catroot2
, sysdir
);
1319 lstrcatA(catroot2
, "\\CatRoot2");
1321 winetest_get_mainargs(&myARGV
);
1322 strcpy(selfname
, myARGV
[0]);
1324 GetCurrentDirectoryA(MAX_PATH
, CURR_DIR
);
1328 test_CryptCATOpen();
1329 /* Parameter checking only */
1330 test_CryptCATCDF_params();
1331 /* Test the parsing of a cdf file */
1333 /* Create a catalog file out of our own catalog definition file */
1334 test_create_catalog_file();
1335 test_CryptCATAdminAddRemoveCatalog();