aboutsummaryrefslogtreecommitdiff
path: root/net/v2raya/patches/014-fix-seed-cannot-be-read-from-vless-sharing-link-and-add-m.patch
blob: ba5030624455ca22538009c45681b7547fd37215 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
From 5db722b22b39642280572a62b149d4e1efa21ce3 Mon Sep 17 00:00:00 2001
From: mzz2017 <mzz@tuta.io>
Date: Mon, 8 Aug 2022 22:30:36 +0800
Subject: [PATCH] fix: seed cannot be read from vless sharing-link and add
 missing sni field. #616

---
 service/core/serverObj/v2ray.go | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

--- a/core/serverObj/v2ray.go
+++ b/core/serverObj/v2ray.go
@@ -12,7 +12,6 @@ import (
 	"time"
 
 	jsoniter "github.com/json-iterator/go"
-	"github.com/tidwall/gjson"
 	"github.com/v2rayA/v2rayA/common"
 	"github.com/v2rayA/v2rayA/core/coreObj"
 	"github.com/v2rayA/v2rayA/core/v2ray/service"
@@ -39,6 +38,7 @@ type V2Ray struct {
 	Net           string `json:"net"`
 	Type          string `json:"type"`
 	Host          string `json:"host"`
+	SNI           string `json:"sni"`
 	Path          string `json:"path"`
 	TLS           string `json:"tls"`
 	Flow          string `json:"flow,omitempty"`
@@ -69,7 +69,8 @@ func ParseVlessURL(vless string) (data *
 		ID:            u.User.String(),
 		Net:           u.Query().Get("type"),
 		Type:          u.Query().Get("headerType"),
-		Host:          u.Query().Get("sni"),
+		Host:          u.Query().Get("host"),
+		SNI:           u.Query().Get("sni"),
 		Path:          u.Query().Get("path"),
 		TLS:           u.Query().Get("security"),
 		Flow:          u.Query().Get("flow"),
@@ -86,16 +87,13 @@ func ParseVlessURL(vless string) (data *
 	if data.Type == "" {
 		data.Type = "none"
 	}
-	if data.Host == "" {
-		data.Host = u.Query().Get("host")
-	}
 	if data.TLS == "" {
 		data.TLS = "none"
 	}
 	if data.Flow == "" {
 		data.Flow = "xtls-rprx-direct"
 	}
-	if data.Type == "mkcp" || data.Type == "kcp" {
+	if data.Net == "mkcp" || data.Net == "kcp" {
 		data.Path = u.Query().Get("seed")
 	}
 	return data, nil
@@ -145,6 +143,7 @@ func ParseVmessURL(vmess string) (data *
 		if aid == "" {
 			aid = q.Get("aid")
 		}
+		sni := q.Get("sni")
 		info = V2Ray{
 			ID:            subMatch[1],
 			Add:           subMatch[2],
@@ -152,6 +151,7 @@ func ParseVmessURL(vmess string) (data *
 			Ps:            ps,
 			Host:          obfsParam,
 			Path:          path,
+			SNI:           sni,
 			Net:           obfs,
 			Aid:           aid,
 			TLS:           map[string]string{"1": "tls"}[q.Get("tls")],
@@ -165,12 +165,6 @@ func ParseVmessURL(vmess string) (data *
 		if err != nil {
 			return
 		}
-		if info.Host == "" {
-			sni := gjson.Get(raw, "sni")
-			if sni.Exists() {
-				info.Host = sni.String()
-			}
-		}
 	}
 	// correct the wrong vmess as much as possible
 	if strings.HasPrefix(info.Host, "/") && info.Path == "" {
@@ -328,7 +322,9 @@ func (v *V2Ray) Configuration(info Prior
 				core.StreamSettings.TLSSettings.AllowInsecure = true
 			}
 			// SNI
-			if v.Host != "" {
+			if v.SNI != "" {
+				core.StreamSettings.TLSSettings.ServerName = v.SNI
+			} else if v.Host != "" {
 				core.StreamSettings.TLSSettings.ServerName = v.Host
 			}
 			// Alpn
@@ -345,6 +341,8 @@ func (v *V2Ray) Configuration(info Prior
 			// SNI
 			if v.Host != "" {
 				core.StreamSettings.XTLSSettings.ServerName = v.Host
+			} else if v.Host != "" {
+				core.StreamSettings.TLSSettings.ServerName = v.Host
 			}
 			if v.AllowInsecure {
 				core.StreamSettings.XTLSSettings.AllowInsecure = true