aboutsummaryrefslogtreecommitdiff
path: root/gemini.go
diff options
context:
space:
mode:
authoradnano <[email protected]>2020-09-25 23:06:54 -0400
committeradnano <[email protected]>2020-09-25 23:18:14 -0400
commit927dfd29c598f2ec79fec711877bc582ffd18749 (patch)
treea6cd29fa36b890c067fc6e84562ff5ac05056c11 /gemini.go
parentImplement basic TOFU (diff)
downloadgo-gemini-927dfd29c598f2ec79fec711877bc582ffd18749.tar.xz
go-gemini-927dfd29c598f2ec79fec711877bc582ffd18749.zip
Refactor TOFU
Diffstat (limited to 'gemini.go')
-rw-r--r--gemini.go52
1 files changed, 0 insertions, 52 deletions
diff --git a/gemini.go b/gemini.go
index 5b95b6a..ccdb5df 100644
--- a/gemini.go
+++ b/gemini.go
@@ -1,13 +1,5 @@
package gemini
-import (
- "crypto/x509"
- "errors"
- "log"
- "os"
- "path/filepath"
-)
-
// Status codes.
const (
StatusInput = 10
@@ -43,47 +35,3 @@ const (
var (
crlf = []byte("\r\n")
)
-
-// TOFUClient is a client that implements Trust-On-First-Use.
-type TOFUClient struct {
- // Trusts, if not nil, will be called to determine whether the client should
- // trust the provided certificate.
- Trusts func(cert *x509.Certificate, req *Request) bool
-}
-
-func (t *TOFUClient) VerifyCertificate(cert *x509.Certificate, req *Request) error {
- if knownHosts.Has(req.URL.Host, cert) {
- return nil
- }
- if t.Trusts != nil && t.Trusts(cert, req) {
- host := NewKnownHost(cert)
- knownHosts = append(knownHosts, host)
- knownHostsFile, err := os.OpenFile(knownHostsPath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
- if err != nil {
- log.Print(err)
- }
- if _, err := host.Write(knownHostsFile); err != nil {
- log.Print(err)
- }
- return nil
- }
- return errors.New("gemini: certificate not trusted")
-}
-
-var (
- knownHosts KnownHosts
- knownHostsPath string
- knownHostsFile *os.File
-)
-
-func init() {
- configDir, err := os.UserConfigDir()
- knownHostsPath = filepath.Join(configDir, "gemini")
- os.MkdirAll(knownHostsPath, 0755)
- knownHostsPath = filepath.Join(knownHostsPath, "known_hosts")
- knownHostsFile, err = os.OpenFile(knownHostsPath, os.O_CREATE|os.O_RDONLY, 0644)
- if err != nil {
- return
- }
- knownHosts = ParseKnownHosts(knownHostsFile)
-}