added masking parameters for native wireguard configs (#743)
Added masking parameters for native wireguard configs
This commit is contained in:
parent
cd2ee00769
commit
a8ccea00c7
7 changed files with 139 additions and 22 deletions
|
@ -4,6 +4,7 @@
|
|||
#include <QFileInfo>
|
||||
#include <QQuickItem>
|
||||
#include <QStandardPaths>
|
||||
#include <QRandomGenerator>
|
||||
|
||||
#include "core/errorstrings.h"
|
||||
#ifdef Q_OS_ANDROID
|
||||
|
@ -15,15 +16,6 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
enum class ConfigTypes {
|
||||
Amnezia,
|
||||
OpenVpn,
|
||||
WireGuard,
|
||||
Xray,
|
||||
Backup,
|
||||
Invalid
|
||||
};
|
||||
|
||||
ConfigTypes checkConfigFormat(const QString &config)
|
||||
{
|
||||
const QString openVpnConfigPatternCli = "client";
|
||||
|
@ -95,8 +87,8 @@ bool ImportController::extractConfigFromFile(const QString &fileName)
|
|||
bool ImportController::extractConfigFromData(QString data)
|
||||
{
|
||||
QString config = data;
|
||||
auto configFormat = checkConfigFormat(config);
|
||||
if (configFormat == ConfigTypes::Invalid) {
|
||||
m_configType = checkConfigFormat(config);
|
||||
if (m_configType == ConfigTypes::Invalid) {
|
||||
data.replace("vpn://", "");
|
||||
QByteArray ba = QByteArray::fromBase64(data.toUtf8(), QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
|
||||
QByteArray ba_uncompressed = qUncompress(ba);
|
||||
|
@ -105,14 +97,15 @@ bool ImportController::extractConfigFromData(QString data)
|
|||
}
|
||||
|
||||
config = ba;
|
||||
configFormat = checkConfigFormat(config);
|
||||
m_configType = checkConfigFormat(config);
|
||||
}
|
||||
|
||||
switch (configFormat) {
|
||||
switch (m_configType) {
|
||||
case ConfigTypes::OpenVpn: {
|
||||
m_config = extractOpenVpnConfig(config);
|
||||
return m_config.empty() ? false : true;
|
||||
}
|
||||
case ConfigTypes::Awg:
|
||||
case ConfigTypes::WireGuard: {
|
||||
m_config = extractWireGuardConfig(config);
|
||||
return m_config.empty() ? false : true;
|
||||
|
@ -168,6 +161,39 @@ QString ImportController::getConfigFileName()
|
|||
return m_configFileName;
|
||||
}
|
||||
|
||||
bool ImportController::isNativeWireGuardConfig()
|
||||
{
|
||||
return m_configType == ConfigTypes::WireGuard;
|
||||
}
|
||||
|
||||
void ImportController::processNativeWireGuardConfig()
|
||||
{
|
||||
auto containers = m_config.value(config_key::containers).toArray();
|
||||
if (!containers.isEmpty()) {
|
||||
auto container = containers.at(0).toObject();
|
||||
auto containerConfig = container.value(ContainerProps::containerTypeToString(DockerContainer::WireGuard)).toObject();
|
||||
auto protocolConfig = QJsonDocument::fromJson(containerConfig.value(config_key::last_config).toString().toUtf8()).object();
|
||||
|
||||
QString junkPacketCount = QString::number(QRandomGenerator::global()->bounded(3, 10));
|
||||
QString junkPacketMinSize = QString::number(50);
|
||||
QString junkPacketMaxSize = QString::number(1000);
|
||||
protocolConfig[config_key::junkPacketCount] = junkPacketCount;
|
||||
protocolConfig[config_key::junkPacketMinSize] = junkPacketMinSize;
|
||||
protocolConfig[config_key::junkPacketMaxSize] = junkPacketMaxSize;
|
||||
protocolConfig[config_key::initPacketJunkSize] = "0";
|
||||
protocolConfig[config_key::responsePacketJunkSize] = "0";
|
||||
protocolConfig[config_key::initPacketMagicHeader] = "1";
|
||||
protocolConfig[config_key::responsePacketMagicHeader] = "2";
|
||||
protocolConfig[config_key::underloadPacketMagicHeader] = "3";
|
||||
protocolConfig[config_key::transportPacketMagicHeader] = "4";
|
||||
|
||||
containerConfig[config_key::last_config] = QString(QJsonDocument(protocolConfig).toJson());
|
||||
container["wireguard"] = containerConfig;
|
||||
containers.replace(0, container);
|
||||
m_config[config_key::containers] = containers;
|
||||
}
|
||||
}
|
||||
|
||||
void ImportController::importConfig()
|
||||
{
|
||||
ServerCredentials credentials;
|
||||
|
@ -323,6 +349,7 @@ QJsonObject ImportController::extractWireGuardConfig(const QString &data)
|
|||
lastConfig[config_key::underloadPacketMagicHeader] = configMap.value(config_key::underloadPacketMagicHeader);
|
||||
lastConfig[config_key::transportPacketMagicHeader] = configMap.value(config_key::transportPacketMagicHeader);
|
||||
protocolName = "awg";
|
||||
m_configType = ConfigTypes::Awg;
|
||||
}
|
||||
|
||||
QJsonObject wireguardConfig;
|
||||
|
|
|
@ -3,11 +3,22 @@
|
|||
|
||||
#include <QObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/defs.h"
|
||||
#include "ui/models/containers_model.h"
|
||||
#include "ui/models/servers_model.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
enum class ConfigTypes {
|
||||
Amnezia,
|
||||
OpenVpn,
|
||||
WireGuard,
|
||||
Awg,
|
||||
Xray,
|
||||
Backup,
|
||||
Invalid
|
||||
};
|
||||
}
|
||||
|
||||
class ImportController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -36,6 +47,9 @@ public slots:
|
|||
static bool decodeQrCode(const QString &code);
|
||||
#endif
|
||||
|
||||
bool isNativeWireGuardConfig();
|
||||
void processNativeWireGuardConfig();
|
||||
|
||||
signals:
|
||||
void importFinished();
|
||||
void importErrorOccurred(const QString &errorMessage, bool goToPageHome);
|
||||
|
@ -59,6 +73,7 @@ private:
|
|||
|
||||
QJsonObject m_config;
|
||||
QString m_configFileName;
|
||||
ConfigTypes m_configType;
|
||||
|
||||
#if defined Q_OS_ANDROID || defined Q_OS_IOS
|
||||
QMap<int, QByteArray> m_qrCodeChunks;
|
||||
|
|
|
@ -116,6 +116,15 @@ PageType {
|
|||
}
|
||||
}
|
||||
|
||||
CheckBoxType {
|
||||
id: cloakingCheckBox
|
||||
|
||||
visible: ImportController.isNativeWireGuardConfig()
|
||||
|
||||
Layout.fillWidth: true
|
||||
text: qsTr("Enable WireGuard obfuscation. It may be useful if WireGuard is blocked on your provider.")
|
||||
}
|
||||
|
||||
WarningType {
|
||||
Layout.topMargin: 16
|
||||
Layout.fillWidth: true
|
||||
|
@ -164,6 +173,9 @@ PageType {
|
|||
|
||||
text: qsTr("Connect")
|
||||
clickedFunc: function() {
|
||||
if (cloakingCheckBox.checked) {
|
||||
ImportController.processNativeWireGuardConfig()
|
||||
}
|
||||
ImportController.importConfig()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue