1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-18 05:28:40 +00:00

add new firmware update method, update protobuf

This commit is contained in:
Pavol Rusnak 2017-04-12 14:11:42 +02:00
parent dccc1b08ed
commit 29348f4098
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 316 additions and 160 deletions

View File

@ -956,17 +956,34 @@ class ProtocolMixin(object):
return False
data = fp.read()
fingerprint = hashlib.sha256(data[256:]).hexdigest()
log("Firmware fingerprint: " + fingerprint)
resp = self.call(proto.FirmwareUpload(payload=data))
# TREZORv1 method
if isinstance(resp, proto.Success):
return True
fingerprint = hashlib.sha256(data[256:]).hexdigest()
log("Firmware fingerprint: " + fingerprint)
resp = self.call(proto.FirmwareUpload(payload=data))
if isinstance(resp, proto.Success):
return True
elif isinstance(resp, proto.Failure) and resp.code == types.Failure_FirmwareError:
return False
raise Exception("Unexpected result %s" % resp)
elif isinstance(resp, proto.Failure) and resp.code == types.Failure_FirmwareError:
return False
# TREZORv2 method
if isinstance(resp, proto.FirmwareRequest):
import pyblake2
while True:
payload = data[resp.offset:resp.offset + resp.length]
digest = pyblake2.blake2s(payload).digest()
resp = self.call(proto.FirmwareUpload(payload=payload, hash=digest))
if isinstance(resp, proto.FirmwareRequest):
continue
elif isinstance(resp, proto.Success):
return True
elif isinstance(resp, proto.Failure) and resp.code == types.Failure_FirmwareError:
return False
raise Exception("Unexpected result %s" % resp)
raise Exception("Unexpected result %s" % resp)
raise Exception("Unexpected message %s" % resp)
class TrezorClient(ProtocolMixin, TextUIMixin, BaseClient):
pass

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long