📄 register.c
字号:
if (Res != ERROR_SUCCESS) WriteActionError = Res;
Res = WINTRUST_WriteProviderToReg(GuidString, Cleanup , psProvInfo->sCleanupProvider);
if (Res != ERROR_SUCCESS) WriteActionError = Res;
/* Testing (by restricting access to the registry for some keys) shows that the last failing function
* will be used for last error.
* If the flag WT_ADD_ACTION_ID_RET_RESULT_FLAG is set and there are errors when adding the action
* we have to return FALSE. Errors includes both invalid entries as well as registry errors.
* Testing also showed that one error doesn't stop the registry writes. Every action will be dealt with.
*/
if (WriteActionError != ERROR_SUCCESS)
{
SetLastError(WriteActionError);
if (fdwFlags == WT_ADD_ACTION_ID_RET_RESULT_FLAG)
return FALSE;
}
return TRUE;
}
/***********************************************************************
* WINTRUST_RemoveProviderFromReg
*
* Helper function for WintrustRemoveActionID
*
*/
static void WINTRUST_RemoveProviderFromReg(WCHAR* GuidString,
const WCHAR* FunctionType)
{
WCHAR ProvKey[MAX_PATH];
/* Create the needed key string */
ProvKey[0]='\0';
lstrcatW(ProvKey, Trust);
lstrcatW(ProvKey, FunctionType);
lstrcatW(ProvKey, GuidString);
/* We don't care about success or failure */
RegDeleteKeyW(HKEY_LOCAL_MACHINE, ProvKey);
}
/***********************************************************************
* WintrustRemoveActionID (WINTRUST.@)
*
* Remove the definitions of the actions a Trust provider can perform
* from the registry.
*
* PARAMS
* pgActionID [I] Pointer to a GUID for the Trust provider.
*
* RETURNS
* Success: TRUE. (Use GetLastError() for more information)
* Failure: FALSE. (Use GetLastError() for more information)
*
* NOTES
* Testing shows that WintrustRemoveActionID always returns TRUE and
* that a possible error should be retrieved via GetLastError().
* There are no checks if the definitions are in the registry.
*/
BOOL WINAPI WintrustRemoveActionID( GUID* pgActionID )
{
WCHAR GuidString[39];
TRACE("(%s)\n", debugstr_guid(pgActionID));
if (!pgActionID)
{
SetLastError(ERROR_INVALID_PARAMETER);
return TRUE;
}
/* Create this string only once, instead of in the helper function */
WINTRUST_Guid2Wstr( pgActionID, GuidString);
/* We don't care about success or failure */
WINTRUST_RemoveProviderFromReg(GuidString, Initialization);
WINTRUST_RemoveProviderFromReg(GuidString, Message);
WINTRUST_RemoveProviderFromReg(GuidString, Signature);
WINTRUST_RemoveProviderFromReg(GuidString, Certificate);
WINTRUST_RemoveProviderFromReg(GuidString, CertCheck);
WINTRUST_RemoveProviderFromReg(GuidString, FinalPolicy);
WINTRUST_RemoveProviderFromReg(GuidString, DiagnosticPolicy);
WINTRUST_RemoveProviderFromReg(GuidString, Cleanup);
return TRUE;
}
/***********************************************************************
* WINTRUST_WriteSingleUsageEntry
*
* Helper for WintrustAddDefaultForUsage, writes a single value and its
* data to:
*
* HKLM\Software\Microsoft\Cryptography\Trust\Usages\<OID>
*/
static LONG WINTRUST_WriteSingleUsageEntry(LPCSTR OID,
const WCHAR* Value,
WCHAR* Data)
{
static const WCHAR Usages[] = {'U','s','a','g','e','s','\\', 0};
WCHAR* UsageKey;
HKEY Key;
LONG Res = ERROR_SUCCESS;
WCHAR* OIDW;
DWORD Len;
/* Turn OID into a wide-character string */
Len = MultiByteToWideChar( CP_ACP, 0, OID, -1, NULL, 0 );
OIDW = HeapAlloc( GetProcessHeap(), 0, Len * sizeof(WCHAR) );
MultiByteToWideChar( CP_ACP, 0, OID, -1, OIDW, Len );
/* Allocate the needed space for UsageKey */
UsageKey = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(Trust) + lstrlenW(Usages) + Len) * sizeof(WCHAR));
/* Create the key string */
lstrcpyW(UsageKey, Trust);
lstrcatW(UsageKey, Usages);
lstrcatW(UsageKey, OIDW);
Res = RegCreateKeyExW(HKEY_LOCAL_MACHINE, UsageKey, 0, NULL, 0, KEY_WRITE, NULL, &Key, NULL);
if (Res == ERROR_SUCCESS)
{
/* Create the Value entry */
Res = RegSetValueExW(Key, Value, 0, REG_SZ, (BYTE*)Data,
(lstrlenW(Data) + 1)*sizeof(WCHAR));
}
RegCloseKey(Key);
HeapFree(GetProcessHeap(), 0, OIDW);
HeapFree(GetProcessHeap(), 0, UsageKey);
return Res;
}
/***************************************************************************
* WINTRUST_RegisterGenVerifyV2
*
* Register WINTRUST_ACTION_GENERIC_VERIFY_V2 actions and usages.
*
* NOTES
* WINTRUST_ACTION_GENERIC_VERIFY_V2 ({00AAC56B-CD44-11D0-8CC2-00C04FC295EE}
* is defined in softpub.h
*/
static BOOL WINTRUST_RegisterGenVerifyV2(void)
{
BOOL RegisteredOK = TRUE;
static GUID ProvGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2;
CRYPT_REGISTER_ACTIONID ProvInfo = { sizeof(CRYPT_REGISTER_ACTIONID),
SoftpubInitialization,
SoftpubMessage,
SoftpubSignature,
SoftpubCertficate,
SoftpubCertCheck,
SoftpubFinalPolicy,
{ 0, NULL, NULL }, /* No diagnostic policy */
SoftpubCleanup };
CRYPT_PROVIDER_REGDEFUSAGE DefUsage = { sizeof(CRYPT_PROVIDER_REGDEFUSAGE),
&ProvGUID,
NULL, /* No Dll provided */
NULL, /* No load callback function */
NULL }; /* No free callback function */
if (!WintrustAddDefaultForUsage(szOID_PKIX_KP_CODE_SIGNING, &DefUsage))
RegisteredOK = FALSE;
if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
RegisteredOK = FALSE;
return RegisteredOK;
}
/***************************************************************************
* WINTRUST_RegisterPublishedSoftware
*
* Register WIN_SPUB_ACTION_PUBLISHED_SOFTWARE actions and usages.
*
* NOTES
* WIN_SPUB_ACTION_PUBLISHED_SOFTWARE ({64B9D180-8DA2-11CF-8736-00AA00A485EB})
* is defined in wintrust.h
*/
static BOOL WINTRUST_RegisterPublishedSoftware(void)
{
static GUID ProvGUID = WIN_SPUB_ACTION_PUBLISHED_SOFTWARE;
CRYPT_REGISTER_ACTIONID ProvInfo = { sizeof(CRYPT_REGISTER_ACTIONID),
SoftpubInitialization,
SoftpubMessage,
SoftpubSignature,
SoftpubCertficate,
SoftpubCertCheck,
SoftpubFinalPolicy,
{ 0, NULL, NULL }, /* No diagnostic policy */
SoftpubCleanup };
if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
return FALSE;
return TRUE;
}
#define WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI { 0xc6b2e8d0, 0xe005, 0x11cf, { 0xa1,0x34,0x00,0xc0,0x4f,0xd7,0xbf,0x43 }}
/***************************************************************************
* WINTRUST_RegisterPublishedSoftwareNoBadUi
*
* Register WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI actions and usages.
*
* NOTES
* WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI ({C6B2E8D0-E005-11CF-A134-00C04FD7BF43})
* is not defined in any include file. (FIXME: Find out if the name is correct).
*/
static BOOL WINTRUST_RegisterPublishedSoftwareNoBadUi(void)
{
static GUID ProvGUID = WIN_SPUB_ACTION_PUBLISHED_SOFTWARE_NOBADUI;
CRYPT_REGISTER_ACTIONID ProvInfo = { sizeof(CRYPT_REGISTER_ACTIONID),
SoftpubInitialization,
SoftpubMessage,
SoftpubSignature,
SoftpubCertficate,
SoftpubCertCheck,
SoftpubFinalPolicy,
{ 0, NULL, NULL }, /* No diagnostic policy */
SoftpubCleanup };
if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
return FALSE;
return TRUE;
}
/***************************************************************************
* WINTRUST_RegisterGenCertVerify
*
* Register WINTRUST_ACTION_GENERIC_CERT_VERIFY actions and usages.
*
* NOTES
* WINTRUST_ACTION_GENERIC_CERT_VERIFY ({189A3842-3041-11D1-85E1-00C04FC295EE})
* is defined in softpub.h
*/
static BOOL WINTRUST_RegisterGenCertVerify(void)
{
static GUID ProvGUID = WINTRUST_ACTION_GENERIC_CERT_VERIFY;
CRYPT_REGISTER_ACTIONID ProvInfo = { sizeof(CRYPT_REGISTER_ACTIONID),
SoftpubDefCertInit,
SoftpubMessage,
SoftpubSignature,
SoftpubCertficate,
SoftpubCertCheck,
SoftpubFinalPolicy,
{ 0, NULL, NULL }, /* No diagnostic policy */
SoftpubCleanup };
if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
return FALSE;
return TRUE;
}
/***************************************************************************
* WINTRUST_RegisterTrustProviderTest
*
* Register WINTRUST_ACTION_TRUSTPROVIDER_TEST actions and usages.
*
* NOTES
* WINTRUST_ACTION_TRUSTPROVIDER_TEST ({573E31F8-DDBA-11D0-8CCB-00C04FC295EE})
* is defined in softpub.h
*/
static BOOL WINTRUST_RegisterTrustProviderTest(void)
{
static GUID ProvGUID = WINTRUST_ACTION_TRUSTPROVIDER_TEST;
CRYPT_REGISTER_ACTIONID ProvInfo = { sizeof(CRYPT_REGISTER_ACTIONID),
SoftpubInitialization,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -