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",
|
||||
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{
|
||||
Name: "keystore",
|
||||
Value: filepath.Join(node.DefaultDataDir(), "keystore"),
|
||||
|
|
@ -196,6 +200,7 @@ The delpw command removes a password for a given address (keyfile).
|
|||
logLevelFlag,
|
||||
keystoreFlag,
|
||||
utils.LightKDFFlag,
|
||||
acceptFlag,
|
||||
},
|
||||
Description: `
|
||||
The newaccount command creates a new keystore-backed account. It is a convenience-method
|
||||
|
|
@ -235,6 +240,7 @@ func init() {
|
|||
stdiouiFlag,
|
||||
testFlag,
|
||||
advancedMode,
|
||||
acceptFlag,
|
||||
}
|
||||
app.Action = signer
|
||||
app.Commands = []cli.Command{initCommand,
|
||||
|
|
@ -433,8 +439,10 @@ func initialize(c *cli.Context) error {
|
|||
if c.GlobalBool(stdiouiFlag.Name) {
|
||||
logOutput = os.Stderr
|
||||
// If using the stdioui, we can't do the 'confirm'-flow
|
||||
if !c.GlobalBool(acceptFlag.Name){
|
||||
fmt.Fprint(logOutput, legalWarning)
|
||||
} else {
|
||||
}
|
||||
} else if !c.GlobalBool(acceptFlag.Name){
|
||||
if !confirm(legalWarning) {
|
||||
return fmt.Errorf("aborted by user")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@ import (
|
|||
"sync"
|
||||
|
||||
"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/log"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
)
|
||||
|
||||
type CommandlineUI struct {
|
||||
|
|
@ -61,17 +61,16 @@ func (ui *CommandlineUI) readString() string {
|
|||
func (ui *CommandlineUI) OnInputRequired(info UserInputRequest) (UserInputResponse, error) {
|
||||
|
||||
fmt.Printf("## %s\n\n%s\n", info.Title, info.Prompt)
|
||||
defer fmt.Println("-----------------------")
|
||||
if info.IsPassword {
|
||||
fmt.Printf("> ")
|
||||
text, err := terminal.ReadPassword(int(os.Stdin.Fd()))
|
||||
text, err := console.Stdin.PromptPassword("> ")
|
||||
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{string(text)}, err
|
||||
return UserInputResponse{text}, nil
|
||||
}
|
||||
text := ui.readString()
|
||||
fmt.Println("-----------------------")
|
||||
return UserInputResponse{text}, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue