Skip to content

Commit 1edfb29

Browse files
committed
v2.11.7
1 parent ab0625c commit 1edfb29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+863
-343
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ The repository contains Dockerfile to simplify building process. Skip all the ot
164164
```
165165
- Install vcpkg:
166166
```bash
167-
sudo docker run --rm -v .:/w ws-builder /bin/bash -c "git clone https://github.com/Microsoft/vcpkg.git && git checkout 576379156e82da642f8d1834220876759f13534d && ./vcpkg/bootstrap-vcpkg.sh --disableMetrics"
167+
sudo docker run --rm -v .:/w ws-builder /bin/bash -c "git clone https://github.com/Microsoft/vcpkg.git && cd vcpkg && git checkout 576379156e82da642f8d1834220876759f13534d && ./bootstrap-vcpkg.sh --disableMetrics"
168168
```
169169
- Build all the dependencies:
170170
```bash

backend/windows/windscribe_service/ipc/serialize_structs.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,5 +212,12 @@ void serialize(Archive & ar, CMD_CREATE_OPENVPN_ADAPTER & g, const unsigned int
212212
ar & g.useDCODriver;
213213
}
214214

215+
template<class Archive>
216+
void serialize(Archive & ar, CMD_SSID_FROM_INTERFACE_GUID & g, const unsigned int version)
217+
{
218+
UNREFERENCED_PARAMETER(version);
219+
ar & g.interfaceGUID;
220+
}
221+
215222
} // namespace serialization
216223
} // namespace boost

backend/windows/windscribe_service/ipc/servicecommunication.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#define AA_COMMAND_DISABLE_DOH_SETTINGS 53
5757
#define AA_COMMAND_ENABLE_DOH_SETTINGS 54
5858
#define AA_COMMAND_CONFIGURE_WIREGUARD 55
59+
#define AA_COMMAND_SSID_FROM_INTERFACE_GUID 56
5960

6061
#include <string>
6162
#include <vector>
@@ -242,6 +243,11 @@ struct CMD_CREATE_OPENVPN_ADAPTER
242243
bool useDCODriver;
243244
};
244245

246+
struct CMD_SSID_FROM_INTERFACE_GUID
247+
{
248+
std::wstring interfaceGUID;
249+
};
250+
245251
struct MessagePacketResult
246252
{
247253
__int64 id;

backend/windows/windscribe_service/process_command.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,6 @@ MessagePacketResult disableDohSettings(boost::archive::text_iarchive &ia)
838838
return mpr;
839839
}
840840

841-
842841
MessagePacketResult enableDohSettings(boost::archive::text_iarchive &ia)
843842
{
844843
MessagePacketResult mpr;
@@ -874,3 +873,21 @@ MessagePacketResult enableDohSettings(boost::archive::text_iarchive &ia)
874873
Logger::instance().out(L"AA_COMMAND_ENABLE_DOH_SETTINGS");
875874
return mpr;
876875
}
876+
877+
MessagePacketResult ssidFromInterfaceGUID(boost::archive::text_iarchive &ia)
878+
{
879+
CMD_SSID_FROM_INTERFACE_GUID cmd;
880+
ia >> cmd;
881+
882+
MessagePacketResult mpr;
883+
try {
884+
mpr.additionalString = Utils::ssidFromInterfaceGUID(cmd.interfaceGUID);
885+
mpr.success = true;
886+
}
887+
catch (std::system_error &ex) {
888+
mpr.exitCode = ex.code().value();
889+
Logger::instance().out("ssidFromInterfaceGUID - %s", ex.what());
890+
}
891+
892+
return mpr;
893+
}

backend/windows/windscribe_service/process_command.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ MessagePacketResult createOpenVPNAdapter(boost::archive::text_iarchive &ia);
8181
MessagePacketResult removeOpenVPNAdapter(boost::archive::text_iarchive &ia);
8282
MessagePacketResult disableDohSettings(boost::archive::text_iarchive &ia);
8383
MessagePacketResult enableDohSettings(boost::archive::text_iarchive &ia);
84+
MessagePacketResult ssidFromInterfaceGUID(boost::archive::text_iarchive &ia);
8485

8586
static const std::map<const int, std::function<MessagePacketResult(boost::archive::text_iarchive &)>> kCommands = {
8687
{ AA_COMMAND_FIREWALL_ON, firewallOn },
@@ -135,7 +136,8 @@ static const std::map<const int, std::function<MessagePacketResult(boost::archiv
135136
{ AA_COMMAND_CREATE_OPENVPN_ADAPTER, createOpenVPNAdapter },
136137
{ AA_COMMAND_REMOVE_OPENVPN_ADAPTER, removeOpenVPNAdapter },
137138
{ AA_COMMAND_DISABLE_DOH_SETTINGS, disableDohSettings },
138-
{ AA_COMMAND_ENABLE_DOH_SETTINGS, enableDohSettings }
139+
{ AA_COMMAND_ENABLE_DOH_SETTINGS, enableDohSettings },
140+
{ AA_COMMAND_SSID_FROM_INTERFACE_GUID, ssidFromInterfaceGUID }
139141
};
140142

141143
MessagePacketResult processCommand(int cmdId, const std::string &packet);

backend/windows/windscribe_service/utils.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
#include <shlobj.h>
99
#include <versionhelpers.h>
1010
#include <WbemIdl.h>
11+
#include <wlanapi.h>
1112

1213
#include <cwctype>
1314

1415
#include "logger.h"
1516
#include "utils/executable_signature/executable_signature.h"
1617
#include "utils/win32handle.h"
18+
#include "utils/wsscopeguard.h"
1719

1820
#pragma comment(lib, "wbemuuid.lib")
1921

@@ -567,4 +569,85 @@ bool isMacAddress(const std::wstring &value)
567569
return valid;
568570
}
569571

