@@ -12,7 +12,7 @@ uint16_t handle_get_public_key(uint8_t p1,
1212 uint8_t dataLength ,
1313 unsigned int * tx ) {
1414 bip32_path_t bip32 ;
15- cx_err_t error = CX_INTERNAL_ERROR ;
15+ uint64_t chain_id ;
1616
1717 if (!G_called_from_swap ) {
1818 reset_app_context ();
@@ -33,18 +33,26 @@ uint16_t handle_get_public_key(uint8_t p1,
3333 }
3434
3535 tmpCtx .publicKeyContext .getChaincode = (p2 == P2_CHAINCODE );
36- CX_CHECK (get_public_key_string (
37- & bip32 ,
38- tmpCtx .publicKeyContext .publicKey .W ,
39- tmpCtx .publicKeyContext .address ,
40- (tmpCtx .publicKeyContext .getChaincode ? tmpCtx .publicKeyContext .chainCode : NULL ),
41- g_chain_config -> chain_id ));
36+ if (get_public_key_string (
37+ & bip32 ,
38+ tmpCtx .publicKeyContext .publicKey .W ,
39+ tmpCtx .publicKeyContext .address ,
40+ (tmpCtx .publicKeyContext .getChaincode ? tmpCtx .publicKeyContext .chainCode : NULL ),
41+ g_chain_config -> chain_id )) {
42+ return SWO_INCORRECT_DATA ;
43+ }
4244
43- uint64_t chain_id = g_chain_config -> chain_id ;
4445 if (dataLength >= sizeof (chain_id )) {
4546 chain_id = u64_from_BE (dataBuffer , sizeof (chain_id ));
4647 dataLength -= sizeof (chain_id );
4748 dataBuffer += sizeof (chain_id );
49+ if ((g_chain_config -> chain_id != ETHEREUM_MAINNET_CHAINID ) &&
50+ (chain_id != g_chain_config -> chain_id )) {
51+ // clones only accept their own chain ID
52+ return SWO_INCORRECT_DATA ;
53+ }
54+ } else {
55+ chain_id = g_chain_config -> chain_id ;
4856 }
4957
5058 (void ) dataBuffer ; // to prevent dead increment warning
@@ -62,10 +70,7 @@ uint16_t handle_get_public_key(uint8_t p1,
6270 "0x%.*s" ,
6371 40 ,
6472 tmpCtx .publicKeyContext .address );
65- // don't unnecessarily pass the current app's chain ID
66- ui_display_public_key (g_chain_config -> chain_id == chain_id ? NULL : & chain_id );
73+ ui_display_public_key (& chain_id );
6774 // Return code will be sent after UI approve/cancel
68- error = 0 ;
69- end :
70- return error ;
75+ return SWO_NO_RESPONSE ;
7176}
0 commit comments