From 93bcdc830b1f260858ec05f589fafefa99b648cf Mon Sep 17 00:00:00 2001 From: arm64v8a <48624112+arm64v8a@users.noreply.github.com> Date: Tue, 4 Apr 2023 14:28:53 +0900 Subject: [PATCH] update --- .../java/io/nekohasekai/sagernet/Constants.kt | 2 + .../nekohasekai/sagernet/fmt/ConfigBuilder.kt | 39 +++++++++--- .../fmt/shadowsocks/ShadowsocksFmt.kt | 6 +- .../sagernet/fmt/v2ray/V2RayFmt.kt | 2 +- .../profile/StandardV2RaySettingsActivity.kt | 3 + .../java/moe/matsuri/nb4a/SingBoxOptions.java | 61 +++++++++++++++++-- .../moe/matsuri/nb4a/SingBoxOptionsUtil.kt | 4 ++ .../java/moe/matsuri/nb4a/utils/SendLog.kt | 2 +- app/src/main/res/values-zh-rCN/strings.xml | 3 +- app/src/main/res/values/strings.xml | 3 +- .../res/xml/standard_v2ray_preferences.xml | 5 ++ libcore/go.mod | 2 - libcore/go.sum | 17 ------ libcore/nb4a.go | 58 ------------------ 14 files changed, 111 insertions(+), 96 deletions(-) diff --git a/app/src/main/java/io/nekohasekai/sagernet/Constants.kt b/app/src/main/java/io/nekohasekai/sagernet/Constants.kt index 23db317..cf7117e 100644 --- a/app/src/main/java/io/nekohasekai/sagernet/Constants.kt +++ b/app/src/main/java/io/nekohasekai/sagernet/Constants.kt @@ -94,6 +94,7 @@ object Key { const val SERVER_CONFIG = "serverConfig" const val SERVER_SECURITY_CATEGORY = "serverSecurityCategory" + const val SERVER_TLS_MODIFY_CATEGORY = "serverTlsModifyCategory" const val SERVER_WS_CATEGORY = "serverWsCategory" const val SERVER_SS_CATEGORY = "serverSsCategory" const val SERVER_HEADERS = "serverHeaders" @@ -180,6 +181,7 @@ object Action { const val SERVICE = "io.nekohasekai.sagernet.SERVICE" const val CLOSE = "io.nekohasekai.sagernet.CLOSE" const val RELOAD = "io.nekohasekai.sagernet.RELOAD" + // const val SWITCH_WAKE_LOCK = "io.nekohasekai.sagernet.SWITCH_WAKELOCK" const val RESET_UPSTREAM_CONNECTIONS = "moe.nb4a.RESET_UPSTREAM_CONNECTIONS" } diff --git a/app/src/main/java/io/nekohasekai/sagernet/fmt/ConfigBuilder.kt b/app/src/main/java/io/nekohasekai/sagernet/fmt/ConfigBuilder.kt index ac2e705..ece2d99 100644 --- a/app/src/main/java/io/nekohasekai/sagernet/fmt/ConfigBuilder.kt +++ b/app/src/main/java/io/nekohasekai/sagernet/fmt/ConfigBuilder.kt @@ -98,7 +98,7 @@ fun buildConfig( val trafficMap = HashMap>() val tagMap = HashMap() - val globalOutbounds = ArrayList() + val globalOutbounds = HashMap() val selectorNames = ArrayList() val group = SagerDatabase.groupDao.getById(proxy.groupId) var optionsToMerge = "" @@ -336,6 +336,13 @@ fun buildConfig( bypassDNSBeans += proxyEntity.requireBean() } + if (needGlobal) { + globalOutbounds[proxyEntity.id]?.let { + if (index == 0) chainTagOut = it // single, duplicate chain + return@forEachIndexed + } + } + // last profile set as "proxy" if (chainId == 0L && index == 0) { tagOut = TAG_PROXY @@ -346,6 +353,11 @@ fun buildConfig( tagOut = selectorName(bean.displayName()) } + // now tagOut is determined + if (needGlobal) { + globalOutbounds[proxyEntity.id] = tagOut + } + // chain rules if (index > 0) { // chain route/proxy rules @@ -362,13 +374,6 @@ fun buildConfig( chainTagOut = tagOut } - if (needGlobal) { - if (globalOutbounds.contains(proxyEntity.id)) { - return@forEachIndexed - } - globalOutbounds.add(proxyEntity.id) - } - // Chain outbound if (proxyEntity.needExternal()) { val localPort = mkPort() @@ -706,18 +711,32 @@ fun buildConfig( if (enableDnsRouting) { val dnsRuleObj = mutableListOf() if (uidListDNSRemote.isNotEmpty()) { + if (useFakeDns) dnsRuleObj.add( + DNSRule_DefaultOptions().apply { + user_id = uidListDNSRemote.toHashSet().toList() + server = "dns-fake" + inbound = listOf("tun-in") + } + ) dnsRuleObj.add( DNSRule_DefaultOptions().apply { user_id = uidListDNSRemote.toHashSet().toList() - server = if (useFakeDns) "dns-fake" else "dns-remote" + server = "dns-remote" } ) } if (domainListDNSRemote.isNotEmpty()) { + if (useFakeDns) dnsRuleObj.add( + DNSRule_DefaultOptions().apply { + makeSingBoxRule(domainListDNSRemote.toHashSet().toList()) + server = "dns-fake" + inbound = listOf("tun-in") + } + ) dnsRuleObj.add( DNSRule_DefaultOptions().apply { makeSingBoxRule(domainListDNSRemote.toHashSet().toList()) - server = if (useFakeDns) "dns-fake" else "dns-remote" + server = "dns-remote" } ) } diff --git a/app/src/main/java/io/nekohasekai/sagernet/fmt/shadowsocks/ShadowsocksFmt.kt b/app/src/main/java/io/nekohasekai/sagernet/fmt/shadowsocks/ShadowsocksFmt.kt index aeecc30..9b0c616 100644 --- a/app/src/main/java/io/nekohasekai/sagernet/fmt/shadowsocks/ShadowsocksFmt.kt +++ b/app/src/main/java/io/nekohasekai/sagernet/fmt/shadowsocks/ShadowsocksFmt.kt @@ -114,7 +114,11 @@ fun buildSingBoxOutboundShadowsocksBean(bean: ShadowsocksBean): SingBoxOptions.O server_port = bean.serverPort password = bean.password method = bean.method - udp_over_tcp = bean.sUoT + if (bean.sUoT) { + udp_over_tcp = SingBoxOptions.UDPOverTCPOptions().apply { + enabled = true + } + } if (bean.plugin.isNotBlank()) { plugin = bean.plugin.substringBefore(";") plugin_opts = bean.plugin.substringAfter(";") diff --git a/app/src/main/java/io/nekohasekai/sagernet/fmt/v2ray/V2RayFmt.kt b/app/src/main/java/io/nekohasekai/sagernet/fmt/v2ray/V2RayFmt.kt index dd17ab6..ba68f6a 100644 --- a/app/src/main/java/io/nekohasekai/sagernet/fmt/v2ray/V2RayFmt.kt +++ b/app/src/main/java/io/nekohasekai/sagernet/fmt/v2ray/V2RayFmt.kt @@ -563,7 +563,7 @@ fun buildSingBoxOutboundTLS(bean: StandardV2RayBean): OutboundTLSOptions? { fingerprint = bean.utlsFingerprint } } - if (bean.realityPubKey.isNotBlank() && bean.realityShortId.isNotBlank()) { + if (bean.realityPubKey.isNotBlank()) { reality = OutboundRealityOptions().apply { enabled = true public_key = bean.realityPubKey diff --git a/app/src/main/java/io/nekohasekai/sagernet/ui/profile/StandardV2RaySettingsActivity.kt b/app/src/main/java/io/nekohasekai/sagernet/ui/profile/StandardV2RaySettingsActivity.kt index 9b9cdbf..1d072f2 100644 --- a/app/src/main/java/io/nekohasekai/sagernet/ui/profile/StandardV2RaySettingsActivity.kt +++ b/app/src/main/java/io/nekohasekai/sagernet/ui/profile/StandardV2RaySettingsActivity.kt @@ -63,6 +63,7 @@ abstract class StandardV2RaySettingsActivity : ProfileSettingsActivity headers; + public Long idle_timeout; + + public Long ping_timeout; + } public static class V2RayWebsocketOptions extends SingBoxOption { @@ -2020,6 +2057,12 @@ public class SingBoxOptions { public String service_name; + public Long idle_timeout; + + public Long ping_timeout; + + public Boolean permit_without_stream; + // Generate note: option type: public Boolean ForceLite; } @@ -3091,7 +3134,7 @@ public class SingBoxOptions { public String network; - public Boolean udp_over_tcp; + public UDPOverTCPOptions udp_over_tcp; } @@ -3187,7 +3230,7 @@ public class SingBoxOptions { public String network; - public Boolean udp_over_tcp; + public UDPOverTCPOptions udp_over_tcp; public MultiplexOptions multiplex; @@ -3793,6 +3836,10 @@ public class SingBoxOptions { public Map headers; + public Long idle_timeout; + + public Long ping_timeout; + } public static class V2RayTransportOptions_WebsocketOptions extends V2RayTransportOptions { @@ -3812,6 +3859,12 @@ public class SingBoxOptions { public String service_name; + public Long idle_timeout; + + public Long ping_timeout; + + public Boolean permit_without_stream; + } diff --git a/app/src/main/java/moe/matsuri/nb4a/SingBoxOptionsUtil.kt b/app/src/main/java/moe/matsuri/nb4a/SingBoxOptionsUtil.kt index e1845d7..1be2a4b 100644 --- a/app/src/main/java/moe/matsuri/nb4a/SingBoxOptionsUtil.kt +++ b/app/src/main/java/moe/matsuri/nb4a/SingBoxOptionsUtil.kt @@ -104,5 +104,9 @@ fun SingBoxOptions.Rule_DefaultOptions.checkEmpty(): Boolean { if (domain_regex?.isNotEmpty() == true) return false if (domain_keyword?.isNotEmpty() == true) return false if (user_id?.isNotEmpty() == true) return false + // + if (port?.isNotEmpty() == true) return false + if (port_range?.isNotEmpty() == true) return false + if (source_ip_cidr?.isNotEmpty() == true) return false return true } diff --git a/app/src/main/java/moe/matsuri/nb4a/utils/SendLog.kt b/app/src/main/java/moe/matsuri/nb4a/utils/SendLog.kt index b37384e..e12fccf 100644 --- a/app/src/main/java/moe/matsuri/nb4a/utils/SendLog.kt +++ b/app/src/main/java/moe/matsuri/nb4a/utils/SendLog.kt @@ -68,6 +68,6 @@ object SendLog { if (max in 1 until len) { stream.skip(len - max) // TODO string? } - return stream.readBytes() + return stream.use { it.readBytes() } } } diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 827e1c6..2dbf5fa 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -246,7 +246,7 @@ 启用 自动 跟随系统 - 安全设置 + TLS 安全设置 允许不安全的连接 禁用证书检查. 启用后该配置安全性相当于明文 配置类型 @@ -470,4 +470,5 @@ 在通知中显示组名 重置连接 删除重复的服务器 + TLS 伪装设置 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ec87a22..5f72a12 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -69,7 +69,7 @@ If you don’t want to use Quick Tile as the switch Show Direct Speed Show the traffic speed without proxy in the notification as well - Security Settings + TLS Security Settings Allow Insecure Disable certificate checking. When enabled, this configuration is as secure as plaintext %1$s↑ %2$s↓ @@ -513,5 +513,6 @@ Anyone can write advanced plugins, which can control NekoBox. please download an Remove duplicate servers Long press the preference to set custom MTU. Long press the preference to set the buffer size. + TLS Modify Settings \ No newline at end of file diff --git a/app/src/main/res/xml/standard_v2ray_preferences.xml b/app/src/main/res/xml/standard_v2ray_preferences.xml index 48919e4..2f0824a 100644 --- a/app/src/main/res/xml/standard_v2ray_preferences.xml +++ b/app/src/main/res/xml/standard_v2ray_preferences.xml @@ -118,6 +118,11 @@ app:key="allowInsecure" app:summary="@string/allow_insecure_sum" app:title="@string/allow_insecure" /> + + +