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
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(wintrust);
38 static CRYPT_TRUST_REG_ENTRY SoftpubInitialization;
39 static CRYPT_TRUST_REG_ENTRY SoftpubMessage;
40 static CRYPT_TRUST_REG_ENTRY SoftpubSignature;
41 static CRYPT_TRUST_REG_ENTRY SoftpubCertficate;
42 static CRYPT_TRUST_REG_ENTRY SoftpubCertCheck;
43 static CRYPT_TRUST_REG_ENTRY SoftpubFinalPolicy;
44 static CRYPT_TRUST_REG_ENTRY SoftpubCleanup;
46 static CRYPT_TRUST_REG_ENTRY SoftpubDefCertInit;
48 static CRYPT_TRUST_REG_ENTRY SoftpubDumpStructure;
50 static CRYPT_TRUST_REG_ENTRY HTTPSCertificateTrust;
51 static CRYPT_TRUST_REG_ENTRY HTTPSFinalProv;
53 static CRYPT_TRUST_REG_ENTRY OfficeInitializePolicy;
54 static CRYPT_TRUST_REG_ENTRY OfficeCleanupPolicy;
56 static CRYPT_TRUST_REG_ENTRY DriverInitializePolicy;
57 static CRYPT_TRUST_REG_ENTRY DriverFinalPolicy;
58 static CRYPT_TRUST_REG_ENTRY DriverCleanupPolicy;
60 static CRYPT_TRUST_REG_ENTRY GenericChainCertificateTrust;
61 static CRYPT_TRUST_REG_ENTRY GenericChainFinalProv;
63 static const WCHAR Trust[] = {'S','o','f','t','w','a','r','e','\\',
64 'M','i','c','r','o','s','o','f','t','\\',
65 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
66 'P','r','o','v','i','d','e','r','s','\\',
67 'T','r','u','s','t','\\', 0 };
69 static const WCHAR Initialization[] = {'I','n','i','t','i','a','l','i','z','a','t','i','o','n','\\', 0};
70 static const WCHAR Message[] = {'M','e','s','s','a','g','e','\\', 0};
71 static const WCHAR Signature[] = {'S','i','g','n','a','t','u','r','e','\\', 0};
72 static const WCHAR Certificate[] = {'C','e','r','t','i','f','i','c','a','t','e','\\', 0};
73 static const WCHAR CertCheck[] = {'C','e','r','t','C','h','e','c','k','\\', 0};
74 static const WCHAR FinalPolicy[] = {'F','i','n','a','l','P','o','l','i','c','y','\\', 0};
75 static const WCHAR DiagnosticPolicy[] = {'D','i','a','g','n','o','s','t','i','c','P','o','l','i','c','y','\\', 0};
76 static const WCHAR Cleanup[] = {'C','l','e','a','n','u','p','\\', 0};
78 static const WCHAR DefaultId[] = {'D','e','f','a','u','l','t','I','d', 0};
79 static const WCHAR Dll[] = {'$','D','L','L', 0};
81 /***********************************************************************
82 * WINTRUST_InitRegStructs
84 * Helper function to allocate and initialize the members of the
85 * CRYPT_TRUST_REG_ENTRY structs.
87 static void WINTRUST_InitRegStructs(void)
89 #define WINTRUST_INITREGENTRY( action, dllname, functionname ) \
90 action.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY); \
91 action.pwszDLLName = HeapAlloc(GetProcessHeap(), 0, sizeof(dllname)); \
92 lstrcpyW(action.pwszDLLName, dllname); \
93 action.pwszFunctionName = HeapAlloc(GetProcessHeap(), 0, sizeof(functionname)); \
94 lstrcpyW(action.pwszFunctionName, functionname);
96 WINTRUST_INITREGENTRY(SoftpubInitialization, SP_POLICY_PROVIDER_DLL_NAME, SP_INIT_FUNCTION)
97 WINTRUST_INITREGENTRY(SoftpubMessage, SP_POLICY_PROVIDER_DLL_NAME, SP_OBJTRUST_FUNCTION)
98 WINTRUST_INITREGENTRY(SoftpubSignature, SP_POLICY_PROVIDER_DLL_NAME, SP_SIGTRUST_FUNCTION)
99 WINTRUST_INITREGENTRY(SoftpubCertficate, SP_POLICY_PROVIDER_DLL_NAME, WT_PROVIDER_CERTTRUST_FUNCTION)
100 WINTRUST_INITREGENTRY(SoftpubCertCheck, SP_POLICY_PROVIDER_DLL_NAME, SP_CHKCERT_FUNCTION)
101 WINTRUST_INITREGENTRY(SoftpubFinalPolicy, SP_POLICY_PROVIDER_DLL_NAME, SP_FINALPOLICY_FUNCTION)
102 WINTRUST_INITREGENTRY(SoftpubCleanup, SP_POLICY_PROVIDER_DLL_NAME, SP_CLEANUPPOLICY_FUNCTION)
103 WINTRUST_INITREGENTRY(SoftpubDefCertInit, SP_POLICY_PROVIDER_DLL_NAME, SP_GENERIC_CERT_INIT_FUNCTION)
104 WINTRUST_INITREGENTRY(SoftpubDumpStructure, SP_POLICY_PROVIDER_DLL_NAME, SP_TESTDUMPPOLICY_FUNCTION_TEST)
105 WINTRUST_INITREGENTRY(HTTPSCertificateTrust, SP_POLICY_PROVIDER_DLL_NAME, HTTPS_CERTTRUST_FUNCTION)
106 WINTRUST_INITREGENTRY(HTTPSFinalProv, SP_POLICY_PROVIDER_DLL_NAME, HTTPS_FINALPOLICY_FUNCTION)
107 WINTRUST_INITREGENTRY(OfficeInitializePolicy, OFFICE_POLICY_PROVIDER_DLL_NAME, OFFICE_INITPROV_FUNCTION)
108 WINTRUST_INITREGENTRY(OfficeCleanupPolicy, OFFICE_POLICY_PROVIDER_DLL_NAME, OFFICE_CLEANUPPOLICY_FUNCTION)
109 WINTRUST_INITREGENTRY(DriverInitializePolicy, SP_POLICY_PROVIDER_DLL_NAME, DRIVER_INITPROV_FUNCTION)
110 WINTRUST_INITREGENTRY(DriverFinalPolicy, SP_POLICY_PROVIDER_DLL_NAME, DRIVER_FINALPOLPROV_FUNCTION)
111 WINTRUST_INITREGENTRY(DriverCleanupPolicy, SP_POLICY_PROVIDER_DLL_NAME, DRIVER_CLEANUPPOLICY_FUNCTION)
112 WINTRUST_INITREGENTRY(GenericChainCertificateTrust, SP_POLICY_PROVIDER_DLL_NAME, GENERIC_CHAIN_CERTTRUST_FUNCTION)
113 WINTRUST_INITREGENTRY(GenericChainFinalProv, SP_POLICY_PROVIDER_DLL_NAME, GENERIC_CHAIN_FINALPOLICY_FUNCTION)
115 #undef WINTRUST_INITREGENTRY
118 /***********************************************************************
119 * WINTRUST_FreeRegStructs
121 * Helper function to free 2 members of the CRYPT_TRUST_REG_ENTRY
124 static void WINTRUST_FreeRegStructs(void)
126 #define WINTRUST_FREEREGENTRY( action ) \
127 HeapFree(GetProcessHeap(), 0, action.pwszDLLName); \
128 HeapFree(GetProcessHeap(), 0, action.pwszFunctionName);
130 WINTRUST_FREEREGENTRY(SoftpubInitialization);
131 WINTRUST_FREEREGENTRY(SoftpubMessage);
132 WINTRUST_FREEREGENTRY(SoftpubSignature);
133 WINTRUST_FREEREGENTRY(SoftpubCertficate);
134 WINTRUST_FREEREGENTRY(SoftpubCertCheck);
135 WINTRUST_FREEREGENTRY(SoftpubFinalPolicy);
136 WINTRUST_FREEREGENTRY(SoftpubCleanup);
137 WINTRUST_FREEREGENTRY(SoftpubDefCertInit);
138 WINTRUST_FREEREGENTRY(SoftpubDumpStructure);
139 WINTRUST_FREEREGENTRY(HTTPSCertificateTrust);
140 WINTRUST_FREEREGENTRY(HTTPSFinalProv);
141 WINTRUST_FREEREGENTRY(OfficeInitializePolicy);
142 WINTRUST_FREEREGENTRY(OfficeCleanupPolicy);
143 WINTRUST_FREEREGENTRY(DriverInitializePolicy);
144 WINTRUST_FREEREGENTRY(DriverFinalPolicy);
145 WINTRUST_FREEREGENTRY(DriverCleanupPolicy);
146 WINTRUST_FREEREGENTRY(GenericChainCertificateTrust);
147 WINTRUST_FREEREGENTRY(GenericChainFinalProv);
149 #undef WINTRUST_FREEREGENTRY
152 /***********************************************************************
155 * Create a wide-string from a GUID
158 static void WINTRUST_Guid2Wstr(const GUID* pgActionID, WCHAR* GuidString)
160 static const WCHAR wszFormat[] = {'{','%','0','8','l','X','-','%','0','4','X','-','%','0','4','X','-',
161 '%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2',
162 'X','%','0','2','X','%','0','2','X','}', 0};
164 wsprintfW(GuidString, wszFormat, pgActionID->Data1, pgActionID->Data2, pgActionID->Data3,
165 pgActionID->Data4[0], pgActionID->Data4[1], pgActionID->Data4[2], pgActionID->Data4[3],
166 pgActionID->Data4[4], pgActionID->Data4[5], pgActionID->Data4[6], pgActionID->Data4[7]);
169 /***********************************************************************
170 * WINTRUST_WriteProviderToReg
172 * Helper function for WintrustAddActionID
175 static LONG WINTRUST_WriteProviderToReg(WCHAR* GuidString,
176 const WCHAR* FunctionType,
177 CRYPT_TRUST_REG_ENTRY RegEntry)
179 static const WCHAR Function[] = {'$','F','u','n','c','t','i','o','n', 0};
180 WCHAR ProvKey[MAX_PATH];
182 LONG Res = ERROR_SUCCESS;
184 /* Create the needed key string */
186 lstrcatW(ProvKey, Trust);
187 lstrcatW(ProvKey, FunctionType);
188 lstrcatW(ProvKey, GuidString);
190 if (!RegEntry.pwszDLLName || !RegEntry.pwszFunctionName)
191 return ERROR_INVALID_PARAMETER;
193 Res = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ProvKey, 0, NULL, 0, KEY_WRITE, NULL, &Key, NULL);
194 if (Res != ERROR_SUCCESS) goto error_close_key;
196 /* Create the $DLL entry */
197 Res = RegSetValueExW(Key, Dll, 0, REG_SZ, (BYTE*)RegEntry.pwszDLLName,
198 (lstrlenW(RegEntry.pwszDLLName) + 1)*sizeof(WCHAR));
199 if (Res != ERROR_SUCCESS) goto error_close_key;
201 /* Create the $Function entry */
202 Res = RegSetValueExW(Key, Function, 0, REG_SZ, (BYTE*)RegEntry.pwszFunctionName,
203 (lstrlenW(RegEntry.pwszFunctionName) + 1)*sizeof(WCHAR));
211 /***********************************************************************
212 * WintrustAddActionID (WINTRUST.@)
214 * Add the definitions of the actions a Trust provider can perform to
218 * pgActionID [I] Pointer to a GUID for the Trust provider.
219 * fdwFlags [I] Flag to indicate whether registry errors are passed on.
220 * psProvInfo [I] Pointer to a structure with information about DLL
221 * name and functions.
225 * Failure: FALSE. (Use GetLastError() for more information)
228 * Adding definitions is basically only adding relevant information
229 * to the registry. No verification takes place whether a DLL or it's
231 * Information in the registry will always be overwritten.
234 BOOL WINAPI WintrustAddActionID( GUID* pgActionID, DWORD fdwFlags,
235 CRYPT_REGISTER_ACTIONID* psProvInfo)
237 WCHAR GuidString[39];
239 LONG WriteActionError = ERROR_SUCCESS;
241 TRACE("%s %lx %p\n", debugstr_guid(pgActionID), fdwFlags, psProvInfo);
243 /* Some sanity checks.
244 * We use the W2K3 last error as it makes more sense (W2K leaves the last error
249 (psProvInfo->cbStruct != sizeof(CRYPT_REGISTER_ACTIONID)))
251 SetLastError(ERROR_INVALID_PARAMETER);
255 /* Create this string only once, instead of in the helper function */
256 WINTRUST_Guid2Wstr( pgActionID, GuidString);
258 /* Write the information to the registry */
259 Res = WINTRUST_WriteProviderToReg(GuidString, Initialization , psProvInfo->sInitProvider);
260 if (Res != ERROR_SUCCESS) WriteActionError = Res;
261 Res = WINTRUST_WriteProviderToReg(GuidString, Message , psProvInfo->sObjectProvider);
262 if (Res != ERROR_SUCCESS) WriteActionError = Res;
263 Res = WINTRUST_WriteProviderToReg(GuidString, Signature , psProvInfo->sSignatureProvider);
264 if (Res != ERROR_SUCCESS) WriteActionError = Res;
265 Res = WINTRUST_WriteProviderToReg(GuidString, Certificate , psProvInfo->sCertificateProvider);
266 if (Res != ERROR_SUCCESS) WriteActionError = Res;
267 Res = WINTRUST_WriteProviderToReg(GuidString, CertCheck , psProvInfo->sCertificatePolicyProvider);
268 if (Res != ERROR_SUCCESS) WriteActionError = Res;
269 Res = WINTRUST_WriteProviderToReg(GuidString, FinalPolicy , psProvInfo->sFinalPolicyProvider);
270 if (Res != ERROR_SUCCESS) WriteActionError = Res;
271 Res = WINTRUST_WriteProviderToReg(GuidString, DiagnosticPolicy, psProvInfo->sTestPolicyProvider);
272 if (Res != ERROR_SUCCESS) WriteActionError = Res;
273 Res = WINTRUST_WriteProviderToReg(GuidString, Cleanup , psProvInfo->sCleanupProvider);
274 if (Res != ERROR_SUCCESS) WriteActionError = Res;
276 /* Testing (by restricting access to the registry for some keys) shows that the last failing function
277 * will be used for last error.
278 * If the flag WT_ADD_ACTION_ID_RET_RESULT_FLAG is set and there are errors when adding the action
279 * we have to return FALSE. Errors includes both invalid entries as well as registry errors.
280 * Testing also showed that one error doesn't stop the registry writes. Every action will be dealt with.
283 if (WriteActionError != ERROR_SUCCESS)
285 SetLastError(WriteActionError);
287 if (fdwFlags == WT_ADD_ACTION_ID_RET_RESULT_FLAG)
294 /***********************************************************************
295 * WINTRUST_RemoveProviderFromReg
297 * Helper function for WintrustRemoveActionID
300 static void WINTRUST_RemoveProviderFromReg(WCHAR* GuidString,
301 const WCHAR* FunctionType)
303 WCHAR ProvKey[MAX_PATH];
305 /* Create the needed key string */
307 lstrcatW(ProvKey, Trust);
308 lstrcatW(ProvKey, FunctionType);
309 lstrcatW(ProvKey, GuidString);
311 /* We don't care about success or failure */
312 RegDeleteKeyW(HKEY_LOCAL_MACHINE, ProvKey);
315 /***********************************************************************
316 * WintrustRemoveActionID (WINTRUST.@)
318 * Remove the definitions of the actions a Trust provider can perform
322 * pgActionID [I] Pointer to a GUID for the Trust provider.
325 * Success: TRUE. (Use GetLastError() for more information)
326 * Failure: FALSE. (Use GetLastError() for more information)
329 * Testing shows that WintrustRemoveActionID always returns TRUE and
330 * that a possible error should be retrieved via GetLastError().
331 * There are no checks if the definitions are in the registry.
333 BOOL WINAPI WintrustRemoveActionID( GUID* pgActionID )
335 WCHAR GuidString[39];
337 TRACE("(%s)\n", debugstr_guid(pgActionID));
341 SetLastError(ERROR_INVALID_PARAMETER);
345 /* Create this string only once, instead of in the helper function */
346 WINTRUST_Guid2Wstr( pgActionID, GuidString);
348 /* We don't care about success or failure */
349 WINTRUST_RemoveProviderFromReg(GuidString, Initialization);
350 WINTRUST_RemoveProviderFromReg(GuidString, Message);
351 WINTRUST_RemoveProviderFromReg(GuidString, Signature);
352 WINTRUST_RemoveProviderFromReg(GuidString, Certificate);
353 WINTRUST_RemoveProviderFromReg(GuidString, CertCheck);
354 WINTRUST_RemoveProviderFromReg(GuidString, FinalPolicy);
355 WINTRUST_RemoveProviderFromReg(GuidString, DiagnosticPolicy);
356 WINTRUST_RemoveProviderFromReg(GuidString, Cleanup);
361 /***********************************************************************
362 * WINTRUST_WriteSingleUsageEntry
364 * Helper for WintrustAddDefaultForUsage, writes a single value and its
367 * HKLM\Software\Microsoft\Cryptography\Trust\Usages\<OID>
369 static LONG WINTRUST_WriteSingleUsageEntry(LPCSTR OID,
373 static const WCHAR Usages[] = {'U','s','a','g','e','s','\\', 0};
376 LONG Res = ERROR_SUCCESS;
380 /* Turn OID into a wide-character string */
381 Len = MultiByteToWideChar( CP_ACP, 0, OID, -1, NULL, 0 );
382 OIDW = HeapAlloc( GetProcessHeap(), 0, Len * sizeof(WCHAR) );
383 MultiByteToWideChar( CP_ACP, 0, OID, -1, OIDW, Len );
385 /* Allocate the needed space for UsageKey */
386 UsageKey = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(Trust) + lstrlenW(Usages) + Len) * sizeof(WCHAR));
387 /* Create the key string */
388 lstrcpyW(UsageKey, Trust);
389 lstrcatW(UsageKey, Usages);
390 lstrcatW(UsageKey, OIDW);
392 Res = RegCreateKeyExW(HKEY_LOCAL_MACHINE, UsageKey, 0, NULL, 0, KEY_WRITE, NULL, &Key, NULL);
393 if (Res == ERROR_SUCCESS)
395 /* Create the Value entry */
396 Res = RegSetValueExW(Key, Value, 0, REG_SZ, (BYTE*)Data,
397 (lstrlenW(Data) + 1)*sizeof(WCHAR));
401 HeapFree(GetProcessHeap(), 0, OIDW);
402 HeapFree(GetProcessHeap(), 0, UsageKey);
407 /***************************************************************************
408 * WINTRUST_RegisterGenVerifyV2
410 * Register WINTRUST_ACTION_GENERIC_VERIFY_V2 actions and usages.
413 * WINTRUST_ACTION_GENERIC_VERIFY_V2 ({00AAC56B-CD44-11D0-8CC2-00C04FC295EE}
414 * is defined in softpub.h
416 static BOOL WINTRUST_RegisterGenVerifyV2(void)
418 BOOL RegisteredOK = TRUE;
419 static GUID ProvGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2;
420 CRYPT_REGISTER_ACTIONID ProvInfo = { sizeof(CRYPT_REGISTER_ACTIONID),
421 SoftpubInitialization,
427 { 0, NULL, NULL }, /* No diagnostic policy */
429 CRYPT_PROVIDER_REGDEFUSAGE DefUsage = { sizeof(CRYPT_PROVIDER_REGDEFUSAGE),
431 NULL, /* No Dll provided */
432 NULL, /* No load callback function */
433 NULL }; /* No free callback function */
435 if (!WintrustAddDefaultForUsage(szOID_PKIX_KP_CODE_SIGNING, &DefUsage))
436 RegisteredOK = FALSE;
438 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
439 RegisteredOK = FALSE;
444 /***************************************************************************
445 * WINTRUST_RegisterPublishedSoftware
447 * Register WIN_SPUB_ACTION_PUBLISHED_SOFTWARE actions and usages.
450 * WIN_SPUB_ACTION_PUBLISHED_SOFTWARE ({64B9D180-8DA2-11CF-8736-00AA00A485EB})
451 * is defined in wintrust.h
453 static BOOL WINTRUST_RegisterPublishedSoftware(void)
455 static GUID ProvGUID = WIN_SPUB_ACTION_PUBLISHED_SOFTWARE;
456 CRYPT_REGISTER_ACTIONID ProvInfo = { sizeof(CRYPT_REGISTER_ACTIONID),
457 SoftpubInitialization,
463 { 0, NULL, NULL }, /* No diagnostic policy */
466 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
472 #define WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI { 0xc6b2e8d0, 0xe005, 0x11cf, { 0xa1,0x34,0x00,0xc0,0x4f,0xd7,0xbf,0x43 }}
474 /***************************************************************************
475 * WINTRUST_RegisterPublishedSoftwareNoBadUi
477 * Register WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI actions and usages.
480 * WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI ({C6B2E8D0-E005-11CF-A134-00C04FD7BF43})
481 * is not defined in any include file. (FIXME: Find out if the name is correct).
483 static BOOL WINTRUST_RegisterPublishedSoftwareNoBadUi(void)
485 static GUID ProvGUID = WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI;
486 CRYPT_REGISTER_ACTIONID ProvInfo = { sizeof(CRYPT_REGISTER_ACTIONID),
487 SoftpubInitialization,
493 { 0, NULL, NULL }, /* No diagnostic policy */
496 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
502 /***************************************************************************
503 * WINTRUST_RegisterGenCertVerify
505 * Register WINTRUST_ACTION_GENERIC_CERT_VERIFY actions and usages.
508 * WINTRUST_ACTION_GENERIC_CERT_VERIFY ({189A3842-3041-11D1-85E1-00C04FC295EE})
509 * is defined in softpub.h
511 static BOOL WINTRUST_RegisterGenCertVerify(void)
513 static GUID ProvGUID = WINTRUST_ACTION_GENERIC_CERT_VERIFY;
514 CRYPT_REGISTER_ACTIONID ProvInfo = { sizeof(CRYPT_REGISTER_ACTIONID),
521 { 0, NULL, NULL }, /* No diagnostic policy */
524 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
530 /***************************************************************************
531 * WINTRUST_RegisterTrustProviderTest
533 * Register WINTRUST_ACTION_TRUSTPROVIDER_TEST actions and usages.
536 * WINTRUST_ACTION_TRUSTPROVIDER_TEST ({573E31F8-DDBA-11D0-8CCB-00C04FC295EE})
537 * is defined in softpub.h
539 static BOOL WINTRUST_RegisterTrustProviderTest(void)
541 static GUID ProvGUID = WINTRUST_ACTION_TRUSTPROVIDER_TEST;
542 CRYPT_REGISTER_ACTIONID ProvInfo = { sizeof(CRYPT_REGISTER_ACTIONID),
543 SoftpubInitialization,
549 SoftpubDumpStructure,
552 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
558 /***************************************************************************
559 * WINTRUST_RegisterHttpsProv
561 * Register HTTPSPROV_ACTION actions and usages.
564 * HTTPSPROV_ACTION ({573E31F8-AABA-11D0-8CCB-00C04FC295EE})
565 * is defined in softpub.h
567 static BOOL WINTRUST_RegisterHttpsProv(void)
569 BOOL RegisteredOK = TRUE;
570 static CHAR SoftpubLoadUsage[] = "SoftpubLoadDefUsageCallData";
571 static CHAR SoftpubFreeUsage[] = "SoftpubFreeDefUsageCallData";
572 static GUID ProvGUID = HTTPSPROV_ACTION;
573 CRYPT_REGISTER_ACTIONID ProvInfo = { sizeof(CRYPT_REGISTER_ACTIONID),
574 SoftpubInitialization,
577 HTTPSCertificateTrust,
580 { 0, NULL, NULL }, /* No diagnostic policy */
582 CRYPT_PROVIDER_REGDEFUSAGE DefUsage = { sizeof(CRYPT_PROVIDER_REGDEFUSAGE),
584 NULL, /* Will be filled later */
588 DefUsage.pwszDllName = HeapAlloc(GetProcessHeap(), 0, sizeof(SP_POLICY_PROVIDER_DLL_NAME));
589 lstrcpyW(DefUsage.pwszDllName, SP_POLICY_PROVIDER_DLL_NAME);
591 if (!WintrustAddDefaultForUsage(szOID_PKIX_KP_SERVER_AUTH, &DefUsage))
592 RegisteredOK = FALSE;
593 if (!WintrustAddDefaultForUsage(szOID_PKIX_KP_CLIENT_AUTH, &DefUsage))
594 RegisteredOK = FALSE;
595 if (!WintrustAddDefaultForUsage(szOID_SERVER_GATED_CRYPTO, &DefUsage))
596 RegisteredOK = FALSE;
597 if (!WintrustAddDefaultForUsage(szOID_SGC_NETSCAPE, &DefUsage))
598 RegisteredOK = FALSE;
600 HeapFree(GetProcessHeap(), 0, DefUsage.pwszDllName);
602 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
603 RegisteredOK = FALSE;
608 /***************************************************************************
609 * WINTRUST_RegisterOfficeSignVerify
611 * Register OFFICESIGN_ACTION_VERIFY actions and usages.
614 * OFFICESIGN_ACTION_VERIFY ({5555C2CD-17FB-11D1-85C4-00C04FC295EE})
615 * is defined in softpub.h
617 static BOOL WINTRUST_RegisterOfficeSignVerify(void)
619 static GUID ProvGUID = OFFICESIGN_ACTION_VERIFY;
620 CRYPT_REGISTER_ACTIONID ProvInfo = { sizeof(CRYPT_REGISTER_ACTIONID),
621 OfficeInitializePolicy,
627 { 0, NULL, NULL }, /* No diagnostic policy */
628 OfficeCleanupPolicy };
630 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
636 /***************************************************************************
637 * WINTRUST_RegisterDriverVerify
639 * Register DRIVER_ACTION_VERIFY actions and usages.
642 * DRIVER_ACTION_VERIFY ({F750E6C3-38EE-11D1-85E5-00C04FC295EE})
643 * is defined in softpub.h
645 static BOOL WINTRUST_RegisterDriverVerify(void)
647 static GUID ProvGUID = DRIVER_ACTION_VERIFY;
648 CRYPT_REGISTER_ACTIONID ProvInfo = { sizeof(CRYPT_REGISTER_ACTIONID),
649 DriverInitializePolicy,
655 { 0, NULL, NULL }, /* No diagnostic policy */
656 DriverCleanupPolicy };
658 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
664 /***************************************************************************
665 * WINTRUST_RegisterGenChainVerify
667 * Register WINTRUST_ACTION_GENERIC_CHAIN_VERIFY actions and usages.
670 * WINTRUST_ACTION_GENERIC_CHAIN_VERIFY ({FC451C16-AC75-11D1-B4B8-00C04FB66EA0})
671 * is defined in softpub.h
673 static BOOL WINTRUST_RegisterGenChainVerify(void)
675 static GUID ProvGUID = WINTRUST_ACTION_GENERIC_CHAIN_VERIFY;
676 CRYPT_REGISTER_ACTIONID ProvInfo = { sizeof(CRYPT_REGISTER_ACTIONID),
677 SoftpubInitialization,
680 GenericChainCertificateTrust,
682 GenericChainFinalProv,
683 { 0, NULL, NULL }, /* No diagnostic policy */
686 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
692 /***********************************************************************
693 * WintrustAddDefaultForUsage (WINTRUST.@)
695 * Write OID and callback functions to the registry.
698 * pszUsageOID [I] Pointer to a GUID.
699 * psDefUsage [I] Pointer to a structure that specifies the callback functions.
706 * WintrustAddDefaultForUsage will only return TRUE or FALSE, no last
707 * error is set, not even when the registry cannot be written to.
709 BOOL WINAPI WintrustAddDefaultForUsage(const CHAR *pszUsageOID,
710 CRYPT_PROVIDER_REGDEFUSAGE *psDefUsage)
712 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};
713 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};
714 LONG Res = ERROR_SUCCESS;
715 LONG WriteUsageError = ERROR_SUCCESS;
717 WCHAR GuidString[39];
719 TRACE("(%s %p)\n", debugstr_a(pszUsageOID), psDefUsage);
721 /* Some sanity checks. */
724 !psDefUsage->pgActionID ||
725 (psDefUsage->cbStruct != sizeof(CRYPT_PROVIDER_REGDEFUSAGE)))
727 SetLastError(ERROR_INVALID_PARAMETER);
731 if (psDefUsage->pwszDllName)
733 Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, Dll, psDefUsage->pwszDllName);
734 if (Res != ERROR_SUCCESS) WriteUsageError = Res;
736 if (psDefUsage->pwszLoadCallbackDataFunctionName)
740 Len = MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszLoadCallbackDataFunctionName, -1, NULL, 0 );
741 CallbackW = HeapAlloc( GetProcessHeap(), 0, Len * sizeof(WCHAR) );
742 MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszLoadCallbackDataFunctionName, -1, CallbackW, Len );
744 Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, CBAlloc, CallbackW);
745 if (Res != ERROR_SUCCESS) WriteUsageError = Res;
747 HeapFree(GetProcessHeap(), 0, CallbackW);
749 if (psDefUsage->pwszFreeCallbackDataFunctionName)
753 Len = MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszFreeCallbackDataFunctionName, -1, NULL, 0 );
754 CallbackW = HeapAlloc( GetProcessHeap(), 0, Len * sizeof(WCHAR) );
755 MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszFreeCallbackDataFunctionName, -1, CallbackW, Len );
757 Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, CBFree, CallbackW);
758 if (Res != ERROR_SUCCESS) WriteUsageError = Res;
760 HeapFree(GetProcessHeap(), 0, CallbackW);
763 WINTRUST_Guid2Wstr(psDefUsage->pgActionID, GuidString);
764 Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, DefaultId, GuidString);
765 if (Res != ERROR_SUCCESS) WriteUsageError = Res;
767 if (WriteUsageError != ERROR_SUCCESS)
773 /***********************************************************************
774 * DllRegisterServer (WINTRUST.@)
776 HRESULT WINAPI DllRegisterServer(void)
778 static const CHAR SpcPeImageDataEncode[] = "WVTAsn1SpcPeImageDataEncode";
779 static const CHAR SpcPeImageDataDecode[] = "WVTAsn1SpcPeImageDataDecode";
780 static const CHAR SpcLinkEncode[] = "WVTAsn1SpcLinkEncode";
781 static const CHAR SpcLinkDecode[] = "WVTAsn1SpcLinkDecode";
782 static const CHAR SpcSigInfoEncode[] = "WVTAsn1SpcSigInfoEncode";
783 static const CHAR SpcSigInfoDecode[] = "WVTAsn1SpcSigInfoDecode";
784 static const CHAR SpcIndirectDataContentEncode[] = "WVTAsn1SpcIndirectDataContentEncode";
785 static const CHAR SpcIndirectDataContentDecode[] = "WVTAsn1SpcIndirectDataContentDecode";
786 static const CHAR SpcSpAgencyInfoEncode[] = "WVTAsn1SpcSpAgencyInfoEncode";
787 static const CHAR SpcSpAgencyInfoDecode[] = "WVTAsn1SpcSpAgencyInfoDecode";
788 static const CHAR SpcMinimalCriteriaInfoEncode[] = "WVTAsn1SpcMinimalCriteriaInfoEncode";
789 static const CHAR SpcMinimalCriteriaInfoDecode[] = "WVTAsn1SpcMinimalCriteriaInfoDecode";
790 static const CHAR SpcFinancialCriteriaInfoEncode[] = "WVTAsn1SpcFinancialCriteriaInfoEncode";
791 static const CHAR SpcFinancialCriteriaInfoDecode[] = "WVTAsn1SpcFinancialCriteriaInfoDecode";
792 static const CHAR SpcStatementTypeEncode[] = "WVTAsn1SpcStatementTypeEncode";
793 static const CHAR SpcStatementTypeDecode[] = "WVTAsn1SpcStatementTypeDecode";
794 static const CHAR CatNameValueEncode[] = "WVTAsn1CatNameValueEncode";
795 static const CHAR CatNameValueDecode[] = "WVTAsn1CatNameValueDecode";
796 static const CHAR CatMemberInfoEncode[] = "WVTAsn1CatMemberInfoEncode";
797 static const CHAR CatMemberInfoDecode[] = "WVTAsn1CatMemberInfoDecode";
798 static const CHAR SpcSpOpusInfoEncode[] = "WVTAsn1SpcSpOpusInfoEncode";
799 static const CHAR SpcSpOpusInfoDecode[] = "WVTAsn1SpcSpOpusInfoDecode";
800 HRESULT CryptRegisterRes = S_OK;
801 HRESULT TrustProviderRes = S_OK;
807 * A short list of stuff that should be done here:
809 * - Several calls to CryptRegisterOIDFunction
810 * - Several action registrations (NOT through WintrustAddActionID)
811 * - Several calls to CryptSIPAddProvider
812 * - One call to CryptSIPRemoveProvider (do we need that?)
815 /* Testing on native shows that when an error is encountered in one of the CryptRegisterOIDFunction calls
816 * the rest of these calls is skipped. Registering is however continued for the trust providers.
818 * We are not totally in line with native as there all decoding functions are registered after all encoding
821 #define WINTRUST_REGISTEROID( oid, encode_funcname, decode_funcname ) \
823 if (!CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_ENCODE_OBJECT_FUNC, oid, SP_POLICY_PROVIDER_DLL_NAME, encode_funcname)) \
825 CryptRegisterRes = HRESULT_FROM_WIN32(GetLastError()); \
826 goto add_trust_providers; \
828 if (!CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_DECODE_OBJECT_FUNC, oid, SP_POLICY_PROVIDER_DLL_NAME, decode_funcname)) \
830 CryptRegisterRes = HRESULT_FROM_WIN32(GetLastError()); \
831 goto add_trust_providers; \
835 WINTRUST_REGISTEROID(SPC_PE_IMAGE_DATA_OBJID, SpcPeImageDataEncode, SpcPeImageDataDecode);
836 WINTRUST_REGISTEROID(SPC_PE_IMAGE_DATA_STRUCT, SpcPeImageDataEncode, SpcPeImageDataDecode);
837 WINTRUST_REGISTEROID(SPC_CAB_DATA_OBJID, SpcLinkEncode, SpcLinkDecode);
838 WINTRUST_REGISTEROID(SPC_CAB_DATA_STRUCT, SpcLinkEncode, SpcLinkDecode);
839 WINTRUST_REGISTEROID(SPC_JAVA_CLASS_DATA_OBJID, SpcLinkEncode, SpcLinkDecode);
840 WINTRUST_REGISTEROID(SPC_JAVA_CLASS_DATA_STRUCT, SpcLinkEncode, SpcLinkDecode);
841 WINTRUST_REGISTEROID(SPC_LINK_OBJID, SpcLinkEncode, SpcLinkDecode);
842 WINTRUST_REGISTEROID(SPC_LINK_STRUCT, SpcLinkEncode, SpcLinkDecode);
843 WINTRUST_REGISTEROID(SPC_SIGINFO_OBJID, SpcSigInfoEncode, SpcSigInfoDecode);
844 WINTRUST_REGISTEROID(SPC_SIGINFO_STRUCT, SpcSigInfoEncode, SpcSigInfoDecode);
845 WINTRUST_REGISTEROID(SPC_INDIRECT_DATA_OBJID, SpcIndirectDataContentEncode, SpcIndirectDataContentDecode);
846 WINTRUST_REGISTEROID(SPC_INDIRECT_DATA_CONTENT_STRUCT, SpcIndirectDataContentEncode, SpcIndirectDataContentDecode);
847 WINTRUST_REGISTEROID(SPC_SP_AGENCY_INFO_OBJID, SpcSpAgencyInfoEncode, SpcSpAgencyInfoDecode);
848 WINTRUST_REGISTEROID(SPC_SP_AGENCY_INFO_STRUCT, SpcSpAgencyInfoEncode, SpcSpAgencyInfoDecode);
849 WINTRUST_REGISTEROID(SPC_MINIMAL_CRITERIA_OBJID, SpcMinimalCriteriaInfoEncode, SpcMinimalCriteriaInfoDecode);
850 WINTRUST_REGISTEROID(SPC_MINIMAL_CRITERIA_STRUCT, SpcMinimalCriteriaInfoEncode, SpcMinimalCriteriaInfoDecode);
851 WINTRUST_REGISTEROID(SPC_FINANCIAL_CRITERIA_OBJID, SpcFinancialCriteriaInfoEncode, SpcFinancialCriteriaInfoDecode);
852 WINTRUST_REGISTEROID(SPC_FINANCIAL_CRITERIA_STRUCT, SpcFinancialCriteriaInfoEncode, SpcFinancialCriteriaInfoDecode);
853 WINTRUST_REGISTEROID(SPC_STATEMENT_TYPE_OBJID, SpcStatementTypeEncode, SpcStatementTypeDecode);
854 WINTRUST_REGISTEROID(SPC_STATEMENT_TYPE_STRUCT, SpcStatementTypeEncode, SpcStatementTypeDecode);
855 WINTRUST_REGISTEROID(CAT_NAMEVALUE_OBJID, CatNameValueEncode, CatNameValueDecode);
856 WINTRUST_REGISTEROID(CAT_NAMEVALUE_STRUCT, CatNameValueEncode, CatNameValueDecode);
857 WINTRUST_REGISTEROID(CAT_MEMBERINFO_OBJID, CatMemberInfoEncode, CatMemberInfoDecode);
858 WINTRUST_REGISTEROID(CAT_MEMBERINFO_STRUCT, CatMemberInfoEncode, CatMemberInfoDecode);
859 WINTRUST_REGISTEROID(SPC_SP_OPUS_INFO_OBJID, SpcSpOpusInfoEncode, SpcSpOpusInfoDecode);
860 WINTRUST_REGISTEROID(SPC_SP_OPUS_INFO_STRUCT, SpcSpOpusInfoEncode, SpcSpOpusInfoDecode);
862 #undef WINTRUST_REGISTEROID
866 /* Testing on W2K3 shows:
867 * All registry writes are tried. If one fails this part will return S_FALSE
868 * but only if the first (CryptRegisterOIDFunction calls) and the third
869 * (CryptSIPAddProvider calls) part succeed.
871 * Last error is set to the last error encountered, regardless if the first
872 * part failed or not.
875 /* Create the necessary action registry structures */
876 WINTRUST_InitRegStructs();
878 /* Register several Trust Provider actions */
879 if (!WINTRUST_RegisterGenVerifyV2())
880 TrustProviderRes = S_FALSE;
881 if (!WINTRUST_RegisterPublishedSoftware())
882 TrustProviderRes = S_FALSE;
883 if (!WINTRUST_RegisterPublishedSoftwareNoBadUi())
884 TrustProviderRes = S_FALSE;
885 if (!WINTRUST_RegisterGenCertVerify())
886 TrustProviderRes = S_FALSE;
887 if (!WINTRUST_RegisterTrustProviderTest())
888 TrustProviderRes = S_FALSE;
889 if (!WINTRUST_RegisterHttpsProv())
890 TrustProviderRes = S_FALSE;
891 if (!WINTRUST_RegisterOfficeSignVerify())
892 TrustProviderRes = S_FALSE;
893 if (!WINTRUST_RegisterDriverVerify())
894 TrustProviderRes = S_FALSE;
895 if (!WINTRUST_RegisterGenChainVerify())
896 TrustProviderRes = S_FALSE;
898 /* Free the registry structures */
899 WINTRUST_FreeRegStructs();
901 if (CryptRegisterRes == S_OK)
902 return TrustProviderRes;
904 return CryptRegisterRes;
907 /***********************************************************************
908 * DllUnregisterServer (WINTRUST.@)
910 HRESULT WINAPI DllUnregisterServer(void)
916 /***********************************************************************
917 * SoftpubDllRegisterServer (WINTRUST.@)
919 HRESULT WINAPI SoftpubDllRegisterServer(void)
925 /***********************************************************************
926 * SoftpubDllUnregisterServer (WINTRUST.@)
928 HRESULT WINAPI SoftpubDllUnregisterServer(void)
934 /***********************************************************************
935 * mscat32DllRegisterServer (WINTRUST.@)
937 HRESULT WINAPI mscat32DllRegisterServer(void)
943 /***********************************************************************
944 * mscat32DllUnregisterServer (WINTRUST.@)
946 HRESULT WINAPI mscat32DllUnregisterServer(void)
952 /***********************************************************************
953 * mssip32DllRegisterServer (WINTRUST.@)
955 HRESULT WINAPI mssip32DllRegisterServer(void)
961 /***********************************************************************
962 * mssip32DllUnregisterServer (WINTRUST.@)
964 HRESULT WINAPI mssip32DllUnregisterServer(void)