diff options
| author | Rob Mensching <rob@firegiant.com> | 2021-05-11 07:47:12 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2021-05-11 07:47:12 -0700 |
| commit | 0923aba915ca2450cc87e3e2c6c0e4e3d2b28294 (patch) | |
| tree | 994f53dc35c927d219f4b8cae3f522a5f163473b /src/ext/Util/be/detectsha2support.cpp | |
| parent | 68cc62fc46efac3375aef5694e9f645ac09b622f (diff) | |
| parent | ff659159e041bf6c083e6b7fcb9b726065a9dd73 (diff) | |
| download | wix-0923aba915ca2450cc87e3e2c6c0e4e3d2b28294.tar.gz wix-0923aba915ca2450cc87e3e2c6c0e4e3d2b28294.tar.bz2 wix-0923aba915ca2450cc87e3e2c6c0e4e3d2b28294.zip | |
Merge Util.wixext
Diffstat (limited to 'src/ext/Util/be/detectsha2support.cpp')
| -rw-r--r-- | src/ext/Util/be/detectsha2support.cpp | 58 |
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 | ||
| 6 | HRESULT 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 | |||
| 35 | LExit: | ||
| 36 | ::FreeLibrary(hModule); | ||
| 37 | |||
| 38 | return hr; | ||
| 39 | } | ||
| 40 | |||
| 41 | HRESULT 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 | |||
| 56 | LExit: | ||
| 57 | return hr; | ||
| 58 | } | ||
