Make TrustCertificate accept hostname instead of request
This commit is contained in:
parent
32a9fcba0c
commit
73a1692a5b
|
@ -185,7 +185,7 @@ type Client struct {
|
|||
// TrustCertificate, if not nil, will be called to determine whether the
|
||||
// client should trust the given certificate.
|
||||
// If error is not nil, the connection will be aborted.
|
||||
TrustCertificate func(req *Request, cert *x509.Certificate, knownHosts *KnownHosts) error
|
||||
TrustCertificate func(hostname string, cert *x509.Certificate, knownHosts *KnownHosts) error
|
||||
}
|
||||
|
||||
// Send sends a Gemini request and returns a Gemini response.
|
||||
|
@ -219,7 +219,7 @@ func (c *Client) Send(req *Request) (*Response, error) {
|
|||
if err := c.KnownHosts.Lookup(req.Hostname(), cert); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if err := c.TrustCertificate(req, cert, &c.KnownHosts); err != nil {
|
||||
} else if err := c.TrustCertificate(req.Hostname(), cert, &c.KnownHosts); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -22,8 +22,8 @@ func init() {
|
|||
client = &gemini.Client{}
|
||||
client.KnownHosts.Load()
|
||||
|
||||
client.TrustCertificate = func(req *gemini.Request, cert *x509.Certificate, knownHosts *gemini.KnownHosts) error {
|
||||
err := knownHosts.Lookup(req.Hostname(), cert)
|
||||
client.TrustCertificate = func(hostname string, cert *x509.Certificate, knownHosts *gemini.KnownHosts) error {
|
||||
err := knownHosts.Lookup(hostname, cert)
|
||||
if err != nil {
|
||||
switch err {
|
||||
case gemini.ErrCertificateNotTrusted:
|
||||
|
@ -37,7 +37,7 @@ func init() {
|
|||
return nil
|
||||
} else if userTrustsCertificatePermanently() {
|
||||
// Add the certificate to the known hosts file
|
||||
knownHosts.Add(req.Hostname(), cert)
|
||||
knownHosts.Add(hostname, cert)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,11 +48,11 @@ var DefaultClient *Client
|
|||
|
||||
func init() {
|
||||
DefaultClient = &Client{
|
||||
TrustCertificate: func(req *Request, cert *x509.Certificate, knownHosts *KnownHosts) error {
|
||||
TrustCertificate: func(hostname string, cert *x509.Certificate, knownHosts *KnownHosts) error {
|
||||
// Load the hosts only once. This is so that the hosts don't have to be loaded
|
||||
// for those using their own clients.
|
||||
setupDefaultClientOnce.Do(setupDefaultClient)
|
||||
return knownHosts.Lookup(req.Hostname(), cert)
|
||||
return knownHosts.Lookup(hostname, cert)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user