def recovery_loop(self, client, mnemonic, result): ret = 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)): assert isinstance(ret, proto.WordRequest) (word, pos) = client.debug.read_recovery_word() if pos != 0: ret = client.call_raw(proto.WordAck(word=mnemonic[pos - 1])) mnemonic[pos - 1] = None else: ret = client.call_raw(proto.WordAck(word=word)) fakes += 1 print(mnemonic) assert isinstance(ret, proto.ButtonRequest) client.debug.press_yes() ret = client.call_raw(proto.ButtonAck()) assert isinstance(ret, result)
def test_word_fail(self, client): ret = client.call_raw( proto.RecoveryDevice( word_count=12, passphrase_protection=False, pin_protection=False, label="label", language="en-US", enforce_wordlist=True, )) # click through confirmation assert isinstance(ret, proto.ButtonRequest) client.debug.press_yes() ret = client.call_raw(proto.ButtonAck()) assert isinstance(ret, proto.WordRequest) for _ in range(int(12 * 2)): (word, pos) = client.debug.read_recovery_word() if pos != 0: ret = client.call_raw(proto.WordAck(word="kwyjibo")) assert isinstance(ret, proto.Failure) break else: client.call_raw(proto.WordAck(word=word))
def test_pin_passphrase(self, client): mnemonic = MNEMONIC12.split(" ") ret = client.call_raw( proto.RecoveryDevice( word_count=12, passphrase_protection=True, pin_protection=True, label="label", language="en-US", enforce_wordlist=True, )) # click through confirmation assert isinstance(ret, proto.ButtonRequest) client.debug.press_yes() ret = client.call_raw(proto.ButtonAck()) assert isinstance(ret, proto.PinMatrixRequest) # Enter PIN for first time pin_encoded = client.debug.encode_pin(PIN6) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) assert isinstance(ret, proto.PinMatrixRequest) # Enter PIN for second time pin_encoded = client.debug.encode_pin(PIN6) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) fakes = 0 for _ in range(int(12 * 2)): assert isinstance(ret, proto.WordRequest) (word, pos) = client.debug.read_recovery_word() if pos != 0: ret = client.call_raw(proto.WordAck(word=mnemonic[pos - 1])) mnemonic[pos - 1] = None else: ret = client.call_raw(proto.WordAck(word=word)) fakes += 1 print(mnemonic) # Workflow succesfully ended assert isinstance(ret, proto.Success) # 12 expected fake words and all words of mnemonic are used assert fakes == 12 assert mnemonic == [None] * 12 # Mnemonic is the same client.init_device() assert client.debug.read_mnemonic_secret() == MNEMONIC12.encode() assert client.features.pin_protection is True assert client.features.passphrase_protection is True # Do passphrase-protected action, PassphraseRequest should be raised resp = client.call_raw(proto.GetAddress()) assert isinstance(resp, proto.PassphraseRequest) client.call_raw(proto.Cancel())
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)) assert isinstance(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)) assert isinstance(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)): assert isinstance(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 assert isinstance(ret, proto.Success) # 12 expected fake words and all words of mnemonic are used assert fakes == 12 assert mnemonic == [None] * 12 # Mnemonic is the same self.client.init_device() assert self.client.debug.read_mnemonic() == self.mnemonic12 assert self.client.features.pin_protection is True assert self.client.features.passphrase_protection is True # Do passphrase-protected action, PassphraseRequest should be raised resp = self.client.call_raw(proto.Ping(passphrase_protection=True)) assert isinstance(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)) assert isinstance(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, )) # click through confirmation assert isinstance(ret, proto.ButtonRequest) self.client.debug.press_yes() ret = self.client.call_raw(proto.ButtonAck()) fakes = 0 for _ in range(int(12 * 2)): assert isinstance(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 assert isinstance(ret, proto.Success) # 12 expected fake words and all words of mnemonic are used assert fakes == 12 assert mnemonic == [None] * 12 # Mnemonic is the same self.client.init_device() assert self.client.debug.read_mnemonic_secret( ) == self.mnemonic12.encode() assert self.client.features.pin_protection is False assert self.client.features.passphrase_protection is False # Do passphrase-protected action, PassphraseRequest should NOT be raised resp = self.client.call_raw(proto.Ping(passphrase_protection=True)) assert isinstance(resp, proto.Success) # Do PIN-protected action, PinRequest should NOT be raised resp = self.client.call_raw(proto.Ping(pin_protection=True)) assert isinstance(resp, proto.Success)
def test_nopin_nopassphrase(client: Client): mnemonic = MNEMONIC12.split(" ") ret = client.call_raw( messages.RecoveryDevice( word_count=12, passphrase_protection=False, pin_protection=False, label="label", language="en-US", enforce_wordlist=True, ) ) # click through confirmation assert isinstance(ret, messages.ButtonRequest) client.debug.press_yes() ret = client.call_raw(messages.ButtonAck()) fakes = 0 for _ in range(int(12 * 2)): assert isinstance(ret, messages.WordRequest) (word, pos) = client.debug.read_recovery_word() if pos != 0: ret = client.call_raw(messages.WordAck(word=mnemonic[pos - 1])) mnemonic[pos - 1] = None else: ret = client.call_raw(messages.WordAck(word=word)) fakes += 1 # Workflow succesfully ended assert isinstance(ret, messages.Success) # 12 expected fake words and all words of mnemonic are used assert fakes == 12 assert mnemonic == [None] * 12 # Mnemonic is the same client.init_device() assert client.debug.state().mnemonic_secret == MNEMONIC12.encode() assert client.features.pin_protection is False assert client.features.passphrase_protection is False # Do pin & passphrase-protected action, PassphraseRequest should NOT be raised resp = client.call_raw(messages.GetAddress(address_n=parse_path("m/44'/0'/0'/0/0"))) assert isinstance(resp, messages.Address)
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)) assert isinstance(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')) assert isinstance(ret, proto.Failure) break else: self.client.call_raw(proto.WordAck(word=word))
def callback_WordRequest(self, msg): if msg.type in (trezor_proto.WordRequestType.Matrix9, trezor_proto.WordRequestType.Matrix6): return self.callback_RecoveryMatrix(msg) msg = "Enter one word of mnemonic: " word = ask_for_word_callback(msg, self.__mnemonic.wordlist) if not word: raise HardwareWalletCancelException('Cancelled') return trezor_proto.WordAck(word=word)