diff options
Diffstat (limited to 'installer/fetcher/fetcher.c')
-rw-r--r-- | installer/fetcher/fetcher.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/installer/fetcher/fetcher.c b/installer/fetcher/fetcher.c index e9d23567..5c688997 100644 --- a/installer/fetcher/fetcher.c +++ b/installer/fetcher/fetcher.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * Copyright (C) 2020-2021 Jason A. Donenfeld. All Rights Reserved. + * Copyright (C) 2020-2022 Jason A. Donenfeld. All Rights Reserved. */ #include <windows.h> @@ -23,7 +23,7 @@ #include "constants.h" static char msi_filename[MAX_PATH]; -static volatile bool msi_filename_is_set; +static volatile bool msi_filename_is_set, prompts = true; static volatile size_t g_current, g_total; static HWND progress; static HANDLE filehandle = INVALID_HANDLE_VALUE; @@ -114,6 +114,12 @@ static DWORD __stdcall download_thread(void *param) if (!session) goto out; WinHttpSetOption(session, WINHTTP_OPTION_ENABLE_HTTP_PROTOCOL, &enable_http2, sizeof(enable_http2)); // Don't check return value, in case of old Windows + if (is_win8dotzero_or_below()) { + DWORD enable_tls12 = WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2; + if (!WinHttpSetOption(session, WINHTTP_OPTION_SECURE_PROTOCOLS, &enable_tls12, sizeof(enable_tls12))) + goto out; + } + connection = WinHttpConnect(session, L(server), port, 0); if (!connection) goto out; @@ -181,7 +187,10 @@ static DWORD __stdcall download_thread(void *param) CloseHandle(filehandle); //TODO: I wish this wasn't required. filehandle = INVALID_HANDLE_VALUE; wintrust_fileinfo.pcwszFilePath = L(msi_filename); - if (WinVerifyTrust(INVALID_HANDLE_VALUE, &(GUID)WINTRUST_ACTION_GENERIC_VERIFY_V2, &wintrust_data)) + ret = WinVerifyTrustEx(INVALID_HANDLE_VALUE, &(GUID)WINTRUST_ACTION_GENERIC_VERIFY_V2, &wintrust_data); + wintrust_data.dwStateAction = WTD_STATEACTION_CLOSE; + WinVerifyTrustEx(INVALID_HANDLE_VALUE, &(GUID)WINTRUST_ACTION_GENERIC_VERIFY_V2, &wintrust_data); + if (ret) goto out; set_status(progress, "launching installer"); @@ -199,7 +208,7 @@ out: if (security_attributes.lpSecurityDescriptor) LocalFree(security_attributes.lpSecurityDescriptor); - if (ret) { + if (ret && prompts) { ShowWindow(progress, SW_SHOWDEFAULT); if (MessageBoxA(progress, "Something went wrong when downloading the WireGuard installer. Would you like to open your web browser to the MSI download page?", "Download Error", MB_YESNO | MB_ICONWARNING) == IDYES) ShellExecuteA(progress, NULL, "https://" server msi_path, NULL, NULL, SW_SHOWNORMAL); @@ -276,6 +285,20 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar return DefSubclassProc(hWnd, uMsg, wParam, lParam); } +static void parse_command_line(void) +{ + LPWSTR *argv; + int argc; + argv = CommandLineToArgvW(GetCommandLineW(), &argc); + if (!argv) + return; + for (int i = 1; i < argc; ++i) { + if (wcsicmp(argv[i], L"/noprompt") == 0) + prompts = false; + } + LocalFree(argv); +} + int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int nCmdShow) { MSG msg; @@ -288,6 +311,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, if (!SetDllDirectoryA("") || !SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32)) return 1; + parse_command_line(); + InitCommonControlsEx(&(INITCOMMONCONTROLSEX){ .dwSize = sizeof(INITCOMMONCONTROLSEX), .dwICC = ICC_PROGRESS_CLASS }); progress = CreateWindowExA(0, PROGRESS_CLASS, "WireGuard Installer", |