]> Sergey Matveev's repositories - tofuproxy.git/blobdiff - httpauth.go
Raise copyright years
[tofuproxy.git] / httpauth.go
index 79b51ecc32ca8642a118ee18932964eb2d310d36..9408d98348c44367fd6ec38f0fe25ace80b6ca43 100644 (file)
@@ -1,6 +1,7 @@
 /*
-tofuproxy -- HTTP proxy with TLS certificates management
-Copyright (C) 2021 Sergey Matveev <stargrave@stargrave.org>
+tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
+             manager, WARC/geminispace browser
+Copyright (C) 2021-2023 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -21,42 +22,11 @@ import (
        "bytes"
        "errors"
        "fmt"
-       "io/ioutil"
-       "log"
-       "os"
        "os/exec"
-       "path/filepath"
        "strings"
-)
 
-func findInNetrc(host string) (string, string) {
-       netrcPath, ok := os.LookupEnv("NETRC")
-       if !ok {
-               netrcPath = filepath.Join(os.Getenv("HOME"), ".netrc")
-       }
-       data, err := ioutil.ReadFile(netrcPath)
-       if err != nil {
-               if os.IsNotExist(err) {
-                       return "", ""
-               }
-               log.Fatalln(err)
-       }
-       var login string
-       var password string
-       for _, line := range strings.Split(string(data), "\n") {
-               if i := strings.Index(line, "#"); i >= 0 {
-                       line = line[:i]
-               }
-               f := strings.Fields(line)
-               if len(f) >= 6 &&
-                       f[0] == "machine" && f[1] == host &&
-                       f[2] == "login" && f[4] == "password" {
-                       login, password = f[3], f[5]
-                       break
-               }
-       }
-       return login, password
-}
+       ttls "go.stargrave.org/tofuproxy/tls"
+)
 
 func authDialog(host, realm string) (string, string, error) {
        var b bytes.Buffer
@@ -89,8 +59,8 @@ bind . <KeyPress> {switch -exact %%K {
     q {exit 0} ; # reject once
     l login
 }}
-`, realm, userInit, passInit))
-       cmd := exec.Command(CmdWish)
+`, strings.ReplaceAll(realm, "\"", ""), userInit, passInit))
+       cmd := exec.Command(ttls.CmdWish)
        cmd.Stdin = &b
        out, err := cmd.Output()
        if err != nil {