1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-29 19:08:12 +00:00
trezor-firmware/bitkeylib/debuglink.py

51 lines
1.6 KiB
Python
Raw Normal View History

import bitkey_pb2 as proto
2013-01-05 14:42:49 +00:00
from transport import NotImplementedException
2012-12-13 19:05:04 +00:00
def otp_info(otp):
2012-12-13 19:05:04 +00:00
print "Device asks for OTP %s" % otp.otp
def pin_info(pin):
2012-12-13 19:05:04 +00:00
print "Device asks for PIN %s" % pin.pin
def button_press(yes_no):
print "User pressed", '"y"' if yes_no else '"n"'
class DebugLink(object):
def __init__(self, transport, otp_func=otp_info, pin_func=pin_info, button_func=button_press):
self.transport = transport
2012-12-13 19:05:04 +00:00
self.otp_func = otp_func
self.pin_func = pin_func
self.button_func = button_func
2012-12-13 19:05:04 +00:00
def get_state(self, otp=False, pin=False):
self.transport.write(proto.DebugLinkGetState(otp=otp, pin=pin))
return self.transport.read_blocking()
2013-02-18 17:45:33 +00:00
2013-04-15 17:58:38 +00:00
def load_device(self, algo, seed, otp, pin, spv):
self.transport.write(proto.LoadDevice(algo=algo, seed=seed, otp=otp, pin=pin, spv=spv))
2013-02-18 17:45:33 +00:00
resp = self.transport.read_blocking()
return isinstance(resp, proto.Success)
def read_otp(self):
2012-12-13 19:05:04 +00:00
obj = self.get_state(otp=True).otp
print "Read OTP:", obj.otp
self.otp_func(obj)
return obj
def read_pin(self):
2012-12-13 19:05:04 +00:00
obj = self.get_state(pin=True).pin
print "Read PIN:", obj.pin
self.pin_func(obj)
return obj
def press_button(self, yes_no):
2012-12-13 19:05:04 +00:00
print "Pressing", yes_no
self.button_func(yes_no)
self.transport.write(proto.DebugLinkDecision(yes_no=yes_no))
2012-12-13 19:05:04 +00:00
def press_yes(self):
self.press_button(True)
def press_no(self):
self.press_button(False)