summaryrefslogtreecommitdiff
path: root/src/ext/Util/be/detectsha2support.cpp
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2021-05-03 09:55:22 -0700
committerRob Mensching <rob@firegiant.com>2021-05-03 09:55:22 -0700
commitff659159e041bf6c083e6b7fcb9b726065a9dd73 (patch)
treeea95bf3d3e031edcee65de33b9e6954178be669c /src/ext/Util/be/detectsha2support.cpp
parent8a8a25695351ee542f08886a9d0957c78c6af366 (diff)
downloadwix-ff659159e041bf6c083e6b7fcb9b726065a9dd73.tar.gz
wix-ff659159e041bf6c083e6b7fcb9b726065a9dd73.tar.bz2
wix-ff659159e041bf6c083e6b7fcb9b726065a9dd73.zip
Move Util.wixext into ext
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}