From 90dfa74538b5d2ccdb519bace02b64628cbc7e2f Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Wed, 4 May 2022 17:16:25 +0200 Subject: [PATCH] Emulates old behaviour with new APDUs but computed all on-device --- src_features/signMessageEIP712/path.c | 18 ++++++++++++++++-- .../signMessageEIP712_v0/cmd_signMessage712.c | 15 ++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src_features/signMessageEIP712/path.c b/src_features/signMessageEIP712/path.c index 8a8ec1f..00acffd 100644 --- a/src_features/signMessageEIP712/path.c +++ b/src_features/signMessageEIP712/path.c @@ -6,6 +6,7 @@ #include "eip712.h" #include "type_hash.h" #include "shared_context.h" +#include "ethUtils.h" static s_path *path_struct = NULL; @@ -131,9 +132,22 @@ static bool path_depth_list_pop(void) NULL, 0); } -#ifdef DEBUG else { + if (allzeroes(tmpCtx.messageSigningContext712.domainHash, KECCAK256_HASH_BYTESIZE)) + { + memcpy(tmpCtx.messageSigningContext712.domainHash, + shash, + KECCAK256_HASH_BYTESIZE); + } + else + { + memcpy(tmpCtx.messageSigningContext712.messageHash, + shash, + KECCAK256_HASH_BYTESIZE); + mem_reset(); + } +#ifdef DEBUG PRINTF("Hash = 0x"); for (int idx = 0; idx < KECCAK256_HASH_BYTESIZE; ++idx) { @@ -142,8 +156,8 @@ static bool path_depth_list_pop(void) PRINTF("%x", shash[idx]); } PRINTF("\n\n"); - } #endif + } return true; } diff --git a/src_features/signMessageEIP712_v0/cmd_signMessage712.c b/src_features/signMessageEIP712_v0/cmd_signMessage712.c index cd32dad..3834711 100644 --- a/src_features/signMessageEIP712_v0/cmd_signMessage712.c +++ b/src_features/signMessageEIP712_v0/cmd_signMessage712.c @@ -13,7 +13,7 @@ void handleSignEIP712Message_v0(uint8_t p1, UNUSED(tx); if ((p1 != 00) || (p2 != 00)) { - THROW(0x6B00); + //THROW(0x6B00); // TODO: TMP } if (appState != APP_STATE_IDLE) { reset_app_context(); @@ -21,12 +21,17 @@ void handleSignEIP712Message_v0(uint8_t p1, workBuffer = parseBip32(workBuffer, &dataLength, &tmpCtx.messageSigningContext.bip32); - if (workBuffer == NULL || dataLength < 32 + 32) { + if (workBuffer == NULL) { THROW(0x6a80); } - - memmove(tmpCtx.messageSigningContext712.domainHash, workBuffer, 32); - memmove(tmpCtx.messageSigningContext712.messageHash, workBuffer + 32, 32); + if (p2 == 0) // TODO: TMP + { + if (dataLength < (32 + 32)) { + THROW(0x6a80); + } + memmove(tmpCtx.messageSigningContext712.domainHash, workBuffer, 32); + memmove(tmpCtx.messageSigningContext712.messageHash, workBuffer + 32, 32); + } #ifdef NO_CONSENT io_seproxyhal_touch_signMessage_ok(NULL);