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

hot storage: ask for encryption password only if it's enabled #526

Merged
merged 2 commits into from Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/cryptoadvance/specter/devices/bitcoin_core.py
Expand Up @@ -10,6 +10,9 @@
from ..rpc import get_default_datadir
from io import BytesIO
import hmac
import logging

logger = logging.getLogger(__name__)


class BitcoinCore(Device):
Expand Down Expand Up @@ -128,12 +131,24 @@ def _load_wallet(self, wallet_manager):
loaded_wallets = wallet_manager.rpc.listwallets()

hotstorage_path = wallet_manager.rpc_path + "_hotstorage"
if (
existing_wallets is None
or os.path.join(hotstorage_path, self.alias) in existing_wallets
):
if os.path.join(hotstorage_path, self.alias) not in loaded_wallets:
wallet_manager.rpc.loadwallet(os.path.join(hotstorage_path, self.alias))
wallet_path = os.path.join(hotstorage_path, self.alias)
if existing_wallets is None or wallet_path in existing_wallets:
if wallet_path not in loaded_wallets:
wallet_manager.rpc.loadwallet(wallet_path)

def is_encrypted(self, wallet_manager):
"""Check if the wallet is encrypted"""
self._load_wallet(wallet_manager)
hotstorage_path = wallet_manager.rpc_path + "_hotstorage"
wallet_path = os.path.join(hotstorage_path, self.alias)
try:
# check if password is enabled
info = wallet_manager.rpc.getwalletinfo(wallet=wallet_path)
return "unlocked_until" in info
except Exception as e:
logger.warning("Cannot fetch hot wallet info")
# Assuming encrypted by default
return True

def create_psbts(self, base64_psbt, wallet):
return {"core": base64_psbt}
Expand Down
Expand Up @@ -73,17 +73,27 @@
});
</script>
<div id="hot_enter_passphrase" class="hidden">
<h2>Enter Passphrase</h2>
{% set is_encrypted = device.is_encrypted(wallet.manager) %}
{% if is_encrypted %}
<h2>Enter decryption password</h2>
{% else %}
<h2>Proceed with signing</h2>
{% endif %}
<form action="?" method="POST" id="hot_enter_passphrase__content" class="flex-center flex-column">
<br/>
<div>
{% if is_encrypted %}
<input name="passphrase" type="password" id="hwi_enter_passphrase__passphrase" />
{% else %}
Wallet is not encrypted, just click the button.
<input name="passphrase" type="hidden" id="hwi_enter_passphrase__passphrase" value="" />
{% endif %}
<input name="device" type="hidden" value="{{ device.alias }}" />
<input name="psbt" type="hidden" value='{{ psbt|tojson|safe }}' />
</div>
<br/>
<br/>
<button id="hot_enter_passphrase__submit" class="btn" type="submit" name="action" value="signhotwallet">Submit</button>
<button id="hot_enter_passphrase__submit" class="btn" type="submit" name="action" value="signhotwallet">Sign transaction</button>
</form>
</div>
{% endif %}
Expand Down