17
17
// Avoid saving the full structure when parsing
18
18
// Alternative option : add a callback to f_tlv_payload_handler
19
19
static uint16_t g_7702_sw ;
20
- static unsigned int g_7702_flags ;
21
20
22
21
#define MAGIC_7702 5
23
22
@@ -76,14 +75,15 @@ static bool handleAuth7702TLV(const uint8_t *payload, uint16_t size, bool to_fre
76
75
tlv_parse (payload , size , (f_tlv_data_handler ) handle_auth_7702_struct , & auth_7702_ctx );
77
76
if (to_free ) mem_dealloc (size );
78
77
if (!parsing_ret || !verify_auth_7702_struct (& auth_7702_ctx )) {
78
+ g_7702_sw = APDU_RESPONSE_INVALID_DATA ;
79
79
return false;
80
80
}
81
81
82
82
// Reject if not enabled
83
83
if (!N_storage .eip7702_enable ) {
84
84
ui_error_no_7702 ();
85
85
g_7702_sw = APDU_RESPONSE_CONDITION_NOT_SATISFIED ;
86
- return true ;
86
+ return false ;
87
87
}
88
88
89
89
// Compute the authorization hash
@@ -99,24 +99,24 @@ static bool handleAuth7702TLV(const uint8_t *payload, uint16_t size, bool to_fre
99
99
hashSize = rlpEncodeListHeader8 (rlpDataSize , rlpTmp + 1 , sizeof (rlpTmp ) - 1 );
100
100
if (hashSize == 0 ) {
101
101
g_7702_sw = APDU_RESPONSE_UNKNOWN ;
102
- return true ;
102
+ return false ;
103
103
}
104
104
CX_CHECK (cx_keccak_init_no_throw (& global_sha3 , 256 ));
105
105
CX_CHECK (cx_hash_no_throw ((cx_hash_t * ) & global_sha3 , 0 , rlpTmp , hashSize + 1 , NULL , 0 ));
106
106
sw = hashRLP64 (auth7702 -> chainId , rlpTmp , sizeof (rlpTmp ));
107
107
if (sw != APDU_NO_RESPONSE ) {
108
108
g_7702_sw = sw ;
109
- return true ;
109
+ return false ;
110
110
}
111
111
sw = hashRLP (auth7702 -> delegate , sizeof (auth7702 -> delegate ), rlpTmp , sizeof (rlpTmp ));
112
112
if (sw != APDU_NO_RESPONSE ) {
113
113
g_7702_sw = sw ;
114
- return true ;
114
+ return false ;
115
115
}
116
116
sw = hashRLP64 (auth7702 -> nonce , rlpTmp , sizeof (rlpTmp ));
117
117
if (sw != APDU_NO_RESPONSE ) {
118
118
g_7702_sw = sw ;
119
- return true ;
119
+ return false ;
120
120
}
121
121
CX_CHECK (cx_hash_no_throw ((cx_hash_t * ) & global_sha3 ,
122
122
CX_LAST ,
@@ -143,7 +143,7 @@ static bool handleAuth7702TLV(const uint8_t *payload, uint16_t size, bool to_fre
143
143
// Reject if not in the whitelist
144
144
ui_error_no_7702_whitelist ();
145
145
g_7702_sw = APDU_RESPONSE_CONDITION_NOT_SATISFIED ;
146
- return true ;
146
+ return false ;
147
147
} else {
148
148
strlcpy (strings .common .toAddress , delegateName , sizeof (strings .common .toAddress ));
149
149
}
@@ -153,7 +153,7 @@ static bool handleAuth7702TLV(const uint8_t *payload, uint16_t size, bool to_fre
153
153
sizeof (strings .common .toAddress ),
154
154
auth7702 -> chainId )) {
155
155
g_7702_sw = APDU_RESPONSE_UNKNOWN ;
156
- return true ;
156
+ return false ;
157
157
}
158
158
#endif // HAVE_EIP7702_WHITELIST
159
159
// * ChainId
@@ -178,22 +178,19 @@ static bool handleAuth7702TLV(const uint8_t *payload, uint16_t size, bool to_fre
178
178
}
179
179
180
180
ui_sign_7702_auth ();
181
- g_7702_flags |= IO_ASYNCH_REPLY ;
182
- g_7702_sw = APDU_NO_RESPONSE ;
183
181
return true;
184
182
185
183
end :
186
184
// Internal error triggered by CX_CHECK
187
185
g_7702_sw = APDU_RESPONSE_UNKNOWN ;
188
- return true ;
186
+ return false ;
189
187
}
190
188
191
189
uint16_t handleSignEIP7702Authorization (uint8_t p1 ,
192
190
const uint8_t * dataBuffer ,
193
191
uint8_t dataLength ,
194
192
unsigned int * flags ) {
195
- g_7702_sw = APDU_RESPONSE_OK ;
196
- g_7702_flags = * flags ;
193
+ g_7702_sw = APDU_RESPONSE_UNKNOWN ;
197
194
if (p1 == P1_FIRST_CHUNK ) {
198
195
if ((dataBuffer =
199
196
parseBip32 (dataBuffer , & dataLength , & tmpCtx .authSigningContext7702 .bip32 )) ==
@@ -202,10 +199,10 @@ uint16_t handleSignEIP7702Authorization(uint8_t p1,
202
199
}
203
200
}
204
201
if (!tlv_from_apdu (p1 == P1_FIRST_CHUNK , dataLength , dataBuffer , & handleAuth7702TLV )) {
205
- return APDU_RESPONSE_INVALID_DATA ;
202
+ return g_7702_sw ;
206
203
}
207
- * flags = g_7702_flags ;
208
- return g_7702_sw ;
204
+ * flags |= IO_ASYNCH_REPLY ;
205
+ return APDU_NO_RESPONSE ;
209
206
}
210
207
211
208
#endif // HAVE_EIP7702
0 commit comments