diff options
author | Kurkó Mihály <kurkomisi@users.noreply.github.com> | 2019-05-07 20:49:51 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2019-05-07 20:49:51 +0800 |
commit | 107c67d74ebfee16616bac92d0c39c8bfc9348ae (patch) | |
tree | 82588f987ee8a345183e03aa2403e1c5cf9695ed | |
parent | c8cf360f29f00d16aacf9a0592dd3621efef0d41 (diff) | |
download | go-tangerine-107c67d74ebfee16616bac92d0c39c8bfc9348ae.tar go-tangerine-107c67d74ebfee16616bac92d0c39c8bfc9348ae.tar.gz go-tangerine-107c67d74ebfee16616bac92d0c39c8bfc9348ae.tar.bz2 go-tangerine-107c67d74ebfee16616bac92d0c39c8bfc9348ae.tar.lz go-tangerine-107c67d74ebfee16616bac92d0c39c8bfc9348ae.tar.xz go-tangerine-107c67d74ebfee16616bac92d0c39c8bfc9348ae.tar.zst go-tangerine-107c67d74ebfee16616bac92d0c39c8bfc9348ae.zip |
accounts, cmd, internal, signer: add note about backing up the keystore (#19432)
* accounts: add note about backing up the keystore
* cmd, accounts: move the printout to accountCreate
* internal, signer: add info when new account is created via rpc
* cmd, internal, signer: split logs
* cmd/geth: make account new output a bit more verbose
-rw-r--r-- | accounts/keystore/passphrase.go | 5 | ||||
-rw-r--r-- | cmd/geth/accountcmd.go | 10 | ||||
-rw-r--r-- | cmd/geth/accountcmd_test.go | 12 | ||||
-rw-r--r-- | internal/ethapi/api.go | 3 | ||||
-rw-r--r-- | signer/core/api.go | 3 |
5 files changed, 28 insertions, 5 deletions
diff --git a/accounts/keystore/passphrase.go b/accounts/keystore/passphrase.go index a0b6cf538..1ced41e99 100644 --- a/accounts/keystore/passphrase.go +++ b/accounts/keystore/passphrase.go @@ -38,6 +38,7 @@ import ( "os" "path/filepath" + "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/crypto" @@ -97,9 +98,9 @@ func (ks keyStorePassphrase) GetKey(addr common.Address, filename, auth string) } // StoreKey generates a key, encrypts with 'auth' and stores in the given directory -func StoreKey(dir, auth string, scryptN, scryptP int) (common.Address, error) { +func StoreKey(dir, auth string, scryptN, scryptP int) (accounts.Account, error) { _, a, err := storeNewKey(&keyStorePassphrase{dir, scryptN, scryptP, false}, rand.Reader, auth) - return a.Address, err + return a, err } func (ks keyStorePassphrase) StoreKey(filename string, key *Key, auth string) error { diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go index 940290899..8fd149cac 100644 --- a/cmd/geth/accountcmd.go +++ b/cmd/geth/accountcmd.go @@ -307,12 +307,18 @@ func accountCreate(ctx *cli.Context) error { password := getPassPhrase("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx)) - address, err := keystore.StoreKey(keydir, password, scryptN, scryptP) + account, err := keystore.StoreKey(keydir, password, scryptN, scryptP) if err != nil { utils.Fatalf("Failed to create account: %v", err) } - fmt.Printf("Address: {%x}\n", address) + fmt.Printf("\nYour new key was generated\n\n") + fmt.Printf("Public address of the key: %s\n", account.Address.Hex()) + fmt.Printf("Path of the secret key file: %s\n\n", account.URL.Path) + fmt.Printf("- You can share your public address with anyone. Others need it to interact with you.\n") + fmt.Printf("- You must NEVER share the secret key with anyone! The key controls access to your funds!\n") + fmt.Printf("- You must BACKUP your key file! Without the key, it's impossible to access account funds!\n") + fmt.Printf("- You must REMEMBER your password! Without the password, it's impossible to decrypt the key!\n\n") return nil } diff --git a/cmd/geth/accountcmd_test.go b/cmd/geth/accountcmd_test.go index 3ea22ccfa..6c97f0ddc 100644 --- a/cmd/geth/accountcmd_test.go +++ b/cmd/geth/accountcmd_test.go @@ -74,8 +74,18 @@ Your new account is locked with a password. Please give a password. Do not forge !! Unsupported terminal, password will be echoed. Passphrase: {{.InputLine "foobar"}} Repeat passphrase: {{.InputLine "foobar"}} + +Your new key was generated +`) + geth.ExpectRegexp(` +Public address of the key: 0x[0-9a-fA-F]{40} +Path of the secret key file: .*UTC--.+--[0-9a-f]{40} + +- You can share your public address with anyone. Others need it to interact with you. +- You must NEVER share the secret key with anyone! The key controls access to your funds! +- You must BACKUP your key file! Without the key, it's impossible to access account funds! +- You must REMEMBER your password! Without the password, it's impossible to decrypt the key! `) - geth.ExpectRegexp(`Address: \{[0-9a-f]{40}\}\n`) } func TestAccountNewBadRepeat(t *testing.T) { diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 3c18ea709..e918df9bb 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -295,6 +295,9 @@ func (s *PrivateAccountAPI) DeriveAccount(url string, path string, pin *bool) (a func (s *PrivateAccountAPI) NewAccount(password string) (common.Address, error) { acc, err := fetchKeystore(s.am).NewAccount(password) if err == nil { + log.Info("Your new key was generated", "address", acc.Address) + log.Warn("Please backup your key file!", "path", acc.URL.Path) + log.Warn("Please remember your password!") return acc.Address, nil } return common.Address{}, err diff --git a/signer/core/api.go b/signer/core/api.go index 671fbf79b..783aaece4 100644 --- a/signer/core/api.go +++ b/signer/core/api.go @@ -392,6 +392,9 @@ func (api *SignerAPI) New(ctx context.Context) (common.Address, error) { } else { // No error acc, err := be[0].(*keystore.KeyStore).NewAccount(resp.Text) + log.Info("Your new key was generated", "address", acc.Address) + log.Warn("Please backup your key file!", "path", acc.URL.Path) + log.Warn("Please remember your password!") return acc.Address, err } } |