|
|
@ -1,3 +1,4 @@
|
|
|
|
|
|
|
|
import time
|
|
|
|
import unittest
|
|
|
|
import unittest
|
|
|
|
import common
|
|
|
|
import common
|
|
|
|
|
|
|
|
|
|
|
@ -31,5 +32,36 @@ class TestProtectCall(common.TrezorTest):
|
|
|
|
self.client.setup_debuglink(button=True, pin_correct=-1) # PIN cancel
|
|
|
|
self.client.setup_debuglink(button=True, pin_correct=-1) # PIN cancel
|
|
|
|
self.assertRaises(PinException, self._some_protected_call)
|
|
|
|
self.assertRaises(PinException, self._some_protected_call)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_exponential_backoff_with_reboot(self):
|
|
|
|
|
|
|
|
self.client.setup_debuglink(button=True, pin_correct=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_backoff(attempts, start):
|
|
|
|
|
|
|
|
expected = 1.8 ** attempts
|
|
|
|
|
|
|
|
got = time.time() - start
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
msg = "Pin delay expected to be at least %s seconds, got %s" % (expected, got)
|
|
|
|
|
|
|
|
print msg
|
|
|
|
|
|
|
|
self.assertLessEqual(expected, got, msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for attempt in range(1, 6):
|
|
|
|
|
|
|
|
start = time.time()
|
|
|
|
|
|
|
|
self.assertRaises(PinException, self._some_protected_call)
|
|
|
|
|
|
|
|
test_backoff(attempt, start)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Unplug Trezor now
|
|
|
|
|
|
|
|
self.client.debuglink.stop()
|
|
|
|
|
|
|
|
self.client.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Give it some time to reboot (it may take some time on RPi)
|
|
|
|
|
|
|
|
boot_delay = 5
|
|
|
|
|
|
|
|
start = time.time()
|
|
|
|
|
|
|
|
time.sleep(boot_delay)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Connect to Trezor again
|
|
|
|
|
|
|
|
self.setUp()
|
|
|
|
|
|
|
|
print "Expected reboot time %s seconds" % (1.8 ** attempt)
|
|
|
|
|
|
|
|
print "Rebooted in %s seconds" % (time.time() - start)
|
|
|
|
|
|
|
|
self.assertLessEqual(1.8 ** attempt, time.time() - start, "Bootup took less than expected!")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
unittest.main()
|
|
|
|