mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-02-02 06:48:14 -05:00
chore: support reality
This commit is contained in:
parent
78beaeb03f
commit
329d148002
@ -86,7 +86,7 @@ type V2rayExtraConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RealityConfig struct {
|
type RealityConfig struct {
|
||||||
Dest interface{} `yaml:"Dest" json:"Dest"`
|
Dest string `yaml:"Dest" json:"Dest"`
|
||||||
Xver string `yaml:"Xver" json:"Xver"`
|
Xver string `yaml:"Xver" json:"Xver"`
|
||||||
ServerNames []string `yaml:"ServerNames" json:"ServerNames"`
|
ServerNames []string `yaml:"ServerNames" json:"ServerNames"`
|
||||||
PrivateKey string `yaml:"PrivateKey" json:"PrivateKey"`
|
PrivateKey string `yaml:"PrivateKey" json:"PrivateKey"`
|
||||||
|
@ -13,7 +13,7 @@ type CertConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RealityConfig struct {
|
type RealityConfig struct {
|
||||||
Dest interface{} `yaml:"Dest" json:"Dest"`
|
Dest string `yaml:"Dest" json:"Dest"`
|
||||||
Xver uint64 `yaml:"Xver" json:"Xver"`
|
Xver uint64 `yaml:"Xver" json:"Xver"`
|
||||||
ServerNames []string `yaml:"ServerNames" json:"ServerNames"`
|
ServerNames []string `yaml:"ServerNames" json:"ServerNames"`
|
||||||
PrivateKey string `yaml:"PrivateKey" json:"PrivateKey"`
|
PrivateKey string `yaml:"PrivateKey" json:"PrivateKey"`
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/inazumav/sing-box/inbound"
|
"github.com/inazumav/sing-box/inbound"
|
||||||
F "github.com/sagernet/sing/common/format"
|
F "github.com/sagernet/sing/common/format"
|
||||||
@ -40,11 +41,69 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
|||||||
SniffOverrideDestination: c.SingOptions.SniffOverrideDestination,
|
SniffOverrideDestination: c.SingOptions.SniffOverrideDestination,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tls := option.InboundTLSOptions{
|
var tls option.InboundTLSOptions
|
||||||
Enabled: info.Tls,
|
if info.Tls || info.Type == "hysteria" {
|
||||||
CertificatePath: c.CertConfig.CertFile,
|
if c.CertConfig == nil {
|
||||||
KeyPath: c.CertConfig.KeyFile,
|
return option.Inbound{}, fmt.Errorf("the CertConfig is not vail")
|
||||||
ServerName: info.ServerName,
|
}
|
||||||
|
tls.Enabled = true
|
||||||
|
tls.Insecure = true
|
||||||
|
tls.ServerName = info.ServerName
|
||||||
|
switch c.CertConfig.CertMode {
|
||||||
|
case "none", "":
|
||||||
|
break // disable
|
||||||
|
case "reality":
|
||||||
|
if c.CertConfig.RealityConfig == nil {
|
||||||
|
return option.Inbound{}, fmt.Errorf("RealityConfig is not valid")
|
||||||
|
}
|
||||||
|
rc := c.CertConfig.RealityConfig
|
||||||
|
tls.ServerName = rc.ServerNames[0]
|
||||||
|
if len(rc.ShortIds) == 0 {
|
||||||
|
rc.ShortIds = []string{""}
|
||||||
|
}
|
||||||
|
dest, _ := strconv.Atoi(rc.Dest)
|
||||||
|
mtd, _ := strconv.Atoi(strconv.FormatUint(rc.MaxTimeDiff, 10))
|
||||||
|
tls.Reality = &option.InboundRealityOptions{
|
||||||
|
Enabled: true,
|
||||||
|
ShortID: rc.ShortIds,
|
||||||
|
PrivateKey: rc.PrivateKey,
|
||||||
|
MaxTimeDifference: option.Duration(time.Duration(mtd) * time.Second),
|
||||||
|
Handshake: option.InboundRealityHandshakeOptions{
|
||||||
|
ServerOptions: option.ServerOptions{
|
||||||
|
Server: rc.ServerNames[0],
|
||||||
|
ServerPort: uint16(dest),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
case "remote":
|
||||||
|
if info.ExtraConfig.EnableReality == "true" {
|
||||||
|
if c.CertConfig.RealityConfig == nil {
|
||||||
|
return option.Inbound{}, fmt.Errorf("RealityConfig is not valid")
|
||||||
|
}
|
||||||
|
rc := info.ExtraConfig.RealityConfig
|
||||||
|
if len(rc.ShortIds) == 0 {
|
||||||
|
rc.ShortIds = []string{""}
|
||||||
|
}
|
||||||
|
dest, _ := strconv.Atoi(rc.Dest)
|
||||||
|
mtd, _ := strconv.Atoi(rc.MaxTimeDiff)
|
||||||
|
tls.Reality = &option.InboundRealityOptions{
|
||||||
|
Enabled: true,
|
||||||
|
ShortID: rc.ShortIds,
|
||||||
|
PrivateKey: rc.PrivateKey,
|
||||||
|
MaxTimeDifference: option.Duration(time.Duration(mtd) * time.Second),
|
||||||
|
Handshake: option.InboundRealityHandshakeOptions{
|
||||||
|
ServerOptions: option.ServerOptions{
|
||||||
|
Server: rc.ServerNames[0],
|
||||||
|
ServerPort: uint16(dest),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
tls.CertificatePath = c.CertConfig.CertFile
|
||||||
|
tls.KeyPath = c.CertConfig.KeyFile
|
||||||
|
}
|
||||||
}
|
}
|
||||||
in := option.Inbound{
|
in := option.Inbound{
|
||||||
Tag: tag,
|
Tag: tag,
|
||||||
|
Loading…
Reference in New Issue
Block a user