]> Sergey Matveev's repositories - tofuproxy.git/blobdiff - httpauth.go
Yet another restyling
[tofuproxy.git] / httpauth.go
index 5b454cacb64d495d8bc49c1d1924f9ef4d45e250..d62d0fc91674b0542e5f849cda733fe1905f315b 100644 (file)
@@ -1,7 +1,7 @@
 /*
 tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
              manager, WARC/geminispace browser
-Copyright (C) 2021 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2021-2022 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
@@ -22,45 +22,12 @@ import (
        "bytes"
        "errors"
        "fmt"
-       "io/ioutil"
-       "log"
-       "os"
        "os/exec"
-       "path/filepath"
        "strings"
 
        ttls "go.stargrave.org/tofuproxy/tls"
 )
 
-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
-}
-
 func authDialog(host, realm string) (string, string, error) {
        var b bytes.Buffer
        userInit, passInit := findInNetrc(host)