diff --git a/cmd/config.go b/cmd/config.go index f748181e53a..74121f982ca 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -15,8 +15,8 @@ import ( "github.com/cozy/cozy-stack/pkg/crypto" "github.com/cozy/cozy-stack/pkg/keyring" "github.com/cozy/cozy-stack/pkg/utils" - "github.com/howeyc/gopass" "github.com/spf13/cobra" + "golang.org/x/term" ) var configCmdGroup = &cobra.Command{ @@ -30,9 +30,13 @@ var adminPasswdCmd = &cobra.Command{ Aliases: []string{"password", "passphrase", "pass"}, Short: "Generate an admin passphrase", Long: ` -cozy-stack instances passphrase generate a passphrase hash and save it to the specified file. If no file is specified, it is directly printed in standard output. This passphrase is the one used to authenticate accesses to the administration API. +cozy-stack config passwd generates a passphrase hash and save it to the +specified file. If no file is specified, it is directly printed in standard +output. This passphrase is the one used to authenticate accesses to the +administration API. -The environment variable 'COZY_ADMIN_PASSPHRASE' can be used to pass the passphrase if needed. +The environment variable 'COZY_ADMIN_PASSPHRASE' can be used to pass the +passphrase if needed. `, Example: "$ cozy-stack config passwd ~/.cozy/cozy-admin-passphrase", RunE: func(cmd *cobra.Command, args []string) error { @@ -55,13 +59,15 @@ The environment variable 'COZY_ADMIN_PASSPHRASE' can be used to pass the passphr passphrase := []byte(os.Getenv("COZY_ADMIN_PASSPHRASE")) if len(passphrase) == 0 { errPrintf("Passphrase: ") - pass1, err := gopass.GetPasswdPrompt("", false, os.Stdin, os.Stderr) + pass1, err := term.ReadPassword(int(os.Stdin.Fd())) + errPrintfln("") if err != nil { return err } errPrintf("Confirmation: ") - pass2, err := gopass.GetPasswdPrompt("", false, os.Stdin, os.Stderr) + pass2, err := term.ReadPassword(int(os.Stdin.Fd())) + errPrintfln("") if err != nil { return err } diff --git a/cmd/root.go b/cmd/root.go index 720ab5558fa..8373334c235 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -14,9 +14,9 @@ import ( "github.com/cozy/cozy-stack/pkg/config/config" "github.com/cozy/cozy-stack/pkg/consts" "github.com/cozy/cozy-stack/pkg/tlsclient" - "github.com/howeyc/gopass" "github.com/spf13/cobra" "github.com/spf13/viper" + "golang.org/x/term" ) // DefaultStorageDir is the default directory name in which data @@ -101,7 +101,8 @@ func newAdminClient() *client.AdminClient { if len(pass) == 0 { var err error fmt.Fprintf(os.Stdout, "Password:") - pass, err = gopass.GetPasswdMasked() + pass, err = term.ReadPassword(int(os.Stdin.Fd())) + fmt.Fprintln(os.Stdout, "") if err != nil { errFatalf("Could not get password from standard input: %s\n", err) } diff --git a/docs/cli/cozy-stack_config_passwd.md b/docs/cli/cozy-stack_config_passwd.md index 38a23a0cabd..5c2e67ebb3b 100644 --- a/docs/cli/cozy-stack_config_passwd.md +++ b/docs/cli/cozy-stack_config_passwd.md @@ -5,9 +5,13 @@ Generate an admin passphrase ### Synopsis -cozy-stack instances passphrase generate a passphrase hash and save it to the specified file. If no file is specified, it is directly printed in standard output. This passphrase is the one used to authenticate accesses to the administration API. +cozy-stack config passwd generates a passphrase hash and save it to the +specified file. If no file is specified, it is directly printed in standard +output. This passphrase is the one used to authenticate accesses to the +administration API. -The environment variable 'COZY_ADMIN_PASSPHRASE' can be used to pass the passphrase if needed. +The environment variable 'COZY_ADMIN_PASSPHRASE' can be used to pass the +passphrase if needed. ``` diff --git a/go.mod b/go.mod index d4785a835e0..05eb6c3ce9f 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,6 @@ require ( github.com/h2non/filetype v1.1.3 github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/golang-lru/v2 v2.0.7 - github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef github.com/justincampbell/bigduration v0.0.0-20160531141349-e45bf03c0666 github.com/labstack/echo/v4 v4.11.2 github.com/leonelquinteros/gotext v1.5.2 @@ -51,6 +50,7 @@ require ( golang.org/x/net v0.17.0 golang.org/x/oauth2 v0.13.0 golang.org/x/sync v0.4.0 + golang.org/x/term v0.13.0 golang.org/x/text v0.13.0 ) @@ -109,7 +109,6 @@ require ( github.com/yudai/gojsondiff v1.0.0 // indirect github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect golang.org/x/sys v0.13.0 // indirect - golang.org/x/term v0.13.0 // indirect golang.org/x/time v0.3.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.31.0 // indirect diff --git a/go.sum b/go.sum index e8522fd4abb..0cef5dec4db 100644 --- a/go.sum +++ b/go.sum @@ -220,8 +220,6 @@ github.com/hashicorp/hcl v0.0.0-20170914154624-68e816d1c783/go.mod h1:oZtUIOe8dh github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f h1:7LYC+Yfkj3CTRcShK0KOL/w6iTiKyqqBA9a41Wnggw8= -github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef h1:A9HsByNhogrvm9cWb28sjiS3i7tcKCkflWFEkHfuAgM= -github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef/go.mod h1:lADxMC39cJJqL93Duh1xhAs4I2Zs8mKS89XWXFGp9cs= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=