コード例 #1
0
    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.ButtonRequest(),
                                                proto.PinMatrixRequest(),
                                                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.PinMatrixRequest(),
                                                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.PinMatrixRequest(),
                                                proto.Success(),
                                                proto.Features()])
            self.client.apply_settings(use_passphrase=True)

        self.assertEqual(self.client.features.passphrase_protection, True)
コード例 #2
0
 def test_change_pin(self):
     with self.client:
         self.setup_mnemonic_pin_passphrase()
         self.client.set_expected_responses([proto.ButtonRequest(),
                                   proto.PinMatrixRequest(),
                                   proto.PinMatrixRequest(),
                                   proto.PinMatrixRequest(),
                                   proto.Success(),
                                   proto.Features()])
         self.client.change_pin()
コード例 #3
0
    def test_signtx(self):
        self.setup_mnemonic_pin_passphrase()


        inp1 = proto_types.TxInputType(address_n=[0],  # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
                             prev_hash=binascii.unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'),
                             prev_index=0,
                             )

        out1 = proto_types.TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
                              amount=390000 - 10000,
                              script_type=proto_types.PAYTOADDRESS,
                              )
        tx_responses = [
            proto.TxRequest(request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=0)),
            proto.TxRequest(request_type=proto_types.TXMETA, details=proto_types.TxRequestDetailsType(tx_hash=binascii.unhexlify("d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"))),
            proto.TxRequest(request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=0, tx_hash=binascii.unhexlify("d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"))),
            proto.TxRequest(request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=1, tx_hash=binascii.unhexlify("d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"))),
            proto.TxRequest(request_type=proto_types.TXOUTPUT, details=proto_types.TxRequestDetailsType(request_index=0, tx_hash=binascii.unhexlify("d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"))),
            proto.TxRequest(request_type=proto_types.TXOUTPUT, details=proto_types.TxRequestDetailsType(request_index=0)),
            proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput),
            proto.ButtonRequest(code=proto_types.ButtonRequest_SignTx),
            proto.TxRequest(request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=0)),
            proto.TxRequest(request_type=proto_types.TXOUTPUT, details=proto_types.TxRequestDetailsType(request_index=0)),
            proto.TxRequest(request_type=proto_types.TXOUTPUT, details=proto_types.TxRequestDetailsType(request_index=0)),
            proto.TxRequest(request_type=proto_types.TXFINISHED),
        ]

        self.client.clear_session()
        with self.client:

            # Pin & Passphrase are needed after device is locked
            self.client.set_expected_responses([
                proto.PinMatrixRequest(),
                proto.PassphraseRequest(),

            ] + tx_responses)
            self.client.sign_tx('Bitcoin', [inp1, ], [out1, ])

        with self.client:

            # Pin & Passphrase not needed, since they're cached, and the device is unlocked
            self.client.set_expected_responses([
            ] + tx_responses)
            self.client.sign_tx('Bitcoin', [inp1, ], [out1, ])

        self.client.clear_session()
        with self.client:

            # Pin & Passphrase needed again after session is cleared, and the device is locked
            self.client.set_expected_responses([
                proto.PinMatrixRequest(),
                proto.PassphraseRequest(),
            ] + tx_responses)
            self.client.sign_tx('Bitcoin', [inp1, ], [out1, ])
コード例 #4
0
    def test_ping(self):
        self.setup_mnemonic_pin_passphrase()
        self.client.clear_session()

        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_Ping), 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.ButtonRequest(code=proto_types.ButtonRequest_Other), 
                proto.Success()
                ])
            res = self.client.ping('random data', passphrase_protection=True)
            self.assertEqual(res, 'random data')
コード例 #5
0
 def test_get_address(self):
     with self.client:
         self.setup_mnemonic_pin_passphrase()
         self.client.clear_session()
         self.client.set_expected_responses([proto.PinMatrixRequest(),
                                   proto.PassphraseRequest(),
                                   proto.Address()])
         self.client.get_address('Bitcoin', [])
コード例 #6
0
 def test_get_public_key(self):
     with self.client:
         self.setup_mnemonic_pin_passphrase()
         self.client.clear_session()
         self.client.set_expected_responses([proto.PinMatrixRequest(),
                                   proto.PassphraseRequest(),
                                   proto.PublicKey()])
         self.client.get_public_node([])
コード例 #7
0
 def test_ping(self):
     with self.client:
         self.setup_mnemonic_pin_passphrase()
         self.client.clear_session()
         self.client.set_expected_responses([proto.ButtonRequest(),
                                   proto.PinMatrixRequest(),
                                   proto.PassphraseRequest(),
                                   proto.Success()])
         self.client.ping('msg', True, True, True)
コード例 #8
0
 def test_apply_settings(self):
     with self.client:
         self.setup_mnemonic_pin_passphrase()
         self.client.clear_session()
         self.client.set_expected_responses([proto.ButtonRequest(),
                                   proto.PinMatrixRequest(),
                                   proto.Success(),
                                   proto.Features()])  # KeepKeyClient reinitializes device
         self.client.apply_settings(label='nazdar')
コード例 #9
0
 def test_sign_message(self):
     with self.client:
         self.setup_mnemonic_pin_passphrase()
         self.client.clear_session()
         self.client.set_expected_responses([proto.ButtonRequest(),
                                   proto.PinMatrixRequest(),
                                   proto.PassphraseRequest(),
                                   proto.MessageSignature()])
         self.client.sign_message('Bitcoin', [], 'testing message')
コード例 #10
0
    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.ButtonRequest(),
                                                proto.PinMatrixRequest(),
                                                proto.Success(),
                                                proto.Features()])
            self.client.apply_settings(language='nonexistent')

        self.assertEqual(self.client.features.language, 'english')
コード例 #11
0
    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.ButtonRequest(),
                                                proto.PinMatrixRequest(),
                                                proto.Success(),
                                                proto.Features()])
            self.client.apply_settings(label='new label')

        self.assertEqual(self.client.features.label, 'new label')
コード例 #12
0
    def test_pin(self):
        self.setup_mnemonic_pin_passphrase()
        self.client.clear_session()

        with self.client:
            self.assertEqual(self.client.debug.read_pin()[0], self.pin4)
            self.client.setup_debuglink(button=True, pin_correct=True)
            self.client.set_expected_responses([
                proto.ButtonRequest(),
                proto.PinMatrixRequest(),
                proto.Success()
            ])
            self._some_protected_call(True, True, False)
コード例 #13
0
 def test_ping_format_specifier_sanitize(self):
     self.setup_mnemonic_pin_passphrase()
     self.client.clear_session()
     with self.client:
         self.client.set_expected_responses([
             proto.ButtonRequest(code=proto_types.ButtonRequest_Ping), 
             proto.PinMatrixRequest(), 
             proto.PassphraseRequest(), 
             proto.ButtonRequest(code=proto_types.ButtonRequest_Other), 
             proto.Success()
             ])
         res = self.client.ping('%s%x%n%p', button_protection=True, pin_protection=True, passphrase_protection=True)
         self.assertEqual(res, '%s%x%n%p')