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
|
// TrustCertificate, if not nil, will be called to determine whether the
|
||||||
// client should trust the given certificate.
|
// client should trust the given certificate.
|
||||||
// If error is not nil, the connection will be aborted.
|
// 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.
|
// 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 {
|
if err := c.KnownHosts.Lookup(req.Hostname(), cert); err != nil {
|
||||||
return err
|
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 err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -22,8 +22,8 @@ func init() {
|
|||||||
client = &gemini.Client{}
|
client = &gemini.Client{}
|
||||||
client.KnownHosts.Load()
|
client.KnownHosts.Load()
|
||||||
|
|
||||||
client.TrustCertificate = func(req *gemini.Request, cert *x509.Certificate, knownHosts *gemini.KnownHosts) error {
|
client.TrustCertificate = func(hostname string, cert *x509.Certificate, knownHosts *gemini.KnownHosts) error {
|
||||||
err := knownHosts.Lookup(req.Hostname(), cert)
|
err := knownHosts.Lookup(hostname, cert)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch err {
|
switch err {
|
||||||
case gemini.ErrCertificateNotTrusted:
|
case gemini.ErrCertificateNotTrusted:
|
||||||
@ -37,7 +37,7 @@ func init() {
|
|||||||
return nil
|
return nil
|
||||||
} else if userTrustsCertificatePermanently() {
|
} else if userTrustsCertificatePermanently() {
|
||||||
// Add the certificate to the known hosts file
|
// Add the certificate to the known hosts file
|
||||||
knownHosts.Add(req.Hostname(), cert)
|
knownHosts.Add(hostname, cert)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,11 +48,11 @@ var DefaultClient *Client
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
DefaultClient = &Client{
|
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
|
// Load the hosts only once. This is so that the hosts don't have to be loaded
|
||||||
// for those using their own clients.
|
// for those using their own clients.
|
||||||
setupDefaultClientOnce.Do(setupDefaultClient)
|
setupDefaultClientOnce.Do(setupDefaultClient)
|
||||||
return knownHosts.Lookup(req.Hostname(), cert)
|
return knownHosts.Lookup(hostname, cert)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user