fix cert mode

This commit is contained in:
yuzuki999 2023-07-13 14:16:21 +08:00
parent a9319e2732
commit b3a8b27c2f
3 changed files with 30 additions and 23 deletions

View File

@ -6,7 +6,6 @@ import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"fmt" "fmt"
"github.com/Yuzuki616/V2bX/api/panel" "github.com/Yuzuki616/V2bX/api/panel"
"github.com/Yuzuki616/V2bX/conf" "github.com/Yuzuki616/V2bX/conf"
"github.com/goccy/go-json" "github.com/goccy/go-json"
@ -102,24 +101,24 @@ func buildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s
RejectUnknownSNI: config.CertConfig.RejectUnknownSni, RejectUnknownSNI: config.CertConfig.RejectUnknownSni,
} }
} }
} // use remote reality replace local config
// use remote reality replace local config if nodeInfo.ExtraConfig.EnableReality {
if nodeInfo.ExtraConfig.EnableReality { rc := nodeInfo.ExtraConfig.RealityConfig
rc := nodeInfo.ExtraConfig.RealityConfig in.StreamSetting.Security = "reality"
in.StreamSetting.Security = "reality" d, err := json.Marshal(rc.Dest)
d, err := json.Marshal(rc.Dest) 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) }
} in.StreamSetting.REALITYSettings = &coreConf.REALITYConfig{
in.StreamSetting.REALITYSettings = &coreConf.REALITYConfig{ Dest: d,
Dest: d, Xver: rc.Xver,
Xver: rc.Xver, ServerNames: rc.ServerNames,
ServerNames: rc.ServerNames, PrivateKey: rc.PrivateKey,
PrivateKey: rc.PrivateKey, MinClientVer: rc.MinClientVer,
MinClientVer: rc.MinClientVer, MaxClientVer: rc.MaxClientVer,
MaxClientVer: rc.MaxClientVer, MaxTimeDiff: rc.MaxTimeDiff,
MaxTimeDiff: rc.MaxTimeDiff, ShortIds: rc.ShortIds,
ShortIds: rc.ShortIds, }
} }
} }
// Support ProxyProtocol for any transport protocol // Support ProxyProtocol for any transport protocol
@ -194,6 +193,8 @@ func buildV2ray(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, inbound
if err != nil { if err != nil {
return fmt.Errorf("unmarshal grpc settings error: %s", err) return fmt.Errorf("unmarshal grpc settings error: %s", err)
} }
default:
return errors.New("the network type is not vail")
} }
return nil return nil
} }

View File

@ -77,12 +77,14 @@ func (c *Core) AddUsers(p *vCore.AddUsersParams) (added int, err error) {
p.NodeInfo.ExtraConfig.EnableVless { p.NodeInfo.ExtraConfig.EnableVless {
if p.Config.XrayOptions.VlessFlow != "" { if p.Config.XrayOptions.VlessFlow != "" {
if p.Config.XrayOptions.VlessFlow == p.NodeInfo.ExtraConfig.VlessFlow { if p.Config.XrayOptions.VlessFlow == p.NodeInfo.ExtraConfig.VlessFlow {
// local
users = buildVlessUsers(p.Tag, p.UserInfo, p.Config.XrayOptions.VlessFlow) users = buildVlessUsers(p.Tag, p.UserInfo, p.Config.XrayOptions.VlessFlow)
} else { } else {
// remote
users = buildVlessUsers(p.Tag, p.UserInfo, p.NodeInfo.ExtraConfig.VlessFlow) users = buildVlessUsers(p.Tag, p.UserInfo, p.NodeInfo.ExtraConfig.VlessFlow)
} }
} else { } else {
// remote
users = buildVlessUsers(p.Tag, p.UserInfo, p.NodeInfo.ExtraConfig.VlessFlow) users = buildVlessUsers(p.Tag, p.UserInfo, p.NodeInfo.ExtraConfig.VlessFlow)
} }
} else { } else {

View File

@ -21,13 +21,17 @@ func (c *Controller) renewCertTask() {
} }
func (c *Controller) requestCert() error { func (c *Controller) requestCert() error {
if c.CertConfig.CertFile == "" || c.CertConfig.KeyFile == "" {
return fmt.Errorf("cert file path or key file path not exist")
}
switch c.CertConfig.CertMode { switch c.CertConfig.CertMode {
case "reality", "none", "": case "reality", "none", "":
return nil return nil
case "file":
if c.CertConfig.CertFile == "" || c.CertConfig.KeyFile == "" {
return fmt.Errorf("cert file path or key file path not exist")
}
case "dns", "http": case "dns", "http":
if c.CertConfig.CertFile == "" || c.CertConfig.KeyFile == "" {
return fmt.Errorf("cert file path or key file path not exist")
}
if file.IsExist(c.CertConfig.CertFile) && file.IsExist(c.CertConfig.KeyFile) { if file.IsExist(c.CertConfig.CertFile) && file.IsExist(c.CertConfig.KeyFile) {
return nil return nil
} }