1 /*
2 * wintrust softpub functions tests
3 *
4 * Copyright 2007,2010 Juan Lang
5 * Copyright 2010 Andrey Turkin
6 * Copyright 2016 Mark Jansen
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23 #include <stdio.h>
24 #include <stdarg.h>
25
26 #include <windef.h>
27 #include <winbase.h>
28 #include <winerror.h>
29 #include <wintrust.h>
30 #include <softpub.h>
31 #include <mssip.h>
32 #include <winuser.h>
33 #include "winnls.h"
34
35 #include "wine/test.h"
36
37 /* Just in case we're being built with borked headers, redefine function
38 * pointers to have the correct calling convention.
39 */
40 typedef void *(WINAPI *SAFE_MEM_ALLOC)(DWORD);
41 typedef void (WINAPI *SAFE_MEM_FREE)(void *);
42 typedef BOOL (WINAPI *SAFE_ADD_STORE)(CRYPT_PROVIDER_DATA *,
43 HCERTSTORE);
44 typedef BOOL (WINAPI *SAFE_ADD_SGNR)(CRYPT_PROVIDER_DATA *,
45 BOOL, DWORD, struct _CRYPT_PROVIDER_SGNR *);
46 typedef BOOL (WINAPI *SAFE_ADD_CERT)(CRYPT_PROVIDER_DATA *,
47 DWORD, BOOL, DWORD, PCCERT_CONTEXT);
48 typedef BOOL (WINAPI *SAFE_ADD_PRIVDATA)(CRYPT_PROVIDER_DATA *,
49 CRYPT_PROVIDER_PRIVDATA *);
50 typedef HRESULT (WINAPI *SAFE_PROVIDER_INIT_CALL)(CRYPT_PROVIDER_DATA *);
51 typedef HRESULT (WINAPI *SAFE_PROVIDER_OBJTRUST_CALL)(CRYPT_PROVIDER_DATA *);
52 typedef HRESULT (WINAPI *SAFE_PROVIDER_SIGTRUST_CALL)(CRYPT_PROVIDER_DATA *);
53 typedef HRESULT (WINAPI *SAFE_PROVIDER_CERTTRUST_CALL)(CRYPT_PROVIDER_DATA *);
54 typedef HRESULT (WINAPI *SAFE_PROVIDER_FINALPOLICY_CALL)(CRYPT_PROVIDER_DATA *);
55 typedef HRESULT (WINAPI *SAFE_PROVIDER_TESTFINALPOLICY_CALL)(
56 CRYPT_PROVIDER_DATA *);
57 typedef HRESULT (WINAPI *SAFE_PROVIDER_CLEANUP_CALL)(CRYPT_PROVIDER_DATA *);
58 typedef BOOL (WINAPI *SAFE_PROVIDER_CERTCHKPOLICY_CALL)(
59 CRYPT_PROVIDER_DATA *, DWORD, BOOL, DWORD);
60
61 typedef struct _SAFE_PROVIDER_FUNCTIONS
62 {
63 DWORD cbStruct;
64 SAFE_MEM_ALLOC pfnAlloc;
65 SAFE_MEM_FREE pfnFree;
66 SAFE_ADD_STORE pfnAddStore2Chain;
67 SAFE_ADD_SGNR pfnAddSgnr2Chain;
68 SAFE_ADD_CERT pfnAddCert2Chain;
69 SAFE_ADD_PRIVDATA pfnAddPrivData2Chain;
70 SAFE_PROVIDER_INIT_CALL pfnInitialize;
71 SAFE_PROVIDER_OBJTRUST_CALL pfnObjectTrust;
72 SAFE_PROVIDER_SIGTRUST_CALL pfnSignatureTrust;
73 SAFE_PROVIDER_CERTTRUST_CALL pfnCertificateTrust;
74 SAFE_PROVIDER_FINALPOLICY_CALL pfnFinalPolicy;
75 SAFE_PROVIDER_CERTCHKPOLICY_CALL pfnCertCheckPolicy;
76 SAFE_PROVIDER_TESTFINALPOLICY_CALL pfnTestFinalPolicy;
77 struct _CRYPT_PROVUI_FUNCS *psUIpfns;
78 SAFE_PROVIDER_CLEANUP_CALL pfnCleanupPolicy;
79 } SAFE_PROVIDER_FUNCTIONS;
80
81 static BOOL (WINAPI * pWTHelperGetKnownUsages)(DWORD action, PCCRYPT_OID_INFO **usages);
82 static BOOL (WINAPI * CryptSIPCreateIndirectData_p)(SIP_SUBJECTINFO *, DWORD *, SIP_INDIRECT_DATA *);
83 static VOID (WINAPI * CertFreeCertificateChain_p)(PCCERT_CHAIN_CONTEXT);
84
InitFunctionPtrs(void)85 static void InitFunctionPtrs(void)
86 {
87 HMODULE hWintrust = GetModuleHandleA("wintrust.dll");
88 HMODULE hCrypt32 = GetModuleHandleA("crypt32.dll");
89
90 #define WINTRUST_GET_PROC(func) \
91 p ## func = (void*)GetProcAddress(hWintrust, #func); \
92 if(!p ## func) { \
93 trace("GetProcAddress(%s) failed\n", #func); \
94 }
95
96 WINTRUST_GET_PROC(WTHelperGetKnownUsages)
97
98 #undef WINTRUST_GET_PROC
99
100 #define CRYPT32_GET_PROC(func) \
101 func ## _p = (void*)GetProcAddress(hCrypt32, #func); \
102 if(!func ## _p) { \
103 trace("GetProcAddress(%s) failed\n", #func); \
104 }
105
106 CRYPT32_GET_PROC(CryptSIPCreateIndirectData)
107 CRYPT32_GET_PROC(CertFreeCertificateChain)
108
109 #undef CRYPT32_GET_PROC
110 }
111
112 static const BYTE v1CertWithPubKey[] = {
113 0x30,0x81,0x95,0x02,0x01,0x01,0x30,0x02,0x06,0x00,0x30,0x15,0x31,0x13,0x30,
114 0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,
115 0x6e,0x67,0x00,0x30,0x22,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,
116 0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,
117 0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x15,0x31,0x13,0x30,0x11,
118 0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,
119 0x67,0x00,0x30,0x22,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,
120 0x01,0x01,0x05,0x00,0x03,0x11,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
121 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0xa3,0x16,0x30,0x14,0x30,0x12,0x06,
122 0x03,0x55,0x1d,0x13,0x01,0x01,0xff,0x04,0x08,0x30,0x06,0x01,0x01,0xff,0x02,
123 0x01,0x01 };
124
test_utils(SAFE_PROVIDER_FUNCTIONS * funcs)125 static void test_utils(SAFE_PROVIDER_FUNCTIONS *funcs)
126 {
127 CRYPT_PROVIDER_DATA data = { 0 };
128 HCERTSTORE store;
129 CRYPT_PROVIDER_SGNR sgnr = { 0 };
130 BOOL ret;
131
132 /* Crash
133 ret = funcs->pfnAddStore2Chain(NULL, NULL);
134 ret = funcs->pfnAddStore2Chain(&data, NULL);
135 */
136 store = CertOpenStore(CERT_STORE_PROV_MEMORY, X509_ASN_ENCODING, 0,
137 CERT_STORE_CREATE_NEW_FLAG, NULL);
138 if (store)
139 {
140 ret = funcs->pfnAddStore2Chain(&data, store);
141 ok(ret, "pfnAddStore2Chain failed: %08x\n", GetLastError());
142 ok(data.chStores == 1, "Expected 1 store, got %d\n", data.chStores);
143 ok(data.pahStores != NULL, "Expected pahStores to be allocated\n");
144 if (data.pahStores)
145 {
146 ok(data.pahStores[0] == store, "Unexpected store\n");
147 CertCloseStore(data.pahStores[0], 0);
148 funcs->pfnFree(data.pahStores);
149 data.pahStores = NULL;
150 data.chStores = 0;
151 CertCloseStore(store, 0);
152 store = NULL;
153 }
154 }
155 else
156 skip("CertOpenStore failed: %08x\n", GetLastError());
157
158 /* Crash
159 ret = funcs->pfnAddSgnr2Chain(NULL, FALSE, 0, NULL);
160 ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, NULL);
161 */
162 ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, &sgnr);
163 ok(ret, "pfnAddSgnr2Chain failed: %08x\n", GetLastError());
164 ok(data.csSigners == 1, "Expected 1 signer, got %d\n", data.csSigners);
165 ok(data.pasSigners != NULL, "Expected pasSigners to be allocated\n");
166 if (data.pasSigners)
167 {
168 PCCERT_CONTEXT cert;
169
170 ok(!memcmp(&data.pasSigners[0], &sgnr, sizeof(sgnr)),
171 "Unexpected data in signer\n");
172 /* Adds into the location specified by the index */
173 sgnr.cbStruct = sizeof(CRYPT_PROVIDER_SGNR);
174 sgnr.sftVerifyAsOf.dwLowDateTime = 0xdeadbeef;
175 ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 1, &sgnr);
176 ok(ret, "pfnAddSgnr2Chain failed: %08x\n", GetLastError());
177 ok(data.csSigners == 2, "Expected 2 signers, got %d\n", data.csSigners);
178 ok(!memcmp(&data.pasSigners[1], &sgnr, sizeof(sgnr)),
179 "Unexpected data in signer\n");
180 /* This also adds, but the index is ignored */
181 sgnr.cbStruct = sizeof(DWORD);
182 ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, &sgnr);
183 ok(ret, "pfnAddSgnr2Chain failed: %08x\n", GetLastError());
184 ok(data.csSigners == 3, "Expected 3 signers, got %d\n", data.csSigners);
185 sgnr.sftVerifyAsOf.dwLowDateTime = 0;
186 todo_wine
187 ok(!memcmp(&data.pasSigners[2], &sgnr, sizeof(sgnr)),
188 "Unexpected data in signer\n");
189 /* But too large a thing isn't added */
190 sgnr.cbStruct = sizeof(sgnr) + sizeof(DWORD);
191 SetLastError(0xdeadbeef);
192 ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, &sgnr);
193 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
194 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
195
196 /* Crash
197 ret = funcs->pfnAddCert2Chain(NULL, 0, FALSE, 0, NULL);
198 ret = funcs->pfnAddCert2Chain(&data, 0, FALSE, 0, NULL);
199 */
200 cert = CertCreateCertificateContext(X509_ASN_ENCODING, v1CertWithPubKey,
201 sizeof(v1CertWithPubKey));
202 if (cert)
203 {
204 /* Notes on behavior that are hard to test:
205 * 1. If pasSigners is invalid, pfnAddCert2Chain crashes
206 * 2. An invalid signer index isn't checked.
207 */
208 ret = funcs->pfnAddCert2Chain(&data, 0, FALSE, 0, cert);
209 ok(ret, "pfnAddCert2Chain failed: %08x\n", GetLastError());
210 ok(data.pasSigners[0].csCertChain == 1, "Expected 1 cert, got %d\n",
211 data.pasSigners[0].csCertChain);
212 ok(data.pasSigners[0].pasCertChain != NULL,
213 "Expected pasCertChain to be allocated\n");
214 if (data.pasSigners[0].pasCertChain)
215 {
216 ok(data.pasSigners[0].pasCertChain[0].pCert == cert,
217 "Unexpected cert\n");
218 CertFreeCertificateContext(
219 data.pasSigners[0].pasCertChain[0].pCert);
220 }
221 CertFreeCertificateContext(cert);
222 }
223 else
224 skip("CertCreateCertificateContext failed: %08x\n", GetLastError());
225 funcs->pfnFree(data.pasSigners);
226 }
227 }
228
testInitialize(SAFE_PROVIDER_FUNCTIONS * funcs,GUID * actionID)229 static void testInitialize(SAFE_PROVIDER_FUNCTIONS *funcs, GUID *actionID)
230 {
231 HRESULT ret;
232 CRYPT_PROVIDER_DATA data = { 0 };
233 WINTRUST_DATA wintrust_data = { 0 };
234
235 if (!funcs->pfnInitialize)
236 {
237 skip("missing pfnInitialize\n");
238 return;
239 }
240
241 /* Crashes
242 ret = funcs->pfnInitialize(NULL);
243 */
244 memset(&data, 0, sizeof(data));
245 ret = funcs->pfnInitialize(&data);
246 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
247 data.padwTrustStepErrors =
248 funcs->pfnAlloc(TRUSTERROR_MAX_STEPS * sizeof(DWORD));
249 /* Without wintrust data set, crashes when padwTrustStepErrors is set */
250 data.pWintrustData = &wintrust_data;
251 if (data.padwTrustStepErrors)
252 {
253 /* Apparently, cdwTrustStepErrors does not need to be set. */
254 memset(data.padwTrustStepErrors, 0,
255 TRUSTERROR_MAX_STEPS * sizeof(DWORD));
256 ret = funcs->pfnInitialize(&data);
257 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
258 data.cdwTrustStepErrors = 1;
259 ret = funcs->pfnInitialize(&data);
260 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
261 memset(data.padwTrustStepErrors, 0xba,
262 TRUSTERROR_MAX_STEPS * sizeof(DWORD));
263 ret = funcs->pfnInitialize(&data);
264 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
265 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_WVTINIT] = 0;
266 ret = funcs->pfnInitialize(&data);
267 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
268 funcs->pfnFree(data.padwTrustStepErrors);
269 }
270 }
271
getNotepadPath(WCHAR * notepadPathW,DWORD size)272 static void getNotepadPath(WCHAR *notepadPathW, DWORD size)
273 {
274 static const CHAR notepad[] = "\\notepad.exe";
275 CHAR notepadPath[MAX_PATH];
276
277 /* Workaround missing W-functions for win9x */
278 GetWindowsDirectoryA(notepadPath, MAX_PATH);
279 lstrcatA(notepadPath, notepad);
280 MultiByteToWideChar(CP_ACP, 0, notepadPath, -1, notepadPathW, size);
281 }
282
283 /* Creates a test file and returns a handle to it. The file's path is returned
284 * in temp_file, which must be at least MAX_PATH characters in length.
285 */
create_temp_file(WCHAR * temp_file)286 static HANDLE create_temp_file(WCHAR *temp_file)
287 {
288 HANDLE file = INVALID_HANDLE_VALUE;
289 WCHAR temp_path[MAX_PATH];
290
291 if (GetTempPathW(ARRAY_SIZE(temp_path), temp_path))
292 {
293 static const WCHAR img[] = { 'i','m','g',0 };
294
295 if (GetTempFileNameW(temp_path, img, 0, temp_file))
296 file = CreateFileW(temp_file, GENERIC_READ | GENERIC_WRITE, 0, NULL,
297 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
298 }
299 return file;
300 }
301
testObjTrust(SAFE_PROVIDER_FUNCTIONS * funcs,GUID * actionID)302 static void testObjTrust(SAFE_PROVIDER_FUNCTIONS *funcs, GUID *actionID)
303 {
304 HRESULT ret;
305 CRYPT_PROVIDER_DATA data = { 0 };
306 CRYPT_PROVIDER_SIGSTATE sig_state = { 0 };
307 WINTRUST_DATA wintrust_data = { 0 };
308 WINTRUST_CERT_INFO certInfo = { sizeof(WINTRUST_CERT_INFO), 0 };
309 WINTRUST_FILE_INFO fileInfo = { sizeof(WINTRUST_FILE_INFO), 0 };
310
311 if (!funcs->pfnObjectTrust)
312 {
313 skip("missing pfnObjectTrust\n");
314 return;
315 }
316
317 /* Crashes
318 ret = funcs->pfnObjectTrust(NULL);
319 */
320 data.pSigState = &sig_state;
321 data.pWintrustData = &wintrust_data;
322 data.padwTrustStepErrors =
323 funcs->pfnAlloc(TRUSTERROR_MAX_STEPS * sizeof(DWORD));
324 if (data.padwTrustStepErrors)
325 {
326 WCHAR pathW[MAX_PATH];
327 PROVDATA_SIP provDataSIP = { 0 };
328 static const GUID unknown = { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,
329 0x00,0xC0,0x4F,0xC2,0x95,0xEE } };
330 static GUID bogusGuid = { 0xdeadbeef, 0xbaad, 0xf00d, { 0x00,0x00,0x00,
331 0x00,0x00,0x00,0x00,0x00 } };
332
333 ret = funcs->pfnObjectTrust(&data);
334 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
335 ok(data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
336 ERROR_INVALID_PARAMETER,
337 "Expected ERROR_INVALID_PARAMETER, got %08x\n",
338 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
339 U(wintrust_data).pCert = &certInfo;
340 wintrust_data.dwUnionChoice = WTD_CHOICE_CERT;
341 ret = funcs->pfnObjectTrust(&data);
342 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
343 certInfo.psCertContext = (PCERT_CONTEXT)CertCreateCertificateContext(
344 X509_ASN_ENCODING, v1CertWithPubKey, sizeof(v1CertWithPubKey));
345 ret = funcs->pfnObjectTrust(&data);
346 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
347 CertFreeCertificateContext(certInfo.psCertContext);
348 certInfo.psCertContext = NULL;
349 wintrust_data.dwUnionChoice = WTD_CHOICE_FILE;
350 U(wintrust_data).pFile = NULL;
351 ret = funcs->pfnObjectTrust(&data);
352 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
353 ok(data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
354 ERROR_INVALID_PARAMETER,
355 "Expected ERROR_INVALID_PARAMETER, got %08x\n",
356 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
357 U(wintrust_data).pFile = &fileInfo;
358 /* Crashes
359 ret = funcs->pfnObjectTrust(&data);
360 */
361 /* Create and test with an empty file */
362 fileInfo.hFile = create_temp_file(pathW);
363 /* pfnObjectTrust now crashes unless both pPDSip and psPfns are set */
364 U(data).pPDSip = &provDataSIP;
365 data.psPfns = (CRYPT_PROVIDER_FUNCTIONS *)funcs;
366 ret = funcs->pfnObjectTrust(&data);
367 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
368 ok(data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
369 TRUST_E_SUBJECT_FORM_UNKNOWN,
370 "expected TRUST_E_SUBJECT_FORM_UNKNOWN, got %08x\n",
371 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
372 CloseHandle(fileInfo.hFile);
373 fileInfo.hFile = NULL;
374 fileInfo.pcwszFilePath = pathW;
375 ret = funcs->pfnObjectTrust(&data);
376 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
377 ok(data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
378 TRUST_E_SUBJECT_FORM_UNKNOWN,
379 "expected TRUST_E_SUBJECT_FORM_UNKNOWN, got %08x\n",
380 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
381 DeleteFileW(pathW);
382 /* Test again with a file we expect to exist, and to contain no
383 * signature.
384 */
385 getNotepadPath(pathW, MAX_PATH);
386 ret = funcs->pfnObjectTrust(&data);
387 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
388 ok(data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
389 TRUST_E_NOSIGNATURE ||
390 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
391 TRUST_E_SUBJECT_FORM_UNKNOWN,
392 "Expected TRUST_E_NOSIGNATURE or TRUST_E_SUBJECT_FORM_UNKNOWN, got %08x\n",
393 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
394 if (data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
395 TRUST_E_NOSIGNATURE)
396 {
397 ok(!memcmp(&provDataSIP.gSubject, &unknown, sizeof(unknown)),
398 "Unexpected subject GUID\n");
399 ok(provDataSIP.pSip != NULL, "Expected a SIP\n");
400 ok(provDataSIP.psSipSubjectInfo != NULL,
401 "Expected a subject info\n");
402 }
403 /* Specifying the GUID results in that GUID being the subject GUID */
404 fileInfo.pgKnownSubject = &bogusGuid;
405 ret = funcs->pfnObjectTrust(&data);
406 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
407 ok(data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
408 TRUST_E_NOSIGNATURE ||
409 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
410 TRUST_E_SUBJECT_FORM_UNKNOWN ||
411 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
412 TRUST_E_PROVIDER_UNKNOWN,
413 "Expected TRUST_E_NOSIGNATURE or TRUST_E_SUBJECT_FORM_UNKNOWN or TRUST_E_PROVIDER_UNKNOWN, got %08x\n",
414 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
415 if (data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
416 TRUST_E_NOSIGNATURE)
417 {
418 ok(!memcmp(&provDataSIP.gSubject, &bogusGuid, sizeof(bogusGuid)),
419 "unexpected subject GUID\n");
420 }
421 /* Specifying a bogus GUID pointer crashes */
422 if (0)
423 {
424 fileInfo.pgKnownSubject = (GUID *)0xdeadbeef;
425 ret = funcs->pfnObjectTrust(&data);
426 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
427 }
428 funcs->pfnFree(data.padwTrustStepErrors);
429 }
430 }
431
432 static const BYTE selfSignedCert[] = {
433 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x43,
434 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d,
435 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x44, 0x70, 0x7a, 0x43, 0x43,
436 0x41, 0x6f, 0x2b, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49, 0x4a,
437 0x41, 0x4c, 0x59, 0x51, 0x67, 0x65, 0x66, 0x7a, 0x51, 0x41, 0x61, 0x43,
438 0x4d, 0x41, 0x30, 0x47, 0x43, 0x53, 0x71, 0x47, 0x53, 0x49, 0x62, 0x33,
439 0x44, 0x51, 0x45, 0x42, 0x42, 0x51, 0x55, 0x41, 0x4d, 0x47, 0x6f, 0x78,
440 0x43, 0x7a, 0x41, 0x4a, 0x42, 0x67, 0x4e, 0x56, 0x0a, 0x42, 0x41, 0x59,
441 0x54, 0x41, 0x6b, 0x46, 0x56, 0x4d, 0x52, 0x4d, 0x77, 0x45, 0x51, 0x59,
442 0x44, 0x56, 0x51, 0x51, 0x49, 0x44, 0x41, 0x70, 0x54, 0x62, 0x32, 0x31,
443 0x6c, 0x4c, 0x56, 0x4e, 0x30, 0x59, 0x58, 0x52, 0x6c, 0x4d, 0x53, 0x45,
444 0x77, 0x48, 0x77, 0x59, 0x44, 0x56, 0x51, 0x51, 0x4b, 0x44, 0x42, 0x68,
445 0x4a, 0x62, 0x6e, 0x52, 0x6c, 0x63, 0x6d, 0x35, 0x6c, 0x64, 0x43, 0x42,
446 0x58, 0x0a, 0x61, 0x57, 0x52, 0x6e, 0x61, 0x58, 0x52, 0x7a, 0x49, 0x46,
447 0x42, 0x30, 0x65, 0x53, 0x42, 0x4d, 0x64, 0x47, 0x51, 0x78, 0x49, 0x7a,
448 0x41, 0x68, 0x42, 0x67, 0x4e, 0x56, 0x42, 0x41, 0x4d, 0x4d, 0x47, 0x6e,
449 0x4e, 0x6c, 0x62, 0x47, 0x5a, 0x7a, 0x61, 0x57, 0x64, 0x75, 0x5a, 0x57,
450 0x51, 0x75, 0x64, 0x47, 0x56, 0x7a, 0x64, 0x43, 0x35, 0x33, 0x61, 0x57,
451 0x35, 0x6c, 0x61, 0x48, 0x45, 0x75, 0x0a, 0x62, 0x33, 0x4a, 0x6e, 0x4d,
452 0x42, 0x34, 0x58, 0x44, 0x54, 0x45, 0x7a, 0x4d, 0x44, 0x59, 0x79, 0x4d,
453 0x54, 0x45, 0x78, 0x4d, 0x6a, 0x55, 0x78, 0x4d, 0x46, 0x6f, 0x58, 0x44,
454 0x54, 0x49, 0x7a, 0x4d, 0x44, 0x59, 0x78, 0x4f, 0x54, 0x45, 0x78, 0x4d,
455 0x6a, 0x55, 0x78, 0x4d, 0x46, 0x6f, 0x77, 0x61, 0x6a, 0x45, 0x4c, 0x4d,
456 0x41, 0x6b, 0x47, 0x41, 0x31, 0x55, 0x45, 0x42, 0x68, 0x4d, 0x43, 0x0a,
457 0x51, 0x56, 0x55, 0x78, 0x45, 0x7a, 0x41, 0x52, 0x42, 0x67, 0x4e, 0x56,
458 0x42, 0x41, 0x67, 0x4d, 0x43, 0x6c, 0x4e, 0x76, 0x62, 0x57, 0x55, 0x74,
459 0x55, 0x33, 0x52, 0x68, 0x64, 0x47, 0x55, 0x78, 0x49, 0x54, 0x41, 0x66,
460 0x42, 0x67, 0x4e, 0x56, 0x42, 0x41, 0x6f, 0x4d, 0x47, 0x45, 0x6c, 0x75,
461 0x64, 0x47, 0x56, 0x79, 0x62, 0x6d, 0x56, 0x30, 0x49, 0x46, 0x64, 0x70,
462 0x5a, 0x47, 0x64, 0x70, 0x0a, 0x64, 0x48, 0x4d, 0x67, 0x55, 0x48, 0x52,
463 0x35, 0x49, 0x45, 0x78, 0x30, 0x5a, 0x44, 0x45, 0x6a, 0x4d, 0x43, 0x45,
464 0x47, 0x41, 0x31, 0x55, 0x45, 0x41, 0x77, 0x77, 0x61, 0x63, 0x32, 0x56,
465 0x73, 0x5a, 0x6e, 0x4e, 0x70, 0x5a, 0x32, 0x35, 0x6c, 0x5a, 0x43, 0x35,
466 0x30, 0x5a, 0x58, 0x4e, 0x30, 0x4c, 0x6e, 0x64, 0x70, 0x62, 0x6d, 0x56,
467 0x6f, 0x63, 0x53, 0x35, 0x76, 0x63, 0x6d, 0x63, 0x77, 0x0a, 0x67, 0x67,
468 0x45, 0x69, 0x4d, 0x41, 0x30, 0x47, 0x43, 0x53, 0x71, 0x47, 0x53, 0x49,
469 0x62, 0x33, 0x44, 0x51, 0x45, 0x42, 0x41, 0x51, 0x55, 0x41, 0x41, 0x34,
470 0x49, 0x42, 0x44, 0x77, 0x41, 0x77, 0x67, 0x67, 0x45, 0x4b, 0x41, 0x6f,
471 0x49, 0x42, 0x41, 0x51, 0x44, 0x77, 0x4e, 0x6d, 0x2b, 0x46, 0x7a, 0x78,
472 0x6e, 0x6b, 0x48, 0x57, 0x2f, 0x4e, 0x70, 0x37, 0x59, 0x48, 0x34, 0x4d,
473 0x79, 0x45, 0x0a, 0x77, 0x4d, 0x6c, 0x49, 0x67, 0x71, 0x30, 0x66, 0x45,
474 0x77, 0x70, 0x47, 0x6f, 0x41, 0x75, 0x78, 0x44, 0x64, 0x61, 0x46, 0x55,
475 0x32, 0x6f, 0x70, 0x76, 0x41, 0x51, 0x56, 0x61, 0x2b, 0x41, 0x43, 0x46,
476 0x38, 0x63, 0x6f, 0x38, 0x4d, 0x4a, 0x6c, 0x33, 0x78, 0x77, 0x76, 0x46,
477 0x44, 0x2b, 0x67, 0x61, 0x46, 0x45, 0x7a, 0x59, 0x78, 0x53, 0x58, 0x30,
478 0x43, 0x47, 0x72, 0x4a, 0x45, 0x4c, 0x63, 0x0a, 0x74, 0x34, 0x4d, 0x69,
479 0x30, 0x68, 0x4b, 0x50, 0x76, 0x42, 0x70, 0x65, 0x73, 0x59, 0x6c, 0x46,
480 0x4d, 0x51, 0x65, 0x6b, 0x2b, 0x63, 0x70, 0x51, 0x50, 0x33, 0x4b, 0x35,
481 0x75, 0x36, 0x71, 0x58, 0x5a, 0x52, 0x49, 0x67, 0x48, 0x75, 0x59, 0x45,
482 0x4c, 0x2f, 0x73, 0x55, 0x6f, 0x39, 0x32, 0x70, 0x44, 0x30, 0x7a, 0x4a,
483 0x65, 0x4c, 0x47, 0x41, 0x31, 0x49, 0x30, 0x4b, 0x5a, 0x34, 0x73, 0x2f,
484 0x0a, 0x51, 0x7a, 0x77, 0x61, 0x4f, 0x38, 0x62, 0x62, 0x4b, 0x6d, 0x37,
485 0x42, 0x72, 0x6e, 0x56, 0x77, 0x30, 0x6e, 0x5a, 0x2f, 0x4b, 0x41, 0x5a,
486 0x6a, 0x75, 0x78, 0x75, 0x6f, 0x4e, 0x33, 0x52, 0x64, 0x72, 0x69, 0x30,
487 0x4a, 0x48, 0x77, 0x7a, 0x6a, 0x41, 0x55, 0x34, 0x2b, 0x71, 0x57, 0x65,
488 0x55, 0x63, 0x2f, 0x64, 0x33, 0x45, 0x70, 0x4f, 0x47, 0x78, 0x69, 0x42,
489 0x77, 0x5a, 0x4e, 0x61, 0x7a, 0x0a, 0x39, 0x6f, 0x4a, 0x41, 0x37, 0x54,
490 0x2f, 0x51, 0x6f, 0x62, 0x75, 0x61, 0x4e, 0x53, 0x6b, 0x65, 0x55, 0x48,
491 0x43, 0x61, 0x50, 0x53, 0x6a, 0x44, 0x37, 0x71, 0x7a, 0x6c, 0x43, 0x4f,
492 0x52, 0x48, 0x47, 0x68, 0x75, 0x31, 0x76, 0x79, 0x79, 0x35, 0x31, 0x45,
493 0x36, 0x79, 0x46, 0x43, 0x4e, 0x47, 0x66, 0x65, 0x7a, 0x71, 0x2f, 0x4d,
494 0x59, 0x34, 0x4e, 0x4b, 0x68, 0x77, 0x72, 0x61, 0x59, 0x64, 0x0a, 0x62,
495 0x79, 0x49, 0x2f, 0x6c, 0x42, 0x46, 0x62, 0x36, 0x35, 0x6b, 0x5a, 0x45,
496 0x66, 0x49, 0x4b, 0x4b, 0x54, 0x7a, 0x79, 0x36, 0x76, 0x30, 0x44, 0x65,
497 0x79, 0x50, 0x37, 0x52, 0x6b, 0x34, 0x75, 0x48, 0x44, 0x38, 0x77, 0x62,
498 0x49, 0x79, 0x50, 0x32, 0x47, 0x6c, 0x42, 0x30, 0x67, 0x37, 0x2f, 0x69,
499 0x79, 0x33, 0x4c, 0x61, 0x74, 0x49, 0x74, 0x49, 0x70, 0x2b, 0x49, 0x35,
500 0x53, 0x50, 0x56, 0x0a, 0x41, 0x67, 0x4d, 0x42, 0x41, 0x41, 0x47, 0x6a,
501 0x55, 0x44, 0x42, 0x4f, 0x4d, 0x42, 0x30, 0x47, 0x41, 0x31, 0x55, 0x64,
502 0x44, 0x67, 0x51, 0x57, 0x42, 0x42, 0x53, 0x36, 0x49, 0x4c, 0x5a, 0x2f,
503 0x71, 0x38, 0x66, 0x2f, 0x4b, 0x45, 0x68, 0x4b, 0x76, 0x68, 0x69, 0x2b,
504 0x73, 0x6b, 0x59, 0x45, 0x31, 0x79, 0x48, 0x71, 0x39, 0x7a, 0x41, 0x66,
505 0x42, 0x67, 0x4e, 0x56, 0x48, 0x53, 0x4d, 0x45, 0x0a, 0x47, 0x44, 0x41,
506 0x57, 0x67, 0x42, 0x53, 0x36, 0x49, 0x4c, 0x5a, 0x2f, 0x71, 0x38, 0x66,
507 0x2f, 0x4b, 0x45, 0x68, 0x4b, 0x76, 0x68, 0x69, 0x2b, 0x73, 0x6b, 0x59,
508 0x45, 0x31, 0x79, 0x48, 0x71, 0x39, 0x7a, 0x41, 0x4d, 0x42, 0x67, 0x4e,
509 0x56, 0x48, 0x52, 0x4d, 0x45, 0x42, 0x54, 0x41, 0x44, 0x41, 0x51, 0x48,
510 0x2f, 0x4d, 0x41, 0x30, 0x47, 0x43, 0x53, 0x71, 0x47, 0x53, 0x49, 0x62,
511 0x33, 0x0a, 0x44, 0x51, 0x45, 0x42, 0x42, 0x51, 0x55, 0x41, 0x41, 0x34,
512 0x49, 0x42, 0x41, 0x51, 0x41, 0x79, 0x5a, 0x59, 0x77, 0x47, 0x4b, 0x46,
513 0x34, 0x34, 0x43, 0x68, 0x47, 0x51, 0x72, 0x6e, 0x74, 0x57, 0x6c, 0x38,
514 0x48, 0x53, 0x4a, 0x30, 0x63, 0x69, 0x55, 0x58, 0x4d, 0x44, 0x4b, 0x32,
515 0x46, 0x6c, 0x6f, 0x74, 0x47, 0x49, 0x6a, 0x30, 0x32, 0x6c, 0x4d, 0x39,
516 0x38, 0x71, 0x45, 0x49, 0x65, 0x68, 0x0a, 0x56, 0x67, 0x66, 0x41, 0x34,
517 0x7a, 0x69, 0x37, 0x4d, 0x45, 0x6c, 0x51, 0x61, 0x76, 0x6b, 0x52, 0x76,
518 0x32, 0x54, 0x43, 0x50, 0x50, 0x55, 0x51, 0x62, 0x35, 0x51, 0x64, 0x61,
519 0x6f, 0x37, 0x57, 0x78, 0x37, 0x6c, 0x66, 0x61, 0x54, 0x6f, 0x5a, 0x68,
520 0x4f, 0x54, 0x2b, 0x4e, 0x52, 0x68, 0x32, 0x6b, 0x35, 0x78, 0x2b, 0x6b,
521 0x6a, 0x5a, 0x46, 0x77, 0x38, 0x70, 0x45, 0x48, 0x74, 0x35, 0x51, 0x0a,
522 0x69, 0x68, 0x62, 0x46, 0x4c, 0x35, 0x58, 0x2b, 0x57, 0x7a, 0x6f, 0x2b,
523 0x42, 0x36, 0x36, 0x59, 0x79, 0x49, 0x76, 0x68, 0x77, 0x54, 0x63, 0x48,
524 0x30, 0x46, 0x2b, 0x6e, 0x66, 0x55, 0x71, 0x66, 0x74, 0x38, 0x59, 0x74,
525 0x72, 0x2f, 0x38, 0x37, 0x47, 0x45, 0x62, 0x73, 0x41, 0x48, 0x6a, 0x48,
526 0x43, 0x36, 0x4c, 0x2b, 0x77, 0x6b, 0x31, 0x76, 0x4e, 0x6e, 0x64, 0x49,
527 0x59, 0x47, 0x30, 0x51, 0x0a, 0x79, 0x62, 0x73, 0x7a, 0x78, 0x49, 0x72,
528 0x32, 0x6d, 0x46, 0x45, 0x49, 0x4a, 0x6f, 0x69, 0x51, 0x44, 0x44, 0x67,
529 0x66, 0x6c, 0x71, 0x67, 0x64, 0x76, 0x4c, 0x54, 0x32, 0x79, 0x64, 0x46,
530 0x6d, 0x79, 0x33, 0x73, 0x32, 0x68, 0x49, 0x74, 0x51, 0x6c, 0x49, 0x71,
531 0x4b, 0x4c, 0x42, 0x36, 0x49, 0x4a, 0x51, 0x49, 0x75, 0x69, 0x37, 0x72,
532 0x37, 0x34, 0x76, 0x64, 0x72, 0x63, 0x58, 0x71, 0x58, 0x0a, 0x44, 0x7a,
533 0x68, 0x6d, 0x4c, 0x66, 0x67, 0x6a, 0x67, 0x4c, 0x77, 0x33, 0x2b, 0x55,
534 0x79, 0x69, 0x59, 0x74, 0x44, 0x54, 0x76, 0x63, 0x78, 0x65, 0x7a, 0x62,
535 0x4c, 0x73, 0x76, 0x51, 0x6f, 0x52, 0x6b, 0x74, 0x77, 0x4b, 0x5a, 0x4c,
536 0x44, 0x54, 0x42, 0x42, 0x35, 0x76, 0x59, 0x32, 0x78, 0x4b, 0x36, 0x6b,
537 0x4f, 0x4f, 0x44, 0x70, 0x7a, 0x50, 0x48, 0x73, 0x4b, 0x67, 0x30, 0x42,
538 0x59, 0x77, 0x0a, 0x4d, 0x6b, 0x48, 0x56, 0x56, 0x54, 0x34, 0x79, 0x2f,
539 0x4d, 0x59, 0x36, 0x63, 0x63, 0x4b, 0x51, 0x2f, 0x4c, 0x56, 0x74, 0x32,
540 0x66, 0x4a, 0x49, 0x74, 0x69, 0x41, 0x71, 0x49, 0x47, 0x32, 0x38, 0x64,
541 0x37, 0x31, 0x53, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44,
542 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45,
543 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a
544 };
545
testCertTrust(SAFE_PROVIDER_FUNCTIONS * funcs,GUID * actionID)546 static void testCertTrust(SAFE_PROVIDER_FUNCTIONS *funcs, GUID *actionID)
547 {
548 CRYPT_PROVIDER_DATA data = { 0 };
549 CRYPT_PROVIDER_SIGSTATE sig_state = { 0 };
550 CRYPT_PROVIDER_SGNR sgnr = { sizeof(sgnr), { 0 } };
551 HRESULT ret;
552 BOOL b;
553
554 if (!CertFreeCertificateChain_p)
555 {
556 win_skip("CertFreeCertificateChain not found\n");
557 return;
558 }
559
560 data.pSigState = &sig_state;
561 data.padwTrustStepErrors =
562 funcs->pfnAlloc(TRUSTERROR_MAX_STEPS * sizeof(DWORD));
563 if (!data.padwTrustStepErrors)
564 {
565 skip("pfnAlloc failed\n");
566 return;
567 }
568 ret = funcs->pfnCertificateTrust(&data);
569 ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
570 ok(data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_CERTPROV] ==
571 TRUST_E_NOSIGNATURE, "Expected TRUST_E_NOSIGNATURE, got %08x\n",
572 data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_CERTPROV]);
573 b = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, &sgnr);
574 if (b)
575 {
576 PCCERT_CONTEXT cert;
577
578 /* An empty signer "succeeds," even though there's no cert */
579 ret = funcs->pfnCertificateTrust(&data);
580 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
581 cert = CertCreateCertificateContext(X509_ASN_ENCODING, selfSignedCert,
582 sizeof(selfSignedCert));
583 if (cert)
584 {
585 WINTRUST_DATA wintrust_data = { 0 };
586
587 b = funcs->pfnAddCert2Chain(&data, 0, FALSE, 0, cert);
588 ok(b == TRUE, "Expected TRUE, got %d\n", b);
589
590 /* If pWintrustData isn't set, crashes attempting to access
591 * pWintrustData->fdwRevocationChecks
592 */
593 data.pWintrustData = &wintrust_data;
594 /* If psPfns isn't set, crashes attempting to access
595 * psPfns->pfnCertCheckPolicy
596 */
597 data.psPfns = (CRYPT_PROVIDER_FUNCTIONS *)funcs;
598 ret = funcs->pfnCertificateTrust(&data);
599 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
600 ok(data.csSigners == 1, "Unexpected number of signers %d\n",
601 data.csSigners);
602 ok(data.pasSigners[0].pChainContext != NULL,
603 "Expected a certificate chain\n");
604 ok(data.pasSigners[0].csCertChain == 1,
605 "Unexpected number of chain elements %d\n",
606 data.pasSigners[0].csCertChain);
607 /* pasSigners and pasSigners[0].pasCertChain are guaranteed to be
608 * initialized, see tests for pfnAddSgnr2Chain and pfnAddCert2Chain
609 */
610 ok(!data.pasSigners[0].pasCertChain[0].fTrustedRoot,
611 "Didn't expect cert to be trusted\n");
612 ok(data.pasSigners[0].pasCertChain[0].fSelfSigned,
613 "Expected cert to be self-signed\n");
614 ok(data.pasSigners[0].pasCertChain[0].dwConfidence ==
615 (CERT_CONFIDENCE_SIG | CERT_CONFIDENCE_TIMENEST),
616 "Expected CERT_CONFIDENCE_SIG | CERT_CONFIDENCE_TIMENEST, got %08x\n",
617 data.pasSigners[0].pasCertChain[0].dwConfidence);
618 CertFreeCertificateContext(
619 data.pasSigners[0].pasCertChain[0].pCert);
620 CertFreeCertificateChain_p(data.pasSigners[0].pChainContext);
621 CertFreeCertificateContext(cert);
622 }
623 }
624 funcs->pfnFree(data.padwTrustStepErrors);
625 }
626
test_provider_funcs(void)627 static void test_provider_funcs(void)
628 {
629 static GUID generic_verify_v2 = WINTRUST_ACTION_GENERIC_VERIFY_V2;
630 SAFE_PROVIDER_FUNCTIONS funcs = { sizeof(SAFE_PROVIDER_FUNCTIONS), 0 };
631 BOOL ret;
632
633 ret = WintrustLoadFunctionPointers(&generic_verify_v2,
634 (CRYPT_PROVIDER_FUNCTIONS *)&funcs);
635 if (!ret)
636 skip("WintrustLoadFunctionPointers failed\n");
637 else
638 {
639 test_utils(&funcs);
640 testInitialize(&funcs, &generic_verify_v2);
641 testObjTrust(&funcs, &generic_verify_v2);
642 testCertTrust(&funcs, &generic_verify_v2);
643 }
644 }
645
646 /* minimal PE file image */
647 #define VA_START 0x400000
648 #define FILE_PE_START 0x50
649 #define NUM_SECTIONS 3
650 #define FILE_TEXT 0x200
651 #define RVA_TEXT 0x1000
652 #define RVA_BSS 0x2000
653 #define FILE_IDATA 0x400
654 #define RVA_IDATA 0x3000
655 #define FILE_TOTAL 0x600
656 #define RVA_TOTAL 0x4000
657 #include <pshpack1.h>
658 struct Imports {
659 IMAGE_IMPORT_DESCRIPTOR descriptors[2];
660 IMAGE_THUNK_DATA32 original_thunks[2];
661 IMAGE_THUNK_DATA32 thunks[2];
662 struct __IMPORT_BY_NAME {
663 WORD hint;
664 char funcname[0x20];
665 } ibn;
666 char dllname[0x10];
667 };
668 #define EXIT_PROCESS (VA_START+RVA_IDATA+FIELD_OFFSET(struct Imports, thunks))
669
670 static struct _PeImage {
671 IMAGE_DOS_HEADER dos_header;
672 char __alignment1[FILE_PE_START - sizeof(IMAGE_DOS_HEADER)];
673 IMAGE_NT_HEADERS32 nt_headers;
674 IMAGE_SECTION_HEADER sections[NUM_SECTIONS];
675 char __alignment2[FILE_TEXT - FILE_PE_START - sizeof(IMAGE_NT_HEADERS32) -
676 NUM_SECTIONS * sizeof(IMAGE_SECTION_HEADER)];
677 unsigned char text_section[FILE_IDATA-FILE_TEXT];
678 struct Imports idata_section;
679 char __alignment3[FILE_TOTAL-FILE_IDATA-sizeof(struct Imports)];
680 } bin = {
681 /* dos header */
682 {IMAGE_DOS_SIGNATURE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0}, 0, 0, {0}, FILE_PE_START},
683 /* alignment before PE header */
684 {0},
685 /* nt headers */
686 {IMAGE_NT_SIGNATURE,
687 /* basic headers - 3 sections, no symbols, EXE file */
688 {IMAGE_FILE_MACHINE_I386, NUM_SECTIONS, 0, 0, 0, sizeof(IMAGE_OPTIONAL_HEADER32),
689 IMAGE_FILE_32BIT_MACHINE | IMAGE_FILE_EXECUTABLE_IMAGE},
690 /* optional header */
691 {IMAGE_NT_OPTIONAL_HDR32_MAGIC, 4, 0, FILE_IDATA-FILE_TEXT,
692 FILE_TOTAL-FILE_IDATA + FILE_IDATA-FILE_TEXT, 0x400,
693 RVA_TEXT, RVA_TEXT, RVA_BSS, VA_START, 0x1000, 0x200, 4, 0, 1, 0, 4, 0, 0,
694 RVA_TOTAL, FILE_TEXT, 0, IMAGE_SUBSYSTEM_WINDOWS_GUI, 0,
695 0x200000, 0x1000, 0x100000, 0x1000, 0, 0x10,
696 {{0, 0},
697 {RVA_IDATA, sizeof(struct Imports)}
698 }
699 }
700 },
701 /* sections */
702 {
703 {".text", {0x100}, RVA_TEXT, FILE_IDATA-FILE_TEXT, FILE_TEXT,
704 0, 0, 0, 0, IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ},
705 {".bss", {0x400}, RVA_BSS, 0, 0, 0, 0, 0, 0,
706 IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE},
707 {".idata", {sizeof(struct Imports)}, RVA_IDATA, FILE_TOTAL-FILE_IDATA, FILE_IDATA, 0,
708 0, 0, 0, IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE}
709 },
710 /* alignment before first section */
711 {0},
712 /* .text section */
713 {
714 0x31, 0xC0, /* xor eax, eax */
715 0xFF, 0x25, EXIT_PROCESS&0xFF, (EXIT_PROCESS>>8)&0xFF, (EXIT_PROCESS>>16)&0xFF,
716 (EXIT_PROCESS>>24)&0xFF, /* jmp ExitProcess */
717 0
718 },
719 /* .idata section */
720 {
721 {
722 {{RVA_IDATA + FIELD_OFFSET(struct Imports, original_thunks)}, 0, 0,
723 RVA_IDATA + FIELD_OFFSET(struct Imports, dllname),
724 RVA_IDATA + FIELD_OFFSET(struct Imports, thunks)
725 },
726 {{0}, 0, 0, 0, 0}
727 },
728 {{{RVA_IDATA+FIELD_OFFSET(struct Imports, ibn)}}, {{0}}},
729 {{{RVA_IDATA+FIELD_OFFSET(struct Imports, ibn)}}, {{0}}},
730 {0,"ExitProcess"},
731 "KERNEL32.DLL"
732 },
733 /* final alignment */
734 {0}
735 };
736 #include <poppack.h>
737
test_sip_create_indirect_data(void)738 static void test_sip_create_indirect_data(void)
739 {
740 static GUID unknown = { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,
741 0x00,0xC0,0x4F,0xC2,0x95,0xEE } };
742 static char oid_sha1[] = szOID_OIWSEC_sha1;
743 BOOL ret;
744 SIP_SUBJECTINFO subjinfo = { 0 };
745 WCHAR temp_file[MAX_PATH];
746 HANDLE file;
747 DWORD count;
748
749 if (!CryptSIPCreateIndirectData_p)
750 {
751 skip("Missing CryptSIPCreateIndirectData\n");
752 return;
753 }
754 SetLastError(0xdeadbeef);
755 ret = CryptSIPCreateIndirectData_p(NULL, NULL, NULL);
756 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
757 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
758 SetLastError(0xdeadbeef);
759 ret = CryptSIPCreateIndirectData_p(&subjinfo, NULL, NULL);
760 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
761 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
762 subjinfo.cbSize = sizeof(subjinfo);
763 SetLastError(0xdeadbeef);
764 ret = CryptSIPCreateIndirectData_p(&subjinfo, NULL, NULL);
765 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
766 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
767 file = create_temp_file(temp_file);
768 if (file == INVALID_HANDLE_VALUE)
769 {
770 skip("couldn't create temp file\n");
771 return;
772 }
773 WriteFile(file, &bin, sizeof(bin), &count, NULL);
774 FlushFileBuffers(file);
775
776 subjinfo.hFile = file;
777 SetLastError(0xdeadbeef);
778 ret = CryptSIPCreateIndirectData_p(&subjinfo, NULL, NULL);
779 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
780 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
781 subjinfo.pgSubjectType = &unknown;
782 SetLastError(0xdeadbeef);
783 ret = CryptSIPCreateIndirectData_p(&subjinfo, NULL, NULL);
784 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
785 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
786 subjinfo.DigestAlgorithm.pszObjId = oid_sha1;
787 count = 0xdeadbeef;
788 ret = CryptSIPCreateIndirectData_p(&subjinfo, &count, NULL);
789 todo_wine
790 ok(ret, "CryptSIPCreateIndirectData failed: %d\n", GetLastError());
791 ok(count, "expected a positive count\n");
792 if (ret)
793 {
794 SIP_INDIRECT_DATA *indirect = HeapAlloc(GetProcessHeap(), 0, count);
795
796 count = 256;
797 ret = CryptSIPCreateIndirectData_p(&subjinfo, &count, indirect);
798 ok(ret, "CryptSIPCreateIndirectData failed: %d\n", GetLastError());
799 /* If the count is larger than needed, it's unmodified */
800 ok(count == 256, "unexpected count %d\n", count);
801 ok(!strcmp(indirect->Data.pszObjId, SPC_PE_IMAGE_DATA_OBJID),
802 "unexpected data oid %s\n",
803 indirect->Data.pszObjId);
804 ok(!strcmp(indirect->DigestAlgorithm.pszObjId, oid_sha1),
805 "unexpected digest algorithm oid %s\n",
806 indirect->DigestAlgorithm.pszObjId);
807 ok(indirect->Digest.cbData == 20, "unexpected hash size %d\n",
808 indirect->Digest.cbData);
809 if (indirect->Digest.cbData == 20)
810 {
811 const BYTE hash[20] = {
812 0x8a,0xd5,0x45,0x53,0x3d,0x67,0xdf,0x2f,0x78,0xe0,
813 0x55,0x0a,0xe0,0xd9,0x7a,0x28,0x3e,0xbf,0x45,0x2b };
814
815 ok(!memcmp(indirect->Digest.pbData, hash, 20),
816 "unexpected value\n");
817 }
818
819 HeapFree(GetProcessHeap(), 0, indirect);
820 }
821 CloseHandle(file);
822 DeleteFileW(temp_file);
823 }
824
test_wintrust(void)825 static void test_wintrust(void)
826 {
827 static GUID generic_action_v2 = WINTRUST_ACTION_GENERIC_VERIFY_V2;
828 WINTRUST_DATA wtd;
829 WINTRUST_FILE_INFO file;
830 LONG r;
831 HRESULT hr;
832 WCHAR pathW[MAX_PATH];
833
834 memset(&wtd, 0, sizeof(wtd));
835 wtd.cbStruct = sizeof(wtd);
836 wtd.dwUIChoice = WTD_UI_NONE;
837 wtd.fdwRevocationChecks = WTD_REVOKE_WHOLECHAIN;
838 wtd.dwUnionChoice = WTD_CHOICE_FILE;
839 U(wtd).pFile = &file;
840 wtd.dwStateAction = WTD_STATEACTION_VERIFY;
841 memset(&file, 0, sizeof(file));
842 file.cbStruct = sizeof(file);
843 file.pcwszFilePath = pathW;
844 /* Test with an empty file */
845 file.hFile = create_temp_file(pathW);
846 r = WinVerifyTrust(INVALID_HANDLE_VALUE, &generic_action_v2, &wtd);
847 ok(r == TRUST_E_SUBJECT_FORM_UNKNOWN,
848 "expected TRUST_E_SUBJECT_FORM_UNKNOWN, got %08x\n", r);
849 CloseHandle(file.hFile);
850 DeleteFileW(pathW);
851 file.hFile = NULL;
852 /* Test with a known file path, which we expect not have a signature */
853 getNotepadPath(pathW, MAX_PATH);
854 r = WinVerifyTrust(INVALID_HANDLE_VALUE, &generic_action_v2, &wtd);
855 ok(r == TRUST_E_NOSIGNATURE || r == CRYPT_E_FILE_ERROR,
856 "expected TRUST_E_NOSIGNATURE or CRYPT_E_FILE_ERROR, got %08x\n", r);
857 wtd.dwStateAction = WTD_STATEACTION_CLOSE;
858 r = WinVerifyTrust(INVALID_HANDLE_VALUE, &generic_action_v2, &wtd);
859 ok(r == S_OK, "WinVerifyTrust failed: %08x\n", r);
860 wtd.dwStateAction = WTD_STATEACTION_VERIFY;
861 hr = WinVerifyTrustEx(INVALID_HANDLE_VALUE, &generic_action_v2, &wtd);
862 ok(hr == TRUST_E_NOSIGNATURE || hr == CRYPT_E_FILE_ERROR,
863 "expected TRUST_E_NOSIGNATURE or CRYPT_E_FILE_ERROR, got %08x\n", hr);
864 wtd.dwStateAction = WTD_STATEACTION_CLOSE;
865 r = WinVerifyTrust(INVALID_HANDLE_VALUE, &generic_action_v2, &wtd);
866 ok(r == S_OK, "WinVerifyTrust failed: %08x\n", r);
867 }
868
869 /* Self-signed .exe, built with tcc, signed with signtool
870 * (and a certificate generated on a self-signed CA).
871 *
872 * small.c:
873 * int _start()
874 * {
875 * return 0;
876 * }
877 *
878 * tcc -nostdlib small.c
879 * signtool sign /v /f codesign.pfx small.exe
880 */
881 static const BYTE SelfSignedFile32[] =
882 {
883 0x4D,0x5A,0x90,0x00,0x03,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0xB8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
884 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
885 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x0E,0x1F,0xBA,0x0E,0x00,0xB4,0x09,0xCD,
886 0x21,0xB8,0x01,0x4C,0xCD,0x21,0x54,0x68,0x69,0x73,0x20,0x70,0x72,0x6F,0x67,0x72,0x61,0x6D,0x20,0x63,0x61,0x6E,0x6E,0x6F,
887 0x74,0x20,0x62,0x65,0x20,0x72,0x75,0x6E,0x20,0x69,0x6E,0x20,0x44,0x4F,0x53,0x20,0x6D,0x6F,0x64,0x65,0x2E,0x0D,0x0D,0x0A,
888 0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x45,0x00,0x00,0x4C,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
889 0x00,0x00,0x00,0x00,0xE0,0x00,0x0F,0x03,0x0B,0x01,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
890 0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x10,0x00,0x00,0x00,0x02,0x00,0x00,
891 0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x02,0x00,0x00,
892 0xE7,0x0C,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x00,
893 0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
894 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x68,0x05,0x00,0x00,
895 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
896 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
897 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
898 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2E,0x74,0x65,0x78,0x74,0x00,0x00,0x00,
899 0x18,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
900 0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
901 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
902 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
903 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
904 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x55,0x89,0xE5,0x81,0xEC,0x00,0x00,0x00,0x00,0x90,0xB8,0x00,0x00,0x00,0x00,0xE9,
905 0x00,0x00,0x00,0x00,0xC9,0xC3,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
906 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
907 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
908 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
909 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
910 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
911 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
912 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
913 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
914 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
915 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
916 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
917 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
918 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
919 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
920 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
921 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
922 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
923 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
924 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
925 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x68,0x05,0x00,0x00,0x00,0x02,0x02,0x00,
926 /* Start of the signature overlay */
927 0x30,0x82,0x05,0x5A,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x02,0xA0,0x82,0x05,0x4B,0x30,0x82,0x05,0x47,0x02,
928 0x01,0x01,0x31,0x0B,0x30,0x09,0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0x30,0x4C,0x06,0x0A,0x2B,0x06,0x01,0x04,0x01,
929 0x82,0x37,0x02,0x01,0x04,0xA0,0x3E,0x30,0x3C,0x30,0x17,0x06,0x0A,0x2B,0x06,0x01,0x04,0x01,0x82,0x37,0x02,0x01,0x0F,0x30,
930 0x09,0x03,0x01,0x00,0xA0,0x04,0xA2,0x02,0x80,0x00,0x30,0x21,0x30,0x09,0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0x04,
931 0x14,0xA0,0x95,0xDE,0xBD,0x1A,0xB7,0x86,0xAF,0x50,0x63,0xD8,0x8F,0x90,0xD5,0x49,0x96,0x4E,0x44,0xF0,0x71,0xA0,0x82,0x03,
932 0x1D,0x30,0x82,0x03,0x19,0x30,0x82,0x02,0x01,0xA0,0x03,0x02,0x01,0x02,0x02,0x10,0x96,0x53,0x2C,0xC9,0x23,0x56,0x8A,0x87,
933 0x42,0x30,0x3E,0xD5,0x8D,0x72,0xD5,0x25,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x0B,0x05,0x00,0x30,
934 0x17,0x31,0x15,0x30,0x13,0x06,0x03,0x55,0x04,0x03,0x13,0x0C,0x54,0x65,0x73,0x74,0x20,0x43,0x41,0x20,0x52,0x6F,0x6F,0x74,
935 0x30,0x1E,0x17,0x0D,0x31,0x36,0x30,0x33,0x30,0x33,0x32,0x30,0x32,0x37,0x30,0x37,0x5A,0x17,0x0D,0x34,0x39,0x31,0x32,0x33,
936 0x31,0x32,0x33,0x30,0x30,0x30,0x30,0x5A,0x30,0x17,0x31,0x15,0x30,0x13,0x06,0x03,0x55,0x04,0x03,0x13,0x0C,0x43,0x6F,0x64,
937 0x65,0x53,0x69,0x67,0x6E,0x54,0x65,0x73,0x74,0x30,0x82,0x01,0x22,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,
938 0x01,0x01,0x05,0x00,0x03,0x82,0x01,0x0F,0x00,0x30,0x82,0x01,0x0A,0x02,0x82,0x01,0x01,0x00,0xB2,0xC9,0x91,0x98,0x8C,0xDC,
939 0x80,0xBC,0x16,0xBF,0xC1,0x04,0x77,0x90,0xC0,0xFD,0x8C,0xBA,0x68,0x26,0xAC,0xB7,0x20,0x68,0x41,0xED,0xC3,0x9C,0x47,0x7C,
940 0x36,0xC2,0x7B,0xE1,0x5E,0xFD,0xA9,0x99,0xF4,0x29,0x36,0x86,0x93,0x40,0x55,0x53,0x65,0x79,0xBC,0x9F,0x8F,0x6E,0x2B,0x05,
941 0x84,0xE1,0xFD,0xD2,0xEF,0xEA,0x89,0x8C,0xEC,0xF9,0x55,0xF0,0x2C,0xE5,0xA7,0x29,0xF9,0x7E,0x50,0xDC,0x9C,0xA1,0x23,0xA5,
942 0xD9,0x78,0xA1,0xE7,0x7C,0xD7,0x04,0x4F,0x11,0xAC,0x9F,0x4A,0x47,0xA1,0x1E,0xD5,0x9E,0xE7,0x5B,0xB5,0x8C,0x9C,0x67,0x7A,
943 0xD0,0xF8,0x54,0xD1,0x64,0x7F,0x39,0x48,0xB6,0xCF,0x2F,0x26,0x7D,0x7B,0x13,0x2B,0xC2,0x8F,0xA6,0x3F,0x42,0x71,0x95,0x3E,
944 0x59,0x0F,0x12,0xFA,0xC2,0x70,0x89,0xB7,0xB6,0x10,0x49,0xE0,0x7D,0x4D,0xFC,0x80,0x61,0x53,0x50,0x72,0xFD,0x46,0x35,0x51,
945 0x36,0xE6,0x06,0xA9,0x4C,0x0D,0x82,0x15,0xF6,0x5D,0xDE,0xD4,0xDB,0xE7,0x82,0x10,0x40,0xA1,0x47,0x68,0x88,0x0C,0x0A,0x80,
946 0xD1,0xE5,0x9A,0x35,0x28,0x82,0x1F,0x0F,0x80,0x5A,0x6E,0x1D,0x22,0x22,0xB3,0xA7,0xA2,0x9E,0x82,0x2D,0xC0,0x7F,0x5A,0xD0,
947 0xBA,0xB2,0xCA,0x20,0xE2,0x97,0xE9,0x72,0x41,0xB7,0xD6,0x1A,0x93,0x23,0x97,0xF0,0xA9,0x61,0xD2,0x91,0xBD,0xB6,0x6B,0x95,
948 0x12,0x67,0x16,0xAC,0x0A,0xB7,0x55,0x02,0x0D,0xA5,0xAD,0x17,0x95,0x77,0xF9,0x96,0x03,0x41,0xD3,0xE1,0x61,0x68,0xBB,0x0A,
949 0xB5,0xC4,0xEE,0x70,0x40,0x08,0x05,0xC4,0xF1,0x5D,0x02,0x03,0x01,0x00,0x01,0xA3,0x61,0x30,0x5F,0x30,0x13,0x06,0x03,0x55,
950 0x1D,0x25,0x04,0x0C,0x30,0x0A,0x06,0x08,0x2B,0x06,0x01,0x05,0x05,0x07,0x03,0x03,0x30,0x48,0x06,0x03,0x55,0x1D,0x01,0x04,
951 0x41,0x30,0x3F,0x80,0x10,0x35,0x40,0x67,0x8F,0x7D,0x03,0x1B,0x76,0x52,0x62,0x2D,0xF5,0x21,0xF6,0x7C,0xBC,0xA1,0x19,0x30,
952 0x17,0x31,0x15,0x30,0x13,0x06,0x03,0x55,0x04,0x03,0x13,0x0C,0x54,0x65,0x73,0x74,0x20,0x43,0x41,0x20,0x52,0x6F,0x6F,0x74,
953 0x82,0x10,0xA0,0x4B,0xEB,0xAC,0xFA,0x08,0xF2,0x8B,0x47,0xD2,0xB3,0x54,0x60,0x6C,0xE6,0x29,0x30,0x0D,0x06,0x09,0x2A,0x86,
954 0x48,0x86,0xF7,0x0D,0x01,0x01,0x0B,0x05,0x00,0x03,0x82,0x01,0x01,0x00,0x5F,0x8C,0x7F,0xDA,0x1D,0x21,0x7A,0x15,0xD8,0x20,
955 0x04,0x53,0x7F,0x44,0x6D,0x7B,0x57,0xBE,0x7F,0x86,0x77,0x58,0xC4,0xD4,0x80,0xC7,0x2E,0x64,0x9B,0x44,0xC5,0x2D,0x6D,0xDB,
956 0x35,0x5A,0xFE,0xA4,0xD8,0x66,0x9B,0xF7,0x6E,0xFC,0xEF,0x52,0x7B,0xC5,0x16,0xE6,0xA3,0x7D,0x59,0xB7,0x31,0x28,0xEB,0xB5,
957 0x45,0xC9,0xB1,0xD1,0x08,0x67,0xC6,0x37,0xE7,0xD7,0x2A,0xE6,0x1F,0xD9,0x6A,0xE5,0x04,0xDF,0x6A,0x9D,0x91,0xFA,0x41,0xBD,
958 0x2A,0x50,0xEA,0x99,0x24,0xA9,0x0F,0x2B,0x50,0x51,0x5F,0xD9,0x0B,0x89,0x1B,0xCB,0xDB,0x88,0xE8,0xEC,0x87,0xB0,0x16,0xCC,
959 0x43,0xEE,0x5A,0xBD,0x57,0xE2,0x46,0xA7,0x56,0x54,0x23,0x32,0x8A,0xFB,0x25,0x51,0x39,0x38,0xE6,0x87,0xF5,0x73,0x63,0xD0,
960 0x5B,0xC7,0x3F,0xFD,0x04,0x75,0x74,0x4C,0x3D,0xB5,0x31,0x22,0x7D,0xF1,0x8D,0xB4,0xE0,0xAA,0xE1,0xFF,0x8F,0xDD,0xB8,0x04,
961 0x6A,0x31,0xEE,0x30,0x2D,0x6E,0x74,0x0F,0x37,0x71,0x77,0x2B,0xB8,0x9E,0x62,0x47,0x00,0x9C,0xA5,0x82,0x2B,0x9F,0x24,0x67,
962 0x50,0x86,0x8B,0xC9,0x36,0x81,0xEB,0x44,0xC2,0xF1,0x91,0xA6,0x84,0x75,0x15,0x8F,0x22,0xDE,0xAC,0xB5,0x16,0xE3,0x96,0x74,
963 0x72,0x2F,0x15,0xD5,0xFB,0x01,0x22,0xC4,0x24,0xEE,0x3D,0xDF,0x9E,0xA9,0x0A,0x5B,0x16,0x21,0xE8,0x4A,0x8C,0x7E,0x3A,0x9C,
964 0x22,0xA0,0x49,0x60,0x97,0x1B,0x3E,0x2D,0x80,0x91,0xDB,0xF7,0x78,0x38,0x76,0x78,0x0C,0xE3,0xD4,0x27,0x77,0x69,0x96,0xE6,
965 0x41,0xC7,0x2E,0xE9,0x61,0xD6,0x31,0x82,0x01,0xC4,0x30,0x82,0x01,0xC0,0x02,0x01,0x01,0x30,0x2B,0x30,0x17,0x31,0x15,0x30,
966 0x13,0x06,0x03,0x55,0x04,0x03,0x13,0x0C,0x54,0x65,0x73,0x74,0x20,0x43,0x41,0x20,0x52,0x6F,0x6F,0x74,0x02,0x10,0x96,0x53,
967 0x2C,0xC9,0x23,0x56,0x8A,0x87,0x42,0x30,0x3E,0xD5,0x8D,0x72,0xD5,0x25,0x30,0x09,0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,
968 0x00,0xA0,0x70,0x30,0x10,0x06,0x0A,0x2B,0x06,0x01,0x04,0x01,0x82,0x37,0x02,0x01,0x0C,0x31,0x02,0x30,0x00,0x30,0x19,0x06,
969 0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x03,0x31,0x0C,0x06,0x0A,0x2B,0x06,0x01,0x04,0x01,0x82,0x37,0x02,0x01,0x04,
970 0x30,0x1C,0x06,0x0A,0x2B,0x06,0x01,0x04,0x01,0x82,0x37,0x02,0x01,0x0B,0x31,0x0E,0x30,0x0C,0x06,0x0A,0x2B,0x06,0x01,0x04,
971 0x01,0x82,0x37,0x02,0x01,0x15,0x30,0x23,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x04,0x31,0x16,0x04,0x14,0x3D,
972 0x08,0xC8,0xA3,0xEE,0x05,0x1A,0x61,0xD9,0xFE,0x1A,0x63,0xC0,0x8A,0x6E,0x9D,0xF9,0xC3,0x13,0x98,0x30,0x0D,0x06,0x09,0x2A,
973 0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x01,0x05,0x00,0x04,0x82,0x01,0x00,0x90,0xF9,0xC0,0x7F,0x1D,0x70,0x8C,0x04,0x22,0x82,
974 0xB6,0x2D,0x48,0xBF,0x30,0x51,0x29,0xF8,0xE3,0x11,0x39,0xE0,0x64,0x23,0x72,0xE2,0x4C,0x09,0x9F,0x39,0xF2,0x6F,0xDD,0xB9,
975 0x5A,0x3D,0xEF,0xEB,0xBE,0xEC,0x3B,0xE6,0x58,0x4C,0xC9,0x4F,0xED,0xCB,0x6E,0x9D,0x67,0x8E,0x89,0x92,0x40,0x39,0xA2,0x5F,
976 0xF9,0xEF,0xD3,0xF5,0x24,0x27,0x8D,0xF7,0x3C,0x92,0x66,0x56,0xC8,0x2B,0xEA,0x04,0xA1,0x0E,0xDA,0x89,0x30,0xA7,0x01,0xD8,
977 0x0B,0xF8,0xFD,0x99,0xB6,0xC0,0x38,0xB0,0x21,0x50,0x3A,0x86,0x01,0xD0,0xF3,0x86,0x72,0xE3,0x5A,0xBB,0x2A,0x6E,0xBD,0xFB,
978 0x22,0xF9,0x42,0xD3,0x04,0xFE,0x8D,0xD8,0x79,0xD1,0xEE,0x61,0xC6,0x48,0x04,0x99,0x9A,0xA2,0x73,0xE5,0xFB,0x24,0x10,0xD5,
979 0x6B,0x71,0x80,0x0E,0x09,0xEA,0x85,0x9A,0xBD,0xBB,0xDE,0x99,0x5D,0xA3,0x18,0x4D,0xED,0x20,0x73,0x3E,0x32,0xEF,0x2C,0xAC,
980 0x5A,0x83,0x87,0x1F,0x7F,0x19,0x61,0x35,0x53,0xC1,0xAA,0x89,0x97,0xB3,0xDD,0x8D,0xA8,0x67,0x5B,0xC2,0xE2,0x09,0xB7,0xDD,
981 0x6A,0xCB,0xD5,0xBF,0xD6,0x08,0xE2,0x23,0x1A,0x41,0x9D,0xD5,0x6A,0x6B,0x8D,0x3C,0x29,0x1B,0xF1,0x3F,0x4E,0x4A,0x8F,0x29,
982 0x33,0xF9,0x1C,0x60,0xA0,0x92,0x7E,0x4F,0x35,0xB8,0xDD,0xEB,0xD1,0x68,0x1A,0x9D,0xA2,0xA6,0x97,0x1F,0x5F,0xC6,0x2C,0xFB,
983 0xCA,0xDF,0xF7,0x95,0x33,0x95,0xD4,0x79,0x5C,0x73,0x87,0x49,0x1F,0x8C,0x6E,0xCE,0x3E,0x6D,0x3D,0x2B,0x6B,0xD7,0x66,0xE9,
984 0x88,0x6F,0xF2,0x83,0xB9,0x9B,0x00,0x00
985 };
986
987 static const BYTE SelfSignedFile64[] =
988 {
989 0x4D,0x5A,0x90,0x00,0x03,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0xB8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
990 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
991 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x0E,0x1F,0xBA,0x0E,0x00,0xB4,0x09,0xCD,
992 0x21,0xB8,0x01,0x4C,0xCD,0x21,0x54,0x68,0x69,0x73,0x20,0x70,0x72,0x6F,0x67,0x72,0x61,0x6D,0x20,0x63,0x61,0x6E,0x6E,0x6F,
993 0x74,0x20,0x62,0x65,0x20,0x72,0x75,0x6E,0x20,0x69,0x6E,0x20,0x44,0x4F,0x53,0x20,0x6D,0x6F,0x64,0x65,0x2E,0x0D,0x0D,0x0A,
994 0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x45,0x00,0x00,0x64,0x86,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
995 0x00,0x00,0x00,0x00,0xF0,0x00,0x2F,0x02,0x0B,0x02,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
996 0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x02,0x00,0x00,
997 0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x02,0x00,0x00,
998 0x02,0xB9,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
999 0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,
1000 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1001 0x00,0x20,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x68,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1002 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1003 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1004 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1005 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2E,0x74,0x65,0x78,0x74,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
1006 0x00,0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x60,
1007 0x2E,0x70,0x64,0x61,0x74,0x61,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x04,0x00,0x00,
1008 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1009 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1010 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x55,0x48,0x89,0xE5,0x48,0x81,0xEC,0x00,0x00,0x00,0x00,0xB8,0x00,0x00,0x00,0x00,
1011 0xE9,0x00,0x00,0x00,0x00,0xC9,0xC3,0x00,0x01,0x04,0x02,0x05,0x04,0x03,0x01,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1012 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1013 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1014 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1015 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1016 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1017 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1018 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1019 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1020 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1021 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1022 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1023 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1024 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1025 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1026 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1027 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1028 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1029 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1030 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1031 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0B,0x10,0x00,0x00,0x17,0x10,0x00,0x00,
1032 0x18,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1033 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1034 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1035 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1036 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1037 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1038 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1039 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1040 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1041 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1042 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1043 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1044 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1045 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1046 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1047 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1048 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1049 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1050 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1051 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1052 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1053 /* Start of the signature overlay */
1054 0x68,0x05,0x00,0x00,0x00,0x02,0x02,0x00,0x30,0x82,0x05,0x5A,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x02,0xA0,
1055 0x82,0x05,0x4B,0x30,0x82,0x05,0x47,0x02,0x01,0x01,0x31,0x0B,0x30,0x09,0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0x30,
1056 0x4C,0x06,0x0A,0x2B,0x06,0x01,0x04,0x01,0x82,0x37,0x02,0x01,0x04,0xA0,0x3E,0x30,0x3C,0x30,0x17,0x06,0x0A,0x2B,0x06,0x01,
1057 0x04,0x01,0x82,0x37,0x02,0x01,0x0F,0x30,0x09,0x03,0x01,0x00,0xA0,0x04,0xA2,0x02,0x80,0x00,0x30,0x21,0x30,0x09,0x06,0x05,
1058 0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0x04,0x14,0xCA,0x7C,0x10,0xFB,0x5A,0x96,0x6D,0x69,0xEF,0x26,0x30,0x1A,0xE9,0xC7,0x22,
1059 0x19,0xEB,0x6E,0x17,0x07,0xA0,0x82,0x03,0x1D,0x30,0x82,0x03,0x19,0x30,0x82,0x02,0x01,0xA0,0x03,0x02,0x01,0x02,0x02,0x10,
1060 0x96,0x53,0x2C,0xC9,0x23,0x56,0x8A,0x87,0x42,0x30,0x3E,0xD5,0x8D,0x72,0xD5,0x25,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,
1061 0xF7,0x0D,0x01,0x01,0x0B,0x05,0x00,0x30,0x17,0x31,0x15,0x30,0x13,0x06,0x03,0x55,0x04,0x03,0x13,0x0C,0x54,0x65,0x73,0x74,
1062 0x20,0x43,0x41,0x20,0x52,0x6F,0x6F,0x74,0x30,0x1E,0x17,0x0D,0x31,0x36,0x30,0x33,0x30,0x33,0x32,0x30,0x32,0x37,0x30,0x37,
1063 0x5A,0x17,0x0D,0x34,0x39,0x31,0x32,0x33,0x31,0x32,0x33,0x30,0x30,0x30,0x30,0x5A,0x30,0x17,0x31,0x15,0x30,0x13,0x06,0x03,
1064 0x55,0x04,0x03,0x13,0x0C,0x43,0x6F,0x64,0x65,0x53,0x69,0x67,0x6E,0x54,0x65,0x73,0x74,0x30,0x82,0x01,0x22,0x30,0x0D,0x06,
1065 0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x01,0x05,0x00,0x03,0x82,0x01,0x0F,0x00,0x30,0x82,0x01,0x0A,0x02,0x82,0x01,
1066 0x01,0x00,0xB2,0xC9,0x91,0x98,0x8C,0xDC,0x80,0xBC,0x16,0xBF,0xC1,0x04,0x77,0x90,0xC0,0xFD,0x8C,0xBA,0x68,0x26,0xAC,0xB7,
1067 0x20,0x68,0x41,0xED,0xC3,0x9C,0x47,0x7C,0x36,0xC2,0x7B,0xE1,0x5E,0xFD,0xA9,0x99,0xF4,0x29,0x36,0x86,0x93,0x40,0x55,0x53,
1068 0x65,0x79,0xBC,0x9F,0x8F,0x6E,0x2B,0x05,0x84,0xE1,0xFD,0xD2,0xEF,0xEA,0x89,0x8C,0xEC,0xF9,0x55,0xF0,0x2C,0xE5,0xA7,0x29,
1069 0xF9,0x7E,0x50,0xDC,0x9C,0xA1,0x23,0xA5,0xD9,0x78,0xA1,0xE7,0x7C,0xD7,0x04,0x4F,0x11,0xAC,0x9F,0x4A,0x47,0xA1,0x1E,0xD5,
1070 0x9E,0xE7,0x5B,0xB5,0x8C,0x9C,0x67,0x7A,0xD0,0xF8,0x54,0xD1,0x64,0x7F,0x39,0x48,0xB6,0xCF,0x2F,0x26,0x7D,0x7B,0x13,0x2B,
1071 0xC2,0x8F,0xA6,0x3F,0x42,0x71,0x95,0x3E,0x59,0x0F,0x12,0xFA,0xC2,0x70,0x89,0xB7,0xB6,0x10,0x49,0xE0,0x7D,0x4D,0xFC,0x80,
1072 0x61,0x53,0x50,0x72,0xFD,0x46,0x35,0x51,0x36,0xE6,0x06,0xA9,0x4C,0x0D,0x82,0x15,0xF6,0x5D,0xDE,0xD4,0xDB,0xE7,0x82,0x10,
1073 0x40,0xA1,0x47,0x68,0x88,0x0C,0x0A,0x80,0xD1,0xE5,0x9A,0x35,0x28,0x82,0x1F,0x0F,0x80,0x5A,0x6E,0x1D,0x22,0x22,0xB3,0xA7,
1074 0xA2,0x9E,0x82,0x2D,0xC0,0x7F,0x5A,0xD0,0xBA,0xB2,0xCA,0x20,0xE2,0x97,0xE9,0x72,0x41,0xB7,0xD6,0x1A,0x93,0x23,0x97,0xF0,
1075 0xA9,0x61,0xD2,0x91,0xBD,0xB6,0x6B,0x95,0x12,0x67,0x16,0xAC,0x0A,0xB7,0x55,0x02,0x0D,0xA5,0xAD,0x17,0x95,0x77,0xF9,0x96,
1076 0x03,0x41,0xD3,0xE1,0x61,0x68,0xBB,0x0A,0xB5,0xC4,0xEE,0x70,0x40,0x08,0x05,0xC4,0xF1,0x5D,0x02,0x03,0x01,0x00,0x01,0xA3,
1077 0x61,0x30,0x5F,0x30,0x13,0x06,0x03,0x55,0x1D,0x25,0x04,0x0C,0x30,0x0A,0x06,0x08,0x2B,0x06,0x01,0x05,0x05,0x07,0x03,0x03,
1078 0x30,0x48,0x06,0x03,0x55,0x1D,0x01,0x04,0x41,0x30,0x3F,0x80,0x10,0x35,0x40,0x67,0x8F,0x7D,0x03,0x1B,0x76,0x52,0x62,0x2D,
1079 0xF5,0x21,0xF6,0x7C,0xBC,0xA1,0x19,0x30,0x17,0x31,0x15,0x30,0x13,0x06,0x03,0x55,0x04,0x03,0x13,0x0C,0x54,0x65,0x73,0x74,
1080 0x20,0x43,0x41,0x20,0x52,0x6F,0x6F,0x74,0x82,0x10,0xA0,0x4B,0xEB,0xAC,0xFA,0x08,0xF2,0x8B,0x47,0xD2,0xB3,0x54,0x60,0x6C,
1081 0xE6,0x29,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x0B,0x05,0x00,0x03,0x82,0x01,0x01,0x00,0x5F,0x8C,
1082 0x7F,0xDA,0x1D,0x21,0x7A,0x15,0xD8,0x20,0x04,0x53,0x7F,0x44,0x6D,0x7B,0x57,0xBE,0x7F,0x86,0x77,0x58,0xC4,0xD4,0x80,0xC7,
1083 0x2E,0x64,0x9B,0x44,0xC5,0x2D,0x6D,0xDB,0x35,0x5A,0xFE,0xA4,0xD8,0x66,0x9B,0xF7,0x6E,0xFC,0xEF,0x52,0x7B,0xC5,0x16,0xE6,
1084 0xA3,0x7D,0x59,0xB7,0x31,0x28,0xEB,0xB5,0x45,0xC9,0xB1,0xD1,0x08,0x67,0xC6,0x37,0xE7,0xD7,0x2A,0xE6,0x1F,0xD9,0x6A,0xE5,
1085 0x04,0xDF,0x6A,0x9D,0x91,0xFA,0x41,0xBD,0x2A,0x50,0xEA,0x99,0x24,0xA9,0x0F,0x2B,0x50,0x51,0x5F,0xD9,0x0B,0x89,0x1B,0xCB,
1086 0xDB,0x88,0xE8,0xEC,0x87,0xB0,0x16,0xCC,0x43,0xEE,0x5A,0xBD,0x57,0xE2,0x46,0xA7,0x56,0x54,0x23,0x32,0x8A,0xFB,0x25,0x51,
1087 0x39,0x38,0xE6,0x87,0xF5,0x73,0x63,0xD0,0x5B,0xC7,0x3F,0xFD,0x04,0x75,0x74,0x4C,0x3D,0xB5,0x31,0x22,0x7D,0xF1,0x8D,0xB4,
1088 0xE0,0xAA,0xE1,0xFF,0x8F,0xDD,0xB8,0x04,0x6A,0x31,0xEE,0x30,0x2D,0x6E,0x74,0x0F,0x37,0x71,0x77,0x2B,0xB8,0x9E,0x62,0x47,
1089 0x00,0x9C,0xA5,0x82,0x2B,0x9F,0x24,0x67,0x50,0x86,0x8B,0xC9,0x36,0x81,0xEB,0x44,0xC2,0xF1,0x91,0xA6,0x84,0x75,0x15,0x8F,
1090 0x22,0xDE,0xAC,0xB5,0x16,0xE3,0x96,0x74,0x72,0x2F,0x15,0xD5,0xFB,0x01,0x22,0xC4,0x24,0xEE,0x3D,0xDF,0x9E,0xA9,0x0A,0x5B,
1091 0x16,0x21,0xE8,0x4A,0x8C,0x7E,0x3A,0x9C,0x22,0xA0,0x49,0x60,0x97,0x1B,0x3E,0x2D,0x80,0x91,0xDB,0xF7,0x78,0x38,0x76,0x78,
1092 0x0C,0xE3,0xD4,0x27,0x77,0x69,0x96,0xE6,0x41,0xC7,0x2E,0xE9,0x61,0xD6,0x31,0x82,0x01,0xC4,0x30,0x82,0x01,0xC0,0x02,0x01,
1093 0x01,0x30,0x2B,0x30,0x17,0x31,0x15,0x30,0x13,0x06,0x03,0x55,0x04,0x03,0x13,0x0C,0x54,0x65,0x73,0x74,0x20,0x43,0x41,0x20,
1094 0x52,0x6F,0x6F,0x74,0x02,0x10,0x96,0x53,0x2C,0xC9,0x23,0x56,0x8A,0x87,0x42,0x30,0x3E,0xD5,0x8D,0x72,0xD5,0x25,0x30,0x09,
1095 0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0xA0,0x70,0x30,0x10,0x06,0x0A,0x2B,0x06,0x01,0x04,0x01,0x82,0x37,0x02,0x01,
1096 0x0C,0x31,0x02,0x30,0x00,0x30,0x19,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x03,0x31,0x0C,0x06,0x0A,0x2B,0x06,
1097 0x01,0x04,0x01,0x82,0x37,0x02,0x01,0x04,0x30,0x1C,0x06,0x0A,0x2B,0x06,0x01,0x04,0x01,0x82,0x37,0x02,0x01,0x0B,0x31,0x0E,
1098 0x30,0x0C,0x06,0x0A,0x2B,0x06,0x01,0x04,0x01,0x82,0x37,0x02,0x01,0x15,0x30,0x23,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,
1099 0x01,0x09,0x04,0x31,0x16,0x04,0x14,0x0C,0xEC,0x76,0xF2,0x3F,0xE4,0x6F,0xEB,0xFF,0x00,0xDA,0x95,0xE7,0x8B,0x64,0xBC,0x55,
1100 0xBA,0xF0,0xEA,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x01,0x05,0x00,0x04,0x82,0x01,0x00,0x05,0x22,
1101 0xD1,0xB3,0x85,0x09,0x46,0x99,0x77,0x69,0xC8,0xD2,0x0C,0xFC,0x8D,0xF4,0x01,0xD4,0x5B,0xF0,0xB4,0x13,0x63,0xAF,0x24,0x0E,
1102 0x6C,0x1B,0x14,0xCF,0xA8,0x9A,0xEC,0x7E,0xF2,0x60,0xED,0x6C,0x39,0x4D,0x7A,0x73,0x9C,0x9F,0x24,0x46,0xE2,0xEA,0xFA,0x70,
1103 0xB4,0xAC,0xFC,0x38,0x90,0xF2,0x4F,0x70,0xCC,0x00,0xD1,0x2B,0xB6,0xFB,0xCD,0x7F,0xFC,0xCB,0x35,0xA9,0xA6,0x76,0x37,0xD6,
1104 0x08,0x82,0x99,0x4C,0x47,0xD7,0x4E,0xB5,0xDE,0xCA,0x4E,0xED,0x71,0x48,0xD4,0x84,0xE1,0x30,0x10,0x33,0x7F,0x84,0xEE,0x2F,
1105 0x44,0x99,0xE4,0x26,0x27,0xB5,0xB8,0xC1,0xA1,0x40,0x6B,0x87,0x04,0x95,0xC3,0xF0,0xFF,0x25,0x97,0xFD,0xDB,0x9C,0x67,0x80,
1106 0x39,0x97,0x72,0x75,0x07,0x92,0xA5,0x08,0x19,0x5B,0xD3,0xC9,0x5E,0xC4,0x7B,0xA9,0x04,0x02,0x63,0xCC,0xC5,0x92,0xF6,0xE9,
1107 0xD6,0xB0,0xA8,0xF9,0xD0,0x9F,0x3F,0xBC,0x86,0x77,0x1E,0x12,0x9A,0x9A,0x9B,0x05,0x77,0x39,0x42,0x01,0xB7,0x23,0xF0,0x78,
1108 0x4F,0x52,0x6D,0x1B,0x9F,0xBA,0x29,0xEC,0x90,0xA9,0x1E,0x1E,0x5C,0xA9,0x28,0xA0,0x0B,0x09,0xDC,0x99,0x82,0xE3,0x34,0xBB,
1109 0x5C,0x66,0x8E,0x54,0x95,0x4B,0x65,0x95,0xCD,0x87,0x72,0x74,0xCD,0x3B,0x5C,0x72,0xBB,0x61,0x6A,0x98,0x44,0x9C,0xB0,0x2A,
1110 0xE7,0xB0,0xA6,0x2B,0xDA,0x47,0x5C,0x75,0x36,0xB5,0x90,0x8E,0x82,0x47,0xCD,0x3F,0x4B,0xD0,0xFB,0x8E,0x17,0x6B,0x40,0x57,
1111 0x9C,0x68,0x1A,0x5D,0x92,0xCD,0xD0,0x5F,0x02,0xA1,0x2C,0xD9,0x56,0x20,0x00,0x00
1112 };
1113
call_winverify(WCHAR * pathW,LONG * status,BOOL hash_only)1114 static void call_winverify(WCHAR *pathW, LONG *status, BOOL hash_only)
1115 {
1116 static GUID WVTPolicyGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2;
1117 WINTRUST_FILE_INFO file_info = { sizeof(file_info), 0 };
1118 WINTRUST_DATA data = { sizeof(data), 0 };
1119 LONG ret;
1120
1121 file_info.pcwszFilePath = pathW;
1122
1123 data.dwUIChoice = WTD_UI_NONE;
1124 data.fdwRevocationChecks = WTD_REVOKE_NONE;
1125 data.dwUnionChoice = WTD_CHOICE_FILE;
1126 data.pFile = &file_info;
1127 data.dwStateAction = WTD_STATEACTION_VERIFY;
1128 data.dwProvFlags = hash_only ? WTD_HASH_ONLY_FLAG : 0;
1129 *status = WinVerifyTrust(NULL, &WVTPolicyGUID, &data);
1130
1131 data.dwStateAction = WTD_STATEACTION_CLOSE;
1132 ret = WinVerifyTrust(NULL, &WVTPolicyGUID, &data);
1133 ok(ret == S_OK, "WinVerifyTrust failed: %08x\n", ret);
1134 }
1135
test_wintrust_digest(void)1136 static void test_wintrust_digest(void)
1137 {
1138 static const BYTE Dummy[] = { 0x11,0x22,0x33,0x44 };
1139 static const struct
1140 {
1141 struct { const BYTE *data; DWORD length; } blocks[5];
1142 struct { LONG status; BOOL todo; } t1;
1143 struct { LONG status; BOOL todo; } t2;
1144 }
1145 tests[] =
1146 {
1147 /* 32-bit tests */
1148 {
1149 {{ SelfSignedFile32, sizeof(SelfSignedFile32) }},
1150 { CERT_E_CHAINING, TRUE }, { S_OK, FALSE }
1151 },
1152 {
1153 {{ SelfSignedFile32, sizeof(SelfSignedFile32) },
1154 { Dummy, sizeof(Dummy) }},
1155 { TRUST_E_NOSIGNATURE, FALSE }, { TRUST_E_NOSIGNATURE, FALSE }
1156 },
1157 {
1158 {{ Dummy, sizeof(Dummy) },
1159 { SelfSignedFile32 + sizeof(Dummy), sizeof(SelfSignedFile32) - sizeof(Dummy) }},
1160 { TRUST_E_SUBJECT_FORM_UNKNOWN, FALSE }, { TRUST_E_NOSIGNATURE, TRUE }
1161 },
1162 {
1163 {{ SelfSignedFile32, 19 },
1164 { Dummy, sizeof(Dummy) },
1165 { SelfSignedFile32 + 19 + sizeof(Dummy), sizeof(SelfSignedFile32) - 19 - sizeof(Dummy) }},
1166 { TRUST_E_BAD_DIGEST, FALSE }, { TRUST_E_NOSIGNATURE, TRUE }
1167 },
1168 {
1169 {{ SelfSignedFile32, sizeof(IMAGE_DOS_HEADER) }},
1170 { TRUST_E_SUBJECT_FORM_UNKNOWN, TRUE }, { TRUST_E_NOSIGNATURE, FALSE }
1171 },
1172 {
1173 {{ SelfSignedFile32, sizeof(IMAGE_DOS_HEADER) + sizeof(IMAGE_NT_HEADERS32) * 2 }},
1174 { TRUST_E_NOSIGNATURE, FALSE }, { TRUST_E_NOSIGNATURE, FALSE }
1175 },
1176
1177 /* 64-bit tests */
1178 {
1179 {{ SelfSignedFile64, sizeof(SelfSignedFile64) }},
1180 { CERT_E_CHAINING, TRUE }, { S_OK, FALSE }
1181 },
1182 {
1183 {{ SelfSignedFile64, sizeof(SelfSignedFile64) },
1184 { Dummy, sizeof(Dummy) }},
1185 { TRUST_E_NOSIGNATURE, FALSE }, { TRUST_E_NOSIGNATURE, FALSE }
1186 },
1187 {
1188 {{ Dummy, sizeof(Dummy) },
1189 { SelfSignedFile64 + sizeof(Dummy), sizeof(SelfSignedFile64) - sizeof(Dummy) }},
1190 { TRUST_E_SUBJECT_FORM_UNKNOWN, FALSE }, { TRUST_E_NOSIGNATURE, TRUE }
1191 },
1192 {
1193 {{ SelfSignedFile64, 19 },
1194 { Dummy, sizeof(Dummy) },
1195 { SelfSignedFile64 + 19 + sizeof(Dummy), sizeof(SelfSignedFile64) - 19 - sizeof(Dummy) }},
1196 { TRUST_E_BAD_DIGEST, FALSE }, { TRUST_E_NOSIGNATURE, TRUE }
1197 },
1198 {
1199 {{ SelfSignedFile64, sizeof(IMAGE_DOS_HEADER) }},
1200 { TRUST_E_SUBJECT_FORM_UNKNOWN, TRUE }, { TRUST_E_NOSIGNATURE, FALSE }
1201 },
1202 {
1203 {{ SelfSignedFile64, sizeof(IMAGE_DOS_HEADER) + sizeof(IMAGE_NT_HEADERS64) * 2 }},
1204 { TRUST_E_NOSIGNATURE, FALSE }, { TRUST_E_NOSIGNATURE, FALSE }
1205 },
1206 };
1207 WCHAR pathW[MAX_PATH];
1208 DWORD written;
1209 HANDLE file;
1210 LONG status;
1211 BOOL ret;
1212 int i, j;
1213
1214 for (i = 0; i < ARRAY_SIZE(tests); i++)
1215 {
1216 file = create_temp_file(pathW);
1217 ok(file != INVALID_HANDLE_VALUE, "failed to create temporary file\n");
1218
1219 for (j = 0; tests[i].blocks[j].data; j++)
1220 {
1221 ret = WriteFile(file, tests[i].blocks[j].data, tests[i].blocks[j].length, &written, NULL);
1222 ok(ret && written == tests[i].blocks[j].length, "WriteFile failed with %u\n", GetLastError());
1223 }
1224
1225 CloseHandle(file);
1226
1227 call_winverify(pathW, &status, FALSE);
1228 todo_wine_if(tests[i].t1.todo)
1229 ok(status == tests[i].t1.status, "test %d/1: expected %08x, got %08x\n", i, tests[i].t1.status, status);
1230
1231 call_winverify(pathW, &status, TRUE);
1232 todo_wine_if(tests[i].t2.todo)
1233 ok(status == tests[i].t2.status, "test %d/2: expected %08x, got %08x\n", i, tests[i].t2.status, status);
1234
1235 DeleteFileW(pathW);
1236 }
1237 }
1238
test_get_known_usages(void)1239 static void test_get_known_usages(void)
1240 {
1241 BOOL ret;
1242 PCCRYPT_OID_INFO *usages;
1243
1244 if (!pWTHelperGetKnownUsages)
1245 {
1246 skip("missing WTHelperGetKnownUsages\n");
1247 return;
1248 }
1249 SetLastError(0xdeadbeef);
1250 ret = pWTHelperGetKnownUsages(0, NULL);
1251 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1252 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
1253 SetLastError(0xdeadbeef);
1254 ret = pWTHelperGetKnownUsages(1, NULL);
1255 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1256 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
1257 SetLastError(0xdeadbeef);
1258 ret = pWTHelperGetKnownUsages(0, &usages);
1259 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1260 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
1261 /* A value of 1 for the first parameter seems to imply the value is
1262 * allocated
1263 */
1264 SetLastError(0xdeadbeef);
1265 usages = NULL;
1266 ret = pWTHelperGetKnownUsages(1, &usages);
1267 ok(ret, "WTHelperGetKnownUsages failed: %d\n", GetLastError());
1268 ok(usages != NULL, "expected a pointer\n");
1269 if (ret && usages)
1270 {
1271 PCCRYPT_OID_INFO *ptr;
1272
1273 /* The returned usages are an array of PCCRYPT_OID_INFOs, terminated with a
1274 * NULL pointer.
1275 */
1276 for (ptr = usages; *ptr; ptr++)
1277 {
1278 ok((*ptr)->cbSize == sizeof(CRYPT_OID_INFO) ||
1279 (*ptr)->cbSize == (sizeof(CRYPT_OID_INFO) + 2 * sizeof(LPCWSTR)), /* Vista */
1280 "unexpected size %d\n", (*ptr)->cbSize);
1281 /* Each returned usage is in the CRYPT_ENHKEY_USAGE_OID_GROUP_ID group */
1282 ok((*ptr)->dwGroupId == CRYPT_ENHKEY_USAGE_OID_GROUP_ID,
1283 "expected group CRYPT_ENHKEY_USAGE_OID_GROUP_ID, got %d\n",
1284 (*ptr)->dwGroupId);
1285 }
1286 }
1287 /* A value of 2 for the second parameter seems to imply the value is freed
1288 */
1289 SetLastError(0xdeadbeef);
1290 ret = pWTHelperGetKnownUsages(2, &usages);
1291 ok(ret, "WTHelperGetKnownUsages failed: %d\n", GetLastError());
1292 ok(usages == NULL, "expected pointer to be cleared\n");
1293 SetLastError(0xdeadbeef);
1294 usages = NULL;
1295 ret = pWTHelperGetKnownUsages(2, &usages);
1296 ok(ret, "WTHelperGetKnownUsages failed: %d\n", GetLastError());
1297 SetLastError(0xdeadbeef);
1298 ret = pWTHelperGetKnownUsages(2, NULL);
1299 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1300 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
1301 }
1302
test_WTHelperGetProvCertFromChain(void)1303 static void test_WTHelperGetProvCertFromChain(void)
1304 {
1305 CRYPT_PROVIDER_CERT *cert;
1306
1307 cert = WTHelperGetProvCertFromChain(NULL, 0);
1308 ok(!cert, "got certificate\n");
1309 }
1310
START_TEST(softpub)1311 START_TEST(softpub)
1312 {
1313 InitFunctionPtrs();
1314 test_provider_funcs();
1315 test_sip_create_indirect_data();
1316 test_wintrust();
1317 test_wintrust_digest();
1318 test_get_known_usages();
1319 test_WTHelperGetProvCertFromChain();
1320 }
1321