From fd63c8377af12d92370c5e1675c8d3c668b6363f Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sun, 29 Sep 2024 11:07:45 +0800 Subject: [PATCH] Add obfs for Hysteria2 --- .../kotlin/com/neko/v2ray/dto/Hysteria2Bean.kt | 16 +++++++++++++--- .../kotlin/com/neko/v2ray/dto/V2rayConfig.kt | 3 ++- .../kotlin/com/neko/v2ray/ui/ServerActivity.kt | 7 +++++++ .../com/neko/v2ray/util/fmt/Hysteria2Fmt.kt | 17 +++++++++++++++++ .../res/layout/activity_server_hysteria2.xml | 18 ++++++++++++++++++ app/src/main/res/values-ar/strings.xml | 1 + app/src/main/res/values-fa/strings.xml | 1 + app/src/main/res/values-in/strings.xml | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-jw/strings.xml | 1 + app/src/main/res/values-ru/strings.xml | 1 + app/src/main/res/values-su/strings.xml | 1 + app/src/main/res/values-vi/strings.xml | 1 + app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 16 files changed, 68 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/neko/v2ray/dto/Hysteria2Bean.kt b/app/src/main/kotlin/com/neko/v2ray/dto/Hysteria2Bean.kt index 714092fa..25bb29bd 100644 --- a/app/src/main/kotlin/com/neko/v2ray/dto/Hysteria2Bean.kt +++ b/app/src/main/kotlin/com/neko/v2ray/dto/Hysteria2Bean.kt @@ -4,9 +4,19 @@ data class Hysteria2Bean( val server: String?, val auth: String?, val lazy: Boolean? = true, - val socks5: Socks5Bean?, - val tls: TlsBean? + val obfs: ObfsBean? = null, + val socks5: Socks5Bean? = null, + val tls: TlsBean? = null, ) { + data class ObfsBean( + val type: String?, + val salamander: SalamanderBean? + ) { + data class SalamanderBean( + val password: String?, + ) + } + data class Socks5Bean( val listen: String?, ) @@ -15,4 +25,4 @@ data class Hysteria2Bean( val sni: String?, val insecure: Boolean?, ) -} \ No newline at end of file +} diff --git a/app/src/main/kotlin/com/neko/v2ray/dto/V2rayConfig.kt b/app/src/main/kotlin/com/neko/v2ray/dto/V2rayConfig.kt index 89933106..8f2facb7 100644 --- a/app/src/main/kotlin/com/neko/v2ray/dto/V2rayConfig.kt +++ b/app/src/main/kotlin/com/neko/v2ray/dto/V2rayConfig.kt @@ -104,7 +104,8 @@ data class V2rayConfig( var secretKey: String? = null, val peers: List? = null, var reserved: List? = null, - var mtu: Int? = null + var mtu: Int? = null, + var obfsPassword: String? = null, ) { data class VnextBean( diff --git a/app/src/main/kotlin/com/neko/v2ray/ui/ServerActivity.kt b/app/src/main/kotlin/com/neko/v2ray/ui/ServerActivity.kt index 861714ae..2971d65d 100644 --- a/app/src/main/kotlin/com/neko/v2ray/ui/ServerActivity.kt +++ b/app/src/main/kotlin/com/neko/v2ray/ui/ServerActivity.kt @@ -133,6 +133,7 @@ class ServerActivity : BaseActivity() { private val et_reserved3: EditText? by lazy { findViewById(R.id.et_reserved3) } private val et_local_address: EditText? by lazy { findViewById(R.id.et_local_address) } private val et_local_mtu: EditText? by lazy { findViewById(R.id.et_local_mtu) } + private val et_obfs_password: EditText? by lazy { findViewById(R.id.et_obfs_password) } override fun onCreate(savedInstanceState: Bundle?) { @@ -348,7 +349,10 @@ class ServerActivity : BaseActivity() { } else { et_local_mtu?.text = Utils.getEditable(outbound.settings?.mtu.toString()) } + } else if (config.configType == EConfigType.HYSTERIA2) { + et_obfs_password?.text = Utils.getEditable(outbound.settings?.obfsPassword) } + val securityEncryptions = if (config.configType == EConfigType.SHADOWSOCKS) shadowsocksSecuritys else securitys val security = @@ -511,6 +515,9 @@ class ServerActivity : BaseActivity() { if (config.subscriptionId.isEmpty() && !subscriptionId.isNullOrEmpty()) { config.subscriptionId = subscriptionId.orEmpty() } + if (config.configType == EConfigType.HYSTERIA2) { + config.outboundBean?.settings?.obfsPassword = et_obfs_password?.text?.toString() + } MmkvManager.encodeServerConfig(editGuid, config) toast(R.string.toast_success) diff --git a/app/src/main/kotlin/com/neko/v2ray/util/fmt/Hysteria2Fmt.kt b/app/src/main/kotlin/com/neko/v2ray/util/fmt/Hysteria2Fmt.kt index 7eb640dd..6b4227df 100644 --- a/app/src/main/kotlin/com/neko/v2ray/util/fmt/Hysteria2Fmt.kt +++ b/app/src/main/kotlin/com/neko/v2ray/util/fmt/Hysteria2Fmt.kt @@ -40,6 +40,10 @@ object Hysteria2Fmt { server.port = uri.port server.password = uri.userInfo } + if (!queryParam["obfs-password"].isNullOrEmpty()) { + config.outboundBean?.settings?.obfsPassword = queryParam["obfs-password"] + } + return config } @@ -59,6 +63,10 @@ object Hysteria2Fmt { dicQuery["alpn"] = Utils.removeWhiteSpace(tlsSetting.alpn.joinToString(",")).orEmpty() } } + if (!outbound.settings?.obfsPassword.isNullOrEmpty()) { + dicQuery["obfs"] = "salamander" + dicQuery["obfs-password"] = outbound.settings?.obfsPassword ?: "" + } val query = "?" + dicQuery.toList().joinToString( separator = "&", @@ -76,9 +84,18 @@ object Hysteria2Fmt { fun toNativeConfig(config: ServerConfig, socksPort: Int): Hysteria2Bean? { val outbound = config.getProxyOutbound() ?: return null val tls = outbound.streamSettings?.tlsSettings + val obfs = if (outbound.settings?.obfsPassword.isNullOrEmpty()) null else + Hysteria2Bean.ObfsBean( + type = "salamander", + salamander = Hysteria2Bean.ObfsBean.SalamanderBean( + password = outbound.settings?.obfsPassword + ) + ) + val bean = Hysteria2Bean( server = outbound.getServerAddressAndPort(), auth = outbound.getPassword(), + obfs = obfs, socks5 = Hysteria2Bean.Socks5Bean( listen = "$LOOPBACK:${socksPort}", ), diff --git a/app/src/main/res/layout/activity_server_hysteria2.xml b/app/src/main/res/layout/activity_server_hysteria2.xml index 8b951e62..5e98f998 100644 --- a/app/src/main/res/layout/activity_server_hysteria2.xml +++ b/app/src/main/res/layout/activity_server_hysteria2.xml @@ -276,6 +276,24 @@ android:layout_marginStart="16.0dip" android:layout_marginEnd="16.0dip"> + + + + + لم يتم العثور على الملف الملاحظات موجودة بالفعل الإجراء غير مسموح به + كلمة مرور Obfs تحميل diff --git a/app/src/main/res/values-fa/strings.xml b/app/src/main/res/values-fa/strings.xml index 314d470a..6137f387 100644 --- a/app/src/main/res/values-fa/strings.xml +++ b/app/src/main/res/values-fa/strings.xml @@ -103,6 +103,7 @@ فایل پیدا نشد اظهارات قبلاً وجود دارد اقدام مجاز نیست + رمز عبور Obfs diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index 4c55c746..1956e736 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -103,6 +103,7 @@ File tidak ditemukan Keterangan sudah ada Tindakan tidak diizinkan + Kata sandi obfs Memuat diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index cf8fbbd5..3bf6f959 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -103,6 +103,7 @@ ファイルが見つかりません コメントはすでに存在します 許可されていないアクション + Obfsパスワード 読み込み中 diff --git a/app/src/main/res/values-jw/strings.xml b/app/src/main/res/values-jw/strings.xml index 2445d2b3..27af2d7f 100644 --- a/app/src/main/res/values-jw/strings.xml +++ b/app/src/main/res/values-jw/strings.xml @@ -103,6 +103,7 @@ File ora ditemokake Deskripsi wis ana Tindakan ora diidini + Obfs sandi Loading diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index eed74034..ec477b67 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -103,6 +103,7 @@ Файл не найден Замечания уже есть Действие не разрешено + пароль obfs Загрузка diff --git a/app/src/main/res/values-su/strings.xml b/app/src/main/res/values-su/strings.xml index c4e1e596..f7803120 100644 --- a/app/src/main/res/values-su/strings.xml +++ b/app/src/main/res/values-su/strings.xml @@ -103,6 +103,7 @@ File henteu kapendak Inpormasi parantos aya Aksi teu diwenangkeun + sandi Obfs ngamuat diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index 4acb90e9..681bc9c1 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -103,6 +103,7 @@ Không tìm thấy tập tin Nhận xét đã tồn tại Hành động không được phép + Mật khẩu Obfs Đang tải diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index bc9e4612..eba969bf 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -103,6 +103,7 @@ 文件未找到 备注已经存在 不允许的操作 + Obfs 密码 加载中 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index d48a90ba..de12bb3c 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -103,6 +103,7 @@ 文件未找到 備註已經存在 不允許執行的操作 + OBFS密碼 載入中 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7c012090..c521d901 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -103,6 +103,7 @@ File not found The remarks already exists Action not allowed + Obfs password Loading