Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

daemon: store wallet password in memory when wallet is loaded #8612

Closed
ecdsa opened this issue Sep 14, 2023 · 0 comments
Closed

daemon: store wallet password in memory when wallet is loaded #8612

ecdsa opened this issue Sep 14, 2023 · 0 comments
Milestone

Comments

@ecdsa
Copy link
Member

ecdsa commented Sep 14, 2023

A daemon may need to perform transactions without receiving a command. Currently, the swapserver plugin requires the keystore to be unencrypted, see https://github.com/spesmilo/electrum/blob/master/electrum/submarine_swaps.py#L392. Another reason to store passwords in memory is anchor outputs #7509.

Note that the QML gui has been storing passwords as a field of qewallet. We should probably move that to a class that is not GUI-specific, such as wallet or to daemon.

Here is a small diff that stores passwords in the wallet object, and makes the CLI work without passing the password on each command.

index 326f86a1e..276c90237 100644
--- a/electrum/commands.py
+++ b/electrum/commands.py
@@ -146,6 +146,8 @@ def command(s):
                         if wallet is None:
                             raise Exception('wallet not loaded')
                         kwargs['wallet'] = wallet
+                if cmd.requires_password and password is None:
+                    kwargs['password'] = wallet.password
             wallet = kwargs.get('wallet')  # type: Optional[Abstract_Wallet]
             if cmd.requires_wallet and not wallet:
                 raise Exception('wallet not loaded')
diff --git a/electrum/daemon.py b/electrum/daemon.py
index 553b2a0ef..508381183 100644
--- a/electrum/daemon.py
+++ b/electrum/daemon.py
@@ -490,6 +490,8 @@ class Daemon(Logger):
         wallet = self._load_wallet(path, password, manual_upgrades=manual_upgrades, config=self.config)
         if wallet is None:
             return
+        wallet.check_password(password)
+        wallet.password = password
         wallet.start_network(self.network)
         self.add_wallet(wallet)
         return wallet
diff --git a/run_electrum b/run_electrum
index e8a965f40..ef9a24137 100755
--- a/run_electrum
+++ b/run_electrum
@@ -155,7 +155,7 @@ def init_cmdline(config_options, wallet_path, *, rpcserver: bool, config: 'Simpl
     # commands needing password
     if ((cmd.requires_wallet and storage.is_encrypted() and not rpcserver)
             or (cmdname == 'load_wallet' and storage.is_encrypted())
-            or cmd.requires_password):
+            or (cmd.requires_password and not rpcserver)):
         if storage.is_encrypted_with_hw_device():
             # this case is handled later in the control flow
             password = None
@ecdsa ecdsa added this to the 4.5.0 milestone Sep 14, 2023
@ecdsa ecdsa closed this as completed in 3bc9ead Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant