diff --git a/electrum/commands.py b/electrum/commands.py index dca66ed7e..021041b77 100644 --- a/electrum/commands.py +++ b/electrum/commands.py @@ -397,10 +397,19 @@ class Commands(Logger): def _setconfig(self, key, value): value = self._setconfig_normalize_value(key, value) - if self.daemon and key == SimpleConfig.RPC_USERNAME.key(): - self.daemon.commands_server.rpc_user = value - if self.daemon and key == SimpleConfig.RPC_PASSWORD.key(): - self.daemon.commands_server.rpc_password = value + if self.daemon and key in ( + SimpleConfig.RPC_USERNAME.key(), + SimpleConfig.RPC_PASSWORD.key(), + SimpleConfig.RPC_HOST.key(), + SimpleConfig.RPC_PORT.key(), + SimpleConfig.RPC_SOCKET_TYPE.key(), + SimpleConfig.RPC_SOCKET_FILEPATH.key(), + ): + raise UserFacingException( + "error: RPC server settings cannot be changed for already running daemon. " + "Stop the daemon first, and run 'setconfig' in --offline mode. " + "\nFor example: '$ electrum -o setconfig rpcport 7777'." + ) if Plugins.is_plugin_enabler_config_key(key): self.config.set_key(key, value) else: diff --git a/electrum/daemon.py b/electrum/daemon.py index 818b32786..ceab53cf3 100644 --- a/electrum/daemon.py +++ b/electrum/daemon.py @@ -180,6 +180,7 @@ def wait_until_daemon_becomes_ready(*, config: SimpleConfig, timeout=5) -> bool: def get_rpc_credentials(config: SimpleConfig) -> Tuple[str, str]: rpc_user = config.RPC_USERNAME or None rpc_password = config.RPC_PASSWORD or None + # note: we explicitly forbid empty/unset password, and will generate one now instead if rpc_user is None or rpc_password is None: rpc_user = 'user' bits = 128 @@ -219,9 +220,8 @@ class AuthenticatedServer(Logger): self._methods[name] = f async def authenticate(self, headers): - if self.rpc_password == '': - # RPC authentication is disabled - return + if not self.rpc_password: + raise Exception('Server RPC password is unset. This should not happen.') auth_string = headers.get('Authorization', None) if auth_string is None: raise AuthenticationInvalidOrMissing('CredentialsMissing')