mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-26 09:28:13 +00:00
tools: pass sigmask and seckey as parameter to binctl
This commit is contained in:
parent
393ead9beb
commit
62ad4d6a39
6
Makefile
6
Makefile
@ -26,7 +26,7 @@ res: ## update resources
|
|||||||
|
|
||||||
vendorheader: ## construct default vendor header
|
vendorheader: ## construct default vendor header
|
||||||
./tools/build_vendorheader 'db995fe25169d141cab9bbba92baa01f9f2e1ece7df4cb2ac05190f37fcc1f9d:2152f8d19b791d24453242e15f2eab6cb7cffa7b6a5ed30097960e069881db12:22fc297792f0b6ffc0bfcfdb7edb0c0aa14e025a365ec0e342e86e3829cb74b6' 1 0.0 SatoshiLabs assets/satoshilabs_120.toif micropython/firmware/vendorheader.bin
|
./tools/build_vendorheader 'db995fe25169d141cab9bbba92baa01f9f2e1ece7df4cb2ac05190f37fcc1f9d:2152f8d19b791d24453242e15f2eab6cb7cffa7b6a5ed30097960e069881db12:22fc297792f0b6ffc0bfcfdb7edb0c0aa14e025a365ec0e342e86e3829cb74b6' 1 0.0 SatoshiLabs assets/satoshilabs_120.toif micropython/firmware/vendorheader.bin
|
||||||
./tools/binctl micropython/firmware/vendorheader.bin -s
|
./tools/binctl micropython/firmware/vendorheader.bin -s 1 4141414141414141414141414141414141414141414141414141414141414141
|
||||||
|
|
||||||
binctl: ## print info about binary files
|
binctl: ## print info about binary files
|
||||||
./tools/binctl micropython/loader/build/loader.bin
|
./tools/binctl micropython/loader/build/loader.bin
|
||||||
@ -58,11 +58,11 @@ build_bootloader: ## build bootloader
|
|||||||
|
|
||||||
build_loader: ## build loader
|
build_loader: ## build loader
|
||||||
$(MAKE) -f Makefile.loader $(TREZORHAL_PORT_OPTS)
|
$(MAKE) -f Makefile.loader $(TREZORHAL_PORT_OPTS)
|
||||||
./tools/binctl micropython/loader/build/loader.bin -s
|
./tools/binctl micropython/loader/build/loader.bin -s 1 4141414141414141414141414141414141414141414141414141414141414141
|
||||||
|
|
||||||
build_firmware: res build_cross ## build firmware with frozen modules
|
build_firmware: res build_cross ## build firmware with frozen modules
|
||||||
$(MAKE) -f Makefile.firmware $(TREZORHAL_PORT_OPTS)
|
$(MAKE) -f Makefile.firmware $(TREZORHAL_PORT_OPTS)
|
||||||
./tools/binctl micropython/firmware/build/firmware.bin -s
|
./tools/binctl micropython/firmware/build/firmware.bin -s 1 4141414141414141414141414141414141414141414141414141414141414141
|
||||||
|
|
||||||
build_unix: ## build unix port
|
build_unix: ## build unix port
|
||||||
$(MAKE) -f ../../../micropython/unix/Makefile -C vendor/micropython/unix $(UNIX_PORT_OPTS)
|
$(MAKE) -f ../../../micropython/unix/Makefile -C vendor/micropython/unix $(UNIX_PORT_OPTS)
|
||||||
|
35
tools/binctl
35
tools/binctl
@ -6,21 +6,10 @@ import ed25519
|
|||||||
import pyblake2
|
import pyblake2
|
||||||
|
|
||||||
|
|
||||||
def get_sig(data):
|
def sign_data(seckey, data):
|
||||||
if False:
|
|
||||||
print('Enter index : ', end='')
|
|
||||||
idx = int(input())
|
|
||||||
print('Enter privkey : ', end='')
|
|
||||||
seckey = binascii.unhexlify(input())
|
|
||||||
else:
|
|
||||||
idx = 1
|
|
||||||
seckey = binascii.unhexlify('4141414141414141414141414141414141414141414141414141414141414141')
|
|
||||||
signkey = ed25519.SigningKey(seckey)
|
signkey = ed25519.SigningKey(seckey)
|
||||||
digest = pyblake2.blake2s(data).digest()
|
digest = pyblake2.blake2s(data).digest()
|
||||||
sigmask = 1 << (idx - 1)
|
return signkey.sign(digest)
|
||||||
sig = signkey.sign(digest)
|
|
||||||
return sigmask, sig
|
|
||||||
|
|
||||||
|
|
||||||
def format_sigmask(sigmask):
|
def format_sigmask(sigmask):
|
||||||
bits = [ str(b + 1) if sigmask & (1<<b) else '.' for b in range(8) ]
|
bits = [ str(b + 1) if sigmask & (1<<b) else '.' for b in range(8) ]
|
||||||
@ -86,11 +75,12 @@ class BinImage:
|
|||||||
assert len(header) == self.hdrlen
|
assert len(header) == self.hdrlen
|
||||||
return header
|
return header
|
||||||
|
|
||||||
def sign(self):
|
def sign(self, sigmask, seckey):
|
||||||
header = self.serialize_header(sig=False)
|
header = self.serialize_header(sig=False)
|
||||||
data = header + self.code
|
data = header + self.code
|
||||||
assert len(data) == self.hdrlen + self.codelen
|
assert len(data) == self.hdrlen + self.codelen
|
||||||
self.sigmask, self.sig = get_sig(data)
|
self.sigmask = sigmask
|
||||||
|
self.sig = sign_data(seckey, data)
|
||||||
|
|
||||||
def write(self, filename):
|
def write(self, filename):
|
||||||
with open(filename, 'wb') as f:
|
with open(filename, 'wb') as f:
|
||||||
@ -185,9 +175,10 @@ class VendorHeader:
|
|||||||
assert len(header) == self.hdrlen
|
assert len(header) == self.hdrlen
|
||||||
return header
|
return header
|
||||||
|
|
||||||
def sign(self):
|
def sign(self, sigmask, seckey):
|
||||||
header = self.serialize_header(sig=False)
|
header = self.serialize_header(sig=False)
|
||||||
self.sigmask, self.sig = get_sig(header)
|
self.sigmask = sigmask
|
||||||
|
self.sig = sign_data(seckey, header)
|
||||||
|
|
||||||
def write(self, filename):
|
def write(self, filename):
|
||||||
with open(filename, 'wb') as f:
|
with open(filename, 'wb') as f:
|
||||||
@ -212,18 +203,18 @@ def binopen(filename):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print('Usage: binctl file.bin [-s]')
|
print('Usage: binctl file.bin [-s index seckey]')
|
||||||
return 1
|
return 1
|
||||||
fn = sys.argv[1]
|
fn = sys.argv[1]
|
||||||
sign = len(sys.argv) > 2 and sys.argv[2] == '-s'
|
sign = len(sys.argv) > 2 and sys.argv[2] == '-s'
|
||||||
b = binopen(fn)
|
b = binopen(fn)
|
||||||
if sign:
|
if sign:
|
||||||
b.sign()
|
sigmask = 1 << (int(sys.argv[3]) - 1)
|
||||||
|
seckey = binascii.unhexlify(sys.argv[4])
|
||||||
|
b.sign(sigmask, seckey)
|
||||||
print()
|
print()
|
||||||
b.print()
|
|
||||||
b.write(fn)
|
b.write(fn)
|
||||||
else:
|
b.print()
|
||||||
b.print()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user