1 /* Unit test suite for wintrust crypt functions 2 * 3 * Copyright 2007 Paul Vriens 4 * Copyright 2008 Hans Leidekker for CodeWeavers 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 19 * 20 */ 21 22 #include <stdarg.h> 23 #include <stdio.h> 24 25 #include "windows.h" 26 #include "wincrypt.h" 27 #include "mscat.h" 28 29 #include "wine/test.h" 30 31 static char selfname[MAX_PATH]; 32 static CHAR CURR_DIR[MAX_PATH]; 33 static CHAR catroot[MAX_PATH]; 34 static CHAR catroot2[MAX_PATH]; 35 36 static const WCHAR hashmeW[] = {'h','a','s','h','m','e',0}; 37 static const WCHAR attr1W[] = {'a','t','t','r','1',0}; 38 static const WCHAR attr2W[] = {'a','t','t','r','2',0}; 39 40 /* 41 * Minimalistic catalog file. To reconstruct, save text below as winetest.cdf, 42 * convert to DOS line endings and run 'makecat /cat winetest.cdf' 43 */ 44 45 /* 46 [CatalogHeader] 47 Name=winetest.cat 48 ResultDir=.\ 49 PublicVersion=0x00000001 50 EncodingType= 51 CATATTR1=0x10010001:attr1:value1 52 CATATTR2=0x10010001:attr2:value2 53 54 [CatalogFiles] 55 hashme=.\winetest.cdf 56 */ 57 58 static const CHAR test_cdf[] = 59 "[CatalogHeader]\r\n" 60 "Name=winetest.cat\r\n" 61 "ResultDir=.\\\r\n" 62 "PublicVersion=0x00000001\r\n" 63 "EncodingType=\r\n" 64 "CATATTR1=0x10010001:attr1:value1\r\n" 65 "CATATTR2=0x10010001:attr2:value2\r\n" 66 "\r\n" 67 "[CatalogFiles]\r\n" 68 "hashme=.\\winetest.cdf\r\n"; 69 70 static const BYTE test_catalog[] = { 71 0x30, 0x82, 0x01, 0xbc, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0, 72 0x82, 0x01, 0xad, 0x30, 0x82, 0x01, 0xa9, 0x02, 0x01, 0x01, 0x31, 0x00, 0x30, 0x82, 0x01, 0x9e, 73 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0a, 0x01, 0xa0, 0x82, 0x01, 0x8f, 0x30, 74 0x82, 0x01, 0x8b, 0x30, 0x0c, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x01, 75 0x01, 0x04, 0x10, 0xfa, 0x55, 0x2c, 0xc2, 0xf6, 0xcc, 0xdd, 0x11, 0x2a, 0x9c, 0x00, 0x14, 0x22, 76 0xec, 0x8f, 0x3b, 0x17, 0x0d, 0x30, 0x38, 0x31, 0x32, 0x31, 0x38, 0x31, 0x31, 0x32, 0x36, 0x34, 77 0x38, 0x5a, 0x30, 0x0e, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x01, 0x02, 78 0x05, 0x00, 0x30, 0x81, 0xdd, 0x30, 0x81, 0xda, 0x04, 0x0e, 0x68, 0x00, 0x61, 0x00, 0x73, 0x00, 79 0x68, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x00, 0x00, 0x31, 0x81, 0xc7, 0x30, 0x61, 0x06, 0x0a, 0x2b, 80 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x04, 0x31, 0x53, 0x30, 0x51, 0x30, 0x2c, 0x06, 81 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x19, 0xa2, 0x1e, 0x80, 0x1c, 0x00, 82 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x4f, 0x00, 0x62, 0x00, 0x73, 0x00, 0x6f, 0x00, 0x6c, 0x00, 83 0x65, 0x00, 0x74, 0x00, 0x65, 0x00, 0x3e, 0x00, 0x3e, 0x00, 0x3e, 0x30, 0x21, 0x30, 0x09, 0x06, 84 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14, 0xed, 0xd6, 0x9c, 0x9c, 0xb2, 0xfc, 85 0xaa, 0x03, 0xe8, 0xd3, 0x20, 0xf6, 0xab, 0x28, 0xc3, 0xff, 0xbd, 0x07, 0x36, 0xf5, 0x30, 0x62, 86 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x02, 0x02, 0x31, 0x54, 0x30, 0x52, 87 0x1e, 0x4c, 0x00, 0x7b, 0x00, 0x44, 0x00, 0x45, 0x00, 0x33, 0x00, 0x35, 0x00, 0x31, 0x00, 0x41, 88 0x00, 0x34, 0x00, 0x32, 0x00, 0x2d, 0x00, 0x38, 0x00, 0x45, 0x00, 0x35, 0x00, 0x39, 0x00, 0x2d, 89 0x00, 0x31, 0x00, 0x31, 0x00, 0x44, 0x00, 0x30, 0x00, 0x2d, 0x00, 0x38, 0x00, 0x43, 0x00, 0x34, 90 0x00, 0x37, 0x00, 0x2d, 0x00, 0x30, 0x00, 0x30, 0x00, 0x43, 0x00, 0x30, 0x00, 0x34, 0x00, 0x46, 91 0x00, 0x43, 0x00, 0x32, 0x00, 0x39, 0x00, 0x35, 0x00, 0x45, 0x00, 0x45, 0x00, 0x7d, 0x02, 0x02, 92 0x02, 0x00, 0xa0, 0x6a, 0x30, 0x68, 0x30, 0x32, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 93 0x37, 0x0c, 0x02, 0x01, 0x04, 0x24, 0x30, 0x22, 0x1e, 0x0a, 0x00, 0x61, 0x00, 0x74, 0x00, 0x74, 94 0x00, 0x72, 0x00, 0x32, 0x02, 0x04, 0x10, 0x01, 0x00, 0x01, 0x04, 0x0e, 0x76, 0x00, 0x61, 0x00, 95 0x6c, 0x00, 0x75, 0x00, 0x65, 0x00, 0x32, 0x00, 0x00, 0x00, 0x30, 0x32, 0x06, 0x0a, 0x2b, 0x06, 96 0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x02, 0x01, 0x04, 0x24, 0x30, 0x22, 0x1e, 0x0a, 0x00, 0x61, 97 0x00, 0x74, 0x00, 0x74, 0x00, 0x72, 0x00, 0x31, 0x02, 0x04, 0x10, 0x01, 0x00, 0x01, 0x04, 0x0e, 98 0x76, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x75, 0x00, 0x65, 0x00, 0x31, 0x00, 0x00, 0x00, 0x31, 0x00, 99 }; 100 101 static BOOL (WINAPI * pCryptCATAdminAcquireContext)(HCATADMIN*, const GUID*, DWORD); 102 static BOOL (WINAPI * pCryptCATAdminReleaseContext)(HCATADMIN, DWORD); 103 static BOOL (WINAPI * pCryptCATAdminCalcHashFromFileHandle)(HANDLE hFile, DWORD*, BYTE*, DWORD); 104 static HCATINFO (WINAPI * pCryptCATAdminAddCatalog)(HCATADMIN, PWSTR, PWSTR, DWORD); 105 static BOOL (WINAPI * pCryptCATAdminRemoveCatalog)(HCATADMIN, LPCWSTR, DWORD); 106 static BOOL (WINAPI * pCryptCATAdminReleaseCatalogContext)(HCATADMIN, HCATINFO, DWORD); 107 static HANDLE (WINAPI * pCryptCATOpen)(LPWSTR, DWORD, HCRYPTPROV, DWORD, DWORD); 108 static BOOL (WINAPI * pCryptCATCatalogInfoFromContext)(HCATINFO, CATALOG_INFO *, DWORD); 109 static BOOL (WINAPI * pCryptCATCDFClose)(CRYPTCATCDF *); 110 static CRYPTCATATTRIBUTE * (WINAPI * pCryptCATCDFEnumCatAttributes)(CRYPTCATCDF *, CRYPTCATATTRIBUTE *, 111 PFN_CDF_PARSE_ERROR_CALLBACK); 112 static LPWSTR (WINAPI * pCryptCATCDFEnumMembersByCDFTagEx)(CRYPTCATCDF *, LPWSTR, PFN_CDF_PARSE_ERROR_CALLBACK, 113 CRYPTCATMEMBER **, BOOL, LPVOID); 114 static CRYPTCATCDF * (WINAPI * pCryptCATCDFOpen)(LPWSTR, PFN_CDF_PARSE_ERROR_CALLBACK); 115 static CRYPTCATATTRIBUTE * (WINAPI * pCryptCATEnumerateCatAttr)(HANDLE, CRYPTCATATTRIBUTE *); 116 static CRYPTCATMEMBER * (WINAPI * pCryptCATEnumerateMember)(HANDLE, CRYPTCATMEMBER *); 117 static CRYPTCATATTRIBUTE * (WINAPI * pCryptCATEnumerateAttr)(HANDLE, CRYPTCATMEMBER *, CRYPTCATATTRIBUTE *); 118 static BOOL (WINAPI * pCryptCATClose)(HANDLE); 119 static pCryptSIPGetSignedDataMsg pGetSignedDataMsg; 120 static pCryptSIPPutSignedDataMsg pPutSignedDataMsg; 121 122 static void InitFunctionPtrs(void) 123 { 124 HMODULE hWintrust = GetModuleHandleA("wintrust.dll"); 125 126 #define WINTRUST_GET_PROC(func) \ 127 p ## func = (void*)GetProcAddress(hWintrust, #func); \ 128 if(!p ## func) { \ 129 trace("GetProcAddress(%s) failed\n", #func); \ 130 } 131 132 WINTRUST_GET_PROC(CryptCATAdminAcquireContext) 133 WINTRUST_GET_PROC(CryptCATAdminReleaseContext) 134 WINTRUST_GET_PROC(CryptCATAdminCalcHashFromFileHandle) 135 WINTRUST_GET_PROC(CryptCATAdminAddCatalog) 136 WINTRUST_GET_PROC(CryptCATAdminRemoveCatalog) 137 WINTRUST_GET_PROC(CryptCATAdminReleaseCatalogContext) 138 WINTRUST_GET_PROC(CryptCATOpen) 139 WINTRUST_GET_PROC(CryptCATCatalogInfoFromContext) 140 WINTRUST_GET_PROC(CryptCATCDFClose) 141 WINTRUST_GET_PROC(CryptCATCDFEnumCatAttributes) 142 WINTRUST_GET_PROC(CryptCATCDFEnumMembersByCDFTagEx) 143 WINTRUST_GET_PROC(CryptCATCDFOpen) 144 WINTRUST_GET_PROC(CryptCATEnumerateCatAttr) 145 WINTRUST_GET_PROC(CryptCATEnumerateMember) 146 WINTRUST_GET_PROC(CryptCATEnumerateAttr) 147 WINTRUST_GET_PROC(CryptCATClose) 148 149 #undef WINTRUST_GET_PROC 150 151 pGetSignedDataMsg = (void*)GetProcAddress(hWintrust, "CryptSIPGetSignedDataMsg"); 152 if(!pGetSignedDataMsg) 153 trace("GetProcAddress(CryptSIPGetSignedDataMsg) failed\n"); 154 155 pPutSignedDataMsg = (void*)GetProcAddress(hWintrust, "CryptSIPPutSignedDataMsg"); 156 if(!pPutSignedDataMsg) 157 trace("GetProcAddress(CryptSIPPutSignedDataMsg) failed\n"); 158 } 159 160 static GUID dummy = {0xdeadbeef,0xdead,0xbeef,{0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}}; 161 162 static void test_context(void) 163 { 164 BOOL ret; 165 HCATADMIN hca; 166 static GUID unknown = { 0xC689AABA, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }}; /* WINTRUST.DLL */ 167 CHAR dummydir[MAX_PATH]; 168 DWORD attrs; 169 170 /* When CryptCATAdminAcquireContext is successful it will create 171 * several directories if they don't exist: 172 * 173 * ...\system32\CatRoot\{GUID}, this directory holds the .cat files 174 * ...\system32\CatRoot2\{GUID} (WinXP and up), here we find the catalog database for that GUID 175 * 176 * Windows Vista uses lowercase catroot and catroot2. 177 * 178 * When passed a NULL GUID it will create the following directories although on 179 * WinXP and up these directories are already present when Windows is installed: 180 * 181 * ...\system32\CatRoot\{127D0A1D-4EF2-11D1-8608-00C04FC295EE} 182 * ...\system32\CatRoot2\{127D0A1D-4EF2-11D1-8608-00C04FC295EE} (WinXP up) 183 * 184 * TODO: Find out what this GUID is/does. 185 * 186 * On WinXP and up there is also a TimeStamp file in some of directories that 187 * seem to indicate the last change to the catalog database for that GUID. 188 * 189 * On Windows 2000 some files are created/updated: 190 * 191 * ...\system32\CatRoot\SYSMAST.cbk 192 * ...\system32\CatRoot\SYSMAST.cbd 193 * ...\system32\CatRoot\{GUID}\CATMAST.cbk 194 * ...\system32\CatRoot\{GUID}\CATMAST.cbd 195 * 196 */ 197 198 /* All NULL */ 199 SetLastError(0xdeadbeef); 200 ret = pCryptCATAdminAcquireContext(NULL, NULL, 0); 201 ok(!ret, "Expected failure\n"); 202 ok(GetLastError() == ERROR_INVALID_PARAMETER, 203 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); 204 205 /* NULL GUID */ 206 if (0) { /* crashes on 64-bit win10 */ 207 ret = pCryptCATAdminAcquireContext(&hca, NULL, 0); 208 ok(ret, "Expected success, got FALSE with %d\n", GetLastError()); 209 ok(hca != NULL, "Expected a context handle, got NULL\n"); 210 211 /* Proper release */ 212 SetLastError(0xdeadbeef); 213 ret = pCryptCATAdminReleaseContext(hca, 0); 214 ok(ret, "Expected success, got FALSE with %d\n", GetLastError()); 215 216 /* Try to release a second time */ 217 SetLastError(0xdeadbeef); 218 ret = pCryptCATAdminReleaseContext(hca, 0); 219 ok(!ret, "Expected failure\n"); 220 ok(GetLastError() == ERROR_INVALID_PARAMETER, 221 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); 222 } 223 224 /* All NULL */ 225 SetLastError(0xdeadbeef); 226 ret = pCryptCATAdminReleaseContext(NULL, 0); 227 ok(!ret, "Expected failure\n"); 228 ok(GetLastError() == ERROR_INVALID_PARAMETER, 229 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); 230 231 /* NULL context handle and dummy GUID */ 232 SetLastError(0xdeadbeef); 233 ret = pCryptCATAdminAcquireContext(NULL, &dummy, 0); 234 ok(!ret, "Expected failure\n"); 235 ok(GetLastError() == ERROR_INVALID_PARAMETER, 236 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); 237 238 /* Correct context handle and dummy GUID 239 * 240 * The tests run in the past unfortunately made sure that some directories were created. 241 * 242 * FIXME: 243 * We don't want to mess too much with these for now so we should delete only the ones 244 * that shouldn't be there like the deadbeef ones. We first have to figure out if it's 245 * safe to remove files and directories from CatRoot/CatRoot2. 246 */ 247 248 ret = pCryptCATAdminAcquireContext(&hca, &dummy, 0); 249 ok(ret || GetLastError() == ERROR_ACCESS_DENIED, "CryptCATAdminAcquireContext failed %u\n", GetLastError()); 250 if (!ret && GetLastError() == ERROR_ACCESS_DENIED) 251 { 252 win_skip("Not running as administrator\n"); 253 return; 254 } 255 ok(hca != NULL, "Expected a context handle, got NULL\n"); 256 257 attrs = GetFileAttributesA(catroot); 258 ok(attrs != INVALID_FILE_ATTRIBUTES, "Expected the CatRoot directory to exist\n"); 259 260 /* Windows creates the GUID directory in capitals */ 261 lstrcpyA(dummydir, catroot); 262 lstrcatA(dummydir, "\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}"); 263 attrs = GetFileAttributesA(dummydir); 264 ok(attrs != INVALID_FILE_ATTRIBUTES, 265 "Expected CatRoot\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF} directory to exist\n"); 266 267 /* Only present on XP or higher. */ 268 attrs = GetFileAttributesA(catroot2); 269 if (attrs != INVALID_FILE_ATTRIBUTES) 270 { 271 lstrcpyA(dummydir, catroot2); 272 lstrcatA(dummydir, "\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}"); 273 attrs = GetFileAttributesA(dummydir); 274 ok(attrs != INVALID_FILE_ATTRIBUTES, 275 "Expected CatRoot2\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF} directory to exist\n"); 276 } 277 278 ret = pCryptCATAdminReleaseContext(hca, 0); 279 ok(ret, "Expected success, got FALSE with %d\n", GetLastError()); 280 281 /* Correct context handle and GUID */ 282 ret = pCryptCATAdminAcquireContext(&hca, &unknown, 0); 283 ok(ret, "Expected success, got FALSE with %d\n", GetLastError()); 284 ok(hca != NULL, "Expected a context handle, got NULL\n"); 285 286 ret = pCryptCATAdminReleaseContext(hca, 0); 287 ok(ret, "Expected success, got FALSE with %d\n", GetLastError()); 288 289 hca = (void *) 0xdeadbeef; 290 SetLastError(0xdeadbeef); 291 /* Flags is documented as unused, but the parameter is checked since win8 */ 292 ret = pCryptCATAdminAcquireContext(&hca, &unknown, 1); 293 ok((!ret && (GetLastError() == ERROR_INVALID_PARAMETER) && (hca == (void *) 0xdeadbeef)) || 294 broken(ret && hca != NULL && hca != (void *) 0xdeadbeef), 295 "Expected FALSE and ERROR_INVALID_PARAMETER with untouched handle, got %d and %u with %p\n", 296 ret, GetLastError(), hca); 297 298 if (ret && hca) 299 { 300 SetLastError(0xdeadbeef); 301 ret = pCryptCATAdminReleaseContext(hca, 0); 302 ok(ret, "Expected success, got FALSE with %d\n", GetLastError()); 303 } 304 } 305 306 /* TODO: Check whether SHA-1 is the algorithm that's always used */ 307 static void test_calchash(void) 308 { 309 BOOL ret; 310 HANDLE file; 311 DWORD hashsize = 0; 312 BYTE* hash; 313 BYTE expectedhash[20] = {0x3a,0xa1,0x19,0x08,0xec,0xa6,0x0d,0x2e,0x7e,0xcc,0x7a,0xca,0xf5,0xb8,0x2e,0x62,0x6a,0xda,0xf0,0x19}; 314 CHAR temp[MAX_PATH]; 315 DWORD written; 316 317 /* All NULL */ 318 SetLastError(0xdeadbeef); 319 ret = pCryptCATAdminCalcHashFromFileHandle(NULL, NULL, NULL, 0); 320 ok(!ret, "Expected failure\n"); 321 ok(GetLastError() == ERROR_INVALID_PARAMETER, 322 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); 323 324 /* NULL filehandle, rest is legal */ 325 SetLastError(0xdeadbeef); 326 ret = pCryptCATAdminCalcHashFromFileHandle(NULL, &hashsize, NULL, 0); 327 ok(!ret, "Expected failure\n"); 328 ok(GetLastError() == ERROR_INVALID_PARAMETER, 329 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); 330 331 /* Correct filehandle, rest is NULL */ 332 file = CreateFileA(selfname, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); 333 SetLastError(0xdeadbeef); 334 ret = pCryptCATAdminCalcHashFromFileHandle(file, NULL, NULL, 0); 335 ok(!ret, "Expected failure\n"); 336 ok(GetLastError() == ERROR_INVALID_PARAMETER, 337 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); 338 CloseHandle(file); 339 340 /* All OK, but dwFlags set to 1 */ 341 file = CreateFileA(selfname, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); 342 SetLastError(0xdeadbeef); 343 ret = pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, NULL, 1); 344 ok(!ret, "Expected failure\n"); 345 ok(GetLastError() == ERROR_INVALID_PARAMETER, 346 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); 347 CloseHandle(file); 348 349 /* All OK, requesting the size of the hash */ 350 file = CreateFileA(selfname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); 351 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed %u\n", GetLastError()); 352 SetLastError(0xdeadbeef); 353 ret = pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, NULL, 0); 354 ok(ret, "Expected success, got FALSE with %d\n", GetLastError()); 355 ok(hashsize == 20," Expected a hash size of 20, got %d\n", hashsize); 356 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, 357 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError()); 358 CloseHandle(file); 359 360 /* All OK, retrieve the hash 361 * Double the hash buffer to see what happens to the size parameter 362 */ 363 file = CreateFileA(selfname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); 364 hashsize *= 2; 365 hash = HeapAlloc(GetProcessHeap(), 0, hashsize); 366 SetLastError(0xdeadbeef); 367 ret = pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, hash, 0); 368 ok(ret, "Expected success, got FALSE with %d\n", GetLastError()); 369 ok(hashsize == 20," Expected a hash size of 20, got %d\n", hashsize); 370 ok(GetLastError() == ERROR_SUCCESS, 371 "Expected ERROR_SUCCESS, got %d\n", GetLastError()); 372 CloseHandle(file); 373 HeapFree(GetProcessHeap(), 0, hash); 374 375 /* Do the same test with a file created and filled by ourselves (and we thus 376 * have a known hash for). 377 */ 378 GetTempFileNameA(CURR_DIR, "hsh", 0, temp); 379 file = CreateFileA(temp, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); 380 WriteFile(file, "Text in this file is needed to create a know hash", 49, &written, NULL); 381 CloseHandle(file); 382 383 /* All OK, first request the size and then retrieve the hash */ 384 file = CreateFileA(temp, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); 385 hashsize = 0; 386 pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, NULL, 0); 387 hash = HeapAlloc(GetProcessHeap(), 0, hashsize); 388 SetLastError(0xdeadbeef); 389 ret = pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, hash, 0); 390 ok(ret, "Expected success, got FALSE with %d\n", GetLastError()); 391 ok(GetLastError() == ERROR_SUCCESS, 392 "Expected ERROR_SUCCESS, got %d\n", GetLastError()); 393 ok(hashsize == sizeof(expectedhash) && 394 !memcmp(hash, expectedhash, sizeof(expectedhash)), 395 "Hashes didn't match\n"); 396 CloseHandle(file); 397 398 HeapFree(GetProcessHeap(), 0, hash); 399 DeleteFileA(temp); 400 } 401 402 static void test_CryptCATOpen(void) 403 { 404 HANDLE hcat; 405 char empty[MAX_PATH]; 406 WCHAR emptyW[MAX_PATH]; 407 HANDLE file; 408 BOOL ret; 409 410 SetLastError(0xdeadbeef); 411 hcat = pCryptCATOpen(NULL, 0, 0, 0, 0); 412 ok(hcat == INVALID_HANDLE_VALUE, "CryptCATOpen succeeded\n"); 413 ok(GetLastError() == ERROR_INVALID_PARAMETER, 414 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError()); 415 416 if (!GetTempFileNameA(CURR_DIR, "cat", 0, empty)) return; 417 418 file = CreateFileA(empty, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); 419 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %u\n", GetLastError()); 420 CloseHandle(file); 421 MultiByteToWideChar(CP_ACP, 0, empty, -1, emptyW, MAX_PATH); 422 423 hcat = pCryptCATOpen(emptyW, 0, 0, 0, 0); 424 todo_wine 425 ok(hcat != INVALID_HANDLE_VALUE, "Expected a correct handle\n"); 426 427 ret = pCryptCATClose(hcat); 428 todo_wine 429 ok(ret, "CryptCATClose failed\n"); 430 DeleteFileA(empty); 431 } 432 433 static DWORD error_area; 434 static DWORD local_error; 435 436 static void WINAPI cdf_callback(DWORD area, DWORD error, WCHAR* line) 437 { 438 ok(error_area != -2, "Didn't expect cdf_callback() to be called (%08x, %08x)\n", 439 area, error); 440 441 error_area = area; 442 local_error = error; 443 } 444 445 static void test_CryptCATCDF_params(void) 446 { 447 static WCHAR nonexistent[] = {'d','e','a','d','b','e','e','f','.','c','d','f',0}; 448 CRYPTCATCDF *catcdf; 449 BOOL ret; 450 451 if (!pCryptCATCDFOpen) 452 { 453 win_skip("CryptCATCDFOpen is not available\n"); 454 return; 455 } 456 457 SetLastError(0xdeadbeef); 458 catcdf = pCryptCATCDFOpen(NULL, NULL); 459 ok(catcdf == NULL, "CryptCATCDFOpen succeeded\n"); 460 todo_wine 461 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); 462 463 SetLastError(0xdeadbeef); 464 catcdf = pCryptCATCDFOpen(NULL, cdf_callback); 465 ok(catcdf == NULL, "CryptCATCDFOpen succeeded\n"); 466 todo_wine 467 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); 468 469 /* File doesn't exist */ 470 SetLastError(0xdeadbeef); 471 catcdf = pCryptCATCDFOpen(nonexistent, cdf_callback); 472 ok(catcdf == NULL, "CryptCATCDFOpen succeeded\n"); 473 todo_wine 474 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); 475 476 SetLastError(0xdeadbeef); 477 ret = pCryptCATCDFClose(NULL); 478 ok(!ret, "Expected failure\n"); 479 todo_wine 480 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); 481 482 catcdf = NULL; 483 SetLastError(0xdeadbeef); 484 ret = pCryptCATCDFClose(catcdf); 485 ok(!ret, "Expected failure\n"); 486 todo_wine 487 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); 488 } 489 490 /* FIXME: Once Wine can create catalog files we should use the created catalog file in this test */ 491 static void test_CryptCATAdminAddRemoveCatalog(void) 492 { 493 static WCHAR basenameW[] = {'w','i','n','e','t','e','s','t','.','c','a','t',0}; 494 static const char basename[] = "winetest.cat"; 495 HCATADMIN hcatadmin; 496 HCATINFO hcatinfo; 497 CATALOG_INFO info; 498 WCHAR tmpfileW[MAX_PATH]; 499 char tmpfile[MAX_PATH]; 500 char catfile[MAX_PATH], catfilepath[MAX_PATH], *p; 501 WCHAR catfileW[MAX_PATH]; 502 HANDLE file; 503 DWORD error, written; 504 BOOL ret; 505 DWORD attrs; 506 507 if (!pCryptCATAdminRemoveCatalog) 508 { 509 /* NT4 and W2K do have CryptCATAdminAddCatalog !! */ 510 win_skip("CryptCATAdminRemoveCatalog is not available\n"); 511 return; 512 } 513 514 if (!GetTempFileNameA(CURR_DIR, "cat", 0, tmpfile)) return; 515 DeleteFileA(tmpfile); 516 file = CreateFileA(tmpfile, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL); 517 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %u\n", GetLastError()); 518 CloseHandle(file); 519 520 ret = pCryptCATAdminAcquireContext(&hcatadmin, &dummy, 0); 521 ok(ret || GetLastError() == ERROR_ACCESS_DENIED, "CryptCATAdminAcquireContext failed %u\n", GetLastError()); 522 if (!ret && GetLastError() == ERROR_ACCESS_DENIED) 523 { 524 win_skip("Not running as administrator\n"); 525 return; 526 } 527 528 SetLastError(0xdeadbeef); 529 hcatinfo = pCryptCATAdminAddCatalog(NULL, NULL, NULL, 0); 530 error = GetLastError(); 531 ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n"); 532 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", GetLastError()); 533 534 SetLastError(0xdeadbeef); 535 hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, NULL, NULL, 0); 536 error = GetLastError(); 537 ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n"); 538 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", GetLastError()); 539 540 MultiByteToWideChar(CP_ACP, 0, tmpfile, -1, tmpfileW, MAX_PATH); 541 542 SetLastError(0xdeadbeef); 543 hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, basenameW, 0); 544 error = GetLastError(); 545 todo_wine { 546 ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n"); 547 ok(error == ERROR_BAD_FORMAT, "got %u expected ERROR_BAD_FORMAT\n", GetLastError()); 548 } 549 if (hcatinfo != NULL) 550 pCryptCATAdminReleaseCatalogContext(hcatadmin, hcatinfo, 0); 551 552 SetLastError(0xdeadbeef); 553 hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, basenameW, 1); 554 error = GetLastError(); 555 ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n"); 556 ok(error == ERROR_INVALID_PARAMETER || 557 error == ERROR_BAD_FORMAT, /* win 8 */ 558 "got %u\n", GetLastError()); 559 560 SetLastError(0xdeadbeef); 561 hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, NULL, 0); 562 error = GetLastError(); 563 ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n"); 564 todo_wine ok(error == ERROR_BAD_FORMAT, "got %u expected ERROR_BAD_FORMAT\n", GetLastError()); 565 566 DeleteFileA(tmpfile); 567 file = CreateFileA(tmpfile, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL); 568 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %u\n", GetLastError()); 569 WriteFile(file, test_catalog, sizeof(test_catalog), &written, NULL); 570 CloseHandle(file); 571 572 /* Unique name will be created */ 573 hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, NULL, 0); 574 if (!hcatinfo && (GetLastError() == ERROR_ACCESS_DENIED)) 575 { 576 win_skip("Not enough rights\n"); 577 goto cleanup; 578 } 579 todo_wine ok(hcatinfo != NULL, "CryptCATAdminAddCatalog failed %u\n", GetLastError()); 580 581 info.cbStruct = sizeof(info); 582 info.wszCatalogFile[0] = 0; 583 ret = pCryptCATCatalogInfoFromContext(hcatinfo, &info, 0); 584 todo_wine 585 { 586 ok(ret, "CryptCATCatalogInfoFromContext failed %u\n", GetLastError()); 587 ok(info.wszCatalogFile[0] != 0, "Expected a filename\n"); 588 } 589 WideCharToMultiByte(CP_ACP, 0, info.wszCatalogFile, -1, catfile, MAX_PATH, NULL, NULL); 590 if ((p = strrchr(catfile, '\\'))) p++; 591 memset(catfileW, 0, sizeof(catfileW)); 592 MultiByteToWideChar(CP_ACP, 0, p, -1, catfileW, MAX_PATH); 593 594 /* Set the file attributes so we can check what happens with them during the 'copy' */ 595 attrs = FILE_ATTRIBUTE_READONLY; 596 ret = SetFileAttributesA(tmpfile, attrs); 597 ok(ret, "SetFileAttributesA failed : %u\n", GetLastError()); 598 599 /* winetest.cat will be created */ 600 hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, basenameW, 0); 601 ok(hcatinfo != NULL, "CryptCATAdminAddCatalog failed %u\n", GetLastError()); 602 603 lstrcpyA(catfilepath, catroot); 604 lstrcatA(catfilepath, "\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}\\winetest.cat"); 605 attrs = GetFileAttributesA(catfilepath); 606 ok(attrs != INVALID_FILE_ATTRIBUTES, "Expected %s to exist\n", catfilepath); 607 todo_wine 608 ok(attrs == FILE_ATTRIBUTE_SYSTEM || 609 attrs == (FILE_ATTRIBUTE_NOT_CONTENT_INDEXED | FILE_ATTRIBUTE_SYSTEM), /* Vista */ 610 "File has wrong attributes : %08x\n", attrs); 611 612 info.cbStruct = sizeof(info); 613 info.wszCatalogFile[0] = 0; 614 ret = pCryptCATCatalogInfoFromContext(hcatinfo, &info, 0); 615 ok(ret, "CryptCATCatalogInfoFromContext failed %u\n", GetLastError()); 616 ok(info.wszCatalogFile[0] != 0, "Expected a filename\n"); 617 WideCharToMultiByte(CP_ACP, 0, info.wszCatalogFile, -1, catfile, MAX_PATH, NULL, NULL); 618 if ((p = strrchr(catfile, '\\'))) p++; 619 ok(!lstrcmpA(basename, p), "Expected %s, got %s\n", basename, p); 620 621 ret = pCryptCATAdminReleaseCatalogContext(hcatadmin, hcatinfo, 0); 622 ok(ret, "CryptCATAdminReleaseCatalogContext failed %u\n", GetLastError()); 623 624 /* Remove the catalog file with the unique name */ 625 ret = pCryptCATAdminRemoveCatalog(hcatadmin, catfileW, 0); 626 ok(ret, "CryptCATAdminRemoveCatalog failed %u\n", GetLastError()); 627 628 /* Remove the winetest.cat catalog file, first with the full path. This should not succeed 629 * according to MSDN */ 630 ret = pCryptCATAdminRemoveCatalog(hcatadmin, info.wszCatalogFile, 0); 631 ok(ret, "CryptCATAdminRemoveCatalog failed %u\n", GetLastError()); 632 /* The call succeeded with the full path but the file is not removed */ 633 attrs = GetFileAttributesA(catfilepath); 634 ok(attrs != INVALID_FILE_ATTRIBUTES, "Expected %s to exist\n", catfilepath); 635 /* Given only the filename the file is removed */ 636 ret = pCryptCATAdminRemoveCatalog(hcatadmin, basenameW, 0); 637 ok(ret, "CryptCATAdminRemoveCatalog failed %u\n", GetLastError()); 638 attrs = GetFileAttributesA(catfilepath); 639 ok(attrs == INVALID_FILE_ATTRIBUTES, "Expected %s to be removed\n", catfilepath); 640 641 cleanup: 642 ret = pCryptCATAdminReleaseContext(hcatadmin, 0); 643 ok(ret, "CryptCATAdminReleaseContext failed %u\n", GetLastError()); 644 645 /* Set the attributes so we can delete the file */ 646 attrs = FILE_ATTRIBUTE_NORMAL; 647 ret = SetFileAttributesA(tmpfile, attrs); 648 ok(ret, "SetFileAttributesA failed %u\n", GetLastError()); 649 DeleteFileA(tmpfile); 650 } 651 652 static void test_catalog_properties(const char *catfile, int attributes, int members) 653 { 654 static const GUID subject = {0xde351a42,0x8e59,0x11d0,{0x8c,0x47,0x00,0xc0,0x4f,0xc2,0x95,0xee}}; 655 656 HANDLE hcat; 657 CRYPTCATMEMBER *m; 658 CRYPTCATATTRIBUTE *attr; 659 char catalog[MAX_PATH]; 660 WCHAR catalogW[MAX_PATH]; 661 DWORD attrs; 662 BOOL ret; 663 int attrcount = 0, membercount = 0; 664 665 /* FIXME: Wine can't create catalog files out of catalog definition files yet. Remove this piece 666 * once wine is fixed 667 */ 668 attrs = GetFileAttributesA(catfile); 669 if (attrs == INVALID_FILE_ATTRIBUTES) 670 { 671 HANDLE file; 672 DWORD written; 673 674 trace("Creating the catalog file\n"); 675 if (!GetTempFileNameA(CURR_DIR, "cat", 0, catalog)) return; 676 file = CreateFileA(catalog, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); 677 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %u\n", GetLastError()); 678 WriteFile(file, test_catalog, sizeof(test_catalog), &written, NULL); 679 CloseHandle(file); 680 681 attributes = 2; 682 members = 1; 683 MultiByteToWideChar(CP_ACP, 0, catalog, -1, catalogW, MAX_PATH); 684 } 685 else 686 { 687 MultiByteToWideChar(CP_ACP, 0, catfile, -1, catalogW, MAX_PATH); 688 catalog[0] = 0; 689 } 690 691 hcat = pCryptCATOpen(catalogW, 0, 0, 0, 0); 692 if (hcat == INVALID_HANDLE_VALUE && members == 0) 693 { 694 win_skip("CryptCATOpen on W2K can't handle catalog files with no members\n"); 695 return; 696 } 697 ok(hcat != INVALID_HANDLE_VALUE, "CryptCATOpen failed %u\n", GetLastError()); 698 699 m = pCryptCATEnumerateMember(NULL, NULL); 700 ok(m == NULL, "CryptCATEnumerateMember succeeded\n"); 701 702 m = NULL; 703 while ((m = pCryptCATEnumerateMember(hcat, m))) 704 { 705 ok(m->cbStruct == sizeof(CRYPTCATMEMBER), "unexpected size %u\n", m->cbStruct); 706 todo_wine ok(!lstrcmpW(m->pwszReferenceTag, hashmeW), "unexpected tag\n"); 707 ok(!memcmp(&m->gSubjectType, &subject, sizeof(subject)), "guid differs\n"); 708 ok(!m->fdwMemberFlags, "got %x expected 0\n", m->fdwMemberFlags); 709 ok(m->dwCertVersion == 0x200, "got %x expected 0x200\n", m->dwCertVersion); 710 ok(!m->dwReserved, "got %x expected 0\n", m->dwReserved); 711 ok(m->hReserved == NULL, "got %p expected NULL\n", m->hReserved); 712 713 attr = pCryptCATEnumerateAttr(hcat, m, NULL); 714 ok(attr == NULL, "CryptCATEnumerateAttr succeeded\n"); 715 716 membercount++; 717 } 718 ok(membercount == members, "Expected %d members, got %d\n", members, membercount); 719 720 attr = pCryptCATEnumerateAttr(NULL, NULL, NULL); 721 ok(attr == NULL, "CryptCATEnumerateAttr succeeded\n"); 722 723 attr = pCryptCATEnumerateAttr(hcat, NULL, NULL); 724 ok(attr == NULL, "CryptCATEnumerateAttr succeeded\n"); 725 726 attr = NULL; 727 while ((attr = pCryptCATEnumerateCatAttr(hcat, attr))) 728 { 729 ok(!lstrcmpW(attr->pwszReferenceTag, attr1W) || 730 !lstrcmpW(attr->pwszReferenceTag, attr2W), 731 "Expected 'attr1' or 'attr2'\n"); 732 733 attrcount++; 734 } 735 todo_wine 736 ok(attrcount == attributes, "Expected %d catalog attributes, got %d\n", attributes, attrcount); 737 738 ret = pCryptCATClose(hcat); 739 ok(ret, "CryptCATClose failed\n"); 740 if (catalog[0]) DeleteFileA( catalog ); 741 } 742 743 static void test_create_catalog_file(void) 744 { 745 static const char catfileA[] = "winetest.cat"; 746 static const char cdffileA[] = "winetest.cdf"; 747 static WCHAR cdffileW[] = {'w','i','n','e','t','e','s','t','.','c','d','f',0}; 748 CRYPTCATCDF *catcdf; 749 CRYPTCATATTRIBUTE *catattr; 750 CRYPTCATMEMBER *catmember; 751 WCHAR *catmembertag; 752 DWORD written, attrs; 753 HANDLE file; 754 BOOL ret; 755 int attrcount, membercount; 756 757 if (!pCryptCATCDFOpen) 758 { 759 win_skip("CryptCATCDFOpen is not available\n"); 760 return; 761 } 762 763 /* Create the cdf file */ 764 file = CreateFileA(cdffileA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 765 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %u\n", GetLastError()); 766 WriteFile(file, test_cdf, sizeof(test_cdf) - 1, &written, NULL); 767 CloseHandle(file); 768 769 /* Don't enumerate attributes and members */ 770 trace("No attribs and members\n"); 771 SetLastError(0xdeadbeef); 772 catcdf = pCryptCATCDFOpen(cdffileW, NULL); 773 todo_wine 774 { 775 ok(catcdf != NULL, "CryptCATCDFOpen failed\n"); 776 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); 777 } 778 779 ret = pCryptCATCDFClose(catcdf); 780 todo_wine 781 { 782 ok(ret, "Expected success, got FALSE with %d\n", GetLastError()); 783 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); 784 } 785 786 attrs = GetFileAttributesA(catfileA); 787 todo_wine 788 ok(attrs != INVALID_FILE_ATTRIBUTES, "Expected the catalog file to exist\n"); 789 790 test_catalog_properties(catfileA, 0, 0); 791 DeleteFileA(catfileA); 792 793 /* Only enumerate the attributes */ 794 trace("Only attributes\n"); 795 attrcount = 0; 796 catcdf = pCryptCATCDFOpen(cdffileW, NULL); 797 798 catattr = NULL; 799 while ((catattr = pCryptCATCDFEnumCatAttributes(catcdf, catattr, NULL))) 800 { 801 ok(!lstrcmpW(catattr->pwszReferenceTag, attr1W) || 802 !lstrcmpW(catattr->pwszReferenceTag, attr2W), 803 "Expected 'attr1' or 'attr2'\n"); 804 805 attrcount++; 806 } 807 todo_wine 808 ok(attrcount == 2, "Expected 2 attributes, got %d\n", attrcount); 809 810 pCryptCATCDFClose(catcdf); 811 /* Even though the resulting catalog file shows the attributes, they will not be enumerated */ 812 test_catalog_properties(catfileA, 0, 0); 813 DeleteFileA(catfileA); 814 815 /* Only enumerate the members */ 816 trace("Only members\n"); 817 membercount = 0; 818 catcdf = pCryptCATCDFOpen(cdffileW, NULL); 819 820 catmember = NULL; 821 catmembertag = NULL; 822 while ((catmembertag = pCryptCATCDFEnumMembersByCDFTagEx(catcdf, catmembertag, NULL, &catmember, FALSE, NULL))) 823 { 824 ok(!lstrcmpW(catmembertag, hashmeW), "Expected 'hashme'\n"); 825 membercount++; 826 } 827 todo_wine 828 ok(membercount == 1, "Expected 1 member, got %d\n", membercount); 829 830 pCryptCATCDFClose(catcdf); 831 test_catalog_properties(catfileA, 0, 1); 832 DeleteFileA(catfileA); 833 834 /* Enumerate members and attributes */ 835 trace("Attributes and members\n"); 836 attrcount = membercount = 0; 837 catcdf = pCryptCATCDFOpen(cdffileW, NULL); 838 839 catattr = NULL; 840 while ((catattr = pCryptCATCDFEnumCatAttributes(catcdf, catattr, NULL))) 841 attrcount++; 842 todo_wine 843 ok(attrcount == 2, "Expected 2 attributes, got %d\n", attrcount); 844 845 catmember = NULL; 846 catmembertag = NULL; 847 while ((catmembertag = pCryptCATCDFEnumMembersByCDFTagEx(catcdf, catmembertag, NULL, &catmember, FALSE, NULL))) 848 membercount++; 849 todo_wine 850 ok(membercount == 1, "Expected 1 member, got %d\n", membercount); 851 852 pCryptCATCDFClose(catcdf); 853 test_catalog_properties(catfileA, 2, 1); 854 DeleteFileA(catfileA); 855 856 DeleteFileA(cdffileA); 857 } 858 859 static void create_cdf_file(const CHAR *filename, const CHAR *contents) 860 { 861 HANDLE file; 862 DWORD written; 863 864 file = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 865 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %u\n", GetLastError()); 866 WriteFile(file, contents, lstrlenA(contents), &written, NULL); 867 CloseHandle(file); 868 } 869 870 #define CHECK_EXPECT(a, b) \ 871 do { \ 872 ok(a == error_area, "Expected %08x, got %08x\n", a, error_area); \ 873 ok(b == local_error, "Expected %08x, got %08x\n", b, local_error); \ 874 } while (0) 875 876 /* Clear the variables (can't use 0) */ 877 #define CLEAR_EXPECT \ 878 error_area = local_error = -1 879 880 /* Set both variables so the callback routine can check if a call to it was unexpected */ 881 #define SET_UNEXPECTED \ 882 error_area = local_error = -2 883 884 static void test_cdf_parsing(void) 885 { 886 static const char catfileA[] = "tempfile.cat"; 887 static const char cdffileA[] = "tempfile.cdf"; 888 static WCHAR cdffileW[] = {'t','e','m','p','f','i','l','e','.','c','d','f',0}; 889 CHAR cdf_contents[4096]; 890 CRYPTCATCDF *catcdf; 891 CRYPTCATATTRIBUTE *catattr; 892 CRYPTCATMEMBER *catmember; 893 WCHAR *catmembertag; 894 895 if (!pCryptCATCDFOpen) 896 { 897 win_skip("CryptCATCDFOpen is not available\n"); 898 return; 899 } 900 901 /* Empty file */ 902 DeleteFileA(cdffileA); 903 create_cdf_file(cdffileA, ""); 904 905 CLEAR_EXPECT; 906 SetLastError(0xdeadbeef); 907 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback); 908 todo_wine 909 CHECK_EXPECT(CRYPTCAT_E_AREA_HEADER, CRYPTCAT_E_CDF_TAGNOTFOUND); 910 ok(catcdf == NULL, "CryptCATCDFOpen succeeded\n"); 911 todo_wine 912 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); 913 DeleteFileA(cdffileA); 914 ok(!DeleteFileA(catfileA), "Didn't expect a catalog file to be created\n"); 915 916 /* Just the header */ 917 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n"); 918 create_cdf_file(cdffileA, cdf_contents); 919 920 SET_UNEXPECTED; 921 SetLastError(0xdeadbeef); 922 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback); 923 ok(catcdf == NULL, "CryptCATCDFOpen succeeded\n"); 924 todo_wine 925 ok(GetLastError() == ERROR_SHARING_VIOLATION, 926 "Expected ERROR_SHARING_VIOLATION, got %d\n", GetLastError()); 927 DeleteFileA(cdffileA); 928 929 /* Header and member only */ 930 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n"); 931 lstrcatA(cdf_contents, "[CatalogFiles]\r\n"); 932 lstrcatA(cdf_contents, "hashme=.\\tempfile.cdf\r\n"); 933 create_cdf_file(cdffileA, cdf_contents); 934 935 SET_UNEXPECTED; 936 SetLastError(0xdeadbeef); 937 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback); 938 ok(catcdf == NULL, "CryptCATCDFOpen succeeded\n"); 939 todo_wine 940 ok(GetLastError() == ERROR_SHARING_VIOLATION, 941 "Expected ERROR_SHARING_VIOLATION, got %d\n", GetLastError()); 942 DeleteFileA(cdffileA); 943 ok(!DeleteFileA(catfileA), "Didn't expect a catalog file to be created\n"); 944 945 /* Header and Name (no value) */ 946 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n"); 947 lstrcatA(cdf_contents, "Name=\r\n"); 948 create_cdf_file(cdffileA, cdf_contents); 949 950 SET_UNEXPECTED; 951 SetLastError(0xdeadbeef); 952 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback); 953 ok(catcdf == NULL, "CryptCATCDFOpen succeeded\n"); 954 todo_wine 955 ok(GetLastError() == ERROR_SHARING_VIOLATION, 956 "Expected ERROR_SHARING_VIOLATION, got %d\n", GetLastError()); 957 DeleteFileA(cdffileA); 958 ok(!DeleteFileA(catfileA), "Didn't expect a catalog file to be created\n"); 959 960 /* Header and Name */ 961 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n"); 962 lstrcatA(cdf_contents, "Name=tempfile.cat\r\n"); 963 create_cdf_file(cdffileA, cdf_contents); 964 965 SET_UNEXPECTED; 966 SetLastError(0xdeadbeef); 967 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback); 968 todo_wine 969 { 970 ok(catcdf != NULL, "CryptCATCDFOpen failed\n"); 971 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); 972 } 973 pCryptCATCDFClose(catcdf); 974 DeleteFileA(cdffileA); 975 todo_wine 976 ok(DeleteFileA(catfileA), "Expected a catalog file to be created\n"); 977 978 /* Header and nonexistent member */ 979 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n"); 980 lstrcatA(cdf_contents, "Name=tempfile.cat\r\n"); 981 lstrcatA(cdf_contents, "[CatalogFiles]\r\n"); 982 lstrcatA(cdf_contents, "hashme=.\\deadbeef.cdf\r\n"); 983 create_cdf_file(cdffileA, cdf_contents); 984 985 SET_UNEXPECTED; 986 SetLastError(0xdeadbeef); 987 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback); 988 todo_wine 989 { 990 ok(catcdf != NULL, "CryptCATCDFOpen failed\n"); 991 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); 992 } 993 /* Loop through the members */ 994 CLEAR_EXPECT; 995 catmember = NULL; 996 catmembertag = NULL; 997 while ((catmembertag = pCryptCATCDFEnumMembersByCDFTagEx(catcdf, catmembertag, cdf_callback, &catmember, FALSE, NULL))) ; 998 todo_wine 999 CHECK_EXPECT(CRYPTCAT_E_AREA_MEMBER, CRYPTCAT_E_CDF_MEMBER_FILENOTFOUND); 1000 pCryptCATCDFClose(catcdf); 1001 DeleteFileA(cdffileA); 1002 todo_wine 1003 ok(DeleteFileA(catfileA), "Expected a catalog file to be created\n"); 1004 1005 /* Header, correct member but no explicit newline */ 1006 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n"); 1007 lstrcatA(cdf_contents, "Name=tempfile.cat\r\n"); 1008 lstrcatA(cdf_contents, "[CatalogFiles]\r\n"); 1009 lstrcatA(cdf_contents, "hashme=.\\tempfile.cdf\r"); 1010 create_cdf_file(cdffileA, cdf_contents); 1011 1012 SET_UNEXPECTED; 1013 SetLastError(0xdeadbeef); 1014 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback); 1015 todo_wine 1016 { 1017 ok(catcdf != NULL, "CryptCATCDFOpen failed\n"); 1018 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); 1019 } 1020 /* Loop through the members */ 1021 CLEAR_EXPECT; 1022 catmember = NULL; 1023 catmembertag = NULL; 1024 while ((catmembertag = pCryptCATCDFEnumMembersByCDFTagEx(catcdf, catmembertag, cdf_callback, &catmember, FALSE, NULL))) ; 1025 ok(error_area == 0xffffffff || broken(error_area == CRYPTCAT_E_AREA_MEMBER) /* < win81 */, 1026 "Expected area 0xffffffff, got %08x\n", error_area); 1027 ok(local_error == 0xffffffff || broken(local_error == CRYPTCAT_E_CDF_MEMBER_FILE_PATH) /* < win81 */, 1028 "Expected error 0xffffffff, got %08x\n", local_error); 1029 1030 pCryptCATCDFClose(catcdf); 1031 DeleteFileA(cdffileA); 1032 todo_wine 1033 ok(DeleteFileA(catfileA), "Expected a catalog file to be created\n"); 1034 1035 /* Header and 2 duplicate members */ 1036 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n"); 1037 lstrcatA(cdf_contents, "Name=tempfile.cat\r\n"); 1038 lstrcatA(cdf_contents, "[CatalogFiles]\r\n"); 1039 lstrcatA(cdf_contents, "hashme=.\\tempfile.cdf\r\n"); 1040 lstrcatA(cdf_contents, "hashme=.\\tempfile.cdf\r\n"); 1041 create_cdf_file(cdffileA, cdf_contents); 1042 1043 SET_UNEXPECTED; 1044 SetLastError(0xdeadbeef); 1045 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback); 1046 todo_wine 1047 { 1048 ok(catcdf != NULL, "CryptCATCDFOpen failed\n"); 1049 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); 1050 } 1051 /* Loop through the members */ 1052 SET_UNEXPECTED; 1053 catmember = NULL; 1054 catmembertag = NULL; 1055 while ((catmembertag = pCryptCATCDFEnumMembersByCDFTagEx(catcdf, catmembertag, cdf_callback, &catmember, FALSE, NULL))) ; 1056 pCryptCATCDFClose(catcdf); 1057 test_catalog_properties(catfileA, 0, 1); 1058 DeleteFileA(cdffileA); 1059 todo_wine 1060 ok(DeleteFileA(catfileA), "Expected a catalog file to be created\n"); 1061 1062 /* Wrong attribute */ 1063 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n"); 1064 lstrcatA(cdf_contents, "Name=tempfile.cat\r\n"); 1065 lstrcatA(cdf_contents, "CATATTR1=0x10010001:attr1\r\n"); 1066 create_cdf_file(cdffileA, cdf_contents); 1067 1068 SET_UNEXPECTED; 1069 SetLastError(0xdeadbeef); 1070 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback); 1071 todo_wine 1072 { 1073 ok(catcdf != NULL, "CryptCATCDFOpen failed\n"); 1074 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); 1075 } 1076 /* Loop through the attributes */ 1077 CLEAR_EXPECT; 1078 catattr = NULL; 1079 while ((catattr = pCryptCATCDFEnumCatAttributes(catcdf, catattr, cdf_callback))) ; 1080 todo_wine 1081 CHECK_EXPECT(CRYPTCAT_E_AREA_ATTRIBUTE, CRYPTCAT_E_CDF_ATTR_TOOFEWVALUES); 1082 pCryptCATCDFClose(catcdf); 1083 DeleteFileA(cdffileA); 1084 todo_wine 1085 ok(DeleteFileA(catfileA), "Expected a catalog file to be created\n"); 1086 1087 /* Two identical attributes */ 1088 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n"); 1089 lstrcatA(cdf_contents, "Name=tempfile.cat\r\n"); 1090 lstrcatA(cdf_contents, "CATATTR1=0x10010001:attr1:value1\r\n"); 1091 lstrcatA(cdf_contents, "CATATTR1=0x10010001:attr1:value1\r\n"); 1092 lstrcatA(cdf_contents, "[CatalogFiles]\r\n"); 1093 lstrcatA(cdf_contents, "hashme=.\\tempfile.cdf\r\n"); 1094 create_cdf_file(cdffileA, cdf_contents); 1095 1096 SET_UNEXPECTED; 1097 SetLastError(0xdeadbeef); 1098 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback); 1099 todo_wine 1100 { 1101 ok(catcdf != NULL, "CryptCATCDFOpen failed\n"); 1102 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); 1103 } 1104 /* Loop through the members */ 1105 SET_UNEXPECTED; 1106 catmember = NULL; 1107 catmembertag = NULL; 1108 while ((catmembertag = pCryptCATCDFEnumMembersByCDFTagEx(catcdf, catmembertag, cdf_callback, &catmember, FALSE, NULL))) ; 1109 /* Loop through the attributes */ 1110 SET_UNEXPECTED; 1111 catattr = NULL; 1112 while ((catattr = pCryptCATCDFEnumCatAttributes(catcdf, catattr, cdf_callback))) ; 1113 pCryptCATCDFClose(catcdf); 1114 test_catalog_properties(catfileA, 1, 1); 1115 DeleteFileA(cdffileA); 1116 todo_wine 1117 ok(DeleteFileA(catfileA), "Expected a catalog file to be created\n"); 1118 1119 /* Two different attribute values with the same tag */ 1120 lstrcpyA(cdf_contents, "[CatalogHeader]\r\n"); 1121 lstrcatA(cdf_contents, "Name=tempfile.cat\r\n"); 1122 lstrcatA(cdf_contents, "CATATTR1=0x10010001:attr1:value1\r\n"); 1123 lstrcatA(cdf_contents, "CATATTR1=0x10010001:attr2:value2\r\n"); 1124 lstrcatA(cdf_contents, "[CatalogFiles]\r\n"); 1125 lstrcatA(cdf_contents, "hashme=.\\tempfile.cdf\r\n"); 1126 create_cdf_file(cdffileA, cdf_contents); 1127 1128 SET_UNEXPECTED; 1129 SetLastError(0xdeadbeef); 1130 catcdf = pCryptCATCDFOpen(cdffileW, cdf_callback); 1131 todo_wine 1132 { 1133 ok(catcdf != NULL, "CryptCATCDFOpen failed\n"); 1134 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); 1135 } 1136 /* Loop through the members */ 1137 SET_UNEXPECTED; 1138 catmember = NULL; 1139 catmembertag = NULL; 1140 while ((catmembertag = pCryptCATCDFEnumMembersByCDFTagEx(catcdf, catmembertag, cdf_callback, &catmember, FALSE, NULL))) ; 1141 /* Loop through the attributes */ 1142 SET_UNEXPECTED; 1143 catattr = NULL; 1144 while ((catattr = pCryptCATCDFEnumCatAttributes(catcdf, catattr, cdf_callback))) ; 1145 pCryptCATCDFClose(catcdf); 1146 test_catalog_properties(catfileA, 1, 1); 1147 DeleteFileA(cdffileA); 1148 todo_wine 1149 ok(DeleteFileA(catfileA), "Expected a catalog file to be created\n"); 1150 } 1151 1152 static const struct 1153 { 1154 WORD e_magic; /* 00: MZ Header signature */ 1155 WORD unused[29]; 1156 DWORD e_lfanew; /* 3c: Offset to extended header */ 1157 } dos_header = 1158 { 1159 IMAGE_DOS_SIGNATURE, { 0 }, sizeof(dos_header) 1160 }; 1161 1162 static IMAGE_NT_HEADERS nt_header = 1163 { 1164 IMAGE_NT_SIGNATURE, /* Signature */ 1165 { 1166 IMAGE_FILE_MACHINE_I386, /* Machine */ 1167 1, /* NumberOfSections */ 1168 0, /* TimeDateStamp */ 1169 0, /* PointerToSymbolTable */ 1170 0, /* NumberOfSymbols */ 1171 sizeof(IMAGE_OPTIONAL_HEADER), /* SizeOfOptionalHeader */ 1172 IMAGE_FILE_EXECUTABLE_IMAGE /* Characteristics */ 1173 }, 1174 { 1175 IMAGE_NT_OPTIONAL_HDR_MAGIC, /* Magic */ 1176 2, /* MajorLinkerVersion */ 1177 15, /* MinorLinkerVersion */ 1178 0, /* SizeOfCode */ 1179 0, /* SizeOfInitializedData */ 1180 0, /* SizeOfUninitializedData */ 1181 0, /* AddressOfEntryPoint */ 1182 0x10, /* BaseOfCode, also serves as e_lfanew in the truncated MZ header */ 1183 #ifndef _WIN64 1184 0, /* BaseOfData */ 1185 #endif 1186 0x10000000, /* ImageBase */ 1187 0, /* SectionAlignment */ 1188 0, /* FileAlignment */ 1189 4, /* MajorOperatingSystemVersion */ 1190 0, /* MinorOperatingSystemVersion */ 1191 1, /* MajorImageVersion */ 1192 0, /* MinorImageVersion */ 1193 4, /* MajorSubsystemVersion */ 1194 0, /* MinorSubsystemVersion */ 1195 0, /* Win32VersionValue */ 1196 0x200, /* SizeOfImage */ 1197 sizeof(dos_header) + sizeof(nt_header), /* SizeOfHeaders */ 1198 0, /* CheckSum */ 1199 IMAGE_SUBSYSTEM_WINDOWS_CUI, /* Subsystem */ 1200 0, /* DllCharacteristics */ 1201 0, /* SizeOfStackReserve */ 1202 0, /* SizeOfStackCommit */ 1203 0, /* SizeOfHeapReserve */ 1204 3, /* SizeOfHeapCommit */ 1205 2, /* LoaderFlags */ 1206 1, /* NumberOfRvaAndSizes */ 1207 { { 0 } } /* DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES] */ 1208 } 1209 }; 1210 1211 static void test_sip(void) 1212 { 1213 static const WCHAR nameW[] = {'t','e','s','t','.','e','x','e',0}; 1214 SIP_SUBJECTINFO info; 1215 DWORD index, encoding, size; 1216 HANDLE file; 1217 GUID guid; 1218 BOOL ret; 1219 char buf[1024]; 1220 1221 file = CreateFileW(nameW, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 1222 ok(file != INVALID_HANDLE_VALUE, "can't create file\n"); 1223 if(file == INVALID_HANDLE_VALUE) 1224 return; 1225 WriteFile(file, &dos_header, sizeof(dos_header), &size, NULL); 1226 WriteFile(file, &nt_header, sizeof(nt_header), &size, NULL); 1227 memset(buf, 0, sizeof(buf)); 1228 WriteFile(file, buf, 0x200 - sizeof(dos_header) - sizeof(nt_header), &size, NULL); 1229 CloseHandle(file); 1230 1231 file= CreateFileW(nameW, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 1232 ok(file != INVALID_HANDLE_VALUE, "can't open file\n"); 1233 1234 memset(&info, 0, sizeof(SIP_SUBJECTINFO)); 1235 info.cbSize = sizeof(SIP_SUBJECTINFO); 1236 info.pgSubjectType = &guid; 1237 ret = CryptSIPRetrieveSubjectGuid(NULL, file, info.pgSubjectType); 1238 ok(ret, "CryptSIPRetrieveSubjectGuid failed (%x)\n", GetLastError()); 1239 1240 ret = pPutSignedDataMsg(&info, X509_ASN_ENCODING, &index, 4, (BYTE*)"test"); 1241 ok(!ret, "CryptSIPPutSignedDataMsg succeeded\n"); 1242 index = GetLastError(); 1243 ok(index == ERROR_PATH_NOT_FOUND, "GetLastError returned %x\n", index); 1244 1245 info.hFile = file; 1246 info.pwsFileName = nameW; 1247 ret = pPutSignedDataMsg(&info, X509_ASN_ENCODING, &index, 4, (BYTE*)"test"); 1248 ok(!ret, "CryptSIPPutSignedDataMsg succeeded\n"); 1249 index = GetLastError(); 1250 todo_wine ok(index == ERROR_INVALID_PARAMETER, "GetLastError returned %x\n", index); 1251 1252 info.hFile = INVALID_HANDLE_VALUE; 1253 info.pwsFileName = nameW; 1254 ret = pPutSignedDataMsg(&info, X509_ASN_ENCODING, &index, 4, (BYTE*)"test"); 1255 ok(!ret, "CryptSIPPutSignedDataMsg succeeded\n"); 1256 index = GetLastError(); 1257 ok(index == ERROR_SHARING_VIOLATION, "GetLastError returned %x\n", index); 1258 1259 CloseHandle(file); 1260 file= CreateFileW(nameW, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 1261 1262 info.hFile = file; 1263 info.pwsFileName = (void*)0xdeadbeef; 1264 ret = pPutSignedDataMsg(&info, X509_ASN_ENCODING, &index, 4, (BYTE*)"test"); 1265 ok(ret, "CryptSIPPutSignedDataMsg failed (%x)\n", GetLastError()); 1266 ok(index == 0, "index = %x\n", index); 1267 1268 CloseHandle(file); 1269 file= CreateFileW(nameW, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 1270 1271 info.hFile = INVALID_HANDLE_VALUE; 1272 info.pwsFileName = nameW; 1273 ret = pPutSignedDataMsg(&info, X509_ASN_ENCODING, &index, 14, (BYTE*)"longer message"); 1274 ok(ret, "CryptSIPPutSignedDataMsg failed (%x)\n", GetLastError()); 1275 ok(index == 1, "index = %x\n", index); 1276 1277 size = 0; 1278 encoding = 0xdeadbeef; 1279 ret = pGetSignedDataMsg(&info, &encoding, 0, &size, NULL); 1280 ok(ret, "CryptSIPGetSignedDataMsg failed (%x)\n", GetLastError()); 1281 ok(encoding == 0xdeadbeef, "encoding = %x\n", encoding); 1282 ok(size == 16, "size = %d\n", size); 1283 1284 ret = pGetSignedDataMsg(&info, &encoding, 0, &size, (BYTE*)buf); 1285 ok(ret, "CryptSIPGetSignedDataMsg failed (%x)\n", GetLastError()); 1286 ok(encoding == (X509_ASN_ENCODING|PKCS_7_ASN_ENCODING), "encoding = %x\n", encoding); 1287 ok(size == 8, "size = %d\n", size); 1288 ok(!memcmp(buf, "test\0\0\0\0", 8), "buf = %s\n", buf); 1289 1290 size = 0; 1291 encoding = 0xdeadbeef; 1292 ret = pGetSignedDataMsg(&info, &encoding, 1, &size, NULL); 1293 ok(ret, "CryptSIPGetSignedDataMsg failed (%x)\n", GetLastError()); 1294 ok(encoding == 0xdeadbeef, "encoding = %x\n", encoding); 1295 ok(size == 24, "size = %d\n", size); 1296 1297 ret = pGetSignedDataMsg(&info, &encoding, 1, &size, (BYTE*)buf); 1298 ok(ret, "CryptSIPGetSignedDataMsg failed (%x)\n", GetLastError()); 1299 ok(encoding == (X509_ASN_ENCODING|PKCS_7_ASN_ENCODING), "encoding = %x\n", encoding); 1300 ok(size == 16, "size = %d\n", size); 1301 ok(!strcmp(buf, "longer message"), "buf = %s\n", buf); 1302 1303 CryptReleaseContext(info.hProv, 0); 1304 CloseHandle(file); 1305 DeleteFileW(nameW); 1306 } 1307 1308 START_TEST(crypt) 1309 { 1310 char** myARGV; 1311 char sysdir[MAX_PATH]; 1312 1313 InitFunctionPtrs(); 1314 1315 if (!pCryptCATAdminAcquireContext) 1316 { 1317 win_skip("CryptCATAdmin functions are not available\n"); 1318 return; 1319 } 1320 1321 GetSystemDirectoryA(sysdir, MAX_PATH); 1322 lstrcpyA(catroot, sysdir); 1323 lstrcatA(catroot, "\\CatRoot"); 1324 lstrcpyA(catroot2, sysdir); 1325 lstrcatA(catroot2, "\\CatRoot2"); 1326 1327 winetest_get_mainargs(&myARGV); 1328 strcpy(selfname, myARGV[0]); 1329 1330 GetCurrentDirectoryA(MAX_PATH, CURR_DIR); 1331 1332 test_context(); 1333 test_calchash(); 1334 test_CryptCATOpen(); 1335 /* Parameter checking only */ 1336 test_CryptCATCDF_params(); 1337 /* Test the parsing of a cdf file */ 1338 test_cdf_parsing(); 1339 /* Create a catalog file out of our own catalog definition file */ 1340 test_create_catalog_file(); 1341 test_CryptCATAdminAddRemoveCatalog(); 1342 test_sip(); 1343 } 1344