d914b8e0815c5f97047b2f794c4415a64437c3fa
[reactos.git] / reactos / dll / win32 / wintrust / register.c
1 /*
2 * Register related wintrust functions
3 *
4 * Copyright 2006 Paul Vriens
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 #include "wintrust_priv.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(wintrust);
24
25 static CRYPT_TRUST_REG_ENTRY SoftpubInitialization;
26 static CRYPT_TRUST_REG_ENTRY SoftpubMessage;
27 static CRYPT_TRUST_REG_ENTRY SoftpubSignature;
28 static CRYPT_TRUST_REG_ENTRY SoftpubCertficate;
29 static CRYPT_TRUST_REG_ENTRY SoftpubCertCheck;
30 static CRYPT_TRUST_REG_ENTRY SoftpubFinalPolicy;
31 static CRYPT_TRUST_REG_ENTRY SoftpubCleanup;
32
33 static CRYPT_TRUST_REG_ENTRY SoftpubDefCertInit;
34
35 static CRYPT_TRUST_REG_ENTRY SoftpubDumpStructure;
36
37 static CRYPT_TRUST_REG_ENTRY HTTPSCertificateTrust;
38 static CRYPT_TRUST_REG_ENTRY HTTPSFinalProv;
39
40 static CRYPT_TRUST_REG_ENTRY OfficeInitializePolicy;
41 static CRYPT_TRUST_REG_ENTRY OfficeCleanupPolicy;
42
43 static CRYPT_TRUST_REG_ENTRY DriverInitializePolicy;
44 static CRYPT_TRUST_REG_ENTRY DriverFinalPolicy;
45 static CRYPT_TRUST_REG_ENTRY DriverCleanupPolicy;
46
47 static CRYPT_TRUST_REG_ENTRY GenericChainCertificateTrust;
48 static CRYPT_TRUST_REG_ENTRY GenericChainFinalProv;
49
50 static const CRYPT_TRUST_REG_ENTRY NullCTRE = { 0, NULL, NULL };
51
52 static const WCHAR Trust[] = {'S','o','f','t','w','a','r','e','\\',
53 'M','i','c','r','o','s','o','f','t','\\',
54 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
55 'P','r','o','v','i','d','e','r','s','\\',
56 'T','r','u','s','t','\\', 0 };
57
58 static const WCHAR Initialization[] = {'I','n','i','t','i','a','l','i','z','a','t','i','o','n','\\', 0};
59 static const WCHAR Message[] = {'M','e','s','s','a','g','e','\\', 0};
60 static const WCHAR Signature[] = {'S','i','g','n','a','t','u','r','e','\\', 0};
61 static const WCHAR Certificate[] = {'C','e','r','t','i','f','i','c','a','t','e','\\', 0};
62 static const WCHAR CertCheck[] = {'C','e','r','t','C','h','e','c','k','\\', 0};
63 static const WCHAR FinalPolicy[] = {'F','i','n','a','l','P','o','l','i','c','y','\\', 0};
64 static const WCHAR DiagnosticPolicy[] = {'D','i','a','g','n','o','s','t','i','c','P','o','l','i','c','y','\\', 0};
65 static const WCHAR Cleanup[] = {'C','l','e','a','n','u','p','\\', 0};
66
67 static const WCHAR DefaultId[] = {'D','e','f','a','u','l','t','I','d', 0};
68 static const WCHAR Dll[] = {'$','D','L','L', 0};
69
70 /***********************************************************************
71 * WINTRUST_InitRegStructs
72 *
73 * Helper function to allocate and initialize the members of the
74 * CRYPT_TRUST_REG_ENTRY structs.
75 */
76 static void WINTRUST_InitRegStructs(void)
77 {
78 #define WINTRUST_INITREGENTRY( action, dllname, functionname ) \
79 action.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY); \
80 action.pwszDLLName = WINTRUST_Alloc(sizeof(dllname)); \
81 lstrcpyW(action.pwszDLLName, dllname); \
82 action.pwszFunctionName = WINTRUST_Alloc(sizeof(functionname)); \
83 lstrcpyW(action.pwszFunctionName, functionname);
84
85 WINTRUST_INITREGENTRY(SoftpubInitialization, SP_POLICY_PROVIDER_DLL_NAME, SP_INIT_FUNCTION)
86 WINTRUST_INITREGENTRY(SoftpubMessage, SP_POLICY_PROVIDER_DLL_NAME, SP_OBJTRUST_FUNCTION)
87 WINTRUST_INITREGENTRY(SoftpubSignature, SP_POLICY_PROVIDER_DLL_NAME, SP_SIGTRUST_FUNCTION)
88 WINTRUST_INITREGENTRY(SoftpubCertficate, SP_POLICY_PROVIDER_DLL_NAME, WT_PROVIDER_CERTTRUST_FUNCTION)
89 WINTRUST_INITREGENTRY(SoftpubCertCheck, SP_POLICY_PROVIDER_DLL_NAME, SP_CHKCERT_FUNCTION)
90 WINTRUST_INITREGENTRY(SoftpubFinalPolicy, SP_POLICY_PROVIDER_DLL_NAME, SP_FINALPOLICY_FUNCTION)
91 WINTRUST_INITREGENTRY(SoftpubCleanup, SP_POLICY_PROVIDER_DLL_NAME, SP_CLEANUPPOLICY_FUNCTION)
92 WINTRUST_INITREGENTRY(SoftpubDefCertInit, SP_POLICY_PROVIDER_DLL_NAME, SP_GENERIC_CERT_INIT_FUNCTION)
93 WINTRUST_INITREGENTRY(SoftpubDumpStructure, SP_POLICY_PROVIDER_DLL_NAME, SP_TESTDUMPPOLICY_FUNCTION_TEST)
94 WINTRUST_INITREGENTRY(HTTPSCertificateTrust, SP_POLICY_PROVIDER_DLL_NAME, HTTPS_CERTTRUST_FUNCTION)
95 WINTRUST_INITREGENTRY(HTTPSFinalProv, SP_POLICY_PROVIDER_DLL_NAME, HTTPS_FINALPOLICY_FUNCTION)
96 WINTRUST_INITREGENTRY(OfficeInitializePolicy, OFFICE_POLICY_PROVIDER_DLL_NAME, OFFICE_INITPROV_FUNCTION)
97 WINTRUST_INITREGENTRY(OfficeCleanupPolicy, OFFICE_POLICY_PROVIDER_DLL_NAME, OFFICE_CLEANUPPOLICY_FUNCTION)
98 WINTRUST_INITREGENTRY(DriverInitializePolicy, SP_POLICY_PROVIDER_DLL_NAME, DRIVER_INITPROV_FUNCTION)
99 WINTRUST_INITREGENTRY(DriverFinalPolicy, SP_POLICY_PROVIDER_DLL_NAME, DRIVER_FINALPOLPROV_FUNCTION)
100 WINTRUST_INITREGENTRY(DriverCleanupPolicy, SP_POLICY_PROVIDER_DLL_NAME, DRIVER_CLEANUPPOLICY_FUNCTION)
101 WINTRUST_INITREGENTRY(GenericChainCertificateTrust, SP_POLICY_PROVIDER_DLL_NAME, GENERIC_CHAIN_CERTTRUST_FUNCTION)
102 WINTRUST_INITREGENTRY(GenericChainFinalProv, SP_POLICY_PROVIDER_DLL_NAME, GENERIC_CHAIN_FINALPOLICY_FUNCTION)
103
104 #undef WINTRUST_INITREGENTRY
105 }
106
107 /***********************************************************************
108 * WINTRUST_FreeRegStructs
109 *
110 * Helper function to free 2 members of the CRYPT_TRUST_REG_ENTRY
111 * structs.
112 */
113 static void WINTRUST_FreeRegStructs(void)
114 {
115 #define WINTRUST_FREEREGENTRY( action ) \
116 WINTRUST_Free(action.pwszDLLName); \
117 WINTRUST_Free(action.pwszFunctionName);
118
119 WINTRUST_FREEREGENTRY(SoftpubInitialization);
120 WINTRUST_FREEREGENTRY(SoftpubMessage);
121 WINTRUST_FREEREGENTRY(SoftpubSignature);
122 WINTRUST_FREEREGENTRY(SoftpubCertficate);
123 WINTRUST_FREEREGENTRY(SoftpubCertCheck);
124 WINTRUST_FREEREGENTRY(SoftpubFinalPolicy);
125 WINTRUST_FREEREGENTRY(SoftpubCleanup);
126 WINTRUST_FREEREGENTRY(SoftpubDefCertInit);
127 WINTRUST_FREEREGENTRY(SoftpubDumpStructure);
128 WINTRUST_FREEREGENTRY(HTTPSCertificateTrust);
129 WINTRUST_FREEREGENTRY(HTTPSFinalProv);
130 WINTRUST_FREEREGENTRY(OfficeInitializePolicy);
131 WINTRUST_FREEREGENTRY(OfficeCleanupPolicy);
132 WINTRUST_FREEREGENTRY(DriverInitializePolicy);
133 WINTRUST_FREEREGENTRY(DriverFinalPolicy);
134 WINTRUST_FREEREGENTRY(DriverCleanupPolicy);
135 WINTRUST_FREEREGENTRY(GenericChainCertificateTrust);
136 WINTRUST_FREEREGENTRY(GenericChainFinalProv);
137
138 #undef WINTRUST_FREEREGENTRY
139 }
140
141 /***********************************************************************
142 * WINTRUST_guid2wstr
143 *
144 * Create a wide-string from a GUID
145 *
146 */
147 static void WINTRUST_Guid2Wstr(const GUID* pgActionID, WCHAR* GuidString)
148 {
149 static const WCHAR wszFormat[] = {'{','%','0','8','l','X','-','%','0','4','X','-','%','0','4','X','-',
150 '%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2',
151 'X','%','0','2','X','%','0','2','X','}', 0};
152
153 wsprintfW(GuidString, wszFormat, pgActionID->Data1, pgActionID->Data2, pgActionID->Data3,
154 pgActionID->Data4[0], pgActionID->Data4[1], pgActionID->Data4[2], pgActionID->Data4[3],
155 pgActionID->Data4[4], pgActionID->Data4[5], pgActionID->Data4[6], pgActionID->Data4[7]);
156 }
157
158 /***********************************************************************
159 * WINTRUST_WriteProviderToReg
160 *
161 * Helper function for WintrustAddActionID
162 *
163 */
164 static LONG WINTRUST_WriteProviderToReg(WCHAR* GuidString,
165 const WCHAR* FunctionType,
166 CRYPT_TRUST_REG_ENTRY RegEntry)
167 {
168 static const WCHAR Function[] = {'$','F','u','n','c','t','i','o','n', 0};
169 WCHAR ProvKey[MAX_PATH];
170 HKEY Key;
171 LONG Res = ERROR_SUCCESS;
172
173 /* Create the needed key string */
174 ProvKey[0]='\0';
175 lstrcatW(ProvKey, Trust);
176 lstrcatW(ProvKey, FunctionType);
177 lstrcatW(ProvKey, GuidString);
178
179 if (!RegEntry.pwszDLLName || !RegEntry.pwszFunctionName)
180 return ERROR_INVALID_PARAMETER;
181
182 Res = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ProvKey, 0, NULL, 0, KEY_WRITE, NULL, &Key, NULL);
183 if (Res != ERROR_SUCCESS) goto error_close_key;
184
185 /* Create the $DLL entry */
186 Res = RegSetValueExW(Key, Dll, 0, REG_SZ, (BYTE*)RegEntry.pwszDLLName,
187 (lstrlenW(RegEntry.pwszDLLName) + 1)*sizeof(WCHAR));
188 if (Res != ERROR_SUCCESS) goto error_close_key;
189
190 /* Create the $Function entry */
191 Res = RegSetValueExW(Key, Function, 0, REG_SZ, (BYTE*)RegEntry.pwszFunctionName,
192 (lstrlenW(RegEntry.pwszFunctionName) + 1)*sizeof(WCHAR));
193
194 error_close_key:
195 RegCloseKey(Key);
196
197 return Res;
198 }
199
200 /***********************************************************************
201 * WintrustAddActionID (WINTRUST.@)
202 *
203 * Add the definitions of the actions a Trust provider can perform to
204 * the registry.
205 *
206 * PARAMS
207 * pgActionID [I] Pointer to a GUID for the Trust provider.
208 * fdwFlags [I] Flag to indicate whether registry errors are passed on.
209 * psProvInfo [I] Pointer to a structure with information about DLL
210 * name and functions.
211 *
212 * RETURNS
213 * Success: TRUE.
214 * Failure: FALSE. (Use GetLastError() for more information)
215 *
216 * NOTES
217 * Adding definitions is basically only adding relevant information
218 * to the registry. No verification takes place whether a DLL or its
219 * entrypoints exist.
220 * Information in the registry will always be overwritten.
221 *
222 */
223 BOOL WINAPI WintrustAddActionID( GUID* pgActionID, DWORD fdwFlags,
224 CRYPT_REGISTER_ACTIONID* psProvInfo)
225 {
226 WCHAR GuidString[39];
227 LONG Res;
228 LONG WriteActionError = ERROR_SUCCESS;
229
230 TRACE("%s %x %p\n", debugstr_guid(pgActionID), fdwFlags, psProvInfo);
231
232 /* Some sanity checks.
233 * We use the W2K3 last error as it makes more sense (W2K leaves the last error
234 * as is).
235 */
236 if (!pgActionID ||
237 !psProvInfo ||
238 (psProvInfo->cbStruct != sizeof(CRYPT_REGISTER_ACTIONID)))
239 {
240 SetLastError(ERROR_INVALID_PARAMETER);
241 return FALSE;
242 }
243
244 /* Create this string only once, instead of in the helper function */
245 WINTRUST_Guid2Wstr( pgActionID, GuidString);
246
247 /* Write the information to the registry */
248 Res = WINTRUST_WriteProviderToReg(GuidString, Initialization , psProvInfo->sInitProvider);
249 if (Res != ERROR_SUCCESS) WriteActionError = Res;
250 Res = WINTRUST_WriteProviderToReg(GuidString, Message , psProvInfo->sObjectProvider);
251 if (Res != ERROR_SUCCESS) WriteActionError = Res;
252 Res = WINTRUST_WriteProviderToReg(GuidString, Signature , psProvInfo->sSignatureProvider);
253 if (Res != ERROR_SUCCESS) WriteActionError = Res;
254 Res = WINTRUST_WriteProviderToReg(GuidString, Certificate , psProvInfo->sCertificateProvider);
255 if (Res != ERROR_SUCCESS) WriteActionError = Res;
256 Res = WINTRUST_WriteProviderToReg(GuidString, CertCheck , psProvInfo->sCertificatePolicyProvider);
257 if (Res != ERROR_SUCCESS) WriteActionError = Res;
258 Res = WINTRUST_WriteProviderToReg(GuidString, FinalPolicy , psProvInfo->sFinalPolicyProvider);
259 if (Res != ERROR_SUCCESS) WriteActionError = Res;
260 Res = WINTRUST_WriteProviderToReg(GuidString, DiagnosticPolicy, psProvInfo->sTestPolicyProvider);
261 if (Res != ERROR_SUCCESS) WriteActionError = Res;
262 Res = WINTRUST_WriteProviderToReg(GuidString, Cleanup , psProvInfo->sCleanupProvider);
263 if (Res != ERROR_SUCCESS) WriteActionError = Res;
264
265 /* Testing (by restricting access to the registry for some keys) shows that the last failing function
266 * will be used for last error.
267 * If the flag WT_ADD_ACTION_ID_RET_RESULT_FLAG is set and there are errors when adding the action
268 * we have to return FALSE. Errors includes both invalid entries as well as registry errors.
269 * Testing also showed that one error doesn't stop the registry writes. Every action will be dealt with.
270 */
271
272 if (WriteActionError != ERROR_SUCCESS)
273 {
274 SetLastError(WriteActionError);
275
276 if (fdwFlags == WT_ADD_ACTION_ID_RET_RESULT_FLAG)
277 return FALSE;
278 }
279
280 return TRUE;
281 }
282
283 /***********************************************************************
284 * WINTRUST_RemoveProviderFromReg
285 *
286 * Helper function for WintrustRemoveActionID
287 *
288 */
289 static void WINTRUST_RemoveProviderFromReg(WCHAR* GuidString,
290 const WCHAR* FunctionType)
291 {
292 WCHAR ProvKey[MAX_PATH];
293
294 /* Create the needed key string */
295 ProvKey[0]='\0';
296 lstrcatW(ProvKey, Trust);
297 lstrcatW(ProvKey, FunctionType);
298 lstrcatW(ProvKey, GuidString);
299
300 /* We don't care about success or failure */
301 RegDeleteKeyW(HKEY_LOCAL_MACHINE, ProvKey);
302 }
303
304 /***********************************************************************
305 * WintrustRemoveActionID (WINTRUST.@)
306 *
307 * Remove the definitions of the actions a Trust provider can perform
308 * from the registry.
309 *
310 * PARAMS
311 * pgActionID [I] Pointer to a GUID for the Trust provider.
312 *
313 * RETURNS
314 * Success: TRUE. (Use GetLastError() for more information)
315 * Failure: FALSE. (Use GetLastError() for more information)
316 *
317 * NOTES
318 * Testing shows that WintrustRemoveActionID always returns TRUE and
319 * that a possible error should be retrieved via GetLastError().
320 * There are no checks if the definitions are in the registry.
321 */
322 BOOL WINAPI WintrustRemoveActionID( GUID* pgActionID )
323 {
324 WCHAR GuidString[39];
325
326 TRACE("(%s)\n", debugstr_guid(pgActionID));
327
328 if (!pgActionID)
329 {
330 SetLastError(ERROR_INVALID_PARAMETER);
331 return TRUE;
332 }
333
334 /* Create this string only once, instead of in the helper function */
335 WINTRUST_Guid2Wstr( pgActionID, GuidString);
336
337 /* We don't care about success or failure */
338 WINTRUST_RemoveProviderFromReg(GuidString, Initialization);
339 WINTRUST_RemoveProviderFromReg(GuidString, Message);
340 WINTRUST_RemoveProviderFromReg(GuidString, Signature);
341 WINTRUST_RemoveProviderFromReg(GuidString, Certificate);
342 WINTRUST_RemoveProviderFromReg(GuidString, CertCheck);
343 WINTRUST_RemoveProviderFromReg(GuidString, FinalPolicy);
344 WINTRUST_RemoveProviderFromReg(GuidString, DiagnosticPolicy);
345 WINTRUST_RemoveProviderFromReg(GuidString, Cleanup);
346
347 return TRUE;
348 }
349
350 /***********************************************************************
351 * WINTRUST_WriteSingleUsageEntry
352 *
353 * Helper for WintrustAddDefaultForUsage, writes a single value and its
354 * data to:
355 *
356 * HKLM\Software\Microsoft\Cryptography\Trust\Usages\<OID>
357 */
358 static LONG WINTRUST_WriteSingleUsageEntry(LPCSTR OID,
359 const WCHAR* Value,
360 WCHAR* Data)
361 {
362 static const WCHAR Usages[] = {'U','s','a','g','e','s','\\', 0};
363 WCHAR* UsageKey;
364 HKEY Key;
365 LONG Res = ERROR_SUCCESS;
366 WCHAR* OIDW;
367 DWORD Len;
368
369 /* Turn OID into a wide-character string */
370 Len = MultiByteToWideChar( CP_ACP, 0, OID, -1, NULL, 0 );
371 OIDW = WINTRUST_Alloc( Len * sizeof(WCHAR) );
372 MultiByteToWideChar( CP_ACP, 0, OID, -1, OIDW, Len );
373
374 /* Allocate the needed space for UsageKey */
375 UsageKey = WINTRUST_Alloc((lstrlenW(Trust) + lstrlenW(Usages) + Len) * sizeof(WCHAR));
376 /* Create the key string */
377 lstrcpyW(UsageKey, Trust);
378 lstrcatW(UsageKey, Usages);
379 lstrcatW(UsageKey, OIDW);
380
381 Res = RegCreateKeyExW(HKEY_LOCAL_MACHINE, UsageKey, 0, NULL, 0, KEY_WRITE, NULL, &Key, NULL);
382 if (Res == ERROR_SUCCESS)
383 {
384 /* Create the Value entry */
385 Res = RegSetValueExW(Key, Value, 0, REG_SZ, (BYTE*)Data,
386 (lstrlenW(Data) + 1)*sizeof(WCHAR));
387 }
388 RegCloseKey(Key);
389
390 WINTRUST_Free(OIDW);
391 WINTRUST_Free(UsageKey);
392
393 return Res;
394 }
395
396 /***************************************************************************
397 * WINTRUST_RegisterGenVerifyV2
398 *
399 * Register WINTRUST_ACTION_GENERIC_VERIFY_V2 actions and usages.
400 *
401 * NOTES
402 * WINTRUST_ACTION_GENERIC_VERIFY_V2 ({00AAC56B-CD44-11D0-8CC2-00C04FC295EE}
403 * is defined in softpub.h
404 */
405 static BOOL WINTRUST_RegisterGenVerifyV2(void)
406 {
407 BOOL RegisteredOK = TRUE;
408 static GUID ProvGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2;
409 CRYPT_REGISTER_ACTIONID ProvInfo;
410 CRYPT_PROVIDER_REGDEFUSAGE DefUsage = { sizeof(CRYPT_PROVIDER_REGDEFUSAGE),
411 &ProvGUID,
412 NULL, /* No Dll provided */
413 NULL, /* No load callback function */
414 NULL }; /* No free callback function */
415
416 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
417 ProvInfo.sInitProvider = SoftpubInitialization;
418 ProvInfo.sObjectProvider = SoftpubMessage;
419 ProvInfo.sSignatureProvider = SoftpubSignature;
420 ProvInfo.sCertificateProvider = SoftpubCertficate;
421 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
422 ProvInfo.sFinalPolicyProvider = SoftpubFinalPolicy;
423 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
424 ProvInfo.sCleanupProvider = SoftpubCleanup;
425
426 if (!WintrustAddDefaultForUsage(szOID_PKIX_KP_CODE_SIGNING, &DefUsage))
427 RegisteredOK = FALSE;
428
429 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
430 RegisteredOK = FALSE;
431
432 return RegisteredOK;
433 }
434
435 /***************************************************************************
436 * WINTRUST_RegisterPublishedSoftware
437 *
438 * Register WIN_SPUB_ACTION_PUBLISHED_SOFTWARE actions and usages.
439 *
440 * NOTES
441 * WIN_SPUB_ACTION_PUBLISHED_SOFTWARE ({64B9D180-8DA2-11CF-8736-00AA00A485EB})
442 * is defined in wintrust.h
443 */
444 static BOOL WINTRUST_RegisterPublishedSoftware(void)
445 {
446 static GUID ProvGUID = WIN_SPUB_ACTION_PUBLISHED_SOFTWARE;
447 CRYPT_REGISTER_ACTIONID ProvInfo;
448
449 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
450 ProvInfo.sInitProvider = SoftpubInitialization;
451 ProvInfo.sObjectProvider = SoftpubMessage;
452 ProvInfo.sSignatureProvider = SoftpubSignature;
453 ProvInfo.sCertificateProvider = SoftpubCertficate;
454 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
455 ProvInfo.sFinalPolicyProvider = SoftpubFinalPolicy;
456 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
457 ProvInfo.sCleanupProvider = SoftpubCleanup;
458
459 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
460 return FALSE;
461
462 return TRUE;
463 }
464
465 #define WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI { 0xc6b2e8d0, 0xe005, 0x11cf, { 0xa1,0x34,0x00,0xc0,0x4f,0xd7,0xbf,0x43 }}
466
467 /***************************************************************************
468 * WINTRUST_RegisterPublishedSoftwareNoBadUi
469 *
470 * Register WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI actions and usages.
471 *
472 * NOTES
473 * WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI ({C6B2E8D0-E005-11CF-A134-00C04FD7BF43})
474 * is not defined in any include file. (FIXME: Find out if the name is correct).
475 */
476 static BOOL WINTRUST_RegisterPublishedSoftwareNoBadUi(void)
477 {
478 static GUID ProvGUID = WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI;
479 CRYPT_REGISTER_ACTIONID ProvInfo;
480
481 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
482 ProvInfo.sInitProvider = SoftpubInitialization;
483 ProvInfo.sObjectProvider = SoftpubMessage;
484 ProvInfo.sSignatureProvider = SoftpubSignature;
485 ProvInfo.sCertificateProvider = SoftpubCertficate;
486 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
487 ProvInfo.sFinalPolicyProvider = SoftpubFinalPolicy;
488 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
489 ProvInfo.sCleanupProvider = SoftpubCleanup;
490
491 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
492 return FALSE;
493
494 return TRUE;
495 }
496
497 /***************************************************************************
498 * WINTRUST_RegisterGenCertVerify
499 *
500 * Register WINTRUST_ACTION_GENERIC_CERT_VERIFY actions and usages.
501 *
502 * NOTES
503 * WINTRUST_ACTION_GENERIC_CERT_VERIFY ({189A3842-3041-11D1-85E1-00C04FC295EE})
504 * is defined in softpub.h
505 */
506 static BOOL WINTRUST_RegisterGenCertVerify(void)
507 {
508 static GUID ProvGUID = WINTRUST_ACTION_GENERIC_CERT_VERIFY;
509 CRYPT_REGISTER_ACTIONID ProvInfo;
510
511 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
512 ProvInfo.sInitProvider = SoftpubDefCertInit;
513 ProvInfo.sObjectProvider = SoftpubMessage;
514 ProvInfo.sSignatureProvider = SoftpubSignature;
515 ProvInfo.sCertificateProvider = SoftpubCertficate;
516 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
517 ProvInfo.sFinalPolicyProvider = SoftpubFinalPolicy;
518 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
519 ProvInfo.sCleanupProvider = SoftpubCleanup;
520
521 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
522 return FALSE;
523
524 return TRUE;
525 }
526
527 /***************************************************************************
528 * WINTRUST_RegisterTrustProviderTest
529 *
530 * Register WINTRUST_ACTION_TRUSTPROVIDER_TEST actions and usages.
531 *
532 * NOTES
533 * WINTRUST_ACTION_TRUSTPROVIDER_TEST ({573E31F8-DDBA-11D0-8CCB-00C04FC295EE})
534 * is defined in softpub.h
535 */
536 static BOOL WINTRUST_RegisterTrustProviderTest(void)
537 {
538 static GUID ProvGUID = WINTRUST_ACTION_TRUSTPROVIDER_TEST;
539 CRYPT_REGISTER_ACTIONID ProvInfo;
540
541 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
542 ProvInfo.sInitProvider = SoftpubInitialization;
543 ProvInfo.sObjectProvider = SoftpubMessage;
544 ProvInfo.sSignatureProvider = SoftpubSignature;
545 ProvInfo.sCertificateProvider = SoftpubCertficate;
546 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
547 ProvInfo.sFinalPolicyProvider = SoftpubFinalPolicy;
548 ProvInfo.sTestPolicyProvider = SoftpubDumpStructure;
549 ProvInfo.sCleanupProvider = SoftpubCleanup;
550
551 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
552 return FALSE;
553
554 return TRUE;
555 }
556
557 /***************************************************************************
558 * WINTRUST_RegisterHttpsProv
559 *
560 * Register HTTPSPROV_ACTION actions and usages.
561 *
562 * NOTES
563 * HTTPSPROV_ACTION ({573E31F8-AABA-11D0-8CCB-00C04FC295EE})
564 * is defined in softpub.h
565 */
566 static BOOL WINTRUST_RegisterHttpsProv(void)
567 {
568 BOOL RegisteredOK = TRUE;
569 static CHAR SoftpubLoadUsage[] = "SoftpubLoadDefUsageCallData";
570 static CHAR SoftpubFreeUsage[] = "SoftpubFreeDefUsageCallData";
571 static GUID ProvGUID = HTTPSPROV_ACTION;
572 CRYPT_REGISTER_ACTIONID ProvInfo;
573 CRYPT_PROVIDER_REGDEFUSAGE DefUsage = { sizeof(CRYPT_PROVIDER_REGDEFUSAGE),
574 &ProvGUID,
575 NULL, /* Will be filled later */
576 SoftpubLoadUsage,
577 SoftpubFreeUsage };
578
579 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
580 ProvInfo.sInitProvider = SoftpubInitialization;
581 ProvInfo.sObjectProvider = SoftpubMessage;
582 ProvInfo.sSignatureProvider = SoftpubSignature;
583 ProvInfo.sCertificateProvider = HTTPSCertificateTrust;
584 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
585 ProvInfo.sFinalPolicyProvider = HTTPSFinalProv;
586 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
587 ProvInfo.sCleanupProvider = SoftpubCleanup;
588
589 DefUsage.pwszDllName = WINTRUST_Alloc(sizeof(SP_POLICY_PROVIDER_DLL_NAME));
590 lstrcpyW(DefUsage.pwszDllName, SP_POLICY_PROVIDER_DLL_NAME);
591
592 if (!WintrustAddDefaultForUsage(szOID_PKIX_KP_SERVER_AUTH, &DefUsage))
593 RegisteredOK = FALSE;
594 if (!WintrustAddDefaultForUsage(szOID_PKIX_KP_CLIENT_AUTH, &DefUsage))
595 RegisteredOK = FALSE;
596 if (!WintrustAddDefaultForUsage(szOID_SERVER_GATED_CRYPTO, &DefUsage))
597 RegisteredOK = FALSE;
598 if (!WintrustAddDefaultForUsage(szOID_SGC_NETSCAPE, &DefUsage))
599 RegisteredOK = FALSE;
600
601 WINTRUST_Free(DefUsage.pwszDllName);
602
603 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
604 RegisteredOK = FALSE;
605
606 return RegisteredOK;
607 }
608
609 /***************************************************************************
610 * WINTRUST_RegisterOfficeSignVerify
611 *
612 * Register OFFICESIGN_ACTION_VERIFY actions and usages.
613 *
614 * NOTES
615 * OFFICESIGN_ACTION_VERIFY ({5555C2CD-17FB-11D1-85C4-00C04FC295EE})
616 * is defined in softpub.h
617 */
618 static BOOL WINTRUST_RegisterOfficeSignVerify(void)
619 {
620 static GUID ProvGUID = OFFICESIGN_ACTION_VERIFY;
621 CRYPT_REGISTER_ACTIONID ProvInfo;
622
623 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
624 ProvInfo.sInitProvider = OfficeInitializePolicy;
625 ProvInfo.sObjectProvider = SoftpubMessage;
626 ProvInfo.sSignatureProvider = SoftpubSignature;
627 ProvInfo.sCertificateProvider = SoftpubCertficate;
628 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
629 ProvInfo.sFinalPolicyProvider = SoftpubFinalPolicy;
630 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
631 ProvInfo.sCleanupProvider = OfficeCleanupPolicy;
632
633
634 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
635 return FALSE;
636
637 return TRUE;
638 }
639
640 /***************************************************************************
641 * WINTRUST_RegisterDriverVerify
642 *
643 * Register DRIVER_ACTION_VERIFY actions and usages.
644 *
645 * NOTES
646 * DRIVER_ACTION_VERIFY ({F750E6C3-38EE-11D1-85E5-00C04FC295EE})
647 * is defined in softpub.h
648 */
649 static BOOL WINTRUST_RegisterDriverVerify(void)
650 {
651 static GUID ProvGUID = DRIVER_ACTION_VERIFY;
652 CRYPT_REGISTER_ACTIONID ProvInfo;
653
654 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
655 ProvInfo.sInitProvider = DriverInitializePolicy;
656 ProvInfo.sObjectProvider = SoftpubMessage;
657 ProvInfo.sSignatureProvider = SoftpubSignature;
658 ProvInfo.sCertificateProvider = SoftpubCertficate;
659 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
660 ProvInfo.sFinalPolicyProvider = DriverFinalPolicy;
661 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
662 ProvInfo.sCleanupProvider = DriverCleanupPolicy;
663
664
665 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
666 return FALSE;
667
668 return TRUE;
669 }
670
671 /***************************************************************************
672 * WINTRUST_RegisterGenChainVerify
673 *
674 * Register WINTRUST_ACTION_GENERIC_CHAIN_VERIFY actions and usages.
675 *
676 * NOTES
677 * WINTRUST_ACTION_GENERIC_CHAIN_VERIFY ({FC451C16-AC75-11D1-B4B8-00C04FB66EA0})
678 * is defined in softpub.h
679 */
680 static BOOL WINTRUST_RegisterGenChainVerify(void)
681 {
682 static GUID ProvGUID = WINTRUST_ACTION_GENERIC_CHAIN_VERIFY;
683 CRYPT_REGISTER_ACTIONID ProvInfo;
684
685 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
686 ProvInfo.sInitProvider = SoftpubInitialization;
687 ProvInfo.sObjectProvider = SoftpubMessage;
688 ProvInfo.sSignatureProvider = SoftpubSignature;
689 ProvInfo.sCertificateProvider = GenericChainCertificateTrust;
690 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
691 ProvInfo.sFinalPolicyProvider = GenericChainFinalProv;
692 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
693 ProvInfo.sCleanupProvider = SoftpubCleanup;
694
695 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
696 return FALSE;
697
698 return TRUE;
699 }
700
701 /***********************************************************************
702 * WintrustAddDefaultForUsage (WINTRUST.@)
703 *
704 * Write OID and callback functions to the registry.
705 *
706 * PARAMS
707 * pszUsageOID [I] Pointer to a GUID.
708 * psDefUsage [I] Pointer to a structure that specifies the callback functions.
709 *
710 * RETURNS
711 * Success: TRUE.
712 * Failure: FALSE.
713 *
714 * NOTES
715 * WintrustAddDefaultForUsage will only return TRUE or FALSE, no last
716 * error is set, not even when the registry cannot be written to.
717 */
718 BOOL WINAPI WintrustAddDefaultForUsage(const char *pszUsageOID,
719 CRYPT_PROVIDER_REGDEFUSAGE *psDefUsage)
720 {
721 static const WCHAR CBAlloc[] = {'C','a','l','l','b','a','c','k','A','l','l','o','c','F','u','n','c','t','i','o','n', 0};
722 static const WCHAR CBFree[] = {'C','a','l','l','b','a','c','k','F','r','e','e','F','u','n','c','t','i','o','n', 0};
723 LONG Res = ERROR_SUCCESS;
724 LONG WriteUsageError = ERROR_SUCCESS;
725 DWORD Len;
726 WCHAR GuidString[39];
727
728 TRACE("(%s %p)\n", debugstr_a(pszUsageOID), psDefUsage);
729
730 /* Some sanity checks. */
731 if (!pszUsageOID ||
732 !psDefUsage ||
733 !psDefUsage->pgActionID ||
734 (psDefUsage->cbStruct != sizeof(CRYPT_PROVIDER_REGDEFUSAGE)))
735 {
736 SetLastError(ERROR_INVALID_PARAMETER);
737 return FALSE;
738 }
739
740 if (psDefUsage->pwszDllName)
741 {
742 Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, Dll, psDefUsage->pwszDllName);
743 if (Res != ERROR_SUCCESS) WriteUsageError = Res;
744 }
745 if (psDefUsage->pwszLoadCallbackDataFunctionName)
746 {
747 WCHAR* CallbackW;
748
749 Len = MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszLoadCallbackDataFunctionName, -1, NULL, 0 );
750 CallbackW = WINTRUST_Alloc( Len * sizeof(WCHAR) );
751 MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszLoadCallbackDataFunctionName, -1, CallbackW, Len );
752
753 Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, CBAlloc, CallbackW);
754 if (Res != ERROR_SUCCESS) WriteUsageError = Res;
755
756 WINTRUST_Free(CallbackW);
757 }
758 if (psDefUsage->pwszFreeCallbackDataFunctionName)
759 {
760 WCHAR* CallbackW;
761
762 Len = MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszFreeCallbackDataFunctionName, -1, NULL, 0 );
763 CallbackW = WINTRUST_Alloc( Len * sizeof(WCHAR) );
764 MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszFreeCallbackDataFunctionName, -1, CallbackW, Len );
765
766 Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, CBFree, CallbackW);
767 if (Res != ERROR_SUCCESS) WriteUsageError = Res;
768
769 WINTRUST_Free(CallbackW);
770 }
771
772 WINTRUST_Guid2Wstr(psDefUsage->pgActionID, GuidString);
773 Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, DefaultId, GuidString);
774 if (Res != ERROR_SUCCESS) WriteUsageError = Res;
775
776 if (WriteUsageError != ERROR_SUCCESS)
777 return FALSE;
778
779 return TRUE;
780 }
781
782 static FARPROC WINTRUST_ReadProviderFromReg(WCHAR *GuidString, const WCHAR *FunctionType)
783 {
784 WCHAR ProvKey[MAX_PATH], DllName[MAX_PATH];
785 char FunctionName[MAX_PATH];
786 HKEY Key;
787 LONG Res = ERROR_SUCCESS;
788 DWORD Size;
789 HMODULE Lib;
790 FARPROC Func = NULL;
791
792 /* Create the needed key string */
793 ProvKey[0]='\0';
794 lstrcatW(ProvKey, Trust);
795 lstrcatW(ProvKey, FunctionType);
796 lstrcatW(ProvKey, GuidString);
797
798 Res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, ProvKey, 0, KEY_READ, &Key);
799 if (Res != ERROR_SUCCESS) goto error_close_key;
800
801 /* Read the $DLL entry */
802 Size = sizeof(DllName);
803 Res = RegQueryValueExW(Key, Dll, NULL, NULL, (LPBYTE)DllName, &Size);
804 if (Res != ERROR_SUCCESS) goto error_close_key;
805
806 /* Read the $Function entry */
807 Size = sizeof(FunctionName);
808 Res = RegQueryValueExA(Key, "$Function", NULL, NULL, (LPBYTE)FunctionName, &Size);
809 if (Res != ERROR_SUCCESS) goto error_close_key;
810
811 /* Load the library - there appears to be no way to close a provider, so
812 * just leak the module handle.
813 */
814 Lib = LoadLibraryW(DllName);
815 Func = GetProcAddress(Lib, FunctionName);
816
817 error_close_key:
818 RegCloseKey(Key);
819
820 return Func;
821 }
822
823 /***********************************************************************
824 * WintrustLoadFunctionPointers (WINTRUST.@)
825 */
826 BOOL WINAPI WintrustLoadFunctionPointers( GUID* pgActionID,
827 CRYPT_PROVIDER_FUNCTIONS* pPfns )
828 {
829 WCHAR GuidString[39];
830
831 TRACE("(%s %p)\n", debugstr_guid(pgActionID), pPfns);
832
833 if (!pPfns) return FALSE;
834 if (!pgActionID)
835 {
836 SetLastError(ERROR_INVALID_PARAMETER);
837 return FALSE;
838 }
839 if (pPfns->cbStruct != sizeof(CRYPT_PROVIDER_FUNCTIONS)) return FALSE;
840
841 /* Create this string only once, instead of in the helper function */
842 WINTRUST_Guid2Wstr( pgActionID, GuidString);
843
844 /* Get the function pointers from the registry, where applicable */
845 pPfns->pfnAlloc = WINTRUST_Alloc;
846 pPfns->pfnFree = WINTRUST_Free;
847 pPfns->pfnAddStore2Chain = WINTRUST_AddStore;
848 pPfns->pfnAddSgnr2Chain = WINTRUST_AddSgnr;
849 pPfns->pfnAddCert2Chain = WINTRUST_AddCert;
850 pPfns->pfnAddPrivData2Chain = WINTRUST_AddPrivData;
851 pPfns->psUIpfns = NULL;
852 pPfns->pfnInitialize = (PFN_PROVIDER_INIT_CALL)WINTRUST_ReadProviderFromReg(GuidString, Initialization);
853 pPfns->pfnObjectTrust = (PFN_PROVIDER_OBJTRUST_CALL)WINTRUST_ReadProviderFromReg(GuidString, Message);
854 pPfns->pfnSignatureTrust = (PFN_PROVIDER_SIGTRUST_CALL)WINTRUST_ReadProviderFromReg(GuidString, Signature);
855 pPfns->pfnCertificateTrust = (PFN_PROVIDER_CERTTRUST_CALL)WINTRUST_ReadProviderFromReg(GuidString, Certificate);
856 pPfns->pfnCertCheckPolicy = (PFN_PROVIDER_CERTCHKPOLICY_CALL)WINTRUST_ReadProviderFromReg(GuidString, CertCheck);
857 pPfns->pfnFinalPolicy = (PFN_PROVIDER_FINALPOLICY_CALL)WINTRUST_ReadProviderFromReg(GuidString, FinalPolicy);
858 pPfns->pfnTestFinalPolicy = (PFN_PROVIDER_TESTFINALPOLICY_CALL)WINTRUST_ReadProviderFromReg(GuidString, DiagnosticPolicy);
859 pPfns->pfnCleanupPolicy = (PFN_PROVIDER_CLEANUP_CALL)WINTRUST_ReadProviderFromReg(GuidString, Cleanup);
860
861 return TRUE;
862 }
863
864 /***********************************************************************
865 * WINTRUST_SIPPAddProvider
866 *
867 * Helper for DllRegisterServer.
868 */
869 static BOOL WINTRUST_SIPPAddProvider(GUID* Subject, WCHAR* MagicNumber)
870 {
871 static WCHAR CryptSIPGetSignedDataMsg[] =
872 {'C','r','y','p','t','S','I','P','G','e','t','S','i','g','n','e','d','D','a','t','a','M','s','g', 0};
873 static WCHAR CryptSIPPutSignedDataMsg[] =
874 {'C','r','y','p','t','S','I','P','P','u','t','S','i','g','n','e','d','D','a','t','a','M','s','g', 0};
875 static WCHAR CryptSIPCreateIndirectData[] =
876 {'C','r','y','p','t','S','I','P','C','r','e','a','t','e','I','n','d','i','r','e','c','t','D','a','t','a', 0};
877 static WCHAR CryptSIPVerifyIndirectData[] =
878 {'C','r','y','p','t','S','I','P','V','e','r','i','f','y','I','n','d','i','r','e','c','t','D','a','t','a', 0};
879 static WCHAR CryptSIPRemoveSignedDataMsg[] =
880 {'C','r','y','p','t','S','I','P','R','e','m','o','v','e','S','i','g','n','e','d','D','a','t','a','M','s','g', 0};
881 SIP_ADD_NEWPROVIDER NewProv;
882 BOOL Ret;
883
884 /* Clear and initialize the structure */
885 memset(&NewProv, 0, sizeof(SIP_ADD_NEWPROVIDER));
886 NewProv.cbStruct = sizeof(SIP_ADD_NEWPROVIDER);
887 NewProv.pwszDLLFileName = WINTRUST_Alloc(sizeof(SP_POLICY_PROVIDER_DLL_NAME));
888 /* Fill the structure */
889 NewProv.pgSubject = Subject;
890 lstrcpyW(NewProv.pwszDLLFileName, SP_POLICY_PROVIDER_DLL_NAME);
891 NewProv.pwszMagicNumber = MagicNumber;
892 NewProv.pwszIsFunctionName = NULL;
893 NewProv.pwszGetFuncName = CryptSIPGetSignedDataMsg;
894 NewProv.pwszPutFuncName = CryptSIPPutSignedDataMsg;
895 NewProv.pwszCreateFuncName = CryptSIPCreateIndirectData;
896 NewProv.pwszVerifyFuncName = CryptSIPVerifyIndirectData;
897 NewProv.pwszRemoveFuncName = CryptSIPRemoveSignedDataMsg;
898 NewProv.pwszIsFunctionNameFmt2 = NULL;
899
900 Ret = CryptSIPAddProvider(&NewProv);
901
902 WINTRUST_Free(NewProv.pwszDLLFileName);
903
904 return Ret;
905 }
906
907 /***********************************************************************
908 * DllRegisterServer (WINTRUST.@)
909 */
910 HRESULT WINAPI DllRegisterServer(void)
911 {
912 static const CHAR SpcPeImageDataEncode[] = "WVTAsn1SpcPeImageDataEncode";
913 static const CHAR SpcPeImageDataDecode[] = "WVTAsn1SpcPeImageDataDecode";
914 static const CHAR SpcLinkEncode[] = "WVTAsn1SpcLinkEncode";
915 static const CHAR SpcLinkDecode[] = "WVTAsn1SpcLinkDecode";
916 static const CHAR SpcSigInfoEncode[] = "WVTAsn1SpcSigInfoEncode";
917 static const CHAR SpcSigInfoDecode[] = "WVTAsn1SpcSigInfoDecode";
918 static const CHAR SpcIndirectDataContentEncode[] = "WVTAsn1SpcIndirectDataContentEncode";
919 static const CHAR SpcIndirectDataContentDecode[] = "WVTAsn1SpcIndirectDataContentDecode";
920 static const CHAR SpcSpAgencyInfoEncode[] = "WVTAsn1SpcSpAgencyInfoEncode";
921 static const CHAR SpcSpAgencyInfoDecode[] = "WVTAsn1SpcSpAgencyInfoDecode";
922 static const CHAR SpcMinimalCriteriaInfoEncode[] = "WVTAsn1SpcMinimalCriteriaInfoEncode";
923 static const CHAR SpcMinimalCriteriaInfoDecode[] = "WVTAsn1SpcMinimalCriteriaInfoDecode";
924 static const CHAR SpcFinancialCriteriaInfoEncode[] = "WVTAsn1SpcFinancialCriteriaInfoEncode";
925 static const CHAR SpcFinancialCriteriaInfoDecode[] = "WVTAsn1SpcFinancialCriteriaInfoDecode";
926 static const CHAR SpcStatementTypeEncode[] = "WVTAsn1SpcStatementTypeEncode";
927 static const CHAR SpcStatementTypeDecode[] = "WVTAsn1SpcStatementTypeDecode";
928 static const CHAR CatNameValueEncode[] = "WVTAsn1CatNameValueEncode";
929 static const CHAR CatNameValueDecode[] = "WVTAsn1CatNameValueDecode";
930 static const CHAR CatMemberInfoEncode[] = "WVTAsn1CatMemberInfoEncode";
931 static const CHAR CatMemberInfoDecode[] = "WVTAsn1CatMemberInfoDecode";
932 static const CHAR SpcSpOpusInfoEncode[] = "WVTAsn1SpcSpOpusInfoEncode";
933 static const CHAR SpcSpOpusInfoDecode[] = "WVTAsn1SpcSpOpusInfoDecode";
934 static GUID Unknown1 = { 0xDE351A42, 0x8E59, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
935 static GUID Unknown2 = { 0xC689AABA, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
936 static GUID Unknown3 = { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
937 static GUID Unknown4 = { 0xC689AAB9, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
938 static GUID Unknown5 = { 0xDE351A43, 0x8E59, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
939 static GUID Unknown6 = { 0x9BA61D3F, 0xE73A, 0x11D0, { 0x8C,0xD2,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
940 static WCHAR MagicNumber2[] = {'M','S','C','F', 0};
941 static WCHAR MagicNumber3[] = {'0','x','0','0','0','0','4','5','5','0', 0};
942 static WCHAR CafeBabe[] = {'0','x','c','a','f','e','b','a','b','e', 0};
943
944 HRESULT CryptRegisterRes = S_OK;
945 HRESULT TrustProviderRes = S_OK;
946 HRESULT SIPAddProviderRes = S_OK;
947
948 TRACE("\n");
949
950 /* Testing on native shows that when an error is encountered in one of the CryptRegisterOIDFunction calls
951 * the rest of these calls are skipped. Registering is however continued for the trust providers.
952 *
953 * We are not totally in line with native as all decoding functions are registered after all encoding
954 * functions there.
955 */
956 #define WINTRUST_REGISTEROID( oid, encode_funcname, decode_funcname ) \
957 do { \
958 if (!CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_ENCODE_OBJECT_FUNC, oid, SP_POLICY_PROVIDER_DLL_NAME, encode_funcname)) \
959 { \
960 CryptRegisterRes = HRESULT_FROM_WIN32(GetLastError()); \
961 goto add_trust_providers; \
962 } \
963 if (!CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_DECODE_OBJECT_FUNC, oid, SP_POLICY_PROVIDER_DLL_NAME, decode_funcname)) \
964 { \
965 CryptRegisterRes = HRESULT_FROM_WIN32(GetLastError()); \
966 goto add_trust_providers; \
967 } \
968 } while (0)
969
970 WINTRUST_REGISTEROID(SPC_PE_IMAGE_DATA_OBJID, SpcPeImageDataEncode, SpcPeImageDataDecode);
971 WINTRUST_REGISTEROID(SPC_PE_IMAGE_DATA_STRUCT, SpcPeImageDataEncode, SpcPeImageDataDecode);
972 WINTRUST_REGISTEROID(SPC_CAB_DATA_OBJID, SpcLinkEncode, SpcLinkDecode);
973 WINTRUST_REGISTEROID(SPC_CAB_DATA_STRUCT, SpcLinkEncode, SpcLinkDecode);
974 WINTRUST_REGISTEROID(SPC_JAVA_CLASS_DATA_OBJID, SpcLinkEncode, SpcLinkDecode);
975 WINTRUST_REGISTEROID(SPC_JAVA_CLASS_DATA_STRUCT, SpcLinkEncode, SpcLinkDecode);
976 WINTRUST_REGISTEROID(SPC_LINK_OBJID, SpcLinkEncode, SpcLinkDecode);
977 WINTRUST_REGISTEROID(SPC_LINK_STRUCT, SpcLinkEncode, SpcLinkDecode);
978 WINTRUST_REGISTEROID(SPC_SIGINFO_OBJID, SpcSigInfoEncode, SpcSigInfoDecode);
979 WINTRUST_REGISTEROID(SPC_SIGINFO_STRUCT, SpcSigInfoEncode, SpcSigInfoDecode);
980 WINTRUST_REGISTEROID(SPC_INDIRECT_DATA_OBJID, SpcIndirectDataContentEncode, SpcIndirectDataContentDecode);
981 WINTRUST_REGISTEROID(SPC_INDIRECT_DATA_CONTENT_STRUCT, SpcIndirectDataContentEncode, SpcIndirectDataContentDecode);
982 WINTRUST_REGISTEROID(SPC_SP_AGENCY_INFO_OBJID, SpcSpAgencyInfoEncode, SpcSpAgencyInfoDecode);
983 WINTRUST_REGISTEROID(SPC_SP_AGENCY_INFO_STRUCT, SpcSpAgencyInfoEncode, SpcSpAgencyInfoDecode);
984 WINTRUST_REGISTEROID(SPC_MINIMAL_CRITERIA_OBJID, SpcMinimalCriteriaInfoEncode, SpcMinimalCriteriaInfoDecode);
985 WINTRUST_REGISTEROID(SPC_MINIMAL_CRITERIA_STRUCT, SpcMinimalCriteriaInfoEncode, SpcMinimalCriteriaInfoDecode);
986 WINTRUST_REGISTEROID(SPC_FINANCIAL_CRITERIA_OBJID, SpcFinancialCriteriaInfoEncode, SpcFinancialCriteriaInfoDecode);
987 WINTRUST_REGISTEROID(SPC_FINANCIAL_CRITERIA_STRUCT, SpcFinancialCriteriaInfoEncode, SpcFinancialCriteriaInfoDecode);
988 WINTRUST_REGISTEROID(SPC_STATEMENT_TYPE_OBJID, SpcStatementTypeEncode, SpcStatementTypeDecode);
989 WINTRUST_REGISTEROID(SPC_STATEMENT_TYPE_STRUCT, SpcStatementTypeEncode, SpcStatementTypeDecode);
990 WINTRUST_REGISTEROID(CAT_NAMEVALUE_OBJID, CatNameValueEncode, CatNameValueDecode);
991 WINTRUST_REGISTEROID(CAT_NAMEVALUE_STRUCT, CatNameValueEncode, CatNameValueDecode);
992 WINTRUST_REGISTEROID(CAT_MEMBERINFO_OBJID, CatMemberInfoEncode, CatMemberInfoDecode);
993 WINTRUST_REGISTEROID(CAT_MEMBERINFO_STRUCT, CatMemberInfoEncode, CatMemberInfoDecode);
994 WINTRUST_REGISTEROID(SPC_SP_OPUS_INFO_OBJID, SpcSpOpusInfoEncode, SpcSpOpusInfoDecode);
995 WINTRUST_REGISTEROID(SPC_SP_OPUS_INFO_STRUCT, SpcSpOpusInfoEncode, SpcSpOpusInfoDecode);
996
997 #undef WINTRUST_REGISTEROID
998
999 add_trust_providers:
1000
1001 /* Testing on W2K3 shows:
1002 * All registry writes are tried. If one fails this part will return S_FALSE.
1003 *
1004 * Last error is set to the last error encountered, regardless if the first
1005 * part failed or not.
1006 */
1007
1008 /* Create the necessary action registry structures */
1009 WINTRUST_InitRegStructs();
1010
1011 /* Register several Trust Provider actions */
1012 if (!WINTRUST_RegisterGenVerifyV2())
1013 TrustProviderRes = S_FALSE;
1014 if (!WINTRUST_RegisterPublishedSoftware())
1015 TrustProviderRes = S_FALSE;
1016 if (!WINTRUST_RegisterPublishedSoftwareNoBadUi())
1017 TrustProviderRes = S_FALSE;
1018 if (!WINTRUST_RegisterGenCertVerify())
1019 TrustProviderRes = S_FALSE;
1020 if (!WINTRUST_RegisterTrustProviderTest())
1021 TrustProviderRes = S_FALSE;
1022 if (!WINTRUST_RegisterHttpsProv())
1023 TrustProviderRes = S_FALSE;
1024 if (!WINTRUST_RegisterOfficeSignVerify())
1025 TrustProviderRes = S_FALSE;
1026 if (!WINTRUST_RegisterDriverVerify())
1027 TrustProviderRes = S_FALSE;
1028 if (!WINTRUST_RegisterGenChainVerify())
1029 TrustProviderRes = S_FALSE;
1030
1031 /* Free the registry structures */
1032 WINTRUST_FreeRegStructs();
1033
1034 /* Testing on W2K3 shows:
1035 * All registry writes are tried. If one fails this part will return S_FALSE.
1036 *
1037 * Last error is set to the last error encountered, regardless if the previous
1038 * parts failed or not.
1039 */
1040
1041 if (!WINTRUST_SIPPAddProvider(&Unknown1, NULL))
1042 SIPAddProviderRes = S_FALSE;
1043 if (!WINTRUST_SIPPAddProvider(&Unknown2, MagicNumber2))
1044 SIPAddProviderRes = S_FALSE;
1045 if (!WINTRUST_SIPPAddProvider(&Unknown3, MagicNumber3))
1046 SIPAddProviderRes = S_FALSE;
1047 if (!WINTRUST_SIPPAddProvider(&Unknown4, CafeBabe))
1048 SIPAddProviderRes = S_FALSE;
1049 if (!WINTRUST_SIPPAddProvider(&Unknown5, CafeBabe))
1050 SIPAddProviderRes = S_FALSE;
1051 if (!WINTRUST_SIPPAddProvider(&Unknown6, CafeBabe))
1052 SIPAddProviderRes = S_FALSE;
1053
1054 /* Native does a CryptSIPRemoveProvider here for {941C2937-1292-11D1-85BE-00C04FC295EE}.
1055 * This SIP Provider is however not found on up-to-date window install and native will
1056 * set the last error to ERROR_FILE_NOT_FOUND.
1057 * Wine has the last error set to ERROR_INVALID_PARAMETER. There shouldn't be an app
1058 * depending on this last error though so there is no need to imitate native to the full extent.
1059 *
1060 * (The ERROR_INVALID_PARAMETER for Wine it totally valid as we (and native) do register
1061 * a trust provider without a diagnostic policy).
1062 */
1063
1064 /* If CryptRegisterRes is not S_OK it will always overrule the return value. */
1065 if (CryptRegisterRes != S_OK)
1066 return CryptRegisterRes;
1067 else if (SIPAddProviderRes == S_OK)
1068 return TrustProviderRes;
1069 else
1070 return SIPAddProviderRes;
1071 }
1072
1073 /***********************************************************************
1074 * DllUnregisterServer (WINTRUST.@)
1075 */
1076 HRESULT WINAPI DllUnregisterServer(void)
1077 {
1078 FIXME("stub\n");
1079 return S_OK;
1080 }
1081
1082 /***********************************************************************
1083 * SoftpubDllRegisterServer (WINTRUST.@)
1084 *
1085 * Registers softpub.dll
1086 *
1087 * PARAMS
1088 *
1089 * RETURNS
1090 * Success: S_OK.
1091 * Failure: S_FALSE. (See also GetLastError()).
1092 *
1093 * NOTES
1094 * DllRegisterServer in softpub.dll will call this function.
1095 * See comments in DllRegisterServer.
1096 */
1097 HRESULT WINAPI SoftpubDllRegisterServer(void)
1098 {
1099 HRESULT TrustProviderRes = S_OK;
1100
1101 TRACE("\n");
1102
1103 /* Create the necessary action registry structures */
1104 WINTRUST_InitRegStructs();
1105
1106 /* Register several Trust Provider actions */
1107 if (!WINTRUST_RegisterGenVerifyV2())
1108 TrustProviderRes = S_FALSE;
1109 if (!WINTRUST_RegisterPublishedSoftware())
1110 TrustProviderRes = S_FALSE;
1111 if (!WINTRUST_RegisterPublishedSoftwareNoBadUi())
1112 TrustProviderRes = S_FALSE;
1113 if (!WINTRUST_RegisterGenCertVerify())
1114 TrustProviderRes = S_FALSE;
1115 if (!WINTRUST_RegisterTrustProviderTest())
1116 TrustProviderRes = S_FALSE;
1117 if (!WINTRUST_RegisterHttpsProv())
1118 TrustProviderRes = S_FALSE;
1119 if (!WINTRUST_RegisterOfficeSignVerify())
1120 TrustProviderRes = S_FALSE;
1121 if (!WINTRUST_RegisterDriverVerify())
1122 TrustProviderRes = S_FALSE;
1123 if (!WINTRUST_RegisterGenChainVerify())
1124 TrustProviderRes = S_FALSE;
1125
1126 /* Free the registry structures */
1127 WINTRUST_FreeRegStructs();
1128
1129 return TrustProviderRes;
1130 }
1131
1132 /***********************************************************************
1133 * SoftpubDllUnregisterServer (WINTRUST.@)
1134 */
1135 HRESULT WINAPI SoftpubDllUnregisterServer(void)
1136 {
1137 FIXME("stub\n");
1138 return S_OK;
1139 }
1140
1141 /***********************************************************************
1142 * mscat32DllRegisterServer (WINTRUST.@)
1143 */
1144 HRESULT WINAPI mscat32DllRegisterServer(void)
1145 {
1146 FIXME("stub\n");
1147 return S_OK;
1148 }
1149
1150 /***********************************************************************
1151 * mscat32DllUnregisterServer (WINTRUST.@)
1152 */
1153 HRESULT WINAPI mscat32DllUnregisterServer(void)
1154 {
1155 FIXME("stub\n");
1156 return S_OK;
1157 }
1158
1159 /***********************************************************************
1160 * mssip32DllRegisterServer (WINTRUST.@)
1161 */
1162 HRESULT WINAPI mssip32DllRegisterServer(void)
1163 {
1164 FIXME("stub\n");
1165 return S_OK;
1166 }
1167
1168 /***********************************************************************
1169 * mssip32DllUnregisterServer (WINTRUST.@)
1170 */
1171 HRESULT WINAPI mssip32DllUnregisterServer(void)
1172 {
1173 FIXME("stub\n");
1174 return S_OK;
1175 }