aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2020-12-19 13:44:33 -0500
committerAdnan Maolood <[email protected]>2020-12-19 13:44:33 -0500
commit48fa6a724e55c35d46504be9c23336a13359fc4e (patch)
treeb32b8df47b7d22b86bde0ae4067845d31d962396 /examples
parentclient: Verify expiration time (diff)
downloadgo-gemini-48fa6a724e55c35d46504be9c23336a13359fc4e.tar.xz
go-gemini-48fa6a724e55c35d46504be9c23336a13359fc4e.zip
examples/client: Fix fingerprint checkv0.1.10
Diffstat (limited to 'examples')
-rw-r--r--examples/client.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/examples/client.go b/examples/client.go
index 5ccb3ef..f707f04 100644
--- a/examples/client.go
+++ b/examples/client.go
@@ -46,13 +46,16 @@ Otherwise, this should be safe to trust.
=> `
func trustCertificate(hostname string, cert *x509.Certificate) error {
+ fingerprint := gemini.NewFingerprint(cert.Raw, cert.NotAfter)
knownHost, ok := hosts.Lookup(hostname)
if ok && time.Now().Before(knownHost.Expires) {
- // Certificate is in known hosts file and is not expired
- return nil
+ // Check fingerprint
+ if knownHost.Hex == fingerprint.Hex {
+ return nil
+ }
+ return errors.New("error: fingerprint does not match!")
}
- fingerprint := gemini.NewFingerprint(cert.Raw, cert.NotAfter)
fmt.Printf(trustPrompt, hostname, fingerprint.Hex)
scanner.Scan()
switch scanner.Text() {