advapi32/tests: Test token label inheritance.
[wine.git] / dlls / wintrust / register.c
blob49b8ce06175b64041ad67d1ee301901146b4ac19
1 /*
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
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winerror.h"
26 #include "winuser.h"
27 #include "winreg.h"
28 #include "winnls.h"
29 #include "objbase.h"
31 #include "guiddef.h"
32 #include "wintrust.h"
33 #include "softpub.h"
34 #include "mssip.h"
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 SoftpubCertificate;
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 = wcsdup(dllname); \
96 action.pwszFunctionName = wcsdup(functionname);
98 WINTRUST_INITREGENTRY(SoftpubInitialization, SP_POLICY_PROVIDER_DLL_NAME, SP_INIT_FUNCTION)
99 WINTRUST_INITREGENTRY(SoftpubMessage, SP_POLICY_PROVIDER_DLL_NAME, SP_OBJTRUST_FUNCTION)
100 WINTRUST_INITREGENTRY(SoftpubSignature, SP_POLICY_PROVIDER_DLL_NAME, SP_SIGTRUST_FUNCTION)
101 WINTRUST_INITREGENTRY(SoftpubCertificate, SP_POLICY_PROVIDER_DLL_NAME, WT_PROVIDER_CERTTRUST_FUNCTION)
102 WINTRUST_INITREGENTRY(SoftpubCertCheck, SP_POLICY_PROVIDER_DLL_NAME, SP_CHKCERT_FUNCTION)
103 WINTRUST_INITREGENTRY(SoftpubFinalPolicy, SP_POLICY_PROVIDER_DLL_NAME, SP_FINALPOLICY_FUNCTION)
104 WINTRUST_INITREGENTRY(SoftpubCleanup, SP_POLICY_PROVIDER_DLL_NAME, SP_CLEANUPPOLICY_FUNCTION)
105 WINTRUST_INITREGENTRY(SoftpubDefCertInit, SP_POLICY_PROVIDER_DLL_NAME, SP_GENERIC_CERT_INIT_FUNCTION)
106 WINTRUST_INITREGENTRY(SoftpubDumpStructure, SP_POLICY_PROVIDER_DLL_NAME, SP_TESTDUMPPOLICY_FUNCTION_TEST)
107 WINTRUST_INITREGENTRY(HTTPSCertificateTrust, SP_POLICY_PROVIDER_DLL_NAME, HTTPS_CERTTRUST_FUNCTION)
108 WINTRUST_INITREGENTRY(HTTPSFinalProv, SP_POLICY_PROVIDER_DLL_NAME, HTTPS_FINALPOLICY_FUNCTION)
109 WINTRUST_INITREGENTRY(OfficeInitializePolicy, OFFICE_POLICY_PROVIDER_DLL_NAME, OFFICE_INITPROV_FUNCTION)
110 WINTRUST_INITREGENTRY(OfficeCleanupPolicy, OFFICE_POLICY_PROVIDER_DLL_NAME, OFFICE_CLEANUPPOLICY_FUNCTION)
111 WINTRUST_INITREGENTRY(DriverInitializePolicy, SP_POLICY_PROVIDER_DLL_NAME, DRIVER_INITPROV_FUNCTION)
112 WINTRUST_INITREGENTRY(DriverFinalPolicy, SP_POLICY_PROVIDER_DLL_NAME, DRIVER_FINALPOLPROV_FUNCTION)
113 WINTRUST_INITREGENTRY(DriverCleanupPolicy, SP_POLICY_PROVIDER_DLL_NAME, DRIVER_CLEANUPPOLICY_FUNCTION)
114 WINTRUST_INITREGENTRY(GenericChainCertificateTrust, SP_POLICY_PROVIDER_DLL_NAME, GENERIC_CHAIN_CERTTRUST_FUNCTION)
115 WINTRUST_INITREGENTRY(GenericChainFinalProv, SP_POLICY_PROVIDER_DLL_NAME, GENERIC_CHAIN_FINALPOLICY_FUNCTION)
117 #undef WINTRUST_INITREGENTRY
120 /***********************************************************************
121 * WINTRUST_FreeRegStructs
123 * Helper function to free 2 members of the CRYPT_TRUST_REG_ENTRY
124 * structs.
126 static void WINTRUST_FreeRegStructs(void)
128 #define WINTRUST_FREEREGENTRY( action ) \
129 free(action.pwszDLLName); \
130 free(action.pwszFunctionName);
132 WINTRUST_FREEREGENTRY(SoftpubInitialization);
133 WINTRUST_FREEREGENTRY(SoftpubMessage);
134 WINTRUST_FREEREGENTRY(SoftpubSignature);
135 WINTRUST_FREEREGENTRY(SoftpubCertificate);
136 WINTRUST_FREEREGENTRY(SoftpubCertCheck);
137 WINTRUST_FREEREGENTRY(SoftpubFinalPolicy);
138 WINTRUST_FREEREGENTRY(SoftpubCleanup);
139 WINTRUST_FREEREGENTRY(SoftpubDefCertInit);
140 WINTRUST_FREEREGENTRY(SoftpubDumpStructure);
141 WINTRUST_FREEREGENTRY(HTTPSCertificateTrust);
142 WINTRUST_FREEREGENTRY(HTTPSFinalProv);
143 WINTRUST_FREEREGENTRY(OfficeInitializePolicy);
144 WINTRUST_FREEREGENTRY(OfficeCleanupPolicy);
145 WINTRUST_FREEREGENTRY(DriverInitializePolicy);
146 WINTRUST_FREEREGENTRY(DriverFinalPolicy);
147 WINTRUST_FREEREGENTRY(DriverCleanupPolicy);
148 WINTRUST_FREEREGENTRY(GenericChainCertificateTrust);
149 WINTRUST_FREEREGENTRY(GenericChainFinalProv);
151 #undef WINTRUST_FREEREGENTRY
154 /***********************************************************************
155 * WINTRUST_guid2wstr
157 * Create a wide-string from a GUID
160 static void WINTRUST_Guid2Wstr(const GUID* pgActionID, WCHAR* GuidString)
162 static const WCHAR wszFormat[] = {'{','%','0','8','l','X','-','%','0','4','X','-','%','0','4','X','-',
163 '%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2',
164 'X','%','0','2','X','%','0','2','X','}', 0};
166 wsprintfW(GuidString, wszFormat, pgActionID->Data1, pgActionID->Data2, pgActionID->Data3,
167 pgActionID->Data4[0], pgActionID->Data4[1], pgActionID->Data4[2], pgActionID->Data4[3],
168 pgActionID->Data4[4], pgActionID->Data4[5], pgActionID->Data4[6], pgActionID->Data4[7]);
171 /***********************************************************************
172 * WINTRUST_WriteProviderToReg
174 * Helper function for WintrustAddActionID
177 static LONG WINTRUST_WriteProviderToReg(WCHAR* GuidString,
178 const WCHAR* FunctionType,
179 CRYPT_TRUST_REG_ENTRY RegEntry)
181 static const WCHAR Function[] = {'$','F','u','n','c','t','i','o','n', 0};
182 WCHAR ProvKey[MAX_PATH];
183 HKEY Key;
184 LONG Res = ERROR_SUCCESS;
186 /* Create the needed key string */
187 ProvKey[0]='\0';
188 lstrcatW(ProvKey, Trust);
189 lstrcatW(ProvKey, FunctionType);
190 lstrcatW(ProvKey, GuidString);
192 if (!RegEntry.pwszDLLName || !RegEntry.pwszFunctionName)
193 return ERROR_INVALID_PARAMETER;
195 Res = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ProvKey, 0, NULL, 0, KEY_WRITE, NULL, &Key, NULL);
196 if (Res != ERROR_SUCCESS) goto error_close_key;
198 /* Create the $DLL entry */
199 Res = RegSetValueExW(Key, Dll, 0, REG_SZ, (BYTE*)RegEntry.pwszDLLName,
200 (lstrlenW(RegEntry.pwszDLLName) + 1)*sizeof(WCHAR));
201 if (Res != ERROR_SUCCESS) goto error_close_key;
203 /* Create the $Function entry */
204 Res = RegSetValueExW(Key, Function, 0, REG_SZ, (BYTE*)RegEntry.pwszFunctionName,
205 (lstrlenW(RegEntry.pwszFunctionName) + 1)*sizeof(WCHAR));
207 error_close_key:
208 RegCloseKey(Key);
210 return Res;
213 /***********************************************************************
214 * WintrustAddActionID (WINTRUST.@)
216 * Add the definitions of the actions a Trust provider can perform to
217 * the registry.
219 * PARAMS
220 * pgActionID [I] Pointer to a GUID for the Trust provider.
221 * fdwFlags [I] Flag to indicate whether registry errors are passed on.
222 * psProvInfo [I] Pointer to a structure with information about DLL
223 * name and functions.
225 * RETURNS
226 * Success: TRUE.
227 * Failure: FALSE. (Use GetLastError() for more information)
229 * NOTES
230 * Adding definitions is basically only adding relevant information
231 * to the registry. No verification takes place whether a DLL or its
232 * entrypoints exist.
233 * Information in the registry will always be overwritten.
236 BOOL WINAPI WintrustAddActionID( GUID* pgActionID, DWORD fdwFlags,
237 CRYPT_REGISTER_ACTIONID* psProvInfo)
239 WCHAR GuidString[39];
240 LONG Res;
241 LONG WriteActionError = ERROR_SUCCESS;
243 TRACE("%s %lx %p\n", debugstr_guid(pgActionID), fdwFlags, psProvInfo);
245 /* Some sanity checks.
246 * We use the W2K3 last error as it makes more sense (W2K leaves the last error
247 * as is).
249 if (!pgActionID ||
250 !psProvInfo ||
251 (psProvInfo->cbStruct != sizeof(CRYPT_REGISTER_ACTIONID)))
253 SetLastError(ERROR_INVALID_PARAMETER);
254 return FALSE;
257 /* Create this string only once, instead of in the helper function */
258 WINTRUST_Guid2Wstr( pgActionID, GuidString);
260 /* Write the information to the registry */
261 Res = WINTRUST_WriteProviderToReg(GuidString, Initialization , psProvInfo->sInitProvider);
262 if (Res != ERROR_SUCCESS) WriteActionError = Res;
263 Res = WINTRUST_WriteProviderToReg(GuidString, Message , psProvInfo->sObjectProvider);
264 if (Res != ERROR_SUCCESS) WriteActionError = Res;
265 Res = WINTRUST_WriteProviderToReg(GuidString, Signature , psProvInfo->sSignatureProvider);
266 if (Res != ERROR_SUCCESS) WriteActionError = Res;
267 Res = WINTRUST_WriteProviderToReg(GuidString, Certificate , psProvInfo->sCertificateProvider);
268 if (Res != ERROR_SUCCESS) WriteActionError = Res;
269 Res = WINTRUST_WriteProviderToReg(GuidString, CertCheck , psProvInfo->sCertificatePolicyProvider);
270 if (Res != ERROR_SUCCESS) WriteActionError = Res;
271 Res = WINTRUST_WriteProviderToReg(GuidString, FinalPolicy , psProvInfo->sFinalPolicyProvider);
272 if (Res != ERROR_SUCCESS) WriteActionError = Res;
273 Res = WINTRUST_WriteProviderToReg(GuidString, DiagnosticPolicy, psProvInfo->sTestPolicyProvider);
274 if (Res != ERROR_SUCCESS) WriteActionError = Res;
275 Res = WINTRUST_WriteProviderToReg(GuidString, Cleanup , psProvInfo->sCleanupProvider);
276 if (Res != ERROR_SUCCESS) WriteActionError = Res;
278 /* Testing (by restricting access to the registry for some keys) shows that the last failing function
279 * will be used for last error.
280 * If the flag WT_ADD_ACTION_ID_RET_RESULT_FLAG is set and there are errors when adding the action
281 * we have to return FALSE. Errors includes both invalid entries as well as registry errors.
282 * Testing also showed that one error doesn't stop the registry writes. Every action will be dealt with.
285 if (WriteActionError != ERROR_SUCCESS)
287 SetLastError(WriteActionError);
289 if (fdwFlags == WT_ADD_ACTION_ID_RET_RESULT_FLAG)
290 return FALSE;
293 return TRUE;
296 /***********************************************************************
297 * WINTRUST_RemoveProviderFromReg
299 * Helper function for WintrustRemoveActionID
302 static void WINTRUST_RemoveProviderFromReg(WCHAR* GuidString,
303 const WCHAR* FunctionType)
305 WCHAR ProvKey[MAX_PATH];
307 /* Create the needed key string */
308 ProvKey[0]='\0';
309 lstrcatW(ProvKey, Trust);
310 lstrcatW(ProvKey, FunctionType);
311 lstrcatW(ProvKey, GuidString);
313 /* We don't care about success or failure */
314 RegDeleteKeyW(HKEY_LOCAL_MACHINE, ProvKey);
317 /***********************************************************************
318 * WintrustRemoveActionID (WINTRUST.@)
320 * Remove the definitions of the actions a Trust provider can perform
321 * from the registry.
323 * PARAMS
324 * pgActionID [I] Pointer to a GUID for the Trust provider.
326 * RETURNS
327 * Success: TRUE. (Use GetLastError() for more information)
328 * Failure: FALSE. (Use GetLastError() for more information)
330 * NOTES
331 * Testing shows that WintrustRemoveActionID always returns TRUE and
332 * that a possible error should be retrieved via GetLastError().
333 * There are no checks if the definitions are in the registry.
335 BOOL WINAPI WintrustRemoveActionID( GUID* pgActionID )
337 WCHAR GuidString[39];
339 TRACE("(%s)\n", debugstr_guid(pgActionID));
341 if (!pgActionID)
343 SetLastError(ERROR_INVALID_PARAMETER);
344 return TRUE;
347 /* Create this string only once, instead of in the helper function */
348 WINTRUST_Guid2Wstr( pgActionID, GuidString);
350 /* We don't care about success or failure */
351 WINTRUST_RemoveProviderFromReg(GuidString, Initialization);
352 WINTRUST_RemoveProviderFromReg(GuidString, Message);
353 WINTRUST_RemoveProviderFromReg(GuidString, Signature);
354 WINTRUST_RemoveProviderFromReg(GuidString, Certificate);
355 WINTRUST_RemoveProviderFromReg(GuidString, CertCheck);
356 WINTRUST_RemoveProviderFromReg(GuidString, FinalPolicy);
357 WINTRUST_RemoveProviderFromReg(GuidString, DiagnosticPolicy);
358 WINTRUST_RemoveProviderFromReg(GuidString, Cleanup);
360 return TRUE;
363 /***********************************************************************
364 * WINTRUST_WriteSingleUsageEntry
366 * Helper for WintrustAddDefaultForUsage, writes a single value and its
367 * data to:
369 * HKLM\Software\Microsoft\Cryptography\Trust\Usages\<OID>
371 static LONG WINTRUST_WriteSingleUsageEntry(LPCSTR OID,
372 const WCHAR* Value,
373 WCHAR* Data)
375 static const WCHAR Usages[] = {'U','s','a','g','e','s','\\', 0};
376 WCHAR* UsageKey;
377 HKEY Key;
378 LONG Res = ERROR_SUCCESS;
379 WCHAR* OIDW;
380 DWORD Len;
382 /* Turn OID into a wide-character string */
383 Len = MultiByteToWideChar( CP_ACP, 0, OID, -1, NULL, 0 );
384 OIDW = malloc( Len * sizeof(WCHAR) );
385 MultiByteToWideChar( CP_ACP, 0, OID, -1, OIDW, Len );
387 /* Allocate the needed space for UsageKey */
388 UsageKey = malloc((wcslen(Trust) + wcslen(Usages) + Len) * sizeof(WCHAR));
389 /* Create the key string */
390 lstrcpyW(UsageKey, Trust);
391 lstrcatW(UsageKey, Usages);
392 lstrcatW(UsageKey, OIDW);
394 Res = RegCreateKeyExW(HKEY_LOCAL_MACHINE, UsageKey, 0, NULL, 0, KEY_WRITE, NULL, &Key, NULL);
395 if (Res == ERROR_SUCCESS)
397 /* Create the Value entry */
398 Res = RegSetValueExW(Key, Value, 0, REG_SZ, (BYTE*)Data,
399 (lstrlenW(Data) + 1)*sizeof(WCHAR));
401 RegCloseKey(Key);
403 free(OIDW);
404 free(UsageKey);
406 return Res;
409 /***************************************************************************
410 * WINTRUST_RegisterGenVerifyV2
412 * Register WINTRUST_ACTION_GENERIC_VERIFY_V2 actions and usages.
414 * NOTES
415 * WINTRUST_ACTION_GENERIC_VERIFY_V2 ({00AAC56B-CD44-11D0-8CC2-00C04FC295EE}
416 * is defined in softpub.h
418 static BOOL WINTRUST_RegisterGenVerifyV2(void)
420 BOOL RegisteredOK = TRUE;
421 static GUID ProvGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2;
422 CRYPT_REGISTER_ACTIONID ProvInfo;
423 CRYPT_PROVIDER_REGDEFUSAGE DefUsage = { sizeof(CRYPT_PROVIDER_REGDEFUSAGE),
424 &ProvGUID,
425 NULL, /* No Dll provided */
426 NULL, /* No load callback function */
427 NULL }; /* No free callback function */
429 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
430 ProvInfo.sInitProvider = SoftpubInitialization;
431 ProvInfo.sObjectProvider = SoftpubMessage;
432 ProvInfo.sSignatureProvider = SoftpubSignature;
433 ProvInfo.sCertificateProvider = SoftpubCertificate;
434 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
435 ProvInfo.sFinalPolicyProvider = SoftpubFinalPolicy;
436 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
437 ProvInfo.sCleanupProvider = SoftpubCleanup;
439 if (!WintrustAddDefaultForUsage(szOID_PKIX_KP_CODE_SIGNING, &DefUsage))
440 RegisteredOK = FALSE;
442 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
443 RegisteredOK = FALSE;
445 return RegisteredOK;
448 /***************************************************************************
449 * WINTRUST_RegisterPublishedSoftware
451 * Register WIN_SPUB_ACTION_PUBLISHED_SOFTWARE actions and usages.
453 * NOTES
454 * WIN_SPUB_ACTION_PUBLISHED_SOFTWARE ({64B9D180-8DA2-11CF-8736-00AA00A485EB})
455 * is defined in wintrust.h
457 static BOOL WINTRUST_RegisterPublishedSoftware(void)
459 static GUID ProvGUID = WIN_SPUB_ACTION_PUBLISHED_SOFTWARE;
460 CRYPT_REGISTER_ACTIONID ProvInfo;
462 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
463 ProvInfo.sInitProvider = SoftpubInitialization;
464 ProvInfo.sObjectProvider = SoftpubMessage;
465 ProvInfo.sSignatureProvider = SoftpubSignature;
466 ProvInfo.sCertificateProvider = SoftpubCertificate;
467 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
468 ProvInfo.sFinalPolicyProvider = SoftpubFinalPolicy;
469 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
470 ProvInfo.sCleanupProvider = SoftpubCleanup;
472 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
473 return FALSE;
475 return TRUE;
478 #define WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI { 0xc6b2e8d0, 0xe005, 0x11cf, { 0xa1,0x34,0x00,0xc0,0x4f,0xd7,0xbf,0x43 }}
480 /***************************************************************************
481 * WINTRUST_RegisterPublishedSoftwareNoBadUi
483 * Register WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI actions and usages.
485 * NOTES
486 * WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI ({C6B2E8D0-E005-11CF-A134-00C04FD7BF43})
487 * is not defined in any include file. (FIXME: Find out if the name is correct).
489 static BOOL WINTRUST_RegisterPublishedSoftwareNoBadUi(void)
491 static GUID ProvGUID = WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI;
492 CRYPT_REGISTER_ACTIONID ProvInfo;
494 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
495 ProvInfo.sInitProvider = SoftpubInitialization;
496 ProvInfo.sObjectProvider = SoftpubMessage;
497 ProvInfo.sSignatureProvider = SoftpubSignature;
498 ProvInfo.sCertificateProvider = SoftpubCertificate;
499 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
500 ProvInfo.sFinalPolicyProvider = SoftpubFinalPolicy;
501 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
502 ProvInfo.sCleanupProvider = SoftpubCleanup;
504 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
505 return FALSE;
507 return TRUE;
510 /***************************************************************************
511 * WINTRUST_RegisterGenCertVerify
513 * Register WINTRUST_ACTION_GENERIC_CERT_VERIFY actions and usages.
515 * NOTES
516 * WINTRUST_ACTION_GENERIC_CERT_VERIFY ({189A3842-3041-11D1-85E1-00C04FC295EE})
517 * is defined in softpub.h
519 static BOOL WINTRUST_RegisterGenCertVerify(void)
521 static GUID ProvGUID = WINTRUST_ACTION_GENERIC_CERT_VERIFY;
522 CRYPT_REGISTER_ACTIONID ProvInfo;
524 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
525 ProvInfo.sInitProvider = SoftpubDefCertInit;
526 ProvInfo.sObjectProvider = SoftpubMessage;
527 ProvInfo.sSignatureProvider = SoftpubSignature;
528 ProvInfo.sCertificateProvider = SoftpubCertificate;
529 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
530 ProvInfo.sFinalPolicyProvider = SoftpubFinalPolicy;
531 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
532 ProvInfo.sCleanupProvider = SoftpubCleanup;
534 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
535 return FALSE;
537 return TRUE;
540 /***************************************************************************
541 * WINTRUST_RegisterTrustProviderTest
543 * Register WINTRUST_ACTION_TRUSTPROVIDER_TEST actions and usages.
545 * NOTES
546 * WINTRUST_ACTION_TRUSTPROVIDER_TEST ({573E31F8-DDBA-11D0-8CCB-00C04FC295EE})
547 * is defined in softpub.h
549 static BOOL WINTRUST_RegisterTrustProviderTest(void)
551 static GUID ProvGUID = WINTRUST_ACTION_TRUSTPROVIDER_TEST;
552 CRYPT_REGISTER_ACTIONID ProvInfo;
554 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
555 ProvInfo.sInitProvider = SoftpubInitialization;
556 ProvInfo.sObjectProvider = SoftpubMessage;
557 ProvInfo.sSignatureProvider = SoftpubSignature;
558 ProvInfo.sCertificateProvider = SoftpubCertificate;
559 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
560 ProvInfo.sFinalPolicyProvider = SoftpubFinalPolicy;
561 ProvInfo.sTestPolicyProvider = SoftpubDumpStructure;
562 ProvInfo.sCleanupProvider = SoftpubCleanup;
564 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
565 return FALSE;
567 return TRUE;
570 /***************************************************************************
571 * WINTRUST_RegisterHttpsProv
573 * Register HTTPSPROV_ACTION actions and usages.
575 * NOTES
576 * HTTPSPROV_ACTION ({573E31F8-AABA-11D0-8CCB-00C04FC295EE})
577 * is defined in softpub.h
579 static BOOL WINTRUST_RegisterHttpsProv(void)
581 BOOL RegisteredOK = TRUE;
582 static CHAR SoftpubLoadUsage[] = "SoftpubLoadDefUsageCallData";
583 static CHAR SoftpubFreeUsage[] = "SoftpubFreeDefUsageCallData";
584 static GUID ProvGUID = HTTPSPROV_ACTION;
585 CRYPT_REGISTER_ACTIONID ProvInfo;
586 CRYPT_PROVIDER_REGDEFUSAGE DefUsage = { sizeof(CRYPT_PROVIDER_REGDEFUSAGE),
587 &ProvGUID,
588 NULL, /* Will be filled later */
589 SoftpubLoadUsage,
590 SoftpubFreeUsage };
592 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
593 ProvInfo.sInitProvider = SoftpubInitialization;
594 ProvInfo.sObjectProvider = SoftpubMessage;
595 ProvInfo.sSignatureProvider = SoftpubSignature;
596 ProvInfo.sCertificateProvider = HTTPSCertificateTrust;
597 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
598 ProvInfo.sFinalPolicyProvider = HTTPSFinalProv;
599 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
600 ProvInfo.sCleanupProvider = SoftpubCleanup;
602 DefUsage.pwszDllName = wcsdup(SP_POLICY_PROVIDER_DLL_NAME);
604 if (!WintrustAddDefaultForUsage(szOID_PKIX_KP_SERVER_AUTH, &DefUsage))
605 RegisteredOK = FALSE;
606 if (!WintrustAddDefaultForUsage(szOID_PKIX_KP_CLIENT_AUTH, &DefUsage))
607 RegisteredOK = FALSE;
608 if (!WintrustAddDefaultForUsage(szOID_SERVER_GATED_CRYPTO, &DefUsage))
609 RegisteredOK = FALSE;
610 if (!WintrustAddDefaultForUsage(szOID_SGC_NETSCAPE, &DefUsage))
611 RegisteredOK = FALSE;
613 free(DefUsage.pwszDllName);
615 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
616 RegisteredOK = FALSE;
618 return RegisteredOK;
621 /***************************************************************************
622 * WINTRUST_RegisterOfficeSignVerify
624 * Register OFFICESIGN_ACTION_VERIFY actions and usages.
626 * NOTES
627 * OFFICESIGN_ACTION_VERIFY ({5555C2CD-17FB-11D1-85C4-00C04FC295EE})
628 * is defined in softpub.h
630 static BOOL WINTRUST_RegisterOfficeSignVerify(void)
632 static GUID ProvGUID = OFFICESIGN_ACTION_VERIFY;
633 CRYPT_REGISTER_ACTIONID ProvInfo;
635 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
636 ProvInfo.sInitProvider = OfficeInitializePolicy;
637 ProvInfo.sObjectProvider = SoftpubMessage;
638 ProvInfo.sSignatureProvider = SoftpubSignature;
639 ProvInfo.sCertificateProvider = SoftpubCertificate;
640 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
641 ProvInfo.sFinalPolicyProvider = SoftpubFinalPolicy;
642 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
643 ProvInfo.sCleanupProvider = OfficeCleanupPolicy;
646 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
647 return FALSE;
649 return TRUE;
652 /***************************************************************************
653 * WINTRUST_RegisterDriverVerify
655 * Register DRIVER_ACTION_VERIFY actions and usages.
657 * NOTES
658 * DRIVER_ACTION_VERIFY ({F750E6C3-38EE-11D1-85E5-00C04FC295EE})
659 * is defined in softpub.h
661 static BOOL WINTRUST_RegisterDriverVerify(void)
663 static GUID ProvGUID = DRIVER_ACTION_VERIFY;
664 CRYPT_REGISTER_ACTIONID ProvInfo;
666 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
667 ProvInfo.sInitProvider = DriverInitializePolicy;
668 ProvInfo.sObjectProvider = SoftpubMessage;
669 ProvInfo.sSignatureProvider = SoftpubSignature;
670 ProvInfo.sCertificateProvider = SoftpubCertificate;
671 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
672 ProvInfo.sFinalPolicyProvider = DriverFinalPolicy;
673 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
674 ProvInfo.sCleanupProvider = DriverCleanupPolicy;
677 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
678 return FALSE;
680 return TRUE;
683 /***************************************************************************
684 * WINTRUST_RegisterGenChainVerify
686 * Register WINTRUST_ACTION_GENERIC_CHAIN_VERIFY actions and usages.
688 * NOTES
689 * WINTRUST_ACTION_GENERIC_CHAIN_VERIFY ({FC451C16-AC75-11D1-B4B8-00C04FB66EA0})
690 * is defined in softpub.h
692 static BOOL WINTRUST_RegisterGenChainVerify(void)
694 static GUID ProvGUID = WINTRUST_ACTION_GENERIC_CHAIN_VERIFY;
695 CRYPT_REGISTER_ACTIONID ProvInfo;
697 ProvInfo.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
698 ProvInfo.sInitProvider = SoftpubInitialization;
699 ProvInfo.sObjectProvider = SoftpubMessage;
700 ProvInfo.sSignatureProvider = SoftpubSignature;
701 ProvInfo.sCertificateProvider = GenericChainCertificateTrust;
702 ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
703 ProvInfo.sFinalPolicyProvider = GenericChainFinalProv;
704 ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
705 ProvInfo.sCleanupProvider = SoftpubCleanup;
707 if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
708 return FALSE;
710 return TRUE;
713 /***********************************************************************
714 * WintrustAddDefaultForUsage (WINTRUST.@)
716 * Write OID and callback functions to the registry.
718 * PARAMS
719 * pszUsageOID [I] Pointer to a GUID.
720 * psDefUsage [I] Pointer to a structure that specifies the callback functions.
722 * RETURNS
723 * Success: TRUE.
724 * Failure: FALSE.
726 * NOTES
727 * WintrustAddDefaultForUsage will only return TRUE or FALSE, no last
728 * error is set, not even when the registry cannot be written to.
730 BOOL WINAPI WintrustAddDefaultForUsage(const char *pszUsageOID,
731 CRYPT_PROVIDER_REGDEFUSAGE *psDefUsage)
733 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};
734 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};
735 LONG Res = ERROR_SUCCESS;
736 LONG WriteUsageError = ERROR_SUCCESS;
737 DWORD Len;
738 WCHAR GuidString[39];
740 TRACE("(%s %p)\n", debugstr_a(pszUsageOID), psDefUsage);
742 /* Some sanity checks. */
743 if (!pszUsageOID ||
744 !psDefUsage ||
745 !psDefUsage->pgActionID ||
746 (psDefUsage->cbStruct != sizeof(CRYPT_PROVIDER_REGDEFUSAGE)))
748 SetLastError(ERROR_INVALID_PARAMETER);
749 return FALSE;
752 if (psDefUsage->pwszDllName)
754 Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, Dll, psDefUsage->pwszDllName);
755 if (Res != ERROR_SUCCESS) WriteUsageError = Res;
757 if (psDefUsage->pwszLoadCallbackDataFunctionName)
759 WCHAR* CallbackW;
761 Len = MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszLoadCallbackDataFunctionName, -1, NULL, 0 );
762 CallbackW = malloc( Len * sizeof(WCHAR) );
763 MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszLoadCallbackDataFunctionName, -1, CallbackW, Len );
765 Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, CBAlloc, CallbackW);
766 if (Res != ERROR_SUCCESS) WriteUsageError = Res;
768 free(CallbackW);
770 if (psDefUsage->pwszFreeCallbackDataFunctionName)
772 WCHAR* CallbackW;
774 Len = MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszFreeCallbackDataFunctionName, -1, NULL, 0 );
775 CallbackW = malloc( Len * sizeof(WCHAR) );
776 MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszFreeCallbackDataFunctionName, -1, CallbackW, Len );
778 Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, CBFree, CallbackW);
779 if (Res != ERROR_SUCCESS) WriteUsageError = Res;
781 free(CallbackW);
784 WINTRUST_Guid2Wstr(psDefUsage->pgActionID, GuidString);
785 Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, DefaultId, GuidString);
786 if (Res != ERROR_SUCCESS) WriteUsageError = Res;
788 if (WriteUsageError != ERROR_SUCCESS)
789 return FALSE;
791 return TRUE;
794 static FARPROC WINTRUST_ReadProviderFromReg(WCHAR *GuidString, const WCHAR *FunctionType)
796 WCHAR ProvKey[MAX_PATH], DllName[MAX_PATH];
797 char FunctionName[MAX_PATH];
798 HKEY Key;
799 LONG Res = ERROR_SUCCESS;
800 DWORD Size;
801 HMODULE Lib;
802 FARPROC Func = NULL;
804 /* Create the needed key string */
805 ProvKey[0]='\0';
806 lstrcatW(ProvKey, Trust);
807 lstrcatW(ProvKey, FunctionType);
808 lstrcatW(ProvKey, GuidString);
810 Res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, ProvKey, 0, KEY_READ, &Key);
811 if (Res != ERROR_SUCCESS) return NULL;
813 /* Read the $DLL entry */
814 Size = sizeof(DllName);
815 Res = RegQueryValueExW(Key, Dll, NULL, NULL, (LPBYTE)DllName, &Size);
816 if (Res != ERROR_SUCCESS) goto error_close_key;
818 /* Read the $Function entry */
819 Size = sizeof(FunctionName);
820 Res = RegQueryValueExA(Key, "$Function", NULL, NULL, (LPBYTE)FunctionName, &Size);
821 if (Res != ERROR_SUCCESS) goto error_close_key;
823 /* Load the library - there appears to be no way to close a provider, so
824 * just leak the module handle.
826 Lib = LoadLibraryW(DllName);
827 Func = GetProcAddress(Lib, FunctionName);
829 error_close_key:
830 RegCloseKey(Key);
832 return Func;
835 static CRITICAL_SECTION cache_cs;
836 static CRITICAL_SECTION_DEBUG cache_cs_debug =
838 0, 0, &cache_cs,
839 { &cache_cs_debug.ProcessLocksList, &cache_cs_debug.ProcessLocksList },
840 0, 0, { (DWORD_PTR)(__FILE__ ": cache_cs") }
842 static CRITICAL_SECTION cache_cs = { &cache_cs_debug, -1, 0, 0, 0, 0 };
844 static struct provider_cache_entry
846 GUID guid;
847 CRYPT_PROVIDER_FUNCTIONS provider_functions;
849 *provider_cache;
850 static unsigned int provider_cache_size;
852 static void * WINAPI WINTRUST_Alloc(DWORD cb)
854 return calloc(1, cb);
857 static void WINAPI WINTRUST_Free(void *p)
859 free(p);
862 /***********************************************************************
863 * WintrustLoadFunctionPointers (WINTRUST.@)
865 BOOL WINAPI WintrustLoadFunctionPointers( GUID* pgActionID,
866 CRYPT_PROVIDER_FUNCTIONS* pPfns )
868 WCHAR GuidString[39];
869 BOOL cached = FALSE;
870 unsigned int i;
872 TRACE("(%s %p)\n", debugstr_guid(pgActionID), pPfns);
874 if (!pPfns) return FALSE;
875 if (!pgActionID)
877 SetLastError(ERROR_INVALID_PARAMETER);
878 return FALSE;
880 if (pPfns->cbStruct != sizeof(CRYPT_PROVIDER_FUNCTIONS)) return FALSE;
882 EnterCriticalSection( &cache_cs );
883 for (i = 0; i < provider_cache_size; ++i)
885 if (IsEqualGUID( &provider_cache[i].guid, pgActionID ))
887 TRACE( "Using cached data.\n" );
888 *pPfns = provider_cache[i].provider_functions;
889 cached = TRUE;
890 break;
893 LeaveCriticalSection( &cache_cs );
894 if (cached) return TRUE;
896 /* Create this string only once, instead of in the helper function */
897 WINTRUST_Guid2Wstr( pgActionID, GuidString);
899 /* Get the function pointers from the registry, where applicable */
900 pPfns->pfnAlloc = WINTRUST_Alloc;
901 pPfns->pfnFree = WINTRUST_Free;
902 pPfns->pfnAddStore2Chain = WINTRUST_AddStore;
903 pPfns->pfnAddSgnr2Chain = WINTRUST_AddSgnr;
904 pPfns->pfnAddCert2Chain = WINTRUST_AddCert;
905 pPfns->pfnAddPrivData2Chain = WINTRUST_AddPrivData;
906 pPfns->psUIpfns = NULL;
907 pPfns->pfnInitialize = (PFN_PROVIDER_INIT_CALL)WINTRUST_ReadProviderFromReg(GuidString, Initialization);
908 pPfns->pfnObjectTrust = (PFN_PROVIDER_OBJTRUST_CALL)WINTRUST_ReadProviderFromReg(GuidString, Message);
909 pPfns->pfnSignatureTrust = (PFN_PROVIDER_SIGTRUST_CALL)WINTRUST_ReadProviderFromReg(GuidString, Signature);
910 pPfns->pfnCertificateTrust = (PFN_PROVIDER_CERTTRUST_CALL)WINTRUST_ReadProviderFromReg(GuidString, Certificate);
911 pPfns->pfnCertCheckPolicy = (PFN_PROVIDER_CERTCHKPOLICY_CALL)WINTRUST_ReadProviderFromReg(GuidString, CertCheck);
912 pPfns->pfnFinalPolicy = (PFN_PROVIDER_FINALPOLICY_CALL)WINTRUST_ReadProviderFromReg(GuidString, FinalPolicy);
913 pPfns->pfnTestFinalPolicy = (PFN_PROVIDER_TESTFINALPOLICY_CALL)WINTRUST_ReadProviderFromReg(GuidString, DiagnosticPolicy);
914 pPfns->pfnCleanupPolicy = (PFN_PROVIDER_CLEANUP_CALL)WINTRUST_ReadProviderFromReg(GuidString, Cleanup);
916 EnterCriticalSection( &cache_cs );
917 for (i = 0; i < provider_cache_size; ++i)
918 if (IsEqualGUID( &provider_cache[i].guid, pgActionID )) break;
920 if (i == provider_cache_size)
922 struct provider_cache_entry *new;
924 new = realloc( provider_cache, (provider_cache_size + 1) * sizeof(*new) );
925 if (new)
927 provider_cache = new;
928 provider_cache[provider_cache_size].guid = *pgActionID;
929 provider_cache[provider_cache_size].provider_functions = *pPfns;
930 ++provider_cache_size;
933 LeaveCriticalSection( &cache_cs );
935 return TRUE;
938 /***********************************************************************
939 * WINTRUST_SIPPAddProvider
941 * Helper for DllRegisterServer.
943 static BOOL WINTRUST_SIPPAddProvider(GUID* Subject, WCHAR* MagicNumber)
945 static WCHAR CryptSIPGetSignedDataMsg[] =
946 {'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};
947 static WCHAR CryptSIPPutSignedDataMsg[] =
948 {'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};
949 static WCHAR CryptSIPCreateIndirectData[] =
950 {'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};
951 static WCHAR CryptSIPVerifyIndirectData[] =
952 {'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};
953 static WCHAR CryptSIPRemoveSignedDataMsg[] =
954 {'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};
955 SIP_ADD_NEWPROVIDER NewProv;
956 BOOL Ret;
958 /* Clear and initialize the structure */
959 memset(&NewProv, 0, sizeof(SIP_ADD_NEWPROVIDER));
960 NewProv.cbStruct = sizeof(SIP_ADD_NEWPROVIDER);
961 NewProv.pwszDLLFileName = wcsdup(SP_POLICY_PROVIDER_DLL_NAME);
962 /* Fill the structure */
963 NewProv.pgSubject = Subject;
964 NewProv.pwszMagicNumber = MagicNumber;
965 NewProv.pwszIsFunctionName = NULL;
966 NewProv.pwszGetFuncName = CryptSIPGetSignedDataMsg;
967 NewProv.pwszPutFuncName = CryptSIPPutSignedDataMsg;
968 NewProv.pwszCreateFuncName = CryptSIPCreateIndirectData;
969 NewProv.pwszVerifyFuncName = CryptSIPVerifyIndirectData;
970 NewProv.pwszRemoveFuncName = CryptSIPRemoveSignedDataMsg;
971 NewProv.pwszIsFunctionNameFmt2 = NULL;
972 NewProv.pwszGetCapFuncName = NULL;
974 Ret = CryptSIPAddProvider(&NewProv);
976 free(NewProv.pwszDLLFileName);
978 return Ret;
981 /***********************************************************************
982 * DllRegisterServer (WINTRUST.@)
984 HRESULT WINAPI DllRegisterServer(void)
986 static const CHAR SpcPeImageDataEncode[] = "WVTAsn1SpcPeImageDataEncode";
987 static const CHAR SpcPeImageDataDecode[] = "WVTAsn1SpcPeImageDataDecode";
988 static const CHAR SpcLinkEncode[] = "WVTAsn1SpcLinkEncode";
989 static const CHAR SpcLinkDecode[] = "WVTAsn1SpcLinkDecode";
990 static const CHAR SpcSigInfoEncode[] = "WVTAsn1SpcSigInfoEncode";
991 static const CHAR SpcSigInfoDecode[] = "WVTAsn1SpcSigInfoDecode";
992 static const CHAR SpcIndirectDataContentEncode[] = "WVTAsn1SpcIndirectDataContentEncode";
993 static const CHAR SpcIndirectDataContentDecode[] = "WVTAsn1SpcIndirectDataContentDecode";
994 static const CHAR SpcSpAgencyInfoEncode[] = "WVTAsn1SpcSpAgencyInfoEncode";
995 static const CHAR SpcSpAgencyInfoDecode[] = "WVTAsn1SpcSpAgencyInfoDecode";
996 static const CHAR SpcMinimalCriteriaInfoEncode[] = "WVTAsn1SpcMinimalCriteriaInfoEncode";
997 static const CHAR SpcMinimalCriteriaInfoDecode[] = "WVTAsn1SpcMinimalCriteriaInfoDecode";
998 static const CHAR SpcFinancialCriteriaInfoEncode[] = "WVTAsn1SpcFinancialCriteriaInfoEncode";
999 static const CHAR SpcFinancialCriteriaInfoDecode[] = "WVTAsn1SpcFinancialCriteriaInfoDecode";
1000 static const CHAR SpcStatementTypeEncode[] = "WVTAsn1SpcStatementTypeEncode";
1001 static const CHAR SpcStatementTypeDecode[] = "WVTAsn1SpcStatementTypeDecode";
1002 static const CHAR CatNameValueEncode[] = "WVTAsn1CatNameValueEncode";
1003 static const CHAR CatNameValueDecode[] = "WVTAsn1CatNameValueDecode";
1004 static const CHAR CatMemberInfoEncode[] = "WVTAsn1CatMemberInfoEncode";
1005 static const CHAR CatMemberInfoDecode[] = "WVTAsn1CatMemberInfoDecode";
1006 static const CHAR SpcSpOpusInfoEncode[] = "WVTAsn1SpcSpOpusInfoEncode";
1007 static const CHAR SpcSpOpusInfoDecode[] = "WVTAsn1SpcSpOpusInfoDecode";
1008 static GUID Unknown1 = { 0xDE351A42, 0x8E59, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
1009 static GUID Unknown2 = { 0xC689AABA, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
1010 static GUID Unknown3 = { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
1011 static GUID Unknown4 = { 0xC689AAB9, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
1012 static GUID Unknown5 = { 0xDE351A43, 0x8E59, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
1013 static GUID Unknown6 = { 0x9BA61D3F, 0xE73A, 0x11D0, { 0x8C,0xD2,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
1014 static WCHAR MagicNumber2[] = {'M','S','C','F', 0};
1015 static WCHAR MagicNumber3[] = {'0','x','0','0','0','0','4','5','5','0', 0};
1016 static WCHAR CafeBabe[] = {'0','x','c','a','f','e','b','a','b','e', 0};
1018 HRESULT CryptRegisterRes = S_OK;
1019 HRESULT TrustProviderRes = S_OK;
1020 HRESULT SIPAddProviderRes = S_OK;
1021 HCRYPTPROV crypt_provider;
1022 BOOL ret;
1024 TRACE("\n");
1026 /* Testing on native shows that when an error is encountered in one of the CryptRegisterOIDFunction calls
1027 * the rest of these calls are skipped. Registering is however continued for the trust providers.
1029 * We are not totally in line with native as all decoding functions are registered after all encoding
1030 * functions there.
1032 #define WINTRUST_REGISTEROID( oid, encode_funcname, decode_funcname ) \
1033 do { \
1034 if (!CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_ENCODE_OBJECT_FUNC, oid, SP_POLICY_PROVIDER_DLL_NAME, encode_funcname)) \
1036 CryptRegisterRes = HRESULT_FROM_WIN32(GetLastError()); \
1037 goto add_trust_providers; \
1039 if (!CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_DECODE_OBJECT_FUNC, oid, SP_POLICY_PROVIDER_DLL_NAME, decode_funcname)) \
1041 CryptRegisterRes = HRESULT_FROM_WIN32(GetLastError()); \
1042 goto add_trust_providers; \
1044 } while (0)
1046 WINTRUST_REGISTEROID(SPC_PE_IMAGE_DATA_OBJID, SpcPeImageDataEncode, SpcPeImageDataDecode);
1047 WINTRUST_REGISTEROID(SPC_PE_IMAGE_DATA_STRUCT, SpcPeImageDataEncode, SpcPeImageDataDecode);
1048 WINTRUST_REGISTEROID(SPC_CAB_DATA_OBJID, SpcLinkEncode, SpcLinkDecode);
1049 WINTRUST_REGISTEROID(SPC_CAB_DATA_STRUCT, SpcLinkEncode, SpcLinkDecode);
1050 WINTRUST_REGISTEROID(SPC_JAVA_CLASS_DATA_OBJID, SpcLinkEncode, SpcLinkDecode);
1051 WINTRUST_REGISTEROID(SPC_JAVA_CLASS_DATA_STRUCT, SpcLinkEncode, SpcLinkDecode);
1052 WINTRUST_REGISTEROID(SPC_LINK_OBJID, SpcLinkEncode, SpcLinkDecode);
1053 WINTRUST_REGISTEROID(SPC_LINK_STRUCT, SpcLinkEncode, SpcLinkDecode);
1054 WINTRUST_REGISTEROID(SPC_SIGINFO_OBJID, SpcSigInfoEncode, SpcSigInfoDecode);
1055 WINTRUST_REGISTEROID(SPC_SIGINFO_STRUCT, SpcSigInfoEncode, SpcSigInfoDecode);
1056 WINTRUST_REGISTEROID(SPC_INDIRECT_DATA_OBJID, SpcIndirectDataContentEncode, SpcIndirectDataContentDecode);
1057 WINTRUST_REGISTEROID(SPC_INDIRECT_DATA_CONTENT_STRUCT, SpcIndirectDataContentEncode, SpcIndirectDataContentDecode);
1058 WINTRUST_REGISTEROID(SPC_SP_AGENCY_INFO_OBJID, SpcSpAgencyInfoEncode, SpcSpAgencyInfoDecode);
1059 WINTRUST_REGISTEROID(SPC_SP_AGENCY_INFO_STRUCT, SpcSpAgencyInfoEncode, SpcSpAgencyInfoDecode);
1060 WINTRUST_REGISTEROID(SPC_MINIMAL_CRITERIA_OBJID, SpcMinimalCriteriaInfoEncode, SpcMinimalCriteriaInfoDecode);
1061 WINTRUST_REGISTEROID(SPC_MINIMAL_CRITERIA_STRUCT, SpcMinimalCriteriaInfoEncode, SpcMinimalCriteriaInfoDecode);
1062 WINTRUST_REGISTEROID(SPC_FINANCIAL_CRITERIA_OBJID, SpcFinancialCriteriaInfoEncode, SpcFinancialCriteriaInfoDecode);
1063 WINTRUST_REGISTEROID(SPC_FINANCIAL_CRITERIA_STRUCT, SpcFinancialCriteriaInfoEncode, SpcFinancialCriteriaInfoDecode);
1064 WINTRUST_REGISTEROID(SPC_STATEMENT_TYPE_OBJID, SpcStatementTypeEncode, SpcStatementTypeDecode);
1065 WINTRUST_REGISTEROID(SPC_STATEMENT_TYPE_STRUCT, SpcStatementTypeEncode, SpcStatementTypeDecode);
1066 WINTRUST_REGISTEROID(CAT_NAMEVALUE_OBJID, CatNameValueEncode, CatNameValueDecode);
1067 WINTRUST_REGISTEROID(CAT_NAMEVALUE_STRUCT, CatNameValueEncode, CatNameValueDecode);
1068 WINTRUST_REGISTEROID(CAT_MEMBERINFO_OBJID, CatMemberInfoEncode, CatMemberInfoDecode);
1069 WINTRUST_REGISTEROID(CAT_MEMBERINFO_STRUCT, CatMemberInfoEncode, CatMemberInfoDecode);
1070 WINTRUST_REGISTEROID(SPC_SP_OPUS_INFO_OBJID, SpcSpOpusInfoEncode, SpcSpOpusInfoDecode);
1071 WINTRUST_REGISTEROID(SPC_SP_OPUS_INFO_STRUCT, SpcSpOpusInfoEncode, SpcSpOpusInfoDecode);
1073 #undef WINTRUST_REGISTEROID
1075 add_trust_providers:
1077 /* Testing on W2K3 shows:
1078 * All registry writes are tried. If one fails this part will return S_FALSE.
1080 * Last error is set to the last error encountered, regardless if the first
1081 * part failed or not.
1084 /* Create the necessary action registry structures */
1085 WINTRUST_InitRegStructs();
1087 /* Register several Trust Provider actions */
1088 if (!WINTRUST_RegisterGenVerifyV2())
1089 TrustProviderRes = S_FALSE;
1090 if (!WINTRUST_RegisterPublishedSoftware())
1091 TrustProviderRes = S_FALSE;
1092 if (!WINTRUST_RegisterPublishedSoftwareNoBadUi())
1093 TrustProviderRes = S_FALSE;
1094 if (!WINTRUST_RegisterGenCertVerify())
1095 TrustProviderRes = S_FALSE;
1096 if (!WINTRUST_RegisterTrustProviderTest())
1097 TrustProviderRes = S_FALSE;
1098 if (!WINTRUST_RegisterHttpsProv())
1099 TrustProviderRes = S_FALSE;
1100 if (!WINTRUST_RegisterOfficeSignVerify())
1101 TrustProviderRes = S_FALSE;
1102 if (!WINTRUST_RegisterDriverVerify())
1103 TrustProviderRes = S_FALSE;
1104 if (!WINTRUST_RegisterGenChainVerify())
1105 TrustProviderRes = S_FALSE;
1107 /* Free the registry structures */
1108 WINTRUST_FreeRegStructs();
1110 /* Testing on W2K3 shows:
1111 * All registry writes are tried. If one fails this part will return S_FALSE.
1113 * Last error is set to the last error encountered, regardless if the previous
1114 * parts failed or not.
1117 if (!WINTRUST_SIPPAddProvider(&Unknown1, NULL))
1118 SIPAddProviderRes = S_FALSE;
1119 if (!WINTRUST_SIPPAddProvider(&Unknown2, MagicNumber2))
1120 SIPAddProviderRes = S_FALSE;
1121 if (!WINTRUST_SIPPAddProvider(&Unknown3, MagicNumber3))
1122 SIPAddProviderRes = S_FALSE;
1123 if (!WINTRUST_SIPPAddProvider(&Unknown4, CafeBabe))
1124 SIPAddProviderRes = S_FALSE;
1125 if (!WINTRUST_SIPPAddProvider(&Unknown5, CafeBabe))
1126 SIPAddProviderRes = S_FALSE;
1127 if (!WINTRUST_SIPPAddProvider(&Unknown6, CafeBabe))
1128 SIPAddProviderRes = S_FALSE;
1130 /* Native does a CryptSIPRemoveProvider here for {941C2937-1292-11D1-85BE-00C04FC295EE}.
1131 * This SIP Provider is however not found on up-to-date window install and native will
1132 * set the last error to ERROR_FILE_NOT_FOUND.
1133 * Wine has the last error set to ERROR_INVALID_PARAMETER. There shouldn't be an app
1134 * depending on this last error though so there is no need to imitate native to the full extent.
1136 * (The ERROR_INVALID_PARAMETER for Wine it totally valid as we (and native) do register
1137 * a trust provider without a diagnostic policy).
1140 /* Create a dummy context to force creation of the MachineGuid registry key. */
1141 ret = CryptAcquireContextW(&crypt_provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
1142 if (ret) CryptReleaseContext(crypt_provider, 0);
1143 else ERR("Failed to acquire cryptographic context: %lu\n", GetLastError());
1145 /* If CryptRegisterRes is not S_OK it will always overrule the return value. */
1146 if (CryptRegisterRes != S_OK)
1147 return CryptRegisterRes;
1148 else if (SIPAddProviderRes == S_OK)
1149 return TrustProviderRes;
1150 else
1151 return SIPAddProviderRes;
1154 /***********************************************************************
1155 * DllUnregisterServer (WINTRUST.@)
1157 HRESULT WINAPI DllUnregisterServer(void)
1159 FIXME("stub\n");
1160 return S_OK;
1163 /***********************************************************************
1164 * SoftpubDllRegisterServer (WINTRUST.@)
1166 * Registers softpub.dll
1168 * PARAMS
1170 * RETURNS
1171 * Success: S_OK.
1172 * Failure: S_FALSE. (See also GetLastError()).
1174 * NOTES
1175 * DllRegisterServer in softpub.dll will call this function.
1176 * See comments in DllRegisterServer.
1178 HRESULT WINAPI SoftpubDllRegisterServer(void)
1180 HRESULT TrustProviderRes = S_OK;
1182 TRACE("\n");
1184 /* Create the necessary action registry structures */
1185 WINTRUST_InitRegStructs();
1187 /* Register several Trust Provider actions */
1188 if (!WINTRUST_RegisterGenVerifyV2())
1189 TrustProviderRes = S_FALSE;
1190 if (!WINTRUST_RegisterPublishedSoftware())
1191 TrustProviderRes = S_FALSE;
1192 if (!WINTRUST_RegisterPublishedSoftwareNoBadUi())
1193 TrustProviderRes = S_FALSE;
1194 if (!WINTRUST_RegisterGenCertVerify())
1195 TrustProviderRes = S_FALSE;
1196 if (!WINTRUST_RegisterTrustProviderTest())
1197 TrustProviderRes = S_FALSE;
1198 if (!WINTRUST_RegisterHttpsProv())
1199 TrustProviderRes = S_FALSE;
1200 if (!WINTRUST_RegisterOfficeSignVerify())
1201 TrustProviderRes = S_FALSE;
1202 if (!WINTRUST_RegisterDriverVerify())
1203 TrustProviderRes = S_FALSE;
1204 if (!WINTRUST_RegisterGenChainVerify())
1205 TrustProviderRes = S_FALSE;
1207 /* Free the registry structures */
1208 WINTRUST_FreeRegStructs();
1210 return TrustProviderRes;
1213 /***********************************************************************
1214 * SoftpubDllUnregisterServer (WINTRUST.@)
1216 HRESULT WINAPI SoftpubDllUnregisterServer(void)
1218 FIXME("stub\n");
1219 return S_OK;
1222 /***********************************************************************
1223 * mscat32DllRegisterServer (WINTRUST.@)
1225 HRESULT WINAPI mscat32DllRegisterServer(void)
1227 FIXME("stub\n");
1228 return S_OK;
1231 /***********************************************************************
1232 * mscat32DllUnregisterServer (WINTRUST.@)
1234 HRESULT WINAPI mscat32DllUnregisterServer(void)
1236 FIXME("stub\n");
1237 return S_OK;
1240 /***********************************************************************
1241 * mssip32DllRegisterServer (WINTRUST.@)
1243 HRESULT WINAPI mssip32DllRegisterServer(void)
1245 FIXME("stub\n");
1246 return S_OK;
1249 /***********************************************************************
1250 * mssip32DllUnregisterServer (WINTRUST.@)
1252 HRESULT WINAPI mssip32DllUnregisterServer(void)
1254 FIXME("stub\n");
1255 return S_OK;