Port 'test_pubkey_cmd' from 'speculos' to 'ragger'

This commit is contained in:
Charles-Edouard de la Vergne
2024-03-27 09:39:20 +01:00
parent 6e477717de
commit 91d73f9110
59 changed files with 67 additions and 121 deletions

View File

Before

Width:  |  Height:  |  Size: 360 B

After

Width:  |  Height:  |  Size: 360 B

View File

Before

Width:  |  Height:  |  Size: 490 B

After

Width:  |  Height:  |  Size: 490 B

View File

Before

Width:  |  Height:  |  Size: 502 B

After

Width:  |  Height:  |  Size: 502 B

View File

Before

Width:  |  Height:  |  Size: 383 B

After

Width:  |  Height:  |  Size: 383 B

View File

Before

Width:  |  Height:  |  Size: 341 B

After

Width:  |  Height:  |  Size: 341 B

View File

Before

Width:  |  Height:  |  Size: 349 B

After

Width:  |  Height:  |  Size: 349 B

View File

Before

Width:  |  Height:  |  Size: 360 B

After

Width:  |  Height:  |  Size: 360 B

View File

Before

Width:  |  Height:  |  Size: 466 B

After

Width:  |  Height:  |  Size: 466 B

View File

Before

Width:  |  Height:  |  Size: 486 B

After

Width:  |  Height:  |  Size: 486 B

View File

Before

Width:  |  Height:  |  Size: 406 B

After

Width:  |  Height:  |  Size: 406 B

View File

Before

Width:  |  Height:  |  Size: 341 B

After

Width:  |  Height:  |  Size: 341 B

View File

Before

Width:  |  Height:  |  Size: 340 B

After

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 B

View File

Before

Width:  |  Height:  |  Size: 360 B

After

Width:  |  Height:  |  Size: 360 B

View File

Before

Width:  |  Height:  |  Size: 490 B

After

Width:  |  Height:  |  Size: 490 B

View File

Before

Width:  |  Height:  |  Size: 502 B

After

Width:  |  Height:  |  Size: 502 B

View File

Before

Width:  |  Height:  |  Size: 383 B

After

Width:  |  Height:  |  Size: 383 B

View File

Before

Width:  |  Height:  |  Size: 341 B

After

Width:  |  Height:  |  Size: 341 B

View File

Before

Width:  |  Height:  |  Size: 340 B

After

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 B

View File

Before

Width:  |  Height:  |  Size: 400 B

After

Width:  |  Height:  |  Size: 400 B

View File

Before

Width:  |  Height:  |  Size: 769 B

After

Width:  |  Height:  |  Size: 769 B

View File

Before

Width:  |  Height:  |  Size: 364 B

After

Width:  |  Height:  |  Size: 364 B

View File

Before

Width:  |  Height:  |  Size: 381 B

After

Width:  |  Height:  |  Size: 381 B

View File

Before

Width:  |  Height:  |  Size: 400 B

After

Width:  |  Height:  |  Size: 400 B

View File

Before

Width:  |  Height:  |  Size: 748 B

After

Width:  |  Height:  |  Size: 748 B

View File

Before

Width:  |  Height:  |  Size: 364 B

After

Width:  |  Height:  |  Size: 364 B

View File

Before

Width:  |  Height:  |  Size: 366 B

After

Width:  |  Height:  |  Size: 366 B

View File

Before

Width:  |  Height:  |  Size: 381 B

After

Width:  |  Height:  |  Size: 381 B

View File

Before

Width:  |  Height:  |  Size: 400 B

After

Width:  |  Height:  |  Size: 400 B

View File

Before

Width:  |  Height:  |  Size: 769 B

After

Width:  |  Height:  |  Size: 769 B

View File

Before

Width:  |  Height:  |  Size: 364 B

After

Width:  |  Height:  |  Size: 364 B

View File

Before

Width:  |  Height:  |  Size: 366 B

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 381 B

View File

Before

Width:  |  Height:  |  Size: 400 B

After

Width:  |  Height:  |  Size: 400 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 769 B

View File

Before

Width:  |  Height:  |  Size: 364 B

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 381 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 400 B

View File

Before

Width:  |  Height:  |  Size: 748 B

After

Width:  |  Height:  |  Size: 748 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

View File

Before

Width:  |  Height:  |  Size: 366 B

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 381 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 400 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 769 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 381 B

