wintrust: Register HTTPSPROV_ACTION.
[wine] / dlls / wintrust / register.c
1 /*
2  * Register related wintrust functions
3  *
4  * Copyright 2006 Paul Vriens
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <stdarg.h>
22
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
30 #include "guiddef.h"
31 #include "wintrust.h"
32 #include "softpub.h"
33
34 #include "wine/debug.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(wintrust);
37
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;
45
46 static CRYPT_TRUST_REG_ENTRY SoftpubDefCertInit;
47
48 static CRYPT_TRUST_REG_ENTRY SoftpubDumpStructure;
49
50 static CRYPT_TRUST_REG_ENTRY HTTPSCertificateTrust;
51 static CRYPT_TRUST_REG_ENTRY HTTPSFinalProv;
52
53 static const WCHAR Trust[]            = {'S','o','f','t','w','a','r','e','\\',
54                                          'M','i','c','r','o','s','o','f','t','\\',
55                                          'C','r','y','p','t','o','g','r','a','p','h','y','\\',
56                                          'P','r','o','v','i','d','e','r','s','\\',
57                                          'T','r','u','s','t','\\', 0 };
58
59 static const WCHAR Initialization[]   = {'I','n','i','t','i','a','l','i','z','a','t','i','o','n','\\', 0};
60 static const WCHAR Message[]          = {'M','e','s','s','a','g','e','\\', 0};
61 static const WCHAR Signature[]        = {'S','i','g','n','a','t','u','r','e','\\', 0};
62 static const WCHAR Certificate[]      = {'C','e','r','t','i','f','i','c','a','t','e','\\', 0};
63 static const WCHAR CertCheck[]        = {'C','e','r','t','C','h','e','c','k','\\', 0};
64 static const WCHAR FinalPolicy[]      = {'F','i','n','a','l','P','o','l','i','c','y','\\', 0};
65 static const WCHAR DiagnosticPolicy[] = {'D','i','a','g','n','o','s','t','i','c','P','o','l','i','c','y','\\', 0};
66 static const WCHAR Cleanup[]          = {'C','l','e','a','n','u','p','\\', 0};
67
68 static const WCHAR DefaultId[]        = {'D','e','f','a','u','l','t','I','d', 0};
69 static const WCHAR Dll[]              = {'$','D','L','L', 0};
70
71 /***********************************************************************
72  *              WINTRUST_InitRegStructs
73  *
74  * Helper function to allocate and initialize the members of the
75  * CRYPT_TRUST_REG_ENTRY structs.
76  */
77 static void WINTRUST_InitRegStructs(void)
78 {
79 #define WINTRUST_INITREGENTRY( action, dllname, functionname ) \
80     action.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY); \
81     action.pwszDLLName = HeapAlloc(GetProcessHeap(), 0, sizeof(dllname)); \
82     lstrcpyW(action.pwszDLLName, dllname); \
83     action.pwszFunctionName = HeapAlloc(GetProcessHeap(), 0, sizeof(functionname)); \
84     lstrcpyW(action.pwszFunctionName, functionname);
85
86     WINTRUST_INITREGENTRY(SoftpubInitialization, SP_POLICY_PROVIDER_DLL_NAME, SP_INIT_FUNCTION)
87     WINTRUST_INITREGENTRY(SoftpubMessage, SP_POLICY_PROVIDER_DLL_NAME, SP_OBJTRUST_FUNCTION)
88     WINTRUST_INITREGENTRY(SoftpubSignature, SP_POLICY_PROVIDER_DLL_NAME, SP_SIGTRUST_FUNCTION)
89     WINTRUST_INITREGENTRY(SoftpubCertficate, SP_POLICY_PROVIDER_DLL_NAME, WT_PROVIDER_CERTTRUST_FUNCTION)
90     WINTRUST_INITREGENTRY(SoftpubCertCheck, SP_POLICY_PROVIDER_DLL_NAME, SP_CHKCERT_FUNCTION)
91     WINTRUST_INITREGENTRY(SoftpubFinalPolicy, SP_POLICY_PROVIDER_DLL_NAME, SP_FINALPOLICY_FUNCTION)
92     WINTRUST_INITREGENTRY(SoftpubCleanup, SP_POLICY_PROVIDER_DLL_NAME, SP_CLEANUPPOLICY_FUNCTION)
93     WINTRUST_INITREGENTRY(SoftpubDefCertInit, SP_POLICY_PROVIDER_DLL_NAME, SP_GENERIC_CERT_INIT_FUNCTION)
94     WINTRUST_INITREGENTRY(SoftpubDumpStructure, SP_POLICY_PROVIDER_DLL_NAME, SP_TESTDUMPPOLICY_FUNCTION_TEST)
95     WINTRUST_INITREGENTRY(HTTPSCertificateTrust, SP_POLICY_PROVIDER_DLL_NAME, HTTPS_CERTTRUST_FUNCTION)
96     WINTRUST_INITREGENTRY(HTTPSFinalProv, SP_POLICY_PROVIDER_DLL_NAME, HTTPS_FINALPOLICY_FUNCTION)
97
98 #undef WINTRUST_INITREGENTRY
99 }
100
101 /***********************************************************************
102  *              WINTRUST_FreeRegStructs
103  *
104  * Helper function to free 2 members of the CRYPT_TRUST_REG_ENTRY
105  * structs.
106  */
107 static void WINTRUST_FreeRegStructs(void)
108 {
109 #define WINTRUST_FREEREGENTRY( action ) \
110     HeapFree(GetProcessHeap(), 0, action.pwszDLLName); \
111     HeapFree(GetProcessHeap(), 0, action.pwszFunctionName);
112
113     WINTRUST_FREEREGENTRY(SoftpubInitialization);
114     WINTRUST_FREEREGENTRY(SoftpubMessage);
115     WINTRUST_FREEREGENTRY(SoftpubSignature);
116     WINTRUST_FREEREGENTRY(SoftpubCertficate);
117     WINTRUST_FREEREGENTRY(SoftpubCertCheck);
118     WINTRUST_FREEREGENTRY(SoftpubFinalPolicy);
119     WINTRUST_FREEREGENTRY(SoftpubCleanup);
120     WINTRUST_FREEREGENTRY(SoftpubDefCertInit);
121     WINTRUST_FREEREGENTRY(SoftpubDumpStructure);
122     WINTRUST_FREEREGENTRY(HTTPSCertificateTrust);
123     WINTRUST_FREEREGENTRY(HTTPSFinalProv);
124
125 #undef WINTRUST_FREEREGENTRY
126 }
127
128 /***********************************************************************
129  *              WINTRUST_guid2wstr
130  *
131  * Create a wide-string from a GUID
132  *
133  */
134 static void WINTRUST_Guid2Wstr(const GUID* pgActionID, WCHAR* GuidString)
135
136     static const WCHAR wszFormat[] = {'{','%','0','8','l','X','-','%','0','4','X','-','%','0','4','X','-',
137                                       '%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2',
138                                       'X','%','0','2','X','%','0','2','X','}', 0};
139
140     wsprintfW(GuidString, wszFormat, pgActionID->Data1, pgActionID->Data2, pgActionID->Data3,
141         pgActionID->Data4[0], pgActionID->Data4[1], pgActionID->Data4[2], pgActionID->Data4[3],
142         pgActionID->Data4[4], pgActionID->Data4[5], pgActionID->Data4[6], pgActionID->Data4[7]);
143 }
144
145 /***********************************************************************
146  *              WINTRUST_WriteProviderToReg
147  *
148  * Helper function for WintrustAddActionID
149  *
150  */
151 static LONG WINTRUST_WriteProviderToReg(WCHAR* GuidString,
152                                         const WCHAR* FunctionType,
153                                         CRYPT_TRUST_REG_ENTRY RegEntry)
154 {
155     static const WCHAR Function[] = {'$','F','u','n','c','t','i','o','n', 0};
156     WCHAR ProvKey[MAX_PATH];
157     HKEY Key;
158     LONG Res = ERROR_SUCCESS;
159
160     /* Create the needed key string */
161     ProvKey[0]='\0';
162     lstrcatW(ProvKey, Trust);
163     lstrcatW(ProvKey, FunctionType);
164     lstrcatW(ProvKey, GuidString);
165
166     if (!RegEntry.pwszDLLName || !RegEntry.pwszFunctionName)
167         return ERROR_INVALID_PARAMETER;
168
169     Res = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ProvKey, 0, NULL, 0, KEY_WRITE, NULL, &Key, NULL);
170     if (Res != ERROR_SUCCESS) goto error_close_key;
171
172     /* Create the $DLL entry */
173     Res = RegSetValueExW(Key, Dll, 0, REG_SZ, (BYTE*)RegEntry.pwszDLLName,
174         (lstrlenW(RegEntry.pwszDLLName) + 1)*sizeof(WCHAR));
175     if (Res != ERROR_SUCCESS) goto error_close_key;
176
177     /* Create the $Function entry */
178     Res = RegSetValueExW(Key, Function, 0, REG_SZ, (BYTE*)RegEntry.pwszFunctionName,
179         (lstrlenW(RegEntry.pwszFunctionName) + 1)*sizeof(WCHAR));
180
181 error_close_key:
182     RegCloseKey(Key);
183
184     return Res;
185 }
186
187 /***********************************************************************
188  *              WintrustAddActionID (WINTRUST.@)
189  *
190  * Add the definitions of the actions a Trust provider can perform to
191  * the registry.
192  *
193  * PARAMS
194  *   pgActionID [I] Pointer to a GUID for the Trust provider.
195  *   fdwFlags   [I] Flag to indicate whether registry errors are passed on.
196  *   psProvInfo [I] Pointer to a structure with information about DLL
197  *                  name and functions.
198  *
199  * RETURNS
200  *   Success: TRUE.
201  *   Failure: FALSE. (Use GetLastError() for more information)
202  *
203  * NOTES
204  *   Adding definitions is basically only adding relevant information
205  *   to the registry. No verification takes place whether a DLL or it's
206  *   entrypoints exist.
207  *   Information in the registry will always be overwritten.
208  *
209  */
210 BOOL WINAPI WintrustAddActionID( GUID* pgActionID, DWORD fdwFlags,
211                                  CRYPT_REGISTER_ACTIONID* psProvInfo)
212 {
213     WCHAR GuidString[39];
214     LONG Res;
215     LONG WriteActionError = ERROR_SUCCESS;
216
217     TRACE("%p %lx %p\n", debugstr_guid(pgActionID), fdwFlags, psProvInfo);
218
219     /* Some sanity checks.
220      * We use the W2K3 last error as it makes more sense (W2K leaves the last error
221      * as is).
222      */
223     if (!pgActionID ||
224         !psProvInfo ||
225         (psProvInfo->cbStruct != sizeof(CRYPT_REGISTER_ACTIONID)))
226     {
227         SetLastError(ERROR_INVALID_PARAMETER);
228         return FALSE;
229     }
230
231     /* Create this string only once, instead of in the helper function */
232     WINTRUST_Guid2Wstr( pgActionID, GuidString);
233
234     /* Write the information to the registry */
235     Res = WINTRUST_WriteProviderToReg(GuidString, Initialization  , psProvInfo->sInitProvider);
236     if (Res != ERROR_SUCCESS) WriteActionError = Res;
237     Res = WINTRUST_WriteProviderToReg(GuidString, Message         , psProvInfo->sObjectProvider);
238     if (Res != ERROR_SUCCESS) WriteActionError = Res;
239     Res = WINTRUST_WriteProviderToReg(GuidString, Signature       , psProvInfo->sSignatureProvider);
240     if (Res != ERROR_SUCCESS) WriteActionError = Res;
241     Res = WINTRUST_WriteProviderToReg(GuidString, Certificate     , psProvInfo->sCertificateProvider);
242     if (Res != ERROR_SUCCESS) WriteActionError = Res;
243     Res = WINTRUST_WriteProviderToReg(GuidString, CertCheck       , psProvInfo->sCertificatePolicyProvider);
244     if (Res != ERROR_SUCCESS) WriteActionError = Res;
245     Res = WINTRUST_WriteProviderToReg(GuidString, FinalPolicy     , psProvInfo->sFinalPolicyProvider);
246     if (Res != ERROR_SUCCESS) WriteActionError = Res;
247     Res = WINTRUST_WriteProviderToReg(GuidString, DiagnosticPolicy, psProvInfo->sTestPolicyProvider);
248     if (Res != ERROR_SUCCESS) WriteActionError = Res;
249     Res = WINTRUST_WriteProviderToReg(GuidString, Cleanup         , psProvInfo->sCleanupProvider);
250     if (Res != ERROR_SUCCESS) WriteActionError = Res;
251
252     /* Testing (by restricting access to the registry for some keys) shows that the last failing function
253      * will be used for last error.
254      * If the flag WT_ADD_ACTION_ID_RET_RESULT_FLAG is set and there are errors when adding the action
255      * we have to return FALSE. Errors includes both invalid entries as well as registry errors.
256      * Testing also showed that one error doesn't stop the registry writes. Every action will be dealt with.
257      */
258
259     if (WriteActionError != ERROR_SUCCESS)
260     {
261         SetLastError(WriteActionError);
262
263         if (fdwFlags == WT_ADD_ACTION_ID_RET_RESULT_FLAG)
264             return FALSE;
265     }
266
267     return TRUE;
268 }
269
270 /***********************************************************************
271  *              WINTRUST_RemoveProviderFromReg
272  *
273  * Helper function for WintrustRemoveActionID
274  *
275  */
276 static void WINTRUST_RemoveProviderFromReg(WCHAR* GuidString,
277                                            const WCHAR* FunctionType)
278 {
279     WCHAR ProvKey[MAX_PATH];
280
281     /* Create the needed key string */
282     ProvKey[0]='\0';
283     lstrcatW(ProvKey, Trust);
284     lstrcatW(ProvKey, FunctionType);
285     lstrcatW(ProvKey, GuidString);
286
287     /* We don't care about success or failure */
288     RegDeleteKeyW(HKEY_LOCAL_MACHINE, ProvKey);
289 }
290
291 /***********************************************************************
292  *              WintrustRemoveActionID (WINTRUST.@)
293  *
294  * Remove the definitions of the actions a Trust provider can perform
295  * from the registry.
296  *
297  * PARAMS
298  *   pgActionID [I] Pointer to a GUID for the Trust provider.
299  *
300  * RETURNS
301  *   Success: TRUE. (Use GetLastError() for more information)
302  *   Failure: FALSE. (Use GetLastError() for more information)
303  *
304  * NOTES
305  *   Testing shows that WintrustRemoveActionID always returns TRUE and
306  *   that a possible error should be retrieved via GetLastError().
307  *   There are no checks if the definitions are in the registry.
308  */
309 BOOL WINAPI WintrustRemoveActionID( GUID* pgActionID )
310 {
311     WCHAR GuidString[39];
312
313     TRACE("(%s)\n", debugstr_guid(pgActionID));
314  
315     if (!pgActionID)
316     {
317         SetLastError(ERROR_INVALID_PARAMETER);
318         return TRUE;
319     }
320
321     /* Create this string only once, instead of in the helper function */
322     WINTRUST_Guid2Wstr( pgActionID, GuidString);
323
324     /* We don't care about success or failure */
325     WINTRUST_RemoveProviderFromReg(GuidString, Initialization);
326     WINTRUST_RemoveProviderFromReg(GuidString, Message);
327     WINTRUST_RemoveProviderFromReg(GuidString, Signature);
328     WINTRUST_RemoveProviderFromReg(GuidString, Certificate);
329     WINTRUST_RemoveProviderFromReg(GuidString, CertCheck);
330     WINTRUST_RemoveProviderFromReg(GuidString, FinalPolicy);
331     WINTRUST_RemoveProviderFromReg(GuidString, DiagnosticPolicy);
332     WINTRUST_RemoveProviderFromReg(GuidString, Cleanup);
333
334     return TRUE;
335 }
336
337 /***********************************************************************
338  *              WINTRUST_WriteSingleUsageEntry
339  *
340  * Write a single value and its data to:
341  *
342  * HKLM\Software\Microsoft\Cryptography\Trust\Usages\<OID>
343  */
344 static LONG WINTRUST_WriteSingleUsageEntry(LPCSTR OID,
345                                            const WCHAR* Value,
346                                            WCHAR* Data)
347 {
348     static const WCHAR Usages[] = {'U','s','a','g','e','s','\\', 0};
349     WCHAR* UsageKey;
350     HKEY Key;
351     LONG Res = ERROR_SUCCESS;
352     WCHAR* OIDW;
353     DWORD Len;
354
355     /* Turn OID into a wide-character string */
356     Len = MultiByteToWideChar( CP_ACP, 0, OID, -1, NULL, 0 );
357     OIDW = HeapAlloc( GetProcessHeap(), 0, Len * sizeof(WCHAR) );
358     MultiByteToWideChar( CP_ACP, 0, OID, -1, OIDW, Len );
359
360     /* Allocate the needed space for UsageKey */
361     UsageKey = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(Trust) + lstrlenW(Usages) + Len) * sizeof(WCHAR));
362     /* Create the key string */
363     lstrcpyW(UsageKey, Trust);
364     lstrcatW(UsageKey, Usages);
365     lstrcatW(UsageKey, OIDW);
366
367     Res = RegCreateKeyExW(HKEY_LOCAL_MACHINE, UsageKey, 0, NULL, 0, KEY_WRITE, NULL, &Key, NULL);
368     if (Res == ERROR_SUCCESS)
369     {
370         /* Create the Value entry */
371         Res = RegSetValueExW(Key, Value, 0, REG_SZ, (BYTE*)Data,
372                              (lstrlenW(Data) + 1)*sizeof(WCHAR));
373     }
374     RegCloseKey(Key);
375
376     HeapFree(GetProcessHeap(), 0, OIDW);
377     HeapFree(GetProcessHeap(), 0, UsageKey);
378
379     return Res;
380 }
381
382 /***************************************************************************
383  *              WINTRUST_RegisterGenVerifyV2
384  *
385  * Register WINTRUST_ACTION_GENERIC_VERIFY_V2 actions and usages.
386  *
387  * NOTES
388  *   WINTRUST_ACTION_GENERIC_VERIFY_V2 ({00AAC56B-CD44-11D0-8CC2-00C04FC295EE}
389  *   is defined in softpub.h
390  *   We don't care about failures (see comments in DllRegisterServer)
391  */
392 static void WINTRUST_RegisterGenVerifyV2(void)
393 {
394     static const GUID ProvGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2;
395     WCHAR GuidString[39];
396
397     WINTRUST_Guid2Wstr(&ProvGUID , GuidString);
398
399     TRACE("Going to register WINTRUST_ACTION_GENERIC_VERIFY_V2 : %s\n", wine_dbgstr_w(GuidString));
400
401     /* HKLM\Software\Microsoft\Cryptography\Trust\Usages\1.3.6.1.5.5.7.3.3 */
402     WINTRUST_WriteSingleUsageEntry(szOID_PKIX_KP_CODE_SIGNING, DefaultId, GuidString);
403
404     /* HKLM\Software\Microsoft\Cryptography\Trust\Provider\*\{00AAC56B-CD44-11D0-8CC2-00C04FC295EE} */
405     WINTRUST_WriteProviderToReg(GuidString, Initialization, SoftpubInitialization);
406     WINTRUST_WriteProviderToReg(GuidString, Message       , SoftpubMessage);
407     WINTRUST_WriteProviderToReg(GuidString, Signature     , SoftpubSignature);
408     WINTRUST_WriteProviderToReg(GuidString, Certificate   , SoftpubCertficate);
409     WINTRUST_WriteProviderToReg(GuidString, CertCheck     , SoftpubCertCheck);
410     WINTRUST_WriteProviderToReg(GuidString, FinalPolicy   , SoftpubFinalPolicy);
411     WINTRUST_WriteProviderToReg(GuidString, Cleanup       , SoftpubCleanup);
412 }
413
414 /***************************************************************************
415  *              WINTRUST_RegisterPublishedSoftware
416  *
417  * Register WIN_SPUB_ACTION_PUBLISHED_SOFTWARE actions and usages.
418  *
419  * NOTES
420  *   WIN_SPUB_ACTION_PUBLISHED_SOFTWARE ({64B9D180-8DA2-11CF-8736-00AA00A485EB})
421  *   is defined in wintrust.h
422  *   We don't care about failures (see comments in DllRegisterServer)
423  */
424 static void WINTRUST_RegisterPublishedSoftware(void)
425 {
426     static const GUID ProvGUID = WIN_SPUB_ACTION_PUBLISHED_SOFTWARE;
427     WCHAR GuidString[39];
428
429     WINTRUST_Guid2Wstr(&ProvGUID , GuidString);
430
431     TRACE("Going to register WIN_SPUB_ACTION_PUBLISHED_SOFTWARE : %s\n", wine_dbgstr_w(GuidString));
432
433     /* HKLM\Software\Microsoft\Cryptography\Trust\Provider\*\{64B9D180-8DA2-11CF-8736-00AA00A485EB} */
434     WINTRUST_WriteProviderToReg(GuidString, Initialization, SoftpubInitialization);
435     WINTRUST_WriteProviderToReg(GuidString, Message       , SoftpubMessage);
436     WINTRUST_WriteProviderToReg(GuidString, Signature     , SoftpubSignature);
437     WINTRUST_WriteProviderToReg(GuidString, Certificate   , SoftpubCertficate);
438     WINTRUST_WriteProviderToReg(GuidString, CertCheck     , SoftpubCertCheck);
439     WINTRUST_WriteProviderToReg(GuidString, FinalPolicy   , SoftpubFinalPolicy);
440     WINTRUST_WriteProviderToReg(GuidString, Cleanup       , SoftpubCleanup);
441 }
442
443 #define WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI { 0xc6b2e8d0, 0xe005, 0x11cf, { 0xa1,0x34,0x00,0xc0,0x4f,0xd7,0xbf,0x43 }}
444
445 /***************************************************************************
446  *              WINTRUST_RegisterPublishedSoftwareNoBadUi
447  *
448  * Register WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI actions and usages.
449  *
450  * NOTES
451  *   WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI ({C6B2E8D0-E005-11CF-A134-00C04FD7BF43})
452  *   is not defined in any include file. (FIXME: Find out if the name is correct).
453  *   We don't care about failures (see comments in DllRegisterServer)
454  */
455 static void WINTRUST_RegisterPublishedSoftwareNoBadUi(void)
456 {
457     static const GUID ProvGUID = WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI;
458     WCHAR GuidString[39];
459
460     WINTRUST_Guid2Wstr(&ProvGUID , GuidString);
461
462     TRACE("Going to register WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI : %s\n", wine_dbgstr_w(GuidString));
463
464     /* HKLM\Software\Microsoft\Cryptography\Trust\Provider\*\{C6B2E8D0-E005-11CF-A134-00C04FD7BF43} */
465     WINTRUST_WriteProviderToReg(GuidString, Initialization, SoftpubInitialization);
466     WINTRUST_WriteProviderToReg(GuidString, Message       , SoftpubMessage);
467     WINTRUST_WriteProviderToReg(GuidString, Signature     , SoftpubSignature);
468     WINTRUST_WriteProviderToReg(GuidString, Certificate   , SoftpubCertficate);
469     WINTRUST_WriteProviderToReg(GuidString, CertCheck     , SoftpubCertCheck);
470     WINTRUST_WriteProviderToReg(GuidString, FinalPolicy   , SoftpubFinalPolicy);
471     WINTRUST_WriteProviderToReg(GuidString, Cleanup       , SoftpubCleanup);
472 }
473
474 /***************************************************************************
475  *              WINTRUST_RegisterGenCertVerify
476  *
477  * Register WINTRUST_ACTION_GENERIC_CERT_VERIFY actions and usages.
478  *
479  * NOTES
480  *   WINTRUST_ACTION_GENERIC_CERT_VERIFY ({189A3842-3041-11D1-85E1-00C04FC295EE})
481  *   is defined in softpub.h
482  *   We don't care about failures (see comments in DllRegisterServer)
483  */
484 static void WINTRUST_RegisterGenCertVerify(void)
485 {
486     static const GUID ProvGUID = WINTRUST_ACTION_GENERIC_CERT_VERIFY;
487     WCHAR GuidString[39];
488
489     WINTRUST_Guid2Wstr(&ProvGUID , GuidString);
490
491     TRACE("Going to register WINTRUST_ACTION_GENERIC_CERT_VERIFY : %s\n", wine_dbgstr_w(GuidString));
492
493     /* HKLM\Software\Microsoft\Cryptography\Trust\Provider\*\{189A3842-3041-11D1-85E1-00C04FC295EE} */
494     WINTRUST_WriteProviderToReg(GuidString, Initialization, SoftpubDefCertInit);
495     WINTRUST_WriteProviderToReg(GuidString, Message       , SoftpubMessage);
496     WINTRUST_WriteProviderToReg(GuidString, Signature     , SoftpubSignature);
497     WINTRUST_WriteProviderToReg(GuidString, Certificate   , SoftpubCertficate);
498     WINTRUST_WriteProviderToReg(GuidString, CertCheck     , SoftpubCertCheck);
499     WINTRUST_WriteProviderToReg(GuidString, FinalPolicy   , SoftpubFinalPolicy);
500     WINTRUST_WriteProviderToReg(GuidString, Cleanup       , SoftpubCleanup);
501 }
502
503 /***************************************************************************
504  *              WINTRUST_RegisterTrustProviderTest
505  *
506  * Register WINTRUST_ACTION_TRUSTPROVIDER_TEST actions and usages.
507  *
508  * NOTES
509  *   WINTRUST_ACTION_TRUSTPROVIDER_TEST ({573E31F8-DDBA-11D0-8CCB-00C04FC295EE})
510  *   is defined in softpub.h
511  *   We don't care about failures (see comments in DllRegisterServer)
512  */
513 static void WINTRUST_RegisterTrustProviderTest(void)
514 {
515     static const GUID ProvGUID = WINTRUST_ACTION_TRUSTPROVIDER_TEST;
516     WCHAR GuidString[39];
517
518     WINTRUST_Guid2Wstr(&ProvGUID , GuidString);
519
520     TRACE("Going to register WINTRUST_ACTION_TRUSTPROVIDER_TEST : %s\n", wine_dbgstr_w(GuidString));
521
522     /* HKLM\Software\Microsoft\Cryptography\Trust\Provider\*\{573E31F8-DDBA-11D0-8CCB-00C04FC295EE} */
523     WINTRUST_WriteProviderToReg(GuidString, Initialization  , SoftpubInitialization);
524     WINTRUST_WriteProviderToReg(GuidString, Message         , SoftpubMessage);
525     WINTRUST_WriteProviderToReg(GuidString, Signature       , SoftpubSignature);
526     WINTRUST_WriteProviderToReg(GuidString, Certificate     , SoftpubCertficate);
527     WINTRUST_WriteProviderToReg(GuidString, CertCheck       , SoftpubCertCheck);
528     WINTRUST_WriteProviderToReg(GuidString, FinalPolicy     , SoftpubFinalPolicy);
529     WINTRUST_WriteProviderToReg(GuidString, DiagnosticPolicy, SoftpubDumpStructure);
530     WINTRUST_WriteProviderToReg(GuidString, Cleanup         , SoftpubCleanup);
531 }
532
533 /***************************************************************************
534  *              WINTRUST_RegisterHttpsProv
535  *
536  * Register HTTPSPROV_ACTION actions and usages.
537  *
538  * NOTES
539  *   HTTPSPROV_ACTION ({573E31F8-AABA-11D0-8CCB-00C04FC295EE})
540  *   is defined in softpub.h
541  *   We don't care about failures (see comments in DllRegisterServer)
542  */
543 static void WINTRUST_RegisterHttpsProv(void)
544 {
545     static WCHAR SoftpubLoadUsage[] = {'S','o','f','t','p','u','b','L','o','a','d','D','e','f','U','s','a','g','e','C','a','l','l','D','a','t','a', 0};
546     static WCHAR SoftpubFreeUsage[] = {'S','o','f','t','p','u','b','F','r','e','e','D','e','f','U','s','a','g','e','C','a','l','l','D','a','t','a', 0};
547     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};
548     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};
549     static const GUID ProvGUID = HTTPSPROV_ACTION;
550     WCHAR GuidString[39];
551     WCHAR ProvDllName[sizeof(SP_POLICY_PROVIDER_DLL_NAME)];
552
553     WINTRUST_Guid2Wstr(&ProvGUID , GuidString);
554
555     TRACE("Going to register HTTPSPROV_ACTION : %s\n", wine_dbgstr_w(GuidString));
556
557     lstrcpyW(ProvDllName, SP_POLICY_PROVIDER_DLL_NAME); \
558
559     /* HKLM\Software\Microsoft\Cryptography\Trust\Usages\1.3.6.1.5.5.7.3.1 */
560     WINTRUST_WriteSingleUsageEntry(szOID_PKIX_KP_SERVER_AUTH, Dll, ProvDllName);
561     WINTRUST_WriteSingleUsageEntry(szOID_PKIX_KP_SERVER_AUTH, CBAlloc, SoftpubLoadUsage );
562     WINTRUST_WriteSingleUsageEntry(szOID_PKIX_KP_SERVER_AUTH, CBFree, SoftpubFreeUsage );
563     WINTRUST_WriteSingleUsageEntry(szOID_PKIX_KP_SERVER_AUTH, DefaultId, GuidString );
564     /* HKLM\Software\Microsoft\Cryptography\Trust\Usages\1.3.6.1.5.5.7.3.2 */
565     WINTRUST_WriteSingleUsageEntry(szOID_PKIX_KP_CLIENT_AUTH, Dll, ProvDllName);
566     WINTRUST_WriteSingleUsageEntry(szOID_PKIX_KP_CLIENT_AUTH, CBAlloc, SoftpubLoadUsage );
567     WINTRUST_WriteSingleUsageEntry(szOID_PKIX_KP_CLIENT_AUTH, CBFree, SoftpubFreeUsage );
568     WINTRUST_WriteSingleUsageEntry(szOID_PKIX_KP_CLIENT_AUTH, DefaultId, GuidString );
569     /* HKLM\Software\Microsoft\Cryptography\Trust\Usages\1.3.6.1.4.1.311.10.3.3 */
570     WINTRUST_WriteSingleUsageEntry(szOID_SERVER_GATED_CRYPTO, Dll, ProvDllName);
571     WINTRUST_WriteSingleUsageEntry(szOID_SERVER_GATED_CRYPTO, CBAlloc, SoftpubLoadUsage );
572     WINTRUST_WriteSingleUsageEntry(szOID_SERVER_GATED_CRYPTO, CBFree, SoftpubFreeUsage );
573     WINTRUST_WriteSingleUsageEntry(szOID_SERVER_GATED_CRYPTO, DefaultId, GuidString );
574     /* HKLM\Software\Microsoft\Cryptography\Trust\Usages\2.16.840.1.113730.4.1 */
575     WINTRUST_WriteSingleUsageEntry(szOID_SGC_NETSCAPE, Dll, ProvDllName);
576     WINTRUST_WriteSingleUsageEntry(szOID_SGC_NETSCAPE, CBAlloc, SoftpubLoadUsage );
577     WINTRUST_WriteSingleUsageEntry(szOID_SGC_NETSCAPE, CBFree, SoftpubFreeUsage );
578     WINTRUST_WriteSingleUsageEntry(szOID_SGC_NETSCAPE, DefaultId, GuidString );
579
580     /* HKLM\Software\Microsoft\Cryptography\Trust\Provider\*\{573E31F8-AABA-11D0-8CCB-00C04FC295EE} */
581     WINTRUST_WriteProviderToReg(GuidString, Initialization, SoftpubInitialization);
582     WINTRUST_WriteProviderToReg(GuidString, Message       , SoftpubMessage);
583     WINTRUST_WriteProviderToReg(GuidString, Signature     , SoftpubSignature);
584     WINTRUST_WriteProviderToReg(GuidString, Certificate   , HTTPSCertificateTrust);
585     WINTRUST_WriteProviderToReg(GuidString, CertCheck     , SoftpubCertCheck);
586     WINTRUST_WriteProviderToReg(GuidString, FinalPolicy   , HTTPSFinalProv);
587     WINTRUST_WriteProviderToReg(GuidString, Cleanup       , SoftpubCleanup);
588 }
589
590
591 /***********************************************************************
592  *              DllRegisterServer (WINTRUST.@)
593  */
594 HRESULT WINAPI DllRegisterServer(void)
595 {
596     HRESULT Res = S_OK;
597     HKEY Key;
598
599     TRACE("\n");
600
601     /* Create the necessary action registry structures */
602     WINTRUST_InitRegStructs();
603
604     /* FIXME:
605      * 
606      * A short list of stuff that should be done here:
607      *
608      * - Several calls to CryptRegisterOIDFunction
609      * - Several action registrations (NOT through WintrustAddActionID)
610      * - Several calls to CryptSIPAddProvider
611      * - One call to CryptSIPRemoveProvider (do we need that?)
612      */
613
614     /* Testing on W2K3 shows:
615      * If we cannot open HKLM\Software\Microsoft\Cryptography\Providers\Trust
616      * for writing, DllRegisterServer returns S_FALSE. If the key can be opened 
617      * there is no check whether the actions can be written in the registry.
618      * As the previous list shows, there are several calls after these registrations.
619      * If they fail they will overwrite the returnvalue of DllRegisterServer.
620      */
621
622     /* Check if we can open/create HKLM\Software\Microsoft\Cryptography\Providers\Trust */
623     if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, Trust, 0, NULL, 0, KEY_WRITE, NULL, &Key, NULL) != ERROR_SUCCESS)
624         Res = S_FALSE;
625     RegCloseKey(Key);
626
627     /* Register several Trust Provider actions */
628     WINTRUST_RegisterGenVerifyV2();
629     WINTRUST_RegisterPublishedSoftware();
630     WINTRUST_RegisterPublishedSoftwareNoBadUi();
631     WINTRUST_RegisterGenCertVerify();
632     WINTRUST_RegisterTrustProviderTest();
633     WINTRUST_RegisterHttpsProv();
634
635     /* Free the registry structures */
636     WINTRUST_FreeRegStructs();
637
638     return Res;
639 }
640
641 /***********************************************************************
642  *              DllUnregisterServer (WINTRUST.@)
643  */
644 HRESULT WINAPI DllUnregisterServer(void)
645 {
646      FIXME("stub\n");
647      return S_OK;
648 }
649
650 /***********************************************************************
651  *              SoftpubDllRegisterServer (WINTRUST.@)
652  */
653 HRESULT WINAPI SoftpubDllRegisterServer(void)
654 {
655      FIXME("stub\n");
656      return S_OK;
657 }
658
659 /***********************************************************************
660  *              SoftpubDllUnregisterServer (WINTRUST.@)
661  */
662 HRESULT WINAPI SoftpubDllUnregisterServer(void)
663 {
664      FIXME("stub\n");
665      return S_OK;
666 }
667
668 /***********************************************************************
669  *              mscat32DllRegisterServer (WINTRUST.@)
670  */
671 HRESULT WINAPI mscat32DllRegisterServer(void)
672 {
673      FIXME("stub\n");
674      return S_OK;
675 }
676
677 /***********************************************************************
678  *              mscat32DllUnregisterServer (WINTRUST.@)
679  */
680 HRESULT WINAPI mscat32DllUnregisterServer(void)
681 {
682      FIXME("stub\n");
683      return S_OK;
684 }
685
686 /***********************************************************************
687  *              mssip32DllRegisterServer (WINTRUST.@)
688  */
689 HRESULT WINAPI mssip32DllRegisterServer(void)
690 {
691      FIXME("stub\n");
692      return S_OK;
693 }
694
695 /***********************************************************************
696  *              mssip32DllUnregisterServer (WINTRUST.@)
697  */
698 HRESULT WINAPI mssip32DllUnregisterServer(void)
699 {
700      FIXME("stub\n");
701      return S_OK;
702 }