chore: reuse cert pool

This commit is contained in:
Skyxim 2023-03-29 14:09:42 +08:00
parent d305e0ddfc
commit 5b73942960

View file

@ -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