fix: hy2/tuic inbound cert isn't path

Co-authored-by: wwqgtxx <wwqgtxx@gmail.com>
This commit is contained in:
Larvan2 2023-10-01 12:04:34 +08:00
parent 8253bfe2e0
commit dbaee284e4
4 changed files with 10 additions and 10 deletions

View File

@ -10,7 +10,11 @@ import (
"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 == "" {
return newRandomTLSKeyPair()
}
@ -19,6 +23,8 @@ func ParseCert(certificate, privateKey string) (tls.Certificate, error) {
return cert, nil
}
certificate = path.Resolve(certificate)
privateKey = path.Resolve(privateKey)
cert, loadErr := tls.LoadX509KeyPair(certificate, privateKey)
if loadErr != nil {
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 {
go func() {
c, err := CN.ParseCert(certificat, privateKey)
c, err := CN.ParseCert(certificat, privateKey, C.Path)
if err != nil {
log.Errorln("External controller tls listen error: %s", err)
return

View File

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

View File

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