572+
std::string ssidFromInterfaceGUID(const std::wstring &interfaceGUID)
573+
{
574+
// This DLL is not available on default installs of Windows Server. Dynamically load it so
575+
// the app doesn't fail to launch with a "DLL not found" error. App profiling was performed
576+
// and indicated no performance degradation when dynamically loading and unloading the DLL.
577+
const std::wstring dll = getSystemDir() + L"\\wlanapi.dll";
578+
auto wlanDll = ::LoadLibraryEx(dll.c_str(), NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
579+
if (wlanDll == NULL) {
580+
throw std::system_error(::GetLastError(), std::generic_category(), "wlanapi.dll could not be loaded");
581+
}
582+
583+
auto freeDLL = wsl::wsScopeGuard([&] {
584+
::FreeLibrary(wlanDll);
585+
});
586+
587+
typedef DWORD (WINAPI * WlanOpenHandleFunc)(DWORD dwClientVersion, PVOID pReserved, PDWORD pdwNegotiatedVersion, PHANDLE phClientHandle);
588+
typedef DWORD (WINAPI * WlanCloseHandleFunc)(HANDLE hClientHandle, PVOID pReserved);
589+
typedef VOID (WINAPI * WlanFreeMemoryFunc)(PVOID pMemory);
590+
typedef DWORD (WINAPI * WlanQueryInterfaceFunc)(HANDLE hClientHandle, CONST GUID *pInterfaceGuid, WLAN_INTF_OPCODE OpCode, PVOID pReserved,
591+
PDWORD pdwDataSize, PVOID *ppData, PWLAN_OPCODE_VALUE_TYPE pWlanOpcodeValueType);
592+
593+
WlanOpenHandleFunc pfnWlanOpenHandle = (WlanOpenHandleFunc)::GetProcAddress(wlanDll, "WlanOpenHandle");
594+
if (pfnWlanOpenHandle == NULL) {
595+
throw std::system_error(::GetLastError(), std::generic_category(), "Failed to load WlanOpenHandle");
596+
}
597+
598+
WlanCloseHandleFunc pfnWlanCloseHandle = (WlanCloseHandleFunc)::GetProcAddress(wlanDll, "WlanCloseHandle");
599+
if (pfnWlanCloseHandle == NULL) {
600+
throw std::system_error(::GetLastError(), std::generic_category(), "Failed to load WlanCloseHandle");
601+
}
602+
603+
WlanFreeMemoryFunc pfnWlanFreeMemory = (WlanFreeMemoryFunc)::GetProcAddress(wlanDll, "WlanFreeMemory");
604+
if (pfnWlanFreeMemory == NULL) {
605+
throw std::system_error(::GetLastError(), std::generic_category(), "Failed to load WlanFreeMemory");
606+
}
607+
608+
WlanQueryInterfaceFunc pfnWlanQueryInterface = (WlanQueryInterfaceFunc)::GetProcAddress(wlanDll, "WlanQueryInterface");
609+
if (pfnWlanQueryInterface == NULL) {
610+
throw std::system_error(::GetLastError(), std::generic_category(), "Failed to load WlanQueryInterface");
611+
}
612+
613+
DWORD dwCurVersion = 0;
614+
HANDLE hClient = NULL;
615+
auto result = pfnWlanOpenHandle(2, NULL, &dwCurVersion, &hClient);
616+
if (result != ERROR_SUCCESS) {
617+
throw std::system_error(::GetLastError(), std::generic_category(), "WlanOpenHandle failed");
618+
}
619+
620+
PWLAN_CONNECTION_ATTRIBUTES pConnectInfo = NULL;
621+
622+
auto freeWlanResources = wsl::wsScopeGuard([&] {
623+
if (pConnectInfo != NULL) {
624+
pfnWlanFreeMemory(pConnectInfo);
625+
}
626+
627+
pfnWlanCloseHandle(hClient, NULL);
628+
});
629+
630+
GUID actualGUID = guidFromString(interfaceGUID);
631+
632+
DWORD connectInfoSize = sizeof(WLAN_CONNECTION_ATTRIBUTES);
633+
WLAN_OPCODE_VALUE_TYPE opCode = wlan_opcode_value_type_invalid;
634+
635+
result = pfnWlanQueryInterface(hClient, &actualGUID, wlan_intf_opcode_current_connection, NULL,
636+
&connectInfoSize, (PVOID *) &pConnectInfo, &opCode);
637+
if (result != ERROR_SUCCESS) {
638+
throw std::system_error(::GetLastError(), std::generic_category(), "WlanQueryInterface failed");
639+
}
640+
641+
std::string ssid;
642+
const auto &dot11Ssid = pConnectInfo->wlanAssociationAttributes.dot11Ssid;
643+
if (dot11Ssid.uSSIDLength > 0) {
644+
ssid.reserve(dot11Ssid.uSSIDLength);
645+
for (ULONG k = 0; k < dot11Ssid.uSSIDLength; k++) {
646+
ssid.push_back(static_cast<char>(dot11Ssid.ucSSID[k]));
647+
}
648+
}
649+
650+
return ssid;
651+
}
652+
570653
}

