From 00f6312a81c5856796857a23ec3e65399b8b25cc Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Sun, 18 Jun 2017 21:10:12 +0200 Subject: [PATCH] rename failures, unify strings where possible --- firmware/ethereum.c | 24 ++++++------ firmware/fsm.c | 74 ++++++++++++++++++------------------- firmware/messages.c | 6 +-- firmware/protect.c | 6 +-- firmware/protob/types.pb.h | 4 +- firmware/recovery.c | 8 ++-- firmware/reset.c | 6 +-- firmware/signing.c | 76 +++++++++++++++++++------------------- vendor/trezor-common | 2 +- 9 files changed, 103 insertions(+), 103 deletions(-) diff --git a/firmware/ethereum.c b/firmware/ethereum.c index 3ebf234ec7..9715de9ceb 100644 --- a/firmware/ethereum.c +++ b/firmware/ethereum.c @@ -163,7 +163,7 @@ static void send_signature(void) keccak_Final(&keccak_ctx, hash); if (ecdsa_sign_digest(&secp256k1, privkey, hash, sig, &v, ethereum_is_canonic) != 0) { - fsm_sendFailure(FailureType_Failure_Other, "Signing failed"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Signing failed"); ethereum_signing_abort(); return; } @@ -409,7 +409,7 @@ void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node) /* eip-155 chain id */ if (msg->has_chain_id) { if (msg->chain_id < 1 || msg->chain_id > 109) { - fsm_sendFailure(FailureType_Failure_Other, "Chain Id out of bounds"); + fsm_sendFailure(FailureType_Failure_DataError, "Chain Id out of bounds"); ethereum_signing_abort(); return; } @@ -420,7 +420,7 @@ void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node) if (msg->has_data_length && msg->data_length > 0) { if (!msg->has_data_initial_chunk || msg->data_initial_chunk.size == 0) { - fsm_sendFailure(FailureType_Failure_Other, "Data length provided, but no initial chunk"); + fsm_sendFailure(FailureType_Failure_DataError, "Data length provided, but no initial chunk"); ethereum_signing_abort(); return; } @@ -428,7 +428,7 @@ void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node) * prevent exceeding the limit we use a stricter limit on data length. */ if (msg->data_length > 16000000) { - fsm_sendFailure(FailureType_Failure_Other, "Data length exceeds limit"); + fsm_sendFailure(FailureType_Failure_DataError, "Data length exceeds limit"); ethereum_signing_abort(); return; } @@ -437,14 +437,14 @@ void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node) data_total = 0; } if (msg->data_initial_chunk.size > data_total) { - fsm_sendFailure(FailureType_Failure_Other, "Invalid size of initial chunk"); + fsm_sendFailure(FailureType_Failure_DataError, "Invalid size of initial chunk"); ethereum_signing_abort(); return; } // safety checks if (!ethereum_signing_check(msg)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Signing aborted (safety check failed)"); + fsm_sendFailure(FailureType_Failure_DataError, "Safety check failed"); ethereum_signing_abort(); return; } @@ -464,7 +464,7 @@ void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node) } if (!protectButton(ButtonRequestType_ButtonRequest_SignTx, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Signing cancelled by user"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); ethereum_signing_abort(); return; } @@ -472,7 +472,7 @@ void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node) if (token == NULL && data_total > 0) { layoutEthereumData(msg->data_initial_chunk.bytes, msg->data_initial_chunk.size, data_total); if (!protectButton(ButtonRequestType_ButtonRequest_SignTx, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Signing cancelled by user"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); ethereum_signing_abort(); return; } @@ -482,7 +482,7 @@ void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node) msg->gas_price.bytes, msg->gas_price.size, msg->gas_limit.bytes, msg->gas_limit.size, token != NULL); if (!protectButton(ButtonRequestType_ButtonRequest_SignTx, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Signing cancelled by user"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); ethereum_signing_abort(); return; } @@ -530,19 +530,19 @@ void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node) void ethereum_signing_txack(EthereumTxAck *tx) { if (!ethereum_signing) { - fsm_sendFailure(FailureType_Failure_UnexpectedMessage, "Not in Signing mode"); + fsm_sendFailure(FailureType_Failure_UnexpectedMessage, "Not in Ethereum signing mode"); layoutHome(); return; } if (tx->data_chunk.size > data_left) { - fsm_sendFailure(FailureType_Failure_Other, "Too much data"); + fsm_sendFailure(FailureType_Failure_DataError, "Too much data"); ethereum_signing_abort(); return; } if (data_left > 0 && (!tx->has_data_chunk || tx->data_chunk.size == 0)) { - fsm_sendFailure(FailureType_Failure_Other, "Empty data chunk received"); + fsm_sendFailure(FailureType_Failure_DataError, "Empty data chunk received"); ethereum_signing_abort(); return; } diff --git a/firmware/fsm.c b/firmware/fsm.c index 70cfaf08f2..cb2c7d1782 100644 --- a/firmware/fsm.c +++ b/firmware/fsm.c @@ -86,7 +86,7 @@ static uint8_t msg_resp[MSG_OUT_SIZE] __attribute__ ((aligned)); #define CHECK_PARAM(cond, errormsg) \ if (!(cond)) { \ - fsm_sendFailure(FailureType_Failure_SyntaxError, (errormsg)); \ + fsm_sendFailure(FailureType_Failure_DataError, (errormsg)); \ layoutHome(); \ return; \ } @@ -127,7 +127,7 @@ const CoinType *fsm_getCoin(bool has_name, const char *name) coin = coinByName("Bitcoin"); } if (!coin) { - fsm_sendFailure(FailureType_Failure_Other, "Invalid coin name"); + fsm_sendFailure(FailureType_Failure_DataError, "Invalid coin name"); layoutHome(); return 0; } @@ -146,7 +146,7 @@ HDNode *fsm_getDerivedNode(const char *curve, uint32_t *address_n, size_t addres return &node; } if (hdnode_private_ckd_cached(&node, address_n, address_n_count, NULL) == 0) { - fsm_sendFailure(FailureType_Failure_Other, "Failed to derive private key"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Failed to derive private key"); layoutHome(); return 0; } @@ -203,7 +203,7 @@ void fsm_msgPing(Ping *msg) if (msg->has_button_protection && msg->button_protection) { layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, "Do you really want to", "answer to ping?", NULL, NULL, NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Ping cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } @@ -215,7 +215,7 @@ void fsm_msgPing(Ping *msg) if (msg->has_passphrase_protection && msg->passphrase_protection) { if (!protectPassphrase()) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Ping cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); return; } } @@ -246,7 +246,7 @@ void fsm_msgChangePin(ChangePin *msg) } } if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, removal ? "PIN removal cancelled" : "PIN change cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } @@ -260,7 +260,7 @@ void fsm_msgChangePin(ChangePin *msg) if (protectChangePin()) { fsm_sendSuccess("PIN changed"); } else { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "PIN change failed"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); } } layoutHome(); @@ -271,7 +271,7 @@ void fsm_msgWipeDevice(WipeDevice *msg) (void)msg; layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, "Do you really want to", "wipe the device?", NULL, "All data will be lost.", NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_WipeDevice, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Wipe cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } @@ -289,7 +289,7 @@ void fsm_msgGetEntropy(GetEntropy *msg) { layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, "Do you really want to", "send entropy?", NULL, NULL, NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Entropy cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } @@ -338,7 +338,7 @@ void fsm_msgGetPublicKey(GetPublicKey *msg) if (msg->has_show_display && msg->show_display) { layoutPublicKey(node->public_key); if (!protectButton(ButtonRequestType_ButtonRequest_PublicKey, true)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Show public key cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } @@ -369,14 +369,14 @@ void fsm_msgLoadDevice(LoadDevice *msg) layoutDialogSwipe(&bmp_icon_question, "Cancel", "I take the risk", NULL, "Loading private seed", "is not recommended.", "Continue only if you", "know what you are", "doing!", NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Load cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } if (msg->has_mnemonic && !(msg->has_skip_checksum && msg->skip_checksum) ) { if (!mnemonic_check(msg->mnemonic)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Mnemonic with wrong checksum provided"); + fsm_sendFailure(FailureType_Failure_DataError, "Mnemonic with wrong checksum provided"); layoutHome(); return; } @@ -435,7 +435,7 @@ void fsm_msgCancel(Cancel *msg) recovery_abort(); signing_abort(); ethereum_signing_abort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Aborted"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); } void fsm_msgEthereumSignTx(EthereumSignTx *msg) @@ -474,7 +474,7 @@ void fsm_msgCipherKeyValue(CipherKeyValue *msg) if ((encrypt && ask_on_encrypt) || (!encrypt && ask_on_decrypt)) { layoutCipherKeyValue(encrypt, msg->key); if (!protectButton(ButtonRequestType_ButtonRequest_Other, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "CipherKeyValue cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } @@ -520,7 +520,7 @@ void fsm_msgApplySettings(ApplySettings *msg) if (msg->has_label) { layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, "Do you really want to", "change label to", msg->label, "?", NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } @@ -528,7 +528,7 @@ void fsm_msgApplySettings(ApplySettings *msg) if (msg->has_language) { layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, "Do you really want to", "change language to", msg->language, "?", NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } @@ -536,7 +536,7 @@ void fsm_msgApplySettings(ApplySettings *msg) if (msg->has_use_passphrase) { layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, "Do you really want to", msg->use_passphrase ? "enable passphrase" : "disable passphrase", "encryption?", NULL, NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } @@ -544,7 +544,7 @@ void fsm_msgApplySettings(ApplySettings *msg) if (msg->has_homescreen) { layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, "Do you really want to", "change the home", "screen ?", NULL, NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } @@ -583,7 +583,7 @@ void fsm_msgGetAddress(GetAddress *msg) layoutProgress("Computing address", 0); if (!compute_address(coin, msg->script_type, node, msg->has_multisig, &msg->multisig, resp->address)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Can't encode address"); + fsm_sendFailure(FailureType_Failure_DataError, "Can't encode address"); } if (msg->has_show_display && msg->show_display) { @@ -601,7 +601,7 @@ void fsm_msgGetAddress(GetAddress *msg) } layoutAddress(resp->address, desc); if (!protectButton(ButtonRequestType_ButtonRequest_Address, true)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Show address cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } @@ -636,7 +636,7 @@ void fsm_msgEthereumGetAddress(EthereumGetAddress *msg) layoutAddress(address, desc); if (!protectButton(ButtonRequestType_ButtonRequest_Address, true)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Show address cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } @@ -663,7 +663,7 @@ void fsm_msgSignMessage(SignMessage *msg) layoutSignMessage(msg->message.bytes, msg->message.size); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Sign message cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } @@ -683,7 +683,7 @@ void fsm_msgSignMessage(SignMessage *msg) resp->signature.size = 65; msg_write(MessageType_MessageType_MessageSignature, resp); } else { - fsm_sendFailure(FailureType_Failure_Other, "Error signing message"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Error signing message"); } layoutHome(); } @@ -698,26 +698,26 @@ void fsm_msgVerifyMessage(VerifyMessage *msg) uint8_t addr_raw[MAX_ADDR_RAW_SIZE]; uint32_t address_type; if (!coinExtractAddressType(coin, msg->address, &address_type) || !ecdsa_address_decode(msg->address, address_type, addr_raw)) { - fsm_sendFailure(FailureType_Failure_InvalidSignature, "Invalid address"); + fsm_sendFailure(FailureType_Failure_DataError, "Invalid address"); return; } layoutProgressSwipe("Verifying", 0); if (msg->signature.size == 65 && cryptoMessageVerify(coin, msg->message.bytes, msg->message.size, address_type, addr_raw, msg->signature.bytes) == 0) { layoutVerifyAddress(msg->address); if (!protectButton(ButtonRequestType_ButtonRequest_Other, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Message verification cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } layoutVerifyMessage(msg->message.bytes, msg->message.size); if (!protectButton(ButtonRequestType_ButtonRequest_Other, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Message verification cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } fsm_sendSuccess("Message verified"); } else { - fsm_sendFailure(FailureType_Failure_InvalidSignature, "Invalid signature"); + fsm_sendFailure(FailureType_Failure_DataError, "Invalid signature"); } layoutHome(); } @@ -730,7 +730,7 @@ void fsm_msgSignIdentity(SignIdentity *msg) layoutSignIdentity(&(msg->identity), msg->has_challenge_visual ? msg->challenge_visual : 0); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Sign identity cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } @@ -739,7 +739,7 @@ void fsm_msgSignIdentity(SignIdentity *msg) uint8_t hash[32]; if (!msg->has_identity || cryptoIdentityFingerprint(&(msg->identity), hash) == 0) { - fsm_sendFailure(FailureType_Failure_Other, "Invalid identity"); + fsm_sendFailure(FailureType_Failure_DataError, "Invalid identity"); layoutHome(); return; } @@ -793,7 +793,7 @@ void fsm_msgSignIdentity(SignIdentity *msg) resp->signature.size = 65; msg_write(MessageType_MessageType_SignedIdentity, resp); } else { - fsm_sendFailure(FailureType_Failure_Other, "Error signing identity"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Error signing identity"); } layoutHome(); } @@ -806,7 +806,7 @@ void fsm_msgGetECDHSessionKey(GetECDHSessionKey *msg) layoutDecryptIdentity(&msg->identity); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "ECDH Session cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } @@ -815,7 +815,7 @@ void fsm_msgGetECDHSessionKey(GetECDHSessionKey *msg) uint8_t hash[32]; if (!msg->has_identity || cryptoIdentityFingerprint(&(msg->identity), hash) == 0) { - fsm_sendFailure(FailureType_Failure_Other, "Invalid identity"); + fsm_sendFailure(FailureType_Failure_DataError, "Invalid identity"); layoutHome(); return; } @@ -841,7 +841,7 @@ void fsm_msgGetECDHSessionKey(GetECDHSessionKey *msg) resp->session_key.size = result_size; msg_write(MessageType_MessageType_ECDHSessionKey, resp); } else { - fsm_sendFailure(FailureType_Failure_Other, "Error getting ECDH session key"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Error getting ECDH session key"); } layoutHome(); } @@ -874,13 +874,13 @@ void fsm_msgEncryptMessage(EncryptMessage *msg) } layoutEncryptMessage(msg->message.bytes, msg->message.size, signing); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Encrypt message cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } layoutProgressSwipe("Encrypting", 0); if (cryptoMessageEncrypt(&pubkey, msg->message.bytes, msg->message.size, display_only, resp->nonce.bytes, &(resp->nonce.size), resp->message.bytes, &(resp->message.size), resp->hmac.bytes, &(resp->hmac.size), signing ? node->private_key : 0, signing ? address_raw : 0) != 0) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Error encrypting message"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Error encrypting message"); layoutHome(); return; } @@ -914,7 +914,7 @@ void fsm_msgDecryptMessage(DecryptMessage *msg) bool signing = false; uint8_t address_raw[MAX_ADDR_RAW_SIZE]; if (cryptoMessageDecrypt(&nonce_pubkey, msg->message.bytes, msg->message.size, msg->hmac.bytes, msg->hmac.size, node->private_key, resp->message.bytes, &(resp->message.size), &display_only, &signing, address_raw) != 0) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Error decrypting message"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } @@ -972,7 +972,7 @@ void fsm_msgSetU2FCounter(SetU2FCounter *msg) { layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, "Do you want to set", "the U2F counter?", NULL, NULL, NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "SetU2FCounter cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } diff --git a/firmware/messages.c b/firmware/messages.c index cf80ac7921..dcdee40f56 100644 --- a/firmware/messages.c +++ b/firmware/messages.c @@ -230,7 +230,7 @@ void msg_process(char type, uint16_t msg_id, const pb_field_t *fields, uint8_t * if (status) { MessageProcessFunc(type, 'i', msg_id, msg_data); } else { - fsm_sendFailure(FailureType_Failure_SyntaxError, stream.errmsg); + fsm_sendFailure(FailureType_Failure_DataError, stream.errmsg); } } @@ -258,7 +258,7 @@ void msg_read_common(char type, const uint8_t *buf, int len) return; } if (msg_size > MSG_IN_SIZE) { // message is too big :( - fsm_sendFailure(FailureType_Failure_SyntaxError, "Message too big"); + fsm_sendFailure(FailureType_Failure_DataError, "Message too big"); return; } @@ -353,7 +353,7 @@ void msg_read_tiny(const uint8_t *buf, int len) if (status) { msg_tiny_id = msg_id; } else { - fsm_sendFailure(FailureType_Failure_SyntaxError, stream.errmsg); + fsm_sendFailure(FailureType_Failure_DataError, stream.errmsg); msg_tiny_id = 0xFFFF; } } else { diff --git a/firmware/protect.c b/firmware/protect.c index 8ba3298c56..d47e58133a 100644 --- a/firmware/protect.c +++ b/firmware/protect.c @@ -170,7 +170,7 @@ bool protectPin(bool use_cached) protectAbortedByInitialize = true; msg_tiny_id = 0xFFFF; usbTiny(0); - fsm_sendFailure(FailureType_Failure_PinCancelled, "PIN Cancelled"); + fsm_sendFailure(FailureType_Failure_PinCancelled, "PIN cancelled"); return false; } wait--; @@ -179,7 +179,7 @@ bool protectPin(bool use_cached) const char *pin; pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_Current, "Please enter current PIN:"); if (!pin) { - fsm_sendFailure(FailureType_Failure_PinCancelled, "PIN Cancelled"); + fsm_sendFailure(FailureType_Failure_PinCancelled, "PIN cancelled"); return false; } if (storage_increasePinFails(fails) && storage_isPinCorrect(pin)) { @@ -187,7 +187,7 @@ bool protectPin(bool use_cached) storage_resetPinFails(fails); return true; } else { - fsm_sendFailure(FailureType_Failure_PinInvalid, "Invalid PIN"); + fsm_sendFailure(FailureType_Failure_PinInvalid, "PIN invalid"); return false; } } diff --git a/firmware/protob/types.pb.h b/firmware/protob/types.pb.h index 4e25d7de28..8ddbee4ffe 100644 --- a/firmware/protob/types.pb.h +++ b/firmware/protob/types.pb.h @@ -12,13 +12,13 @@ extern "C" { typedef enum _FailureType { FailureType_Failure_UnexpectedMessage = 1, FailureType_Failure_ButtonExpected = 2, - FailureType_Failure_SyntaxError = 3, + FailureType_Failure_DataError = 3, FailureType_Failure_ActionCancelled = 4, FailureType_Failure_PinExpected = 5, FailureType_Failure_PinCancelled = 6, FailureType_Failure_PinInvalid = 7, FailureType_Failure_InvalidSignature = 8, - FailureType_Failure_Other = 9, + FailureType_Failure_ProcessError = 9, FailureType_Failure_NotEnoughFunds = 10, FailureType_Failure_NotInitialized = 11, FailureType_Failure_FirmwareError = 99 diff --git a/firmware/recovery.c b/firmware/recovery.c index 41083dd23e..a12328c965 100644 --- a/firmware/recovery.c +++ b/firmware/recovery.c @@ -141,7 +141,7 @@ static void recovery_done(void) { fsm_sendSuccess("Device recovered"); } else { storage_reset(); - fsm_sendFailure(FailureType_Failure_SyntaxError, "Invalid mnemonic, are words in correct order?"); + fsm_sendFailure(FailureType_Failure_DataError, "Invalid mnemonic, are words in correct order?"); } awaiting_word = 0; layoutHome(); @@ -376,7 +376,7 @@ void recovery_init(uint32_t _word_count, bool passphrase_protection, bool pin_pr enforce_wordlist = _enforce_wordlist; if (pin_protection && !protectChangePin()) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "PIN change failed"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } @@ -411,7 +411,7 @@ static void recovery_scrambledword(const char *word) if (word_pos == 0) { // fake word if (strcmp(word, fake_word) != 0) { storage_reset(); - fsm_sendFailure(FailureType_Failure_SyntaxError, "Wrong word retyped"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Wrong word retyped"); layoutHome(); return; } @@ -428,7 +428,7 @@ static void recovery_scrambledword(const char *word) } if (!found) { storage_reset(); - fsm_sendFailure(FailureType_Failure_SyntaxError, "Word not found in a wordlist"); + fsm_sendFailure(FailureType_Failure_DataError, "Word not found in a wordlist"); layoutHome(); return; } diff --git a/firmware/reset.c b/firmware/reset.c index 49db53a719..f10ecd234f 100644 --- a/firmware/reset.c +++ b/firmware/reset.c @@ -50,14 +50,14 @@ void reset_init(bool display_random, uint32_t _strength, bool passphrase_protect if (display_random) { layoutDialogSwipe(&bmp_icon_info, "Cancel", "Continue", NULL, "Internal entropy:", ent_str[0], ent_str[1], ent_str[2], ent_str[3], NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ResetDevice, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Reset cancelled"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } } if (pin_protection && !protectChangePin()) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "PIN change failed"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); layoutHome(); return; } @@ -140,7 +140,7 @@ void reset_entropy(const uint8_t *ext_entropy, uint32_t len) if (!protectButton(ButtonRequestType_ButtonRequest_ConfirmWord, true)) { storage_reset(); layoutHome(); - fsm_sendFailure(FailureType_Failure_Other, "Reset device aborted"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); return; } } diff --git a/firmware/signing.c b/firmware/signing.c index e267948317..5501b41581 100644 --- a/firmware/signing.c +++ b/firmware/signing.c @@ -455,7 +455,7 @@ static bool signing_check_input(TxInputType *txinput) { && txinput->script_type == InputScriptType_SPENDMULTISIG) { uint8_t h[32]; if (cryptoMultisigFingerprint(&txinput->multisig, h) == 0) { - fsm_sendFailure(FailureType_Failure_Other, "Error computing multisig fingerprint"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Error computing multisig fingerprint"); signing_abort(); return false; } @@ -487,7 +487,7 @@ static bool signing_check_prevtx_hash(void) { uint8_t hash[32]; tx_hash_final(&tp, hash, true); if (memcmp(hash, input.prev_hash.bytes, 32) != 0) { - fsm_sendFailure(FailureType_Failure_Other, "Encountered invalid prevhash"); + fsm_sendFailure(FailureType_Failure_DataError, "Encountered invalid prevhash"); signing_abort(); return false; } @@ -504,7 +504,7 @@ static bool signing_check_output(TxOutputType *txoutput) { bool is_change = false; if (txoutput->address_n_count > 0) { if (txoutput->has_address) { - fsm_sendFailure(FailureType_Failure_Other, "Address in change output"); + fsm_sendFailure(FailureType_Failure_DataError, "Address in change output"); signing_abort(); return false; } @@ -528,14 +528,14 @@ static bool signing_check_output(TxOutputType *txoutput) { if (change_spend == 0) { // not set change_spend = txoutput->amount; } else { - fsm_sendFailure(FailureType_Failure_Other, "Only one change output allowed"); + fsm_sendFailure(FailureType_Failure_DataError, "Only one change output allowed"); signing_abort(); return false; } } if (spending + txoutput->amount < spending) { - fsm_sendFailure(FailureType_Failure_Other, "Value overflow"); + fsm_sendFailure(FailureType_Failure_DataError, "Value overflow"); signing_abort(); return false; } @@ -545,11 +545,11 @@ static bool signing_check_output(TxOutputType *txoutput) { layoutProgress("Signing transaction", progress); } if (co < 0) { - fsm_sendFailure(FailureType_Failure_Other, "Signing cancelled by user"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); signing_abort(); return false; } else if (co == 0) { - fsm_sendFailure(FailureType_Failure_Other, "Failed to compile output"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Failed to compile output"); signing_abort(); return false; } @@ -570,7 +570,7 @@ static bool signing_check_fee(void) { if (fee > tx_est_size_kb * coin->maxfee_kb) { layoutFeeOverThreshold(coin, fee); if (!protectButton(ButtonRequestType_ButtonRequest_FeeOverThreshold, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Fee over threshold. Signing cancelled."); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); signing_abort(); return false; } @@ -579,7 +579,7 @@ static bool signing_check_fee(void) { // last confirmation layoutConfirmTx(coin, to_spend - change_spend, fee); if (!protectButton(ButtonRequestType_ButtonRequest_SignTx, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Signing cancelled by user"); + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action cancelled by user"); signing_abort(); return false; } @@ -609,7 +609,7 @@ static bool signing_sign_input(void) { sha256_Final(&hashers[0], hash); sha256_Raw(hash, 32, hash); if (memcmp(hash, hash_outputs, 32) != 0) { - fsm_sendFailure(FailureType_Failure_Other, "Transaction has changed during signing"); + fsm_sendFailure(FailureType_Failure_DataError, "Transaction has changed during signing"); signing_abort(); return false; } @@ -620,7 +620,7 @@ static bool signing_sign_input(void) { resp.serialized.has_signature = true; resp.serialized.has_serialized_tx = true; if (ecdsa_sign_digest(&secp256k1, privkey, hash, sig, NULL, NULL) != 0) { - fsm_sendFailure(FailureType_Failure_Other, "Signing failed"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Signing failed"); signing_abort(); return false; } @@ -630,7 +630,7 @@ static bool signing_sign_input(void) { // fill in the signature int pubkey_idx = cryptoMultisigPubkeyIndex(&(input.multisig), pubkey); if (pubkey_idx < 0) { - fsm_sendFailure(FailureType_Failure_Other, "Pubkey not found in multisig script"); + fsm_sendFailure(FailureType_Failure_DataError, "Pubkey not found in multisig script"); signing_abort(); return false; } @@ -638,7 +638,7 @@ static bool signing_sign_input(void) { input.multisig.signatures[pubkey_idx].size = resp.serialized.signature.size; input.script_sig.size = serialize_script_multisig(&(input.multisig), input.script_sig.bytes); if (input.script_sig.size == 0) { - fsm_sendFailure(FailureType_Failure_Other, "Failed to serialize multisig script"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Failed to serialize multisig script"); signing_abort(); return false; } @@ -658,17 +658,17 @@ static bool signing_sign_segwit_input(TxInputType *txinput) { || txinput->script_type == InputScriptType_SPENDP2SHWITNESS) { // disable native segwit for now if (txinput->script_type == InputScriptType_SPENDWITNESS) { - fsm_sendFailure(FailureType_Failure_Other, "Native segwit is disabled"); + fsm_sendFailure(FailureType_Failure_DataError, "Native segwit is disabled"); signing_abort(); return false; } if (!compile_input_script_sig(txinput)) { - fsm_sendFailure(FailureType_Failure_Other, "Failed to compile input"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Failed to compile input"); signing_abort(); return false; } if (txinput->amount > segwit_to_spend) { - fsm_sendFailure(FailureType_Failure_Other, "Transaction has changed during signing"); + fsm_sendFailure(FailureType_Failure_DataError, "Transaction has changed during signing"); signing_abort(); return false; } @@ -694,7 +694,7 @@ static bool signing_sign_segwit_input(TxInputType *txinput) { resp.serialized.has_signature = true; resp.serialized.has_serialized_tx = true; if (ecdsa_sign_digest(&secp256k1, node.private_key, hash, sig, NULL, NULL) != 0) { - fsm_sendFailure(FailureType_Failure_Other, "Signing failed"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Signing failed"); signing_abort(); return false; } @@ -706,7 +706,7 @@ static bool signing_sign_segwit_input(TxInputType *txinput) { // fill in the signature int pubkey_idx = cryptoMultisigPubkeyIndex(&(txinput->multisig), node.public_key); if (pubkey_idx < 0) { - fsm_sendFailure(FailureType_Failure_Other, "Pubkey not found in multisig script"); + fsm_sendFailure(FailureType_Failure_DataError, "Pubkey not found in multisig script"); signing_abort(); return false; } @@ -786,7 +786,7 @@ void signing_txack(TransactionType *tx) #if !ENABLE_SEGWIT_NONSEGWIT_MIXING // don't mix segwit and non-segwit inputs if (idx1 > 0 && to.is_segwit == true) { - fsm_sendFailure(FailureType_Failure_Other, "Mixing segwit and non-segwit inputs is not allowed"); + fsm_sendFailure(FailureType_Failure_DataError, "Mixing segwit and non-segwit inputs is not allowed"); signing_abort(); return; } @@ -795,23 +795,23 @@ void signing_txack(TransactionType *tx) } else if (tx->inputs[0].script_type == InputScriptType_SPENDWITNESS || tx->inputs[0].script_type == InputScriptType_SPENDP2SHWITNESS) { if (!coin->has_segwit || !coin->segwit) { - fsm_sendFailure(FailureType_Failure_Other, "Segwit not enabled on this coin"); + fsm_sendFailure(FailureType_Failure_DataError, "Segwit not enabled on this coin"); signing_abort(); return; } // disable native segwit for now if (tx->inputs[0].script_type == InputScriptType_SPENDWITNESS) { - fsm_sendFailure(FailureType_Failure_Other, "Native segwit is disabled"); + fsm_sendFailure(FailureType_Failure_DataError, "Native segwit is disabled"); signing_abort(); return; } if (!tx->inputs[0].has_amount) { - fsm_sendFailure(FailureType_Failure_Other, "Segwit input without amount"); + fsm_sendFailure(FailureType_Failure_DataError, "Segwit input without amount"); signing_abort(); return; } if (to_spend + tx->inputs[0].amount < to_spend) { - fsm_sendFailure(FailureType_Failure_Other, "Value overflow"); + fsm_sendFailure(FailureType_Failure_DataError, "Value overflow"); signing_abort(); return; } @@ -820,7 +820,7 @@ void signing_txack(TransactionType *tx) if (idx1 == 0) { to.is_segwit = true; } else if (to.is_segwit == false) { - fsm_sendFailure(FailureType_Failure_Other, "Mixing segwit and non-segwit inputs is not allowed"); + fsm_sendFailure(FailureType_Failure_DataError, "Mixing segwit and non-segwit inputs is not allowed"); signing_abort(); return; } @@ -831,7 +831,7 @@ void signing_txack(TransactionType *tx) segwit_to_spend += tx->inputs[0].amount; phase1_request_next_input(); } else { - fsm_sendFailure(FailureType_Failure_Other, "Wrong input script type"); + fsm_sendFailure(FailureType_Failure_DataError, "Wrong input script type"); signing_abort(); return; } @@ -850,7 +850,7 @@ void signing_txack(TransactionType *tx) case STAGE_REQUEST_2_PREV_INPUT: progress = (idx1 * progress_step + idx2 * progress_meta_step) >> PROGRESS_PRECISION; if (!tx_serialize_input_hash(&tp, tx->inputs)) { - fsm_sendFailure(FailureType_Failure_Other, "Failed to serialize input"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Failed to serialize input"); signing_abort(); return; } @@ -865,13 +865,13 @@ void signing_txack(TransactionType *tx) case STAGE_REQUEST_2_PREV_OUTPUT: progress = (idx1 * progress_step + (tp.inputs_len + idx2) * progress_meta_step) >> PROGRESS_PRECISION; if (!tx_serialize_output_hash(&tp, tx->bin_outputs)) { - fsm_sendFailure(FailureType_Failure_Other, "Failed to serialize output"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Failed to serialize output"); signing_abort(); return; } if (idx2 == input.prev_index) { if (to_spend + tx->bin_outputs[0].amount < to_spend) { - fsm_sendFailure(FailureType_Failure_Other, "Value overflow"); + fsm_sendFailure(FailureType_Failure_DataError, "Value overflow"); signing_abort(); return; } @@ -891,7 +891,7 @@ void signing_txack(TransactionType *tx) return; case STAGE_REQUEST_2_PREV_EXTRADATA: if (!tx_serialize_extra_data_hash(&tp, tx->extra_data.bytes, tx->extra_data.size)) { - fsm_sendFailure(FailureType_Failure_Other, "Failed to serialize extra data"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Failed to serialize extra data"); signing_abort(); return; } @@ -918,7 +918,7 @@ void signing_txack(TransactionType *tx) sha256_Update(&hashers[0], &tx->inputs[0].script_type, sizeof(&tx->inputs[0].script_type)); if (idx2 == idx1) { if (!compile_input_script_sig(&tx->inputs[0])) { - fsm_sendFailure(FailureType_Failure_Other, "Failed to compile input"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Failed to compile input"); signing_abort(); return; } @@ -934,7 +934,7 @@ void signing_txack(TransactionType *tx) tx->inputs[0].script_sig.size = 0; } if (!tx_serialize_input_hash(&ti, tx->inputs)) { - fsm_sendFailure(FailureType_Failure_Other, "Failed to serialize input"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Failed to serialize input"); signing_abort(); return; } @@ -945,7 +945,7 @@ void signing_txack(TransactionType *tx) uint8_t hash[32]; sha256_Final(&hashers[0], hash); if (memcmp(hash, hash_check, 32) != 0) { - fsm_sendFailure(FailureType_Failure_Other, "Transaction has changed during signing"); + fsm_sendFailure(FailureType_Failure_DataError, "Transaction has changed during signing"); signing_abort(); return; } @@ -957,14 +957,14 @@ void signing_txack(TransactionType *tx) case STAGE_REQUEST_4_OUTPUT: progress = 500 + ((signatures * progress_step + (inputs_count + idx2) * progress_meta_step) >> PROGRESS_PRECISION); if (compile_output(coin, root, tx->outputs, &bin_output, false) <= 0) { - fsm_sendFailure(FailureType_Failure_Other, "Failed to compile output"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Failed to compile output"); signing_abort(); return; } // check hashOutputs tx_output_hash(&hashers[0], &bin_output); if (!tx_serialize_output_hash(&ti, &bin_output)) { - fsm_sendFailure(FailureType_Failure_Other, "Failed to serialize output"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Failed to serialize output"); signing_abort(); return; } @@ -998,7 +998,7 @@ void signing_txack(TransactionType *tx) if (tx->inputs[0].script_type == InputScriptType_SPENDP2SHWITNESS && !tx->inputs[0].has_multisig) { if (!compile_input_script_sig(&tx->inputs[0])) { - fsm_sendFailure(FailureType_Failure_Other, "Failed to compile input"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Failed to compile input"); signing_abort(); return; } @@ -1017,7 +1017,7 @@ void signing_txack(TransactionType *tx) tx->inputs[0].script_sig.bytes[2] = 0x20; // push 32 bytes (digest) // compute digest of multisig script if (!compile_script_multisig_hash(&tx->inputs[0].multisig, tx->inputs[0].script_sig.bytes + 3)) { - fsm_sendFailure(FailureType_Failure_Other, "Failed to compile input"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Failed to compile input"); signing_abort(); return; } @@ -1038,7 +1038,7 @@ void signing_txack(TransactionType *tx) case STAGE_REQUEST_5_OUTPUT: if (compile_output(coin, root, tx->outputs, &bin_output,false) <= 0) { - fsm_sendFailure(FailureType_Failure_Other, "Failed to compile output"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Failed to compile output"); signing_abort(); return; } @@ -1075,7 +1075,7 @@ void signing_txack(TransactionType *tx) return; } - fsm_sendFailure(FailureType_Failure_Other, "Signing error"); + fsm_sendFailure(FailureType_Failure_ProcessError, "Signing error"); signing_abort(); } diff --git a/vendor/trezor-common b/vendor/trezor-common index e732226909..4eef33b05a 160000 --- a/vendor/trezor-common +++ b/vendor/trezor-common @@ -1 +1 @@ -Subproject commit e7322269092e0253b0cb1a9c18ba84fd5cd75f91 +Subproject commit 4eef33b05afb5e8465c8947272bc5421b1b6d896