diff --git a/plugins/coldcard/README.md b/plugins/coldcard/README.md index 04e62ce81..edc2a813d 100644 --- a/plugins/coldcard/README.md +++ b/plugins/coldcard/README.md @@ -3,9 +3,13 @@ ## Just the glue please -- This code connects the public USB API and Electrum. Leverages all the good work that's been +This code connects the public USB API and Electrum. Leverages all the good work that's been done my the Electrum team to support hardware wallets. +## TODO Items + +- No effort yet to support translations, sorry. + ### Ctags diff --git a/plugins/coldcard/coldcard.py b/plugins/coldcard/coldcard.py index b68e39f47..6d62ac40f 100644 --- a/plugins/coldcard/coldcard.py +++ b/plugins/coldcard/coldcard.py @@ -562,9 +562,13 @@ class ColdcardPlugin(HW_PluginBase): # We are given a HID device, or at least some details about it. # Not sure why not we aren't just given a HID library handle, but # the 'path' is unabiguous, so we'll use that. - rv = CKCCClient(handler, device.path, + try: + rv = CKCCClient(handler, device.path, is_simulator=(device.product_key[1] == CKCC_SIMULATED_PID)) - return rv + return rv + except: + print_error('[coldcard]', 'late failure connecting to device?') + return None def setup_device(self, device_info, wizard, purpose): devmgr = self.device_manager() diff --git a/plugins/coldcard/qt.py b/plugins/coldcard/qt.py index 26ae70a34..bd84f9718 100644 --- a/plugins/coldcard/qt.py +++ b/plugins/coldcard/qt.py @@ -117,7 +117,7 @@ class CKCCSettingsDialog(WindowModalDialog): devmgr = plugin.device_manager() config = devmgr.config handler = keystore.handler - thread = keystore.thread + self.thread = thread = keystore.thread def connect_and_doit(): client = devmgr.client_by_id(device_id) @@ -188,10 +188,54 @@ class CKCCSettingsDialog(WindowModalDialog): def start_upgrade(self, client): # ask for a filename (must have already downloaded it) mw = get_parent_main_window(self) - fileName = mw.getOpenFileName(_("Select upgraded firmware file"), "*.dfu") + dev = client.dev + + fileName = mw.getOpenFileName("Select upgraded firmware file", "*.dfu") if not fileName: return - dfu = open(fileName, 'rb').read() + from ckcc.utils import dfu_parse + from ckcc.sigheader import FW_HEADER_SIZE, FW_HEADER_OFFSET, FW_HEADER_MAGIC + from ckcc.protocol import CCProtocolPacker + from hashlib import sha256 + import struct + try: + with open(fileName, 'rb') as fd: + + # unwrap firmware from the DFU + offset, size, *ignored = dfu_parse(fd) + + fd.seek(offset) + firmware = fd.read(size) + + hpos = FW_HEADER_OFFSET + hdr = bytes(firmware[hpos:hpos + FW_HEADER_SIZE]) # needed later too + magic = struct.unpack_from("