added generation of random values for awg parameters

This commit is contained in:
vladimir.kuznetsov 2023-10-19 01:14:09 +05:00
parent e2ae341ba9
commit 79e1761c1f
4 changed files with 87 additions and 49 deletions

View file

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

View file

@ -143,58 +143,58 @@
<context> <context>
<name>InstallController</name> <name>InstallController</name>
<message> <message>
<location filename="../ui/controllers/installController.cpp" line="110"/> <location filename="../ui/controllers/installController.cpp" line="141"/>
<location filename="../ui/controllers/installController.cpp" line="161"/> <location filename="../ui/controllers/installController.cpp" line="192"/>
<source>%1 installed successfully. </source> <source>%1 installed successfully. </source>
<translation>%1 успешно установлен. </translation> <translation>%1 успешно установлен. </translation>
</message> </message>
<message> <message>
<location filename="../ui/controllers/installController.cpp" line="112"/> <location filename="../ui/controllers/installController.cpp" line="143"/>
<location filename="../ui/controllers/installController.cpp" line="163"/> <location filename="../ui/controllers/installController.cpp" line="194"/>
<source>%1 is already installed on the server. </source> <source>%1 is already installed on the server. </source>
<translation>%1 уже установлен на сервер. </translation> <translation>%1 уже установлен на сервер. </translation>
</message> </message>
<message> <message>
<location filename="../ui/controllers/installController.cpp" line="115"/> <location filename="../ui/controllers/installController.cpp" line="146"/>
<source> <source>
Added containers that were already installed on the server</source> Added containers that were already installed on the server</source>
<translation> <translation>
В приложение добавлены обнаруженные на сервере протоклы и сервисы</translation> В приложение добавлены обнаруженные на сервере протоклы и сервисы</translation>
</message> </message>
<message> <message>
<location filename="../ui/controllers/installController.cpp" line="182"/> <location filename="../ui/controllers/installController.cpp" line="213"/>
<source> <source>
Already installed containers were found on the server. All installed containers have been added to the application</source> Already installed containers were found on the server. All installed containers have been added to the application</source>
<translation> <translation>
На сервере обнаружены установленные протоколы и сервисы, все они добавлены в приложение</translation> На сервере обнаружены установленные протоколы и сервисы, все они добавлены в приложение</translation>
</message> </message>
<message> <message>
<location filename="../ui/controllers/installController.cpp" line="266"/> <location filename="../ui/controllers/installController.cpp" line="297"/>
<source>Settings updated successfully</source> <source>Settings updated successfully</source>
<translation>Настройки успешно обновлены</translation> <translation>Настройки успешно обновлены</translation>
</message> </message>
<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> <source>Server &apos;%1&apos; was removed</source>
<translation>Сервер &apos;%1&apos; был удален</translation> <translation>Сервер &apos;%1&apos; был удален</translation>
</message> </message>
<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> <source>All containers from server &apos;%1&apos; have been removed</source>
<translation>Все протоклы и сервисы были удалены с сервера &apos;%1&apos;</translation> <translation>Все протоклы и сервисы были удалены с сервера &apos;%1&apos;</translation>
</message> </message>
<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> <source>%1 has been removed from the server &apos;%2&apos;</source>
<translation>%1 был удален с сервера &apos;%2&apos;</translation> <translation>%1 был удален с сервера &apos;%2&apos;</translation>
</message> </message>
<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> <source>Please login as the user</source>
<translation>Пожалуйста, войдите в систему от имени пользователя</translation> <translation>Пожалуйста, войдите в систему от имени пользователя</translation>
</message> </message>
<message> <message>
<location filename="../ui/controllers/installController.cpp" line="483"/> <location filename="../ui/controllers/installController.cpp" line="514"/>
<source>Server added successfully</source> <source>Server added successfully</source>
<translation>Сервер успешно добавлен</translation> <translation>Сервер успешно добавлен</translation>
</message> </message>
@ -2700,6 +2700,16 @@ This means that AmneziaWG keeps the fast performance of the original while addin
<source>error 0x%1: %2</source> <source>error 0x%1: %2</source>
<translation>error 0x%1: %2</translation> <translation>error 0x%1: %2</translation>
</message> </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>
<context> <context>
<name>SelectLanguageDrawer</name> <name>SelectLanguageDrawer</name>

View file

@ -162,47 +162,47 @@
<translation type="obsolete"> </translation> <translation type="obsolete"> </translation>
</message> </message>
<message> <message>
<location filename="../ui/controllers/installController.cpp" line="110"/> <location filename="../ui/controllers/installController.cpp" line="141"/>
<location filename="../ui/controllers/installController.cpp" line="161"/> <location filename="../ui/controllers/installController.cpp" line="192"/>
<source>%1 installed successfully. </source> <source>%1 installed successfully. </source>
<translation>%1 </translation> <translation>%1 </translation>
</message> </message>
<message> <message>
<location filename="../ui/controllers/installController.cpp" line="112"/> <location filename="../ui/controllers/installController.cpp" line="143"/>
<location filename="../ui/controllers/installController.cpp" line="163"/> <location filename="../ui/controllers/installController.cpp" line="194"/>
<source>%1 is already installed on the server. </source> <source>%1 is already installed on the server. </source>
<translation> %1</translation> <translation> %1</translation>
</message> </message>
<message> <message>
<location filename="../ui/controllers/installController.cpp" line="115"/> <location filename="../ui/controllers/installController.cpp" line="146"/>
<source> <source>
Added containers that were already installed on the server</source> Added containers that were already installed on the server</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../ui/controllers/installController.cpp" line="182"/> <location filename="../ui/controllers/installController.cpp" line="213"/>
<source> <source>
Already installed containers were found on the server. All installed containers have been added to the application</source> Already installed containers were found on the server. All installed containers have been added to the application</source>
<translation> <translation>
</translation> </translation>
</message> </message>
<message> <message>
<location filename="../ui/controllers/installController.cpp" line="266"/> <location filename="../ui/controllers/installController.cpp" line="297"/>
<source>Settings updated successfully</source> <source>Settings updated successfully</source>
<translation></translation> <translation></translation>
</message> </message>
<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> <source>Server &apos;%1&apos; was removed</source>
<translation> &apos;%1&apos;</translation> <translation> &apos;%1&apos;</translation>
</message> </message>
<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> <source>All containers from server &apos;%1&apos; have been removed</source>
<translation> &apos;%1&apos; </translation> <translation> &apos;%1&apos; </translation>
</message> </message>
<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> <source>%1 has been removed from the server &apos;%2&apos;</source>
<translation>%1 &apos;%2&apos; </translation> <translation>%1 &apos;%2&apos; </translation>
</message> </message>
@ -223,12 +223,12 @@ Already installed containers were found on the server. All installed containers
<translation type="obsolete"> </translation> <translation type="obsolete"> </translation>
</message> </message>
<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> <source>Please login as the user</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../ui/controllers/installController.cpp" line="483"/> <location filename="../ui/controllers/installController.cpp" line="514"/>
<source>Server added successfully</source> <source>Server added successfully</source>
<translation></translation> <translation></translation>
</message> </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> <source>error 0x%1: %2</source>
<translation> 0x%1: %2</translation> <translation> 0x%1: %2</translation>
</message> </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>
<context> <context>
<name>SelectLanguageDrawer</name> <name>SelectLanguageDrawer</name>

View file

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