mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
cmd/clef: replace password arg with prompt (#17829)
This commit is contained in:
parent
f95811e65b
commit
76f36a4c67
1 changed files with 35 additions and 10 deletions
|
|
@ -37,6 +37,7 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/console"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
|
|
@ -159,15 +160,14 @@ Clef that the file is 'safe' to execute.`,
|
||||||
Action: utils.MigrateFlags(addCredential),
|
Action: utils.MigrateFlags(addCredential),
|
||||||
Name: "addpw",
|
Name: "addpw",
|
||||||
Usage: "Store a credential for a keystore file",
|
Usage: "Store a credential for a keystore file",
|
||||||
ArgsUsage: "<address> <password>",
|
ArgsUsage: "<address>",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
logLevelFlag,
|
logLevelFlag,
|
||||||
configdirFlag,
|
configdirFlag,
|
||||||
signerSecretFlag,
|
signerSecretFlag,
|
||||||
},
|
},
|
||||||
Description: `
|
Description: `
|
||||||
The addpw command stores a password for a given address (keyfile). If you invoke it with only one parameter, it will
|
The addpw command stores a password for a given address (keyfile).
|
||||||
remove any stored credential for that address (keyfile)
|
|
||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -201,6 +201,7 @@ func init() {
|
||||||
app.Commands = []cli.Command{initCommand, attestCommand, addCredentialCommand}
|
app.Commands = []cli.Command{initCommand, attestCommand, addCredentialCommand}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := app.Run(os.Args); err != nil {
|
if err := app.Run(os.Args); err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
|
@ -208,6 +209,29 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// promptPassword retrieves the password entered interactively
|
||||||
|
// from the user.
|
||||||
|
func promptPassword(prompt string, confirmation bool) string {
|
||||||
|
// Prompt the user for the password
|
||||||
|
if prompt != "" {
|
||||||
|
fmt.Println(prompt)
|
||||||
|
}
|
||||||
|
password, err := console.Stdin.PromptPassword("Password: ")
|
||||||
|
if err != nil {
|
||||||
|
utils.Fatalf("Failed to read password: %v", err)
|
||||||
|
}
|
||||||
|
if confirmation {
|
||||||
|
confirm, err := console.Stdin.PromptPassword("Repeat password: ")
|
||||||
|
if err != nil {
|
||||||
|
utils.Fatalf("Failed to read password confirmation: %v", err)
|
||||||
|
}
|
||||||
|
if password != confirm {
|
||||||
|
utils.Fatalf("Passwords do not match")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return password
|
||||||
|
}
|
||||||
|
|
||||||
func initializeSecrets(c *cli.Context) error {
|
func initializeSecrets(c *cli.Context) error {
|
||||||
if err := initialize(c); err != nil {
|
if err := initialize(c); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -247,6 +271,7 @@ NOTE: This file does not contain your accounts. Those need to be backed up separ
|
||||||
`)
|
`)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func attestFile(ctx *cli.Context) error {
|
func attestFile(ctx *cli.Context) error {
|
||||||
if len(ctx.Args()) < 1 {
|
if len(ctx.Args()) < 1 {
|
||||||
utils.Fatalf("This command requires an argument.")
|
utils.Fatalf("This command requires an argument.")
|
||||||
|
|
@ -273,8 +298,12 @@ func attestFile(ctx *cli.Context) error {
|
||||||
|
|
||||||
func addCredential(ctx *cli.Context) error {
|
func addCredential(ctx *cli.Context) error {
|
||||||
if len(ctx.Args()) < 1 {
|
if len(ctx.Args()) < 1 {
|
||||||
utils.Fatalf("This command requires at leaste one argument.")
|
utils.Fatalf("This command requires at least one argument.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prompt user to enter a password
|
||||||
|
password := promptPassword("Enter a password to store with this address.", true)
|
||||||
|
|
||||||
if err := initialize(ctx); err != nil {
|
if err := initialize(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -290,11 +319,7 @@ func addCredential(ctx *cli.Context) error {
|
||||||
// Initialize the encrypted storages
|
// Initialize the encrypted storages
|
||||||
pwStorage := storage.NewAESEncryptedStorage(filepath.Join(vaultLocation, "credentials.json"), pwkey)
|
pwStorage := storage.NewAESEncryptedStorage(filepath.Join(vaultLocation, "credentials.json"), pwkey)
|
||||||
key := ctx.Args().First()
|
key := ctx.Args().First()
|
||||||
value := ""
|
pwStorage.Put(key, password)
|
||||||
if len(ctx.Args()) > 1 {
|
|
||||||
value = ctx.Args().Get(1)
|
|
||||||
}
|
|
||||||
pwStorage.Put(key, value)
|
|
||||||
log.Info("Credential store updated", "key", key)
|
log.Info("Credential store updated", "key", key)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue