ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

register.c
Go to the documentation of this file.
00001 /*
00002  * Register related wintrust functions
00003  *
00004  * Copyright 2006 Paul Vriens
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include <stdarg.h>
00022 
00023 #include "windef.h"
00024 #include "winbase.h"
00025 #include "winerror.h"
00026 #include "winuser.h"
00027 #include "winreg.h"
00028 #include "winnls.h"
00029 #include "objbase.h"
00030 
00031 #include "guiddef.h"
00032 #include "wintrust.h"
00033 #include "softpub.h"
00034 #include "mssip.h"
00035 #include "wintrust_priv.h"
00036 #include "wine/debug.h"
00037 
00038 WINE_DEFAULT_DEBUG_CHANNEL(wintrust);
00039 
00040 static CRYPT_TRUST_REG_ENTRY SoftpubInitialization;
00041 static CRYPT_TRUST_REG_ENTRY SoftpubMessage;
00042 static CRYPT_TRUST_REG_ENTRY SoftpubSignature;
00043 static CRYPT_TRUST_REG_ENTRY SoftpubCertficate;
00044 static CRYPT_TRUST_REG_ENTRY SoftpubCertCheck;
00045 static CRYPT_TRUST_REG_ENTRY SoftpubFinalPolicy;
00046 static CRYPT_TRUST_REG_ENTRY SoftpubCleanup;
00047 
00048 static CRYPT_TRUST_REG_ENTRY SoftpubDefCertInit;
00049 
00050 static CRYPT_TRUST_REG_ENTRY SoftpubDumpStructure;
00051 
00052 static CRYPT_TRUST_REG_ENTRY HTTPSCertificateTrust;
00053 static CRYPT_TRUST_REG_ENTRY HTTPSFinalProv;
00054 
00055 static CRYPT_TRUST_REG_ENTRY OfficeInitializePolicy;
00056 static CRYPT_TRUST_REG_ENTRY OfficeCleanupPolicy;
00057 
00058 static CRYPT_TRUST_REG_ENTRY DriverInitializePolicy;
00059 static CRYPT_TRUST_REG_ENTRY DriverFinalPolicy;
00060 static CRYPT_TRUST_REG_ENTRY DriverCleanupPolicy;
00061 
00062 static CRYPT_TRUST_REG_ENTRY GenericChainCertificateTrust;
00063 static CRYPT_TRUST_REG_ENTRY GenericChainFinalProv;
00064 
00065 static const CRYPT_TRUST_REG_ENTRY NullCTRE = { 0, NULL, NULL };
00066 
00067 static const WCHAR Trust[]            = {'S','o','f','t','w','a','r','e','\\',
00068                                          'M','i','c','r','o','s','o','f','t','\\',
00069                                          'C','r','y','p','t','o','g','r','a','p','h','y','\\',
00070                                          'P','r','o','v','i','d','e','r','s','\\',
00071                                          'T','r','u','s','t','\\', 0 };
00072 
00073 static const WCHAR Initialization[]   = {'I','n','i','t','i','a','l','i','z','a','t','i','o','n','\\', 0};
00074 static const WCHAR Message[]          = {'M','e','s','s','a','g','e','\\', 0};
00075 static const WCHAR Signature[]        = {'S','i','g','n','a','t','u','r','e','\\', 0};
00076 static const WCHAR Certificate[]      = {'C','e','r','t','i','f','i','c','a','t','e','\\', 0};
00077 static const WCHAR CertCheck[]        = {'C','e','r','t','C','h','e','c','k','\\', 0};
00078 static const WCHAR FinalPolicy[]      = {'F','i','n','a','l','P','o','l','i','c','y','\\', 0};
00079 static const WCHAR DiagnosticPolicy[] = {'D','i','a','g','n','o','s','t','i','c','P','o','l','i','c','y','\\', 0};
00080 static const WCHAR Cleanup[]          = {'C','l','e','a','n','u','p','\\', 0};
00081 
00082 static const WCHAR DefaultId[]        = {'D','e','f','a','u','l','t','I','d', 0};
00083 static const WCHAR Dll[]              = {'$','D','L','L', 0};
00084 
00085 /***********************************************************************
00086  *              WINTRUST_InitRegStructs
00087  *
00088  * Helper function to allocate and initialize the members of the
00089  * CRYPT_TRUST_REG_ENTRY structs.
00090  */
00091 static void WINTRUST_InitRegStructs(void)
00092 {
00093 #define WINTRUST_INITREGENTRY( action, dllname, functionname ) \
00094     action.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY); \
00095     action.pwszDLLName = WINTRUST_Alloc(sizeof(dllname)); \
00096     lstrcpyW(action.pwszDLLName, dllname); \
00097     action.pwszFunctionName = WINTRUST_Alloc(sizeof(functionname)); \
00098     lstrcpyW(action.pwszFunctionName, functionname);
00099 
00100     WINTRUST_INITREGENTRY(SoftpubInitialization, SP_POLICY_PROVIDER_DLL_NAME, SP_INIT_FUNCTION)
00101     WINTRUST_INITREGENTRY(SoftpubMessage, SP_POLICY_PROVIDER_DLL_NAME, SP_OBJTRUST_FUNCTION)
00102     WINTRUST_INITREGENTRY(SoftpubSignature, SP_POLICY_PROVIDER_DLL_NAME, SP_SIGTRUST_FUNCTION)
00103     WINTRUST_INITREGENTRY(SoftpubCertficate, SP_POLICY_PROVIDER_DLL_NAME, WT_PROVIDER_CERTTRUST_FUNCTION)
00104     WINTRUST_INITREGENTRY(SoftpubCertCheck, SP_POLICY_PROVIDER_DLL_NAME, SP_CHKCERT_FUNCTION)
00105     WINTRUST_INITREGENTRY(SoftpubFinalPolicy, SP_POLICY_PROVIDER_DLL_NAME, SP_FINALPOLICY_FUNCTION)
00106     WINTRUST_INITREGENTRY(SoftpubCleanup, SP_POLICY_PROVIDER_DLL_NAME, SP_CLEANUPPOLICY_FUNCTION)
00107     WINTRUST_INITREGENTRY(SoftpubDefCertInit, SP_POLICY_PROVIDER_DLL_NAME, SP_GENERIC_CERT_INIT_FUNCTION)
00108     WINTRUST_INITREGENTRY(SoftpubDumpStructure, SP_POLICY_PROVIDER_DLL_NAME, SP_TESTDUMPPOLICY_FUNCTION_TEST)
00109     WINTRUST_INITREGENTRY(HTTPSCertificateTrust, SP_POLICY_PROVIDER_DLL_NAME, HTTPS_CERTTRUST_FUNCTION)
00110     WINTRUST_INITREGENTRY(HTTPSFinalProv, SP_POLICY_PROVIDER_DLL_NAME, HTTPS_FINALPOLICY_FUNCTION)
00111     WINTRUST_INITREGENTRY(OfficeInitializePolicy, OFFICE_POLICY_PROVIDER_DLL_NAME, OFFICE_INITPROV_FUNCTION)
00112     WINTRUST_INITREGENTRY(OfficeCleanupPolicy, OFFICE_POLICY_PROVIDER_DLL_NAME, OFFICE_CLEANUPPOLICY_FUNCTION)
00113     WINTRUST_INITREGENTRY(DriverInitializePolicy, SP_POLICY_PROVIDER_DLL_NAME, DRIVER_INITPROV_FUNCTION)
00114     WINTRUST_INITREGENTRY(DriverFinalPolicy, SP_POLICY_PROVIDER_DLL_NAME, DRIVER_FINALPOLPROV_FUNCTION)
00115     WINTRUST_INITREGENTRY(DriverCleanupPolicy, SP_POLICY_PROVIDER_DLL_NAME, DRIVER_CLEANUPPOLICY_FUNCTION)
00116     WINTRUST_INITREGENTRY(GenericChainCertificateTrust, SP_POLICY_PROVIDER_DLL_NAME, GENERIC_CHAIN_CERTTRUST_FUNCTION)
00117     WINTRUST_INITREGENTRY(GenericChainFinalProv, SP_POLICY_PROVIDER_DLL_NAME, GENERIC_CHAIN_FINALPOLICY_FUNCTION)
00118 
00119 #undef WINTRUST_INITREGENTRY
00120 }
00121 
00122 /***********************************************************************
00123  *              WINTRUST_FreeRegStructs
00124  *
00125  * Helper function to free 2 members of the CRYPT_TRUST_REG_ENTRY
00126  * structs.
00127  */
00128 static void WINTRUST_FreeRegStructs(void)
00129 {
00130 #define WINTRUST_FREEREGENTRY( action ) \
00131     WINTRUST_Free(action.pwszDLLName); \
00132     WINTRUST_Free(action.pwszFunctionName);
00133 
00134     WINTRUST_FREEREGENTRY(SoftpubInitialization);
00135     WINTRUST_FREEREGENTRY(SoftpubMessage);
00136     WINTRUST_FREEREGENTRY(SoftpubSignature);
00137     WINTRUST_FREEREGENTRY(SoftpubCertficate);
00138     WINTRUST_FREEREGENTRY(SoftpubCertCheck);
00139     WINTRUST_FREEREGENTRY(SoftpubFinalPolicy);
00140     WINTRUST_FREEREGENTRY(SoftpubCleanup);
00141     WINTRUST_FREEREGENTRY(SoftpubDefCertInit);
00142     WINTRUST_FREEREGENTRY(SoftpubDumpStructure);
00143     WINTRUST_FREEREGENTRY(HTTPSCertificateTrust);
00144     WINTRUST_FREEREGENTRY(HTTPSFinalProv);
00145     WINTRUST_FREEREGENTRY(OfficeInitializePolicy);
00146     WINTRUST_FREEREGENTRY(OfficeCleanupPolicy);
00147     WINTRUST_FREEREGENTRY(DriverInitializePolicy);
00148     WINTRUST_FREEREGENTRY(DriverFinalPolicy);
00149     WINTRUST_FREEREGENTRY(DriverCleanupPolicy);
00150     WINTRUST_FREEREGENTRY(GenericChainCertificateTrust);
00151     WINTRUST_FREEREGENTRY(GenericChainFinalProv);
00152 
00153 #undef WINTRUST_FREEREGENTRY
00154 }
00155 
00156 /***********************************************************************
00157  *              WINTRUST_guid2wstr
00158  *
00159  * Create a wide-string from a GUID
00160  *
00161  */
00162 static void WINTRUST_Guid2Wstr(const GUID* pgActionID, WCHAR* GuidString)
00163 { 
00164     static const WCHAR wszFormat[] = {'{','%','0','8','l','X','-','%','0','4','X','-','%','0','4','X','-',
00165                                       '%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2',
00166                                       'X','%','0','2','X','%','0','2','X','}', 0};
00167 
00168     wsprintfW(GuidString, wszFormat, pgActionID->Data1, pgActionID->Data2, pgActionID->Data3,
00169         pgActionID->Data4[0], pgActionID->Data4[1], pgActionID->Data4[2], pgActionID->Data4[3],
00170         pgActionID->Data4[4], pgActionID->Data4[5], pgActionID->Data4[6], pgActionID->Data4[7]);
00171 }
00172 
00173 /***********************************************************************
00174  *              WINTRUST_WriteProviderToReg
00175  *
00176  * Helper function for WintrustAddActionID
00177  *
00178  */
00179 static LONG WINTRUST_WriteProviderToReg(WCHAR* GuidString,
00180                                         const WCHAR* FunctionType,
00181                                         CRYPT_TRUST_REG_ENTRY RegEntry)
00182 {
00183     static const WCHAR Function[] = {'$','F','u','n','c','t','i','o','n', 0};
00184     WCHAR ProvKey[MAX_PATH];
00185     HKEY Key;
00186     LONG Res = ERROR_SUCCESS;
00187 
00188     /* Create the needed key string */
00189     ProvKey[0]='\0';
00190     lstrcatW(ProvKey, Trust);
00191     lstrcatW(ProvKey, FunctionType);
00192     lstrcatW(ProvKey, GuidString);
00193 
00194     if (!RegEntry.pwszDLLName || !RegEntry.pwszFunctionName)
00195         return ERROR_INVALID_PARAMETER;
00196 
00197     Res = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ProvKey, 0, NULL, 0, KEY_WRITE, NULL, &Key, NULL);
00198     if (Res != ERROR_SUCCESS) goto error_close_key;
00199 
00200     /* Create the $DLL entry */
00201     Res = RegSetValueExW(Key, Dll, 0, REG_SZ, (BYTE*)RegEntry.pwszDLLName,
00202         (lstrlenW(RegEntry.pwszDLLName) + 1)*sizeof(WCHAR));
00203     if (Res != ERROR_SUCCESS) goto error_close_key;
00204 
00205     /* Create the $Function entry */
00206     Res = RegSetValueExW(Key, Function, 0, REG_SZ, (BYTE*)RegEntry.pwszFunctionName,
00207         (lstrlenW(RegEntry.pwszFunctionName) + 1)*sizeof(WCHAR));
00208 
00209 error_close_key:
00210     RegCloseKey(Key);
00211 
00212     return Res;
00213 }
00214 
00215 /***********************************************************************
00216  *      WintrustAddActionID (WINTRUST.@)
00217  *
00218  * Add the definitions of the actions a Trust provider can perform to
00219  * the registry.
00220  *
00221  * PARAMS
00222  *   pgActionID [I] Pointer to a GUID for the Trust provider.
00223  *   fdwFlags   [I] Flag to indicate whether registry errors are passed on.
00224  *   psProvInfo [I] Pointer to a structure with information about DLL
00225  *                  name and functions.
00226  *
00227  * RETURNS
00228  *   Success: TRUE.
00229  *   Failure: FALSE. (Use GetLastError() for more information)
00230  *
00231  * NOTES
00232  *   Adding definitions is basically only adding relevant information
00233  *   to the registry. No verification takes place whether a DLL or it's
00234  *   entrypoints exist.
00235  *   Information in the registry will always be overwritten.
00236  *
00237  */
00238 BOOL WINAPI WintrustAddActionID( GUID* pgActionID, DWORD fdwFlags,
00239                                  CRYPT_REGISTER_ACTIONID* psProvInfo)
00240 {
00241     WCHAR GuidString[39];
00242     LONG Res;
00243     LONG WriteActionError = ERROR_SUCCESS;
00244 
00245     TRACE("%s %x %p\n", debugstr_guid(pgActionID), fdwFlags, psProvInfo);
00246 
00247     /* Some sanity checks.
00248      * We use the W2K3 last error as it makes more sense (W2K leaves the last error
00249      * as is).
00250      */
00251     if (!pgActionID ||
00252         !psProvInfo ||
00253         (psProvInfo->cbStruct != sizeof(CRYPT_REGISTER_ACTIONID)))
00254     {
00255         SetLastError(ERROR_INVALID_PARAMETER);
00256         return FALSE;
00257     }
00258 
00259     /* Create this string only once, instead of in the helper function */
00260     WINTRUST_Guid2Wstr( pgActionID, GuidString);
00261 
00262     /* Write the information to the registry */
00263     Res = WINTRUST_WriteProviderToReg(GuidString, Initialization  , psProvInfo->sInitProvider);
00264     if (Res != ERROR_SUCCESS) WriteActionError = Res;
00265     Res = WINTRUST_WriteProviderToReg(GuidString, Message         , psProvInfo->sObjectProvider);
00266     if (Res != ERROR_SUCCESS) WriteActionError = Res;
00267     Res = WINTRUST_WriteProviderToReg(GuidString, Signature       , psProvInfo->sSignatureProvider);
00268     if (Res != ERROR_SUCCESS) WriteActionError = Res;
00269     Res = WINTRUST_WriteProviderToReg(GuidString, Certificate     , psProvInfo->sCertificateProvider);
00270     if (Res != ERROR_SUCCESS) WriteActionError = Res;
00271     Res = WINTRUST_WriteProviderToReg(GuidString, CertCheck       , psProvInfo->sCertificatePolicyProvider);
00272     if (Res != ERROR_SUCCESS) WriteActionError = Res;
00273     Res = WINTRUST_WriteProviderToReg(GuidString, FinalPolicy     , psProvInfo->sFinalPolicyProvider);
00274     if (Res != ERROR_SUCCESS) WriteActionError = Res;
00275     Res = WINTRUST_WriteProviderToReg(GuidString, DiagnosticPolicy, psProvInfo->sTestPolicyProvider);
00276     if (Res != ERROR_SUCCESS) WriteActionError = Res;
00277     Res = WINTRUST_WriteProviderToReg(GuidString, Cleanup         , psProvInfo->sCleanupProvider);
00278     if (Res != ERROR_SUCCESS) WriteActionError = Res;
00279 
00280     /* Testing (by restricting access to the registry for some keys) shows that the last failing function
00281      * will be used for last error.
00282      * If the flag WT_ADD_ACTION_ID_RET_RESULT_FLAG is set and there are errors when adding the action
00283      * we have to return FALSE. Errors includes both invalid entries as well as registry errors.
00284      * Testing also showed that one error doesn't stop the registry writes. Every action will be dealt with.
00285      */
00286 
00287     if (WriteActionError != ERROR_SUCCESS)
00288     {
00289         SetLastError(WriteActionError);
00290 
00291         if (fdwFlags == WT_ADD_ACTION_ID_RET_RESULT_FLAG)
00292             return FALSE;
00293     }
00294 
00295     return TRUE;
00296 }
00297 
00298 /***********************************************************************
00299  *              WINTRUST_RemoveProviderFromReg
00300  *
00301  * Helper function for WintrustRemoveActionID
00302  *
00303  */
00304 static void WINTRUST_RemoveProviderFromReg(WCHAR* GuidString,
00305                                            const WCHAR* FunctionType)
00306 {
00307     WCHAR ProvKey[MAX_PATH];
00308 
00309     /* Create the needed key string */
00310     ProvKey[0]='\0';
00311     lstrcatW(ProvKey, Trust);
00312     lstrcatW(ProvKey, FunctionType);
00313     lstrcatW(ProvKey, GuidString);
00314 
00315     /* We don't care about success or failure */
00316     RegDeleteKeyW(HKEY_LOCAL_MACHINE, ProvKey);
00317 }
00318 
00319 /***********************************************************************
00320  *              WintrustRemoveActionID (WINTRUST.@)
00321  *
00322  * Remove the definitions of the actions a Trust provider can perform
00323  * from the registry.
00324  *
00325  * PARAMS
00326  *   pgActionID [I] Pointer to a GUID for the Trust provider.
00327  *
00328  * RETURNS
00329  *   Success: TRUE. (Use GetLastError() for more information)
00330  *   Failure: FALSE. (Use GetLastError() for more information)
00331  *
00332  * NOTES
00333  *   Testing shows that WintrustRemoveActionID always returns TRUE and
00334  *   that a possible error should be retrieved via GetLastError().
00335  *   There are no checks if the definitions are in the registry.
00336  */
00337 BOOL WINAPI WintrustRemoveActionID( GUID* pgActionID )
00338 {
00339     WCHAR GuidString[39];
00340 
00341     TRACE("(%s)\n", debugstr_guid(pgActionID));
00342  
00343     if (!pgActionID)
00344     {
00345         SetLastError(ERROR_INVALID_PARAMETER);
00346         return TRUE;
00347     }
00348 
00349     /* Create this string only once, instead of in the helper function */
00350     WINTRUST_Guid2Wstr( pgActionID, GuidString);
00351 
00352     /* We don't care about success or failure */
00353     WINTRUST_RemoveProviderFromReg(GuidString, Initialization);
00354     WINTRUST_RemoveProviderFromReg(GuidString, Message);
00355     WINTRUST_RemoveProviderFromReg(GuidString, Signature);
00356     WINTRUST_RemoveProviderFromReg(GuidString, Certificate);
00357     WINTRUST_RemoveProviderFromReg(GuidString, CertCheck);
00358     WINTRUST_RemoveProviderFromReg(GuidString, FinalPolicy);
00359     WINTRUST_RemoveProviderFromReg(GuidString, DiagnosticPolicy);
00360     WINTRUST_RemoveProviderFromReg(GuidString, Cleanup);
00361 
00362     return TRUE;
00363 }
00364 
00365 /***********************************************************************
00366  *              WINTRUST_WriteSingleUsageEntry
00367  *
00368  * Helper for WintrustAddDefaultForUsage, writes a single value and its
00369  * data to:
00370  *
00371  * HKLM\Software\Microsoft\Cryptography\Trust\Usages<OID>
00372  */
00373 static LONG WINTRUST_WriteSingleUsageEntry(LPCSTR OID,
00374                                            const WCHAR* Value,
00375                                            WCHAR* Data)
00376 {
00377     static const WCHAR Usages[] = {'U','s','a','g','e','s','\\', 0};
00378     WCHAR* UsageKey;
00379     HKEY Key;
00380     LONG Res = ERROR_SUCCESS;
00381     WCHAR* OIDW;
00382     DWORD Len;
00383 
00384     /* Turn OID into a wide-character string */
00385     Len = MultiByteToWideChar( CP_ACP, 0, OID, -1, NULL, 0 );
00386     OIDW = WINTRUST_Alloc( Len * sizeof(WCHAR) );
00387     MultiByteToWideChar( CP_ACP, 0, OID, -1, OIDW, Len );
00388 
00389     /* Allocate the needed space for UsageKey */
00390     UsageKey = WINTRUST_Alloc((lstrlenW(Trust) + lstrlenW(Usages) + Len) * sizeof(WCHAR));
00391     /* Create the key string */
00392     lstrcpyW(UsageKey, Trust);
00393     lstrcatW(UsageKey, Usages);
00394     lstrcatW(UsageKey, OIDW);
00395 
00396     Res = RegCreateKeyExW(HKEY_LOCAL_MACHINE, UsageKey, 0, NULL, 0, KEY_WRITE, NULL, &Key, NULL);
00397     if (Res == ERROR_SUCCESS)
00398     {
00399         /* Create the Value entry */
00400         Res = RegSetValueExW(Key, Value, 0, REG_SZ, (BYTE*)Data,
00401                              (lstrlenW(Data) + 1)*sizeof(WCHAR));
00402     }
00403     RegCloseKey(Key);
00404 
00405     WINTRUST_Free(OIDW);
00406     WINTRUST_Free(UsageKey);
00407 
00408     return Res;
00409 }
00410 
00411 /***************************************************************************
00412  *              WINTRUST_RegisterGenVerifyV2
00413  *
00414  * Register WINTRUST_ACTION_GENERIC_VERIFY_V2 actions and usages.
00415  *
00416  * NOTES
00417  *   WINTRUST_ACTION_GENERIC_VERIFY_V2 ({00AAC56B-CD44-11D0-8CC2-00C04FC295EE}
00418  *   is defined in softpub.h
00419  */
00420 static BOOL WINTRUST_RegisterGenVerifyV2(void)
00421 {
00422     BOOL RegisteredOK = TRUE;
00423     static GUID ProvGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2;
00424     CRYPT_REGISTER_ACTIONID ProvInfo;
00425     CRYPT_PROVIDER_REGDEFUSAGE DefUsage = { sizeof(CRYPT_PROVIDER_REGDEFUSAGE),
00426                                             &ProvGUID,
00427                                             NULL,   /* No Dll provided */
00428                                             NULL,   /* No load callback function */
00429                                             NULL }; /* No free callback function */
00430 
00431     ProvInfo.cbStruct                   = sizeof(CRYPT_REGISTER_ACTIONID);
00432     ProvInfo.sInitProvider              = SoftpubInitialization;
00433     ProvInfo.sObjectProvider            = SoftpubMessage;
00434     ProvInfo.sSignatureProvider         = SoftpubSignature;
00435     ProvInfo.sCertificateProvider       = SoftpubCertficate;
00436     ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
00437     ProvInfo.sFinalPolicyProvider       = SoftpubFinalPolicy;
00438     ProvInfo.sTestPolicyProvider        = NullCTRE; /* No diagnostic policy */
00439     ProvInfo.sCleanupProvider           = SoftpubCleanup;
00440 
00441     if (!WintrustAddDefaultForUsage(szOID_PKIX_KP_CODE_SIGNING, &DefUsage))
00442         RegisteredOK = FALSE;
00443 
00444     if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
00445         RegisteredOK = FALSE;
00446 
00447     return RegisteredOK;
00448 }
00449 
00450 /***************************************************************************
00451  *              WINTRUST_RegisterPublishedSoftware
00452  *
00453  * Register WIN_SPUB_ACTION_PUBLISHED_SOFTWARE actions and usages.
00454  *
00455  * NOTES
00456  *   WIN_SPUB_ACTION_PUBLISHED_SOFTWARE ({64B9D180-8DA2-11CF-8736-00AA00A485EB})
00457  *   is defined in wintrust.h
00458  */
00459 static BOOL WINTRUST_RegisterPublishedSoftware(void)
00460 {
00461     static GUID ProvGUID = WIN_SPUB_ACTION_PUBLISHED_SOFTWARE;
00462     CRYPT_REGISTER_ACTIONID ProvInfo;
00463 
00464     ProvInfo.cbStruct                   = sizeof(CRYPT_REGISTER_ACTIONID);
00465     ProvInfo.sInitProvider              = SoftpubInitialization;
00466     ProvInfo.sObjectProvider            = SoftpubMessage;
00467     ProvInfo.sSignatureProvider         = SoftpubSignature;
00468     ProvInfo.sCertificateProvider       = SoftpubCertficate;
00469     ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
00470     ProvInfo.sFinalPolicyProvider       = SoftpubFinalPolicy;
00471     ProvInfo.sTestPolicyProvider        = NullCTRE; /* No diagnostic policy */
00472     ProvInfo.sCleanupProvider           = SoftpubCleanup;
00473 
00474     if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
00475         return FALSE;
00476 
00477     return TRUE;
00478 }
00479 
00480 #define WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI { 0xc6b2e8d0, 0xe005, 0x11cf, { 0xa1,0x34,0x00,0xc0,0x4f,0xd7,0xbf,0x43 }}
00481 
00482 /***************************************************************************
00483  *              WINTRUST_RegisterPublishedSoftwareNoBadUi
00484  *
00485  * Register WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI actions and usages.
00486  *
00487  * NOTES
00488  *   WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI ({C6B2E8D0-E005-11CF-A134-00C04FD7BF43})
00489  *   is not defined in any include file. (FIXME: Find out if the name is correct).
00490  */
00491 static BOOL WINTRUST_RegisterPublishedSoftwareNoBadUi(void)
00492 {
00493     static GUID ProvGUID = WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI;
00494     CRYPT_REGISTER_ACTIONID ProvInfo;
00495 
00496     ProvInfo.cbStruct                   = sizeof(CRYPT_REGISTER_ACTIONID);
00497     ProvInfo.sInitProvider              = SoftpubInitialization;
00498     ProvInfo.sObjectProvider            = SoftpubMessage;
00499     ProvInfo.sSignatureProvider         = SoftpubSignature;
00500     ProvInfo.sCertificateProvider       = SoftpubCertficate;
00501     ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
00502     ProvInfo.sFinalPolicyProvider       = SoftpubFinalPolicy;
00503     ProvInfo.sTestPolicyProvider        = NullCTRE; /* No diagnostic policy */
00504     ProvInfo.sCleanupProvider           = SoftpubCleanup;
00505 
00506     if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
00507         return FALSE;
00508 
00509     return TRUE;
00510 }
00511 
00512 /***************************************************************************
00513  *              WINTRUST_RegisterGenCertVerify
00514  *
00515  * Register WINTRUST_ACTION_GENERIC_CERT_VERIFY actions and usages.
00516  *
00517  * NOTES
00518  *   WINTRUST_ACTION_GENERIC_CERT_VERIFY ({189A3842-3041-11D1-85E1-00C04FC295EE})
00519  *   is defined in softpub.h
00520  */
00521 static BOOL WINTRUST_RegisterGenCertVerify(void)
00522 {
00523     static GUID ProvGUID = WINTRUST_ACTION_GENERIC_CERT_VERIFY;
00524     CRYPT_REGISTER_ACTIONID ProvInfo;
00525 
00526     ProvInfo.cbStruct                   = sizeof(CRYPT_REGISTER_ACTIONID);
00527     ProvInfo.sInitProvider              = SoftpubDefCertInit;
00528     ProvInfo.sObjectProvider            = SoftpubMessage;
00529     ProvInfo.sSignatureProvider         = SoftpubSignature;
00530     ProvInfo.sCertificateProvider       = SoftpubCertficate;
00531     ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
00532     ProvInfo.sFinalPolicyProvider       = SoftpubFinalPolicy;
00533     ProvInfo.sTestPolicyProvider        = NullCTRE; /* No diagnostic policy */
00534     ProvInfo.sCleanupProvider           = SoftpubCleanup;
00535 
00536     if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
00537         return FALSE;
00538 
00539     return TRUE;
00540 }
00541 
00542 /***************************************************************************
00543  *              WINTRUST_RegisterTrustProviderTest
00544  *
00545  * Register WINTRUST_ACTION_TRUSTPROVIDER_TEST actions and usages.
00546  *
00547  * NOTES
00548  *   WINTRUST_ACTION_TRUSTPROVIDER_TEST ({573E31F8-DDBA-11D0-8CCB-00C04FC295EE})
00549  *   is defined in softpub.h
00550  */
00551 static BOOL WINTRUST_RegisterTrustProviderTest(void)
00552 {
00553     static GUID ProvGUID = WINTRUST_ACTION_TRUSTPROVIDER_TEST;
00554     CRYPT_REGISTER_ACTIONID ProvInfo;
00555 
00556     ProvInfo.cbStruct                   = sizeof(CRYPT_REGISTER_ACTIONID);
00557     ProvInfo.sInitProvider              = SoftpubInitialization;
00558     ProvInfo.sObjectProvider            = SoftpubMessage;
00559     ProvInfo.sSignatureProvider         = SoftpubSignature;
00560     ProvInfo.sCertificateProvider       = SoftpubCertficate;
00561     ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
00562     ProvInfo.sFinalPolicyProvider       = SoftpubFinalPolicy;
00563     ProvInfo.sTestPolicyProvider        = SoftpubDumpStructure;
00564     ProvInfo.sCleanupProvider           = SoftpubCleanup;
00565 
00566     if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
00567         return FALSE;
00568 
00569     return TRUE;
00570 }
00571 
00572 /***************************************************************************
00573  *              WINTRUST_RegisterHttpsProv
00574  *
00575  * Register HTTPSPROV_ACTION actions and usages.
00576  *
00577  * NOTES
00578  *   HTTPSPROV_ACTION ({573E31F8-AABA-11D0-8CCB-00C04FC295EE})
00579  *   is defined in softpub.h
00580  */
00581 static BOOL WINTRUST_RegisterHttpsProv(void)
00582 {
00583     BOOL RegisteredOK = TRUE;
00584     static CHAR SoftpubLoadUsage[] = "SoftpubLoadDefUsageCallData";
00585     static CHAR SoftpubFreeUsage[] = "SoftpubFreeDefUsageCallData";
00586     static GUID ProvGUID = HTTPSPROV_ACTION;
00587     CRYPT_REGISTER_ACTIONID ProvInfo;
00588     CRYPT_PROVIDER_REGDEFUSAGE DefUsage = { sizeof(CRYPT_PROVIDER_REGDEFUSAGE),
00589                                             &ProvGUID,
00590                                             NULL, /* Will be filled later */
00591                                             SoftpubLoadUsage,
00592                                             SoftpubFreeUsage };
00593 
00594     ProvInfo.cbStruct                   = sizeof(CRYPT_REGISTER_ACTIONID);
00595     ProvInfo.sInitProvider              = SoftpubInitialization;
00596     ProvInfo.sObjectProvider            = SoftpubMessage;
00597     ProvInfo.sSignatureProvider         = SoftpubSignature;
00598     ProvInfo.sCertificateProvider       = HTTPSCertificateTrust;
00599     ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
00600     ProvInfo.sFinalPolicyProvider       = HTTPSFinalProv;
00601     ProvInfo.sTestPolicyProvider        = NullCTRE; /* No diagnostic policy */
00602     ProvInfo.sCleanupProvider           = SoftpubCleanup;
00603 
00604     DefUsage.pwszDllName = WINTRUST_Alloc(sizeof(SP_POLICY_PROVIDER_DLL_NAME));
00605     lstrcpyW(DefUsage.pwszDllName, SP_POLICY_PROVIDER_DLL_NAME);
00606 
00607     if (!WintrustAddDefaultForUsage(szOID_PKIX_KP_SERVER_AUTH, &DefUsage))
00608         RegisteredOK = FALSE;
00609     if (!WintrustAddDefaultForUsage(szOID_PKIX_KP_CLIENT_AUTH, &DefUsage))
00610         RegisteredOK = FALSE;
00611     if (!WintrustAddDefaultForUsage(szOID_SERVER_GATED_CRYPTO, &DefUsage))
00612         RegisteredOK = FALSE;
00613     if (!WintrustAddDefaultForUsage(szOID_SGC_NETSCAPE, &DefUsage))
00614         RegisteredOK = FALSE;
00615 
00616     WINTRUST_Free(DefUsage.pwszDllName);
00617 
00618     if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
00619         RegisteredOK = FALSE;
00620 
00621     return RegisteredOK;
00622 }
00623 
00624 /***************************************************************************
00625  *              WINTRUST_RegisterOfficeSignVerify
00626  *
00627  * Register OFFICESIGN_ACTION_VERIFY actions and usages.
00628  *
00629  * NOTES
00630  *   OFFICESIGN_ACTION_VERIFY ({5555C2CD-17FB-11D1-85C4-00C04FC295EE})
00631  *   is defined in softpub.h
00632  */
00633 static BOOL WINTRUST_RegisterOfficeSignVerify(void)
00634 {
00635     static GUID ProvGUID = OFFICESIGN_ACTION_VERIFY;
00636     CRYPT_REGISTER_ACTIONID ProvInfo;
00637 
00638     ProvInfo.cbStruct                   = sizeof(CRYPT_REGISTER_ACTIONID);
00639     ProvInfo.sInitProvider              = OfficeInitializePolicy;
00640     ProvInfo.sObjectProvider            = SoftpubMessage;
00641     ProvInfo.sSignatureProvider         = SoftpubSignature;
00642     ProvInfo.sCertificateProvider       = SoftpubCertficate;
00643     ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
00644     ProvInfo.sFinalPolicyProvider       = SoftpubFinalPolicy;
00645     ProvInfo.sTestPolicyProvider        = NullCTRE; /* No diagnostic policy */
00646     ProvInfo.sCleanupProvider           = OfficeCleanupPolicy;
00647 
00648 
00649     if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
00650         return FALSE;
00651 
00652     return TRUE;
00653 }
00654 
00655 /***************************************************************************
00656  *              WINTRUST_RegisterDriverVerify
00657  *
00658  * Register DRIVER_ACTION_VERIFY actions and usages.
00659  *
00660  * NOTES
00661  *   DRIVER_ACTION_VERIFY ({F750E6C3-38EE-11D1-85E5-00C04FC295EE})
00662  *   is defined in softpub.h
00663  */
00664 static BOOL WINTRUST_RegisterDriverVerify(void)
00665 {
00666     static GUID ProvGUID = DRIVER_ACTION_VERIFY;
00667     CRYPT_REGISTER_ACTIONID ProvInfo;
00668 
00669     ProvInfo.cbStruct                   = sizeof(CRYPT_REGISTER_ACTIONID);
00670     ProvInfo.sInitProvider              = DriverInitializePolicy;
00671     ProvInfo.sObjectProvider            = SoftpubMessage;
00672     ProvInfo.sSignatureProvider         = SoftpubSignature;
00673     ProvInfo.sCertificateProvider       = SoftpubCertficate;
00674     ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
00675     ProvInfo.sFinalPolicyProvider       = DriverFinalPolicy;
00676     ProvInfo.sTestPolicyProvider        = NullCTRE; /* No diagnostic policy */
00677     ProvInfo.sCleanupProvider           = DriverCleanupPolicy;
00678 
00679 
00680     if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
00681         return FALSE;
00682 
00683     return TRUE;
00684 }
00685 
00686 /***************************************************************************
00687  *              WINTRUST_RegisterGenChainVerify
00688  *
00689  * Register WINTRUST_ACTION_GENERIC_CHAIN_VERIFY actions and usages.
00690  *
00691  * NOTES
00692  *   WINTRUST_ACTION_GENERIC_CHAIN_VERIFY ({FC451C16-AC75-11D1-B4B8-00C04FB66EA0})
00693  *   is defined in softpub.h
00694  */
00695 static BOOL WINTRUST_RegisterGenChainVerify(void)
00696 {
00697     static GUID ProvGUID = WINTRUST_ACTION_GENERIC_CHAIN_VERIFY;
00698     CRYPT_REGISTER_ACTIONID ProvInfo;
00699 
00700     ProvInfo.cbStruct                   = sizeof(CRYPT_REGISTER_ACTIONID);
00701     ProvInfo.sInitProvider              = SoftpubInitialization;
00702     ProvInfo.sObjectProvider            = SoftpubMessage;
00703     ProvInfo.sSignatureProvider         = SoftpubSignature;
00704     ProvInfo.sCertificateProvider       = GenericChainCertificateTrust;
00705     ProvInfo.sCertificatePolicyProvider = SoftpubCertCheck;
00706     ProvInfo.sFinalPolicyProvider       = GenericChainFinalProv;
00707     ProvInfo.sTestPolicyProvider        = NullCTRE; /* No diagnostic policy */
00708     ProvInfo.sCleanupProvider           = SoftpubCleanup;
00709 
00710     if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
00711         return FALSE;
00712 
00713     return TRUE;
00714 }
00715 
00716 /***********************************************************************
00717  *              WintrustAddDefaultForUsage (WINTRUST.@)
00718  *
00719  * Write OID and callback functions to the registry.
00720  *
00721  * PARAMS
00722  *   pszUsageOID [I] Pointer to a GUID.
00723  *   psDefUsage  [I] Pointer to a structure that specifies the callback functions.
00724  *
00725  * RETURNS
00726  *   Success: TRUE.
00727  *   Failure: FALSE.
00728  *
00729  * NOTES
00730  *   WintrustAddDefaultForUsage will only return TRUE or FALSE, no last 
00731  *   error is set, not even when the registry cannot be written to.
00732  */
00733 BOOL WINAPI WintrustAddDefaultForUsage(const char *pszUsageOID,
00734                                        CRYPT_PROVIDER_REGDEFUSAGE *psDefUsage)
00735 {
00736     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};
00737     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};
00738     LONG Res = ERROR_SUCCESS;
00739     LONG WriteUsageError = ERROR_SUCCESS;
00740     DWORD Len;
00741     WCHAR GuidString[39];
00742 
00743     TRACE("(%s %p)\n", debugstr_a(pszUsageOID), psDefUsage);
00744 
00745     /* Some sanity checks. */
00746     if (!pszUsageOID ||
00747         !psDefUsage ||
00748         !psDefUsage->pgActionID ||
00749         (psDefUsage->cbStruct != sizeof(CRYPT_PROVIDER_REGDEFUSAGE)))
00750     {
00751         SetLastError(ERROR_INVALID_PARAMETER);
00752         return FALSE;
00753     }
00754 
00755     if (psDefUsage->pwszDllName)
00756     {
00757         Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, Dll, psDefUsage->pwszDllName);
00758         if (Res != ERROR_SUCCESS) WriteUsageError = Res;
00759     }
00760     if (psDefUsage->pwszLoadCallbackDataFunctionName)
00761     {
00762         WCHAR* CallbackW;
00763 
00764         Len = MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszLoadCallbackDataFunctionName, -1, NULL, 0 );
00765         CallbackW = WINTRUST_Alloc( Len * sizeof(WCHAR) );
00766         MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszLoadCallbackDataFunctionName, -1, CallbackW, Len );
00767 
00768         Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, CBAlloc, CallbackW);
00769         if (Res != ERROR_SUCCESS) WriteUsageError = Res;
00770 
00771         WINTRUST_Free(CallbackW);
00772     }
00773     if (psDefUsage->pwszFreeCallbackDataFunctionName)
00774     {
00775         WCHAR* CallbackW;
00776 
00777         Len = MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszFreeCallbackDataFunctionName, -1, NULL, 0 );
00778         CallbackW = WINTRUST_Alloc( Len * sizeof(WCHAR) );
00779         MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszFreeCallbackDataFunctionName, -1, CallbackW, Len );
00780 
00781         Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, CBFree, CallbackW);
00782         if (Res != ERROR_SUCCESS) WriteUsageError = Res;
00783 
00784         WINTRUST_Free(CallbackW);
00785     }
00786 
00787     WINTRUST_Guid2Wstr(psDefUsage->pgActionID, GuidString);
00788     Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, DefaultId, GuidString);
00789     if (Res != ERROR_SUCCESS) WriteUsageError = Res;
00790 
00791     if (WriteUsageError != ERROR_SUCCESS)
00792         return FALSE;
00793 
00794     return TRUE;
00795 }
00796 
00797 static FARPROC WINTRUST_ReadProviderFromReg(WCHAR *GuidString, const WCHAR *FunctionType)
00798 {
00799     WCHAR ProvKey[MAX_PATH], DllName[MAX_PATH];
00800     char FunctionName[MAX_PATH];
00801     HKEY Key;
00802     LONG Res = ERROR_SUCCESS;
00803     DWORD Size;
00804     HMODULE Lib;
00805     FARPROC Func = NULL;
00806 
00807     /* Create the needed key string */
00808     ProvKey[0]='\0';
00809     lstrcatW(ProvKey, Trust);
00810     lstrcatW(ProvKey, FunctionType);
00811     lstrcatW(ProvKey, GuidString);
00812 
00813     Res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, ProvKey, 0, KEY_READ, &Key);
00814     if (Res != ERROR_SUCCESS) goto error_close_key;
00815 
00816     /* Read the $DLL entry */
00817     Size = sizeof(DllName);
00818     Res = RegQueryValueExW(Key, Dll, NULL, NULL, (LPBYTE)DllName, &Size);
00819     if (Res != ERROR_SUCCESS) goto error_close_key;
00820 
00821     /* Read the $Function entry */
00822     Size = sizeof(FunctionName);
00823     Res = RegQueryValueExA(Key, "$Function", NULL, NULL, (LPBYTE)FunctionName, &Size);
00824     if (Res != ERROR_SUCCESS) goto error_close_key;
00825 
00826     /* Load the library - there appears to be no way to close a provider, so
00827      * just leak the module handle.
00828      */
00829     Lib = LoadLibraryW(DllName);
00830     Func = GetProcAddress(Lib, FunctionName);
00831 
00832 error_close_key:
00833     RegCloseKey(Key);
00834 
00835     return Func;
00836 }
00837 
00838 /***********************************************************************
00839  *              WintrustLoadFunctionPointers (WINTRUST.@)
00840  */
00841 BOOL WINAPI WintrustLoadFunctionPointers( GUID* pgActionID,
00842                                           CRYPT_PROVIDER_FUNCTIONS* pPfns )
00843 {
00844     WCHAR GuidString[39];
00845 
00846     TRACE("(%s %p)\n", debugstr_guid(pgActionID), pPfns);
00847 
00848     if (!pPfns) return FALSE;
00849     if (!pgActionID)
00850     {
00851         SetLastError(ERROR_INVALID_PARAMETER);
00852         return FALSE;
00853     }
00854     if (pPfns->cbStruct != sizeof(CRYPT_PROVIDER_FUNCTIONS)) return FALSE;
00855 
00856     /* Create this string only once, instead of in the helper function */
00857     WINTRUST_Guid2Wstr( pgActionID, GuidString);
00858 
00859     /* Get the function pointers from the registry, where applicable */
00860     pPfns->pfnAlloc = WINTRUST_Alloc;
00861     pPfns->pfnFree = WINTRUST_Free;
00862     pPfns->pfnAddStore2Chain = WINTRUST_AddStore;
00863     pPfns->pfnAddSgnr2Chain = WINTRUST_AddSgnr;
00864     pPfns->pfnAddCert2Chain = WINTRUST_AddCert;
00865     pPfns->pfnAddPrivData2Chain = WINTRUST_AddPrivData;
00866     pPfns->psUIpfns = NULL;
00867     pPfns->pfnInitialize = (PFN_PROVIDER_INIT_CALL)WINTRUST_ReadProviderFromReg(GuidString, Initialization);
00868     pPfns->pfnObjectTrust = (PFN_PROVIDER_OBJTRUST_CALL)WINTRUST_ReadProviderFromReg(GuidString, Message);
00869     pPfns->pfnSignatureTrust = (PFN_PROVIDER_SIGTRUST_CALL)WINTRUST_ReadProviderFromReg(GuidString, Signature);
00870     pPfns->pfnCertificateTrust = (PFN_PROVIDER_CERTTRUST_CALL)WINTRUST_ReadProviderFromReg(GuidString, Certificate);
00871     pPfns->pfnCertCheckPolicy = (PFN_PROVIDER_CERTCHKPOLICY_CALL)WINTRUST_ReadProviderFromReg(GuidString, CertCheck);
00872     pPfns->pfnFinalPolicy = (PFN_PROVIDER_FINALPOLICY_CALL)WINTRUST_ReadProviderFromReg(GuidString, FinalPolicy);
00873     pPfns->pfnTestFinalPolicy = (PFN_PROVIDER_TESTFINALPOLICY_CALL)WINTRUST_ReadProviderFromReg(GuidString, DiagnosticPolicy);
00874     pPfns->pfnCleanupPolicy = (PFN_PROVIDER_CLEANUP_CALL)WINTRUST_ReadProviderFromReg(GuidString, Cleanup);
00875 
00876     return TRUE;
00877 }
00878 
00879 /***********************************************************************
00880  *              WINTRUST_SIPPAddProvider
00881  *
00882  * Helper for DllRegisterServer.
00883  */
00884 static BOOL WINTRUST_SIPPAddProvider(GUID* Subject, WCHAR* MagicNumber)
00885 {
00886     static WCHAR CryptSIPGetSignedDataMsg[] =
00887         {'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};
00888     static WCHAR CryptSIPPutSignedDataMsg[] =
00889         {'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};
00890     static WCHAR CryptSIPCreateIndirectData[] =
00891         {'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};
00892     static WCHAR CryptSIPVerifyIndirectData[] =
00893         {'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};
00894     static WCHAR CryptSIPRemoveSignedDataMsg[] =
00895         {'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};
00896     SIP_ADD_NEWPROVIDER NewProv;
00897     BOOL Ret;
00898 
00899     /* Clear and initialize the structure */
00900     memset(&NewProv, 0, sizeof(SIP_ADD_NEWPROVIDER));
00901     NewProv.cbStruct = sizeof(SIP_ADD_NEWPROVIDER);
00902     NewProv.pwszDLLFileName = WINTRUST_Alloc(sizeof(SP_POLICY_PROVIDER_DLL_NAME));
00903     /* Fill the structure */
00904     NewProv.pgSubject              = Subject;
00905     lstrcpyW(NewProv.pwszDLLFileName, SP_POLICY_PROVIDER_DLL_NAME);
00906     NewProv.pwszMagicNumber        = MagicNumber;
00907     NewProv.pwszIsFunctionName     = NULL;
00908     NewProv.pwszGetFuncName        = CryptSIPGetSignedDataMsg;
00909     NewProv.pwszPutFuncName        = CryptSIPPutSignedDataMsg;
00910     NewProv.pwszCreateFuncName     = CryptSIPCreateIndirectData;
00911     NewProv.pwszVerifyFuncName     = CryptSIPVerifyIndirectData;
00912     NewProv.pwszRemoveFuncName     = CryptSIPRemoveSignedDataMsg;
00913     NewProv.pwszIsFunctionNameFmt2 = NULL;
00914 
00915     Ret = CryptSIPAddProvider(&NewProv);
00916 
00917     WINTRUST_Free(NewProv.pwszDLLFileName);
00918  
00919     return Ret;
00920 }
00921 
00922 /***********************************************************************
00923  *              DllRegisterServer (WINTRUST.@)
00924  */
00925 HRESULT WINAPI DllRegisterServer(void)
00926 {
00927     static const CHAR SpcPeImageDataEncode[]           = "WVTAsn1SpcPeImageDataEncode";
00928     static const CHAR SpcPeImageDataDecode[]           = "WVTAsn1SpcPeImageDataDecode";
00929     static const CHAR SpcLinkEncode[]                  = "WVTAsn1SpcLinkEncode";
00930     static const CHAR SpcLinkDecode[]                  = "WVTAsn1SpcLinkDecode";
00931     static const CHAR SpcSigInfoEncode[]               = "WVTAsn1SpcSigInfoEncode";
00932     static const CHAR SpcSigInfoDecode[]               = "WVTAsn1SpcSigInfoDecode";
00933     static const CHAR SpcIndirectDataContentEncode[]   = "WVTAsn1SpcIndirectDataContentEncode";
00934     static const CHAR SpcIndirectDataContentDecode[]   = "WVTAsn1SpcIndirectDataContentDecode";
00935     static const CHAR SpcSpAgencyInfoEncode[]          = "WVTAsn1SpcSpAgencyInfoEncode";
00936     static const CHAR SpcSpAgencyInfoDecode[]          = "WVTAsn1SpcSpAgencyInfoDecode";
00937     static const CHAR SpcMinimalCriteriaInfoEncode[]   = "WVTAsn1SpcMinimalCriteriaInfoEncode";
00938     static const CHAR SpcMinimalCriteriaInfoDecode[]   = "WVTAsn1SpcMinimalCriteriaInfoDecode";
00939     static const CHAR SpcFinancialCriteriaInfoEncode[] = "WVTAsn1SpcFinancialCriteriaInfoEncode";
00940     static const CHAR SpcFinancialCriteriaInfoDecode[] = "WVTAsn1SpcFinancialCriteriaInfoDecode";
00941     static const CHAR SpcStatementTypeEncode[]         = "WVTAsn1SpcStatementTypeEncode";
00942     static const CHAR SpcStatementTypeDecode[]         = "WVTAsn1SpcStatementTypeDecode";
00943     static const CHAR CatNameValueEncode[]             = "WVTAsn1CatNameValueEncode";
00944     static const CHAR CatNameValueDecode[]             = "WVTAsn1CatNameValueDecode";
00945     static const CHAR CatMemberInfoEncode[]            = "WVTAsn1CatMemberInfoEncode";
00946     static const CHAR CatMemberInfoDecode[]            = "WVTAsn1CatMemberInfoDecode";
00947     static const CHAR SpcSpOpusInfoEncode[]            = "WVTAsn1SpcSpOpusInfoEncode";
00948     static const CHAR SpcSpOpusInfoDecode[]            = "WVTAsn1SpcSpOpusInfoDecode";
00949     static GUID Unknown1 = { 0xDE351A42, 0x8E59, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
00950     static GUID Unknown2 = { 0xC689AABA, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
00951     static GUID Unknown3 = { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
00952     static GUID Unknown4 = { 0xC689AAB9, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
00953     static GUID Unknown5 = { 0xDE351A43, 0x8E59, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
00954     static GUID Unknown6 = { 0x9BA61D3F, 0xE73A, 0x11D0, { 0x8C,0xD2,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
00955     static WCHAR MagicNumber2[] = {'M','S','C','F', 0};
00956     static WCHAR MagicNumber3[] = {'0','x','0','0','0','0','4','5','5','0', 0};
00957     static WCHAR CafeBabe[] = {'0','x','c','a','f','e','b','a','b','e', 0};
00958 
00959     HRESULT CryptRegisterRes = S_OK;
00960     HRESULT TrustProviderRes = S_OK;
00961     HRESULT SIPAddProviderRes = S_OK;
00962 
00963     TRACE("\n");
00964 
00965     /* Testing on native shows that when an error is encountered in one of the CryptRegisterOIDFunction calls
00966      * the rest of these calls is skipped. Registering is however continued for the trust providers.
00967      *
00968      * We are not totally in line with native as there all decoding functions are registered after all encoding
00969      * functions.
00970      */
00971 #define WINTRUST_REGISTEROID( oid, encode_funcname, decode_funcname ) \
00972     do { \
00973         if (!CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_ENCODE_OBJECT_FUNC, oid, SP_POLICY_PROVIDER_DLL_NAME, encode_funcname)) \
00974         {                                                               \
00975             CryptRegisterRes = HRESULT_FROM_WIN32(GetLastError());      \
00976             goto add_trust_providers;                                   \
00977         }                                                               \
00978         if (!CryptRegisterOIDFunction(X509_ASN_ENCODING, CRYPT_OID_DECODE_OBJECT_FUNC, oid, SP_POLICY_PROVIDER_DLL_NAME, decode_funcname)) \
00979         {                                                               \
00980             CryptRegisterRes = HRESULT_FROM_WIN32(GetLastError());      \
00981             goto add_trust_providers;                                   \
00982         }                                                               \
00983     } while (0)
00984 
00985     WINTRUST_REGISTEROID(SPC_PE_IMAGE_DATA_OBJID, SpcPeImageDataEncode, SpcPeImageDataDecode);
00986     WINTRUST_REGISTEROID(SPC_PE_IMAGE_DATA_STRUCT, SpcPeImageDataEncode, SpcPeImageDataDecode);
00987     WINTRUST_REGISTEROID(SPC_CAB_DATA_OBJID, SpcLinkEncode, SpcLinkDecode);
00988     WINTRUST_REGISTEROID(SPC_CAB_DATA_STRUCT, SpcLinkEncode, SpcLinkDecode);
00989     WINTRUST_REGISTEROID(SPC_JAVA_CLASS_DATA_OBJID, SpcLinkEncode, SpcLinkDecode);
00990     WINTRUST_REGISTEROID(SPC_JAVA_CLASS_DATA_STRUCT, SpcLinkEncode, SpcLinkDecode);
00991     WINTRUST_REGISTEROID(SPC_LINK_OBJID, SpcLinkEncode, SpcLinkDecode);
00992     WINTRUST_REGISTEROID(SPC_LINK_STRUCT, SpcLinkEncode, SpcLinkDecode);
00993     WINTRUST_REGISTEROID(SPC_SIGINFO_OBJID, SpcSigInfoEncode, SpcSigInfoDecode);
00994     WINTRUST_REGISTEROID(SPC_SIGINFO_STRUCT, SpcSigInfoEncode, SpcSigInfoDecode);
00995     WINTRUST_REGISTEROID(SPC_INDIRECT_DATA_OBJID, SpcIndirectDataContentEncode, SpcIndirectDataContentDecode);
00996     WINTRUST_REGISTEROID(SPC_INDIRECT_DATA_CONTENT_STRUCT, SpcIndirectDataContentEncode, SpcIndirectDataContentDecode);
00997     WINTRUST_REGISTEROID(SPC_SP_AGENCY_INFO_OBJID, SpcSpAgencyInfoEncode, SpcSpAgencyInfoDecode);
00998     WINTRUST_REGISTEROID(SPC_SP_AGENCY_INFO_STRUCT, SpcSpAgencyInfoEncode, SpcSpAgencyInfoDecode);
00999     WINTRUST_REGISTEROID(SPC_MINIMAL_CRITERIA_OBJID, SpcMinimalCriteriaInfoEncode, SpcMinimalCriteriaInfoDecode);
01000     WINTRUST_REGISTEROID(SPC_MINIMAL_CRITERIA_STRUCT, SpcMinimalCriteriaInfoEncode, SpcMinimalCriteriaInfoDecode);
01001     WINTRUST_REGISTEROID(SPC_FINANCIAL_CRITERIA_OBJID, SpcFinancialCriteriaInfoEncode, SpcFinancialCriteriaInfoDecode);
01002     WINTRUST_REGISTEROID(SPC_FINANCIAL_CRITERIA_STRUCT, SpcFinancialCriteriaInfoEncode, SpcFinancialCriteriaInfoDecode);
01003     WINTRUST_REGISTEROID(SPC_STATEMENT_TYPE_OBJID, SpcStatementTypeEncode, SpcStatementTypeDecode);
01004     WINTRUST_REGISTEROID(SPC_STATEMENT_TYPE_STRUCT, SpcStatementTypeEncode, SpcStatementTypeDecode);
01005     WINTRUST_REGISTEROID(CAT_NAMEVALUE_OBJID, CatNameValueEncode, CatNameValueDecode);
01006     WINTRUST_REGISTEROID(CAT_NAMEVALUE_STRUCT, CatNameValueEncode, CatNameValueDecode);
01007     WINTRUST_REGISTEROID(CAT_MEMBERINFO_OBJID, CatMemberInfoEncode, CatMemberInfoDecode);
01008     WINTRUST_REGISTEROID(CAT_MEMBERINFO_STRUCT, CatMemberInfoEncode, CatMemberInfoDecode);
01009     WINTRUST_REGISTEROID(SPC_SP_OPUS_INFO_OBJID, SpcSpOpusInfoEncode, SpcSpOpusInfoDecode);
01010     WINTRUST_REGISTEROID(SPC_SP_OPUS_INFO_STRUCT, SpcSpOpusInfoEncode,  SpcSpOpusInfoDecode);
01011 
01012 #undef WINTRUST_REGISTEROID
01013 
01014 add_trust_providers:
01015 
01016     /* Testing on W2K3 shows:
01017      * All registry writes are tried. If one fails this part will return S_FALSE.
01018      *
01019      * Last error is set to the last error encountered, regardless if the first
01020      * part failed or not.
01021      */
01022 
01023     /* Create the necessary action registry structures */
01024     WINTRUST_InitRegStructs();
01025 
01026     /* Register several Trust Provider actions */
01027     if (!WINTRUST_RegisterGenVerifyV2())
01028         TrustProviderRes = S_FALSE;
01029     if (!WINTRUST_RegisterPublishedSoftware())
01030         TrustProviderRes = S_FALSE;
01031     if (!WINTRUST_RegisterPublishedSoftwareNoBadUi())
01032         TrustProviderRes = S_FALSE;
01033     if (!WINTRUST_RegisterGenCertVerify())
01034         TrustProviderRes = S_FALSE;
01035     if (!WINTRUST_RegisterTrustProviderTest())
01036         TrustProviderRes = S_FALSE;
01037     if (!WINTRUST_RegisterHttpsProv())
01038         TrustProviderRes = S_FALSE;
01039     if (!WINTRUST_RegisterOfficeSignVerify())
01040         TrustProviderRes = S_FALSE;
01041     if (!WINTRUST_RegisterDriverVerify())
01042         TrustProviderRes = S_FALSE;
01043     if (!WINTRUST_RegisterGenChainVerify())
01044         TrustProviderRes = S_FALSE;
01045 
01046     /* Free the registry structures */
01047     WINTRUST_FreeRegStructs();
01048 
01049     /* Testing on W2K3 shows:
01050      * All registry writes are tried. If one fails this part will return S_FALSE.
01051      *
01052      * Last error is set to the last error encountered, regardless if the previous
01053      * parts failed or not.
01054      */
01055 
01056     if (!WINTRUST_SIPPAddProvider(&Unknown1, NULL))
01057         SIPAddProviderRes = S_FALSE;
01058     if (!WINTRUST_SIPPAddProvider(&Unknown2, MagicNumber2))
01059         SIPAddProviderRes = S_FALSE;
01060     if (!WINTRUST_SIPPAddProvider(&Unknown3, MagicNumber3))
01061         SIPAddProviderRes = S_FALSE;
01062     if (!WINTRUST_SIPPAddProvider(&Unknown4, CafeBabe))
01063         SIPAddProviderRes = S_FALSE;
01064     if (!WINTRUST_SIPPAddProvider(&Unknown5, CafeBabe))
01065         SIPAddProviderRes = S_FALSE;
01066     if (!WINTRUST_SIPPAddProvider(&Unknown6, CafeBabe))
01067         SIPAddProviderRes = S_FALSE;
01068 
01069     /* Native does a CryptSIPRemoveProvider here for {941C2937-1292-11D1-85BE-00C04FC295EE}.
01070      * This SIP Provider is however not found on up-to-date window install and native will
01071      * set the last error to ERROR_FILE_NOT_FOUND.
01072      * Wine has the last error set to ERROR_INVALID_PARAMETER. There shouldn't be an app
01073      * depending on this last error though so there is no need to imitate native to the full extent.
01074      *
01075      * (The ERROR_INVALID_PARAMETER for Wine it totally valid as we (and native) do register
01076      * a trust provider without a diagnostic policy).
01077      */
01078 
01079     /* If CryptRegisterRes is not S_OK it will always overrule the return value. */
01080     if (CryptRegisterRes != S_OK)
01081         return CryptRegisterRes;
01082     else if (SIPAddProviderRes == S_OK)
01083         return TrustProviderRes;
01084     else 
01085         return SIPAddProviderRes;
01086 }
01087 
01088 /***********************************************************************
01089  *              DllUnregisterServer (WINTRUST.@)
01090  */
01091 HRESULT WINAPI DllUnregisterServer(void)
01092 {
01093      FIXME("stub\n");
01094      return S_OK;
01095 }
01096 
01097 /***********************************************************************
01098  *              SoftpubDllRegisterServer (WINTRUST.@)
01099  *
01100  * Registers softpub.dll
01101  *
01102  * PARAMS
01103  *
01104  * RETURNS
01105  *  Success: S_OK.
01106  *  Failure: S_FALSE. (See also GetLastError()).
01107  *
01108  * NOTES
01109  *  DllRegisterServer in softpub.dll will call this function.
01110  *  See comments in DllRegisterServer.
01111  */
01112 HRESULT WINAPI SoftpubDllRegisterServer(void)
01113 {
01114     HRESULT TrustProviderRes = S_OK;
01115 
01116     TRACE("\n");
01117 
01118     /* Create the necessary action registry structures */
01119     WINTRUST_InitRegStructs();
01120 
01121     /* Register several Trust Provider actions */
01122     if (!WINTRUST_RegisterGenVerifyV2())
01123         TrustProviderRes = S_FALSE;
01124     if (!WINTRUST_RegisterPublishedSoftware())
01125         TrustProviderRes = S_FALSE;
01126     if (!WINTRUST_RegisterPublishedSoftwareNoBadUi())
01127         TrustProviderRes = S_FALSE;
01128     if (!WINTRUST_RegisterGenCertVerify())
01129         TrustProviderRes = S_FALSE;
01130     if (!WINTRUST_RegisterTrustProviderTest())
01131         TrustProviderRes = S_FALSE;
01132     if (!WINTRUST_RegisterHttpsProv())
01133         TrustProviderRes = S_FALSE;
01134     if (!WINTRUST_RegisterOfficeSignVerify())
01135         TrustProviderRes = S_FALSE;
01136     if (!WINTRUST_RegisterDriverVerify())
01137         TrustProviderRes = S_FALSE;
01138     if (!WINTRUST_RegisterGenChainVerify())
01139         TrustProviderRes = S_FALSE;
01140 
01141     /* Free the registry structures */
01142     WINTRUST_FreeRegStructs();
01143 
01144     return TrustProviderRes;
01145 }
01146 
01147 /***********************************************************************
01148  *              SoftpubDllUnregisterServer (WINTRUST.@)
01149  */
01150 HRESULT WINAPI SoftpubDllUnregisterServer(void)
01151 {
01152      FIXME("stub\n");
01153      return S_OK;
01154 }
01155 
01156 /***********************************************************************
01157  *              mscat32DllRegisterServer (WINTRUST.@)
01158  */
01159 HRESULT WINAPI mscat32DllRegisterServer(void)
01160 {
01161      FIXME("stub\n");
01162      return S_OK;
01163 }
01164 
01165 /***********************************************************************
01166  *              mscat32DllUnregisterServer (WINTRUST.@)
01167  */
01168 HRESULT WINAPI mscat32DllUnregisterServer(void)
01169 {
01170      FIXME("stub\n");
01171      return S_OK;
01172 }
01173 
01174 /***********************************************************************
01175  *              mssip32DllRegisterServer (WINTRUST.@)
01176  */
01177 HRESULT WINAPI mssip32DllRegisterServer(void)
01178 {
01179      FIXME("stub\n");
01180      return S_OK;
01181 }
01182 
01183 /***********************************************************************
01184  *              mssip32DllUnregisterServer (WINTRUST.@)
01185  */
01186 HRESULT WINAPI mssip32DllUnregisterServer(void)
01187 {
01188      FIXME("stub\n");
01189      return S_OK;
01190 }

Generated on Sun May 27 2012 04:27:01 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.