Merge pull request #46 from runn1ng/master
Fixing and adding bridge transport
This commit is contained in:
commit
5f59a54983
1
setup.py
1
setup.py
@ -20,6 +20,7 @@ setup(
|
|||||||
'trezorlib.transport',
|
'trezorlib.transport',
|
||||||
'trezorlib.transport_fake',
|
'trezorlib.transport_fake',
|
||||||
'trezorlib.transport_hid',
|
'trezorlib.transport_hid',
|
||||||
|
'trezorlib.transport_bridge',
|
||||||
'trezorlib.transport_pipe',
|
'trezorlib.transport_pipe',
|
||||||
'trezorlib.transport_serial',
|
'trezorlib.transport_serial',
|
||||||
'trezorlib.transport_socket',
|
'trezorlib.transport_socket',
|
||||||
|
@ -15,32 +15,43 @@ def get_error(resp):
|
|||||||
|
|
||||||
class BridgeTransport(Transport):
|
class BridgeTransport(Transport):
|
||||||
def __init__(self, device, *args, **kwargs):
|
def __init__(self, device, *args, **kwargs):
|
||||||
|
self.configure()
|
||||||
|
|
||||||
|
self.path = device['path']
|
||||||
|
|
||||||
|
self.session = None
|
||||||
|
self.response = None
|
||||||
|
self.conn = requests.Session();
|
||||||
|
|
||||||
|
super(BridgeTransport, self).__init__(device, *args, **kwargs)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def configure():
|
||||||
r = requests.get(CONFIG_URL)
|
r = requests.get(CONFIG_URL)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
raise Exception('Could not fetch config from %s' % CONFIG_URL)
|
raise Exception('Could not fetch config from %s' % CONFIG_URL)
|
||||||
|
|
||||||
config = r.text
|
config = r.text
|
||||||
|
|
||||||
self.conn = requests.Session();
|
r = requests.post(TREZORD_HOST + '/configure', data=config)
|
||||||
|
|
||||||
r = self.conn.post(TREZORD_HOST + '/configure', data=config)
|
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
raise Exception('trezord: Could not configure' + get_error(r))
|
raise Exception('trezord: Could not configure' + get_error(r))
|
||||||
|
|
||||||
r = self.conn.get(TREZORD_HOST + '/enumerate')
|
@classmethod
|
||||||
|
def enumerate(cls):
|
||||||
|
"""
|
||||||
|
Return a list of available TREZOR devices.
|
||||||
|
"""
|
||||||
|
devices = {}
|
||||||
|
cls.configure()
|
||||||
|
r = requests.get(TREZORD_HOST + '/enumerate')
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
raise Exception('trezord: Could not enumerate devices' + get_error(r))
|
raise Exception('trezord: Could not enumerate devices' + get_error(r))
|
||||||
|
|
||||||
enum = r.json()
|
enum = r.json()
|
||||||
|
|
||||||
if len(enum) < 1:
|
return enum;
|
||||||
raise Exception('trezord: No devices found')
|
|
||||||
|
|
||||||
self.path = enum[0]['path']
|
|
||||||
self.session = None
|
|
||||||
self.response = None
|
|
||||||
|
|
||||||
super(BridgeTransport, self).__init__(device, *args, **kwargs)
|
|
||||||
|
|
||||||
def _open(self):
|
def _open(self):
|
||||||
r = self.conn.post(TREZORD_HOST + '/acquire/%s' % self.path)
|
r = self.conn.post(TREZORD_HOST + '/acquire/%s' % self.path)
|
||||||
|
Loading…
Reference in New Issue
Block a user