From 6fe26c26e46b83470be6a2ed49b56d7638a5d190 Mon Sep 17 00:00:00 2001 From: slush Date: Sun, 1 Sep 2013 03:34:36 +0200 Subject: [PATCH] Fix PIN handling --- bitkeylib/client.py | 10 +++++----- bitkeylib/debuglink.py | 7 ++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/bitkeylib/client.py b/bitkeylib/client.py index 346a342..a119af9 100644 --- a/bitkeylib/client.py +++ b/bitkeylib/client.py @@ -17,9 +17,6 @@ class CallException(Exception): class PinException(CallException): pass -class OtpException(CallException): - pass - class BitkeyClient(object): def __init__(self, transport, debuglink=None, @@ -80,10 +77,10 @@ class BitkeyClient(object): if isinstance(resp, proto.PinMatrixRequest): if self.debuglink: if self.debug_pin: - pin = self.debuglink.read_pin() + pin = self.debuglink.read_pin_encoded() msg2 = proto.PinMatrixAck(pin=pin) else: - msg2 = proto.PinMatrixAck(pin='__42__') + msg2 = proto.PinMatrixAck(pin='444444222222') else: pin = self.input_func("PIN required: ", resp.message) msg2 = proto.PinMatrixAck(pin=pin) @@ -106,6 +103,9 @@ class BitkeyClient(object): return resp + def ping(self, msg): + return self.call(proto.Ping(message=msg)).message + def get_uuid(self): return self.call(proto.GetUUID()).UUID diff --git a/bitkeylib/debuglink.py b/bitkeylib/debuglink.py index 0e459da..d32f7cb 100644 --- a/bitkeylib/debuglink.py +++ b/bitkeylib/debuglink.py @@ -20,11 +20,16 @@ class DebugLink(object): print "Read PIN:", obj.pin print "Read matrix:", obj.matrix + return (obj.pin, obj.matrix) + + def read_pin_encoded(self): + pin, matrix = self.read_pin() + # Now we have real PIN and PIN matrix. # We have to encode that into encoded pin, # because application must send back positions # on keypad, not a real PIN. - pin_encoded = ''.join([ str(obj.matrix.index(p) + 1) for p in obj.pin]) + pin_encoded = ''.join([ str(matrix.index(p) + 1) for p in pin]) print "Encoded PIN:", pin_encoded self.pin_func(pin_encoded)