From 1663c7d819c069ff21a61f90c83f73401fd25e37 Mon Sep 17 00:00:00 2001
From: 2dust <31833384+2dust@users.noreply.github.com>
Date: Sat, 24 Oct 2020 12:13:38 +0800
Subject: [PATCH] add trojan sni
---
.../v2rayN/Forms/AddServer6Form.Designer.cs | 16 ++
v2rayN/v2rayN/Forms/AddServer6Form.cs | 4 +
v2rayN/v2rayN/Forms/AddServer6Form.resx | 171 ++++++++++++------
.../v2rayN/Forms/AddServer6Form.zh-Hans.resx | 3 +
v2rayN/v2rayN/Handler/ConfigHandler.cs | 7 +-
v2rayN/v2rayN/Handler/V2rayConfigHandler.cs | 7 +-
v2rayN/v2rayN/Properties/AssemblyInfo.cs | 2 +-
7 files changed, 146 insertions(+), 64 deletions(-)
diff --git a/v2rayN/v2rayN/Forms/AddServer6Form.Designer.cs b/v2rayN/v2rayN/Forms/AddServer6Form.Designer.cs
index eba21fc8..f14d46e4 100644
--- a/v2rayN/v2rayN/Forms/AddServer6Form.Designer.cs
+++ b/v2rayN/v2rayN/Forms/AddServer6Form.Designer.cs
@@ -31,6 +31,8 @@
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AddServer6Form));
this.btnClose = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
+ this.label4 = new System.Windows.Forms.Label();
+ this.txtRequestHost = new System.Windows.Forms.TextBox();
this.label13 = new System.Windows.Forms.Label();
this.txtRemarks = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
@@ -58,6 +60,8 @@
// groupBox1
//
resources.ApplyResources(this.groupBox1, "groupBox1");
+ this.groupBox1.Controls.Add(this.label4);
+ this.groupBox1.Controls.Add(this.txtRequestHost);
this.groupBox1.Controls.Add(this.label13);
this.groupBox1.Controls.Add(this.txtRemarks);
this.groupBox1.Controls.Add(this.label6);
@@ -70,6 +74,16 @@
this.groupBox1.Name = "groupBox1";
this.groupBox1.TabStop = false;
//
+ // label4
+ //
+ resources.ApplyResources(this.label4, "label4");
+ this.label4.Name = "label4";
+ //
+ // txtRequestHost
+ //
+ resources.ApplyResources(this.txtRequestHost, "txtRequestHost");
+ this.txtRequestHost.Name = "txtRequestHost";
+ //
// label13
//
resources.ApplyResources(this.label13, "label13");
@@ -169,5 +183,7 @@
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Label label13;
+ private System.Windows.Forms.Label label4;
+ private System.Windows.Forms.TextBox txtRequestHost;
}
}
\ No newline at end of file
diff --git a/v2rayN/v2rayN/Forms/AddServer6Form.cs b/v2rayN/v2rayN/Forms/AddServer6Form.cs
index 37e3f565..6911714f 100644
--- a/v2rayN/v2rayN/Forms/AddServer6Form.cs
+++ b/v2rayN/v2rayN/Forms/AddServer6Form.cs
@@ -35,6 +35,7 @@ namespace v2rayN.Forms
txtAddress.Text = vmessItem.address;
txtPort.Text = vmessItem.port.ToString();
txtId.Text = vmessItem.id;
+ txtRequestHost.Text = vmessItem.requestHost;
txtRemarks.Text = vmessItem.remarks;
}
@@ -47,6 +48,7 @@ namespace v2rayN.Forms
txtAddress.Text = "";
txtPort.Text = "";
txtId.Text = "";
+ txtRequestHost.Text = "";
txtRemarks.Text = "";
}
@@ -55,6 +57,7 @@ namespace v2rayN.Forms
string address = txtAddress.Text;
string port = txtPort.Text;
string id = txtId.Text;
+ string requestHost = txtRequestHost.Text;
string remarks = txtRemarks.Text;
if (Utils.IsNullOrEmpty(address))
@@ -76,6 +79,7 @@ namespace v2rayN.Forms
vmessItem.address = address;
vmessItem.port = Utils.ToInt(port);
vmessItem.id = id;
+ vmessItem.requestHost = requestHost.Replace(" ", "");
vmessItem.remarks = remarks;
if (ConfigHandler.AddTrojanServer(ref config, vmessItem, EditIndex) == 0)
diff --git a/v2rayN/v2rayN/Forms/AddServer6Form.resx b/v2rayN/v2rayN/Forms/AddServer6Form.resx
index e3935dc5..6d3c8975 100644
--- a/v2rayN/v2rayN/Forms/AddServer6Form.resx
+++ b/v2rayN/v2rayN/Forms/AddServer6Form.resx
@@ -134,20 +134,17 @@
Bottom
+
+ NoControl
+
txtPort
True
-
- groupBox1
-
-
- 4
-
-
- System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ Alias (remarks)
System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
@@ -171,26 +168,32 @@
label1
+
+ 359, 21
+
System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
groupBox1
+
+ System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
panel2
12, 155
-
- True
+
+ Fill
53, 12
-
- Fill
+
+ 127, 123
194, 21
@@ -201,6 +204,9 @@
6, 12
+
+ 396, 17
+
True
@@ -229,35 +235,44 @@
12, 93
- 8
+ 10
Server
+
+ 3
+
System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
0
-
- 2
+
+ txtRequestHost
+
+
+ System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
547, 60
-
- 89, 12
+
+ System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ groupBox1
- 278, 21
+ 359, 21
+
+
+ Edit or add a [Trojan] server
359, 21
-
- label6
-
System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
@@ -279,29 +294,35 @@
71, 12
-
- 75, 23
+
+ 24
-
- panel1
+
+ label4
txtId
-
- 12, 62
+
+ 303, 17
-
- 1
+
+ $this
+
+
+ 75, 23
btnClose
-
- System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ Host(SNI)
-
- &OK
+
+ label6
+
+
+ 5
System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
@@ -312,14 +333,14 @@
75, 23
-
- System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 1
txtAddress
-
- 547, 10
+
+ groupBox1
Top
@@ -328,7 +349,7 @@
0, 10
- 2
+ 4
System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
@@ -357,8 +378,11 @@
groupBox1
-
- True
+
+ System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ 23
127, 59
@@ -366,23 +390,26 @@
System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
- Alias (remarks)
+
+ True
-
- 5
+
+ True
-
+
+ 89, 12
+
+
groupBox1
-
- 303, 17
+
+ 0
-
- $this
+
+ 547, 10
- 6
+ 8
&Cancel
@@ -390,8 +417,11 @@
12, 31
-
- Edit or add a [Trojan] server
+
+ &OK
+
+
+ System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
0
@@ -405,21 +435,33 @@
337, 158
-
- groupBox1
+
+ True
+
+
+ 12, 62
127, 91
+
+ 12, 126
+
- 5
+ 7
$this
+
+ 59, 12
+
1
+
+ groupBox1
+
0, 0
@@ -430,7 +472,7 @@
label13
- 3
+ 5
95, 12
@@ -439,7 +481,7 @@
label2
- 0
+ 2
panel2
@@ -451,7 +493,7 @@
22
- 7
+ 9
547, 291
@@ -462,11 +504,14 @@
v2rayN.Forms.BaseServerForm, v2rayN, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+
+ groupBox1
+
$this
-
- 396, 17
+
+ 6
System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
@@ -477,9 +522,15 @@
panel2
+
+ panel1
+
System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 2
+
True
diff --git a/v2rayN/v2rayN/Forms/AddServer6Form.zh-Hans.resx b/v2rayN/v2rayN/Forms/AddServer6Form.zh-Hans.resx
index d7642edd..375c223d 100644
--- a/v2rayN/v2rayN/Forms/AddServer6Form.zh-Hans.resx
+++ b/v2rayN/v2rayN/Forms/AddServer6Form.zh-Hans.resx
@@ -123,6 +123,9 @@
服务器
+
+ 域名(SNI)
+
*手填,方便识别管理
diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs
index 59c0dcd7..37a9878e 100644
--- a/v2rayN/v2rayN/Handler/ConfigHandler.cs
+++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs
@@ -430,11 +430,16 @@ namespace v2rayN.Handler
{
remark = "#" + WebUtility.UrlEncode(vmessItem.remarks);
}
+ string query = string.Empty;
+ if (!Utils.IsNullOrEmpty(vmessItem.requestHost))
+ {
+ query = string.Format("?sni={0}", vmessItem.requestHost);
+ }
url = string.Format("{0}@{1}:{2}",
vmessItem.id,
vmessItem.address,
vmessItem.port);
- url = string.Format("{0}{1}{2}", Global.trojanProtocol, url, remark);
+ url = string.Format("{0}{1}{2}{3}", Global.trojanProtocol, url, query, remark);
}
else
{
diff --git a/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs b/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs
index 9ca18e61..a79ae73e 100644
--- a/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs
+++ b/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs
@@ -561,7 +561,7 @@ namespace v2rayN.Handler
};
if (!string.IsNullOrWhiteSpace(host))
{
- tlsSettings.serverName = host;
+ tlsSettings.serverName = Utils.String2List(host)[0];
}
streamSettings.tlsSettings = tlsSettings;
}
@@ -577,7 +577,7 @@ namespace v2rayN.Handler
};
if (!string.IsNullOrWhiteSpace(host))
{
- xtlsSettings.serverName = host;
+ xtlsSettings.serverName = Utils.String2List(host)[0];
}
streamSettings.xtlsSettings = xtlsSettings;
}
@@ -1441,6 +1441,9 @@ namespace v2rayN.Handler
vmessItem.port = uri.Port;
vmessItem.id = uri.UserInfo;
+ var qurery = HttpUtility.ParseQueryString(uri.Query);
+ vmessItem.requestHost = qurery["sni"] ?? "";
+
var remarks = uri.Fragment.Replace("#", "");
if (Utils.IsNullOrEmpty(remarks))
{
diff --git a/v2rayN/v2rayN/Properties/AssemblyInfo.cs b/v2rayN/v2rayN/Properties/AssemblyInfo.cs
index fa240436..8979aba5 100644
--- a/v2rayN/v2rayN/Properties/AssemblyInfo.cs
+++ b/v2rayN/v2rayN/Properties/AssemblyInfo.cs
@@ -32,4 +32,4 @@ using System.Runtime.InteropServices;
// 方法是按如下所示使用“*”:
//[assembly: AssemblyVersion("1.0.*")]
//[assembly: AssemblyVersion("1.0.0")]
-[assembly: AssemblyFileVersion("3.26")]
+[assembly: AssemblyFileVersion("3.27")]