aboutsummaryrefslogtreecommitdiff
path: root/src/ext/Util/be/detectsha2support.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ext/Util/be/detectsha2support.cpp')
-rw-r--r--src/ext/Util/be/detectsha2support.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/ext/Util/be/detectsha2support.cpp b/src/ext/Util/be/detectsha2support.cpp
new file mode 100644
index 00000000..90e349cd
--- /dev/null
+++ b/src/ext/Util/be/detectsha2support.cpp
@@ -0,0 +1,58 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3#include "precomp.h"
4
5// https://gist.github.com/navossoc/7572c7d82243e9f818989e2765e7793a
6HRESULT DetectSHA2CodeSigning(
7 __out BOOL* pfSupported
8 )
9{
10 HRESULT hr = S_OK;
11 HMODULE hModule = NULL;
12 FARPROC pfn = NULL;
13 DWORD er = ERROR_SUCCESS;
14
15 hr = LoadSystemLibrary(L"wintrust.dll", &hModule);
16 ExitOnFailure(hr, "Failed to load wintrust.dll");
17
18 pfn = ::GetProcAddress(hModule, "CryptCATAdminAcquireContext2");
19 if (pfn)
20 {
21 *pfSupported = TRUE;
22 ExitFunction1(hr = S_OK);
23 }
24
25 er = ::GetLastError();
26 if (er == ERROR_PROC_NOT_FOUND)
27 {
28 *pfSupported = FALSE;
29 ExitFunction1(hr = S_OK);
30 }
31
32 hr = HRESULT_FROM_WIN32(er);
33 ExitOnFailure(hr, "Failed to probe for CryptCATAdminAcquireContext2 in wintrust.dll");
34
35LExit:
36 ::FreeLibrary(hModule);
37
38 return hr;
39}
40
41HRESULT UtilPerformDetectSHA2CodeSigning(
42 __in LPCWSTR wzVariable,
43 __in UTIL_SEARCH* /*pSearch*/,
44 __in IBundleExtensionEngine* pEngine
45 )
46{
47 HRESULT hr = S_OK;
48 BOOL fSupported = FALSE;
49
50 hr = DetectSHA2CodeSigning(&fSupported);
51 ExitOnFailure(hr, "DetectSHA2CodeSigning failed.");
52
53 hr = pEngine->SetVariableNumeric(wzVariable, fSupported ? 1 : 0);
54 ExitOnFailure(hr, "Failed to set variable '%ls'", wzVariable);
55
56LExit:
57 return hr;
58}