backend/windows/windscribe_service/utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@ namespace Utils
4242
bool addFilterV6(HANDLE engineHandle, std::vector<UINT64> *filterId, FWP_ACTION_TYPE type, UINT8 weight,
4343
GUID subLayerKey, wchar_t *subLayerName, PNET_LUID pluid = nullptr,
4444
const std::vector<Ip6AddressAndPrefix> *range = nullptr, bool persistent = true);
45+
46+
std::string ssidFromInterfaceGUID(const std::wstring &interfaceGUID);
4547
};

backend/windows/wireguard_service/ServiceMain.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <tlhelp32.h>
44

55
#include <chrono>
6-
#include <codecvt>
76
#include <filesystem>
87
#include <fstream>
98
#include <iomanip>
@@ -278,12 +277,6 @@ int wmain(int argc, wchar_t *argv[])
278277
// hMonitorThread.wait(5000);
279278
//}
280279

281-
// Delete the config file.
282-
dwAttrib = ::GetFileAttributes(configFile.c_str());
283-
if (dwAttrib != INVALID_FILE_ATTRIBUTES) {
284-
::DeleteFile(configFile.c_str());
285-
}
286-
287280
debugOut("Windscribe WireGuard service stopped");
288281

289282
::FreeLibrary(hTunnelDLL);

client/base/backend/backend.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -712,23 +712,25 @@ void Backend::abortInitialization()
712712
void Backend::handleNetworkChange(types::NetworkInterface networkInterface, bool manual)
713713
{
714714
bool newNetwork = true;
715-
716-
// find or assign friendly name before checking is network is the same as current network
717-
QString friendlyName = networkInterface.networkOrSsid;
718-
719715
QVector<types::NetworkInterface> networkListOld = PersistentState::instance().networkWhitelist();
720-
for (int i = 0; i < networkListOld.size(); i++) {
721-
if (networkListOld[i].networkOrSsid== networkInterface.networkOrSsid) {
722-
friendlyName = networkListOld[i].friendlyName;
723-
newNetwork = false;
724-
break;
725-
}
726-
}
727716

728-
if (friendlyName == "") {
717+
QString friendlyName;
718+
if (!networkInterface.networkOrSsid.isEmpty()) {
719+
// find or assign friendly name before checking is network is the same as current network
729720
friendlyName = networkInterface.networkOrSsid;
721+
for (int i = 0; i < networkListOld.size(); i++) {
722+
if (networkListOld[i].networkOrSsid== networkInterface.networkOrSsid) {
723+
friendlyName = networkListOld[i].friendlyName;
724+
newNetwork = false;
725+
break;
726+
}
727+
}
728+
729+
if (friendlyName == "") {
730+
friendlyName = networkInterface.networkOrSsid;
731+
}
732+
networkInterface.friendlyName = friendlyName;
730733
}
731-
networkInterface.friendlyName = friendlyName;
732734

733735
if (networkInterface.networkOrSsid != "") { // not a disconnect
734736
// Add a new network as secured

client/base/backend/preferences/preferences.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ const types::ConnectionSettings Preferences::networkPreferredProtocol(QString ne
257257
return engineSettings_.networkPreferredProtocols()[networkOrSsid];
258258
}
259259

260+
const QMap<QString, types::ConnectionSettings> Preferences::networkPreferredProtocols() const
261+
{
262+
return engineSettings_.networkPreferredProtocols();
263+
}
264+
260265
bool Preferences::hasNetworkPreferredProtocol(QString networkOrSsid) const
261266
{
262267
return engineSettings_.networkPreferredProtocols().contains(networkOrSsid) &&
@@ -273,6 +278,7 @@ void Preferences::setNetworkPreferredProtocols(const QMap<QString, types::Connec
273278
}
274279
}
275280

281+
276282
void Preferences::setNetworkPreferredProtocol(QString networkOrSsid, const types::ConnectionSettings &settings)
277283
{
278284
QMap<QString, types::ConnectionSettings> map = engineSettings_.networkPreferredProtocols();

0 commit comments

Comments
 (0)