Skip to content

Commit

Permalink
Optional ENFORCE_HWI_INITIALISATION_AT_STARTUP (#2383)
Browse files Browse the repository at this point in the history
* Revert "revert removal of enumerate (#2378)"

This reverts commit 23ad119.

* Make HWI initialisation not default but enforcable
  • Loading branch information
k9ert authored Sep 20, 2023
1 parent 2c8e553 commit 8a06e9b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
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

0 comments on commit 8a06e9b

Please sign in to comment.