From f785ed12fd77362c1132ea88787fbe7d49a4bd13 Mon Sep 17 00:00:00 2001 From: adnano Date: Mon, 28 Sep 2020 14:20:19 -0400 Subject: [PATCH] examples/client: Disable echo for sensitive input --- examples/cert/cert.go | 2 +- examples/client/client.go | 18 ++++++++++++++---- gemini_test.go | 2 +- go.mod | 2 ++ go.sum | 8 ++++++++ 5 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 go.sum diff --git a/examples/cert/cert.go b/examples/cert/cert.go index b9a284f..f8b872b 100644 --- a/examples/cert/cert.go +++ b/examples/cert/cert.go @@ -6,7 +6,7 @@ import ( "log" "time" - gmi "git.sr.ht/~adnano/go-gemini" + "git.sr.ht/~adnano/go-gemini" ) func main() { diff --git a/examples/client/client.go b/examples/client/client.go index 15f6dd2..5582597 100644 --- a/examples/client/client.go +++ b/examples/client/client.go @@ -8,9 +8,11 @@ import ( "crypto/x509" "fmt" "os" + "syscall" "time" - gmi "git.sr.ht/~adnano/go-gemini" + "git.sr.ht/~adnano/go-gemini" + "golang.org/x/crypto/ssh/terminal" ) var ( @@ -76,8 +78,16 @@ func sendRequest(req *gmi.Request) error { switch resp.Status / 10 { case gmi.StatusClassInput: fmt.Printf("%s: ", resp.Meta) - scanner.Scan() - req.URL.RawQuery = scanner.Text() + if resp.Status == gmi.StatusSensitiveInput { + input, err := terminal.ReadPassword(int(syscall.Stdin)) + if err != nil { + return err + } + req.URL.RawQuery = string(input) + } else { + scanner.Scan() + req.URL.RawQuery = scanner.Text() + } return sendRequest(req) case gmi.StatusClassSuccess: fmt.Print(string(resp.Body)) @@ -135,7 +145,7 @@ func trustCertificate(cert *x509.Certificate) trust { func main() { if len(os.Args) < 2 { - fmt.Println("usage: %s gemini://...", os.Args[0]) + fmt.Printf("usage: %s gemini://...", os.Args[0]) os.Exit(1) } diff --git a/gemini_test.go b/gemini_test.go index b92792b..97a30fd 100644 --- a/gemini_test.go +++ b/gemini_test.go @@ -32,7 +32,7 @@ func TestServeMuxEntryOrder(t *testing.T) { for _, s := range a { mux.Handle(s, nil) } - for i, e := range mux.entries { + for i, e := range mux.es { s := e.u.String() if s != expected[i] { t.Errorf("wrong order of mux entries: expected %s, got %s", expected[i], s) diff --git a/go.mod b/go.mod index f850117..a17559e 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module git.sr.ht/~adnano/go-gemini go 1.15 + +require golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..8d6f332 --- /dev/null +++ b/go.sum @@ -0,0 +1,8 @@ +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM= +golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=