From e4429242aacb9c7e6de68e3fe8d9e18854d21c42 Mon Sep 17 00:00:00 2001 From: nelisky Date: Tue, 3 Mar 2015 23:36:51 +0000 Subject: [PATCH 1/5] Allow insight_tx to be passed a dict object instead of an url --- trezorlib/tx_api.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/trezorlib/tx_api.py b/trezorlib/tx_api.py index 5816411..62a7867 100644 --- a/trezorlib/tx_api.py +++ b/trezorlib/tx_api.py @@ -52,12 +52,15 @@ def opcode_serialize(opcode): except: raise Exception('Unknown script opcode: %s' % opcode) -def insight_tx(url): - try: - f = urllib2.urlopen(url) - except: - raise Exception('URL error: %s' % url) - data = json.load(f) +def insight_tx(url, rawdata=False): + if not rawdata: + try: + f = urllib2.urlopen(url) + data = json.load(f) + except: + raise Exception('URL error: %s' % url) + else: + data = url t = proto_types.TransactionType() t.version = data['version'] From f3b7629a4fad2ed96ae0cb434d54d3cc087d42bd Mon Sep 17 00:00:00 2001 From: nelisky Date: Tue, 3 Mar 2015 23:37:32 +0000 Subject: [PATCH 2/5] Prevent floating point issues when pushing output amount --- trezorlib/tx_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trezorlib/tx_api.py b/trezorlib/tx_api.py index 62a7867..94214f0 100644 --- a/trezorlib/tx_api.py +++ b/trezorlib/tx_api.py @@ -84,7 +84,7 @@ def insight_tx(url, rawdata=False): for vout in data['vout']: o = t.bin_outputs.add() - o.amount = int(Decimal(vout['value']) * 100000000) + o.amount = int(Decimal(str(vout['value'])) * 100000000) asm = vout['scriptPubKey']['asm'].split(' ') asm = [ opcode_serialize(x) for x in asm ] o.script_pubkey = ''.join(asm) From 9107aab76a2fc9b439a99a753097d34c4bfe6385 Mon Sep 17 00:00:00 2001 From: Jochen Hoenicke Date: Thu, 5 Mar 2015 11:00:18 +0100 Subject: [PATCH 3/5] Use right URL for bridge and keep-alive connection The bridge is using https with a certificate signed for localback.net. Use a session object (self.conn) to keep connection alive and prevent costly ssl handshakes for every call. --- trezorlib/transport_bridge.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/trezorlib/transport_bridge.py b/trezorlib/transport_bridge.py index 3991dcc..c150e66 100644 --- a/trezorlib/transport_bridge.py +++ b/trezorlib/transport_bridge.py @@ -7,7 +7,7 @@ import mapping from transport import Transport import messages_pb2 as proto -TREZORD_HOST = 'http://localhost:21324' +TREZORD_HOST = 'https://localback.net:21324' CONFIG_URL = 'https://mytrezor.com/data/plugin/config_signed.bin' def get_error(resp): @@ -22,11 +22,13 @@ class BridgeTransport(Transport): config = r.text - r = requests.post(TREZORD_HOST + '/configure', data=config) + self.conn = requests.Session(); + + r = self.conn.post(TREZORD_HOST + '/configure', data=config, verify=None) if r.status_code != 200: raise Exception('trezord: Could not configure' + get_error(r)) - r = requests.get(TREZORD_HOST + '/enumerate') + r = self.conn.get(TREZORD_HOST + '/enumerate', verify=None) if r.status_code != 200: raise Exception('trezord: Could not enumerate devices' + get_error(r)) enum = r.json() @@ -41,14 +43,14 @@ class BridgeTransport(Transport): super(BridgeTransport, self).__init__(device, *args, **kwargs) def _open(self): - r = requests.post(TREZORD_HOST + '/acquire/%s' % self.path) + r = self.conn.post(TREZORD_HOST + '/acquire/%s' % self.path, verify=None) if r.status_code != 200: raise Exception('trezord: Could not acquire session' + get_error(r)) resp = r.json() self.session = resp['session'] def _close(self): - r = requests.post(TREZORD_HOST + '/release/%s' % self.session) + r = self.conn.post(TREZORD_HOST + '/release/%s' % self.session, verify=None) if r.status_code != 200: raise Exception('trezord: Could not release session' + get_error(r)) else: @@ -61,7 +63,7 @@ class BridgeTransport(Transport): cls = protobuf_msg.__class__.__name__ msg = protobuf_json.pb2json(protobuf_msg) payload = '{"type": "%s", "message": %s}' % (cls, json.dumps(msg)) - r = requests.post(TREZORD_HOST + '/call/%s' % self.session, data=payload) + r = self.conn.post(TREZORD_HOST + '/call/%s' % self.session, data=payload, verify=None) if r.status_code != 200: raise Exception('trezord: Could not write message' + get_error(r)) else: From 6f59de799a2d928e2f81cb0083a9bafc2c72b2d7 Mon Sep 17 00:00:00 2001 From: Jochen Hoenicke Date: Thu, 5 Mar 2015 11:15:53 +0100 Subject: [PATCH 4/5] Verify the localback.net certificate --- trezorlib/transport_bridge.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/trezorlib/transport_bridge.py b/trezorlib/transport_bridge.py index c150e66..56ded7d 100644 --- a/trezorlib/transport_bridge.py +++ b/trezorlib/transport_bridge.py @@ -24,11 +24,11 @@ class BridgeTransport(Transport): self.conn = requests.Session(); - r = self.conn.post(TREZORD_HOST + '/configure', data=config, verify=None) + r = self.conn.post(TREZORD_HOST + '/configure', data=config) if r.status_code != 200: raise Exception('trezord: Could not configure' + get_error(r)) - r = self.conn.get(TREZORD_HOST + '/enumerate', verify=None) + r = self.conn.get(TREZORD_HOST + '/enumerate') if r.status_code != 200: raise Exception('trezord: Could not enumerate devices' + get_error(r)) enum = r.json() @@ -43,14 +43,14 @@ class BridgeTransport(Transport): super(BridgeTransport, self).__init__(device, *args, **kwargs) def _open(self): - r = self.conn.post(TREZORD_HOST + '/acquire/%s' % self.path, verify=None) + r = self.conn.post(TREZORD_HOST + '/acquire/%s' % self.path) if r.status_code != 200: raise Exception('trezord: Could not acquire session' + get_error(r)) resp = r.json() self.session = resp['session'] def _close(self): - r = self.conn.post(TREZORD_HOST + '/release/%s' % self.session, verify=None) + r = self.conn.post(TREZORD_HOST + '/release/%s' % self.session) if r.status_code != 200: raise Exception('trezord: Could not release session' + get_error(r)) else: @@ -63,7 +63,7 @@ class BridgeTransport(Transport): cls = protobuf_msg.__class__.__name__ msg = protobuf_json.pb2json(protobuf_msg) payload = '{"type": "%s", "message": %s}' % (cls, json.dumps(msg)) - r = self.conn.post(TREZORD_HOST + '/call/%s' % self.session, data=payload, verify=None) + r = self.conn.post(TREZORD_HOST + '/call/%s' % self.session, data=payload) if r.status_code != 200: raise Exception('trezord: Could not write message' + get_error(r)) else: From 33a913d951878116680d8c8b44f9c17e4ab76389 Mon Sep 17 00:00:00 2001 From: ywecur Date: Mon, 9 Mar 2015 13:12:11 +0100 Subject: [PATCH 5/5] =?UTF-8?q?Add=20=E2=80=99git=E2=80=98=20to=20list=20o?= =?UTF-8?q?f=20programs=20to=20install=20under=20Debian-Ubuntu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 32e5f30..2522f03 100644 --- a/README.rst +++ b/README.rst @@ -57,7 +57,7 @@ How to install (Windows) How to install (Debian-Ubuntu) ------------------------------ -* sudo apt-get install python-dev python-setuptools cython libusb-1.0-0-dev libudev-dev +* sudo apt-get install python-dev python-setuptools cython libusb-1.0-0-dev libudev-dev git * git clone https://github.com/trezor/python-trezor.git * cd python-trezor * python setup.py install (or develop)