Skip to content

Conversation

@mradian1
Copy link
Contributor

@mradian1 mradian1 commented Apr 16, 2025

Checklist

  • App update process has been followed
  • Target branch is develop
  • Application version has been bumped

@mradian1 mradian1 self-assigned this Apr 16, 2025
@mradian1 mradian1 changed the title Fixes after Ledger Reeview - Sign message update Fixes after Ledger Review - Sign message update Apr 16, 2025
src/sign_msg.c Outdated
msg_context.message_received_length += data_length;

if (msg_context.message_received_length > MAX_DISPLAY_MESSAGE_SIZE) {
memcpy(msg_context.message + MAX_DISPLAY_MESSAGE_SIZE - 3, "...", 3);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it the case to make some kind of validation here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An option would be to handle / replace non-printable characters (an idea).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/sign_msg.c Outdated
msg_context.message_received_length += data_length;

if (msg_context.message_received_length > MAX_DISPLAY_MESSAGE_SIZE) {
memcpy(msg_context.message + MAX_DISPLAY_MESSAGE_SIZE - 3, "...", 3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An option would be to handle / replace non-printable characters (an idea).

src/sign_msg.c Outdated
start_review,
nbgl_reject_message_choice);
make_content_list();
nbgl_useCaseReview(TYPE_MESSAGE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is the new, recommended way, without nbgl_useCaseReviewStart, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a newer function, that generates similar result for both blind signing (nbgl_useCaseReviewBlindSigning) and regular flows. The same used in signing transactions. They stated in the review that this is the required form and asked for us to change the code accordingly


content_pairs_list[step].item = "Hash";
content_pairs_list[step++].value = msg_context.strhash;
content_pairs_list[step].item = "Message";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

content.nbMaxLinesForValue = 2;
content.token = 0;
content.smallCaseForValue = false;
content.wrapping = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

src/sign_msg.c Outdated
msg_context.message_received_length += data_length;

if (msg_context.message_received_length > MAX_DISPLAY_MESSAGE_SIZE) {
memcpy(msg_context.message + MAX_DISPLAY_MESSAGE_SIZE - 3, "...", 3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In parse_tx.c, we use e.g.:

int ellipsisLen = strlen(ellipsis);

Maybe have a similar approach (named variable or so)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

rapdu = backend.exchange(CLA, Ins.SIGN_MSG, P1.FIRST, 0, payload)
assert rapdu.status == Error.MESSAGE_TOO_LONG

def test_blind_sign_msg_confirmed(self, backend, navigator, test_name):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should say "message" instead of "transaction" for this flow?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An observation - ü is skipped / lost (utf-8 "magic" / not 1-byte-to-1-char equivalence).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was skipped before the length fix, now it is replace with '??'

src/sign_msg.c Outdated
&C_icon_multiversx_logo_64x64,
"Review message to\nsign on " APPNAME "\nnetwork",
"",
"Accept risk and sign transaction?",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"message" instead of "transaction"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/sign_msg.c Outdated

#endif

static bool verify_message(char *decoded, size_t len) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine for our purpose. The utf-8 encoded bytes used in the test trick this function a bit, since there isn't a 1-to-1 equivalence between the original characters and the input bytes (in the encoding).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I think so too, doing a proper utf8 decoding seems too much for our purposes, in my opinion

src/sign_msg.c Outdated

#endif

static bool verify_message(char *decoded, size_t len) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter name "decoded" - is it appropriate? Maybe simply "message"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

src/sign_msg.c Outdated
data_buffer,
length_to_copy);

bool result = verify_message(msg_context.message + msg_context.message_received_length,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable result can be renamed e.g. verification_result, or directly use found_non_printable_chars (just an opinion, can also stay as it is).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also directly set it to found_non_printable_chars, then we can remove the check & assignment at 292-293

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This takes into account the fact that the body of the message may come in multiple bulks. Thus if in an earlier bulk non-printable chars were found whereas in later bulks all is clear, it wouldn't be correct to update found_non_printable_chars to false.

static bool verify_message(char *decoded, size_t len) {
bool has_non_printable_chars = false;
for (size_t i = 0; i < len / 4 * 3; i++) {
for (size_t i = 0; i < len; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, true, good catch!

andreibancioiu
andreibancioiu previously approved these changes Apr 23, 2025
src/sign_msg.c Outdated
data_buffer,
length_to_copy);

bool result = verify_message(msg_context.message + msg_context.message_received_length,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also directly set it to found_non_printable_chars, then we can remove the check & assignment at 292-293

src/sign_msg.c Outdated
}

static void process_message(uint8_t *message, size_t data_length) {
PRINTF(message, data_length);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required or debugging artifact?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was for debugging purposes. removed

@AdoAdoAdo AdoAdoAdo merged commit 81f7ec4 into feat/flex-and-blind-signing May 15, 2025
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants