From a03991ddb94afb9e50c0fc879b374ecfc2cea0a7 Mon Sep 17 00:00:00 2001
From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com>
Date: Wed, 14 Jul 2021 13:35:55 +0800
Subject: [PATCH] Update V2rayNSharing Util
---
Netch/Servers/V2ray/Models/V2rayNSharing.cs | 82 ++++++++++++---------
Netch/Servers/VMess/VMessUtil.cs | 39 +++++-----
2 files changed, 66 insertions(+), 55 deletions(-)
diff --git a/Netch/Servers/V2ray/Models/V2rayNSharing.cs b/Netch/Servers/V2ray/Models/V2rayNSharing.cs
index a5af695a..069c6d8d 100644
--- a/Netch/Servers/V2ray/Models/V2rayNSharing.cs
+++ b/Netch/Servers/V2ray/Models/V2rayNSharing.cs
@@ -6,39 +6,9 @@
public class V2rayNSharing
{
///
- /// 地址
+ /// 链接版本
///
- public string add { get; set; } = string.Empty;
-
- ///
- /// 额外 ID
- ///
- public int aid { get; set; }
-
- ///
- /// 伪装域名(HTTP,WS)
- ///
- public string? host { get; set; } = string.Empty;
-
- ///
- /// 用户 ID
- ///
- public string id { get; set; } = string.Empty;
-
- ///
- /// 传输协议
- ///
- public string net { get; set; } = string.Empty;
-
- ///
- /// 伪装路径/服务名称
- ///
- public string? path { get; set; } = string.Empty;
-
- ///
- /// 端口
- ///
- public ushort port { get; set; }
+ public int v { get; set; } = 2;
///
/// 备注
@@ -46,9 +16,34 @@
public string ps { get; set; } = string.Empty;
///
- /// 是否使用 TLS
+ /// 地址
///
- public string tls { get; set; } = string.Empty;
+ public string add { get; set; } = string.Empty;
+
+ ///
+ /// 端口
+ ///
+ public ushort port { get; set; }
+
+ ///
+ /// 用户 ID
+ ///
+ public string id { get; set; } = string.Empty;
+
+ ///
+ /// 额外 ID
+ ///
+ public int aid { get; set; }
+
+ ///
+ /// 加密方式 (security)
+ ///
+ public string scy { get; set; } = "auto";
+
+ ///
+ /// 传输协议
+ ///
+ public string net { get; set; } = string.Empty;
///
/// 伪装类型
@@ -56,8 +51,23 @@
public string type { get; set; } = string.Empty;
///
- /// 链接版本
+ /// 伪装域名(HTTP,WS)
///
- public int v { get; set; } = 2;
+ public string host { get; set; } = string.Empty;
+
+ ///
+ /// 伪装路径/服务名称
+ ///
+ public string path { get; set; } = string.Empty;
+
+ ///
+ /// 是否使用 TLS
+ ///
+ public string tls { get; set; } = string.Empty;
+
+ ///
+ /// serverName
+ ///
+ public string sni { get; set; } = string.Empty;
}
}
\ No newline at end of file
diff --git a/Netch/Servers/VMess/VMessUtil.cs b/Netch/Servers/VMess/VMessUtil.cs
index 4ddf0f2f..075426de 100644
--- a/Netch/Servers/VMess/VMessUtil.cs
+++ b/Netch/Servers/VMess/VMessUtil.cs
@@ -42,19 +42,21 @@ namespace Netch.Servers
var server = (VMess)s;
var vmessJson = JsonSerializer.Serialize(new V2rayNSharing
- {
- v = 2,
- ps = server.Remark,
- add = server.Hostname,
- port = server.Port,
- id = server.UserID,
- aid = server.AlterID,
- net = server.TransferProtocol,
- type = server.FakeType,
- host = server.Host,
- path = server.Path,
- tls = server.TLSSecureType
- },
+ {
+ v = 2,
+ ps = server.Remark,
+ add = server.Hostname,
+ port = server.Port,
+ scy = server.EncryptMethod,
+ id = server.UserID,
+ aid = server.AlterID,
+ net = server.TransferProtocol,
+ type = server.FakeType,
+ host = server.Host ?? "",
+ path = server.Path ?? "",
+ tls = server.TLSSecureType,
+ sni = server.ServerName ?? ""
+ },
new JsonSerializerOptions
{
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
@@ -90,18 +92,18 @@ namespace Netch.Servers
data.Remark = vmess.ps;
data.Hostname = vmess.add;
+ data.EncryptMethod = vmess.scy;
data.Port = vmess.port;
+ data.UserID = vmess.id;
data.AlterID = vmess.aid;
data.TransferProtocol = vmess.net;
data.FakeType = vmess.type;
+ data.ServerName = vmess.sni;
if (data.TransferProtocol == "quic")
{
- if (VMessGlobal.QUIC.Contains(vmess.host!))
- {
- data.QUICSecure = vmess.host;
- data.QUICSecret = vmess.path;
- }
+ data.QUICSecure = vmess.host;
+ data.QUICSecret = vmess.path;
}
else
{
@@ -110,7 +112,6 @@ namespace Netch.Servers
}
data.TLSSecureType = vmess.tls;
- data.EncryptMethod = "auto"; // V2Ray 加密方式不包括在链接中,主动添加一个
return new[] { data };
}