trezor-0.7.16/0000755000175000001440000000000013127142534013430 5ustar stickusers00000000000000trezor-0.7.16/bash_completion.d/0000755000175000001440000000000013127142534017020 5ustar stickusers00000000000000trezor-0.7.16/bash_completion.d/trezorctl.sh0000644000175000001440000000051113007442350021375 0ustar stickusers00000000000000_trezorctl() { local cur prev cmds base COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" cmds=$(trezorctl --help | grep -A 1 'Available commands:' | tail -n 1 | tr '{},' ' ') COMPREPLY=($(compgen -W "${cmds}" -- ${cur})) return 0 } complete -F _trezorctl trezorctl trezor-0.7.16/tests/0000755000175000001440000000000013127142534014572 5ustar stickusers00000000000000trezor-0.7.16/tests/device_tests/0000755000175000001440000000000013127142534017253 5ustar stickusers00000000000000trezor-0.7.16/tests/device_tests/common.py0000644000175000001440000001002513127142316021111 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . from __future__ import print_function import unittest import hashlib from trezorlib.client import TrezorClient, TrezorDebugClient from trezorlib import tx_api import config tx_api.cache_dir = '../txcache' class TrezorTest(unittest.TestCase): def setUp(self): transport = config.TRANSPORT(*config.TRANSPORT_ARGS, **config.TRANSPORT_KWARGS) if hasattr(config, 'DEBUG_TRANSPORT'): debug_transport = config.DEBUG_TRANSPORT(*config.DEBUG_TRANSPORT_ARGS, **config.DEBUG_TRANSPORT_KWARGS) self.client = TrezorDebugClient(transport) self.client.set_debuglink(debug_transport) else: self.client = TrezorClient(transport) self.client.set_tx_api(tx_api.TxApiBitcoin) # self.client.set_buttonwait(3) # 1 2 3 4 5 6 7 8 9 10 11 12 self.mnemonic12 = 'alcohol woman abuse must during monitor noble actual mixed trade anger aisle' self.mnemonic18 = 'owner little vague addict embark decide pink prosper true fork panda embody mixture exchange choose canoe electric jewel' self.mnemonic24 = 'dignity pass list indicate nasty swamp pool script soccer toe leaf photo multiply desk host tomato cradle drill spread actor shine dismiss champion exotic' self.mnemonic_all = ' '.join(['all'] * 12) self.pin4 = '1234' self.pin6 = '789456' self.pin8 = '45678978' self.client.wipe_device() print("Setup finished") print("--------------") def setup_mnemonic_allallall(self): self.client.load_device_by_mnemonic(mnemonic=self.mnemonic_all, pin='', passphrase_protection=False, label='test', language='english') def setup_mnemonic_nopin_nopassphrase(self): self.client.load_device_by_mnemonic(mnemonic=self.mnemonic12, pin='', passphrase_protection=False, label='test', language='english') def setup_mnemonic_pin_nopassphrase(self): self.client.load_device_by_mnemonic(mnemonic=self.mnemonic12, pin=self.pin4, passphrase_protection=False, label='test', language='english') def setup_mnemonic_pin_passphrase(self): self.client.load_device_by_mnemonic(mnemonic=self.mnemonic12, pin=self.pin4, passphrase_protection=True, label='test', language='english') def tearDown(self): self.client.close() def generate_entropy(strength, internal_entropy, external_entropy): ''' strength - length of produced seed. One of 128, 192, 256 random - binary stream of random data from external HRNG ''' if strength not in (128, 192, 256): raise Exception("Invalid strength") if not internal_entropy: raise Exception("Internal entropy is not provided") if len(internal_entropy) < 32: raise Exception("Internal entropy too short") if not external_entropy: raise Exception("External entropy is not provided") if len(external_entropy) < 32: raise Exception("External entropy too short") entropy = hashlib.sha256(internal_entropy + external_entropy).digest() entropy_stripped = entropy[:strength // 8] if len(entropy_stripped) * 8 != strength: raise Exception("Entropy length mismatch") return entropy_stripped trezor-0.7.16/tests/device_tests/config.py0000644000175000001440000000477313123262316021102 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . from __future__ import print_function import sys sys.path = ['../../'] + sys.path try: from trezorlib.transport_hid import HidTransport HID_ENABLED = True except Exception as e: print('HID transport disabled:', e.message, e.args) HID_ENABLED = False try: from trezorlib.transport_pipe import PipeTransport PIPE_ENABLED = True except Exception as e: print('PIPE transport disabled:', e.message, e.args) PIPE_ENABLED = False try: from trezorlib.transport_udp import UdpTransport UDP_ENABLED = True except Exception as e: print('UDP transport disabled:', e.message, e.args) UDP_ENABLED = False def pipe_exists(path): import os import stat try: return stat.S_ISFIFO(os.stat(path).st_mode) except: return False if HID_ENABLED and len(HidTransport.enumerate()) > 0: devices = HidTransport.enumerate() print('Using TREZOR') TRANSPORT = HidTransport TRANSPORT_ARGS = (devices[0],) TRANSPORT_KWARGS = {'debug_link': False} DEBUG_TRANSPORT = HidTransport DEBUG_TRANSPORT_ARGS = (devices[0],) DEBUG_TRANSPORT_KWARGS = {'debug_link': True} elif PIPE_ENABLED and pipe_exists('/tmp/pipe.trezor.to'): print('Using Emulator (v1=pipe)') TRANSPORT = PipeTransport TRANSPORT_ARGS = ('/tmp/pipe.trezor', False) TRANSPORT_KWARGS = {} DEBUG_TRANSPORT = PipeTransport DEBUG_TRANSPORT_ARGS = ('/tmp/pipe.trezor_debug', False) DEBUG_TRANSPORT_KWARGS = {} elif UDP_ENABLED: print('Using Emulator (v2=udp)') TRANSPORT = UdpTransport TRANSPORT_ARGS = ('', ) TRANSPORT_KWARGS = {} DEBUG_TRANSPORT = UdpTransport DEBUG_TRANSPORT_ARGS = ('', ) DEBUG_TRANSPORT_KWARGS = {} trezor-0.7.16/tests/device_tests/run-separate.sh0000755000175000001440000000013312645304530022215 0ustar stickusers00000000000000#!/bin/bash for i in test_*.py; do echo Starting: $i python $i > $i.out 2> $i.err done trezor-0.7.16/tests/device_tests/run.sh0000755000175000001440000000005112645304530020412 0ustar stickusers00000000000000#!/bin/bash python -m unittest discover trezor-0.7.16/tests/device_tests/test_basic.py0000644000175000001440000000352013123262107021740 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . import unittest import common from trezorlib import messages_pb2 as messages class TestBasic(common.TrezorTest): def test_features(self): features = self.client.call(messages.Initialize()) self.assertEqual(features, self.client.features) def test_ping(self): ping = self.client.call(messages.Ping(message='ahoj!')) self.assertEqual(ping, messages.Success(message='ahoj!')) def test_device_id_same(self): id1 = self.client.get_device_id() self.client.init_device() id2 = self.client.get_device_id() # ID must be at least 12 characters self.assertTrue(len(id1) >= 12) # Every resulf of UUID must be the same self.assertEqual(id1, id2) def test_device_id_different(self): id1 = self.client.get_device_id() self.client.wipe_device() id2 = self.client.get_device_id() # Device ID must be fresh after every reset self.assertNotEqual(id1, id2) if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_bip32_speed.py0000644000175000001440000000511713123262131022757 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . from __future__ import print_function import unittest import common import time class TestBip32Speed(common.TrezorTest): def test_public_ckd(self): self.setup_mnemonic_nopin_nopassphrase() self.client.get_address('Bitcoin', []) # to compute root node via BIP39 for depth in range(8): start = time.time() self.client.get_address('Bitcoin', range(depth)) delay = time.time() - start expected = (depth + 1) * 0.26 print("DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay) self.assertLessEqual(delay, expected) def test_private_ckd(self): self.setup_mnemonic_nopin_nopassphrase() self.client.get_address('Bitcoin', []) # to compute root node via BIP39 for depth in range(8): start = time.time() self.client.get_address('Bitcoin', range(-depth, 0)) delay = time.time() - start expected = (depth + 1) * 0.26 print("DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay) self.assertLessEqual(delay, expected) def test_cache(self): self.setup_mnemonic_nopin_nopassphrase() start = time.time() for x in range(10): self.client.get_address('Bitcoin', [x, 2, 3, 4, 5, 6, 7, 8]) nocache_time = time.time() - start start = time.time() for x in range(10): self.client.get_address('Bitcoin', [1, 2, 3, 4, 5, 6, 7, x]) cache_time = time.time() - start print("NOCACHE TIME", nocache_time) print("CACHED TIME", cache_time) # Cached time expected to be at least 2x faster self.assertLessEqual(cache_time, nocache_time / 2.) if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_debuglink.py0000644000175000001440000000375313123262221022630 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . import unittest import common from trezorlib import messages_pb2 as proto class TestDebugLink(common.TrezorTest): def test_layout(self): layout = self.client.debug.read_layout() self.assertEqual(len(layout), 1024) def test_mnemonic(self): self.setup_mnemonic_nopin_nopassphrase() mnemonic = self.client.debug.read_mnemonic() self.assertEqual(mnemonic, self.mnemonic12) def test_node(self): self.setup_mnemonic_nopin_nopassphrase() node = self.client.debug.read_node() self.assertIsNotNone(node) def test_pin(self): self.setup_mnemonic_pin_passphrase() # Manually trigger PinMatrixRequest resp = self.client.call_raw(proto.Ping(message='test', pin_protection=True)) self.assertIsInstance(resp, proto.PinMatrixRequest) pin = self.client.debug.read_pin() self.assertEqual(pin[0], '1234') self.assertNotEqual(pin[1], '') pin_encoded = self.client.debug.read_pin_encoded() resp = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) self.assertIsInstance(resp, proto.Success) if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_applysettings.py0000644000175000001440000001645613123262207024450 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . import unittest import common from trezorlib import messages_pb2 as proto class TestMsgApplysettings(common.TrezorTest): def test_apply_settings(self): self.setup_mnemonic_pin_passphrase() self.assertEqual(self.client.features.label, 'test') with self.client: self.client.set_expected_responses([proto.PinMatrixRequest(), proto.ButtonRequest(), proto.Success(), proto.Features()]) self.client.apply_settings(label='new label') self.assertEqual(self.client.features.label, 'new label') def test_invalid_language(self): self.setup_mnemonic_pin_passphrase() self.assertEqual(self.client.features.language, 'english') with self.client: self.client.set_expected_responses([proto.PinMatrixRequest(), proto.ButtonRequest(), proto.Success(), proto.Features()]) self.client.apply_settings(language='nonexistent') self.assertEqual(self.client.features.language, 'english') def test_apply_settings_passphrase(self): self.setup_mnemonic_pin_nopassphrase() self.assertEqual(self.client.features.passphrase_protection, False) with self.client: self.client.set_expected_responses([proto.PinMatrixRequest(), proto.ButtonRequest(), proto.Success(), proto.Features()]) self.client.apply_settings(use_passphrase=True) self.assertEqual(self.client.features.passphrase_protection, True) with self.client: self.client.set_expected_responses([proto.ButtonRequest(), proto.Success(), proto.Features()]) self.client.apply_settings(use_passphrase=False) self.assertEqual(self.client.features.passphrase_protection, False) with self.client: self.client.set_expected_responses([proto.ButtonRequest(), proto.Success(), proto.Features()]) self.client.apply_settings(use_passphrase=True) self.assertEqual(self.client.features.passphrase_protection, True) def test_apply_homescreen(self): self.setup_mnemonic_pin_passphrase() img = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"\x00\x00\x00\x00\x04\x80\x00\x00\x00\x00\x00\x00\x00\x00\x04\x88\x02\x00\x00\x00\x02\x91\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x90@\x00\x11@\x00\x00\x00\x00\x00\x00\x08\x00\x10\x92\x12\x04\x00\x00\x05\x12D\x00\x00\x00\x00\x00 \x00\x00\x08\x00Q\x00\x00\x02\xc0\x00\x00\x00\x00\x00\x00\x00\x10\x02 \x01\x04J\x00)$\x00\x00\x00\x00\x80\x00\x00\x00\x00\x08\x10\xa1\x00\x00\x02\x81 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\tP\x00\x00\x00\x00\x00\x00 \x00\x00\xa0\x00\xa0R \x12\x84\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\t\x08\x00\tP\x00\x00\x00\x00 \x00\x04 \x00\x80\x02\x00@\x02T\xc2 \x00\x00\x00\x00\x00\x00\x00\x10@\x00)\t@\n\xa0\x80\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x80@\x14\xa9H\x04\x00\x00\x88@\x00\x00\x00\x00\x00\x02\x02$\x00\x15B@\x00\nP\x00\x00\x00\x00\x00\x80\x00\x00\x91\x01UP\x00\x00 \x02\x00\x00\x00\x00\x00\x00\x02\x08@ Z\xa5 \x00\x00\x80\x00\x00\x00\x00\x00\x00\x08\xa1%\x14*\xa0\x00\x00\x02\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00@\xaa\x91 \x00\x05E\x80\x00\x00\x00\x00\x00\x02*T\x05-D\x00\x00\x05 @\x00\x00\x00\x00\x00%@\x80\x11V\xa0\x88\x00\x05@\xb0\x00\x00\x00\x00\x00\x818$\x04\xabD \x00\x06\xa1T\x00\x00\x00\x00\x02\x03\xb8\x01R\xd5\x01\x00\x00\x05AP\x00\x00\x00\x00\x08\xadT\x00\x05j\xa4@\x00\x87ah\x00\x00\x00\x00\x02\x8d\xb8\x08\x00.\x01\x00\x00\x02\xa5\xa8\x10\x00\x00\x00*\xc1\xec \n\xaa\x88 \x02@\xf6\xd0\x02\x00\x00\x00\x0bB\xb6\x14@U"\x80\x00\x01{`\x00\x00\x00\x00M\xa3\xf8 \x15*\x00\x00\x00\x10n\xc0\x04\x00\x00\x02\x06\xc2\xa8)\x00\x96\x84\x80\x00\x00\x1b\x00\x00\x80@\x10\x87\xa7\xf0\x84\x10\xaa\x10\x00\x00D\x00\x00\x02 \x00\x8a\x06\xfa\xe0P\n-\x02@\x00\x12\x00\x00\x00\x00\x10@\x83\xdf\xa0\x00\x08\xaa@\x00\x00\x01H\x00\x05H\x04\x12\x01\xf7\x81P\x02T\t\x00\x00\x00 \x00\x00\x84\x10\x00\x00z\x00@)* \x00\x00\x01\n\xa0\x02 \x05\n\x00\x00\x05\x10\x84\xa8\x84\x80\x00\x00@\x14\x00\x92\x10\x80\x00\x04\x11@\tT\x00\x00\x00\x00\n@\x00\x08\x84@$\x00H\x00\x12Q\x02\x00\x00\x00\x00\x90\x02A\x12\xa8\n\xaa\x92\x10\x04\xa8\x10@\x00\x00\x04\x04\x00\x04I\x00\x04\x14H\x80"R\x01\x00\x00\x00!@\x00\x00$\xa0EB\x80\x08\x95hH\x00\x00\x00\x84\x10 \x05Z\x00\x00(\x00\x02\x00\xa1\x01\x00\x00\x04\x00@\x82\x00\xadH*\x92P\x00\xaaP\x00\x00\x00\x00\x11\x02\x01*\xad\x01\x00\x01\x01"\x11D\x08\x00\x00\x10\x80 \x00\x81W\x80J\x94\x04\x08\xa5 !\x00\x00\x00\x02\x00B*\xae\xa1\x00\x80\x10\x01\x08\xa4\x00\x00\x00\x00\x00\x84\x00\t[@"HA\x04E\x00\x84\x00\x00\x00\x10\x00\x01J\xd5\x82\x90\x02\x00!\x02\xa2\x00\x00\x00\x00\x00\x00\x00\x05~\xa0\x00 \x10\n)\x00\x11\x00\x00\x00\x00\x00\x00!U\x80\xa8\x88\x82\x80\x01\x00\x00\x00\x00\x00\x00H@\x11\xaa\xc0\x82\x00 *\n\x00\x00\x00\x00\x00\x00\x00\x00\n\xabb@ \x04\x00! \x84\x00\x00\x00\x00\x02@\xa5\x15A$\x04\x81(\n\x00\x00\x00\x00\x00\x00 \x01\x10\x02\xe0\x91\x02\x00\x00\x04\x00\x00\x00\x00\x00\x00\x01 \xa9\tQH@\x91 P\x00\x00\x00\x00\x00\x00\x08\x00\x00\xa0T\xa5\x00@\x80\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"\x00\x00\x00\x00\xa2\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00 T\xa0\t\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00@\x02\xa0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00*\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x10\x00\x00\x10\x02\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00@\x04\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x08@\x10\x00\x00\x00\x00' with self.client: self.client.set_expected_responses([proto.PinMatrixRequest(), proto.ButtonRequest(), proto.Success(), proto.Features()]) self.client.apply_settings(homescreen=img) if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_changepin.py0000644000175000001440000002110513123262200023452 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . import unittest import common from trezorlib import messages_pb2 as proto class TestMsgChangepin(common.TrezorTest): def test_set_pin(self): self.setup_mnemonic_nopin_nopassphrase() features = self.client.call_raw(proto.Initialize()) self.assertFalse(features.pin_protection) # Check that there's no PIN protection ret = self.client.call_raw(proto.Ping(pin_protection=True)) self.assertIsInstance(ret, proto.Success) # Let's set new PIN ret = self.client.call_raw(proto.ChangePin()) self.assertIsInstance(ret, proto.ButtonRequest) # Press button self.client.debug.press_yes() ret = self.client.call_raw(proto.ButtonAck()) # Send the PIN for first time self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.encode_pin(self.pin6) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Send the PIN for second time self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.encode_pin(self.pin6) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Now we're done self.assertIsInstance(ret, proto.Success) # Check that there's PIN protection now features = self.client.call_raw(proto.Initialize()) self.assertTrue(features.pin_protection) ret = self.client.call_raw(proto.Ping(pin_protection=True)) self.assertIsInstance(ret, proto.PinMatrixRequest) self.client.call_raw(proto.Cancel()) # Check that the PIN is correct self.assertEqual(self.client.debug.read_pin()[0], self.pin6) def test_change_pin(self): self.setup_mnemonic_pin_passphrase() features = self.client.call_raw(proto.Initialize()) self.assertTrue(features.pin_protection) # Check that there's PIN protection ret = self.client.call_raw(proto.Ping(pin_protection=True)) self.assertIsInstance(ret, proto.PinMatrixRequest) self.client.call_raw(proto.Cancel()) # Check current PIN value self.assertEqual(self.client.debug.read_pin()[0], self.pin4) # Let's change PIN ret = self.client.call_raw(proto.ChangePin()) self.assertIsInstance(ret, proto.ButtonRequest) # Press button self.client.debug.press_yes() ret = self.client.call_raw(proto.ButtonAck()) # Send current PIN self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.read_pin_encoded() ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Send new PIN for first time self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.encode_pin(self.pin6) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Send the PIN for second time self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.encode_pin(self.pin6) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Now we're done self.assertIsInstance(ret, proto.Success) # Check that there's still PIN protection now features = self.client.call_raw(proto.Initialize()) self.assertTrue(features.pin_protection) ret = self.client.call_raw(proto.Ping(pin_protection=True)) self.assertIsInstance(ret, proto.PinMatrixRequest) self.client.call_raw(proto.Cancel()) # Check that the PIN is correct self.assertEqual(self.client.debug.read_pin()[0], self.pin6) def test_remove_pin(self): self.setup_mnemonic_pin_passphrase() features = self.client.call_raw(proto.Initialize()) self.assertTrue(features.pin_protection) # Check that there's PIN protection ret = self.client.call_raw(proto.Ping(pin_protection=True)) self.assertIsInstance(ret, proto.PinMatrixRequest) self.client.call_raw(proto.Cancel()) # Let's remove PIN ret = self.client.call_raw(proto.ChangePin(remove=True)) self.assertIsInstance(ret, proto.ButtonRequest) # Press button self.client.debug.press_yes() ret = self.client.call_raw(proto.ButtonAck()) # Send current PIN self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.read_pin_encoded() ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Now we're done self.assertIsInstance(ret, proto.Success) # Check that there's no PIN protection now features = self.client.call_raw(proto.Initialize()) self.assertFalse(features.pin_protection) ret = self.client.call_raw(proto.Ping(pin_protection=True)) self.assertIsInstance(ret, proto.Success) def test_set_failed(self): self.setup_mnemonic_nopin_nopassphrase() features = self.client.call_raw(proto.Initialize()) self.assertFalse(features.pin_protection) # Check that there's no PIN protection ret = self.client.call_raw(proto.Ping(pin_protection=True)) self.assertIsInstance(ret, proto.Success) # Let's set new PIN ret = self.client.call_raw(proto.ChangePin()) self.assertIsInstance(ret, proto.ButtonRequest) # Press button self.client.debug.press_yes() ret = self.client.call_raw(proto.ButtonAck()) # Send the PIN for first time self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.encode_pin(self.pin6) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Send the PIN for second time, but with typo self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.encode_pin(self.pin4) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Now it should fail, because pins are different self.assertIsInstance(ret, proto.Failure) # Check that there's still no PIN protection now features = self.client.call_raw(proto.Initialize()) self.assertFalse(features.pin_protection) ret = self.client.call_raw(proto.Ping(pin_protection=True)) self.assertIsInstance(ret, proto.Success) def test_set_failed_2(self): self.setup_mnemonic_pin_passphrase() features = self.client.call_raw(proto.Initialize()) self.assertTrue(features.pin_protection) # Let's set new PIN ret = self.client.call_raw(proto.ChangePin()) self.assertIsInstance(ret, proto.ButtonRequest) # Press button self.client.debug.press_yes() ret = self.client.call_raw(proto.ButtonAck()) # Send current PIN self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.read_pin_encoded() ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Send the PIN for first time self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.encode_pin(self.pin6) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Send the PIN for second time, but with typo self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.encode_pin(self.pin6 + '3') ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Now it should fail, because pins are different self.assertIsInstance(ret, proto.Failure) # Check that there's still old PIN protection features = self.client.call_raw(proto.Initialize()) self.assertTrue(features.pin_protection) self.assertEqual(self.client.debug.read_pin()[0], self.pin4) if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_cipherkeyvalue.py0000644000175000001440000001127613123262617024562 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . import unittest import common import binascii class TestMsgCipherkeyvalue(common.TrezorTest): def test_encrypt(self): self.setup_mnemonic_nopin_nopassphrase() # different ask values res = self.client.encrypt_keyvalue([0, 1, 2], b"test", b"testing message!", ask_on_encrypt=True, ask_on_decrypt=True) self.assertEqual(binascii.hexlify(res), b'676faf8f13272af601776bc31bc14e8f') res = self.client.encrypt_keyvalue([0, 1, 2], b"test", b"testing message!", ask_on_encrypt=True, ask_on_decrypt=False) self.assertEqual(binascii.hexlify(res), b'5aa0fbcb9d7fa669880745479d80c622') res = self.client.encrypt_keyvalue([0, 1, 2], b"test", b"testing message!", ask_on_encrypt=False, ask_on_decrypt=True) self.assertEqual(binascii.hexlify(res), b'958d4f63269b61044aaedc900c8d6208') res = self.client.encrypt_keyvalue([0, 1, 2], b"test", b"testing message!", ask_on_encrypt=False, ask_on_decrypt=False) self.assertEqual(binascii.hexlify(res), b'e0cf0eb0425947000eb546cc3994bc6c') # different key res = self.client.encrypt_keyvalue([0, 1, 2], b"test2", b"testing message!", ask_on_encrypt=True, ask_on_decrypt=True) self.assertEqual(binascii.hexlify(res), b'de247a6aa6be77a134bb3f3f925f13af') # different message res = self.client.encrypt_keyvalue([0, 1, 2], b"test", b"testing message! it is different", ask_on_encrypt=True, ask_on_decrypt=True) self.assertEqual(binascii.hexlify(res), b'676faf8f13272af601776bc31bc14e8f3ae1c88536bf18f1b44f1e4c2c4a613d') # different path res = self.client.encrypt_keyvalue([0, 1, 3], b"test", b"testing message!", ask_on_encrypt=True, ask_on_decrypt=True) self.assertEqual(binascii.hexlify(res), b'b4811a9d492f5355a5186ddbfccaae7b') def test_decrypt(self): self.setup_mnemonic_nopin_nopassphrase() # different ask values res = self.client.decrypt_keyvalue([0, 1, 2], b"test", binascii.unhexlify("676faf8f13272af601776bc31bc14e8f"), ask_on_encrypt=True, ask_on_decrypt=True) self.assertEqual(res, b'testing message!') res = self.client.decrypt_keyvalue([0, 1, 2], b"test", binascii.unhexlify("5aa0fbcb9d7fa669880745479d80c622"), ask_on_encrypt=True, ask_on_decrypt=False) self.assertEqual(res, b'testing message!') res = self.client.decrypt_keyvalue([0, 1, 2], b"test", binascii.unhexlify("958d4f63269b61044aaedc900c8d6208"), ask_on_encrypt=False, ask_on_decrypt=True) self.assertEqual(res, b'testing message!') res = self.client.decrypt_keyvalue([0, 1, 2], b"test", binascii.unhexlify("e0cf0eb0425947000eb546cc3994bc6c"), ask_on_encrypt=False, ask_on_decrypt=False) self.assertEqual(res, b'testing message!') # different key res = self.client.decrypt_keyvalue([0, 1, 2], b"test2", binascii.unhexlify("de247a6aa6be77a134bb3f3f925f13af"), ask_on_encrypt=True, ask_on_decrypt=True) self.assertEqual(res, b'testing message!') # different message res = self.client.decrypt_keyvalue([0, 1, 2], b"test", binascii.unhexlify("676faf8f13272af601776bc31bc14e8f3ae1c88536bf18f1b44f1e4c2c4a613d"), ask_on_encrypt=True, ask_on_decrypt=True) self.assertEqual(res, b'testing message! it is different') # different path res = self.client.decrypt_keyvalue([0, 1, 3], b"test", binascii.unhexlify("b4811a9d492f5355a5186ddbfccaae7b"), ask_on_encrypt=True, ask_on_decrypt=True) self.assertEqual(res, b'testing message!') def test_encrypt_badlen(self): self.setup_mnemonic_nopin_nopassphrase() self.assertRaises(Exception, self.client.encrypt_keyvalue, [0, 1, 2], b"test", b"testing") def test_decrypt_badlen(self): self.setup_mnemonic_nopin_nopassphrase() self.assertRaises(Exception, self.client.decrypt_keyvalue, [0, 1, 2], b"test", b"testing") if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_clearsession.py0000644000175000001440000000523413123262620024223 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . import unittest import common from trezorlib import messages_pb2 as proto from trezorlib import types_pb2 as proto_types class TestMsgClearsession(common.TrezorTest): def test_clearsession(self): self.setup_mnemonic_pin_passphrase() with self.client: self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ProtectCall), proto.PinMatrixRequest(), proto.PassphraseRequest(), proto.Success()]) res = self.client.ping('random data', button_protection=True, pin_protection=True, passphrase_protection=True) self.assertEqual(res, 'random data') with self.client: # pin and passphrase are cached self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ProtectCall), proto.Success()]) res = self.client.ping('random data', button_protection=True, pin_protection=True, passphrase_protection=True) self.assertEqual(res, 'random data') self.client.clear_session() # session cache is cleared with self.client: self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ProtectCall), proto.PinMatrixRequest(), proto.PassphraseRequest(), proto.Success()]) res = self.client.ping('random data', button_protection=True, pin_protection=True, passphrase_protection=True) self.assertEqual(res, 'random data') with self.client: # pin and passphrase are cached self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ProtectCall), proto.Success()]) res = self.client.ping('random data', button_protection=True, pin_protection=True, passphrase_protection=True) self.assertEqual(res, 'random data') if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_estimatetxsize.py0000644000175000001440000000347413124206211024612 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . import unittest import binascii import common import trezorlib.types_pb2 as proto_types class TestMsgEstimatetxsize(common.TrezorTest): def test_estimate_size(self): self.setup_mnemonic_nopin_nopassphrase() inp1 = proto_types.TxInputType( address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e # amount=390000, prev_hash=binascii.unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'), prev_index=0, ) out1 = proto_types.TxOutputType( address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1', amount=390000 - 10000, script_type=proto_types.PAYTOADDRESS, ) est_size = self.client.estimate_tx_size('Bitcoin', [inp1, ], [out1, ]) self.assertEqual(est_size, 194) (_, tx) = self.client.sign_tx('Bitcoin', [inp1, ], [out1, ]) real_size = len(tx) self.assertGreaterEqual(est_size, real_size) if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_ethereum_getaddress.py0000644000175000001440000000327213123262234025555 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . import unittest import common import binascii class TestMsgEthereumGetaddress(common.TrezorTest): def test_ethereum_getaddress(self): self.setup_mnemonic_nopin_nopassphrase() self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([])), b'1d1c328764a41bda0492b66baa30c4a339ff85ef') self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([1])), b'437207ca3cf43bf2e47dea0756d736c5df4f597a') self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([0, -1])), b'e5d96dfa07bcf1a3ae43677840c31394258861bf') self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([-9, 0])), b'f68804ac9eca9483ab4241d3e4751590d2c05102') self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([0, 9999999])), b'7a6366ecfcaf0d5dcc1539c171696c6cdd1eb8ed') if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_ethereum_signtx.py0000644000175000001440000002437713123263302024752 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . import unittest import common import binascii class TestMsgEthereumSigntx(common.TrezorTest): def test_ethereum_signtx_nodata(self): self.setup_mnemonic_nopin_nopassphrase() sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( n=[0, 0], nonce=0, gas_price=20, gas_limit=20, to=binascii.unhexlify('1d1c328764a41bda0492b66baa30c4a339ff85ef'), value=10) self.assertEqual(sig_v, 27) self.assertEqual(binascii.hexlify(sig_r), '9b61192a161d056c66cfbbd331edb2d783a0193bd4f65f49ee965f791d898f72') self.assertEqual(binascii.hexlify(sig_s), '49c0bbe35131592c6ed5c871ac457feeb16a1493f64237387fab9b83c1a202f7') sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( n=[0, 0], nonce=123456, gas_price=20000, gas_limit=20000, to=binascii.unhexlify('1d1c328764a41bda0492b66baa30c4a339ff85ef'), value=12345678901234567890) self.assertEqual(sig_v, 28) self.assertEqual(binascii.hexlify(sig_r), '6de597b8ec1b46501e5b159676e132c1aa78a95bd5892ef23560a9867528975a') self.assertEqual(binascii.hexlify(sig_s), '6e33c4230b1ecf96a8dbb514b4aec0a6d6ba53f8991c8143f77812aa6daa993f') def test_ethereum_signtx_data(self): self.setup_mnemonic_nopin_nopassphrase() sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( n=[0, 0], nonce=0, gas_price=20, gas_limit=20, to=binascii.unhexlify('1d1c328764a41bda0492b66baa30c4a339ff85ef'), value=10, data='abcdefghijklmnop' * 16) self.assertEqual(sig_v, 28) self.assertEqual(binascii.hexlify(sig_r), '6da89ed8627a491bedc9e0382f37707ac4e5102e25e7a1234cb697cedb7cd2c0') self.assertEqual(binascii.hexlify(sig_s), '691f73b145647623e2d115b208a7c3455a6a8a83e3b4db5b9c6d9bc75825038a') sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( n=[0, 0], nonce=123456, gas_price=20000, gas_limit=20000, to=binascii.unhexlify('1d1c328764a41bda0492b66baa30c4a339ff85ef'), value=12345678901234567890, data='ABCDEFGHIJKLMNOP' * 256 + '!!!') self.assertEqual(sig_v, 28) self.assertEqual(binascii.hexlify(sig_r), '4e90b13c45c6a9bf4aaad0e5427c3e62d76692b36eb727c78d332441b7400404') self.assertEqual(binascii.hexlify(sig_s), '3ff236e7d05f0f9b1ee3d70599bb4200638f28388a8faf6bb36db9e04dc544be') def test_ethereum_signtx_message(self): self.setup_mnemonic_nopin_nopassphrase() sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( n=[0, 0], nonce=0, gas_price=20000, gas_limit=20000, to=binascii.unhexlify('1d1c328764a41bda0492b66baa30c4a339ff85ef'), value=0, data='ABCDEFGHIJKLMNOP' * 256 + '!!!') self.assertEqual(sig_v, 28) self.assertEqual(binascii.hexlify(sig_r), '070e9dafda4d9e733fa7b6747a75f8a4916459560efb85e3e73cd39f31aa160d') self.assertEqual(binascii.hexlify(sig_s), '7842db33ef15c27049ed52741db41fe3238a6fa3a6a0888fcfb74d6917600e41') def test_ethereum_signtx_newcontract(self): self.setup_mnemonic_nopin_nopassphrase() # contract creation without data should fail. self.assertRaises( Exception, self.client.ethereum_sign_tx, n=[0, 0], nonce=123456, gas_price=20000, gas_limit=20000, to='', value=12345678901234567890 ) sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( n=[0, 0], nonce=0, gas_price=20000, gas_limit=20000, to='', value=12345678901234567890, data='ABCDEFGHIJKLMNOP' * 256 + '!!!') self.assertEqual(sig_v, 28) self.assertEqual(binascii.hexlify(sig_r), 'b401884c10ae435a2e792303b5fc257a09f94403b2883ad8c0ac7a7282f5f1f9') self.assertEqual(binascii.hexlify(sig_s), '4742fc9e6a5fa8db3db15c2d856914a7f3daab21603a6c1ce9e9927482f8352e') def test_ethereum_sanity_checks(self): # gas overflow self.assertRaises( Exception, self.client.ethereum_sign_tx, n=[0, 0], nonce=123456, gas_price=0xffffffffffffffffffffffffffffffff, gas_limit=0xffffffffffffffffffffffffffffff, to=binascii.unhexlify('1d1c328764a41bda0492b66baa30c4a339ff85ef'), value=12345678901234567890 ) # no gas price self.assertRaises( Exception, self.client.ethereum_sign_tx, n=[0, 0], nonce=123456, gas_limit=10000, to=binascii.unhexlify('1d1c328764a41bda0492b66baa30c4a339ff85ef'), value=12345678901234567890 ) # no gas limit self.assertRaises( Exception, self.client.ethereum_sign_tx, n=[0, 0], nonce=123456, gas_price=10000, to=binascii.unhexlify('1d1c328764a41bda0492b66baa30c4a339ff85ef'), value=12345678901234567890 ) # no nonce self.assertRaises( Exception, self.client.ethereum_sign_tx, n=[0, 0], gas_price=10000, gas_limit=123456, to=binascii.unhexlify('1d1c328764a41bda0492b66baa30c4a339ff85ef'), value=12345678901234567890 ) def test_ethereum_signtx_nodata_eip155(self): self.setup_mnemonic_allallall() sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( n=[0x80000000 | 44, 0x80000000 | 1, 0x80000000, 0, 0], nonce=0, gas_price=20000000000, gas_limit=21000, to=binascii.unhexlify('8ea7a3fccc211ed48b763b4164884ddbcf3b0a98'), value=100000000000000000, chain_id=3) self.assertEqual(sig_v, 41) self.assertEqual(binascii.hexlify(sig_r), 'a90d0bc4f8d63be69453dd62f2bb5fff53c610000abf956672564d8a654d401a') self.assertEqual(binascii.hexlify(sig_s), '544a2e57bc8b4da18660a1e6036967ea581cc635f5137e3ba97a750867c27cf2') sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( n=[0x80000000 | 44, 0x80000000 | 1, 0x80000000, 0, 0], nonce=1, gas_price=20000000000, gas_limit=21000, to=binascii.unhexlify('8ea7a3fccc211ed48b763b4164884ddbcf3b0a98'), value=100000000000000000, chain_id=3) self.assertEqual(sig_v, 42) self.assertEqual(binascii.hexlify(sig_r), '699428a6950e23c6843f1bf3754f847e64e047e829978df80d55187d19a401ce') self.assertEqual(binascii.hexlify(sig_s), '087343d0a3a2f10842218ffccb146b59a8431b6245ab389fde22dc833f171e6e') def test_ethereum_signtx_data_eip155(self): self.setup_mnemonic_allallall() sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( n=[0x80000000 | 44, 0x80000000 | 1, 0x80000000, 0, 0], nonce=2, gas_price=20000000000, gas_limit=21004, to=binascii.unhexlify('8ea7a3fccc211ed48b763b4164884ddbcf3b0a98'), value=100000000000000000, data='\0', chain_id=3) self.assertEqual(sig_v, 42) self.assertEqual(binascii.hexlify(sig_r), 'ba85b622a8bb82606ba96c132e81fa8058172192d15bc41d7e57c031bca17df4') self.assertEqual(binascii.hexlify(sig_s), '6473b75997634b6f692f8d672193591d299d5bf1c2d6e51f1a14ed0530b91c7d') sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( n=[0x80000000 | 44, 0x80000000 | 1, 0x80000000, 0, 0], nonce=3, gas_price=20000000000, gas_limit=299732, to=binascii.unhexlify('8ea7a3fccc211ed48b763b4164884ddbcf3b0a98'), value=100000000000000000, data='ABCDEFGHIJKLMNOP' * 256 + '!!!', chain_id=3) self.assertEqual(sig_v, 42) self.assertEqual(binascii.hexlify(sig_r), 'd021c98f92859c8db5e4de2f0e410a8deb0c977eb1a631e323ebf7484bd0d79a') self.assertEqual(binascii.hexlify(sig_s), '2c0e9defc9b1e895dc9520ff25ba3c635b14ad70aa86a5ad6c0a3acb82b569b6') sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( n=[0x80000000 | 44, 0x80000000 | 1, 0x80000000, 0, 0], nonce=4, gas_price=20000000000, gas_limit=21004, to=binascii.unhexlify('8ea7a3fccc211ed48b763b4164884ddbcf3b0a98'), value=0, data='\0', chain_id=3) self.assertEqual(sig_v, 42) self.assertEqual(binascii.hexlify(sig_r), 'dd52f026972a83c56b7dea356836fcfc70a68e3b879cdc8ef2bb5fea23e0a7aa') self.assertEqual(binascii.hexlify(sig_s), '079285fe579c9a2da25c811b1c5c0a74cd19b6301ee42cf20ef7b3b1353f7242') sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( n=[0x80000000 | 44, 0x80000000 | 1, 0x80000000, 0, 0], nonce=5, gas_price=0, gas_limit=21004, to=binascii.unhexlify('8ea7a3fccc211ed48b763b4164884ddbcf3b0a98'), value=0, data='\0', chain_id=3) self.assertEqual(sig_v, 42) self.assertEqual(binascii.hexlify(sig_r), 'f7505f709d5999343aea3c384034c62d0514336ff6c6af65582006f708f81503') self.assertEqual(binascii.hexlify(sig_s), '44e09e29a4b6247000b46ddc94fe391e94deb2b39ad6ac6398e6db5bec095ba9') if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_getaddress.py0000644000175000001440000000570313123263057023664 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . import unittest import common import trezorlib.ckd_public as bip32 class TestMsgGetaddress(common.TrezorTest): def test_btc(self): self.setup_mnemonic_nopin_nopassphrase() self.assertEqual(self.client.get_address('Bitcoin', []), '1EfKbQupktEMXf4gujJ9kCFo83k1iMqwqK') self.assertEqual(self.client.get_address('Bitcoin', [1]), '1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb') self.assertEqual(self.client.get_address('Bitcoin', [0, -1]), '1JVq66pzRBvqaBRFeU9SPVvg3er4ZDgoMs') self.assertEqual(self.client.get_address('Bitcoin', [-9, 0]), '1F4YdQdL9ZQwvcNTuy5mjyQxXkyCfMcP2P') self.assertEqual(self.client.get_address('Bitcoin', [0, 9999999]), '1GS8X3yc7ntzwGw9vXwj9wqmBWZkTFewBV') def test_ltc(self): self.setup_mnemonic_nopin_nopassphrase() self.assertEqual(self.client.get_address('Litecoin', []), 'LYtGrdDeqYUQnTkr5sHT2DKZLG7Hqg7HTK') self.assertEqual(self.client.get_address('Litecoin', [1]), 'LKRGNecThFP3Q6c5fosLVA53Z2hUDb1qnE') self.assertEqual(self.client.get_address('Litecoin', [0, -1]), 'LcinMK8pVrAtpz7Qpc8jfWzSFsDLgLYfG6') self.assertEqual(self.client.get_address('Litecoin', [-9, 0]), 'LZHVtcwAEDf1BR4d67551zUijyLUpDF9EX') self.assertEqual(self.client.get_address('Litecoin', [0, 9999999]), 'Laf5nGHSCT94C5dK6fw2RxuXPiw2ZuRR9S') def test_tbtc(self): self.setup_mnemonic_nopin_nopassphrase() self.assertEqual(self.client.get_address('Testnet', [111, 42]), 'moN6aN6NP1KWgnPSqzrrRPvx2x1UtZJssa') def test_public_ckd(self): self.setup_mnemonic_nopin_nopassphrase() node = self.client.get_public_node([]).node node_sub1 = self.client.get_public_node([1]).node node_sub2 = bip32.public_ckd(node, [1]) self.assertEqual(node_sub1.chain_code, node_sub2.chain_code) self.assertEqual(node_sub1.public_key, node_sub2.public_key) address1 = self.client.get_address('Bitcoin', [1]) address2 = bip32.get_address(node_sub2, 0) self.assertEqual(address2, '1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb') self.assertEqual(address1, address2) if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_getaddress_segwit.py0000644000175000001440000000452013123262560025240 0ustar stickusers00000000000000import unittest import common import trezorlib.ckd_public as bip32 import trezorlib.types_pb2 as proto_types class TestMsgGetaddressSegwit(common.TrezorTest): def test_show_segwit(self): self.setup_mnemonic_allallall() self.assertEqual(self.client.get_address("Testnet", self.client.expand_path("49'/1'/0'/1/0"), True, None, script_type=proto_types.SPENDP2SHWITNESS), '2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX') self.assertEqual(self.client.get_address("Testnet", self.client.expand_path("49'/1'/0'/0/0"), False, None, script_type=proto_types.SPENDP2SHWITNESS), '2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp') self.assertEqual(self.client.get_address("Testnet", self.client.expand_path("44'/1'/0'/0/0"), False, None, script_type=proto_types.SPENDP2SHWITNESS), '2N6UeBoqYEEnybg4cReFYDammpsyDw8R2Mc') self.assertEqual(self.client.get_address("Testnet", self.client.expand_path("44'/1'/0'/0/0"), False, None, script_type=proto_types.SPENDADDRESS), 'mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q') def test_show_multisig_3(self): self.setup_mnemonic_allallall() nodes = map(lambda index: self.client.get_public_node(self.client.expand_path("999'/1'/%d'" % index)), range(1, 4)) multisig1 = proto_types.MultisigRedeemScriptType( pubkeys=map(lambda n: proto_types.HDNodePathType(node=bip32.deserialize(n.xpub), address_n=[2, 0]), nodes), signatures=[b'', b'', b''], m=2, ) # multisig2 = proto_types.MultisigRedeemScriptType( # pubkeys=map(lambda n: proto_types.HDNodePathType(node=bip32.deserialize(n.xpub), address_n=[2, 1]), nodes), # signatures=[b'', b'', b''], # m=2, # ) for i in [1, 2, 3]: self.assertEqual(self.client.get_address("Testnet", self.client.expand_path("999'/1'/%d'/2/0" % i), False, multisig1, script_type=proto_types.SPENDP2SHWITNESS), '2N2MxyAfifVhb3AMagisxaj3uij8bfXqf4Y') if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_getaddress_segwit_native.py0000644000175000001440000000520513123263313026604 0ustar stickusers00000000000000import unittest import common import trezorlib.ckd_public as bip32 import trezorlib.types_pb2 as proto_types class TestMsgGetaddressSegwitNative(common.TrezorTest): def test_show_segwit(self): self.setup_mnemonic_allallall() self.assertEqual(self.client.get_address("Testnet", self.client.expand_path("49'/1'/0'/0/0"), True, None, script_type=proto_types.SPENDWITNESS), 'QWywnqNMsMNavbCgMYiQLa91ApvsVRoaqt1i') self.assertEqual(self.client.get_address("Testnet", self.client.expand_path("49'/1'/0'/1/0"), False, None, script_type=proto_types.SPENDWITNESS), 'QWzGpyMkAEvmkSVprBzRRVQMP6UPp17q4kQn') self.assertEqual(self.client.get_address("Testnet", self.client.expand_path("44'/1'/0'/0/0"), False, None, script_type=proto_types.SPENDWITNESS), 'QWzCpc1NeTN7hNDzK9sQQ9yrTQP8zh5Hef5J') self.assertEqual(self.client.get_address("Testnet", self.client.expand_path("44'/1'/0'/0/0"), False, None, script_type=proto_types.SPENDADDRESS), 'mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q') def test_show_multisig_3(self): self.setup_mnemonic_allallall() nodes = map(lambda index: self.client.get_public_node(self.client.expand_path("999'/1'/%d'" % index)), range(1, 4)) multisig1 = proto_types.MultisigRedeemScriptType( pubkeys=map(lambda n: proto_types.HDNodePathType(node=bip32.deserialize(n.xpub), address_n=[2, 0]), nodes), signatures=[b'', b'', b''], m=2, ) multisig2 = proto_types.MultisigRedeemScriptType( pubkeys=map(lambda n: proto_types.HDNodePathType(node=bip32.deserialize(n.xpub), address_n=[2, 1]), nodes), signatures=[b'', b'', b''], m=2, ) for i in [1, 2, 3]: self.assertEqual(self.client.get_address("Testnet", self.client.expand_path("999'/1'/%d'/2/1" % i), False, multisig2, script_type=proto_types.SPENDWITNESS), 'T7nZJt6QbGJy6Hok4EF2LqtJPcT7z7VFSrSysGS3tEqCfDPwizqy4') self.assertEqual(self.client.get_address("Testnet", self.client.expand_path("999'/1'/%d'/2/0" % i), False, multisig1, script_type=proto_types.SPENDWITNESS), 'T7nY3A3kewpDKumsdhonP4TBDfTXFSc2RNhZxkqmeeszRDHjM5yUn') if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_getaddress_show.py0000644000175000001440000000557613123263035024730 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . import unittest import common import trezorlib.ckd_public as bip32 import trezorlib.types_pb2 as proto_types class TestMsgGetaddress(common.TrezorTest): def test_show(self): self.setup_mnemonic_nopin_nopassphrase() self.assertEqual(self.client.get_address('Bitcoin', [1], show_display=True), '1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb') self.assertEqual(self.client.get_address('Bitcoin', [2], show_display=True), '15AeAhtNJNKyowK8qPHwgpXkhsokzLtUpG') self.assertEqual(self.client.get_address('Bitcoin', [3], show_display=True), '1CmzyJp9w3NafXMSEFH4SLYUPAVCSUrrJ5') def test_show_multisig_3(self): self.setup_mnemonic_nopin_nopassphrase() node = bip32.deserialize('xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy') multisig = proto_types.MultisigRedeemScriptType( pubkeys=[ proto_types.HDNodePathType(node=node, address_n=[1]), proto_types.HDNodePathType(node=node, address_n=[2]), proto_types.HDNodePathType(node=node, address_n=[3]) ], signatures=[b'', b'', b''], m=2, ) for i in [1, 2, 3]: self.assertEqual(self.client.get_address('Bitcoin', [i], show_display=True, multisig=multisig), '3E7GDtuHqnqPmDgwH59pVC7AvySiSkbibz') def test_show_multisig_15(self): self.setup_mnemonic_nopin_nopassphrase() node = bip32.deserialize('xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy') pubs = [] for x in range(15): pubs.append(proto_types.HDNodePathType(node=node, address_n=[x])) multisig = proto_types.MultisigRedeemScriptType( pubkeys=pubs, signatures=[b''] * 15, m=15, ) for i in range(15): self.assertEqual(self.client.get_address('Bitcoin', [i], show_display=True, multisig=multisig), '3QaKF8zobqcqY8aS6nxCD5ZYdiRfL3RCmU') if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_getentropy.py0000644000175000001440000000341113123262530023724 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . from __future__ import print_function import unittest import math import common import trezorlib.messages_pb2 as proto import trezorlib.types_pb2 as proto_types def entropy(data): counts = {} for c in data: if c in counts: counts[c] += 1 else: counts[c] = 1 e = 0 for _, v in counts.items(): p = 1.0 * v / len(data) e -= p * math.log(p, 256) return e class TestMsgGetentropy(common.TrezorTest): def test_entropy(self): for l in [0, 1, 2, 3, 4, 5, 8, 9, 16, 17, 32, 33, 64, 65, 128, 129, 256, 257, 512, 513, 1024]: with self.client: self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ProtectCall), proto.Entropy()]) ent = self.client.get_entropy(l) self.assertTrue(len(ent) == l) print('entropy = ', entropy(ent)) if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_getpublickey.py0000644000175000001440000000673213123262601024223 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . import unittest import common import trezorlib.ckd_public as bip32 class TestMsgGetpublic_key(common.TrezorTest): def test_btc(self): self.setup_mnemonic_nopin_nopassphrase() self.assertEqual(bip32.serialize(self.client.get_public_node([]).node, 0x0488B21E), 'xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy') self.assertEqual(bip32.serialize(self.client.get_public_node([1]).node, 0x0488B21E), 'xpub68zNxjsTrV8y9AadThLW7dTAqEpZ7xBLFSyJ3X9pjTv6Njg6kxgjXJkzxq8u3ttnjBw1jupQHMP3gpGZzZqd1eh5S4GjkaMhPR18vMyUi8N') self.assertEqual(bip32.serialize(self.client.get_public_node([0, -1]).node, 0x0488B21E), 'xpub6A3FoZqYXj1AbW4thRwBh26YwZWbmoyjTaZwwxJjY1oKUpefLepL3RFS9DHKQrjAfxDrzDepYMDZPqXN6upQm3bHQ9xaXD5a3mqni3goF4v') self.assertEqual(bip32.serialize(self.client.get_public_node([-9, 0]).node, 0x0488B21E), 'xpub6A2h5mzLDfYginoD7q7wCWbq18wTbN9gducRr2w5NRTwdLeoT3cJSwefFqW7uXTpVFGtpUyDMBNYs3DNvvXx6NPjF9YEbUQrtxFSWnPtVrv') self.assertEqual(bip32.serialize(self.client.get_public_node([0, 9999999]).node, 0x0488B21E), 'xpub6A3FoZqQEK6iwLZ4HFkqSo5fb35BH4bpjC4SPZ63prfLdGYPwYxEuC6o91bUvFFdMzKWe5rs3axHRUjxJaSvBnKKFtnfLwDACRxPxabsv2r') def test_ltc(self): self.setup_mnemonic_nopin_nopassphrase() self.assertEqual(bip32.serialize(self.client.get_public_node([]).node, 0x019dA462), 'Ltub2SSUS19CirucVPGDKDBatBDBEM2s9UbH66pBURfaKrMocCPLhQ7Z7hecy5VYLHA5fRdXwB2e61j2VJCNzVsqKTCVEU1vECjqi5EyczFX9xp') self.assertEqual(bip32.serialize(self.client.get_public_node([1]).node, 0x019dA462), 'Ltub2VRVRP5VjvSyPXra4BLVyVZPv397sjhUNjBGsbtw6xko77JuQyBULxFSKheviJJ3KQLbL3Cx8P2RnudguTw4raUVjCACRG7jsumUptYx55C') self.assertEqual(bip32.serialize(self.client.get_public_node([0, -1]).node, 0x019dA462), 'Ltub2WUNGD3aRAKAqsLqHuwBYtCn2MqAXbVsarmvn33quWe2DCHTzfK4s4jsW5oM5G8RGAdSaM3NPNrwVvtV1ourbyNhhHr3BtqcYGc8caf5GoT') self.assertEqual(bip32.serialize(self.client.get_public_node([-9, 0]).node, 0x019dA462), 'Ltub2WToYRCN76rgyA59iK7w4Ni45wG2M9fpmBpQg7gBjvJeMiHc7473Gb96ci29Zvs55TgUQcMmCD1vy8aVqpdPwJB9YHRhGAAuPT1nRLLXmFu') self.assertEqual(bip32.serialize(self.client.get_public_node([0, 9999999]).node, 0x019dA462), 'Ltub2WUNGD3S7kQjBhpzsjkqJfBtfqPk2r7xrUGRDdqACMW3MeBCbZSyiqbEVt7WaeesxCj6EDFQtcbfXa75DUYN2i6jZ2g81cyCgvijs9J2u2n') def test_tbtc(self): self.setup_mnemonic_nopin_nopassphrase() self.assertEqual(bip32.serialize(self.client.get_public_node([111, 42]).node, 0x043587CF), 'tpubDAgixSyai5PWbc8N1mBkHDR5nLgAnHFtY7r4y5EzxqAxrt9YUDpZL3kaRoHVvCfrcwNo31c2isBP2uTHcZxEosuKbyJhCAbrvGoPuLUZ7Mz') if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_loaddevice.py0000644000175000001440000001133113123262614023626 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . import unittest import common class TestDeviceLoad(common.TrezorTest): def test_load_device_1(self): self.setup_mnemonic_nopin_nopassphrase() mnemonic = self.client.debug.read_mnemonic() self.assertEqual(mnemonic, self.mnemonic12) pin = self.client.debug.read_pin()[0] self.assertEqual(pin, '') passphrase_protection = self.client.debug.read_passphrase_protection() self.assertEqual(passphrase_protection, False) address = self.client.get_address('Bitcoin', []) self.assertEqual(address, '1EfKbQupktEMXf4gujJ9kCFo83k1iMqwqK') def test_load_device_2(self): self.setup_mnemonic_pin_passphrase() self.client.set_passphrase('passphrase') mnemonic = self.client.debug.read_mnemonic() self.assertEqual(mnemonic, self.mnemonic12) pin = self.client.debug.read_pin()[0] self.assertEqual(pin, self.pin4) passphrase_protection = self.client.debug.read_passphrase_protection() self.assertEqual(passphrase_protection, True) address = self.client.get_address('Bitcoin', []) self.assertEqual(address, '15fiTDFwZd2kauHYYseifGi9daH2wniDHH') def test_load_device_utf(self): words_nfkd = u'Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a' words_nfc = u'P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f' words_nfkc = u'P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f' words_nfd = u'Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a' passphrase_nfkd = u'Neuve\u030cr\u030citelne\u030c bezpec\u030cne\u0301 hesli\u0301c\u030cko' passphrase_nfc = u'Neuv\u011b\u0159iteln\u011b bezpe\u010dn\xe9 hesl\xed\u010dko' passphrase_nfkc = u'Neuv\u011b\u0159iteln\u011b bezpe\u010dn\xe9 hesl\xed\u010dko' passphrase_nfd = u'Neuve\u030cr\u030citelne\u030c bezpec\u030cne\u0301 hesli\u0301c\u030cko' self.client.wipe_device() self.client.load_device_by_mnemonic(mnemonic=words_nfkd, pin='', passphrase_protection=True, label='test', language='english', skip_checksum=True) self.client.set_passphrase(passphrase_nfkd) address_nfkd = self.client.get_address('Bitcoin', []) self.client.wipe_device() self.client.load_device_by_mnemonic(mnemonic=words_nfc, pin='', passphrase_protection=True, label='test', language='english', skip_checksum=True) self.client.set_passphrase(passphrase_nfc) address_nfc = self.client.get_address('Bitcoin', []) self.client.wipe_device() self.client.load_device_by_mnemonic(mnemonic=words_nfkc, pin='', passphrase_protection=True, label='test', language='english', skip_checksum=True) self.client.set_passphrase(passphrase_nfkc) address_nfkc = self.client.get_address('Bitcoin', []) self.client.wipe_device() self.client.load_device_by_mnemonic(mnemonic=words_nfd, pin='', passphrase_protection=True, label='test', language='english', skip_checksum=True) self.client.set_passphrase(passphrase_nfd) address_nfd = self.client.get_address('Bitcoin', []) self.assertEqual(address_nfkd, address_nfc) self.assertEqual(address_nfkd, address_nfkc) self.assertEqual(address_nfkd, address_nfd) if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_loaddevice_xprv.py0000644000175000001440000000403613123262311024703 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . import unittest import common class TestDeviceLoadXprv(common.TrezorTest): def test_load_device_xprv_1(self): self.client.load_device_by_xprv(xprv='xprv9s21ZrQH143K2JF8RafpqtKiTbsbaxEeUaMnNHsm5o6wCW3z8ySyH4UxFVSfZ8n7ESu7fgir8imbZKLYVBxFPND1pniTZ81vKfd45EHKX73', pin='', passphrase_protection=False, label='test', language='english') passphrase_protection = self.client.debug.read_passphrase_protection() self.assertEqual(passphrase_protection, False) address = self.client.get_address('Bitcoin', []) self.assertEqual(address, '128RdrAkJDmqasgvfRf6MC5VcX4HKqH4mR') def test_load_device_xprv_2(self): self.client.load_device_by_xprv(xprv='xprv9s21ZrQH143K2JF8RafpqtKiTbsbaxEeUaMnNHsm5o6wCW3z8ySyH4UxFVSfZ8n7ESu7fgir8imbZKLYVBxFPND1pniTZ81vKfd45EHKX73', pin='', passphrase_protection=True, label='test', language='english') self.client.set_passphrase('passphrase') passphrase_protection = self.client.debug.read_passphrase_protection() self.assertEqual(passphrase_protection, True) address = self.client.get_address('Bitcoin', []) self.assertEqual(address, '1CHUbFa4wTTPYgkYaw2LHSd5D4qJjMU8ri') if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_ping.py0000644000175000001440000000553213123262603022470 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . import unittest import common from trezorlib import messages_pb2 as proto from trezorlib import types_pb2 as proto_types class TestPing(common.TrezorTest): def test_ping(self): self.setup_mnemonic_pin_passphrase() with self.client: self.client.set_expected_responses([proto.Success()]) res = self.client.ping('random data') self.assertEqual(res, 'random data') with self.client: self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ProtectCall), proto.Success()]) res = self.client.ping('random data', button_protection=True) self.assertEqual(res, 'random data') with self.client: self.client.set_expected_responses([proto.PinMatrixRequest(), proto.Success()]) res = self.client.ping('random data', pin_protection=True) self.assertEqual(res, 'random data') with self.client: self.client.set_expected_responses([proto.PassphraseRequest(), proto.Success()]) res = self.client.ping('random data', passphrase_protection=True) self.assertEqual(res, 'random data') def test_ping_caching(self): self.setup_mnemonic_pin_passphrase() with self.client: self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ProtectCall), proto.PinMatrixRequest(), proto.PassphraseRequest(), proto.Success()]) res = self.client.ping('random data', button_protection=True, pin_protection=True, passphrase_protection=True) self.assertEqual(res, 'random data') with self.client: # pin and passphrase are cached self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ProtectCall), proto.Success()]) res = self.client.ping('random data', button_protection=True, pin_protection=True, passphrase_protection=True) self.assertEqual(res, 'random data') if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_recoverydevice.py0000644000175000001440000001603213124206236024547 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . from __future__ import print_function import unittest import common from trezorlib import messages_pb2 as proto class TestDeviceRecovery(common.TrezorTest): def test_pin_passphrase(self): mnemonic = self.mnemonic12.split(' ') ret = self.client.call_raw(proto.RecoveryDevice(word_count=12, passphrase_protection=True, pin_protection=True, label='label', language='english', enforce_wordlist=True)) self.assertIsInstance(ret, proto.PinMatrixRequest) # Enter PIN for first time pin_encoded = self.client.debug.encode_pin(self.pin6) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) self.assertIsInstance(ret, proto.PinMatrixRequest) # Enter PIN for second time pin_encoded = self.client.debug.encode_pin(self.pin6) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) fakes = 0 for _ in range(int(12 * 2)): self.assertIsInstance(ret, proto.WordRequest) (word, pos) = self.client.debug.read_recovery_word() if pos != 0: ret = self.client.call_raw(proto.WordAck(word=mnemonic[pos - 1])) mnemonic[pos - 1] = None else: ret = self.client.call_raw(proto.WordAck(word=word)) fakes += 1 print(mnemonic) # Workflow succesfully ended self.assertIsInstance(ret, proto.Success) # 12 expected fake words and all words of mnemonic are used self.assertEqual(fakes, 12) self.assertEqual(mnemonic, [None] * 12) # Mnemonic is the same self.client.init_device() self.assertEqual(self.client.debug.read_mnemonic(), self.mnemonic12) self.assertTrue(self.client.features.pin_protection) self.assertTrue(self.client.features.passphrase_protection) # Do passphrase-protected action, PassphraseRequest should be raised resp = self.client.call_raw(proto.Ping(passphrase_protection=True)) self.assertIsInstance(resp, proto.PassphraseRequest) self.client.call_raw(proto.Cancel()) # Do PIN-protected action, PinRequest should be raised resp = self.client.call_raw(proto.Ping(pin_protection=True)) self.assertIsInstance(resp, proto.PinMatrixRequest) self.client.call_raw(proto.Cancel()) def test_nopin_nopassphrase(self): mnemonic = self.mnemonic12.split(' ') ret = self.client.call_raw(proto.RecoveryDevice(word_count=12, passphrase_protection=False, pin_protection=False, label='label', language='english', enforce_wordlist=True)) fakes = 0 for _ in range(int(12 * 2)): self.assertIsInstance(ret, proto.WordRequest) (word, pos) = self.client.debug.read_recovery_word() if pos != 0: ret = self.client.call_raw(proto.WordAck(word=mnemonic[pos - 1])) mnemonic[pos - 1] = None else: ret = self.client.call_raw(proto.WordAck(word=word)) fakes += 1 print(mnemonic) # Workflow succesfully ended self.assertIsInstance(ret, proto.Success) # 12 expected fake words and all words of mnemonic are used self.assertEqual(fakes, 12) self.assertEqual(mnemonic, [None] * 12) # Mnemonic is the same self.client.init_device() self.assertEqual(self.client.debug.read_mnemonic(), self.mnemonic12) self.assertFalse(self.client.features.pin_protection) self.assertFalse(self.client.features.passphrase_protection) # Do passphrase-protected action, PassphraseRequest should NOT be raised resp = self.client.call_raw(proto.Ping(passphrase_protection=True)) self.assertIsInstance(resp, proto.Success) # Do PIN-protected action, PinRequest should NOT be raised resp = self.client.call_raw(proto.Ping(pin_protection=True)) self.assertIsInstance(resp, proto.Success) def test_word_fail(self): ret = self.client.call_raw(proto.RecoveryDevice(word_count=12, passphrase_protection=False, pin_protection=False, label='label', language='english', enforce_wordlist=True)) self.assertIsInstance(ret, proto.WordRequest) for _ in range(int(12 * 2)): (word, pos) = self.client.debug.read_recovery_word() if pos != 0: ret = self.client.call_raw(proto.WordAck(word='kwyjibo')) self.assertIsInstance(ret, proto.Failure) break else: self.client.call_raw(proto.WordAck(word=word)) def test_pin_fail(self): ret = self.client.call_raw(proto.RecoveryDevice(word_count=12, passphrase_protection=True, pin_protection=True, label='label', language='english', enforce_wordlist=True)) self.assertIsInstance(ret, proto.PinMatrixRequest) # Enter PIN for first time pin_encoded = self.client.debug.encode_pin(self.pin4) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) self.assertIsInstance(ret, proto.PinMatrixRequest) # Enter PIN for second time, but different one pin_encoded = self.client.debug.encode_pin(self.pin6) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Failure should be raised self.assertIsInstance(ret, proto.Failure) def test_already_initialized(self): self.setup_mnemonic_nopin_nopassphrase() self.assertRaises(Exception, self.client.recovery_device, 12, False, False, 'label', 'english') if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_recoverydevice_dryrun.py0000644000175000001440000000517213124737655026173 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . from __future__ import print_function import unittest import common from trezorlib import messages_pb2 as proto class TestDeviceRecoveryDryRun(common.TrezorTest): def recovery_loop(self, mnemonic, result): ret = self.client.call_raw(proto.RecoveryDevice(word_count=12, passphrase_protection=False, pin_protection=False, label='label', language='english', enforce_wordlist=True, dry_run=True)) fakes = 0 for _ in range(int(12 * 2)): self.assertIsInstance(ret, proto.WordRequest) (word, pos) = self.client.debug.read_recovery_word() if pos != 0: ret = self.client.call_raw(proto.WordAck(word=mnemonic[pos - 1])) mnemonic[pos - 1] = None else: ret = self.client.call_raw(proto.WordAck(word=word)) fakes += 1 print(mnemonic) self.assertIsInstance(ret, proto.ButtonRequest) self.client.debug.press_yes() ret = self.client.call_raw(proto.ButtonAck()) self.assertIsInstance(ret, result) def test_correct_notsame(self): self.setup_mnemonic_nopin_nopassphrase() mnemonic = ['all'] * 12 self.recovery_loop(mnemonic, proto.Failure) def test_correct_same(self): self.setup_mnemonic_nopin_nopassphrase() mnemonic = self.mnemonic12.split(' ') self.recovery_loop(mnemonic, proto.Success) def test_incorrect(self): self.setup_mnemonic_nopin_nopassphrase() mnemonic = ['stick'] * 12 self.recovery_loop(mnemonic, proto.Failure) if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_resetdevice.py0000644000175000001440000001740013124750462024040 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . import unittest import common from trezorlib import messages_pb2 as proto from mnemonic import Mnemonic class TestDeviceReset(common.TrezorTest): def test_reset_device(self): # No PIN, no passphrase external_entropy = b'zlutoucky kun upel divoke ody' * 2 strength = 128 ret = self.client.call_raw(proto.ResetDevice( display_random=False, strength=strength, passphrase_protection=False, pin_protection=False, language='english', label='test' )) # Provide entropy self.assertIsInstance(ret, proto.EntropyRequest) internal_entropy = self.client.debug.read_reset_entropy() ret = self.client.call_raw(proto.EntropyAck(entropy=external_entropy)) # Generate mnemonic locally entropy = common.generate_entropy(strength, internal_entropy, external_entropy) expected_mnemonic = Mnemonic('english').to_mnemonic(entropy) mnemonic = [] for _ in range(strength // 32 * 3): self.assertIsInstance(ret, proto.ButtonRequest) mnemonic.append(self.client.debug.read_reset_word()) self.client.debug.press_yes() self.client.call_raw(proto.ButtonAck()) mnemonic = ' '.join(mnemonic) # Compare that device generated proper mnemonic for given entropies self.assertEqual(mnemonic, expected_mnemonic) mnemonic = [] for _ in range(strength // 32 * 3): self.assertIsInstance(ret, proto.ButtonRequest) mnemonic.append(self.client.debug.read_reset_word()) self.client.debug.press_yes() resp = self.client.call_raw(proto.ButtonAck()) self.assertIsInstance(resp, proto.Success) mnemonic = ' '.join(mnemonic) # Compare that second pass printed out the same mnemonic once again self.assertEqual(mnemonic, expected_mnemonic) # Check if device is properly initialized resp = self.client.call_raw(proto.Initialize()) self.assertTrue(resp.initialized) self.assertFalse(resp.needs_backup) self.assertFalse(resp.pin_protection) self.assertFalse(resp.passphrase_protection) # Do passphrase-protected action, PassphraseRequest should NOT be raised resp = self.client.call_raw(proto.Ping(passphrase_protection=True)) self.assertIsInstance(resp, proto.Success) # Do PIN-protected action, PinRequest should NOT be raised resp = self.client.call_raw(proto.Ping(pin_protection=True)) self.assertIsInstance(resp, proto.Success) def test_reset_device_pin(self): external_entropy = b'zlutoucky kun upel divoke ody' * 2 strength = 128 ret = self.client.call_raw(proto.ResetDevice( display_random=True, strength=strength, passphrase_protection=True, pin_protection=True, language='english', label='test' )) self.assertIsInstance(ret, proto.ButtonRequest) self.client.debug.press_yes() ret = self.client.call_raw(proto.ButtonAck()) self.assertIsInstance(ret, proto.PinMatrixRequest) # Enter PIN for first time pin_encoded = self.client.debug.encode_pin('654') ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) self.assertIsInstance(ret, proto.PinMatrixRequest) # Enter PIN for second time pin_encoded = self.client.debug.encode_pin('654') ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Provide entropy self.assertIsInstance(ret, proto.EntropyRequest) internal_entropy = self.client.debug.read_reset_entropy() ret = self.client.call_raw(proto.EntropyAck(entropy=external_entropy)) # Generate mnemonic locally entropy = common.generate_entropy(strength, internal_entropy, external_entropy) expected_mnemonic = Mnemonic('english').to_mnemonic(entropy) mnemonic = [] for _ in range(strength // 32 * 3): self.assertIsInstance(ret, proto.ButtonRequest) mnemonic.append(self.client.debug.read_reset_word()) self.client.debug.press_yes() self.client.call_raw(proto.ButtonAck()) mnemonic = ' '.join(mnemonic) # Compare that device generated proper mnemonic for given entropies self.assertEqual(mnemonic, expected_mnemonic) mnemonic = [] for _ in range(strength // 32 * 3): self.assertIsInstance(ret, proto.ButtonRequest) mnemonic.append(self.client.debug.read_reset_word()) self.client.debug.press_yes() resp = self.client.call_raw(proto.ButtonAck()) self.assertIsInstance(resp, proto.Success) mnemonic = ' '.join(mnemonic) # Compare that second pass printed out the same mnemonic once again self.assertEqual(mnemonic, expected_mnemonic) # Check if device is properly initialized resp = self.client.call_raw(proto.Initialize()) self.assertTrue(resp.initialized) self.assertFalse(resp.needs_backup) self.assertTrue(resp.pin_protection) self.assertTrue(resp.passphrase_protection) # Do passphrase-protected action, PassphraseRequest should be raised resp = self.client.call_raw(proto.Ping(passphrase_protection=True)) self.assertIsInstance(resp, proto.PassphraseRequest) self.client.call_raw(proto.Cancel()) # Do PIN-protected action, PinRequest should be raised resp = self.client.call_raw(proto.Ping(pin_protection=True)) self.assertIsInstance(resp, proto.PinMatrixRequest) self.client.call_raw(proto.Cancel()) def test_failed_pin(self): # external_entropy = b'zlutoucky kun upel divoke ody' * 2 strength = 128 ret = self.client.call_raw(proto.ResetDevice( display_random=True, strength=strength, passphrase_protection=True, pin_protection=True, language='english', label='test' )) self.assertIsInstance(ret, proto.ButtonRequest) self.client.debug.press_yes() ret = self.client.call_raw(proto.ButtonAck()) self.assertIsInstance(ret, proto.PinMatrixRequest) # Enter PIN for first time pin_encoded = self.client.debug.encode_pin(self.pin4) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) self.assertIsInstance(ret, proto.PinMatrixRequest) # Enter PIN for second time pin_encoded = self.client.debug.encode_pin(self.pin6) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) self.assertIsInstance(ret, proto.Failure) def test_already_initialized(self): self.setup_mnemonic_nopin_nopassphrase() self.assertRaises(Exception, self.client.reset_device, False, 128, True, True, 'label', 'english') if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_resetdevice_skipbackup.py0000644000175000001440000000674013124751541026260 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . import unittest import common from trezorlib import messages_pb2 as proto from mnemonic import Mnemonic class TestDeviceResetSkipBackup(common.TrezorTest): def test_reset_device_skip_backup(self): external_entropy = b'zlutoucky kun upel divoke ody' * 2 strength = 128 ret = self.client.call_raw(proto.ResetDevice( display_random=False, strength=strength, passphrase_protection=False, pin_protection=False, language='english', label='test', skip_backup=True )) # Provide entropy self.assertIsInstance(ret, proto.EntropyRequest) internal_entropy = self.client.debug.read_reset_entropy() ret = self.client.call_raw(proto.EntropyAck(entropy=external_entropy)) self.assertIsInstance(ret, proto.Success) # Check if device is properly initialized resp = self.client.call_raw(proto.Initialize()) self.assertTrue(resp.initialized) self.assertTrue(resp.needs_backup) # Generate mnemonic locally entropy = common.generate_entropy(strength, internal_entropy, external_entropy) expected_mnemonic = Mnemonic('english').to_mnemonic(entropy) # start Backup workflow ret = self.client.call_raw(proto.BackupDevice()) mnemonic = [] for _ in range(strength // 32 * 3): self.assertIsInstance(ret, proto.ButtonRequest) mnemonic.append(self.client.debug.read_reset_word()) self.client.debug.press_yes() self.client.call_raw(proto.ButtonAck()) mnemonic = ' '.join(mnemonic) # Compare that device generated proper mnemonic for given entropies self.assertEqual(mnemonic, expected_mnemonic) mnemonic = [] for _ in range(strength // 32 * 3): self.assertIsInstance(ret, proto.ButtonRequest) mnemonic.append(self.client.debug.read_reset_word()) self.client.debug.press_yes() resp = self.client.call_raw(proto.ButtonAck()) self.assertIsInstance(resp, proto.Success) mnemonic = ' '.join(mnemonic) # Compare that second pass printed out the same mnemonic once again self.assertEqual(mnemonic, expected_mnemonic) # start backup again - should fail ret = self.client.call_raw(proto.BackupDevice()) self.assertIsInstance(ret, proto.Failure) def test_initialized_device_backup_fail(self): self.setup_mnemonic_nopin_nopassphrase() ret = self.client.call_raw(proto.BackupDevice()) self.assertIsInstance(ret, proto.Failure) if __name__ == '__main__': unittest.main() trezor-0.7.16/tests/device_tests/test_msg_signidentity.py0000644000175000001440000001202413123262731024241 0ustar stickusers00000000000000# This file is part of the TREZOR project. # # Copyright (C) 2012-2016 Marek Palatinus # Copyright (C) 2012-2016 Pavol Rusnak # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . from __future__ import print_function import unittest import binascii import hashlib import struct import common import trezorlib.types_pb2 as proto_types def check_path(identity): m = hashlib.sha256() m.update(struct.pack("