mirror of
https://github.com/MetaCubeX/Clash.Meta.git
synced 2025-04-19 16:50:56 +00:00
chore: reuse cert pool
This commit is contained in:
parent
d305e0ddfc
commit
5b73942960
1 changed files with 12 additions and 5 deletions
|
@ -15,7 +15,7 @@ import (
|
|||
)
|
||||
|
||||
var trustCerts []*x509.Certificate
|
||||
|
||||
var certPool *x509.CertPool
|
||||
var mutex sync.RWMutex
|
||||
var errNotMacth error = errors.New("certificate fingerprints do not match")
|
||||
|
||||
|
@ -40,10 +40,17 @@ func ResetCertificate() {
|
|||
}
|
||||
|
||||
func getCertPool() *x509.CertPool {
|
||||
certPool, err := x509.SystemCertPool()
|
||||
if err == nil {
|
||||
for _, cert := range trustCerts {
|
||||
certPool.AddCert(cert)
|
||||
if certPool == nil {
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
if certPool != nil {
|
||||
return certPool
|
||||
}
|
||||
certPool, err := x509.SystemCertPool()
|
||||
if err == nil {
|
||||
for _, cert := range trustCerts {
|
||||
certPool.AddCert(cert)
|
||||
}
|
||||
}
|
||||
}
|
||||
return certPool
|
||||
|
|
Loading…
Add table
Reference in a new issue