diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2020-03-30 19:46:56 +1000 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2020-03-30 21:57:49 +1000 |
commit | 0afd76e4c5d46f237591d860e7d445e267522187 (patch) | |
tree | 9f3b648da7733464c83ba6e253a65a18d17f5583 /src/be/detectsha2support.cpp | |
parent | d74e3dd4bcc573d0c4b1fb5c36c8bf0115cc21a1 (diff) | |
download | wix-0afd76e4c5d46f237591d860e7d445e267522187.tar.gz wix-0afd76e4c5d46f237591d860e7d445e267522187.tar.bz2 wix-0afd76e4c5d46f237591d860e7d445e267522187.zip |
Add DetectSHA2Support "search".
Diffstat (limited to 'src/be/detectsha2support.cpp')
-rw-r--r-- | src/be/detectsha2support.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/be/detectsha2support.cpp b/src/be/detectsha2support.cpp new file mode 100644 index 00000000..f1f3637e --- /dev/null +++ b/src/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 | ||
6 | HRESULT DetectSHA2Support( | ||
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 | |||
35 | LExit: | ||
36 | ::FreeLibrary(hModule); | ||
37 | |||
38 | return hr; | ||
39 | } | ||
40 | |||
41 | HRESULT UtilPerformDetectSHA2Support( | ||
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 = DetectSHA2Support(&fSupported); | ||
51 | ExitOnFailure(hr, "DetectSHA2Support failed."); | ||
52 | |||
53 | hr = pEngine->SetVariableNumeric(wzVariable, fSupported ? 1 : 0); | ||
54 | ExitOnFailure(hr, "Failed to set variable '%ls'", wzVariable); | ||
55 | |||
56 | LExit: | ||
57 | return hr; | ||
58 | } | ||