fix bug for reality

This commit is contained in:
Yuzuki616
2023-08-23 22:06:36 +08:00
parent 0a4bb84ccf
commit 2cb2199b83
5 changed files with 22 additions and 24 deletions

View File

@@ -72,7 +72,7 @@ type VAllssNode struct {
type TlsSettings struct { type TlsSettings struct {
ServerName string `json:"server_name"` ServerName string `json:"server_name"`
ServerPort string `json:"server_port"` ServerPort string `json:"server_port"`
ShortIds []string `json:"short_ids"` ShortId string `json:"short_id"`
PrivateKey string `json:"-"` PrivateKey string `json:"-"`
} }
@@ -81,7 +81,7 @@ type RealityConfig struct {
Xver uint64 `json:"Xver"` Xver uint64 `json:"Xver"`
MinClientVer string `json:"MinClientVer"` MinClientVer string `json:"MinClientVer"`
MaxClientVer string `json:"MaxClientVer"` MaxClientVer string `json:"MaxClientVer"`
MaxTimeDiff uint64 `json:"MaxTimeDiff"` MaxTimeDiff string `json:"MaxTimeDiff"`
} }
type ShadowsocksNode struct { type ShadowsocksNode struct {
@@ -148,7 +148,7 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
} }
} }
if node.Security == Reality { if node.Security == Reality {
key := crypt.GenX25519Private([]byte(strconv.Itoa(c.NodeId) + c.NodeType + c.Token)) key := crypt.GenX25519Private([]byte("vless" + c.Token))
rsp.TlsSettings.PrivateKey = base64.RawURLEncoding.EncodeToString(key) rsp.TlsSettings.PrivateKey = base64.RawURLEncoding.EncodeToString(key)
} }
case "shadowsocks": case "shadowsocks":

View File

