Merge pull request #383 from amnezia-vpn/feature/awg-random-values

Feature/awg random values
This commit is contained in:
pokamest 2023-10-19 18:28:13 -07:00 committed by GitHub
commit 7834860245
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 116 additions and 59 deletions

View file

@ -16,11 +16,11 @@ namespace amnezia
Q_NAMESPACE
enum DockerContainer {
None = 0,
OpenVpn,
ShadowSocks,
Cloak,
WireGuard,
Awg,
WireGuard,
OpenVpn,
Cloak,
ShadowSocks,
Ipsec,
// non-vpn

View file

@ -337,7 +337,7 @@ bool ServerController::isReinstallContainerRequired(DockerContainer container, c
!= newProtoConfig.value(config_key::port).toString(protocols::shadowsocks::defaultPort))
return true;
}
if (container == DockerContainer::Awg) {
return true;
}
@ -490,8 +490,7 @@ ServerController::Vars ServerController::genVarsForScript(const ServerCredential
const QJsonObject &cloakConfig = config.value(ProtocolProps::protoToString(Proto::Cloak)).toObject();
const QJsonObject &ssConfig = config.value(ProtocolProps::protoToString(Proto::ShadowSocks)).toObject();
const QJsonObject &wireguarConfig = config.value(ProtocolProps::protoToString(Proto::WireGuard)).toObject();
const QJsonObject &amneziaWireguarConfig =
config.value(ProtocolProps::protoToString(Proto::Awg)).toObject();
const QJsonObject &amneziaWireguarConfig = config.value(ProtocolProps::protoToString(Proto::Awg)).toObject();
const QJsonObject &sftpConfig = config.value(ProtocolProps::protoToString(Proto::Sftp)).toObject();
Vars vars;
@ -591,33 +590,21 @@ ServerController::Vars ServerController::genVarsForScript(const ServerCredential
// Amnezia wireguard vars
vars.append({ { "$AWG_SERVER_PORT",
amneziaWireguarConfig.value(config_key::port).toString(protocols::awg::defaultPort) } });
vars.append({ { "$JUNK_PACKET_COUNT",
amneziaWireguarConfig.value(config_key::junkPacketCount)
.toString(protocols::awg::defaultJunkPacketCount) } });
vars.append({ { "$JUNK_PACKET_MIN_SIZE",
amneziaWireguarConfig.value(config_key::junkPacketMinSize)
.toString(protocols::awg::defaultJunkPacketMinSize) } });
vars.append({ { "$JUNK_PACKET_MAX_SIZE",
amneziaWireguarConfig.value(config_key::junkPacketMaxSize)
.toString(protocols::awg::defaultJunkPacketMaxSize) } });
vars.append({ { "$INIT_PACKET_JUNK_SIZE",
amneziaWireguarConfig.value(config_key::initPacketJunkSize)
.toString(protocols::awg::defaultInitPacketJunkSize) } });
vars.append({ { "$JUNK_PACKET_COUNT", amneziaWireguarConfig.value(config_key::junkPacketCount).toString() } });
vars.append({ { "$JUNK_PACKET_MIN_SIZE", amneziaWireguarConfig.value(config_key::junkPacketMinSize).toString() } });
vars.append({ { "$JUNK_PACKET_MAX_SIZE", amneziaWireguarConfig.value(config_key::junkPacketMaxSize).toString() } });
vars.append({ { "$INIT_PACKET_JUNK_SIZE", amneziaWireguarConfig.value(config_key::initPacketJunkSize).toString() } });
vars.append({ { "$RESPONSE_PACKET_JUNK_SIZE",
amneziaWireguarConfig.value(config_key::responsePacketJunkSize)
.toString(protocols::awg::defaultResponsePacketJunkSize) } });
amneziaWireguarConfig.value(config_key::responsePacketJunkSize).toString() } });
vars.append({ { "$INIT_PACKET_MAGIC_HEADER",
amneziaWireguarConfig.value(config_key::initPacketMagicHeader)
.toString(protocols::awg::defaultInitPacketMagicHeader) } });
amneziaWireguarConfig.value(config_key::initPacketMagicHeader).toString() } });
vars.append({ { "$RESPONSE_PACKET_MAGIC_HEADER",
amneziaWireguarConfig.value(config_key::responsePacketMagicHeader)
.toString(protocols::awg::defaultResponsePacketMagicHeader) } });
amneziaWireguarConfig.value(config_key::responsePacketMagicHeader).toString() } });
vars.append({ { "$UNDERLOAD_PACKET_MAGIC_HEADER",
amneziaWireguarConfig.value(config_key::underloadPacketMagicHeader)
.toString(protocols::awg::defaultUnderloadPacketMagicHeader) } });
amneziaWireguarConfig.value(config_key::underloadPacketMagicHeader).toString() } });
vars.append({ { "$TRANSPORT_PACKET_MAGIC_HEADER",
amneziaWireguarConfig.value(config_key::transportPacketMagicHeader)
.toString(protocols::awg::defaultTransportPacketMagicHeader) } });
amneziaWireguarConfig.value(config_key::transportPacketMagicHeader).toString() } });
QString serverIp = Utils::getIPAddress(credentials.hostName);
if (!serverIp.isEmpty()) {

View file

@ -1,5 +1,7 @@
#include "protocols_defs.h"
#include <QRandomGenerator>
using namespace amnezia;
QDebug operator<<(QDebug debug, const amnezia::ProtocolEnumNS::Proto &p)
@ -98,15 +100,28 @@ amnezia::ServiceType ProtocolProps::protocolService(Proto p)
}
}
int ProtocolProps::getPortForInstall(Proto p)
{
switch (p) {
case Awg:
case WireGuard:
case ShadowSocks:
case OpenVpn:
return QRandomGenerator::global()->bounded(30000, 50000);
default:
return defaultPort(p);
}
}
int ProtocolProps::defaultPort(Proto p)
{
switch (p) {
case Proto::Any: return -1;
case Proto::OpenVpn: return 1194;
case Proto::Cloak: return 443;
case Proto::ShadowSocks: return 6789;
case Proto::WireGuard: return 51820;
case Proto::Awg: return 55424;
case Proto::OpenVpn: return QString(protocols::openvpn::defaultPort).toInt();
case Proto::Cloak: return QString(protocols::cloak::defaultPort).toInt();
case Proto::ShadowSocks: return QString(protocols::shadowsocks::defaultPort).toInt();
case Proto::WireGuard: return QString(protocols::wireguard::defaultPort).toInt();
case Proto::Awg: return QString(protocols::awg::defaultPort).toInt();
case Proto::Ikev2: return -1;
case Proto::L2tp: return -1;

View file

@ -228,6 +228,8 @@ namespace amnezia
Q_INVOKABLE static ServiceType protocolService(Proto p);
Q_INVOKABLE static int getPortForInstall(Proto p);
Q_INVOKABLE static int defaultPort(Proto p);
Q_INVOKABLE static bool defaultPortChangeable(Proto p);

View file

@ -143,58 +143,58 @@
<context>
<name>InstallController</name>
<message>
<location filename="../ui/controllers/installController.cpp" line="110"/>
<location filename="../ui/controllers/installController.cpp" line="161"/>
<location filename="../ui/controllers/installController.cpp" line="141"/>
<location filename="../ui/controllers/installController.cpp" line="192"/>
<source>%1 installed successfully. </source>
<translation>%1 успешно установлен. </translation>
</message>
<message>
<location filename="../ui/controllers/installController.cpp" line="112"/>
<location filename="../ui/controllers/installController.cpp" line="163"/>
<location filename="../ui/controllers/installController.cpp" line="143"/>
<location filename="../ui/controllers/installController.cpp" line="194"/>
<source>%1 is already installed on the server. </source>
<translation>%1 уже установлен на сервер. </translation>
</message>
<message>
<location filename="../ui/controllers/installController.cpp" line="115"/>
<location filename="../ui/controllers/installController.cpp" line="146"/>
<source>
Added containers that were already installed on the server</source>
<translation>
В приложение добавлены обнаруженные на сервере протоклы и сервисы</translation>
</message>
<message>
<location filename="../ui/controllers/installController.cpp" line="182"/>
<location filename="../ui/controllers/installController.cpp" line="213"/>
<source>
Already installed containers were found on the server. All installed containers have been added to the application</source>
<translation>
На сервере обнаружены установленные протоколы и сервисы, все они добавлены в приложение</translation>
</message>
<message>
<location filename="../ui/controllers/installController.cpp" line="266"/>
<location filename="../ui/controllers/installController.cpp" line="297"/>
<source>Settings updated successfully</source>
<translation>Настройки успешно обновлены</translation>
</message>
<message>
<location filename="../ui/controllers/installController.cpp" line="281"/>
<location filename="../ui/controllers/installController.cpp" line="312"/>
<source>Server &apos;%1&apos; was removed</source>
<translation>Сервер &apos;%1&apos; был удален</translation>
</message>
<message>
<location filename="../ui/controllers/installController.cpp" line="291"/>
<location filename="../ui/controllers/installController.cpp" line="322"/>
<source>All containers from server &apos;%1&apos; have been removed</source>
<translation>Все протоклы и сервисы были удалены с сервера &apos;%1&apos;</translation>
</message>
<message>
<location filename="../ui/controllers/installController.cpp" line="308"/>
<location filename="../ui/controllers/installController.cpp" line="339"/>
<source>%1 has been removed from the server &apos;%2&apos;</source>
<translation>%1 был удален с сервера &apos;%2&apos;</translation>
</message>
<message>
<location filename="../ui/controllers/installController.cpp" line="454"/>
<location filename="../ui/controllers/installController.cpp" line="485"/>
<source>Please login as the user</source>
<translation>Пожалуйста, войдите в систему от имени пользователя</translation>
</message>
<message>
<location filename="../ui/controllers/installController.cpp" line="483"/>
<location filename="../ui/controllers/installController.cpp" line="514"/>
<source>Server added successfully</source>
<translation>Сервер успешно добавлен</translation>
</message>
@ -2700,6 +2700,16 @@ This means that AmneziaWG keeps the fast performance of the original while addin
<source>error 0x%1: %2</source>
<translation>error 0x%1: %2</translation>
</message>
<message>
<location filename="../3rd/wireguard-tools/contrib/highlighter/gui/highlight.cpp" line="39"/>
<source>WireGuard Configuration Highlighter</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../3rd/wireguard-tools/contrib/highlighter/gui/highlight.cpp" line="82"/>
<source>&amp;Randomize colors</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SelectLanguageDrawer</name>

View file

@ -162,47 +162,47 @@
<translation type="obsolete"> </translation>
</message>
<message>
<location filename="../ui/controllers/installController.cpp" line="110"/>
<location filename="../ui/controllers/installController.cpp" line="161"/>
<location filename="../ui/controllers/installController.cpp" line="141"/>
<location filename="../ui/controllers/installController.cpp" line="192"/>
<source>%1 installed successfully. </source>
<translation>%1 </translation>
</message>
<message>
<location filename="../ui/controllers/installController.cpp" line="112"/>
<location filename="../ui/controllers/installController.cpp" line="163"/>
<location filename="../ui/controllers/installController.cpp" line="143"/>
<location filename="../ui/controllers/installController.cpp" line="194"/>
<source>%1 is already installed on the server. </source>
<translation> %1</translation>
</message>
<message>
<location filename="../ui/controllers/installController.cpp" line="115"/>
<location filename="../ui/controllers/installController.cpp" line="146"/>
<source>
Added containers that were already installed on the server</source>
<translation></translation>
</message>
<message>
<location filename="../ui/controllers/installController.cpp" line="182"/>
<location filename="../ui/controllers/installController.cpp" line="213"/>
<source>
Already installed containers were found on the server. All installed containers have been added to the application</source>
<translation>
</translation>
</message>
<message>
<location filename="../ui/controllers/installController.cpp" line="266"/>
<location filename="../ui/controllers/installController.cpp" line="297"/>
<source>Settings updated successfully</source>
<translation></translation>
</message>
<message>
<location filename="../ui/controllers/installController.cpp" line="281"/>
<location filename="../ui/controllers/installController.cpp" line="312"/>
<source>Server &apos;%1&apos; was removed</source>
<translation> &apos;%1&apos;</translation>
</message>
<message>
<location filename="../ui/controllers/installController.cpp" line="291"/>
<location filename="../ui/controllers/installController.cpp" line="322"/>
<source>All containers from server &apos;%1&apos; have been removed</source>
<translation> &apos;%1&apos; </translation>
</message>
<message>
<location filename="../ui/controllers/installController.cpp" line="308"/>
<location filename="../ui/controllers/installController.cpp" line="339"/>
<source>%1 has been removed from the server &apos;%2&apos;</source>
<translation>%1 &apos;%2&apos; </translation>
</message>
@ -223,12 +223,12 @@ Already installed containers were found on the server. All installed containers
<translation type="obsolete"> </translation>
</message>
<message>
<location filename="../ui/controllers/installController.cpp" line="454"/>
<location filename="../ui/controllers/installController.cpp" line="485"/>
<source>Please login as the user</source>
<translation></translation>
</message>
<message>
<location filename="../ui/controllers/installController.cpp" line="483"/>
<location filename="../ui/controllers/installController.cpp" line="514"/>
<source>Server added successfully</source>
<translation></translation>
</message>
@ -2839,6 +2839,16 @@ While it offers a blend of security, stability, and speed, it&apos;s essential t
<source>error 0x%1: %2</source>
<translation> 0x%1: %2</translation>
</message>
<message>
<location filename="../3rd/wireguard-tools/contrib/highlighter/gui/highlight.cpp" line="39"/>
<source>WireGuard Configuration Highlighter</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../3rd/wireguard-tools/contrib/highlighter/gui/highlight.cpp" line="82"/>
<source>&amp;Randomize colors</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SelectLanguageDrawer</name>

View file

@ -5,6 +5,7 @@
#include <QEventLoop>
#include <QJsonObject>
#include <QStandardPaths>
#include <QRandomGenerator>
#include "core/errorstrings.h"
#include "core/servercontroller.h"
@ -73,6 +74,38 @@ void InstallController::install(DockerContainer container, int port, TransportPr
containerConfig.insert(config_key::transport_proto,
ProtocolProps::transportProtoToString(transportProto, protocol));
if (container == DockerContainer::Awg) {
QString junkPacketCount = QString::number(QRandomGenerator::global()->bounded(3, 10));
QString junkPacketMinSize = QString::number(50);
QString junkPacketMaxSize = QString::number(1000);
QString initPacketJunkSize = QString::number(QRandomGenerator::global()->bounded(15, 150));
QString responsePacketJunkSize = QString::number(QRandomGenerator::global()->bounded(15, 150));
QSet<QString> headersValue;
while (headersValue.size() != 4) {
auto max = (std::numeric_limits<qint32>::max)();
headersValue.insert(QString::number(QRandomGenerator::global()->bounded(1, max)));
}
auto headersValueList = headersValue.values();
QString initPacketMagicHeader = headersValueList.at(0);
QString responsePacketMagicHeader = headersValueList.at(1);
QString underloadPacketMagicHeader = headersValueList.at(2);
QString transportPacketMagicHeader = headersValueList.at(3);
containerConfig[config_key::junkPacketCount] = junkPacketCount;
containerConfig[config_key::junkPacketMinSize] = junkPacketMinSize;
containerConfig[config_key::junkPacketMaxSize] = junkPacketMaxSize;
containerConfig[config_key::initPacketJunkSize] = initPacketJunkSize;
containerConfig[config_key::responsePacketJunkSize] = responsePacketJunkSize;
containerConfig[config_key::initPacketMagicHeader] = initPacketMagicHeader;
containerConfig[config_key::responsePacketMagicHeader] = responsePacketMagicHeader;
containerConfig[config_key::underloadPacketMagicHeader] = underloadPacketMagicHeader;
containerConfig[config_key::transportPacketMagicHeader] = transportPacketMagicHeader;
}
if (container == DockerContainer::Sftp) {
containerConfig.insert(config_key::userName, protocols::sftp::defaultUserName);
containerConfig.insert(config_key::password, Utils::getRandomString(10));

View file

@ -224,7 +224,7 @@ PageType {
if (ProtocolProps.defaultPort(defaultContainerProto) < 0) {
port.visible = false
} else {
port.textFieldText = ProtocolProps.defaultPort(defaultContainerProto)
port.textFieldText = ProtocolProps.getPortForInstall(defaultContainerProto)
}
transportProtoSelector.currentIndex = ProtocolProps.defaultTransportProto(defaultContainerProto)