From 1b3f9a065572f938c7723153733243c770424646 Mon Sep 17 00:00:00 2001 From: adnano Date: Sat, 26 Sep 2020 13:29:29 -0400 Subject: [PATCH] Remove (*KnownHosts).Has function --- client.go | 4 +++- tofu.go | 14 -------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/client.go b/client.go index bb1fa90..615dcd6 100644 --- a/client.go +++ b/client.go @@ -195,8 +195,10 @@ func (c *Client) Send(req *Request) (*Response, error) { } // Check that the client trusts the certificate if c.TrustCertificate == nil { - if c.KnownHosts == nil || !c.KnownHosts.Has(cert) { + if c.KnownHosts == nil { return ErrCertificateNotTrusted + } else if err := c.KnownHosts.Lookup(cert); err != nil { + return err } } else if err := c.TrustCertificate(cert, c.KnownHosts); err != nil { return err diff --git a/tofu.go b/tofu.go index d3ab251..5c92ea2 100644 --- a/tofu.go +++ b/tofu.go @@ -57,20 +57,6 @@ func (k *KnownHosts) Add(cert *x509.Certificate) { } } -// Has reports whether the provided certificate is in the list. -func (k *KnownHosts) Has(cert *x509.Certificate) bool { - now := time.Now().Unix() - hostname := cert.Subject.CommonName - fingerprint := Fingerprint(cert) - for i := range k.hosts { - if k.hosts[i].Expires > now && k.hosts[i].Hostname == hostname && - k.hosts[i].Fingerprint == fingerprint { - return true - } - } - return false -} - // Lookup looks for the provided certificate in the list of known hosts. // If the hostname is in the list, but the fingerprint differs, // Lookup returns ErrCertificateNotTrusted.