diff options
| author | adnano <[email protected]> | 2020-09-27 15:03:46 -0400 |
|---|---|---|
| committer | adnano <[email protected]> | 2020-09-27 15:03:46 -0400 |
| commit | e01d59f8f67c5540a80a6ca475e7aaf5f487689a (patch) | |
| tree | ba4aadfc19d2681369ac4f1364c57a4aaa987889 /client.go | |
| parent | Remove port from host when verifying hostnames (diff) | |
| download | go-gemini-e01d59f8f67c5540a80a6ca475e7aaf5f487689a.tar.xz go-gemini-e01d59f8f67c5540a80a6ca475e7aaf5f487689a.zip | |
Don't store wildcards in the known hosts file
Diffstat (limited to 'client.go')
| -rw-r--r-- | client.go | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -45,6 +45,11 @@ type Request struct { TLS tls.ConnectionState } +// Hostname returns the request host without the port. +func (r *Request) Hostname() string { + return hostname(r.Host) +} + // NewRequest returns a new request. The host is inferred from the provided url. func NewRequest(rawurl string) (*Request, error) { u, err := url.Parse(rawurl) @@ -180,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(cert *x509.Certificate, knownHosts *KnownHosts) error + TrustCertificate func(req *Request, cert *x509.Certificate, knownHosts *KnownHosts) error } // Send sends a Gemini request and returns a Gemini response. @@ -205,15 +210,15 @@ func (c *Client) Send(req *Request) (*Response, error) { return err } // Check that the certificate is valid for the hostname - if err := cert.VerifyHostname(hostname(req.Host)); err != nil { + if err := cert.VerifyHostname(req.Hostname()); err != nil { return err } // Check that the client trusts the certificate if c.TrustCertificate == nil { - if err := c.KnownHosts.Lookup(cert); err != nil { + if err := c.KnownHosts.Lookup(req.Hostname(), cert); err != nil { return err } - } else if err := c.TrustCertificate(cert, &c.KnownHosts); err != nil { + } else if err := c.TrustCertificate(req, cert, &c.KnownHosts); err != nil { return err } return nil |