1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-29 19:08:12 +00:00

tools: fix bug in vheader processing in binctl

This commit is contained in:
Pavol Rusnak 2018-02-24 21:28:18 +01:00
parent 300016cc92
commit c53b0afd5b
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -182,6 +182,7 @@ class VendorHeader(object):
self.vsig_n, \ self.vsig_n, \
self.vtrust = header self.vtrust = header
assert self.magic == b'TRZV' assert self.magic == b'TRZV'
data = data[:self.hdrlen] # strip remaining data (firmware)
assert self.vsig_m > 0 and self.vsig_m <= self.vsig_n assert self.vsig_m > 0 and self.vsig_m <= self.vsig_n
assert self.vsig_n > 0 and self.vsig_n <= 8 assert self.vsig_n > 0 and self.vsig_n <= 8
p = 32 p = 32
@ -277,6 +278,7 @@ def binopen(filename):
vheader = VendorHeader(data) vheader = VendorHeader(data)
if len(data) == vheader.hdrlen: if len(data) == vheader.hdrlen:
return vheader return vheader
vheader.print()
subdata = data[vheader.hdrlen:] subdata = data[vheader.hdrlen:]
if subdata[:4] == b'TRZF': if subdata[:4] == b'TRZF':
firmware = FirmwareImage(data, vheader.hdrlen) firmware = FirmwareImage(data, vheader.hdrlen)
@ -316,7 +318,6 @@ def main():
sigmask = 1 << (int(sys.argv[3]) - 1) sigmask = 1 << (int(sys.argv[3]) - 1)
signature = binascii.unhexlify(sys.argv[4]) signature = binascii.unhexlify(sys.argv[4])
b.sign(sigmask, signature) b.sign(sigmask, signature)
print()
b.write(fn) b.write(fn)
if rehash: if rehash:
b.update_hashes() b.update_hashes()