Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
1.(test) add skip in review class (ragger)
2. add testing for unexpected states in blindsigning flow.
  • Loading branch information
ajinkyaraj-23 committed Sep 24, 2024
1 parent 8fa2b61 commit 0af9ac9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
14 changes: 7 additions & 7 deletions app/src/apdu_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -914,10 +914,10 @@ handle_data_apdu_clear(command_t *cmd)
#define OPERATION_TYPE_STR_LENGTH 22

static void
get_blindsign_type(char *type)
get_blindsign_type(char *type, size_t type_size)
{
TZ_PREAMBLE(("type=%s", type));
TZ_ASSERT(strlen(type) == OPERATION_TYPE_STR_LENGTH, EXC_WRONG_PARAM);
TZ_ASSERT(type_size >= OPERATION_TYPE_STR_LENGTH, EXC_MEMORY_ERROR);
// clang-format off
switch (global.keys.apdu.sign.tag) {
case 0x01:
Expand Down Expand Up @@ -1018,7 +1018,7 @@ getTagValuePair(uint8_t pairIndex)
}

char num_buffer[DECIMAL_SIZE] = {0};
char type[OPERATION_TYPE_STR_LENGTH] = "Micheline\nexpression";
char type[OPERATION_TYPE_STR_LENGTH] = "Unknown types";
char
hash[TZ_BASE58_BUFFER_SIZE(sizeof(global.keys.apdu.hash.final_hash))];

Expand Down Expand Up @@ -1047,7 +1047,7 @@ getTagValuePair(uint8_t pairIndex)
(char **)&(pair.value));
} break;
case SUMMARY_INDEX_TYPE: {
get_blindsign_type(type);
get_blindsign_type(type, sizeof(type));
pair.item = "Type";
ui_strings_push(type, strlen(type), (char **)&(pair.value));
}
Expand Down Expand Up @@ -1089,7 +1089,7 @@ continue_blindsign_cb(void)
useCaseTagValueList.startIndex = 0;
useCaseTagValueList.nbPairs = 5;
}
PRINTF("[DEBUG] SIGN Stauts: %d, start_index %d Number of pairs:%d ",
PRINTF("[DEBUG] SIGN Status: %d, start_index %d Number of pairs:%d ",
global.step, useCaseTagValueList.startIndex,
useCaseTagValueList.nbPairs);
useCaseTagValueList.smallCaseForValue = false;
Expand Down Expand Up @@ -1117,8 +1117,8 @@ handle_data_apdu_blind(void)

#ifdef HAVE_BAGL

char type[OPERATION_TYPE_STR_LENGTH] = "Michelline\nexpression";
get_blindsign_type(type);
char type[OPERATION_TYPE_STR_LENGTH] = "Unknown type";
get_blindsign_type(type, sizeof(type));
tz_ui_stream_push_all(TZ_UI_STREAM_CB_NOCB, "Sign Hash", type,
TZ_UI_LAYOUT_BN, TZ_UI_ICON_NONE);

Expand Down
2 changes: 2 additions & 0 deletions app/src/ui_stream_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ blindsign_choice(bool confirm)
} else {
tz_ui_stream_t *s = &global.stream;

TZ_ASSERT(EXC_UNEXPECTED_STATE,
global.blindsign_reason != REASON_NONE);
if (global.blindsign_reason == REASON_TOO_MANY_SCREENS) {
s->cb(TZ_UI_STREAM_CB_SUMMARY);
} else {
Expand Down
1 change: 0 additions & 1 deletion tests/integration/touch/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# limitations under the License.

from utils import tezos_app, BlindsigningStatus
import os

if __name__ == "__main__":
app = tezos_app(__file__)
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/touch/test_blindsign_different_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def blindsign_common(app: TezosAppScreen):

def blindsign_review_sign(app: TezosAppScreen):
app.assert_screen("blindsign_warning_ledger_1")
app.review.enable_blindsign.reject()
app.review.back_to_safety.reject()
app.assert_screen("summary_review_transaction")
app.review.next()
app.assert_screen("tbdm_blind_review_1")
Expand Down Expand Up @@ -105,7 +105,7 @@ def blindsign_review_sign(app: TezosAppScreen):
app.assert_screen("tbdm_op_0_screen_8")
app.review.next()
app.assert_screen("blindsign_warning_too_many_screens")
app.review.enable_blindsign.reject()
app.review.back_to_safety.reject()
app.expect_apdu_return("9000")
app.send_apdu("800f81ff48000000096d6573736167653137000000096d6573736167653138000000096d65737361676531397000ffdd6102321bc251e4a5190ad5b12b251069d9b4c0843d0f0103ff80ade204")
blindsign_review_sign(app)
Expand All @@ -117,9 +117,9 @@ def blindsign_review_sign(app: TezosAppScreen):
send_payload(app, "800f01ffeb0300000000000000000000000000000000000000000000000000000000000000006b00ffdd6102321bc251e4a5190ad5b12b251069d9b4c0843d0b0104020320182716513907b6bab33f905396d031931c07e01bddd780780c1a56b9c086da6c00ffdd6102321bc251e4a5190ad5b12b251069d9b480897a0c0107c08db701000278eb8b6ab9a768579cd5146b480789650c83f28effff0d7570646174655f636f6e6669670000000607070005030a6e00ffdd6102321bc251e4a5190ad5b12b251069d9b4c08db7010d0105ff01ee572f02e5be5d097ba17369789582882e8abb87c900ffdd6102321bc2")
app.review.next()
app.assert_screen("tbdm_blindsign_on_screen_1")
app.welcome.settings() # skip button is at the same position as settings button on Home screen
app.review.skip()
app.assert_screen("skip_review")
app.review.enable_blindsign.confirm()
app.review.enable_skip.confirm()
app.expect_apdu_return("9000")
app.send_apdu("800f01ffeb51e4a5190ad5b12b251069d9b48092f4010e0106000000fa000000086d65737361676530000000086d65737361676531000000086d65737361676532000000086d65737361676533000000086d65737361676534000000086d65737361676535000000086d65737361676536000000086d65737361676537000000086d65737361676538000000086d65737361676539000000096d6573736167653130000000096d6573736167653131000000096d6573736167653132000000096d6573736167653133000000096d6573736167653134000000096d6573736167653135000000096d6573736167653136")
app.expect_apdu_return("9000")
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/touch/test_blindsign_too_deep.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
app.review.next()

app.assert_screen("tbtd_review_blindsign_on_0")
app.welcome.settings() # skip button
app.review.enable_blindsign.confirm()
app.review.skip() # skip button
app.review.enable_skip.confirm()
app.assert_screen("too_deep_blindsign_warning")
with app.fading_screen("loading_operation"):
app.review.enable_blindsign.reject()
Expand Down
12 changes: 10 additions & 2 deletions tests/integration/touch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from ragger.firmware.touch.element import Center
from ragger.firmware.touch.screen import MetaScreen
from ragger.firmware.touch.use_cases import (
UseCaseHome,
UseCaseHomeExt,
UseCaseSettings as OriginalUseCaseSettings,
UseCaseAddressConfirmation as OriginalUseCaseAddressConfirmation,
Expand Down Expand Up @@ -66,8 +67,10 @@ class UseCaseReview(OriginalUseCaseReview):
reject_tx: UseCaseChoice
enable_expert: UseCaseChoice
enable_blindsign: UseCaseChoice
enable_skip: UseCaseChoice
back_to_safety: UseCaseChoice
details: UseCaseViewDetails
__skip_screen: UseCaseHome

_center: Center
MORE_POSITIONS = {
Expand All @@ -81,8 +84,10 @@ def __init__(self, client: BackendInterface, firmware: Firmware):
self.enable_expert = UseCaseChoice(client, firmware)
self.enable_blindsign = UseCaseChoice(client, firmware)
self.back_to_safety = UseCaseChoice(client, firmware)
self._center = Center(client, firmware)
self.details = UseCaseViewDetails(client, firmware)
self.enable_skip = UseCaseChoice(client, firmware)
self._center = Center(client, firmware)
self.details = UseCaseViewDetails(client, firmware)
self.__skip_screen = UseCaseHome(client, firmware)

@property
def more_position(self) -> Position:
Expand All @@ -97,6 +102,9 @@ def show_more(self) -> None:
"""Tap to show more."""
self.client.finger_touch(*self.more_position)

def skip(self) -> None:
"""Press the skip button."""
self.__skip_screen.settings()

class UseCaseAddressConfirmation(OriginalUseCaseAddressConfirmation):
"""Extension of UseCaseAddressConfirmation for our app."""
Expand Down

0 comments on commit 0af9ac9

Please sign in to comment.