diff options
| -rw-r--r-- | dist-assets/windows/installer.nsh | 48 | ||||
| -rw-r--r-- | gui/tasks/distribution.js | 1 | ||||
| -rw-r--r-- | windows/driverlogic/driverlogic.vcxproj | 1 | ||||
| -rw-r--r-- | windows/driverlogic/driverlogic.vcxproj.filters | 1 | ||||
| -rw-r--r-- | windows/driverlogic/src/driverlogic.cpp | 30 | ||||
| -rw-r--r-- | windows/driverlogic/src/wireguard.h | 58 |
6 files changed, 133 insertions, 6 deletions
diff --git a/dist-assets/windows/installer.nsh b/dist-assets/windows/installer.nsh index 5f0151f009..c1dac59bf8 100644 --- a/dist-assets/windows/installer.nsh +++ b/dist-assets/windows/installer.nsh @@ -13,6 +13,7 @@ # !define WINTUN_POOL "Mullvad" +!define WG_NT_POOL "Mullvad" # "sc" exit code !define SERVICE_STARTED 0 @@ -59,19 +60,20 @@ !define PERSISTENT_BLOCK_OUTBOUND_IPV4_FILTER_GUID "{79860c64-9a5e-48a3-b5f3-d64b41659aa5}" # -# ExtractWintun +# ExtractWireGuard # -# Extract Wintun installer into $TEMP +# Extract Wintun and WireGuardNT installer into $TEMP # -!macro ExtractWintun +!macro ExtractWireGuard SetOutPath "$TEMP" File "${BUILD_RESOURCES_DIR}\binaries\x86_64-pc-windows-msvc\wintun\wintun.dll" + File "${BUILD_RESOURCES_DIR}\binaries\x86_64-pc-windows-msvc\wireguard-nt\wireguard.dll" File "${BUILD_RESOURCES_DIR}\..\windows\driverlogic\bin\x64-Release\driverlogic.exe" !macroend -!define ExtractWintun '!insertmacro "ExtractWintun"' +!define ExtractWireGuard '!insertmacro "ExtractWireGuard"' # # ExtractMullvadSetup @@ -222,6 +224,41 @@ !define RemoveWintun '!insertmacro "RemoveWintun"' # +# RemoveWireGuardNt +# +# Try to remove WireGuardNT +# +!macro RemoveWireGuardNt + Push $0 + Push $1 + + log::Log "RemoveWireGuardNt()" + + nsExec::ExecToStack '"$TEMP\driverlogic.exe" wg-nt-cleanup ${WG_NT_POOL}' + Pop $0 + Pop $1 + + ${If} $0 != ${DL_GENERAL_SUCCESS} + IntFmt $0 "0x%X" $0 + StrCpy $R0 "Failed to remove WireGuardNT pool: error $0" + log::LogWithDetails $R0 $1 + Goto RemoveWireGuardNt_return_only + ${EndIf} + + log::Log "RemoveWireGuardNt() completed successfully" + + Push 0 + Pop $R0 + + RemoveWireGuardNt_return_only: + + Pop $1 + Pop $0 + +!macroend + +!define RemoveWireGuardNt '!insertmacro "RemoveWireGuardNt"' +# # RemoveAbandonedWintunAdapter # # Removes old Wintun interface, even if it belongs to a different pool. @@ -1244,8 +1281,9 @@ ${ClearFirewallRules} ${RemoveWireGuardKey} - ${ExtractWintun} + ${ExtractWireGuard} ${RemoveWintun} + ${RemoveWireGuardNt} ${ExtractSplitTunnelDriver} ${RemoveSplitTunnelDriver} diff --git a/gui/tasks/distribution.js b/gui/tasks/distribution.js index 452baad71f..6f74d65eda 100644 --- a/gui/tasks/distribution.js +++ b/gui/tasks/distribution.js @@ -114,6 +114,7 @@ const config = { { from: distAssets('binaries/x86_64-pc-windows-msvc/sslocal.exe'), to: '.' }, { from: root('build/lib/x86_64-pc-windows-msvc/libwg.dll'), to: '.' }, { from: distAssets('binaries/x86_64-pc-windows-msvc/wintun/wintun.dll'), to: '.' }, + { from: distAssets('binaries/x86_64-pc-windows-msvc/wireguard-nt/wireguard.dll'), to: '.' }, ], }, diff --git a/windows/driverlogic/driverlogic.vcxproj b/windows/driverlogic/driverlogic.vcxproj index b91e97d86c..cc46c1ac72 100644 --- a/windows/driverlogic/driverlogic.vcxproj +++ b/windows/driverlogic/driverlogic.vcxproj @@ -117,6 +117,7 @@ <ClInclude Include="src\util.h" /> <ClInclude Include="src\version.h" /> <ClInclude Include="src\wintun.h" /> + <ClInclude Include="src\wireguard.h" /> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/windows/driverlogic/driverlogic.vcxproj.filters b/windows/driverlogic/driverlogic.vcxproj.filters index 91ed2267da..9665231376 100644 --- a/windows/driverlogic/driverlogic.vcxproj.filters +++ b/windows/driverlogic/driverlogic.vcxproj.filters @@ -28,5 +28,6 @@ <ClInclude Include="src\util.h" /> <ClInclude Include="src\wintun.h" /> <ClInclude Include="src\devenum.h" /> + <ClInclude Include="src\wireguard.h" /> </ItemGroup> </Project>
\ No newline at end of file diff --git a/windows/driverlogic/src/driverlogic.cpp b/windows/driverlogic/src/driverlogic.cpp index 93af20b400..3cb1739e21 100644 --- a/windows/driverlogic/src/driverlogic.cpp +++ b/windows/driverlogic/src/driverlogic.cpp @@ -5,6 +5,7 @@ #include "log.h" #include "version.h" #include "wintun.h" +#include "wireguard.h" #include "devenum.h" #include <string> #include <libcommon/error.h> @@ -278,6 +279,32 @@ ReturnCode CommandWintunDeleteAbandonedDevice(const std::vector<std::wstring> &a return GENERAL_SUCCESS; } +ReturnCode CommandWireGuardNtCleanup(const std::vector<std::wstring> &args) +{ + ArgumentContext argsContext(args); + + argsContext.ensureExactArgumentCount(1); + + const auto poolName = argsContext.next(); + + WireGuardNtDll wgNt; + + BOOL rebootRequired; + + if (FALSE == wgNt.deletePoolDriver(poolName.c_str(), &rebootRequired)) + { + throw std::runtime_error("Failed to delete WireGuardNT pool"); + } + + std::wstringstream ss; + + ss << L"Successfully deleted WireGuardNT pool. Reboot required: " << rebootRequired; + + Log(ss.str()); + + return ReturnCode::GENERAL_SUCCESS; +} + } // anonymous namespace int wmain(int argc, const wchar_t *argv[]) @@ -325,7 +352,8 @@ int wmain(int argc, const wchar_t *argv[]) { L"st-force-install", CommandSplitTunnelForceInstall }, { L"st-remove", CommandSplitTunnelRemove }, { L"wintun-delete-pool-driver", CommandWintunDeletePool }, - { L"wintun-delete-abandoned-device", CommandWintunDeleteAbandonedDevice } + { L"wintun-delete-abandoned-device", CommandWintunDeleteAbandonedDevice }, + { L"wg-nt-cleanup", CommandWireGuardNtCleanup } }; // diff --git a/windows/driverlogic/src/wireguard.h b/windows/driverlogic/src/wireguard.h new file mode 100644 index 0000000000..5892b248f1 --- /dev/null +++ b/windows/driverlogic/src/wireguard.h @@ -0,0 +1,58 @@ +#pragma once + +#include <wireguard-nt/wireguard.h> +#include <libcommon/error.h> +#include "util.h" + +class WireGuardNtDll +{ +public: + + WireGuardNtDll() : dllHandle(nullptr) + { + auto path = GetProcessModulePath().replace_filename(L"wireguard.dll"); + dllHandle = LoadLibraryExW(path.c_str(), nullptr, LOAD_WITH_ALTERED_SEARCH_PATH); + + if (nullptr == dllHandle) + { + THROW_WINDOWS_ERROR(GetLastError(), "LoadLibraryExW"); + } + + try + { + deletePoolDriver = getProcAddressOrThrow<WIREGUARD_DELETE_POOL_DRIVER_FUNC*>("WireGuardDeletePoolDriver"); + } + catch (...) + { + FreeLibrary(dllHandle); + throw; + } + } + + ~WireGuardNtDll() + { + if (nullptr != dllHandle) + { + FreeLibrary(dllHandle); + } + } + + WIREGUARD_DELETE_POOL_DRIVER_FUNC *deletePoolDriver; + +private: + + template<typename T> + T getProcAddressOrThrow(const char *procName) + { + const T result = reinterpret_cast<T>(GetProcAddress(dllHandle, procName)); + + if (nullptr == result) + { + THROW_WINDOWS_ERROR(GetLastError(), "GetProcAddress"); + } + + return result; + } + + HMODULE dllHandle; +}; |
