From c0141225d323b9ee17f71e3798a273bdb1e9f2e6 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sun, 9 Nov 2025 17:33:40 +0800 Subject: [PATCH] Add allowInsecure and insecure to the shared URI https://github.com/2dust/v2rayN/issues/8267 --- .../main/java/com/v2ray/ang/dto/VmessQRCode.kt | 3 ++- .../src/main/java/com/v2ray/ang/fmt/FmtBase.kt | 16 ++++++++++++---- .../main/java/com/v2ray/ang/fmt/Hysteria2Fmt.kt | 10 ++-------- .../src/main/java/com/v2ray/ang/fmt/VmessFmt.kt | 16 ++++++++++++---- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/dto/VmessQRCode.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/dto/VmessQRCode.kt index 779c7e3c..445dced6 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/dto/VmessQRCode.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/dto/VmessQRCode.kt @@ -15,5 +15,6 @@ data class VmessQRCode( var tls: String = "", var sni: String = "", var alpn: String = "", - var fp: String = "" + var fp: String = "", + var insecure: String = "" ) \ No newline at end of file diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/FmtBase.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/FmtBase.kt index 525e3da5..14c6fd6c 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/FmtBase.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/FmtBase.kt @@ -72,10 +72,12 @@ open class FmtBase { if (config.security != AppConfig.TLS && config.security != AppConfig.REALITY) { config.security = null } - config.insecure = if (queryParam["allowInsecure"].isNullOrEmpty()) { - allowInsecure - } else { - queryParam["allowInsecure"].orEmpty() == "1" + // Support multiple possible query keys for allowInsecure like the C# implementation + val allowInsecureKeys = arrayOf("insecure", "allowInsecure", "allow_insecure", "verify") + config.insecure = when { + allowInsecureKeys.any { queryParam[it] == "1" } -> true + allowInsecureKeys.any { queryParam[it] == "0" } -> false + else -> allowInsecure } config.sni = queryParam["sni"] config.fingerPrint = queryParam["fp"] @@ -104,6 +106,12 @@ open class FmtBase { config.spiderX.let { if (it.isNotNullEmpty()) dicQuery["spx"] = it.orEmpty() } config.mldsa65Verify.let { if (it.isNotNullEmpty()) dicQuery["pqv"] = it.orEmpty() } config.flow.let { if (it.isNotNullEmpty()) dicQuery["flow"] = it.orEmpty() } + // Add two keys for compatibility: "insecure" and "allowInsecure" + if (config.security == AppConfig.TLS) { + val insecureFlag = if (config.insecure == true) "1" else "0" + dicQuery["insecure"] = insecureFlag + dicQuery["allowInsecure"] = insecureFlag + } val networkType = NetworkType.fromString(config.network) dicQuery["type"] = networkType.type diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/Hysteria2Fmt.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/Hysteria2Fmt.kt index 3b3dc88c..7c0b530d 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/Hysteria2Fmt.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/Hysteria2Fmt.kt @@ -34,15 +34,9 @@ object Hysteria2Fmt : FmtBase() { if (!uri.rawQuery.isNullOrEmpty()) { val queryParam = getQueryParam(uri) + getItemFormQuery(config, queryParam, allowInsecure) + config.security = queryParam["security"] ?: AppConfig.TLS - config.insecure = if (queryParam["insecure"].isNullOrEmpty()) { - allowInsecure - } else { - queryParam["insecure"].orEmpty() == "1" - } - config.sni = queryParam["sni"] - config.alpn = queryParam["alpn"] - config.obfsPassword = queryParam["obfs-password"] config.portHopping = queryParam["mport"] config.pinSHA256 = queryParam["pinSHA256"] diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/VmessFmt.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/VmessFmt.kt index 4201f4dc..99db1e06 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/VmessFmt.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/VmessFmt.kt @@ -28,7 +28,7 @@ object VmessFmt : FmtBase() { return parseVmessStd(str) } - var allowInsecure = MmkvManager.decodeSettingsBool(AppConfig.PREF_ALLOW_INSECURE, false) + val allowInsecure = MmkvManager.decodeSettingsBool(AppConfig.PREF_ALLOW_INSECURE, false) val config = ProfileItem.create(EConfigType.VMESS) var result = str.replace(EConfigType.VMESS.protocolScheme, "") @@ -78,12 +78,15 @@ object VmessFmt : FmtBase() { else -> {} } - config.security = vmessQRCode.tls - config.insecure = allowInsecure + config.security = vmessQRCode.tls config.sni = vmessQRCode.sni config.fingerPrint = vmessQRCode.fp config.alpn = vmessQRCode.alpn - + config.insecure = when (vmessQRCode.insecure) { + "1" -> true + "0" -> false + else -> allowInsecure + } return config } @@ -132,6 +135,11 @@ object VmessFmt : FmtBase() { vmessQRCode.sni = config.sni.orEmpty() vmessQRCode.fp = config.fingerPrint.orEmpty() vmessQRCode.alpn = config.alpn.orEmpty() + vmessQRCode.insecure = when (config.insecure) { + true -> "1" + false -> "0" + else -> "" + } val json = JsonUtil.toJson(vmessQRCode) return Utils.encode(json)