@@ -58,22 +58,19 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
tls.Enabled = true tls.Enabled = true
v := info.VAllss v := info.VAllss
tls.ServerName = v.TlsSettings.ServerName tls.ServerName = v.TlsSettings.ServerName
if len(v.TlsSettings.ShortIds) == 0 {
v.TlsSettings.ShortIds = []string{""}
}
dest, _ := strconv.Atoi(v.TlsSettings.ServerPort) dest, _ := strconv.Atoi(v.TlsSettings.ServerPort)
mtd, _ := strconv.Atoi(strconv.FormatUint(v.RealityConfig.MaxTimeDiff, 10)) mtd, _ := time.ParseDuration(v.RealityConfig.MaxTimeDiff)
tls.Reality = &option.InboundRealityOptions{ tls.Reality = &option.InboundRealityOptions{
Enabled: true, Enabled: true,
ShortID: v.TlsSettings.ShortIds, ShortID: []string{v.TlsSettings.ShortId},
PrivateKey: v.TlsSettings.PrivateKey, PrivateKey: v.TlsSettings.PrivateKey,
MaxTimeDifference: option.Duration(time.Duration(mtd) * time.Second),
Handshake: option.InboundRealityHandshakeOptions{ Handshake: option.InboundRealityHandshakeOptions{
ServerOptions: option.ServerOptions{ ServerOptions: option.ServerOptions{
Server: tls.ServerName, Server: tls.ServerName,
ServerPort: uint16(dest), ServerPort: uint16(dest),
}, },
}, },
MaxTimeDifference: option.Duration(mtd),
} }
} }
in := option.Inbound{ in := option.Inbound{
@@ -118,7 +115,6 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
return option.Inbound{}, fmt.Errorf("decode NetworkSettings error: %s", err) return option.Inbound{}, fmt.Errorf("decode NetworkSettings error: %s", err)
} }
} }
tls.ServerName = n.ServerName
if info.Type == "vless" { if info.Type == "vless" {
in.Type = "vless" in.Type = "vless"
in.VLESSOptions = option.VLESSInboundOptions{ in.VLESSOptions = option.VLESSInboundOptions{

View File

@@ -6,6 +6,8 @@ import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"fmt" "fmt"
"time"
"github.com/InazumaV/V2bX/api/panel" "github.com/InazumaV/V2bX/api/panel"
"github.com/InazumaV/V2bX/conf" "github.com/InazumaV/V2bX/conf"
"github.com/goccy/go-json" "github.com/goccy/go-json"
@@ -107,19 +109,16 @@ func buildInbound(option *conf.Options, nodeInfo *panel.NodeInfo, tag string) (*
if err != nil { if err != nil {
return nil, fmt.Errorf("marshal reality dest error: %s", err) return nil, fmt.Errorf("marshal reality dest error: %s", err)
} }
short := nodeInfo.VAllss.TlsSettings.ShortIds mtd, _ := time.ParseDuration(v.RealityConfig.MaxTimeDiff)
if len(short) == 0 {
short = []string{""}
}
in.StreamSetting.REALITYSettings = &coreConf.REALITYConfig{ in.StreamSetting.REALITYSettings = &coreConf.REALITYConfig{
Dest: d, Dest: d,
Xver: v.RealityConfig.Xver, Xver: v.RealityConfig.Xver,
ServerNames: v.TlsSettings.ServerName, ServerNames: []string{v.TlsSettings.ServerName},
PrivateKey: v.TlsSettings.PrivateKey, PrivateKey: v.TlsSettings.PrivateKey,
MinClientVer: v.RealityConfig.MinClientVer, MinClientVer: v.RealityConfig.MinClientVer,
MaxClientVer: v.RealityConfig.MaxClientVer, MaxClientVer: v.RealityConfig.MaxClientVer,
MaxTimeDiff: v.RealityConfig.MaxTimeDiff, MaxTimeDiff: uint64(mtd.Microseconds()),
ShortIds: short, ShortIds: []string{v.TlsSettings.ShortId},
} }
break break
} }

5
go.mod
View File

@@ -11,7 +11,6 @@ require (
github.com/go-redis/redis/v8 v8.11.5 github.com/go-redis/redis/v8 v8.11.5
github.com/go-resty/resty/v2 v2.7.0 github.com/go-resty/resty/v2 v2.7.0
github.com/goccy/go-json v0.10.2 github.com/goccy/go-json v0.10.2
github.com/google/uuid v1.3.0
github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/go-multierror v1.1.1
github.com/inazumav/sing-box v0.0.0-20230809113805-82b279719f5f github.com/inazumav/sing-box v0.0.0-20230809113805-82b279719f5f
github.com/juju/ratelimit v1.0.2 github.com/juju/ratelimit v1.0.2
@@ -22,7 +21,7 @@ require (
golang.org/x/crypto v0.12.0 golang.org/x/crypto v0.12.0
golang.org/x/sys v0.11.0 golang.org/x/sys v0.11.0
google.golang.org/protobuf v1.31.0 google.golang.org/protobuf v1.31.0
gopkg.in/yaml.v3 v3.0.1 gopkg.in/natefinch/lumberjack.v2 v2.2.1
) )
require ( require (
@@ -86,6 +85,7 @@ require (
github.com/google/btree v1.1.2 // indirect github.com/google/btree v1.1.2 // indirect
github.com/google/go-querystring v1.1.0 // indirect github.com/google/go-querystring v1.1.0 // indirect
github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 // indirect github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.7.1 // indirect github.com/googleapis/gax-go/v2 v2.7.1 // indirect
github.com/gophercloud/gophercloud v1.0.0 // indirect github.com/gophercloud/gophercloud v1.0.0 // indirect
@@ -214,6 +214,7 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/ns1/ns1-go.v2 v2.7.6 // indirect gopkg.in/ns1/ns1-go.v2 v2.7.6 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gvisor.dev/gvisor v0.0.0-20220901235040-6ca97ef2ce1c // indirect gvisor.dev/gvisor v0.0.0-20220901235040-6ca97ef2ce1c // indirect
lukechampine.com/blake3 v1.2.1 // indirect lukechampine.com/blake3 v1.2.1 // indirect
) )

2
go.sum
View File

@@ -1134,6 +1134,8 @@ gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
gopkg.in/ns1/ns1-go.v2 v2.7.6 h1:mCPl7q0jbIGACXvGBljAuuApmKZo3rRi4tlRIEbMvjA= gopkg.in/ns1/ns1-go.v2 v2.7.6 h1:mCPl7q0jbIGACXvGBljAuuApmKZo3rRi4tlRIEbMvjA=
gopkg.in/ns1/ns1-go.v2 v2.7.6/go.mod h1:GMnKY+ZuoJ+lVLL+78uSTjwTz2jMazq6AfGKQOYhsPk= gopkg.in/ns1/ns1-go.v2 v2.7.6/go.mod h1:GMnKY+ZuoJ+lVLL+78uSTjwTz2jMazq6AfGKQOYhsPk=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=