Now uses some of the old EIP712 code as common code between the two implementations + approve/reject button now works
This commit is contained in:
@@ -53,12 +53,14 @@
|
||||
|
||||
#endif
|
||||
|
||||
#define OFFSET_CLA 0
|
||||
#define OFFSET_INS 1
|
||||
#define OFFSET_P1 2
|
||||
#define OFFSET_P2 3
|
||||
#define OFFSET_LC 4
|
||||
#define OFFSET_CDATA 5
|
||||
enum {
|
||||
OFFSET_CLA = 0,
|
||||
OFFSET_INS,
|
||||
OFFSET_P1,
|
||||
OFFSET_P2,
|
||||
OFFSET_LC,
|
||||
OFFSET_CDATA
|
||||
};
|
||||
|
||||
void handleGetPublicKey(uint8_t p1,
|
||||
uint8_t p2,
|
||||
@@ -99,7 +101,7 @@ void handleSignPersonalMessage(uint8_t p1,
|
||||
void handleSignEIP712Message_v0(uint8_t p1,
|
||||
uint8_t p2,
|
||||
const uint8_t *dataBuffer,
|
||||
uint16_t dataLength,
|
||||
uint8_t dataLength,
|
||||
unsigned int *flags,
|
||||
unsigned int *tx);
|
||||
|
||||
|
||||
@@ -675,6 +675,7 @@ void handleApdu(unsigned int *flags, unsigned int *tx) {
|
||||
}
|
||||
else
|
||||
{
|
||||
*flags |= IO_ASYNCH_REPLY;
|
||||
handle_eip712_sign(G_io_apdu_buffer);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -14,8 +14,6 @@ unsigned int io_seproxyhal_touch_signMessage_ok(const bagl_element_t *e);
|
||||
unsigned int io_seproxyhal_touch_signMessage_cancel(const bagl_element_t *e);
|
||||
unsigned int io_seproxyhal_touch_data_ok(const bagl_element_t *e);
|
||||
unsigned int io_seproxyhal_touch_data_cancel(const bagl_element_t *e);
|
||||
unsigned int io_seproxyhal_touch_signMessage712_v0_ok(const bagl_element_t *e);
|
||||
unsigned int io_seproxyhal_touch_signMessage712_v0_cancel(const bagl_element_t *e);
|
||||
unsigned int io_seproxyhal_touch_eth2_address_ok(const bagl_element_t *e);
|
||||
unsigned int io_seproxyhal_touch_privacy_ok(const bagl_element_t *e);
|
||||
unsigned int io_seproxyhal_touch_privacy_cancel(const bagl_element_t *e);
|
||||
|
||||
@@ -4,15 +4,6 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
enum {
|
||||
OFFSET_CLA = 0,
|
||||
OFFSET_INS,
|
||||
OFFSET_P1,
|
||||
OFFSET_P2,
|
||||
OFFSET_LC,
|
||||
OFFSET_DATA
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
// contract defined struct
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "apdu_constants.h"
|
||||
#include "eip712.h"
|
||||
#include "mem.h"
|
||||
#include "type_hash.h"
|
||||
@@ -12,6 +13,7 @@
|
||||
#include "path.h"
|
||||
#include "shared_context.h"
|
||||
#include "ui_logic.h"
|
||||
#include "common_712.h"
|
||||
|
||||
|
||||
// lib functions
|
||||
@@ -249,7 +251,7 @@ bool set_struct_name(const uint8_t *const data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
memmove(name_ptr, &data[OFFSET_DATA], data[OFFSET_LC]);
|
||||
memmove(name_ptr, &data[OFFSET_CDATA], data[OFFSET_LC]);
|
||||
|
||||
// initialize number of fields
|
||||
if ((current_struct_fields_array = mem_alloc(sizeof(uint8_t))) == NULL)
|
||||
@@ -264,7 +266,7 @@ bool set_struct_name(const uint8_t *const data)
|
||||
// TODO: Handle partial sends
|
||||
bool set_struct_field(const uint8_t *const data)
|
||||
{
|
||||
uint8_t data_idx = OFFSET_DATA;
|
||||
uint8_t data_idx = OFFSET_CDATA;
|
||||
uint8_t *type_desc_ptr;
|
||||
uint8_t *type_size_ptr;
|
||||
uint8_t *typename_len_ptr;
|
||||
@@ -403,16 +405,16 @@ bool handle_eip712_struct_impl(const uint8_t *const apdu_buf)
|
||||
{
|
||||
case P2_NAME:
|
||||
// set root type
|
||||
ret = path_set_root((char*)&apdu_buf[OFFSET_DATA],
|
||||
ret = path_set_root((char*)&apdu_buf[OFFSET_CDATA],
|
||||
apdu_buf[OFFSET_LC]);
|
||||
break;
|
||||
case P2_FIELD:
|
||||
ret = field_hash(&apdu_buf[OFFSET_DATA],
|
||||
ret = field_hash(&apdu_buf[OFFSET_CDATA],
|
||||
apdu_buf[OFFSET_LC],
|
||||
apdu_buf[OFFSET_P1] != P1_COMPLETE);
|
||||
break;
|
||||
case P2_ARRAY:
|
||||
ret = path_new_array_depth(apdu_buf[OFFSET_DATA]);
|
||||
ret = path_new_array_depth(apdu_buf[OFFSET_CDATA]);
|
||||
break;
|
||||
default:
|
||||
PRINTF("Unknown P2 0x%x for APDU 0x%x\n",
|
||||
@@ -432,22 +434,12 @@ bool handle_eip712_struct_impl(const uint8_t *const apdu_buf)
|
||||
|
||||
bool handle_eip712_sign(const uint8_t *const apdu_buf)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
if (apdu_buf[OFFSET_LC] < 1) {
|
||||
PRINTF("Invalid data\n");
|
||||
THROW(0x6a80);
|
||||
if (parseBip32(&apdu_buf[OFFSET_CDATA],
|
||||
&apdu_buf[OFFSET_LC],
|
||||
&tmpCtx.messageSigningContext.bip32) == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
tmpCtx.messageSigningContext712.pathLength = apdu_buf[OFFSET_DATA];
|
||||
if ((tmpCtx.messageSigningContext712.pathLength < 0x01) ||
|
||||
(tmpCtx.messageSigningContext712.pathLength > MAX_BIP32_PATH)) {
|
||||
PRINTF("Invalid path\n");
|
||||
THROW(0x6a80);
|
||||
}
|
||||
for (i = 0; i < tmpCtx.messageSigningContext712.pathLength; i++) {
|
||||
tmpCtx.messageSigningContext712.bip32Path[i] = U4BE(apdu_buf + OFFSET_LC + 1 + (i * 4), 0);
|
||||
}
|
||||
|
||||
ui_712_end_sign();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "ui_flow_712.h"
|
||||
#include "ui_logic.h"
|
||||
#include "shared_context.h" // strings
|
||||
#include "common_712.h"
|
||||
|
||||
// clang-format off
|
||||
UX_STEP_NOCB(
|
||||
@@ -30,7 +31,7 @@ UX_STEP_INIT(
|
||||
UX_STEP_CB(
|
||||
ux_712_step_approve,
|
||||
pb,
|
||||
NULL,//io_seproxyhal_touch_signMessage712_ok(NULL),
|
||||
ui_712_approve_cb(NULL),
|
||||
{
|
||||
&C_icon_validate_14,
|
||||
"Approve",
|
||||
@@ -38,7 +39,7 @@ UX_STEP_CB(
|
||||
UX_STEP_CB(
|
||||
ux_712_step_reject,
|
||||
pb,
|
||||
NULL,//io_seproxyhal_touch_signMessage712_cancel(NULL),
|
||||
ui_712_reject_cb(NULL),
|
||||
{
|
||||
&C_icon_crossmark,
|
||||
"Reject",
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
#include "os_io_seproxyhal.h"
|
||||
#include "shared_context.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
#include "ui_callbacks.h"
|
||||
#include "common_712.h"
|
||||
|
||||
static const uint8_t EIP_712_MAGIC[] = {0x19, 0x01};
|
||||
|
||||
unsigned int io_seproxyhal_touch_signMessage712_v0_ok(__attribute__((unused))
|
||||
const bagl_element_t *e) {
|
||||
unsigned int ui_712_approve_cb(const bagl_element_t *e)
|
||||
{
|
||||
uint8_t privateKeyData[INT256_LENGTH];
|
||||
uint8_t hash[INT256_LENGTH];
|
||||
uint8_t signature[100];
|
||||
cx_ecfp_private_key_t privateKey;
|
||||
uint32_t tx = 0;
|
||||
|
||||
(void)e;
|
||||
io_seproxyhal_io_heartbeat();
|
||||
cx_keccak_init(&global_sha3, 256);
|
||||
cx_hash((cx_hash_t *) &global_sha3,
|
||||
@@ -53,10 +56,12 @@ unsigned int io_seproxyhal_touch_signMessage712_v0_ok(__attribute__((unused))
|
||||
&info);
|
||||
explicit_bzero(&privateKey, sizeof(privateKey));
|
||||
G_io_apdu_buffer[0] = 27;
|
||||
if (info & CX_ECCINFO_PARITY_ODD) {
|
||||
if (info & CX_ECCINFO_PARITY_ODD)
|
||||
{
|
||||
G_io_apdu_buffer[0]++;
|
||||
}
|
||||
if (info & CX_ECCINFO_xGTn) {
|
||||
if (info & CX_ECCINFO_xGTn)
|
||||
{
|
||||
G_io_apdu_buffer[0] += 2;
|
||||
}
|
||||
format_signature_out(signature);
|
||||
@@ -71,8 +76,9 @@ unsigned int io_seproxyhal_touch_signMessage712_v0_ok(__attribute__((unused))
|
||||
return 0; // do not redraw the widget
|
||||
}
|
||||
|
||||
unsigned int io_seproxyhal_touch_signMessage712_v0_cancel(__attribute__((unused))
|
||||
const bagl_element_t *e) {
|
||||
unsigned int ui_712_reject_cb(const bagl_element_t *e)
|
||||
{
|
||||
(void)e;
|
||||
reset_app_context();
|
||||
G_io_apdu_buffer[0] = 0x69;
|
||||
G_io_apdu_buffer[1] = 0x85;
|
||||
10
src_features/signMessageEIP712_common/common_712.h
Normal file
10
src_features/signMessageEIP712_common/common_712.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef COMMON_EIP712_H_
|
||||
#define COMMON_EIP712_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "ux.h"
|
||||
|
||||
unsigned int ui_712_approve_cb(const bagl_element_t *e);
|
||||
unsigned int ui_712_reject_cb(const bagl_element_t *e);
|
||||
|
||||
#endif // COMMON_EIP712_H_
|
||||
@@ -2,15 +2,15 @@
|
||||
#include "apdu_constants.h"
|
||||
#include "utils.h"
|
||||
#include "ui_flow.h"
|
||||
#include "eip712.h"
|
||||
#include "common_712.h"
|
||||
|
||||
void handleSignEIP712Message_v0(uint8_t p1,
|
||||
uint8_t p2,
|
||||
const uint8_t *workBuffer,
|
||||
uint16_t dataLength,
|
||||
uint8_t dataLength,
|
||||
unsigned int *flags,
|
||||
unsigned int *tx) {
|
||||
uint8_t i;
|
||||
|
||||
UNUSED(tx);
|
||||
if ((p1 != 00) || (p2 != 00)) {
|
||||
THROW(0x6B00);
|
||||
@@ -21,11 +21,15 @@ void handleSignEIP712Message_v0(uint8_t p1,
|
||||
|
||||
workBuffer = parseBip32(workBuffer, &dataLength, &tmpCtx.messageSigningContext.bip32);
|
||||
|
||||
if ((workBuffer == NULL) || (dataLength < (32 + 32))) {
|
||||
if ((workBuffer == NULL) || (dataLength < (KECCAK256_HASH_BYTESIZE * 2))) {
|
||||
THROW(0x6a80);
|
||||
}
|
||||
memmove(tmpCtx.messageSigningContext712.domainHash, workBuffer, 32);
|
||||
memmove(tmpCtx.messageSigningContext712.messageHash, workBuffer + 32, 32);
|
||||
memmove(tmpCtx.messageSigningContext712.domainHash,
|
||||
workBuffer,
|
||||
KECCAK256_HASH_BYTESIZE);
|
||||
memmove(tmpCtx.messageSigningContext712.messageHash,
|
||||
workBuffer + KECCAK256_HASH_BYTESIZE,
|
||||
KECCAK256_HASH_BYTESIZE);
|
||||
|
||||
#ifdef NO_CONSENT
|
||||
io_seproxyhal_touch_signMessage_ok(NULL);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "shared_context.h"
|
||||
#include "ui_callbacks.h"
|
||||
#include "common_712.h"
|
||||
|
||||
void prepare_domain_hash_v0() {
|
||||
snprintf(strings.tmp.tmp, 70, "0x%.*H", 32, tmpCtx.messageSigningContext712.domainHash);
|
||||
@@ -37,7 +38,7 @@ UX_STEP_NOCB_INIT(
|
||||
UX_STEP_CB(
|
||||
ux_sign_712_v0_flow_4_step,
|
||||
pbb,
|
||||
io_seproxyhal_touch_signMessage712_v0_ok(NULL),
|
||||
ui_712_approve_cb(NULL),
|
||||
{
|
||||
&C_icon_validate_14,
|
||||
"Sign",
|
||||
@@ -46,7 +47,7 @@ UX_STEP_CB(
|
||||
UX_STEP_CB(
|
||||
ux_sign_712_v0_flow_5_step,
|
||||
pbb,
|
||||
io_seproxyhal_touch_signMessage712_v0_cancel(NULL),
|
||||
ui_712_reject_cb(NULL),
|
||||
{
|
||||
&C_icon_crossmark,
|
||||
"Cancel",
|
||||
|
||||
Reference in New Issue
Block a user