Merge branch 'master' of github.com:LedgerHQ/app-ethereum into fix_security_and_display_issues
This commit is contained in:
@@ -61,4 +61,6 @@ typedef struct chain_config_s {
|
||||
chain_kind_t kind;
|
||||
} chain_config_t;
|
||||
|
||||
#define ETHEREUM_MAINNET_CHAINID 1
|
||||
|
||||
#endif /* _CHAIN_CONFIG_H_ */
|
||||
|
||||
40
src/main.c
40
src/main.c
@@ -373,11 +373,47 @@ tokenDefinition_t *getKnownToken(uint8_t *contractAddress) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned int const U_os_perso_seed_cookie[] = {
|
||||
0xda7aba5e,
|
||||
0xc1a551c5,
|
||||
};
|
||||
|
||||
#ifndef HAVE_WALLET_ID_SDK
|
||||
|
||||
void handleGetWalletId(volatile unsigned int *tx) {
|
||||
unsigned char t[64];
|
||||
cx_ecfp_256_private_key_t priv;
|
||||
cx_ecfp_256_public_key_t pub;
|
||||
// seed => priv key
|
||||
os_perso_derive_node_bip32(CX_CURVE_256K1, U_os_perso_seed_cookie, 2, t, NULL);
|
||||
// priv key => pubkey
|
||||
cx_ecdsa_init_private_key(CX_CURVE_256K1, t, 32, &priv);
|
||||
cx_ecfp_generate_pair(CX_CURVE_256K1, &pub, &priv, 1);
|
||||
// pubkey -> sha512
|
||||
cx_hash_sha512(pub.W, sizeof(pub.W), t, sizeof(t));
|
||||
// ! cookie !
|
||||
os_memmove(G_io_apdu_buffer, t, 64);
|
||||
*tx = 64;
|
||||
THROW(0x9000);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void handleApdu(unsigned int *flags, unsigned int *tx) {
|
||||
unsigned short sw = 0;
|
||||
|
||||
BEGIN_TRY {
|
||||
TRY {
|
||||
#ifndef HAVE_WALLET_ID_SDK
|
||||
|
||||
if ((G_io_apdu_buffer[OFFSET_CLA] == COMMON_CLA) &&
|
||||
(G_io_apdu_buffer[OFFSET_INS] == COMMON_INS_GET_WALLET_ID)) {
|
||||
handleGetWalletId(tx);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STARKWARE
|
||||
|
||||
if (G_io_apdu_buffer[OFFSET_CLA] == STARKWARE_CLA) {
|
||||
@@ -714,7 +750,11 @@ void coin_main(chain_config_t *coin_config) {
|
||||
|
||||
if (N_storage.initialized != 0x01) {
|
||||
internalStorage_t storage;
|
||||
#ifdef HAVE_ALLOW_DATA
|
||||
storage.dataAllowed = 0x01;
|
||||
#else
|
||||
storage.dataAllowed = 0x00;
|
||||
#endif
|
||||
storage.contractDetails = 0x00;
|
||||
storage.displayNonce = 0x00;
|
||||
storage.initialized = 0x01;
|
||||
|
||||
@@ -158,7 +158,9 @@ typedef struct txStringProperties_t {
|
||||
char fullAddress[43];
|
||||
char fullAmount[50];
|
||||
char maxFee[50];
|
||||
char nonce[8]; // 10M tx per account ought to be enough for everybody
|
||||
char nonce[8]; // 10M tx per account ought to be enough for everybody
|
||||
char chainID[8]; // 10M different chainID ought to be enough for people to find a unique
|
||||
// chainID for their token / chain.
|
||||
} txStringProperties_t;
|
||||
|
||||
typedef struct strDataTmp_t {
|
||||
|
||||
29
src/utils.c
29
src/utils.c
@@ -53,22 +53,23 @@ int local_strchr(char *string, char ch) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t getV(txContent_t *txContent) {
|
||||
uint32_t v = 0;
|
||||
if (txContent->vLength == 1) {
|
||||
v = txContent->v[0];
|
||||
} else if (txContent->vLength == 2) {
|
||||
v = (txContent->v[0] << 8) | txContent->v[1];
|
||||
} else if (txContent->vLength == 3) {
|
||||
v = (txContent->v[0] << 16) | (txContent->v[1] << 8) | txContent->v[2];
|
||||
} else if (txContent->vLength == 4) {
|
||||
v = (txContent->v[0] << 24) | (txContent->v[1] << 16) | (txContent->v[2] << 8) |
|
||||
txContent->v[3];
|
||||
} else if (txContent->vLength != 0) {
|
||||
PRINTF("Unexpected v format\n");
|
||||
// Almost like U4BE except that it takes `size` as a parameter.
|
||||
// The `strict` parameter defines whether we should throw in case of a length > 4.
|
||||
uint32_t u32_from_BE(uint8_t *in, uint8_t size, bool strict) {
|
||||
uint32_t res = 0;
|
||||
if (size == 1) {
|
||||
res = in[0];
|
||||
} else if (size == 2) {
|
||||
res = (in[0] << 8) | in[1];
|
||||
} else if (size == 3) {
|
||||
res = (in[0] << 16) | (in[1] << 8) | in[2];
|
||||
} else if (size == 4) {
|
||||
res = (in[0] << 24) | (in[1] << 16) | (in[2] << 8) | in[3];
|
||||
} else if (strict && size != 0) {
|
||||
PRINTF("Unexpected format\n");
|
||||
THROW(EXCEPTION);
|
||||
}
|
||||
return v;
|
||||
return res;
|
||||
}
|
||||
|
||||
void amountToString(uint8_t *amount,
|
||||
|
||||
@@ -28,7 +28,9 @@ void convertUint256BE(uint8_t* data, uint32_t length, uint256_t* target);
|
||||
|
||||
int local_strchr(char* string, char ch);
|
||||
|
||||
uint32_t getV(txContent_t* txContent);
|
||||
// Converts a list of bytes (in BE) of length `size` to a uint32_t. `strict` will make the function
|
||||
// throw if the size is > 4.
|
||||
uint32_t u32_from_BE(uint8_t* in, uint8_t size, bool strict);
|
||||
|
||||
void amountToString(uint8_t* amount,
|
||||
uint8_t amount_len,
|
||||
|
||||
Reference in New Issue
Block a user