From 8451a64f3ec12c7561b1f2c95930c0cb980b01a7 Mon Sep 17 00:00:00 2001 From: CthulhuVRN Date: Mon, 16 Feb 2026 20:21:55 +0300 Subject: [PATCH] AmneziaWG 2.0: support for H1-H4 ranges ## Changes: ``` - [+] Added support for H1-H4 ranges - [!] Fixed interface fields order (H1-H4 goes before I1-I5) ``` ## Known issues: ``` - [!] no check for unique/overlap of H1-H4 values on settings apply: settings will be applied but wg interface will crash with "Invalid argument" error ``` --- src/i18n/locales/bg.json | 16 ++++++++-------- src/i18n/locales/de.json | 16 ++++++++-------- src/i18n/locales/fr.json | 16 ++++++++-------- src/i18n/locales/nb.json | 16 ++++++++-------- src/i18n/locales/nl.json | 16 ++++++++-------- src/i18n/locales/ru.json | 16 ++++++++-------- src/i18n/locales/uk.json | 16 ++++++++-------- src/i18n/locales/zh-CN.json | 16 ++++++++-------- src/i18n/locales/zh-TW.json | 16 ++++++++-------- src/server/utils/WireGuard.ts | 2 +- src/server/utils/types.ts | 25 +++++++++++++------------ 11 files changed, 86 insertions(+), 85 deletions(-) diff --git a/src/i18n/locales/bg.json b/src/i18n/locales/bg.json index bc1dc518..a79b2bef 100644 --- a/src/i18n/locales/bg.json +++ b/src/i18n/locales/bg.json @@ -262,6 +262,14 @@ "s3Description": "Размер на junk в cookie reply пакета", "s4Label": "Размер на junk в транспортния пакет (S4)", "s4Description": "Размер на junk в транспортния пакет", + "h1Label": "Init magic header (H1)", + "h1Description": "Стойност на хедера в init пакета (5–2147483647, уникална спрямо H2–H4)", + "h2Label": "Response magic header (H2)", + "h2Description": "Стойност на хедера в response пакета (5–2147483647, уникална спрямо H1, H3, H4)", + "h3Label": "Cookie reply magic header (H3)", + "h3Description": "Стойност на хедера в cookie reply пакета (5–2147483647, уникална спрямо H1, H2, H4)", + "h4Label": "Transport magic header (H4)", + "h4Description": "Стойност на хедера в транспортния пакет (5–2147483647, уникална спрямо H1–H3)", "i1Label": "Специален junk пакет 1 (I1)", "i1Description": "Пакет за имитация на протокол в hex формат: ", "i2Label": "Специален junk пакет 2 (I2)", @@ -272,14 +280,6 @@ "i4Description": "Пакет за имитация на протокол в hex формат: ", "i5Label": "Специален junk пакет 5 (I5)", "i5Description": "Пакет за имитация на протокол в hex формат: ", - "h1Label": "Init magic header (H1)", - "h1Description": "Стойност на хедера в init пакета (5–2147483647, уникална спрямо H2–H4)", - "h2Label": "Response magic header (H2)", - "h2Description": "Стойност на хедера в response пакета (5–2147483647, уникална спрямо H1, H3, H4)", - "h3Label": "Cookie reply magic header (H3)", - "h3Description": "Стойност на хедера в cookie reply пакета (5–2147483647, уникална спрямо H1, H2, H4)", - "h4Label": "Transport magic header (H4)", - "h4Description": "Стойност на хедера в транспортния пакет (5–2147483647, уникална спрямо H1–H3)", "mtuNote": "Стойностите зависят от MTU", "obfuscationParameters": "Параметри за обфускация на AmneziaWG" } diff --git a/src/i18n/locales/de.json b/src/i18n/locales/de.json index 47adc8a2..57bd01fa 100644 --- a/src/i18n/locales/de.json +++ b/src/i18n/locales/de.json @@ -262,6 +262,14 @@ "s3Description": "Junk-Paketgröße des Cookie-Antwort-Pakets", "s4Label": "Junk-Paketgröße des Transport-Pakets (S4)", "s4Description": "Junk-Paketgröße des Transport-Pakets", + "h1Label": "Init-Magic-Header (H1)", + "h1Description": "Wert des Init-Paket-Headers (5-2147483647, muss eindeutig zu H2-H4 sein)", + "h2Label": "Antwort-Magic-Header (H2)", + "h2Description": "Wert des Antwort-Paket-Headers (5-2147483647, muss eindeutig zu H1, H3, H4 sein)", + "h3Label": "Cookie-Antwort-Magic-Header (H3)", + "h3Description": "Wert des Cookie-Antwort-Paket-Headers (5-2147483647, muss eindeutig zu H1, H2, H4 sein)", + "h4Label": "Transport-Magic-Header (H4)", + "h4Description": "Wert des Transport-Paket-Headers (5-2147483647, muss eindeutig zu H1-H3 sein)", "i1Label": "Spezial-Junk-Paket 1 (I1)", "i1Description": "Protokoll-Nachahmungspaket im Hex-Format: ", "i2Label": "Spezial-Junk-Paket 2 (I2)", @@ -272,14 +280,6 @@ "i4Description": "Protokoll-Nachahmungspaket im Hex-Format: ", "i5Label": "Spezial-Junk-Paket 5 (I5)", "i5Description": "Protokoll-Nachahmungspaket im Hex-Format: ", - "h1Label": "Init-Magic-Header (H1)", - "h1Description": "Wert des Init-Paket-Headers (5-2147483647, muss eindeutig zu H2-H4 sein)", - "h2Label": "Antwort-Magic-Header (H2)", - "h2Description": "Wert des Antwort-Paket-Headers (5-2147483647, muss eindeutig zu H1, H3, H4 sein)", - "h3Label": "Cookie-Antwort-Magic-Header (H3)", - "h3Description": "Wert des Cookie-Antwort-Paket-Headers (5-2147483647, muss eindeutig zu H1, H2, H4 sein)", - "h4Label": "Transport-Magic-Header (H4)", - "h4Description": "Wert des Transport-Paket-Headers (5-2147483647, muss eindeutig zu H1-H3 sein)", "mtuNote": "Werte hängen von der MTU ab", "obfuscationParameters": "AmneziaWG Verschleierungsparameter" } diff --git a/src/i18n/locales/fr.json b/src/i18n/locales/fr.json index 18a0310c..bf275352 100644 --- a/src/i18n/locales/fr.json +++ b/src/i18n/locales/fr.json @@ -262,6 +262,14 @@ "s3Description": "Taille parasite du paquet de réponse cookie", "s4Label": "Taille parasite du paquet transport (S4)", "s4Description": "Taille parasite du paquet de transport", + "h1Label": "En-tête magique init (H1)", + "h1Description": "Valeur d'en-tête du paquet init (5-2147483647, doit être unique par rapport à H2-H4)", + "h2Label": "En-tête magique réponse (H2)", + "h2Description": "Valeur d'en-tête du paquet réponse (5-2147483647, doit être unique par rapport à H1, H3, H4)", + "h3Label": "En-tête magique cookie reply (H3)", + "h3Description": "Valeur d'en-tête du paquet cookie reply (5-2147483647, doit être unique par rapport à H1, H2, H4)", + "h4Label": "En-tête magique transport (H4)", + "h4Description": "Valeur d'en-tête du paquet transport (5-2147483647, doit être unique par rapport à H1-H3)", "i1Label": "Paquet parasite spécial 1 (I1)", "i1Description": "Paquet de simulation de protocole en format hexadécimal : ", "i2Label": "Paquet parasite spécial 2 (I2)", @@ -272,14 +280,6 @@ "i4Description": "Paquet de simulation de protocole en format hexadécimal : ", "i5Label": "Paquet parasite spécial 5 (I5)", "i5Description": "Paquet de simulation de protocole en format hexadécimal : ", - "h1Label": "En-tête magique init (H1)", - "h1Description": "Valeur d'en-tête du paquet init (5-2147483647, doit être unique par rapport à H2-H4)", - "h2Label": "En-tête magique réponse (H2)", - "h2Description": "Valeur d'en-tête du paquet réponse (5-2147483647, doit être unique par rapport à H1, H3, H4)", - "h3Label": "En-tête magique cookie reply (H3)", - "h3Description": "Valeur d'en-tête du paquet cookie reply (5-2147483647, doit être unique par rapport à H1, H2, H4)", - "h4Label": "En-tête magique transport (H4)", - "h4Description": "Valeur d'en-tête du paquet transport (5-2147483647, doit être unique par rapport à H1-H3)", "mtuNote": "Les valeurs dépendent du MTU", "obfuscationParameters": "Paramètres d'obfuscation AmneziaWG" } diff --git a/src/i18n/locales/nb.json b/src/i18n/locales/nb.json index 0172e0e8..001ef65f 100644 --- a/src/i18n/locales/nb.json +++ b/src/i18n/locales/nb.json @@ -262,6 +262,14 @@ "s3Description": "Cookie-svarpakke junk-størrelse", "s4Label": "Transportpakke junk-størrelse (S4)", "s4Description": "Transportpakke junk-størrelse", + "h1Label": "Init magisk header (H1)", + "h1Description": "Init-pakke header-verdi (5-2147483647, må være unik fra H2-H4)", + "h2Label": "Svar magisk header (H2)", + "h2Description": "Svarpakke header-verdi (5-2147483647, må være unik fra H1, H3, H4)", + "h3Label": "Cookie-svar magisk header (H3)", + "h3Description": "Cookie-svarpakke header-verdi (5-2147483647, må være unik fra H1, H2, H4)", + "h4Label": "Transport magisk header (H4)", + "h4Description": "Transportpakke header-verdi (5-2147483647, må være unik fra H1-H3)", "i1Label": "Spesiell junk-pakke 1 (I1)", "i1Description": "Protokolllignende pakke i heksformat: ", "i2Label": "Spesiell junk-pakke 2 (I2)", @@ -272,14 +280,6 @@ "i4Description": "Protokolllignende pakke i heksformat: ", "i5Label": "Spesiell junk-pakke 5 (I5)", "i5Description": "Protokolllignende pakke i heksformat: ", - "h1Label": "Init magisk header (H1)", - "h1Description": "Init-pakke header-verdi (5-2147483647, må være unik fra H2-H4)", - "h2Label": "Svar magisk header (H2)", - "h2Description": "Svarpakke header-verdi (5-2147483647, må være unik fra H1, H3, H4)", - "h3Label": "Cookie-svar magisk header (H3)", - "h3Description": "Cookie-svarpakke header-verdi (5-2147483647, må være unik fra H1, H2, H4)", - "h4Label": "Transport magisk header (H4)", - "h4Description": "Transportpakke header-verdi (5-2147483647, må være unik fra H1-H3)", "mtuNote": "Verdier avhenger av MTU", "obfuscationParameters": "AmneziaWG obfuskasjonsparametere" } diff --git a/src/i18n/locales/nl.json b/src/i18n/locales/nl.json index a1e591d4..977628b2 100644 --- a/src/i18n/locales/nl.json +++ b/src/i18n/locales/nl.json @@ -262,6 +262,14 @@ "s3Description": "Grootte Cookie reply packet junk", "s4Label": "Transport packet junk size (S4)", "s4Description": "Grootte Transport packet junk", + "h1Label": "Init magic header (H1)", + "h1Description": "Waarde Init packet header (5-2147483647, moet uniek zijn t.o.v. H2-H4)", + "h2Label": "Response magic header (H2)", + "h2Description": "Waarde Response packet header (5-2147483647, moet uniek zijn t.o.v. H1, H3, H4)", + "h3Label": "Cookie reply magic header (H3)", + "h3Description": "Waarde Cookie reply packet header (5-2147483647, moet uniek zijn t.o.v. H1, H2, H4)", + "h4Label": "Transport magic header (H4)", + "h4Description": "Waarde Transport packet header (5-2147483647, moet uniek zijn t.o.v. H1-H3)", "i1Label": "Special junk packet 1 (I1)", "i1Description": "Protocol mimic packet in hex formaat: ", "i2Label": "Special junk packet 2 (I2)", @@ -272,14 +280,6 @@ "i4Description": "Protocol mimic packet in hex formaat: ", "i5Label": "Special junk packet 5 (I5)", "i5Description": "Protocol mimic packet in hex formaat: ", - "h1Label": "Init magic header (H1)", - "h1Description": "Waarde Init packet header (5-2147483647, moet uniek zijn t.o.v. H2-H4)", - "h2Label": "Response magic header (H2)", - "h2Description": "Waarde Response packet header (5-2147483647, moet uniek zijn t.o.v. H1, H3, H4)", - "h3Label": "Cookie reply magic header (H3)", - "h3Description": "Waarde Cookie reply packet header (5-2147483647, moet uniek zijn t.o.v. H1, H2, H4)", - "h4Label": "Transport magic header (H4)", - "h4Description": "Waarde Transport packet header (5-2147483647, moet uniek zijn t.o.v. H1-H3)", "mtuNote": "Waarden zijn afhankelijk van de MTU", "obfuscationParameters": "AmneziaWG Obfuscation Parameters" } diff --git a/src/i18n/locales/ru.json b/src/i18n/locales/ru.json index be94543d..5e2e4278 100644 --- a/src/i18n/locales/ru.json +++ b/src/i18n/locales/ru.json @@ -262,6 +262,14 @@ "s3Description": "Размер мусорных данных в cookie-reply пакете", "s4Label": "Размер мусорных данных в транспортном пакете (S4)", "s4Description": "Размер мусорных данных в транспортном пакете", + "h1Label": "Init magic заголовок (H1)", + "h1Description": "Значение заголовка init-пакета (5-2147483647, должно отличаться от H2-H4)", + "h2Label": "Response magic заголовок (H2)", + "h2Description": "Значение заголовка ответного пакета (5-2147483647, должно отличаться от H1, H3, H4)", + "h3Label": "Cookie reply magic заголовок (H3)", + "h3Description": "Значение заголовка cookie-reply пакета (5-2147483647, должно отличаться от H1, H2, H4)", + "h4Label": "Transport magic заголовок (H4)", + "h4Description": "Значение заголовка транспортного пакета (5-2147483647, должно отличаться от H1-H3)", "i1Label": "Специальный мусорный пакет 1 (I1)", "i1Description": "Пакет имитации протокола в hex формате: ", "i2Label": "Специальный мусорный пакет 2 (I2)", @@ -272,14 +280,6 @@ "i4Description": "Пакет имитации протокола в hex формате: ", "i5Label": "Специальный мусорный пакет 5 (I5)", "i5Description": "Пакет имитации протокола в hex формате: ", - "h1Label": "Init magic заголовок (H1)", - "h1Description": "Значение заголовка init-пакета (5-2147483647, должно отличаться от H2-H4)", - "h2Label": "Response magic заголовок (H2)", - "h2Description": "Значение заголовка ответного пакета (5-2147483647, должно отличаться от H1, H3, H4)", - "h3Label": "Cookie reply magic заголовок (H3)", - "h3Description": "Значение заголовка cookie-reply пакета (5-2147483647, должно отличаться от H1, H2, H4)", - "h4Label": "Transport magic заголовок (H4)", - "h4Description": "Значение заголовка транспортного пакета (5-2147483647, должно отличаться от H1-H3)", "mtuNote": "Значения зависят от MTU", "obfuscationParameters": "Параметры обфускации AmneziaWG" } diff --git a/src/i18n/locales/uk.json b/src/i18n/locales/uk.json index d47c645b..dff4440f 100644 --- a/src/i18n/locales/uk.json +++ b/src/i18n/locales/uk.json @@ -262,6 +262,14 @@ "s3Description": "Розмір сміттєвих даних у пакеті «cookie reply»", "s4Label": "Розмір сміттєвих даних у транспортному пакеті (S4)", "s4Description": "Розмір сміттєвих даних у транспортному пакеті", + "h1Label": "Початковий магічний заголовок (H1)", + "h1Description": "Значення заголовка початкового пакета (5–2147483647, має бути унікальним від H2–H4)", + "h2Label": "Магічний заголовок відповіді (H2)", + "h2Description": "Значення заголовка пакета відповіді (5–2147483647, має бути унікальним від H1, H3, H4)", + "h3Label": "Магічний заголовок «cookie reply» (H3)", + "h3Description": "Значення заголовка пакета «cookie reply» (5–2147483647, має бути унікальним від H1, H2, H4)", + "h4Label": "Магічний заголовок транспортного пакета (H4)", + "h4Description": "Значення заголовка транспортного пакета (5–2147483647, має бути унікальним від H1–H3)", "i1Label": "Спеціальний сміттєвий пакет 1 (I1)", "i1Description": "Пакет-імітація протоколу у hex-форматі: ", "i2Label": "Спеціальний сміттєвий пакет 2 (I2)", @@ -272,14 +280,6 @@ "i4Description": "Пакет-імітація протоколу у hex-форматі: ", "i5Label": "Спеціальний сміттєвий пакет 5 (I5)", "i5Description": "Пакет-імітація протоколу у hex-форматі: ", - "h1Label": "Початковий магічний заголовок (H1)", - "h1Description": "Значення заголовка початкового пакета (5–2147483647, має бути унікальним від H2–H4)", - "h2Label": "Магічний заголовок відповіді (H2)", - "h2Description": "Значення заголовка пакета відповіді (5–2147483647, має бути унікальним від H1, H3, H4)", - "h3Label": "Магічний заголовок «cookie reply» (H3)", - "h3Description": "Значення заголовка пакета «cookie reply» (5–2147483647, має бути унікальним від H1, H2, H4)", - "h4Label": "Магічний заголовок транспортного пакета (H4)", - "h4Description": "Значення заголовка транспортного пакета (5–2147483647, має бути унікальним від H1–H3)", "mtuNote": "Значення залежать від MTU", "obfuscationParameters": "Параметри обфускації AmneziaWG" } diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json index b602284f..46e63abe 100644 --- a/src/i18n/locales/zh-CN.json +++ b/src/i18n/locales/zh-CN.json @@ -262,6 +262,14 @@ "s3Description": "Cookie 回复数据包中垃圾数据的大小", "s4Label": "传输数据包垃圾数据大小(S4)", "s4Description": "传输数据包中垃圾数据的大小", + "h1Label": "初始数据包魔术头部(H1)", + "h1Description": "初始数据包头部值(范围:5-2147483647,必须与 H2-H4 不同)", + "h2Label": "响应数据包魔术头部(H2)", + "h2Description": "响应数据包头部值(范围:5-2147483647,必须与 H1、H3、H4 不同)", + "h3Label": "Cookie 回复数据包魔术头部(H3)", + "h3Description": "Cookie 回复数据包头部值(范围:5-2147483647,必须与 H1、H2、H4 不同)", + "h4Label": "传输数据包魔术头部(H4)", + "h4Description": "传输数据包头部值(范围:5-2147483647,必须与 H1-H3 不同)", "i1Label": "特殊垃圾数据包 1(I1)", "i1Description": "协议模拟数据包(十六进制格式):", "i2Label": "特殊垃圾数据包 2(I2)", @@ -272,14 +280,6 @@ "i4Description": "协议模拟数据包(十六进制格式):", "i5Label": "特殊垃圾数据包 5(I5)", "i5Description": "协议模拟数据包(十六进制格式):", - "h1Label": "初始数据包魔术头部(H1)", - "h1Description": "初始数据包头部值(范围:5-2147483647,必须与 H2-H4 不同)", - "h2Label": "响应数据包魔术头部(H2)", - "h2Description": "响应数据包头部值(范围:5-2147483647,必须与 H1、H3、H4 不同)", - "h3Label": "Cookie 回复数据包魔术头部(H3)", - "h3Description": "Cookie 回复数据包头部值(范围:5-2147483647,必须与 H1、H2、H4 不同)", - "h4Label": "传输数据包魔术头部(H4)", - "h4Description": "传输数据包头部值(范围:5-2147483647,必须与 H1-H3 不同)", "mtuNote": "具体数值取决于 MTU(最大传输单元)", "obfuscationParameters": "AmneziaWG 混淆参数" } diff --git a/src/i18n/locales/zh-TW.json b/src/i18n/locales/zh-TW.json index 6253473c..08682694 100644 --- a/src/i18n/locales/zh-TW.json +++ b/src/i18n/locales/zh-TW.json @@ -262,6 +262,14 @@ "s3Description": "Cookie 回覆封包填充大小", "s4Label": "傳輸封包填充大小 (S4)", "s4Description": "傳輸封包填充大小", + "h1Label": "初始特徵標頭 (H1)", + "h1Description": "初始封包標頭值 (5-2147483647,必須與 H2-H4 不同)", + "h2Label": "回應特徵標頭 (H2)", + "h2Description": "回應封包標頭值 (5-2147483647,必須與 H1、H3、H4 不同)", + "h3Label": "Cookie 回覆特徵標頭 (H3)", + "h3Description": "Cookie 回覆封包標頭值 (5-2147483647,必須與 H1、H2、H4 不同)", + "h4Label": "傳輸特徵標頭 (H4)", + "h4Description": "傳輸封包標頭值 (5-2147483647,必須與 H1-H3 不同)", "i1Label": "特殊填充封包 1 (I1)", "i1Description": "協定模仿封包 (16 進位格式): ", "i2Label": "特殊填充封包 2 (I2)", @@ -272,14 +280,6 @@ "i4Description": "協定模仿封包 (16 進位格式): ", "i5Label": "特殊填充封包 5 (I5)", "i5Description": "協定模仿封包 (16 進位格式): ", - "h1Label": "初始特徵標頭 (H1)", - "h1Description": "初始封包標頭值 (5-2147483647,必須與 H2-H4 不同)", - "h2Label": "回應特徵標頭 (H2)", - "h2Description": "回應封包標頭值 (5-2147483647,必須與 H1、H3、H4 不同)", - "h3Label": "Cookie 回覆特徵標頭 (H3)", - "h3Description": "Cookie 回覆封包標頭值 (5-2147483647,必須與 H1、H2、H4 不同)", - "h4Label": "傳輸特徵標頭 (H4)", - "h4Description": "傳輸封包標頭值 (5-2147483647,必須與 H1-H3 不同)", "mtuNote": "數值取決於 MTU", "obfuscationParameters": "AmneziaWG 混淆參數" } diff --git a/src/server/utils/WireGuard.ts b/src/server/utils/WireGuard.ts index c73b8fdc..b2ec5ffe 100644 --- a/src/server/utils/WireGuard.ts +++ b/src/server/utils/WireGuard.ts @@ -213,7 +213,7 @@ class WireGuard { WG_DEBUG('New Wireguard Keys generated successfully.'); } - if (!wgInterface.h1) { + if (wgInterface.h1 === 0 || wgInterface.h1 === '0') { WG_DEBUG('Generating random AmneziaWG obfuscation parameters...'); const headers = new Set(); diff --git a/src/server/utils/types.ts b/src/server/utils/types.ts index b604c47b..83cd6e39 100644 --- a/src/server/utils/types.ts +++ b/src/server/utils/types.ts @@ -40,26 +40,27 @@ const H_MAX = 2 ** 31 - 1; export const HSchema = z .string() .transform(v => v.replace(/\s+/g, '')) - .refine(v => v === '' || /^\d+(-\d+)?$/.test(v), { - message: t('zod.generic.validNumberRange') - }) .refine(v => { - // if single number + if (!v) return false; + + if (!/^\d+(-\d+)?$/.test(v)) return false; + if (!v.includes('-')) { const num = Number(v); - if ( num < H_MIN || num > H_MAX ) - return false; - return `${num}`; + return num >= H_MIN && num <= H_MAX; } - - // if number range + const [min, max] = v.split('-').map(Number); - if ( min < H_MIN || max > H_MAX || min > max ) - return false; - return min === max ? `${min}` : `${min}-${max}`; + return min >= H_MIN && max <= H_MAX && min <= max; }, { message: t('zod.generic.validNumberRange') }) + .transform(v => { + if (!v.includes('-')) return `${Number(v)}`; + + const [min, max] = v.split('-').map(Number); + return min === max ? `${min}` : `${min}-${max}`; + }) .nullable(); export const ISchema = z.string().nullable();