Skip to content

Commit

Permalink
添加对reality的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
hsernos committed May 10, 2023
1 parent 3f368de commit b5a8c96
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Txray.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

const (
version = "v3.0.6"
version = "v3.0.7"
name = "Txray"
)

Expand Down
89 changes: 84 additions & 5 deletions cmd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,13 @@ func InitNodeShell(shell *ishell.Shell) {
securityList := []string{
"",
"tls",
"reality",
}
security_index := c.MultiChoice(securityList, "底层传输安全(security)?")
security := securityList[security_index]
if security != "" {
switch security {
case "":
case "tls":
data["security"] = security
c.Print("SNI(sni): ")
sni := c.ReadLine()
Expand All @@ -420,6 +423,36 @@ func InitNodeShell(shell *ishell.Shell) {
if alpnList[index] != "" {
data["alpn"] = alpnList[index]
}
case "reality":
data["security"] = security
c.Print("SNI(sni): ")
sni := c.ReadLine()
if sni != "" {
data["sni"] = sni
}
fpList := []string{
"",
"chrome",
"firefox",
"safari",
"ios",
"android",
"edge",
"360",
"qq",
"random",
"randomized",
}
index := c.MultiChoice(fpList, "指纹(FingerPrint) ?")
if fpList[index] != "" {
data["fp"] = fpList[index]
}
c.Print("公钥(PublicKey): ")
data["pbk"] = c.ReadLine()
c.Print("ShortId: ")
data["sid"] = c.ReadLine()
c.Print("SpiderX: ")
data["spx"] = c.ReadLine()
}
vmessAEAD := &protocols.VMessAEAD{
ID: id,
Expand Down Expand Up @@ -563,10 +596,13 @@ func InitNodeShell(shell *ishell.Shell) {
"",
"tls",
"xtls",
"reality",
}
index = c.MultiChoice(securityList, "底层传输安全(security)?")
security := securityList[index]
if security != "" {
switch security {
case "":
case "tls":
data["security"] = security
c.Print("SNI(sni): ")
sni := c.ReadLine()
Expand All @@ -583,10 +619,23 @@ func InitNodeShell(shell *ishell.Shell) {
if alpnList[index] != "" {
data["alpn"] = alpnList[index]
}
}

switch security {
case "xtls":
data["security"] = security
c.Print("SNI(sni): ")
sni := c.ReadLine()
if sni != "" {
data["sni"] = sni
}
alpnList := []string{
"",
"h2",
"http/1.1",
"h2,http/1.1",
}
index := c.MultiChoice(alpnList, "Alpn ?")
if alpnList[index] != "" {
data["alpn"] = alpnList[index]
}
flowList := []string{
"xtls-rprx-origin",
"xtls-rprx-origin-udp443",
Expand All @@ -598,6 +647,36 @@ func InitNodeShell(shell *ishell.Shell) {
index = c.MultiChoice(flowList, "流控(flow)?")
flow := flowList[index]
data["flow"] = flow
case "reality":
data["security"] = security
c.Print("SNI(sni): ")
sni := c.ReadLine()
if sni != "" {
data["sni"] = sni
}
fpList := []string{
"",
"chrome",
"firefox",
"safari",
"ios",
"android",
"edge",
"360",
"qq",
"random",
"randomized",
}
index := c.MultiChoice(fpList, "指纹(FingerPrint) ?")
if fpList[index] != "" {
data["fp"] = fpList[index]
}
c.Print("公钥(PublicKey): ")
data["pbk"] = c.ReadLine()
c.Print("ShortId: ")
data["sid"] = c.ReadLine()
c.Print("SpiderX: ")
data["spx"] = c.ReadLine()
}
vless := &protocols.VLess{
ID: id,
Expand Down
7 changes: 6 additions & 1 deletion core/protocols/field/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (
NetworkType Field = NewField("type", "tcp") // 协议的传输方式, 可选值 tcp/kcp/ws/http/quic/grpc
VLessEncryption = NoneField("encryption") // 加密, VLESS可选值 none
VMessEncryption = NewField("encryption", "auto") // 加密, VMess可选值 auto/aes-128-gcm/chacha20-poly1305/none
TlsSecurity = NoneField("security") // 设定底层传输所使用的 TLS 类型, 可选值有 none/tls/xtls
TlsSecurity = NoneField("security") // 设定底层传输所使用的 TLS 类型, 可选值有 none/tls/xtls/reality

// TCP
TCPHeaderType = NoneField("headerType")
Expand Down Expand Up @@ -60,4 +60,9 @@ var (
SNI = NilStrField("sni") // TLS SNI
Alpn = NilStrField("alpn") // alpn 多选 h2,http/1.1
Flow = NilStrField("flow") // XTLS 的流控方式,可选值xtls-rprx-direct/xtls-rprx-splice

FingerPrint = NewField("fp", "chrome") // TLS Client Hello 指纹
PublicKey = NilStrField("pbk") // REALITY的公钥
ShortId = NilStrField("sid") // REALITY 的 ID
SpiderX = NilStrField("spx") // REALITY 的爬虫
)
6 changes: 6 additions & 0 deletions core/protocols/vless.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ func (v *VLess) GetInfo() string {
buf.WriteString(fmt.Sprintf("%9s: %s\n", "ServiceName", v.GetValue(field.GrpcServiceName)))
buf.WriteString(fmt.Sprintf("%5s: %s\n", "传输模式", v.GetValue(field.GrpcMode)))
}
if v.GetValue(field.Security) == "reality" {
buf.WriteString(fmt.Sprintf("%9s: %s\n", "FingerPrint", v.GetValue(field.FingerPrint)))
buf.WriteString(fmt.Sprintf("%7s: %s\n", "reality公钥", v.GetValue(field.PublicKey)))
buf.WriteString(fmt.Sprintf("%9s: %s\n", "realityID", v.GetValue(field.ShortId)))
buf.WriteString(fmt.Sprintf("%7s: %s\n", "REALITY爬虫", v.GetValue(field.SpiderX)))
}
buf.WriteString(fmt.Sprintf("%5s: %s\n", "底层传输", v.GetValue(field.Security)))
buf.WriteString(fmt.Sprintf("%9s: %s\n", "SNI", v.GetValue(field.SNI)))
buf.WriteString(fmt.Sprintf("%9s: %s\n", "Alpn", v.GetValue(field.Alpn)))
Expand Down
6 changes: 6 additions & 0 deletions core/protocols/vmessAEAD.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ func (v *VMessAEAD) GetInfo() string {
buf.WriteString(fmt.Sprintf("%9s: %s\n", "ServiceName", v.GetValue(field.GrpcServiceName)))
buf.WriteString(fmt.Sprintf("%5s: %s\n", "传输模式", v.GetValue(field.GrpcMode)))
}
if v.GetValue(field.Security) == "reality" {
buf.WriteString(fmt.Sprintf("%9s: %s\n", "FingerPrint", v.GetValue(field.FingerPrint)))
buf.WriteString(fmt.Sprintf("%7s: %s\n", "reality公钥", v.GetValue(field.PublicKey)))
buf.WriteString(fmt.Sprintf("%9s: %s\n", "realityID", v.GetValue(field.ShortId)))
buf.WriteString(fmt.Sprintf("%7s: %s\n", "REALITY爬虫", v.GetValue(field.SpiderX)))
}
buf.WriteString(fmt.Sprintf("%5s: %s\n", "底层传输", v.GetValue(field.Security)))
buf.WriteString(fmt.Sprintf("%9s: %s\n", "SNI", v.GetValue(field.SNI)))
buf.WriteString(fmt.Sprintf("%9s: %s\n", "Alpn", v.GetValue(field.Alpn)))
Expand Down
4 changes: 1 addition & 3 deletions core/setting/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func init() {

viper.SetDefault(key.DNSPort, 13500)
viper.SetDefault(key.DNSForeign, "1.1.1.1")
viper.SetDefault(key.DNSDomestic, "119.29.29.29")
viper.SetDefault(key.DNSDomestic, "223.6.6.6")
viper.SetDefault(key.DNSBackup, "114.114.114.114")

viper.SetDefault(key.TestURL, "https://www.youtube.com")
Expand All @@ -45,6 +45,4 @@ func init() {
if err != nil {
log.Error(err)
}
// 监听配置文件
viper.WatchConfig()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Txray

go 1.18
go 1.19

require (
github.com/abiosoft/ishell v2.0.0+incompatible
Expand Down
12 changes: 0 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/abiosoft/ishell v2.0.0+incompatible h1:zpwIuEHc37EzrsIYah3cpevrIc8Oma7oZPxr03tlmmw=
github.com/abiosoft/ishell v2.0.0+incompatible/go.mod h1:HQR9AqF2R3P4XXpMpI0NAzgHf/aS6+zVXRj14cVk9qg=
github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db h1:CjPUSXOiYptLbTdr1RceuZgSFDQ7U15ITERUGrUORx8=
Expand Down Expand Up @@ -98,8 +96,6 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY=
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
Expand Down Expand Up @@ -257,8 +253,6 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/sagikazarmark/crypt v0.1.0/go.mod h1:B/mN0msZuINBtQ1zZLEQcegFJJf9vnYIR88KRMEuODE=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/shirou/gopsutil/v3 v3.21.9 h1:Vn4MUz2uXhqLSiCbGFRc0DILbMVLAY92DSkT8bsYrHg=
github.com/shirou/gopsutil/v3 v3.21.9/go.mod h1:YWp/H8Qs5fVmf17v7JNZzA0mPJ+mS2e9JdiUF9LlKzQ=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY=
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
Expand All @@ -280,10 +274,6 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tklauser/go-sysconf v0.3.9 h1:JeUVdAOWhhxVcU6Eqr/ATFHgXk/mmiItdKeJPev3vTo=
github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs=
github.com/tklauser/numcpus v0.3.0 h1:ILuRUQBtssgnxw0XXIjKUC56fgnOrFoQQ/4+DeU2biQ=
github.com/tklauser/numcpus v0.3.0/go.mod h1:yFGUr7TUHQRAhyqBcEg0Ge34zDBAsIvJJcyE6boqnA8=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down Expand Up @@ -428,7 +418,6 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -471,7 +460,6 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf h1:2ucpDCmfkl8Bd/FsLtiD653Wf96cW37s+iGx93zsu4k=
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down
22 changes: 22 additions & 0 deletions xray/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,17 @@ func vLessOutbound(vless *protocols.VLess) interface{} {
streamSettings["xtlsSettings"] = xtlsSettings
user["flow"] = vless.GetValue(field.Flow)
mux = false
case "reality":
realitySettings := map[string]interface{}{
"show": false,
"fingerprint": vless.GetValue(field.FingerPrint),
"serverName": vless.GetHostValue(field.SNI),
"publicKey": vless.GetValue(field.PublicKey),
"shortId": vless.GetValue(field.ShortId),
"spiderX": vless.GetValue(field.SpiderX),
}
streamSettings["realitySettings"] = realitySettings
mux = false
}
switch network {
case "tcp":
Expand Down Expand Up @@ -647,6 +658,17 @@ func vMessAEADOutbound(vmess *protocols.VMessAEAD) interface{} {
tlsSettings["alpn"] = strings.Split(alpn, ",")
}
streamSettings["tlsSettings"] = tlsSettings
case "reality":
realitySettings := map[string]interface{}{
"show": false,
"fingerprint": vmess.GetValue(field.FingerPrint),
"serverName": vmess.GetHostValue(field.SNI),
"publicKey": vmess.GetValue(field.PublicKey),
"shortId": vmess.GetValue(field.ShortId),
"spiderX": vmess.GetValue(field.SpiderX),
}
streamSettings["realitySettings"] = realitySettings
mux = false
}
switch network {
case "tcp":
Expand Down

0 comments on commit b5a8c96

Please sign in to comment.