From a9b677bcd468e5859b01af6e576c9832bf152ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ram=C3=ADrez?= Date: Mon, 9 Apr 2018 08:57:47 +0200 Subject: [PATCH 1/2] Hide passwords during input, unescape characters before sending --- main.go | 7 ++++++- registry/registry.go | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 670d02d..bbabd47 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "github.com/mlabouardy/nexus-cli/registry" "github.com/urfave/cli" + "golang.org/x/crypto/ssh/terminal" ) const ( @@ -111,7 +112,11 @@ func setNexusCredentials(c *cli.Context) error { fmt.Print("Enter Nexus Username: ") fmt.Scan(&username) fmt.Print("Enter Nexus Password: ") - fmt.Scan(&password) + bytePassword, err := terminal.ReadPassword(0) + if err != nil { + return fmt.Errorf("Could not read password from terminal: %v", err) + } + password = string(bytePassword) data := struct { Host string diff --git a/registry/registry.go b/registry/registry.go index 03a4826..5366376 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "html" "net/http" "os" @@ -51,6 +52,7 @@ func NewRegistry() (Registry, error) { if _, err := toml.DecodeFile(".credentials", &r); err != nil { return r, err } + r.Password = html.UnescapeString(r.Password) return r, nil } From 5ad224b02ee9e7161eef3f01eb02c469608f96ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ram=C3=ADrez?= Date: Mon, 9 Apr 2018 08:59:40 +0200 Subject: [PATCH 2/2] don't assume stdin handler --- main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index bbabd47..ced1b08 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "fmt" "html/template" "os" + "syscall" "github.com/mlabouardy/nexus-cli/registry" "github.com/urfave/cli" @@ -112,7 +113,7 @@ func setNexusCredentials(c *cli.Context) error { fmt.Print("Enter Nexus Username: ") fmt.Scan(&username) fmt.Print("Enter Nexus Password: ") - bytePassword, err := terminal.ReadPassword(0) + bytePassword, err := terminal.ReadPassword(int(syscall.Stdin)) if err != nil { return fmt.Errorf("Could not read password from terminal: %v", err) }