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

Optional ENFORCE_HWI_INITIALISATION_AT_STARTUP #2383

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/cryptoadvance/specter/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class BaseConfig(object):
CERT = os.getenv("CERT", None)
KEY = os.getenv("KEY", None)

# It might be necessary to enforce the HWI initialisation
ENFORCE_HWI_INITIALISATION_AT_STARTUP = False

# This will be used to search for a bitcoin.conf in order to enable the
# auth method "RPC password as pin"
RASPIBLITZ_SPECTER_RPC_LOGIN_BITCOIN_CONF_LOCATION = os.getenv(
Expand Down
15 changes: 9 additions & 6 deletions src/cryptoadvance/specter/hwi_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class HWIBridge(JSONRPC):
All methods of this class are callable over JSON-RPC, except _underscored.
"""

def __init__(self):
def __init__(self, enforce_hwi_initialisation=False):
self.exposed_rpc = {
"enumerate": self.enumerate,
"detect_device": self.detect_device,
Expand All @@ -81,11 +81,14 @@ def __init__(self):
"extract_master_blinding_key": self.extract_master_blinding_key,
"bitbox02_pairing": self.bitbox02_pairing,
}
# Running enumerate after beginning an interaction with a specific device
# crashes python or make HWI misbehave. For now we just get all connected
# devices once per session and save them.
logger.info("Initializing HWI...") # to explain user why it takes so long
self.enumerate()
if enforce_hwi_initialisation:
# Running enumerate after beginning an interaction with a specific device
# crashes python or make HWI misbehave. For now we just get all connected
# devices once per session and save them.
logger.info("Initializing HWI...") # to explain user why it takes so long
self.enumerate()
logger.info("Finished initializing HWI!")
self.devices = []

@locked(hwilock)
def enumerate(self, passphrase="", chain=""):
Expand Down
2 changes: 1 addition & 1 deletion src/cryptoadvance/specter/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def service_manager_cleanup_on_exit(signum, frame):
specter.initialize()

# HWI
specter.hwi = HWIBridge()
specter.hwi = HWIBridge(app.config["ENFORCE_HWI_INITIALISATION_AT_STARTUP"])

login_manager = LoginManager()
login_manager.session_protection = app.config.get("SESSION_PROTECTION", "strong")
Expand Down
Loading