Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Add obfs for Hysteria2
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust authored and AnGgIt86 committed Sep 30, 2024
1 parent cfb654a commit fd63c83
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 4 deletions.
16 changes: 13 additions & 3 deletions app/src/main/kotlin/com/neko/v2ray/dto/Hysteria2Bean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
)
Expand All @@ -15,4 +25,4 @@ data class Hysteria2Bean(
val sni: String?,
val insecure: Boolean?,
)
}
}
3 changes: 2 additions & 1 deletion app/src/main/kotlin/com/neko/v2ray/dto/V2rayConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ data class V2rayConfig(
var secretKey: String? = null,
val peers: List<WireGuardBean>? = null,
var reserved: List<Int>? = null,
var mtu: Int? = null
var mtu: Int? = null,
var obfsPassword: String? = null,
) {

data class VnextBean(
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/kotlin/com/neko/v2ray/ui/ServerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/kotlin/com/neko/v2ray/util/fmt/Hysteria2Fmt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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 = "&",
Expand All @@ -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}",
),
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/layout/activity_server_hysteria2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,24 @@
android:layout_marginStart="16.0dip"
android:layout_marginEnd="16.0dip">
<include layout="@layout/layout_address_port" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8.0dip"
android:layout_marginBottom="8.0dip">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/server_obfs_password"
style="@style/Outline_TextInputLayout">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_obfs_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<string name="msg_file_not_found">لم يتم العثور على الملف</string>
<string name="msg_remark_is_duplicate">الملاحظات موجودة بالفعل</string>
<string name="toast_action_not_allowed">الإجراء غير مسموح به</string>
<string name="server_obfs_password">كلمة مرور Obfs</string>

<!-- PerAppProxyActivity -->
<string name="msg_dialog_progress">تحميل</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<string name="msg_file_not_found">فایل پیدا نشد</string>
<string name="msg_remark_is_duplicate">اظهارات قبلاً وجود دارد</string>
<string name="toast_action_not_allowed">اقدام مجاز نیست</string>
<string name="server_obfs_password">رمز عبور Obfs</string>


<!-- PerAppProxyActivity -->
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<string name="msg_file_not_found">File tidak ditemukan</string>
<string name="msg_remark_is_duplicate">Keterangan sudah ada</string>
<string name="toast_action_not_allowed">Tindakan tidak diizinkan</string>
<string name="server_obfs_password">Kata sandi obfs</string>

<!-- PerAppProxyActivity -->
<string name="msg_dialog_progress">Memuat</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<string name="msg_file_not_found">ファイルが見つかりません</string>
<string name="msg_remark_is_duplicate">コメントはすでに存在します</string>
<string name="toast_action_not_allowed">許可されていないアクション</string>
<string name="server_obfs_password">Obfsパスワード</string>

<!-- PerAppProxyActivity -->
<string name="msg_dialog_progress">読み込み中</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-jw/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<string name="msg_file_not_found">File ora ditemokake</string>
<string name="msg_remark_is_duplicate">Deskripsi wis ana</string>
<string name="toast_action_not_allowed">Tindakan ora diidini</string>
<string name="server_obfs_password">Obfs sandi</string>

<!-- PerAppProxyActivity -->
<string name="msg_dialog_progress">Loading</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<string name="msg_file_not_found">Файл не найден</string>
<string name="msg_remark_is_duplicate">Замечания уже есть</string>
<string name="toast_action_not_allowed">Действие не разрешено</string>
<string name="server_obfs_password">пароль obfs</string>

<!-- PerAppProxyActivity -->
<string name="msg_dialog_progress">Загрузка</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-su/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<string name="msg_file_not_found">File henteu kapendak</string>
<string name="msg_remark_is_duplicate">Inpormasi parantos aya</string>
<string name="toast_action_not_allowed">Aksi teu diwenangkeun</string>
<string name="server_obfs_password">sandi Obfs</string>

<!-- PerAppProxyActivity -->
<string name="msg_dialog_progress">ngamuat</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-vi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<string name="msg_file_not_found">Không tìm thấy tập tin</string>
<string name="msg_remark_is_duplicate">Nhận xét đã tồn tại</string>
<string name="toast_action_not_allowed">Hành động không được phép</string>
<string name="server_obfs_password">Mật khẩu Obfs</string>

<!-- PerAppProxyActivity -->
<string name="msg_dialog_progress">Đang tải</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<string name="msg_file_not_found">文件未找到</string>
<string name="msg_remark_is_duplicate">备注已经存在</string>
<string name="toast_action_not_allowed">不允许的操作</string>
<string name="server_obfs_password">Obfs 密码</string>

<!-- PerAppProxyActivity -->
<string name="msg_dialog_progress">加载中</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<string name="msg_file_not_found">文件未找到</string>
<string name="msg_remark_is_duplicate">備註已經存在</string>
<string name="toast_action_not_allowed">不允許執行的操作</string>
<string name="server_obfs_password">OBFS密碼</string>

<!-- PerAppProxyActivity -->
<string name="msg_dialog_progress">載入中</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<string name="msg_file_not_found">File not found</string>
<string name="msg_remark_is_duplicate">The remarks already exists</string>
<string name="toast_action_not_allowed">Action not allowed</string>
<string name="server_obfs_password">Obfs password</string>

<!-- PerAppProxyActivity -->
<string name="msg_dialog_progress">Loading</string>
Expand Down

0 comments on commit fd63c83

Please sign in to comment.