From 17c12a678ff3f98139b63c58cbeae542623b7435 Mon Sep 17 00:00:00 2001 From: Roy Lee Date: Wed, 28 Sep 2022 15:16:15 -0700 Subject: [PATCH] wallet: remove public passphrase prompt 1. Remove passphrase support for public keys. 2. Rename privPassphrase to passphrase to avoid confusion. Note: There has been a bug in the prompt, which prevents users from specifying a custom public passphrase. So, most wallet databases have been using the default password for the public keys, anyway. --- cmd/sweepaccount/main.go | 8 +- config.go | 1 - internal/prompt/prompt.go | 71 ++------ internal/prompt/prompt_js.go | 30 ---- lbcwallet.go | 2 +- rpc/legacyrpc/methods.go | 2 +- waddrmgr/common_test.go | 10 +- waddrmgr/db.go | 2 +- waddrmgr/manager.go | 307 +++++++++++++++-------------------- waddrmgr/manager_test.go | 140 +++++----------- wallet/example_test.go | 7 +- wallet/loader.go | 46 +++--- wallet/wallet.go | 110 ++----------- walletsetup.go | 20 +-- 14 files changed, 243 insertions(+), 513 deletions(-) delete mode 100644 internal/prompt/prompt_js.go diff --git a/cmd/sweepaccount/main.go b/cmd/sweepaccount/main.go index 1828697..f38c9ce 100644 --- a/cmd/sweepaccount/main.go +++ b/cmd/sweepaccount/main.go @@ -266,11 +266,11 @@ func sweep() error { sourceOutputs[unspentOutput.Address] = append(sourceAddressOutputs, unspentOutput) } - var privatePassphrase string + var passphrase string if len(sourceOutputs) != 0 { - privatePassphrase, err = promptSecret("Wallet private passphrase") + passphrase, err = promptSecret("Wallet passphrase") if err != nil { - return errContext(err, "failed to read private passphrase") + return errContext(err, "failed to read passphrase") } } @@ -294,7 +294,7 @@ func sweep() error { } // Unlock the wallet, sign the transaction, and immediately lock. - err = rpcClient.WalletPassphrase(privatePassphrase, 60) + err = rpcClient.WalletPassphrase(passphrase, 60) if err != nil { reportError("Failed to unlock wallet: %v", err) continue diff --git a/config.go b/config.go index 6be1abb..9feeb15 100644 --- a/config.go +++ b/config.go @@ -265,7 +265,6 @@ func loadConfig() (*config, []string, error) { ConfigFile: cfgutil.NewExplicitString(defaultConfigFile), AppDataDir: cfgutil.NewExplicitString(defaultAppDataDir), LogDir: defaultLogDir, - WalletPass: wallet.InsecurePubPassphrase, CAFile: cfgutil.NewExplicitString(""), RPCKey: cfgutil.NewExplicitString(defaultRPCKeyFile), RPCCert: cfgutil.NewExplicitString(defaultRPCCertFile), diff --git a/internal/prompt/prompt.go b/internal/prompt/prompt.go index f2cd035..05a5231 100644 --- a/internal/prompt/prompt.go +++ b/internal/prompt/prompt.go @@ -52,10 +52,10 @@ func provideSeed(reader *bufio.Reader) ([]byte, error) { } } -// ProvidePrivPassphrase is used to prompt for the private passphrase which -// maybe required during upgrades. -func ProvidePrivPassphrase() ([]byte, error) { - prompt := "Enter the private passphrase of your wallet: " +// ProvidePassphrase is used to prompt for the passphrase which maybe required +// during upgrades. +func ProvidePassphrase() ([]byte, error) { + prompt := "Enter the passphrase of your wallet: " for { fmt.Print(prompt) pass, err := terminal.ReadPassword(int(os.Stdin.Fd())) @@ -147,10 +147,10 @@ func promptUnixTimestamp(reader *bufio.Reader, prefix string, } } -// promptPass prompts the user for a passphrase with the given prefix. The -// function will ask the user to confirm the passphrase and will repeat the -// prompts until they enter a matching response. -func promptPass(_ *bufio.Reader, prefix string, confirm bool) ([]byte, error) { +// promptPassphrase prompts the user for a passphrase with the given prefix. +// The function will ask the user to confirm the passphrase and will repeat +// the prompts until they enter a matching response. +func promptPassphrase(_ *bufio.Reader, prefix string, confirm bool) ([]byte, error) { // Prompt the user until they enter a passphrase. prompt := fmt.Sprintf("%s: ", prefix) for { @@ -191,56 +191,11 @@ func birthday(reader *bufio.Reader) (time.Time, error) { return promptUnixTimestamp(reader, prompt, "0") } -// PrivatePass prompts the user for a private passphrase. The user is prompted -// for a new private passphrase. All prompts are repeated until the user -// enters a valid response. -func PrivatePass(reader *bufio.Reader) ([]byte, error) { - return promptPass(reader, "Enter the private "+ - "passphrase for your new wallet", true) -} - -// PublicPass prompts the user whether they want to add an additional layer of -// encryption to the wallet. When the user answers yes and there is already a -// public passphrase provided via the passed config, it prompts them whether or -// not to use that configured passphrase. It will also detect when the same -// passphrase is used for the private and public passphrase and prompt the user -// if they are sure they want to use the same passphrase for both. Finally, all -// prompts are repeated until the user enters a valid response. -func PublicPass(reader *bufio.Reader, privPass []byte, - defaultPubPassphrase, configPubPassphrase []byte) ([]byte, error) { - - pubPass := defaultPubPassphrase - usePubPass, err := promptListBool(reader, "Do you want "+ - "to add an additional layer of encryption for public "+ - "data?", "no") - if err != nil { - return nil, err - } - - if !usePubPass { - return pubPass, nil - } - - if !bytes.Equal(configPubPassphrase, pubPass) { - useExisting, err := promptListBool(reader, "Use the "+ - "existing configured public passphrase for encryption "+ - "of public data?", "no") - if err != nil { - return nil, err - } - - if useExisting { - return configPubPassphrase, nil - } - } - pubPass, err = provideSeed(reader) - if err != nil { - return nil, err - } - - fmt.Println("NOTE: Use the --walletpass option to configure your " + - "public passphrase.") - return pubPass, nil +// Passphrase prompts the user for a passphrase. +// All prompts are repeated until the user enters a valid response. +func Passphrase(reader *bufio.Reader) ([]byte, error) { + return promptPassphrase(reader, "Enter the passphrase "+ + "for your new wallet", true) } // Seed prompts the user whether they want to use an existing wallet generation diff --git a/internal/prompt/prompt_js.go b/internal/prompt/prompt_js.go deleted file mode 100644 index c41a5dd..0000000 --- a/internal/prompt/prompt_js.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2015-2021 The btcsuite developers -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -package prompt - -import ( - "bufio" - "fmt" -) - -func ProvideSeed() ([]byte, error) { - return nil, fmt.Errorf("prompt not supported in WebAssembly") -} - -func ProvidePrivPassphrase() ([]byte, error) { - return nil, fmt.Errorf("prompt not supported in WebAssembly") -} - -func PrivatePass(_ *bufio.Reader) ([]byte, error) { - return nil, fmt.Errorf("prompt not supported in WebAssembly") -} - -func PublicPass(_ *bufio.Reader, _, _, _ []byte) ([]byte, error) { - return nil, fmt.Errorf("prompt not supported in WebAssembly") -} - -func Seed(_ *bufio.Reader) ([]byte, error) { - return nil, fmt.Errorf("prompt not supported in WebAssembly") -} diff --git a/lbcwallet.go b/lbcwallet.go index 71f0520..f0bc625 100644 --- a/lbcwallet.go +++ b/lbcwallet.go @@ -94,7 +94,7 @@ func walletMain() error { if !cfg.NoInitialLoad { // Load the wallet database. It must have been created already // or this will return an appropriate error. - _, err = loader.OpenExistingWallet([]byte(cfg.WalletPass), true) + _, err = loader.OpenExistingWallet(true) if err != nil { log.Error(err) return err diff --git a/rpc/legacyrpc/methods.go b/rpc/legacyrpc/methods.go index 025adf2..7ebbc02 100644 --- a/rpc/legacyrpc/methods.go +++ b/rpc/legacyrpc/methods.go @@ -2154,7 +2154,7 @@ func walletPassphrase(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func walletPassphraseChange(icmd interface{}, w *wallet.Wallet) (interface{}, error) { cmd := icmd.(*btcjson.WalletPassphraseChangeCmd) - err := w.ChangePrivatePassphrase([]byte(cmd.OldPassphrase), + err := w.ChangePassphrase([]byte(cmd.OldPassphrase), []byte(cmd.NewPassphrase)) if waddrmgr.IsError(err, waddrmgr.ErrWrongPassphrase) { return nil, &btcjson.RPCError{ diff --git a/waddrmgr/common_test.go b/waddrmgr/common_test.go index 46ea496..2576c6e 100644 --- a/waddrmgr/common_test.go +++ b/waddrmgr/common_test.go @@ -29,9 +29,7 @@ var ( rootKey, _ = hdkeychain.NewMaster(seed, &chaincfg.MainNetParams) - pubPassphrase = []byte("_DJr{fL4H0O}*-0\n:V1izc)(6BomK") - privPassphrase = []byte("81lUHXnOMZ@?XXd7O9xyDIWIbXX-lj") - pubPassphrase2 = []byte("-0NV4P~VSJBWbunw}%