fix(share): импорт полей ядра и пейсинг обфускации в ссылке

Импорт забирает dns, dnss, mcap, listen из ссылок CLI/установщика. Ссылка несёт timing владельца вместе с обфускацией.
This commit is contained in:
samosvalishe committed 2026-09-19 23:54:48 +03:00
1 parent 0f75931ca6
commit 0d88536933
4 files changed
+33 -1

No files matched your search

@@ -15,6 +15,7 @@ data class FreeturnLink(
val mode: String = "", val mode: String = "",
val obfProfile: String = "", val obfProfile: String = "",
val obfKey: String = "", val obfKey: String = "",
val obfTimingMs: Int = 0,
val n: Int = 0, val n: Int = 0,
val streamsPerCred: Int = 0, val streamsPerCred: Int = 0,
val clientId: String = "", val clientId: String = "",
@@ -39,6 +40,7 @@ data class FreeturnLink(
if (obfProfile.isNotEmpty() && obfProfile != "none") { if (obfProfile.isNotEmpty() && obfProfile != "none") {
sb.field("obf", jsonString(obfProfile)) sb.field("obf", jsonString(obfProfile))
sb.field("key", jsonString(obfKey)) sb.field("key", jsonString(obfKey))
if (obfTimingMs != 0) sb.field("timing", obfTimingMs.toString())
} }
if (n != 0) sb.field("n", n.toString()) if (n != 0) sb.field("n", n.toString())
if (streamsPerCred != 0) sb.field("spc", streamsPerCred.toString()) if (streamsPerCred != 0) sb.field("spc", streamsPerCred.toString())
@@ -82,6 +84,7 @@ data class FreeturnLink(
mode = o.optString("mode"), mode = o.optString("mode"),
obfProfile = o.optString("obf"), obfProfile = o.optString("obf"),
obfKey = o.optString("key"), obfKey = o.optString("key"),
obfTimingMs = o.optInt("timing", 0),
n = o.optInt("n", 0), n = o.optInt("n", 0),
streamsPerCred = o.optInt("spc", 0), streamsPerCred = o.optInt("spc", 0),
clientId = o.optString("cid"), clientId = o.optString("cid"),
@@ -32,6 +32,7 @@ object ShareLinkBuilder {
kcp = server.opts.kcp.takeIf { tcpMode && it != KcpProfile.DEFAULT }, kcp = server.opts.kcp.takeIf { tcpMode && it != KcpProfile.DEFAULT },
obfProfile = if (ObfProfile.isValidKey(obfKey)) obfProfile else "", obfProfile = if (ObfProfile.isValidKey(obfKey)) obfProfile else "",
obfKey = if (ObfProfile.isValidKey(obfKey)) obfKey else "", obfKey = if (ObfProfile.isValidKey(obfKey)) obfKey else "",
obfTimingMs = server.opts.obfTimingMs,
n = server.client.threads, n = server.client.threads,
streamsPerCred = server.client.streamsPerCred, streamsPerCred = server.client.streamsPerCred,
clientId = clientId.trim(), clientId = clientId.trim(),
@@ -4,7 +4,10 @@ import android.content.Context
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.freeturn.app.data.AppPreferences import com.freeturn.app.data.AppPreferences
import com.freeturn.app.data.DnsList
import com.freeturn.app.data.config.ClientConfig import com.freeturn.app.data.config.ClientConfig
import com.freeturn.app.data.config.DnsMode
import com.freeturn.app.data.config.HostPort
import com.freeturn.app.data.config.KcpProfile import com.freeturn.app.data.config.KcpProfile
import com.freeturn.app.data.config.ObfProfile import com.freeturn.app.data.config.ObfProfile
import com.freeturn.app.data.config.ProxyMode import com.freeturn.app.data.config.ProxyMode
@@ -138,11 +141,16 @@ class ImportViewModel(
tunnelTransport = if (wgConf.isNotEmpty()) TunnelTransport.WIREGUARD tunnelTransport = if (wgConf.isNotEmpty()) TunnelTransport.WIREGUARD
else TunnelTransport.NONE, else TunnelTransport.NONE,
wireGuardConfig = wgConf, wireGuardConfig = wgConf,
clientId = link.clientId.trim() clientId = link.clientId.trim(),
dnsMode = link.dnsMode.takeIf { it in DnsMode.VALUES } ?: DnsMode.AUTO,
customDns = DnsList.normalize(link.dnsServers),
manualCaptcha = link.manualCaptcha,
localPort = link.listen.takeIf(HostPort::isValid) ?: ClientConfig.DEFAULT_LOCAL_PORT
), ),
opts = ServerOpts( opts = ServerOpts(
obfProfile = link.obfProfile.ifBlank { ObfProfile.NONE }, obfProfile = link.obfProfile.ifBlank { ObfProfile.NONE },
obfKey = link.obfKey, obfKey = link.obfKey,
obfTimingMs = link.obfTimingMs.coerceIn(0, ObfProfile.TIMING_MAX),
proxyMode = if (link.mode == ProxyMode.TCP) ProxyMode.TCP else ProxyMode.UDP, proxyMode = if (link.mode == ProxyMode.TCP) ProxyMode.TCP else ProxyMode.UDP,
kcp = link.kcp ?: KcpProfile.DEFAULT kcp = link.kcp ?: KcpProfile.DEFAULT
) )
@@ -63,6 +63,7 @@ class FreeturnLinkTest {
kcp = KcpProfile.MOBILE, kcp = KcpProfile.MOBILE,
obfProfile = "rtpopus", obfProfile = "rtpopus",
obfKey = "00".repeat(32), obfKey = "00".repeat(32),
obfTimingMs = 20,
n = 10, n = 10,
streamsPerCred = 6, streamsPerCred = 6,
clientId = "cid-1", clientId = "cid-1",
@@ -77,6 +78,25 @@ class FreeturnLinkTest {
assertEquals(original, FreeturnLink.parse(original.encode()).getOrThrow()) assertEquals(original, FreeturnLink.parse(original.encode()).getOrThrow())
} }
@Test
fun `timing and vk follow go field order`() {
val goldenJson = """{"v":1,"provider":"vk","peer":"1.2.3.4:56000","obf":"rtpopus",""" +
""""key":"${"00".repeat(32)}","timing":20,"name":"Papa","vk":"https://vk.ru/call/join/x"}"""
val golden = "freeturn://" + Base64.getUrlEncoder().withoutPadding()
.encodeToString(goldenJson.toByteArray(Charsets.UTF_8))
val link = FreeturnLink(
provider = "vk",
peer = "1.2.3.4:56000",
obfProfile = "rtpopus",
obfKey = "00".repeat(32),
obfTimingMs = 20,
name = "Papa",
vkLink = "https://vk.ru/call/join/x"
)
assertEquals(golden, link.encode())
}
@Test @Test
fun `obf none is omitted entirely`() { fun `obf none is omitted entirely`() {
val link = FreeturnLink(provider = "vk", peer = "1.2.3.4:56000", obfProfile = "none", obfKey = "ff".repeat(32)) val link = FreeturnLink(provider = "vk", peer = "1.2.3.4:56000", obfProfile = "none", obfKey = "ff".repeat(32))