From 3419dc88377f40871fa6b343eda8e98f34c62a81 Mon Sep 17 00:00:00 2001 From: iseki Date: Thu, 23 Jul 2020 00:51:08 +0800 Subject: [PATCH 1/3] add support to new version vmess link some information can be found at: https://github.com/v2ray/discussion/issues/720 --- .../com/v2ray/ang/util/AngConfigManager.kt | 66 +++++++++++++++++-- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt index 06d4f4383..73dde7c0d 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt @@ -2,7 +2,6 @@ package com.v2ray.ang.util import android.graphics.Bitmap import android.text.TextUtils -import android.util.Log import com.google.gson.Gson import com.v2ray.ang.AngApplication import com.v2ray.ang.AppConfig @@ -16,12 +15,9 @@ import com.v2ray.ang.AppConfig.VMESS_PROTOCOL import com.v2ray.ang.R import com.v2ray.ang.dto.AngConfig import com.v2ray.ang.dto.VmessQRCode -import com.v2ray.ang.extension.defaultDPreference -import org.jetbrains.anko.toast +import java.net.URI import java.net.URLDecoder import java.util.* -import java.net.* -import java.math.BigInteger object AngConfigManager { private lateinit var app: AngApplication @@ -256,7 +252,11 @@ object AngConfigManager { if (server.startsWith(VMESS_PROTOCOL)) { val indexSplit = server.indexOf("?") - if (indexSplit > 0) { + val newVmess = tryParseNewVmess(server) + if (newVmess != null) { + vmess = newVmess + vmess.subid = subid + } else if (indexSplit > 0) { vmess = ResolveVmess4Kitsunebi(server) } else { @@ -378,6 +378,60 @@ object AngConfigManager { return 0 } + fun tryParseNewVmess(uri: String): AngConfig.VmessBean? { + return runCatching { + val uri = URI(uri) + check(uri.scheme == "vmess") + val (_, protocol, tlsStr, uuid, alterId) = + Regex("(tcp|http|ws|kcp|quic)(\\+tls)?:([0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12})-([0-9]+)") + .matchEntire(uri.userInfo)?.groupValues + ?: error("parse user info fail.") + val tls = tlsStr.isNotBlank() + val queryParam = uri.rawQuery.split("&") + .map { it.split("=").let { (k, v) -> k to URLDecoder.decode(v, "utf-8")!! } } + .toMap() + val vmess = AngConfig.VmessBean() + vmess.address = uri.host + vmess.port = uri.port + vmess.guid = uuid + vmess.alterId = alterId.toInt() + vmess.streamSecurity = if (tls) "tls" else "" + vmess.remarks = uri.fragment + + // TODO: allowInsecure not supported + + when (protocol) { + "tcp" -> { + vmess.network = "tcp" + vmess.headerType = queryParam["type"] ?: "none" + vmess.requestHost = queryParam["host"] ?: "" + } + "http" -> { + vmess.network = "h2" + vmess.path = queryParam["path"]?.takeIf { it.trim() != "/" } ?: "" + vmess.requestHost = queryParam["host"]?.split("|")?.get(0) ?: "" + } + "ws" -> { + vmess.network = "ws" + vmess.path = queryParam["path"]?.takeIf { it.trim() != "/" } ?: "" + vmess.requestHost = queryParam["host"]?.split("|")?.get(0) ?: "" + } + "kcp" -> { + vmess.network = "kcp" + vmess.headerType = queryParam["type"] ?: "none" + vmess.path = queryParam["seed"] ?: "" + } + "quic" -> { + vmess.network = "quic" + vmess.security = queryParam["security"] ?: "none" + vmess.headerType = queryParam["type"] ?: "none" + vmess.path = queryParam["key"] ?: "" + } + } + vmess + }.getOrNull() + } + private fun ResolveVmess4Kitsunebi(server: String): AngConfig.VmessBean { val vmess = AngConfig.VmessBean() From c0ec0d9404519b1b1f2e8fa157282110cbcec088 Mon Sep 17 00:00:00 2001 From: iseki Date: Fri, 24 Jul 2020 11:21:20 +0800 Subject: [PATCH 2/3] Update AngConfigManager.kt --- .../src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt index 73dde7c0d..3cbc5aa8c 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt @@ -393,7 +393,7 @@ object AngConfigManager { val vmess = AngConfig.VmessBean() vmess.address = uri.host vmess.port = uri.port - vmess.guid = uuid + vmess.id = uuid vmess.alterId = alterId.toInt() vmess.streamSecurity = if (tls) "tls" else "" vmess.remarks = uri.fragment @@ -423,7 +423,7 @@ object AngConfigManager { } "quic" -> { vmess.network = "quic" - vmess.security = queryParam["security"] ?: "none" + vmess.requestHost = queryParam["security"] ?: "none" vmess.headerType = queryParam["type"] ?: "none" vmess.path = queryParam["key"] ?: "" } @@ -893,4 +893,4 @@ object AngConfigManager { return 0 } -} \ No newline at end of file +} From 617f28f3999bdd08a8ddc5b690a2c8d36be2cf67 Mon Sep 17 00:00:00 2001 From: iseki Date: Fri, 24 Jul 2020 11:23:46 +0800 Subject: [PATCH 3/3] Update AngConfigManager.kt --- .../app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt index 3cbc5aa8c..96fc52baf 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt @@ -397,6 +397,7 @@ object AngConfigManager { vmess.alterId = alterId.toInt() vmess.streamSecurity = if (tls) "tls" else "" vmess.remarks = uri.fragment + vmess.security = "auto" // TODO: allowInsecure not supported