mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
cmd/clef, signer/core: use better terminal input for passwords, make it possible to avoid boot-up warning
This commit is contained in:
parent
c60c0c97e7
commit
9b5e232884
2 changed files with 16 additions and 9 deletions
|
|
@ -82,6 +82,10 @@ var (
|
||||||
Name: "advanced",
|
Name: "advanced",
|
||||||
Usage: "If enabled, issues warnings instead of rejections for suspicious requests. Default off",
|
Usage: "If enabled, issues warnings instead of rejections for suspicious requests. Default off",
|
||||||
}
|
}
|
||||||
|
acceptFlag = cli.BoolFlag{
|
||||||
|
Name: "acceptWarn",
|
||||||
|
Usage: "If set, does not show the warning during boot",
|
||||||
|
}
|
||||||
keystoreFlag = cli.StringFlag{
|
keystoreFlag = cli.StringFlag{
|
||||||
Name: "keystore",
|
Name: "keystore",
|
||||||
Value: filepath.Join(node.DefaultDataDir(), "keystore"),
|
Value: filepath.Join(node.DefaultDataDir(), "keystore"),
|
||||||
|
|
@ -196,6 +200,7 @@ The delpw command removes a password for a given address (keyfile).
|
||||||
logLevelFlag,
|
logLevelFlag,
|
||||||
keystoreFlag,
|
keystoreFlag,
|
||||||
utils.LightKDFFlag,
|
utils.LightKDFFlag,
|
||||||
|
acceptFlag,
|
||||||
},
|
},
|
||||||
Description: `
|
Description: `
|
||||||
The newaccount command creates a new keystore-backed account. It is a convenience-method
|
The newaccount command creates a new keystore-backed account. It is a convenience-method
|
||||||
|
|
@ -235,6 +240,7 @@ func init() {
|
||||||
stdiouiFlag,
|
stdiouiFlag,
|
||||||
testFlag,
|
testFlag,
|
||||||
advancedMode,
|
advancedMode,
|
||||||
|
acceptFlag,
|
||||||
}
|
}
|
||||||
app.Action = signer
|
app.Action = signer
|
||||||
app.Commands = []cli.Command{initCommand,
|
app.Commands = []cli.Command{initCommand,
|
||||||
|
|
@ -433,8 +439,10 @@ func initialize(c *cli.Context) error {
|
||||||
if c.GlobalBool(stdiouiFlag.Name) {
|
if c.GlobalBool(stdiouiFlag.Name) {
|
||||||
logOutput = os.Stderr
|
logOutput = os.Stderr
|
||||||
// If using the stdioui, we can't do the 'confirm'-flow
|
// If using the stdioui, we can't do the 'confirm'-flow
|
||||||
fmt.Fprint(logOutput, legalWarning)
|
if !c.GlobalBool(acceptFlag.Name){
|
||||||
} else {
|
fmt.Fprint(logOutput, legalWarning)
|
||||||
|
}
|
||||||
|
} else if !c.GlobalBool(acceptFlag.Name){
|
||||||
if !confirm(legalWarning) {
|
if !confirm(legalWarning) {
|
||||||
return fmt.Errorf("aborted by user")
|
return fmt.Errorf("aborted by user")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,9 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
|
"github.com/ethereum/go-ethereum/console"
|
||||||
"github.com/ethereum/go-ethereum/internal/ethapi"
|
"github.com/ethereum/go-ethereum/internal/ethapi"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"golang.org/x/crypto/ssh/terminal"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type CommandlineUI struct {
|
type CommandlineUI struct {
|
||||||
|
|
@ -61,17 +61,16 @@ func (ui *CommandlineUI) readString() string {
|
||||||
func (ui *CommandlineUI) OnInputRequired(info UserInputRequest) (UserInputResponse, error) {
|
func (ui *CommandlineUI) OnInputRequired(info UserInputRequest) (UserInputResponse, error) {
|
||||||
|
|
||||||
fmt.Printf("## %s\n\n%s\n", info.Title, info.Prompt)
|
fmt.Printf("## %s\n\n%s\n", info.Title, info.Prompt)
|
||||||
|
defer fmt.Println("-----------------------")
|
||||||
if info.IsPassword {
|
if info.IsPassword {
|
||||||
fmt.Printf("> ")
|
text, err := console.Stdin.PromptPassword("> ")
|
||||||
text, err := terminal.ReadPassword(int(os.Stdin.Fd()))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to read password", "err", err)
|
log.Error("Failed to read password", "error", err)
|
||||||
|
return UserInputResponse{}, err
|
||||||
}
|
}
|
||||||
fmt.Println("-----------------------")
|
return UserInputResponse{text}, nil
|
||||||
return UserInputResponse{string(text)}, err
|
|
||||||
}
|
}
|
||||||
text := ui.readString()
|
text := ui.readString()
|
||||||
fmt.Println("-----------------------")
|
|
||||||
return UserInputResponse{text}, nil
|
return UserInputResponse{text}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue