2 * Register related wintrust functions
4 * Copyright 2006 Paul Vriens
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
35 #include "wintrust_priv.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(wintrust);
40 static CRYPT_TRUST_REG_ENTRY SoftpubInitialization;
41 static CRYPT_TRUST_REG_ENTRY SoftpubMessage;
42 static CRYPT_TRUST_REG_ENTRY SoftpubSignature;
43 static CRYPT_TRUST_REG_ENTRY SoftpubCertficate;
44 static CRYPT_TRUST_REG_ENTRY SoftpubCertCheck;
45 static CRYPT_TRUST_REG_ENTRY SoftpubFinalPolicy;
46 static CRYPT_TRUST_REG_ENTRY SoftpubCleanup;
48 static CRYPT_TRUST_REG_ENTRY SoftpubDefCertInit;
50 static CRYPT_TRUST_REG_ENTRY SoftpubDumpStructure;
52 static CRYPT_TRUST_REG_ENTRY HTTPSCertificateTrust;
53 static CRYPT_TRUST_REG_ENTRY HTTPSFinalProv;
55 static CRYPT_TRUST_REG_ENTRY OfficeInitializePolicy;
56 static CRYPT_TRUST_REG_ENTRY OfficeCleanupPolicy;
58 static CRYPT_TRUST_REG_ENTRY DriverInitializePolicy;
59 static CRYPT_TRUST_REG_ENTRY DriverFinalPolicy;
60 static CRYPT_TRUST_REG_ENTRY DriverCleanupPolicy;
62 static CRYPT_TRUST_REG_ENTRY GenericChainCertificateTrust;
63 static CRYPT_TRUST_REG_ENTRY GenericChainFinalProv;
65 static const CRYPT_TRUST_REG_ENTRY NullCTRE = { 0, NULL, NULL };
67 static const WCHAR Trust[] = {'S','o','f','t','w','a','r','e','\\',
68 'M','i','c','r','o','s','o','f','t','\\',
69 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
70 'P','r','o','v','i','d','e','r','s','\\',
71 'T','r','u','s','t','\\', 0 };
73 static const WCHAR Initialization[] = {'I','n','i','t','i','a','l','i','z','a','t','i','o','n','\\', 0};
74 static const WCHAR Message[] = {'M','e','s','s','a','g','e','\\', 0};
75 static const WCHAR Signature[] = {'S','i','g','n','a','t','u','r','e','\\', 0};
76 static const WCHAR Certificate[] = {'C','e','r','t','i','f','i','c','a','t','e','\\', 0};
77 static const WCHAR CertCheck[] = {'C','e','r','t','C','h','e','c','k','\\', 0};
78 static const WCHAR FinalPolicy[] = {'F','i','n','a','l','P','o','l','i','c','y','\\', 0};
79 static const WCHAR DiagnosticPolicy[] = {'D','i','a','g','n','o','s','t','i','c','P','o','l','i','c','y','\\', 0};
80 static const WCHAR Cleanup[] = {'C','l','e','a','n','u','p','\\', 0};
82 static const WCHAR DefaultId[] = {'D','e','f','a','u','l','t','I','d', 0};
83 static const WCHAR Dll[] = {'$','D','L','L', 0};
85 /***********************************************************************
86 * WINTRUST_InitRegStructs
88 * Helper function to allocate and initialize the members of the
89 * CRYPT_TRUST_REG_ENTRY structs.
91 static void WINTRUST_InitRegStructs(void)
93 #define WINTRUST_INITREGENTRY( action, dllname, functionname ) \
94 action.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY); \
95 action.pwszDLLName = WINTRUST_Alloc(sizeof(dllname)); \
96 lstrcpyW(action.pwszDLLName, dllname); \
97 action.pwszFunctionName = WINTRUST_Alloc(sizeof(functionname)); \
98 lstrcpyW(action.pwszFunctionName, functionname);
100 WINTRUST_INITREGENTRY(SoftpubInitialization, SP_POLICY_PROVIDER_DLL_NAME, SP_INIT_FUNCTION)
101 WINTRUST_INITREGENTRY(SoftpubMessage, SP_POLICY_PROVIDER_DLL_NAME, SP_OBJTRUST_FUNCTION)
102 WINTRUST_INITREGENTRY(SoftpubSignature, SP_POLICY_PROVIDER_DLL_NAME, SP_SIGTRUST_FUNCTION)
103 WINTRUST_INITREGENTRY(SoftpubCertficate, SP_POLICY_PROVIDER_DLL_NAME, WT_PROVIDER_CERTTRUST_FUNCTION)
104 WINTRUST_INITREGENTRY(SoftpubCertCheck, SP_POLICY_PROVIDER_DLL_NAME, SP_CHKCERT_FUNCTION)
105 WINTRUST_INITREGENTRY(SoftpubFinalPolicy, SP_POLICY_PROVIDER_DLL_NAME, SP_FINALPOLICY_FUNCTION)
106 WINTRUST_INITREGENTRY(SoftpubCleanup, SP_POLICY_PROVIDER_DLL_NAME, SP_CLEANUPPOLICY_FUNCTION)
107 WINTRUST_INITREGENTRY(SoftpubDefCertInit, SP_POLICY_PROVIDER_DLL_NAME, SP_GENERIC_CERT_INIT_FUNCTION)
108 WINTRUST_INITREGENTRY(SoftpubDumpStructure, SP_POLICY_PROVIDER_DLL_NAME, SP_TESTDUMPPOLICY_FUNCTION_TEST)
109 WINTRUST_INITREGENTRY(HTTPSCertificateTrust, SP_POLICY_PROVIDER_DLL_NAME, HTTPS_CERTTRUST_FUNCTION)
110 WINTRUST_INITREGENTRY(HTTPSFinalProv, SP_POLICY_PROVIDER_DLL_NAME, HTTPS_FINALPOLICY_FUNCTION)
111 WINTRUST_INITREGENTRY(OfficeInitializePolicy, OFFICE_POLICY_PROVIDER_DLL_NAME, OFFICE_INITPROV_FUNCTION)
112 WINTRUST_INITREGENTRY(OfficeCleanupPolicy, OFFICE_POLICY_PROVIDER_DLL_NAME, OFFICE_CLEANUPPOLICY_FUNCTION)
113 WINTRUST_INITREGENTRY(DriverInitializePolicy, SP_POLICY_PROVIDER_DLL_NAME, DRIVER_INITPROV_FUNCTION)
114 WINTRUST_INITREGENTRY(DriverFinalPolicy, SP_POLICY_PROVIDER_DLL_NAME, DRIVER_FINALPOLPROV_FUNCTION)
115 WINTRUST_INITREGENTRY(DriverCleanupPolicy, SP_POLICY_PROVIDER_DLL_NAME, DRIVER_CLEANUPPOLICY_FUNCTION)
116 WINTRUST_INITREGENTRY(GenericChainCertificateTrust, SP_POLICY_PROVIDER_DLL_NAME, GENERIC_CHAIN_CERTTRUST_FUNCTION)
117 WINTRUST_INITREGENTRY(GenericChainFinalProv, SP_POLICY_PROVIDER_DLL_NAME, GENERIC_CHAIN_FINALPOLICY_FUNCTION)
119 #undef WINTRUST_INITREGENTRY
122 /***********************************************************************
123 * WINTRUST_FreeRegStructs
125 * Helper function to free 2 members of the CRYPT_TRUST_REG_ENTRY
128 static void WINTRUST_FreeRegStructs(void)
130 #define WINTRUST_FREEREGENTRY( action ) \
131 WINTRUST_Free(action.pwszDLLName); \
132 WINTRUST_Free(action.pwszFunctionName);
134 WINTRUST_FREEREGENTRY(SoftpubInitialization);
135 WINTRUST_FREEREGENTRY(SoftpubMessage);
136 WINTRUST_FREEREGENTRY(SoftpubSignature);
137 WINTRUST_FREEREGENTRY(SoftpubCertficate);
138 WINTRUST_FREEREGENTRY(SoftpubCertCheck);
139 WINTRUST_FREEREGENTRY(SoftpubFinalPolicy);
140 WINTRUST_FREEREGENTRY(SoftpubCleanup);
141 WINTRUST_FREEREGENTRY(SoftpubDefCertInit);
142 WINTRUST_FREEREGENTRY(SoftpubDumpStructure);
143 WINTRUST_FREEREGENTRY(HTTPSCertificateTrust);
144 WINTRUST_FREEREGENTRY(HTTPSFinalProv);
145 WINTRUST_FREEREGENTRY(OfficeInitializePolicy);
146 WINTRUST_FREEREGENTRY(OfficeCleanupPolicy);
147 WINTRUST_FREEREGENTRY(DriverInitializePolicy);
148 WINTRUST_FREEREGENTRY(DriverFinalPolicy);
149 WINTRUST_FREEREGENTRY(DriverCleanupPolicy);
150 WINTRUST_FREEREGENTRY(GenericChainCertificateTrust);
151 WINTRUST_FREEREGENTRY(GenericChainFinalProv);
153 #undef WINTRUST_FREEREGENTRY
156 /***********************************************************************
159 * Create a wide-string from a GUID
162 static void WINTRUST_Guid2Wstr(const GUID* pgActionID, WCHAR* GuidString)
164 static const WCHAR wszFormat[] = {'{','%','0','8','l','X','-','%','0','4','X','-','%','0','4','X','-',
165 '%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2',
166 'X','%','0','2','X','%','0','2','X','}', 0};
168 wsprintfW(GuidString, wszFormat, pgActionID->Data1, pgActionID->Data2, pgActionID->Data3,
169 pgActionID->Data4[0], pgActionID->Data4[1], pgActionID->Data4[2], pgActionID->Data4[3],
170 pgActionID->Data4[4], pgActionID->Data4[5], pgActionID->Data4[6], pgActionID->Data4[7]);
173 /***********************************************************************
174 * WINTRUST_WriteProviderToReg
176 * Helper function for WintrustAddActionID
179 static LONG WINTRUST_WriteProviderToReg(WCHAR* GuidString,
180 const WCHAR* FunctionType,
181 CRYPT_TRUST_REG_ENTRY RegEntry)
183 static const WCHAR Function[] = {'$','F','u','n','c','t','i','o','n', 0};
184 WCHAR ProvKey[MAX_PATH];
186 LONG Res = ERROR_SUCCESS;
188 /* Create the needed key string */
190 lstrcatW(ProvKey, Trust);
191 lstrcatW(ProvKey, FunctionType);
192 lstrcatW(ProvKey, GuidString);
194 if (!RegEntry.pwszDLLName || !RegEntry.pwszFunctionName)
195 return ERROR_INVALID_PARAMETER;
197 Res = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ProvKey, 0, NULL, 0, KEY_WRITE, NULL, &Key, NULL);
198 if (Res != ERROR_SUCCESS) goto error_close_key;
200 /* Create the $DLL entry */
201 Res = RegSetValueExW(Key, Dll, 0, REG_SZ, (BYTE*)RegEntry.pwszDLLName,
202 (lstrlenW(RegEntry.pwszDLLName) + 1)*sizeof(WCHAR));
203 if (Res != ERROR_SUCCESS) goto error_close_key;
205 /* Create the $Function entry */
206 Res = RegSetValueExW(Key, Function, 0, REG_SZ, (BYTE*)RegEntry.pwszFunctionName,
207 (lstrlenW(RegEntry.pwszFunctionName) + 1)*sizeof(WCHAR));
215 /***********************************************************************
216 * WintrustAddActionID (WINTRUST.@)
218 * Add the definitions of the actions a Trust provider can perform to
222 * pgActionID [I] Pointer to a GUID for the Trust provider.
223 * fdwFlags [I] Flag to indicate whether registry errors are passed on.
224 * psProvInfo [I] Pointer to a structure with information about DLL
225 * name and functions.
229 * Failure: FALSE. (Use GetLastError() for more information)
232 * Adding definitions is basically only adding relevant information
233 * to the registry. No verification takes place whether a DLL or it's
235 * Information in the registry will always be overwritten.
238 BOOL WINAPI WintrustAddActionID( GUID* pgActionID, DWORD fdwFlags,
239 CRYPT_REGISTER_ACTIONID* psProvInfo)
241 WCHAR GuidString[39];
243 LONG WriteActionError = ERROR_SUCCESS;
245 TRACE("%s %x %p\n", debugstr_guid(pgActionID), fdwFlags, psProvInfo);
247 /* Some sanity checks.
248 * We use the W2K3 last error as it makes more sense (W2K leaves the last error
253 (psProvInfo->cbStruct != sizeof(CRYPT_REGISTER_ACTIONID)))
255 SetLastError(ERROR_INVALID_PARAMETER);
259 /* Create this string only once, instead of in the helper function */
260 WINTRUST_Guid2Wstr( pgActionID, GuidString);
262 /* Write the information to the registry */
263 Res = WINTRUST_WriteProviderToReg(GuidString, Initialization , psProvInfo->sInitProvider);
264 if (Res != ERROR_SUCCESS) WriteActionError = Res;
265 Res = WINTRUST_WriteProviderToReg(GuidString, Message , psProvInfo->sObjectProvider);
266 if (Res != ERROR_SUCCESS) WriteActionError = Res;
267 Res = WINTRUST_WriteProviderToReg(GuidString, Signature , psProvInfo->sSignatureProvider);
268 if (Res != ERROR_SUCCESS) WriteActionError = Res;
269 Res = WINTRUST_WriteProviderToReg(GuidString, Certificate , psProvInfo->sCertificateProvider);
270 if (Res != ERROR_SUCCESS) WriteActionError = Res;
271 Res = WINTRUST_WriteProviderToReg(GuidString, CertCheck , psProvInfo->sCertificatePolicyProvider);
272 if (Res != ERROR_SUCCESS) WriteActionError = Res;
273 Res = WINTRUST_WriteProviderToReg(GuidString, FinalPolicy , psProvInfo->sFinalPolicyProvider);
274 if (Res != ERROR_SUCCESS) WriteActionError = Res;
275 Res = WINTRUST_WriteProviderToReg(GuidString, DiagnosticPolicy, psProvInfo->sTestPolicyProvider);
276 if (Res != ERROR_SUCCESS) WriteActionError = Res;
277 Res = WINTRUST_WriteProviderToReg(GuidString, Cleanup , psProvInfo->sCleanupProvider);
278 if (Res != ERROR_SUCCESS) WriteActionError = Res;
280 /* Testing (by restricting access to the registry for some keys) shows that the last failing function
281 * will be used for last error.
282 * If the flag WT_ADD_ACTION_ID_RET_RESULT_FLAG is set and there are errors when adding the action
283 * we have to return FALSE. Errors includes both invalid entries as well as registry errors.
284 * Testing also showed that one error doesn't stop the registry writes. Every action will be dealt with.
287 if (WriteActionError != ERROR_SUCCESS)
289 SetLastError(WriteActionError);
291 if (fdwFlags == WT_ADD_ACTION_ID_RET_RESULT_FLAG)
298 /***********************************************************************
299 * WINTRUST_RemoveProviderFromReg
301 * Helper function for WintrustRemoveActionID
304 static void WINTRUST_RemoveProviderFromReg(WCHAR* GuidString,
305 const WCHAR* FunctionType)
307 WCHAR ProvKey[MAX_PATH];
309 /* Create the needed key string */
311 lstrcatW(ProvKey, Trust);
312 lstrcatW(ProvKey, FunctionType);
313 lstrcatW(ProvKey, GuidString);
315 /* We don't care about success or failure */
316 RegDeleteKeyW(HKEY_LOCAL_MACHINE, ProvKey);
319 /***********************************************************************
320 * WintrustRemoveActionID (WINTRUST.@)
322 * Remove the definitions of the actions a Trust provider can perform
326 * pgActionID [I] Pointer to a GUID for the Trust provider.
329 * Success: TRUE. (Use GetLastError() for more information)
330 * Failure: FALSE. (Use GetLastError() for more information)
333 * Testing shows that WintrustRemoveActionID always returns TRUE and
334 * that a possible error should be retrieved via GetLastError().
335 * There are no checks if the definitions are in the registry.
337 BOOL WINAPI WintrustRemoveActionID( GUID* pgActionID )
339 WCHAR GuidString[39];
341 TRACE("(%s)\n", debugstr_guid(pgActionID));
345 SetLastError(ERROR_INVALID_PARAMETER);
349 /* Create this string only once, instead of in the helper function */
350 WINTRUST_Guid2Wstr( pgActionID, GuidString);
352 /* We don't care about success or failure */
353 WINTRUST_RemoveProviderFromReg(GuidString, Initialization);
354 WINTRUST_RemoveProviderFromReg(GuidString, Message);
355 WINTRUST_RemoveProviderFromReg(GuidString, Signature);
356 WINTRUST_RemoveProviderFromReg(GuidString, Certificate);
357 WINTRUST_RemoveProviderFromReg(GuidString, CertCheck);
358 WINTRUST_RemoveProviderFromReg(GuidString, FinalPolicy);
359 WINTRUST_RemoveProviderFromReg(GuidString, DiagnosticPolicy);
360 WINTRUST_RemoveProviderFromReg(GuidString, Cleanup);
365 /***********************************************************************
366 * WINTRUST_WriteSingleUsageEntry
368 * Helper for WintrustAddDefaultForUsage, writes a single value and its
371 * HKLM\Software\Microsoft\Cryptography\Trust\Usages\<OID>
373 static LONG WINTRUST_WriteSingleUsageEntry(LPCSTR OID,
377 static const WCHAR Usages[] = {'U','s','a','g','e','s','\\', 0};
380 LONG Res = ERROR_SUCCESS;
384 /* Turn OID into a wide-character string */
385 Len = MultiByteToWideChar( CP_ACP, 0, OID, -1, NULL, 0 );
386 OIDW = WINTRUST_Alloc( Len * sizeof(WCHAR) );
387 MultiByteToWideChar( CP_ACP, 0, OID, -1, OIDW, Len );
389 /* Allocate the needed space for UsageKey */
390 UsageKey = WINTRUST_Alloc((lstrlenW(Trust) + lstrlenW(Usages) + Len) * sizeof(WCHAR));
391 /* Create the key string */
392 lstrcpyW(UsageKey, Trust);
393 lstrcatW(UsageKey, Usages);
394 lstrcatW(UsageKey, OIDW);
396 Res = RegCreateKeyExW(HKEY_LOCAL_MACHINE, UsageKey, 0, NULL, 0, KEY_WRITE, NULL, &Key, NULL);
397 if (Res == ERROR_SUCCESS)
399 /* Create the Value entry */
400 Res = RegSetValueExW(Key, Value, 0, REG_SZ, (BYTE*)Data,
401 (lstrlenW(Data) + 1)*sizeof(WCHAR));
406 WINTRUST_Free(UsageKey);
411 /***************************************************************************
412 * WINTRUST_RegisterGenVerifyV2
414 * Register WINTRUST_ACTION_GENERIC_VERIFY_V2 actions and usages.
417 * WINTRUST_ACTION_GENERIC_VERIFY_V2 ({00AAC56B-CD44-11D0-8CC2-00C04FC295EE}
418 * is defined in softpub.h
420 static BOOL WINTRUST_RegisterGenVerifyV2(void)
422 BOOL RegisteredOK = TRUE;
423 static GUID ProvGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2;
424 CRYPT_REGISTER_ACTIONID ProvInfo;
425 CRYPT_PROVIDER_REGDEFUSAGE DefUsage = { sizeof(CRYPT_PROVIDER_REGDEFUSAGE),
427 NULL, /* No Dll provided */
428 NULL, /* No load callback function */
429 NULL }; /* No free callback function */
431 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
432 ProvInfo.sInitProvider = SoftpubInitialization;
433 ProvInfo.sObjectProvider = SoftpubMessage;
434 ProvInfo.sSignatureProvider = SoftpubSignature;
435 ProvInfo.sCertificateProvider = SoftpubCertficate;
436 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
437 ProvInfo.sFinalPolicyProvider = SoftpubFinalPolicy;
438 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
439 ProvInfo.sCleanupProvider = SoftpubCleanup;
441 if (!WintrustAddDefaultForUsage(szOID_PKIX_KP_CODE_SIGNING, &DefUsage))
442 RegisteredOK = FALSE;
444 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
445 RegisteredOK = FALSE;
450 /***************************************************************************
451 * WINTRUST_RegisterPublishedSoftware
453 * Register WIN_SPUB_ACTION_PUBLISHED_SOFTWARE actions and usages.
456 * WIN_SPUB_ACTION_PUBLISHED_SOFTWARE ({64B9D180-8DA2-11CF-8736-00AA00A485EB})
457 * is defined in wintrust.h
459 static BOOL WINTRUST_RegisterPublishedSoftware(void)
461 static GUID ProvGUID = WIN_SPUB_ACTION_PUBLISHED_SOFTWARE;
462 CRYPT_REGISTER_ACTIONID ProvInfo;
464 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
465 ProvInfo.sInitProvider = SoftpubInitialization;
466 ProvInfo.sObjectProvider = SoftpubMessage;
467 ProvInfo.sSignatureProvider = SoftpubSignature;
468 ProvInfo.sCertificateProvider = SoftpubCertficate;
469 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
470 ProvInfo.sFinalPolicyProvider = SoftpubFinalPolicy;
471 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
472 ProvInfo.sCleanupProvider = SoftpubCleanup;
474 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
480 #define WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI { 0xc6b2e8d0, 0xe005, 0x11cf, { 0xa1,0x34,0x00,0xc0,0x4f,0xd7,0xbf,0x43 }}
482 /***************************************************************************
483 * WINTRUST_RegisterPublishedSoftwareNoBadUi
485 * Register WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI actions and usages.
488 * WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI ({C6B2E8D0-E005-11CF-A134-00C04FD7BF43})
489 * is not defined in any include file. (FIXME: Find out if the name is correct).
491 static BOOL WINTRUST_RegisterPublishedSoftwareNoBadUi(void)
493 static GUID ProvGUID = WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI;
494 CRYPT_REGISTER_ACTIONID ProvInfo;
496 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
497 ProvInfo.sInitProvider = SoftpubInitialization;
498 ProvInfo.sObjectProvider = SoftpubMessage;
499 ProvInfo.sSignatureProvider = SoftpubSignature;
500 ProvInfo.sCertificateProvider = SoftpubCertficate;
501 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
502 ProvInfo.sFinalPolicyProvider = SoftpubFinalPolicy;
503 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
504 ProvInfo.sCleanupProvider = SoftpubCleanup;
506 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
512 /***************************************************************************
513 * WINTRUST_RegisterGenCertVerify
515 * Register WINTRUST_ACTION_GENERIC_CERT_VERIFY actions and usages.
518 * WINTRUST_ACTION_GENERIC_CERT_VERIFY ({189A3842-3041-11D1-85E1-00C04FC295EE})
519 * is defined in softpub.h
521 static BOOL WINTRUST_RegisterGenCertVerify(void)
523 static GUID ProvGUID = WINTRUST_ACTION_GENERIC_CERT_VERIFY;
524 CRYPT_REGISTER_ACTIONID ProvInfo;
526 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
527 ProvInfo.sInitProvider = SoftpubDefCertInit;
528 ProvInfo.sObjectProvider = SoftpubMessage;
529 ProvInfo.sSignatureProvider = SoftpubSignature;
530 ProvInfo.sCertificateProvider = SoftpubCertficate;
531 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
532 ProvInfo.sFinalPolicyProvider = SoftpubFinalPolicy;
533 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
534 ProvInfo.sCleanupProvider = SoftpubCleanup;
536 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
542 /***************************************************************************
543 * WINTRUST_RegisterTrustProviderTest
545 * Register WINTRUST_ACTION_TRUSTPROVIDER_TEST actions and usages.
548 * WINTRUST_ACTION_TRUSTPROVIDER_TEST ({573E31F8-DDBA-11D0-8CCB-00C04FC295EE})
549 * is defined in softpub.h
551 static BOOL WINTRUST_RegisterTrustProviderTest(void)
553 static GUID ProvGUID = WINTRUST_ACTION_TRUSTPROVIDER_TEST;
554 CRYPT_REGISTER_ACTIONID ProvInfo;
556 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
557 ProvInfo.sInitProvider = SoftpubInitialization;
558 ProvInfo.sObjectProvider = SoftpubMessage;
559 ProvInfo.sSignatureProvider = SoftpubSignature;
560 ProvInfo.sCertificateProvider = SoftpubCertficate;
561 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
562 ProvInfo.sFinalPolicyProvider = SoftpubFinalPolicy;
563 ProvInfo.sTestPolicyProvider = SoftpubDumpStructure;
564 ProvInfo.sCleanupProvider = SoftpubCleanup;
566 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
572 /***************************************************************************
573 * WINTRUST_RegisterHttpsProv
575 * Register HTTPSPROV_ACTION actions and usages.
578 * HTTPSPROV_ACTION ({573E31F8-AABA-11D0-8CCB-00C04FC295EE})
579 * is defined in softpub.h
581 static BOOL WINTRUST_RegisterHttpsProv(void)
583 BOOL RegisteredOK = TRUE;
584 static CHAR SoftpubLoadUsage[] = "SoftpubLoadDefUsageCallData";
585 static CHAR SoftpubFreeUsage[] = "SoftpubFreeDefUsageCallData";
586 static GUID ProvGUID = HTTPSPROV_ACTION;
587 CRYPT_REGISTER_ACTIONID ProvInfo;
588 CRYPT_PROVIDER_REGDEFUSAGE DefUsage = { sizeof(CRYPT_PROVIDER_REGDEFUSAGE),
590 NULL, /* Will be filled later */
594 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
595 ProvInfo.sInitProvider = SoftpubInitialization;
596 ProvInfo.sObjectProvider = SoftpubMessage;
597 ProvInfo.sSignatureProvider = SoftpubSignature;
598 ProvInfo.sCertificateProvider = HTTPSCertificateTrust;
599 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
600 ProvInfo.sFinalPolicyProvider = HTTPSFinalProv;
601 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
602 ProvInfo.sCleanupProvider = SoftpubCleanup;
604 DefUsage.pwszDllName = WINTRUST_Alloc(sizeof(SP_POLICY_PROVIDER_DLL_NAME));
605 lstrcpyW(DefUsage.pwszDllName, SP_POLICY_PROVIDER_DLL_NAME);
607 if (!WintrustAddDefaultForUsage(szOID_PKIX_KP_SERVER_AUTH, &DefUsage))
608 RegisteredOK = FALSE;
609 if (!WintrustAddDefaultForUsage(szOID_PKIX_KP_CLIENT_AUTH, &DefUsage))
610 RegisteredOK = FALSE;
611 if (!WintrustAddDefaultForUsage(szOID_SERVER_GATED_CRYPTO, &DefUsage))
612 RegisteredOK = FALSE;
613 if (!WintrustAddDefaultForUsage(szOID_SGC_NETSCAPE, &DefUsage))
614 RegisteredOK = FALSE;
616 WINTRUST_Free(DefUsage.pwszDllName);
618 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
619 RegisteredOK = FALSE;
624 /***************************************************************************
625 * WINTRUST_RegisterOfficeSignVerify
627 * Register OFFICESIGN_ACTION_VERIFY actions and usages.
630 * OFFICESIGN_ACTION_VERIFY ({5555C2CD-17FB-11D1-85C4-00C04FC295EE})
631 * is defined in softpub.h
633 static BOOL WINTRUST_RegisterOfficeSignVerify(void)
635 static GUID ProvGUID = OFFICESIGN_ACTION_VERIFY;
636 CRYPT_REGISTER_ACTIONID ProvInfo;
638 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
639 ProvInfo.sInitProvider = OfficeInitializePolicy;
640 ProvInfo.sObjectProvider = SoftpubMessage;
641 ProvInfo.sSignatureProvider = SoftpubSignature;
642 ProvInfo.sCertificateProvider = SoftpubCertficate;
643 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
644 ProvInfo.sFinalPolicyProvider = SoftpubFinalPolicy;
645 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
646 ProvInfo.sCleanupProvider = OfficeCleanupPolicy;
649 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
655 /***************************************************************************
656 * WINTRUST_RegisterDriverVerify
658 * Register DRIVER_ACTION_VERIFY actions and usages.
661 * DRIVER_ACTION_VERIFY ({F750E6C3-38EE-11D1-85E5-00C04FC295EE})
662 * is defined in softpub.h
664 static BOOL WINTRUST_RegisterDriverVerify(void)
666 static GUID ProvGUID = DRIVER_ACTION_VERIFY;
667 CRYPT_REGISTER_ACTIONID ProvInfo;
669 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
670 ProvInfo.sInitProvider = DriverInitializePolicy;
671 ProvInfo.sObjectProvider = SoftpubMessage;
672 ProvInfo.sSignatureProvider = SoftpubSignature;
673 ProvInfo.sCertificateProvider = SoftpubCertficate;
674 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
675 ProvInfo.sFinalPolicyProvider = DriverFinalPolicy;
676 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
677 ProvInfo.sCleanupProvider = DriverCleanupPolicy;
680 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
686 /***************************************************************************
687 * WINTRUST_RegisterGenChainVerify
689 * Register WINTRUST_ACTION_GENERIC_CHAIN_VERIFY actions and usages.
692 * WINTRUST_ACTION_GENERIC_CHAIN_VERIFY ({FC451C16-AC75-11D1-B4B8-00C04FB66EA0})
693 * is defined in softpub.h
695 static BOOL WINTRUST_RegisterGenChainVerify(void)
697 static GUID ProvGUID = WINTRUST_ACTION_GENERIC_CHAIN_VERIFY;
698 CRYPT_REGISTER_ACTIONID ProvInfo;
700 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
701 ProvInfo.sInitProvider = SoftpubInitialization;
702 ProvInfo.sObjectProvider = SoftpubMessage;
703 ProvInfo.sSignatureProvider = SoftpubSignature;
704 ProvInfo.sCertificateProvider = GenericChainCertificateTrust;
705 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
706 ProvInfo.sFinalPolicyProvider = GenericChainFinalProv;
707 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
708 ProvInfo.sCleanupProvider = SoftpubCleanup;
710 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
716 /***********************************************************************
717 * WintrustAddDefaultForUsage (WINTRUST.@)
719 * Write OID and callback functions to the registry.
722 * pszUsageOID [I] Pointer to a GUID.
723 * psDefUsage [I] Pointer to a structure that specifies the callback functions.
730 * WintrustAddDefaultForUsage will only return TRUE or FALSE, no last
731 * error is set, not even when the registry cannot be written to.
733 BOOL WINAPI WintrustAddDefaultForUsage(const char *pszUsageOID,
734 CRYPT_PROVIDER_REGDEFUSAGE *psDefUsage)
736 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};
737 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};
738 LONG Res = ERROR_SUCCESS;
739 LONG WriteUsageError = ERROR_SUCCESS;
741 WCHAR GuidString[39];
743 TRACE("(%s %p)\n", debugstr_a(pszUsageOID), psDefUsage);
745 /* Some sanity checks. */
748 !psDefUsage->pgActionID ||
749 (psDefUsage->cbStruct != sizeof(CRYPT_PROVIDER_REGDEFUSAGE)))
751 SetLastError(ERROR_INVALID_PARAMETER);
755 if (psDefUsage->pwszDllName)
757 Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, Dll, psDefUsage->pwszDllName);
758 if (Res != ERROR_SUCCESS) WriteUsageError = Res;
760 if (psDefUsage->pwszLoadCallbackDataFunctionName)
764 Len = MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszLoadCallbackDataFunctionName, -1, NULL, 0 );
765 CallbackW = WINTRUST_Alloc( Len * sizeof(WCHAR) );
766 MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszLoadCallbackDataFunctionName, -1, CallbackW, Len );
768 Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, CBAlloc, CallbackW);
769 if (Res != ERROR_SUCCESS) WriteUsageError = Res;
771 WINTRUST_Free(CallbackW);
773 if (psDefUsage->pwszFreeCallbackDataFunctionName)
777 Len = MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszFreeCallbackDataFunctionName, -1, NULL, 0 );
778 CallbackW = WINTRUST_Alloc( Len * sizeof(WCHAR) );
779 MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszFreeCallbackDataFunctionName, -1, CallbackW, Len );
781 Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, CBFree, CallbackW);
782 if (Res != ERROR_SUCCESS) WriteUsageError = Res;
784 WINTRUST_Free(CallbackW);
787 WINTRUST_Guid2Wstr(psDefUsage->pgActionID, GuidString);
788 Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, DefaultId, GuidString);
789 if (Res != ERROR_SUCCESS) WriteUsageError = Res;
791 if (WriteUsageError != ERROR_SUCCESS)
797 static FARPROC WINTRUST_ReadProviderFromReg(WCHAR *GuidString, const WCHAR *FunctionType)
799 WCHAR ProvKey[MAX_PATH], DllName[MAX_PATH];
800 char FunctionName[MAX_PATH];
802 LONG Res = ERROR_SUCCESS;
807 /* Create the needed key string */
809 lstrcatW(ProvKey, Trust);
810 lstrcatW(ProvKey, FunctionType);
811 lstrcatW(ProvKey, GuidString);
813 Res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, ProvKey, 0, KEY_READ, &Key);
814 if (Res != ERROR_SUCCESS) goto error_close_key;
816 /* Read the $DLL entry */
817 Size = sizeof(DllName);
818 Res = RegQueryValueExW(Key, Dll, NULL, NULL, (LPBYTE)DllName, &Size);
819 if (Res != ERROR_SUCCESS) goto error_close_key;
821 /* Read the $Function entry */
822 Size = sizeof(FunctionName);
823 Res = RegQueryValueExA(Key, "$Function", NULL, NULL, (LPBYTE)FunctionName, &Size);
824 if (Res != ERROR_SUCCESS) goto error_close_key;
826 /* Load the library - there appears to be no way to close a provider, so
827 * just leak the module handle.
829 Lib = LoadLibraryW(DllName);
830 Func = GetProcAddress(Lib, FunctionName);
838 /***********************************************************************
839 * WintrustLoadFunctionPointers (WINTRUST.@)
841 BOOL WINAPI WintrustLoadFunctionPointers( GUID* pgActionID,
842 CRYPT_PROVIDER_FUNCTIONS* pPfns )
844 WCHAR GuidString[39];
846 TRACE("(%s %p)\n", debugstr_guid(pgActionID), pPfns);
848 if (!pPfns) return FALSE;
851 SetLastError(ERROR_INVALID_PARAMETER);
854 if (pPfns->cbStruct != sizeof(CRYPT_PROVIDER_FUNCTIONS)) return FALSE;
856 /* Create this string only once, instead of in the helper function */
857 WINTRUST_Guid2Wstr( pgActionID, GuidString);
859 /* Get the function pointers from the registry, where applicable */
860 pPfns->pfnAlloc = WINTRUST_Alloc;
861 pPfns->pfnFree = WINTRUST_Free;
862 pPfns->pfnAddStore2Chain = WINTRUST_AddStore;
863 pPfns->pfnAddSgnr2Chain = WINTRUST_AddSgnr;
864 pPfns->pfnAddCert2Chain = WINTRUST_AddCert;
865 pPfns->pfnAddPrivData2Chain = NULL;
866 pPfns->psUIpfns = NULL;
867 pPfns->pfnInitialize = (PFN_PROVIDER_INIT_CALL)WINTRUST_ReadProviderFromReg(GuidString, Initialization);
868 pPfns->pfnObjectTrust = (PFN_PROVIDER_OBJTRUST_CALL)WINTRUST_ReadProviderFromReg(GuidString, Message);
869 pPfns->pfnSignatureTrust = (PFN_PROVIDER_SIGTRUST_CALL)WINTRUST_ReadProviderFromReg(GuidString, Signature);
870 pPfns->pfnCertificateTrust = (PFN_PROVIDER_CERTTRUST_CALL)WINTRUST_ReadProviderFromReg(GuidString, Certificate);
871 pPfns->pfnCertCheckPolicy = (PFN_PROVIDER_CERTCHKPOLICY_CALL)WINTRUST_ReadProviderFromReg(GuidString, CertCheck);
872 pPfns->pfnFinalPolicy = (PFN_PROVIDER_FINALPOLICY_CALL)WINTRUST_ReadProviderFromReg(GuidString, FinalPolicy);
873 pPfns->pfnTestFinalPolicy = (PFN_PROVIDER_TESTFINALPOLICY_CALL)WINTRUST_ReadProviderFromReg(GuidString, DiagnosticPolicy);
874 pPfns->pfnCleanupPolicy = (PFN_PROVIDER_CLEANUP_CALL)WINTRUST_ReadProviderFromReg(GuidString, Cleanup);
879 /***********************************************************************
880 * WINTRUST_SIPPAddProvider
882 * Helper for DllRegisterServer.
884 static BOOL WINTRUST_SIPPAddProvider(GUID* Subject, WCHAR* MagicNumber)
886 static WCHAR CryptSIPGetSignedDataMsg[] =
887 {'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};
888 static WCHAR CryptSIPPutSignedDataMsg[] =
889 {'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};
890 static WCHAR CryptSIPCreateIndirectData[] =
891 {'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};
892 static WCHAR CryptSIPVerifyIndirectData[] =
893 {'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};
894 static WCHAR CryptSIPRemoveSignedDataMsg[] =
895 {'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};
896 SIP_ADD_NEWPROVIDER NewProv;
899 /* Clear and initialize the structure */
900 memset(&NewProv, 0, sizeof(SIP_ADD_NEWPROVIDER));
901 NewProv.cbStruct = sizeof(SIP_ADD_NEWPROVIDER);
902 NewProv.pwszDLLFileName = WINTRUST_Alloc(sizeof(SP_POLICY_PROVIDER_DLL_NAME));
903 /* Fill the structure */
904 NewProv.pgSubject = Subject;
905 lstrcpyW(NewProv.pwszDLLFileName, SP_POLICY_PROVIDER_DLL_NAME);
906 NewProv.pwszMagicNumber = MagicNumber;
907 NewProv.pwszIsFunctionName = NULL;
908 NewProv.pwszGetFuncName = CryptSIPGetSignedDataMsg;
909 NewProv.pwszPutFuncName = CryptSIPPutSignedDataMsg;
910 NewProv.pwszCreateFuncName = CryptSIPCreateIndirectData;
911 NewProv.pwszVerifyFuncName = CryptSIPVerifyIndirectData;
912 NewProv.pwszRemoveFuncName = CryptSIPRemoveSignedDataMsg;
913 NewProv.pwszIsFunctionNameFmt2 = NULL;
915 Ret = CryptSIPAddProvider(&NewProv);
917 WINTRUST_Free(NewProv.pwszDLLFileName);
922 /***********************************************************************
923 * DllRegisterServer (WINTRUST.@)
925 HRESULT WINAPI DllRegisterServer(void)
927 static const CHAR SpcPeImageDataEncode[] = "WVTAsn1SpcPeImageDataEncode";
928 static const CHAR SpcPeImageDataDecode[] = "WVTAsn1SpcPeImageDataDecode";
929 static const CHAR SpcLinkEncode[] = "WVTAsn1SpcLinkEncode";
930 static const CHAR SpcLinkDecode[] = "WVTAsn1SpcLinkDecode";
931 static const CHAR SpcSigInfoEncode[] = "WVTAsn1SpcSigInfoEncode";
932 static const CHAR SpcSigInfoDecode[] = "WVTAsn1SpcSigInfoDecode";
933 static const CHAR SpcIndirectDataContentEncode[] = "WVTAsn1SpcIndirectDataContentEncode";
934 static const CHAR SpcIndirectDataContentDecode[] = "WVTAsn1SpcIndirectDataContentDecode";
935 static const CHAR SpcSpAgencyInfoEncode[] = "WVTAsn1SpcSpAgencyInfoEncode";
936 static const CHAR SpcSpAgencyInfoDecode[] = "WVTAsn1SpcSpAgencyInfoDecode";
937 static const CHAR SpcMinimalCriteriaInfoEncode[] = "WVTAsn1SpcMinimalCriteriaInfoEncode";
938 static const CHAR SpcMinimalCriteriaInfoDecode[] = "WVTAsn1SpcMinimalCriteriaInfoDecode";
939 static const CHAR SpcFinancialCriteriaInfoEncode[] = "WVTAsn1SpcFinancialCriteriaInfoEncode";
940 static const CHAR SpcFinancialCriteriaInfoDecode[] = "WVTAsn1SpcFinancialCriteriaInfoDecode";
941 static const CHAR SpcStatementTypeEncode[] = "WVTAsn1SpcStatementTypeEncode";
942 static const CHAR SpcStatementTypeDecode[] = "WVTAsn1SpcStatementTypeDecode";
943 static const CHAR CatNameValueEncode[] = "WVTAsn1CatNameValueEncode";
944 static const CHAR CatNameValueDecode[] = "WVTAsn1CatNameValueDecode";
945 static const CHAR CatMemberInfoEncode[] = "WVTAsn1CatMemberInfoEncode";
946 static const CHAR CatMemberInfoDecode[] = "WVTAsn1CatMemberInfoDecode";
947 static const CHAR SpcSpOpusInfoEncode[] = "WVTAsn1SpcSpOpusInfoEncode";
948 static const CHAR SpcSpOpusInfoDecode[] = "WVTAsn1SpcSpOpusInfoDecode";
949 static GUID Unknown1 = { 0xDE351A42, 0x8E59, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
950 static GUID Unknown2 = { 0xC689AABA, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
951 static GUID Unknown3 = { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
952 static GUID Unknown4 = { 0xC689AAB9, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
953 static GUID Unknown5 = { 0xDE351A43, 0x8E59, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
954 static GUID Unknown6 = { 0x9BA61D3F, 0xE73A, 0x11D0, { 0x8C,0xD2,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
955 static WCHAR MagicNumber2[] = {'M','S','C','F', 0};
956 static WCHAR MagicNumber3[] = {'0','x','0','0','0','0','4','5','5','0', 0};
957 static WCHAR CafeBabe[] = {'0','x','c','a','f','e','b','a','b','e', 0};
959 HRESULT CryptRegisterRes = S_OK;
960 HRESULT TrustProviderRes = S_OK;
961 HRESULT SIPAddProviderRes = S_OK;
965 /* Testing on native shows that when an error is encountered in one of the CryptRegisterOIDFunction calls
966 * the rest of these calls is skipped. Registering is however continued for the trust providers.
968 * We are not totally in line with native as there all decoding functions are registered after all encoding
971 #define WINTRUST_REGISTEROID( oid, encode_funcname, decode_funcname ) \
973 if (!CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_ENCODE_OBJECT_FUNC, oid, SP_POLICY_PROVIDER_DLL_NAME, encode_funcname)) \
975 CryptRegisterRes = HRESULT_FROM_WIN32(GetLastError()); \
976 goto add_trust_providers; \
978 if (!CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_DECODE_OBJECT_FUNC, oid, SP_POLICY_PROVIDER_DLL_NAME, decode_funcname)) \
980 CryptRegisterRes = HRESULT_FROM_WIN32(GetLastError()); \
981 goto add_trust_providers; \
985 WINTRUST_REGISTEROID(SPC_PE_IMAGE_DATA_OBJID, SpcPeImageDataEncode, SpcPeImageDataDecode);
986 WINTRUST_REGISTEROID(SPC_PE_IMAGE_DATA_STRUCT, SpcPeImageDataEncode, SpcPeImageDataDecode);
987 WINTRUST_REGISTEROID(SPC_CAB_DATA_OBJID, SpcLinkEncode, SpcLinkDecode);
988 WINTRUST_REGISTEROID(SPC_CAB_DATA_STRUCT, SpcLinkEncode, SpcLinkDecode);
989 WINTRUST_REGISTEROID(SPC_JAVA_CLASS_DATA_OBJID, SpcLinkEncode, SpcLinkDecode);
990 WINTRUST_REGISTEROID(SPC_JAVA_CLASS_DATA_STRUCT, SpcLinkEncode, SpcLinkDecode);
991 WINTRUST_REGISTEROID(SPC_LINK_OBJID, SpcLinkEncode, SpcLinkDecode);
992 WINTRUST_REGISTEROID(SPC_LINK_STRUCT, SpcLinkEncode, SpcLinkDecode);
993 WINTRUST_REGISTEROID(SPC_SIGINFO_OBJID, SpcSigInfoEncode, SpcSigInfoDecode);
994 WINTRUST_REGISTEROID(SPC_SIGINFO_STRUCT, SpcSigInfoEncode, SpcSigInfoDecode);
995 WINTRUST_REGISTEROID(SPC_INDIRECT_DATA_OBJID, SpcIndirectDataContentEncode, SpcIndirectDataContentDecode);
996 WINTRUST_REGISTEROID(SPC_INDIRECT_DATA_CONTENT_STRUCT, SpcIndirectDataContentEncode, SpcIndirectDataContentDecode);
997 WINTRUST_REGISTEROID(SPC_SP_AGENCY_INFO_OBJID, SpcSpAgencyInfoEncode, SpcSpAgencyInfoDecode);
998 WINTRUST_REGISTEROID(SPC_SP_AGENCY_INFO_STRUCT, SpcSpAgencyInfoEncode, SpcSpAgencyInfoDecode);
999 WINTRUST_REGISTEROID(SPC_MINIMAL_CRITERIA_OBJID, SpcMinimalCriteriaInfoEncode, SpcMinimalCriteriaInfoDecode);
1000 WINTRUST_REGISTEROID(SPC_MINIMAL_CRITERIA_STRUCT, SpcMinimalCriteriaInfoEncode, SpcMinimalCriteriaInfoDecode);
1001 WINTRUST_REGISTEROID(SPC_FINANCIAL_CRITERIA_OBJID, SpcFinancialCriteriaInfoEncode, SpcFinancialCriteriaInfoDecode);
1002 WINTRUST_REGISTEROID(SPC_FINANCIAL_CRITERIA_STRUCT, SpcFinancialCriteriaInfoEncode, SpcFinancialCriteriaInfoDecode);
1003 WINTRUST_REGISTEROID(SPC_STATEMENT_TYPE_OBJID, SpcStatementTypeEncode, SpcStatementTypeDecode);
1004 WINTRUST_REGISTEROID(SPC_STATEMENT_TYPE_STRUCT, SpcStatementTypeEncode, SpcStatementTypeDecode);
1005 WINTRUST_REGISTEROID(CAT_NAMEVALUE_OBJID, CatNameValueEncode, CatNameValueDecode);
1006 WINTRUST_REGISTEROID(CAT_NAMEVALUE_STRUCT, CatNameValueEncode, CatNameValueDecode);
1007 WINTRUST_REGISTEROID(CAT_MEMBERINFO_OBJID, CatMemberInfoEncode, CatMemberInfoDecode);
1008 WINTRUST_REGISTEROID(CAT_MEMBERINFO_STRUCT, CatMemberInfoEncode, CatMemberInfoDecode);
1009 WINTRUST_REGISTEROID(SPC_SP_OPUS_INFO_OBJID, SpcSpOpusInfoEncode, SpcSpOpusInfoDecode);
1010 WINTRUST_REGISTEROID(SPC_SP_OPUS_INFO_STRUCT, SpcSpOpusInfoEncode, SpcSpOpusInfoDecode);
1012 #undef WINTRUST_REGISTEROID
1014 add_trust_providers:
1016 /* Testing on W2K3 shows:
1017 * All registry writes are tried. If one fails this part will return S_FALSE.
1019 * Last error is set to the last error encountered, regardless if the first
1020 * part failed or not.
1023 /* Create the necessary action registry structures */
1024 WINTRUST_InitRegStructs();
1026 /* Register several Trust Provider actions */
1027 if (!WINTRUST_RegisterGenVerifyV2())
1028 TrustProviderRes = S_FALSE;
1029 if (!WINTRUST_RegisterPublishedSoftware())
1030 TrustProviderRes = S_FALSE;
1031 if (!WINTRUST_RegisterPublishedSoftwareNoBadUi())
1032 TrustProviderRes = S_FALSE;
1033 if (!WINTRUST_RegisterGenCertVerify())
1034 TrustProviderRes = S_FALSE;
1035 if (!WINTRUST_RegisterTrustProviderTest())
1036 TrustProviderRes = S_FALSE;
1037 if (!WINTRUST_RegisterHttpsProv())
1038 TrustProviderRes = S_FALSE;
1039 if (!WINTRUST_RegisterOfficeSignVerify())
1040 TrustProviderRes = S_FALSE;
1041 if (!WINTRUST_RegisterDriverVerify())
1042 TrustProviderRes = S_FALSE;
1043 if (!WINTRUST_RegisterGenChainVerify())
1044 TrustProviderRes = S_FALSE;
1046 /* Free the registry structures */
1047 WINTRUST_FreeRegStructs();
1049 /* Testing on W2K3 shows:
1050 * All registry writes are tried. If one fails this part will return S_FALSE.
1052 * Last error is set to the last error encountered, regardless if the previous
1053 * parts failed or not.
1056 if (!WINTRUST_SIPPAddProvider(&Unknown1, NULL))
1057 SIPAddProviderRes = S_FALSE;
1058 if (!WINTRUST_SIPPAddProvider(&Unknown2, MagicNumber2))
1059 SIPAddProviderRes = S_FALSE;
1060 if (!WINTRUST_SIPPAddProvider(&Unknown3, MagicNumber3))
1061 SIPAddProviderRes = S_FALSE;
1062 if (!WINTRUST_SIPPAddProvider(&Unknown4, CafeBabe))
1063 SIPAddProviderRes = S_FALSE;
1064 if (!WINTRUST_SIPPAddProvider(&Unknown5, CafeBabe))
1065 SIPAddProviderRes = S_FALSE;
1066 if (!WINTRUST_SIPPAddProvider(&Unknown6, CafeBabe))
1067 SIPAddProviderRes = S_FALSE;
1069 /* Native does a CryptSIPRemoveProvider here for {941C2937-1292-11D1-85BE-00C04FC295EE}.
1070 * This SIP Provider is however not found on up-to-date window install and native will
1071 * set the last error to ERROR_FILE_NOT_FOUND.
1072 * Wine has the last error set to ERROR_INVALID_PARAMETER. There shouldn't be an app
1073 * depending on this last error though so there is no need to imitate native to the full extent.
1075 * (The ERROR_INVALID_PARAMETER for Wine it totally valid as we (and native) do register
1076 * a trust provider without a diagnostic policy).
1079 /* If CryptRegisterRes is not S_OK it will always overrule the return value. */
1080 if (CryptRegisterRes != S_OK)
1081 return CryptRegisterRes;
1082 else if (SIPAddProviderRes == S_OK)
1083 return TrustProviderRes;
1085 return SIPAddProviderRes;
1088 /***********************************************************************
1089 * DllUnregisterServer (WINTRUST.@)
1091 HRESULT WINAPI DllUnregisterServer(void)
1097 /***********************************************************************
1098 * SoftpubDllRegisterServer (WINTRUST.@)
1100 * Registers softpub.dll
1106 * Failure: S_FALSE. (See also GetLastError()).
1109 * DllRegisterServer in softpub.dll will call this function.
1110 * See comments in DllRegisterServer.
1112 HRESULT WINAPI SoftpubDllRegisterServer(void)
1114 HRESULT TrustProviderRes = S_OK;
1118 /* Create the necessary action registry structures */
1119 WINTRUST_InitRegStructs();
1121 /* Register several Trust Provider actions */
1122 if (!WINTRUST_RegisterGenVerifyV2())
1123 TrustProviderRes = S_FALSE;
1124 if (!WINTRUST_RegisterPublishedSoftware())
1125 TrustProviderRes = S_FALSE;
1126 if (!WINTRUST_RegisterPublishedSoftwareNoBadUi())
1127 TrustProviderRes = S_FALSE;
1128 if (!WINTRUST_RegisterGenCertVerify())
1129 TrustProviderRes = S_FALSE;
1130 if (!WINTRUST_RegisterTrustProviderTest())
1131 TrustProviderRes = S_FALSE;
1132 if (!WINTRUST_RegisterHttpsProv())
1133 TrustProviderRes = S_FALSE;
1134 if (!WINTRUST_RegisterOfficeSignVerify())
1135 TrustProviderRes = S_FALSE;
1136 if (!WINTRUST_RegisterDriverVerify())
1137 TrustProviderRes = S_FALSE;
1138 if (!WINTRUST_RegisterGenChainVerify())
1139 TrustProviderRes = S_FALSE;
1141 /* Free the registry structures */
1142 WINTRUST_FreeRegStructs();
1144 return TrustProviderRes;
1147 /***********************************************************************
1148 * SoftpubDllUnregisterServer (WINTRUST.@)
1150 HRESULT WINAPI SoftpubDllUnregisterServer(void)
1156 /***********************************************************************
1157 * mscat32DllRegisterServer (WINTRUST.@)
1159 HRESULT WINAPI mscat32DllRegisterServer(void)
1165 /***********************************************************************
1166 * mscat32DllUnregisterServer (WINTRUST.@)
1168 HRESULT WINAPI mscat32DllUnregisterServer(void)
1174 /***********************************************************************
1175 * mssip32DllRegisterServer (WINTRUST.@)
1177 HRESULT WINAPI mssip32DllRegisterServer(void)
1183 /***********************************************************************
1184 * mssip32DllUnregisterServer (WINTRUST.@)
1186 HRESULT WINAPI mssip32DllUnregisterServer(void)