diff --git a/client/ui/controllers/installController.cpp b/client/ui/controllers/installController.cpp index e2e55c32..7a598872 100644 --- a/client/ui/controllers/installController.cpp +++ b/client/ui/controllers/installController.cpp @@ -89,14 +89,20 @@ void InstallController::install(DockerContainer container, int port, TransportPr 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)); + + int s1 = QRandomGenerator::global()->bounded(15, 150); + int s2 = QRandomGenerator::global()->bounded(15, 150); + while (s1 + AwgConstant::messageInitiationSize == s2 + AwgConstant::messageResponseSize) { + s2 = QRandomGenerator::global()->bounded(15, 150); + } + + QString initPacketJunkSize = QString::number(s1); + QString responsePacketJunkSize = QString::number(s2); QSet headersValue; while (headersValue.size() != 4) { - auto max = (std::numeric_limits::max)(); - headersValue.insert(QString::number(QRandomGenerator::global()->bounded(1, max))); + headersValue.insert(QString::number(QRandomGenerator::global()->bounded(5, max))); } auto headersValueList = headersValue.values(); diff --git a/client/ui/models/protocols/awgConfigModel.cpp b/client/ui/models/protocols/awgConfigModel.cpp index ba36c2a9..6b9234f4 100644 --- a/client/ui/models/protocols/awgConfigModel.cpp +++ b/client/ui/models/protocols/awgConfigModel.cpp @@ -129,6 +129,16 @@ QJsonObject AwgConfigModel::getConfig() return m_fullConfig; } +bool AwgConfigModel::isHeadersEqual(const QString &h1, const QString &h2, const QString &h3, const QString &h4) +{ + return (h1 == h2) || (h1 == h3) || (h1 == h4) || (h2 == h3) || (h2 == h4) || (h3 == h4); +} + +bool AwgConfigModel::isPacketSizeEqual(const int s1, const int s2) +{ + return (AwgConstant::messageInitiationSize + s1 == AwgConstant::messageResponseSize + s2); +} + QHash AwgConfigModel::roleNames() const { QHash roles; diff --git a/client/ui/models/protocols/awgConfigModel.h b/client/ui/models/protocols/awgConfigModel.h index e41d172d..80375d38 100644 --- a/client/ui/models/protocols/awgConfigModel.h +++ b/client/ui/models/protocols/awgConfigModel.h @@ -6,6 +6,11 @@ #include "containers/containers_defs.h" +namespace AwgConstant { + const int messageInitiationSize = 148; + const int messageResponseSize = 92; +} + struct AwgConfig { AwgConfig(const QJsonObject &jsonConfig); @@ -57,6 +62,9 @@ public slots: void updateModel(const QJsonObject &config); QJsonObject getConfig(); + bool isHeadersEqual(const QString &h1, const QString &h2, const QString &h3, const QString &h4); + bool isPacketSizeEqual(const int s1, const int s2); + protected: QHash roleNames() const override; diff --git a/client/ui/qml/Pages2/PageProtocolAwgSettings.qml b/client/ui/qml/Pages2/PageProtocolAwgSettings.qml index 29a7afda..32120627 100644 --- a/client/ui/qml/Pages2/PageProtocolAwgSettings.qml +++ b/client/ui/qml/Pages2/PageProtocolAwgSettings.qml @@ -136,7 +136,6 @@ PageType { textField.validator: IntValidator { bottom: 0 } textField.onEditingFinished: { - console.log("1") if (textFieldText === "") { textFieldText = "0" } @@ -332,6 +331,20 @@ PageType { text: qsTr("Save") onClicked: { + if (AwgConfigModel.isHeadersEqual(underloadPacketMagicHeaderTextField.textField.text, + transportPacketMagicHeaderTextField.textField.text, + responsePacketMagicHeaderTextField.textField.text, + initPacketMagicHeaderTextField.textField.text)) { + PageController.showErrorMessage(qsTr("The values of the H1-H4 fields must be unique")) + return + } + + if (AwgConfigModel.isPacketSizeEqual(parseInt(initPacketJunkSizeTextField.textField.text), + parseInt(responsePacketJunkSizeTextField.textField.text))) { + PageController.showErrorMessage(qsTr("The value of the field S1 + message initiation size (148) must not equal S2 + message response size (92)")) + return + } + var headerText = qsTr("Save settings?") var descriptionText = qsTr("All users with whom you shared a connection with will no longer be able to connect to it.") var yesButtonText = qsTr("Continue")