|
|
@ -4,6 +4,8 @@ import binascii
|
|
|
|
import argparse
|
|
|
|
import argparse
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
import base64
|
|
|
|
import base64
|
|
|
|
|
|
|
|
import urllib
|
|
|
|
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
|
|
|
|
from trezorlib.client import TrezorClient, TrezorClientDebug
|
|
|
|
from trezorlib.client import TrezorClient, TrezorClientDebug
|
|
|
|
from trezorlib.tx_api import TXAPIBitcoin
|
|
|
|
from trezorlib.tx_api import TXAPIBitcoin
|
|
|
@ -203,14 +205,34 @@ class Commands(object):
|
|
|
|
return ret
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
def firmware_update(self, args):
|
|
|
|
def firmware_update(self, args):
|
|
|
|
if not args.file:
|
|
|
|
if not args.file and not args.url:
|
|
|
|
raise Exception("Must provide firmware filename")
|
|
|
|
raise Exception("Must provide firmware filename or URL")
|
|
|
|
fp = open(args.file, 'r')
|
|
|
|
|
|
|
|
|
|
|
|
if args.file:
|
|
|
|
|
|
|
|
fp = open(args.file, 'r')
|
|
|
|
|
|
|
|
elif args.url:
|
|
|
|
|
|
|
|
print "Downloading from", args.url
|
|
|
|
|
|
|
|
resp = urllib.urlretrieve(args.url)
|
|
|
|
|
|
|
|
fp = open(resp[0], 'r')
|
|
|
|
|
|
|
|
urllib.urlcleanup() # We still keep file pointer open
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if fp.read(8) == '54525a52':
|
|
|
|
|
|
|
|
print "Converting firmware to binary"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fp.seek(0)
|
|
|
|
|
|
|
|
fp_old = fp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fp = tempfile.TemporaryFile()
|
|
|
|
|
|
|
|
fp.write(binascii.unhexlify(fp_old.read()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fp_old.close()
|
|
|
|
|
|
|
|
fp.seek(0)
|
|
|
|
|
|
|
|
|
|
|
|
if fp.read(4) != 'TRZR':
|
|
|
|
if fp.read(4) != 'TRZR':
|
|
|
|
raise Exception("Trezor firmware header expected")
|
|
|
|
raise Exception("Trezor firmware header expected")
|
|
|
|
|
|
|
|
|
|
|
|
fp.seek(0)
|
|
|
|
fp.seek(0)
|
|
|
|
return self.client.firmware_update(fp=open(args.file, 'r'))
|
|
|
|
return self.client.firmware_update(fp=fp)
|
|
|
|
|
|
|
|
|
|
|
|
list.help = 'List connected Trezor USB devices'
|
|
|
|
list.help = 'List connected Trezor USB devices'
|
|
|
|
ping.help = 'Send ping message'
|
|
|
|
ping.help = 'Send ping message'
|
|
|
@ -335,6 +357,7 @@ class Commands(object):
|
|
|
|
|
|
|
|
|
|
|
|
firmware_update.arguments = (
|
|
|
|
firmware_update.arguments = (
|
|
|
|
(('-f', '--file'), {'type': str}),
|
|
|
|
(('-f', '--file'), {'type': str}),
|
|
|
|
|
|
|
|
(('-u', '--url'), {'type': str}),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def list_usb():
|
|
|
|
def list_usb():
|
|
|
|