aboutsummaryrefslogtreecommitdiff
path: root/examples/client.go
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2021-01-14 17:28:03 -0500
committerAdnan Maolood <[email protected]>2021-01-14 17:28:03 -0500
commit1a3974b3a394e64f714b2942b8882a08efffc12f (patch)
tree673e691d70940d59e99a59f511fa4a933c43f45e /examples/client.go
parenttofu: Add KnownHosts.Load function (diff)
downloadgo-gemini-1a3974b3a394e64f714b2942b8882a08efffc12f.tar.xz
go-gemini-1a3974b3a394e64f714b2942b8882a08efffc12f.zip
Update examples/client.go
Diffstat (limited to 'examples/client.go')
-rw-r--r--examples/client.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/examples/client.go b/examples/client.go
index 60c8351..97a197a 100644
--- a/examples/client.go
+++ b/examples/client.go
@@ -23,16 +23,22 @@ import (
)
var (
- hosts tofu.KnownHostsFile
- scanner *bufio.Scanner
+ hosts tofu.KnownHosts
+ hostsfile *tofu.HostWriter
+ scanner *bufio.Scanner
)
func init() {
// Load known hosts file
path := filepath.Join(xdg.DataHome(), "gemini", "known_hosts")
- err := hosts.Open(path)
+ err := hosts.Load(path)
if err != nil {
- log.Println(err)
+ log.Fatal(err)
+ }
+
+ hostsfile, err = tofu.NewHostsFile(path)
+ if err != nil {
+ log.Fatal(err)
}
scanner = bufio.NewScanner(os.Stdin)
@@ -48,7 +54,7 @@ Otherwise, this should be safe to trust.
=> `
func trustCertificate(hostname string, cert *x509.Certificate) error {
- host := tofu.NewKnownHost(hostname, cert.Raw, cert.NotAfter)
+ host := tofu.NewHost(hostname, cert.Raw, cert.NotAfter)
knownHost, ok := hosts.Lookup(hostname)
if ok && time.Now().Before(knownHost.Expires) {
@@ -64,8 +70,10 @@ func trustCertificate(hostname string, cert *x509.Certificate) error {
switch scanner.Text() {
case "t":
hosts.Add(host)
+ hostsfile.WriteHost(host)
return nil
case "o":
+ hosts.Add(host)
return nil
default:
return errors.New("certificate not trusted")