|
| 1 | +# This file is part of the KeepKey project. |
| 2 | +# |
| 3 | +# Copyright (C) 2026 KeepKey |
| 4 | +# |
| 5 | +# This library is free software: you can redistribute it and/or modify |
| 6 | +# it under the terms of the GNU Lesser General Public License version 3 |
| 7 | +# as published by the Free Software Foundation. |
| 8 | + |
| 9 | +"""Every byte passed through firmware ``confirm_data`` must reach the OLED.""" |
| 10 | + |
| 11 | +from __future__ import print_function |
| 12 | + |
| 13 | +import binascii |
| 14 | + |
| 15 | +import common |
| 16 | + |
| 17 | +from keepkeylib import messages_eos_pb2 as eos_messages |
| 18 | +from keepkeylib import types_pb2 as types |
| 19 | +from keepkeylib.tools import parse_path |
| 20 | +from test_msg_display_disclosure import ScreenRecorder |
| 21 | + |
| 22 | + |
| 23 | +PREV_HASH = binascii.unhexlify( |
| 24 | + "d5f65ee80147b4bcc70b75e4bbf2d738" |
| 25 | + "2021b871bd8867ef8fa525ef50864882" |
| 26 | +) |
| 27 | +EOS_PATH = parse_path("m/44'/194'/0'/0/0") |
| 28 | + |
| 29 | + |
| 30 | +class TestConfirmDataDisclosure(common.KeepKeyTest): |
| 31 | + def setUp(self): |
| 32 | + super(TestConfirmDataDisclosure, self).setUp() |
| 33 | + self.requires_firmware("7.14.2") |
| 34 | + self.requires_fullFeature() |
| 35 | + self.setup_mnemonic_nopin_nopassphrase() |
| 36 | + |
| 37 | + def _capture_op_return(self, payload, group): |
| 38 | + tx_input = types.TxInputType( |
| 39 | + address_n=[0], prev_hash=PREV_HASH, prev_index=0 |
| 40 | + ) |
| 41 | + payment = types.TxOutputType( |
| 42 | + address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1", |
| 43 | + amount=380000, |
| 44 | + script_type=types.PAYTOADDRESS, |
| 45 | + ) |
| 46 | + data_output = types.TxOutputType( |
| 47 | + op_return_data=payload, |
| 48 | + amount=0, |
| 49 | + script_type=types.PAYTOOPRETURN, |
| 50 | + ) |
| 51 | + recorder = ScreenRecorder( |
| 52 | + self.client, answer=True, screenshot_group=group |
| 53 | + ) |
| 54 | + with recorder: |
| 55 | + _, serialized = self.client.sign_tx( |
| 56 | + "Bitcoin", [tx_input], [payment, data_output] |
| 57 | + ) |
| 58 | + return recorder.fingerprint, serialized |
| 59 | + |
| 60 | + def _capture_eos_memo(self, memo, group): |
| 61 | + transaction = { |
| 62 | + "chain_id": ( |
| 63 | + "cf057bbfb72640471fd910bcb67639c22" |
| 64 | + "df9f92470936cddc1ade0e2f2e7dc4f" |
| 65 | + ), |
| 66 | + "transaction": { |
| 67 | + "expiration": "2018-07-14T07:43:28", |
| 68 | + "ref_block_num": 6439, |
| 69 | + "ref_block_prefix": 2995713264, |
| 70 | + "max_net_usage_words": 0, |
| 71 | + "max_cpu_usage_ms": 0, |
| 72 | + "delay_sec": 0, |
| 73 | + "context_free_actions": [], |
| 74 | + "actions": [{ |
| 75 | + "account": "eosio.token", |
| 76 | + "name": "transfer", |
| 77 | + "authorization": [{ |
| 78 | + "actor": "miniminimini", |
| 79 | + "permission": "active", |
| 80 | + }], |
| 81 | + "data": { |
| 82 | + "from": "miniminimini", |
| 83 | + "to": "maximaximaxi", |
| 84 | + "quantity": "1.0000 EOS", |
| 85 | + "memo": memo, |
| 86 | + }, |
| 87 | + }], |
| 88 | + "transaction_extensions": [], |
| 89 | + }, |
| 90 | + } |
| 91 | + recorder = ScreenRecorder( |
| 92 | + self.client, answer=True, screenshot_group=group |
| 93 | + ) |
| 94 | + with recorder: |
| 95 | + signed = self.client.eos_sign_tx(EOS_PATH, transaction) |
| 96 | + signature = ( |
| 97 | + bytes(signed.signature_r), |
| 98 | + bytes(signed.signature_s), |
| 99 | + signed.signature_v, |
| 100 | + ) |
| 101 | + return recorder.fingerprint, signature |
| 102 | + |
| 103 | + def test_binary_op_return_tail_changes_oled_review(self): |
| 104 | + """A byte after the old 50-byte binary preview must be displayed.""" |
| 105 | + common_prefix = b"\x80" + b"A" * 79 |
| 106 | + payload_a = common_prefix + b"X" * 16 |
| 107 | + payload_b = common_prefix + b"Y" + b"X" * 15 |
| 108 | + |
| 109 | + screens_a, signed_a = self._capture_op_return(payload_a, "opreturn-a") |
| 110 | + # Run each member of the A/B pair from the same clean device state. |
| 111 | + # Multi-page review ends with a held confirmation, so merely opening a |
| 112 | + # new protocol session can retain a trailing emulator button event. |
| 113 | + self.client.wipe_device() |
| 114 | + self.setup_mnemonic_nopin_nopassphrase() |
| 115 | + screens_b, signed_b = self._capture_op_return(payload_b, "opreturn-b") |
| 116 | + |
| 117 | + self.assertNotEqual(signed_a, signed_b) |
| 118 | + self.assertGreater(len(screens_a), 1) |
| 119 | + self.assertGreater(len(screens_b), 1) |
| 120 | + self.assertNotEqual( |
| 121 | + screens_a, screens_b, |
| 122 | + "different signed OP_RETURN tails produced identical OLED review", |
| 123 | + ) |
| 124 | + |
| 125 | + def test_non_ascii_eos_memo_tail_changes_oled_review(self): |
| 126 | + """A UTF-8 memo byte after the old 50-byte preview must be displayed.""" |
| 127 | + common_prefix = "\u00e9" + "A" * 79 |
| 128 | + memo_a = common_prefix + "X" * 16 |
| 129 | + memo_b = common_prefix + "Y" + "X" * 15 |
| 130 | + |
| 131 | + screens_a, signed_a = self._capture_eos_memo(memo_a, "eos-a") |
| 132 | + self.client.wipe_device() |
| 133 | + self.setup_mnemonic_nopin_nopassphrase() |
| 134 | + screens_b, signed_b = self._capture_eos_memo(memo_b, "eos-b") |
| 135 | + |
| 136 | + self.assertNotEqual(signed_a, signed_b) |
| 137 | + self.assertGreater(len(screens_a), 1) |
| 138 | + self.assertGreater(len(screens_b), 1) |
| 139 | + self.assertNotEqual( |
| 140 | + screens_a, screens_b, |
| 141 | + "different signed EOS memo tails produced identical OLED review", |
| 142 | + ) |
| 143 | + |
| 144 | + def test_unknown_omni_property_changes_oled_review(self): |
| 145 | + """Unsupported Omni assets must disclose bytes, not a shared ticker.""" |
| 146 | + header = b"omni\x00\x00\x00\x00" + (999999).to_bytes(4, "big") |
| 147 | + payload_a = header + (1).to_bytes(8, "big") |
| 148 | + payload_b = header + (2).to_bytes(8, "big") |
| 149 | + |
| 150 | + screens_a, signed_a = self._capture_op_return(payload_a, "omni-prop-a") |
| 151 | + self.client.wipe_device() |
| 152 | + self.setup_mnemonic_nopin_nopassphrase() |
| 153 | + screens_b, signed_b = self._capture_op_return(payload_b, "omni-prop-b") |
| 154 | + |
| 155 | + self.assertNotEqual(signed_a, signed_b) |
| 156 | + self.assertNotEqual( |
| 157 | + screens_a, screens_b, |
| 158 | + "different unsupported Omni assets produced identical OLED review", |
| 159 | + ) |
| 160 | + |
| 161 | + def test_unknown_omni_type_changes_oled_review(self): |
| 162 | + """Unsupported Omni operations must disclose the complete payload.""" |
| 163 | + header = b"omni\x00\x00\x00\x01" + (31).to_bytes(4, "big") |
| 164 | + payload_a = header + (1).to_bytes(8, "big") |
| 165 | + payload_b = header + (2).to_bytes(8, "big") |
| 166 | + |
| 167 | + screens_a, signed_a = self._capture_op_return(payload_a, "omni-type-a") |
| 168 | + self.client.wipe_device() |
| 169 | + self.setup_mnemonic_nopin_nopassphrase() |
| 170 | + screens_b, signed_b = self._capture_op_return(payload_b, "omni-type-b") |
| 171 | + |
| 172 | + self.assertNotEqual(signed_a, signed_b) |
| 173 | + self.assertNotEqual( |
| 174 | + screens_a, screens_b, |
| 175 | + "different unsupported Omni operations produced identical review", |
| 176 | + ) |
| 177 | + |
| 178 | + |
| 179 | +if __name__ == "__main__": |
| 180 | + import unittest |
| 181 | + unittest.main() |
0 commit comments