fix: hy2/tuic inbound cert isn't path

Co-authored-by: wwqgtxx <wwqgtxx@gmail.com>
This commit is contained in:
gVisor bot 2023-10-01 12:04:34 +08:00
parent 712cf5b2ec
commit 49610fcb1b
4 changed files with 10 additions and 10 deletions

View file

@ -10,7 +10,11 @@ import (
"math/big" "math/big"
) )
func ParseCert(certificate, privateKey string) (tls.Certificate, error) { type Path interface {
Resolve(path string) string
}
func ParseCert(certificate, privateKey string, path Path) (tls.Certificate, error) {
if certificate == "" && privateKey == "" { if certificate == "" && privateKey == "" {
return newRandomTLSKeyPair() return newRandomTLSKeyPair()
} }
@ -19,6 +23,8 @@ func ParseCert(certificate, privateKey string) (tls.Certificate, error) {
return cert, nil return cert, nil
} }
certificate = path.Resolve(certificate)
privateKey = path.Resolve(privateKey)
cert, loadErr := tls.LoadX509KeyPair(certificate, privateKey) cert, loadErr := tls.LoadX509KeyPair(certificate, privateKey)
if loadErr != nil { if loadErr != nil {
return tls.Certificate{}, fmt.Errorf("parse certificate failed, maybe format error:%s, or path error: %s", painTextErr.Error(), loadErr.Error()) return tls.Certificate{}, fmt.Errorf("parse certificate failed, maybe format error:%s, or path error: %s", painTextErr.Error(), loadErr.Error())

View file

@ -112,7 +112,7 @@ func Start(addr string, tlsAddr string, secret string,
if len(tlsAddr) > 0 { if len(tlsAddr) > 0 {
go func() { go func() {
c, err := CN.ParseCert(certificat, privateKey) c, err := CN.ParseCert(certificat, privateKey, C.Path)
if err != nil { if err != nil {
log.Errorln("External controller tls listen error: %s", err) log.Errorln("External controller tls listen error: %s", err)
return return

View file

@ -50,10 +50,7 @@ func New(config LC.Hysteria2Server, tunnel C.Tunnel, additions ...inbound.Additi
sl = &Listener{false, config, nil, nil} sl = &Listener{false, config, nil, nil}
config.Certificate = C.Path.Resolve(config.Certificate) cert, err := CN.ParseCert(config.Certificate, config.PrivateKey, C.Path)
config.PrivateKey = C.Path.Resolve(config.PrivateKey)
cert, err := CN.ParseCert(config.Certificate, config.PrivateKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -44,10 +44,7 @@ func New(config LC.TuicServer, tunnel C.Tunnel, additions ...inbound.Addition) (
Additions: additions, Additions: additions,
} }
config.Certificate = C.Path.Resolve(config.Certificate) cert, err := CN.ParseCert(config.Certificate, config.PrivateKey, C.Path)
config.PrivateKey = C.Path.Resolve(config.PrivateKey)
cert, err := CN.ParseCert(config.Certificate, config.PrivateKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }