proxy: fix loading system trusted ca.
Some checks failed
Coverage CI / build (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
Ubuntu CI / build (push) Has been cancelled

This commit is contained in:
Daniel Ding
2025-10-17 09:41:50 +08:00
parent 566541bea2
commit 25277b573d

View File

@@ -284,19 +284,18 @@ func (t *HttpProxy) openConn(protocol, remote string, insecure bool) (net.Conn,
}
caFile := t.cfg.CaCert
if caFile != "" && libol.FileExist(caFile) == nil {
caCertPool := x509.NewCertPool()
roots, err := x509.SystemCertPool()
// Load CA cert
caCert, err := os.ReadFile(caFile)
if err != nil {
t.out.Warn("HttpProxy.openConn %s", err)
} else {
caCertPool.AppendCertsFromPEM(caCert)
conf.RootCAs = caCertPool
roots.AppendCertsFromPEM(caCert)
conf.RootCAs = roots
}
}
dialer := &net.Dialer{Timeout: 10 * time.Second}
return tls.DialWithDialer(dialer, "tcp", remote, conf)
}
return net.DialTimeout("tcp", remote, 10*time.Second)
}