mirror of
https://github.com/bettercap/bettercap.git
synced 2024-11-08 06:30:13 -08:00
32 lines
586 B
Go
32 lines
586 B
Go
package http_proxy
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"fmt"
|
|
"sync"
|
|
)
|
|
|
|
var (
|
|
certCache = make(map[string]*tls.Certificate)
|
|
certLock = &sync.Mutex{}
|
|
)
|
|
|
|
func keyFor(domain string, port int) string {
|
|
return fmt.Sprintf("%s:%d", domain, port)
|
|
}
|
|
|
|
func getCachedCert(domain string, port int) *tls.Certificate {
|
|
certLock.Lock()
|
|
defer certLock.Unlock()
|
|
if cert, found := certCache[keyFor(domain, port)]; found {
|
|
return cert
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func setCachedCert(domain string, port int, cert *tls.Certificate) {
|
|
certLock.Lock()
|
|
defer certLock.Unlock()
|
|
certCache[keyFor(domain, port)] = cert
|
|
}
|