View File

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

View File

@@ -1,4 +1,4 @@
from typing import Optional
from typing import Optional, Tuple
import pytest
from ledger_app_clients.ethereum.client import EthAppClient, StatusWord
@@ -49,15 +49,24 @@ def get_moves(firmware: Firmware,
return moves
@pytest.mark.parametrize(
"path, suffix",
[
("m/44'/60'/0'/0/0", "60"),
("m/44'/700'/1'/0/0", "700")
],
)
def test_get_pk_rejected(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator):
navigator: Navigator,
path,
suffix):
app_client = EthAppClient(backend)
with pytest.raises(ExceptionRAPDU) as e:
with app_client.get_public_addr():
with app_client.get_public_addr(bip32_path=path):
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
"get_pk_rejected",
f"get_pk_rejected_{suffix}",
get_moves(firmware, reject=True))
assert e.value.status == StatusWord.CONDITION_NOT_SATISFIED
@@ -79,3 +88,57 @@ def test_get_pk(firmware: Firmware,
assert pk.hex() == ref_pk
if with_chaincode:
assert chaincode.hex() == ref_chaincode
def test_get_pk2(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator):
app_client = EthAppClient(backend)
path="m/44'/700'/1'/0/0"
with app_client.get_public_addr(bip32_path=path, chaincode=True):
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
"get_pk_700",
get_moves(firmware))
pk, _, chaincode = ResponseParser.pk_addr(app_client.response().data, True)
ref_pk, ref_chaincode = calculate_public_key_and_chaincode(curve=CurveChoice.Secp256k1,
path=path)
assert pk.hex() == ref_pk
assert chaincode.hex() == ref_chaincode
def test_get_public_key(backend: BackendInterface):
app_client = EthAppClient(backend)
with app_client.get_public_addr(bip32_path="m/44'/60'/1'/0/0", display=False, chaincode=True):
pass
response = app_client.response()
assert response.status == 0x9000
# response = pub_key_len (1)
# pub_key (var)
# eth_addr_len (1)
# eth_addr (var)
# chain_code (var)
buffer, pub_key_len, pub_key = _pop_size_prefixed_buf_from_buf(response.data)
buffer, eth_addr_len, eth_addr = _pop_size_prefixed_buf_from_buf(buffer)
buffer, chain_code = _pop_sized_buf_from_buffer(buffer, 32)
assert len(response.data) == 2 + pub_key_len + eth_addr_len + 32
assert pub_key == b'\x04\xea\x02&\x91\xc7\x87\x00\xd2\xc3\xa0\xc7E\xbe\xa4\xf2\xb8\xe5\xe3\x13\x97j\x10B\xf6\xa1Vc\\\xb2\x05\xda\x1a\xcb\xfe\x04*\nZ\x89eyn6"E\x89\x0eT\xbd-\xbex\xec\x1e\x18df\xf2\xe9\xd0\xf5\xd5\xd8\xdf'
assert eth_addr == b'463e4e114AA57F54f2Fd2C3ec03572C6f75d84C2'
assert chain_code == b'\xaf\x89\xcd)\xea${8I\xec\xc80\xc2\xc8\x94\\e1\xd6P\x87\x07?\x9f\xd09\x00\xa0\xea\xa7\x96\xc8'
def _pop_sized_buf_from_buffer(buffer: bytes, size: int) -> Tuple[bytes, bytes]:
"""Parse buffer and returns: remainder, data[size]"""
return buffer[size:], buffer[0:size]
def _pop_size_prefixed_buf_from_buf(buffer:bytes) -> Tuple[bytes, int, bytes]:
""" Parse buffer and returns: remainder, data_len, data """
data_len = buffer[0]
return buffer[1+data_len:], data_len, buffer[1:data_len+1]

View File

