Skip to content

Commit

Permalink
basti/kn intervention (#10042)
Browse files Browse the repository at this point in the history
* Add basic auto intervention

* Add query api for interventions

* Fixup

* Update src/interventions/killernetwork.h

Co-authored-by: MCleinman <[email protected]>

* Remove wrong things

---------

Co-authored-by: MCleinman <[email protected]>
  • Loading branch information
strseb and mcleinman authored Dec 6, 2024
1 parent f4d97af commit 67cd6a6
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 89 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ target_link_libraries(mozillavpn PRIVATE

if(NOT CMAKE_CROSSCOMPILING)
add_subdirectory(webextension)
add_subdirectory(interventions)
target_link_libraries(mozillavpn PRIVATE mz_webextension)
endif()

Expand Down
11 changes: 11 additions & 0 deletions src/interventions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

if(WIN32)
target_sources(mozillavpn PRIVATE
killernetwork.h
killernetwork.cpp
)
endif()

26 changes: 26 additions & 0 deletions src/interventions/killernetwork.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "killernetwork.h"

#include <qobject.h>

#include <QObject>

#include "platforms/windows/windowsservicemanager.h"

namespace Intervention {

const QString KillerNetwork::id = "intel.killernetwork";

bool KillerNetwork::systemAffected() {
std::unique_ptr<WindowsServiceManager> svm =
WindowsServiceManager::open("Killer Network Service");
if (svm == nullptr) {
return false;
}
return svm->isRunning();
}

} // namespace Intervention
39 changes: 39 additions & 0 deletions src/interventions/killernetwork.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#pragma once

#include <QObject>

class WindowsDaemon;
class WindowsServiceManager;

namespace Intervention {

/**
* @brief Intervention for Intel Killer Network.
*
* Intel's Killer Network services silently breaks
* the extension proxy and the split-tunnel driver.
*
* This class currently only detects if a system will be affected.
*/
class KillerNetwork : public QObject {
Q_OBJECT
public:
/**
* @brief Returns true if the system is affected
* can this Intervention can migitate
*/
static bool systemAffected();

/**
* @brief The ID of the intervention for IPC purposes
*
* @return const QString&
*/
static const QString id;
};

}; // namespace Intervention
195 changes: 106 additions & 89 deletions src/webextensionadapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "webextensionadapter.h"

#include <QFileInfo>
#include <QHostAddress>
#include <QJsonArray>
#include <QJsonDocument>
Expand Down Expand Up @@ -33,6 +32,14 @@
# include "platforms/windows/windowsutils.h"
#endif

#if defined(MZ_LINUX) && !defined(MZ_FLATPAK)
# include <QFileInfo>
#endif

#ifdef MZ_WINDOWS
# include "interventions/killernetwork.h"
#endif

namespace {
// See https://en.cppreference.com/w/cpp/utility/variant/visit
template <class... Ts>
Expand Down Expand Up @@ -66,94 +73,104 @@ WebExtensionAdapter::WebExtensionAdapter(QObject* parent)
connect(vpn->connectionHealth(), &ConnectionHealth::stabilityChanged, this,
&WebExtensionAdapter::writeState);

m_commands = QList<RequestType>({
RequestType{"activate",
[](const QJsonObject&) {
auto t = new TaskControllerAction(
TaskControllerAction::eActivateForExtension);
TaskScheduler::scheduleTask(t);
QJsonObject obj;
obj["ok"] = true;
return QJsonObject();
}},
RequestType{"deactivate",
[](const QJsonObject&) {
auto t = new TaskControllerAction(
TaskControllerAction::eDeactivateForExtension);
TaskScheduler::scheduleTask(t);
QJsonObject obj;
obj["ok"] = true;
return QJsonObject();
}},
RequestType{"servers",
[this](const QJsonObject&) {
QJsonObject servers;
serializeServerCountry(
MozillaVPN::instance()->serverCountryModel(), servers);

QJsonObject obj;
obj["servers"] = servers;
return obj;
}},
RequestType{"focus",
[](const QJsonObject&) {
QmlEngineHolder* engine = QmlEngineHolder::instance();
engine->showWindow();
return QJsonObject{};
}},
RequestType{"openAuth",
[](const QJsonObject&) {
MozillaVPN* vpn = MozillaVPN::instance();
if (vpn->state() != MozillaVPN::StateInitialize) {
return QJsonObject{};
}
vpn->authenticate();
return QJsonObject{};
}},
RequestType{"disabled_apps",
[](const QJsonObject&) {
QJsonArray apps;
for (const QString& app :
SettingsHolder::instance()->vpnDisabledApps()) {
apps.append(app);
}

QJsonObject obj;
obj["disabled_apps"] = apps;
return obj;
}},
RequestType{"featurelist",
[this](const QJsonObject&) {
QJsonObject obj;
obj["featurelist"] = serializeFeaturelist();
return obj;
}},

RequestType{"status",
[this](const QJsonObject&) {
QJsonObject obj;
obj["status"] = serializeStatus();
return obj;
}},
RequestType{"telemetry",
[](const QJsonObject& data) {
auto info = WebextensionTelemetry::fromJson(data);
if (info.has_value()) {
WebextensionTelemetry::recordTelemetry(info.value());
}
return QJsonObject{};
}},
RequestType{"session_start",
[](const QJsonObject& data) {
WebextensionTelemetry::startSession();
return QJsonObject{};
}},
RequestType{"session_stop",
[](const QJsonObject& data) {
WebextensionTelemetry::stopSession();
return QJsonObject{};
}},
});
m_commands = QList<RequestType>(
{RequestType{"activate",
[](const QJsonObject&) {
auto t = new TaskControllerAction(
TaskControllerAction::eActivateForExtension);
TaskScheduler::scheduleTask(t);
QJsonObject obj;
obj["ok"] = true;
return QJsonObject();
}},
RequestType{"deactivate",
[](const QJsonObject&) {
auto t = new TaskControllerAction(
TaskControllerAction::eDeactivateForExtension);
TaskScheduler::scheduleTask(t);
QJsonObject obj;
obj["ok"] = true;
return QJsonObject();
}},
RequestType{"servers",
[this](const QJsonObject&) {
QJsonObject servers;
serializeServerCountry(
MozillaVPN::instance()->serverCountryModel(), servers);

QJsonObject obj;
obj["servers"] = servers;
return obj;
}},
RequestType{"focus",
[](const QJsonObject&) {
QmlEngineHolder* engine = QmlEngineHolder::instance();
engine->showWindow();
return QJsonObject{};
}},
RequestType{"openAuth",
[](const QJsonObject&) {
MozillaVPN* vpn = MozillaVPN::instance();
if (vpn->state() != MozillaVPN::StateInitialize) {
return QJsonObject{};
}
vpn->authenticate();
return QJsonObject{};
}},
RequestType{"disabled_apps",
[](const QJsonObject&) {
QJsonArray apps;
for (const QString& app :
SettingsHolder::instance()->vpnDisabledApps()) {
apps.append(app);
}

QJsonObject obj;
obj["disabled_apps"] = apps;
return obj;
}},
RequestType{"featurelist",
[this](const QJsonObject&) {
QJsonObject obj;
obj["featurelist"] = serializeFeaturelist();
return obj;
}},

RequestType{"status",
[this](const QJsonObject&) {
QJsonObject obj;
obj["status"] = serializeStatus();
return obj;
}},
RequestType{"telemetry",
[](const QJsonObject& data) {
auto info = WebextensionTelemetry::fromJson(data);
if (info.has_value()) {
WebextensionTelemetry::recordTelemetry(info.value());
}
return QJsonObject{};
}},
RequestType{"session_start",
[](const QJsonObject& data) {
WebextensionTelemetry::startSession();
return QJsonObject{};
}},
RequestType{"session_stop",
[](const QJsonObject& data) {
WebextensionTelemetry::stopSession();
return QJsonObject{};
}},
RequestType{"interventions", [](const QJsonObject&) {
QJsonObject out;
QJsonArray interventions;
#ifdef MZ_WINDOWS
if (Intervention::KillerNetwork::systemAffected()) {
interventions.append(Intervention::KillerNetwork::id);
}
#endif
out["interventions"] = interventions;
return out;
}}});
}

WebExtensionAdapter::~WebExtensionAdapter() {
Expand Down

0 comments on commit 67cd6a6

Please sign in to comment.