Restrict client certificates to certain paths

This commit is contained in:
Adnan Maolood
2020-10-27 23:34:06 -04:00
parent fc72224ce9
commit d1dcf070ff
4 changed files with 48 additions and 20 deletions

View File

@@ -49,16 +49,16 @@ func init() {
defaultClientOnce.Do(func() { knownHosts.LoadDefault() })
return knownHosts.Lookup(hostname, cert)
}
DefaultClient.GetCertificate = func(hostname string, store *CertificateStore) *tls.Certificate {
if cert, err := store.Lookup(hostname); err == nil {
DefaultClient.GetCertificate = func(req *Request, store *ClientCertificateStore) *tls.Certificate {
if cert, err := store.Lookup(req.URL.Hostname(), req.URL.Path); err == nil {
return cert
}
duration := time.Hour
cert, err := NewCertificate(hostname, duration)
cert, err := NewCertificate("", duration)
if err != nil {
return nil
}
store.Add(hostname, cert)
store.Add(req.URL.Hostname()+req.URL.Path, cert)
return &cert
}
}