@@ -1,117 +0,0 @@
from time import sleep
import pytest
import ethereum_client
from ethereum_client.utils import compare_screenshot, save_screenshot, PATH_IMG
def test_get_public_key(cmd):
# ETHER COIN without display
result: list = []
with cmd.get_public_key(bip32_path="44'/60'/1'/0/0", display=False, result=result) as exchange:
pass
uncompressed_addr_len, eth_addr, chain_code = result
assert len(uncompressed_addr_len) == 65
assert len(eth_addr) == 40
assert len(chain_code) == 32
assert uncompressed_addr_len == b'\x04\xea\x02&\x91\xc7\x87\x00\xd2\xc3\xa0\xc7E\xbe\xa4\xf2\xb8\xe5\xe3\x13\x97j\x10B\xf6\xa1Vc\\\xb2\x05\xda\x1a\xcb\xfe\x04*\nZ\x89eyn6"E\x89\x0eT\xbd-\xbex\xec\x1e\x18df\xf2\xe9\xd0\xf5\xd5\xd8\xdf'
assert eth_addr == b'463e4e114AA57F54f2Fd2C3ec03572C6f75d84C2'
assert chain_code == b'\xaf\x89\xcd)\xea${8I\xec\xc80\xc2\xc8\x94\\e1\xd6P\x87\x07?\x9f\xd09\x00\xa0\xea\xa7\x96\xc8'
# DAI COIN with display
result: list = []
with cmd.get_public_key(bip32_path="44'/700'/1'/0/0", display=True, result=result) as exchange:
sleep(0.5)
if cmd.model == "nanos":
# Verify address
compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/get_public_key/00000.png")
cmd.client.press_and_release('right')
# Address 1/3, 2/3, 3/3
compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/get_public_key/00001.png")
cmd.client.press_and_release('right')
compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/get_public_key/00002.png")
cmd.client.press_and_release('right')
compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/get_public_key/00003.png")
cmd.client.press_and_release('right')
# Approved
compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/get_public_key/00004.png")
cmd.client.press_and_release('both')
if cmd.model == "nanox" or cmd.model == "nanosp":
# Verify address
compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/get_public_key/00000.png")
cmd.client.press_and_release('right')
# Address
compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/get_public_key/00001.png")
cmd.client.press_and_release('right')
# Approve
compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/get_public_key/00002.png")
cmd.client.press_and_release('both')
uncompressed_addr_len, eth_addr, chain_code = result
assert len(uncompressed_addr_len) == 65
assert len(eth_addr) == 40
assert len(chain_code) == 32
assert uncompressed_addr_len == b'\x04V\x8a\x15\xdc\xed\xc8[\x16\x17\x8d\xaf\xcax\x91v~{\x9c\x06\xba\xaa\xde\xf4\xe7\x9f\x86\x1d~\xed)\xdc\n8\x9c\x84\xf01@E\x13]\xd7~6\x8e\x8e\xabb-\xad\xcdo\xc3Fw\xb7\xc8y\xdbQ/\xc3\xe5\x18'
assert eth_addr == b'Ba9A9aED0a1AbBE1da1155F64e73e57Af7995880'
assert chain_code == b'4\xaa\x95\xf4\x02\x12\x12-T\x155\x86\xed\xc5\x0b\x1d8\x81\xae\xce\xbd\x1a\xbbv\x9a\xc7\xd5\x1a\xd0KT\xe4'
def test_reject_get_public_key(cmd):
# DAI COIN with display
result: list = []
with pytest.raises(ethereum_client.exception.errors.DenyError) as error:
with cmd.get_public_key(bip32_path="44'/700'/1'/0/0", display=True, result=result) as exchange:
sleep(0.5)
if cmd.model == "nanos":
# Verify address
compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/reject_get_public_key/00000.png")
cmd.client.press_and_release('right')
# Address 1/3, 2/3, 3/3
compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/reject_get_public_key/00001.png")
cmd.client.press_and_release('right')
compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/reject_get_public_key/00002.png")
cmd.client.press_and_release('right')
compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/reject_get_public_key/00003.png")
cmd.client.press_and_release('right')
# Approve
compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/reject_get_public_key/00004.png")
cmd.client.press_and_release('right')
# Reject
compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/reject_get_public_key/00005.png")
cmd.client.press_and_release('both')
if cmd.model == "nanox" or cmd.model == "nanosp":
# Verify address
compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/reject_get_public_key/00000.png")
cmd.client.press_and_release('right')
# Address
compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/reject_get_public_key/00001.png")
cmd.client.press_and_release('right')
# Approve
compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/reject_get_public_key/00002.png")
cmd.client.press_and_release('right')
# Reject
compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/reject_get_public_key/00003.png")
cmd.client.press_and_release('both')
assert error.args[0] == '0x6985'