Skip to content

Commit

Permalink
Merge pull request #273 from LedgerHQ/fix-signmessage
Browse files Browse the repository at this point in the history
Fix `signMessage` failing for messages of certain lengths
  • Loading branch information
bigspider authored Aug 7, 2024
2 parents 6367fb2 + 23d0ddf commit 4c60d06
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Dates are in `dd-mm-yyyy` format.

## [2.2.5] - TBD

### Fixed

- `signMessage` would fail since version 2.2.2 for certain message lengths.

## [2.2.4] - 09-07-2024

### Changed
Expand Down
8 changes: 7 additions & 1 deletion src/handler/sign_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ static bool display_message_content_and_confirm(dispatcher_context_t* dc,

total_chunk_len += offset;

for (int j = 0; j < MESSAGE_CHUNK_PER_DISPLAY; j++) {
// each UX display will show MESSAGE_CHUNK_PER_DISPLAY chunks
size_t group_start_index = get_streaming_index() * MESSAGE_CHUNK_PER_DISPLAY;

for (int j = 0;
j < MESSAGE_CHUNK_PER_DISPLAY &&
(group_start_index + j) < (unsigned int) n_chunks; // make sure not to overflow
j++) {
offset += j * MESSAGE_CHUNK_SIZE;

int chunk_len =
Expand Down
10 changes: 5 additions & 5 deletions tests/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from ragger_bitcoin.ragger_instructions import Instructions


def message_instruction_approve(model: Firmware) -> Instructions:
def message_instruction_approve(model: Firmware, save_screenshot=True) -> Instructions:
instructions = Instructions(model)

if model.name.startswith("nano"):
instructions.nano_skip_screen("Path")
instructions.same_request("Sign")
instructions.nano_skip_screen("Path", save_screenshot=save_screenshot)
instructions.same_request("Sign", save_screenshot=save_screenshot)
else:
instructions.review_message()
instructions.confirm_message()
instructions.review_message(save_screenshot=save_screenshot)
instructions.confirm_message(save_screenshot=save_screenshot)

return instructions

Expand Down
9 changes: 9 additions & 0 deletions tests/test_sign_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ def test_sign_message(navigator: Navigator, firmware: Firmware, client: RaggerCl
assert result == "IOR4YRVlmJGMx+H7PgQvHzWAF0HAgrUggQeRdnoWKpypfaAberpvF+XbOCM5Cd/ljogNyU3w2OIL8eYCyZ6Ru2k="


def test_sign_message_64bytes(navigator: Navigator, firmware: Firmware, client: RaggerClient, test_name: str):
# Version 2.2.2 introduced a bug where signing a 64 bytes message would fail; this test is to avoid regressions
msg = "a" * 64
path = "m/44'/1'/0'/0/0"
client.sign_message(msg, path, navigator,
instructions=message_instruction_approve(firmware, save_screenshot=False),
testname=test_name)


def test_sign_message_accept(navigator: Navigator, firmware: Firmware, client: RaggerClient, test_name: str):
message = "Hello world!"

Expand Down

0 comments on commit 4c60d06

Please sign in to comment.