bettercap/modules/http_proxy/http_proxy_cert_cache.go
2019-02-10 23:58:08 +01:00

33 lines
550 B
Go

package http_proxy
import (
"crypto/tls"
"fmt"
"sync"
)
var (
certCache = make(map[string]*tls.Certificate)
certLock = &sync.Mutex{}
)
func getCachedCert(domain string, port int) *tls.Certificate {
key := fmt.Sprintf("%s:%d", domain, port)
certLock.Lock()
defer certLock.Unlock()
if cert, found := certCache[key]; found {
return cert
}
return nil
}
func setCachedCert(domain string, port int, cert *tls.Certificate) {
key := fmt.Sprintf("%s:%d", domain, port)
certLock.Lock()
defer certLock.Unlock()
certCache[key] = cert
}