From 27183323a44e05baf36b3362147a9a1df55c689f Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Thu, 19 Nov 2015 11:03:16 +0100 Subject: [PATCH] fail sooner when the device is not initialized --- firmware/fsm.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/firmware/fsm.c b/firmware/fsm.c index 32b25e28a4..94bb0bb31b 100644 --- a/firmware/fsm.c +++ b/firmware/fsm.c @@ -282,6 +282,11 @@ void fsm_msgGetPublicKey(GetPublicKey *msg) { RESP_INIT(PublicKey); + if (!storage_isInitialized()) { + fsm_sendFailure(FailureType_Failure_NotInitialized, "Device not initialized"); + return; + } + if (!protectPin(true)) { layoutHome(); return; @@ -363,6 +368,11 @@ void fsm_msgResetDevice(ResetDevice *msg) void fsm_msgSignTx(SignTx *msg) { + if (!storage_isInitialized()) { + fsm_sendFailure(FailureType_Failure_NotInitialized, "Device not initialized"); + return; + } + if (msg->inputs_count < 1) { fsm_sendFailure(FailureType_Failure_Other, "Transaction must have at least one input"); layoutHome(); @@ -406,6 +416,10 @@ void fsm_msgTxAck(TxAck *msg) void fsm_msgCipherKeyValue(CipherKeyValue *msg) { + if (!storage_isInitialized()) { + fsm_sendFailure(FailureType_Failure_NotInitialized, "Device not initialized"); + return; + } if (!msg->has_key) { fsm_sendFailure(FailureType_Failure_SyntaxError, "No key provided"); return; @@ -531,6 +545,11 @@ void fsm_msgGetAddress(GetAddress *msg) { RESP_INIT(Address); + if (!storage_isInitialized()) { + fsm_sendFailure(FailureType_Failure_NotInitialized, "Device not initialized"); + return; + } + if (!protectPin(true)) { layoutHome(); return; @@ -599,6 +618,11 @@ void fsm_msgSignMessage(SignMessage *msg) { RESP_INIT(MessageSignature); + if (!storage_isInitialized()) { + fsm_sendFailure(FailureType_Failure_NotInitialized, "Device not initialized"); + return; + } + layoutSignMessage(msg->message.bytes, msg->message.size); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Sign message cancelled"); @@ -660,6 +684,11 @@ void fsm_msgSignIdentity(SignIdentity *msg) { RESP_INIT(SignedIdentity); + if (!storage_isInitialized()) { + fsm_sendFailure(FailureType_Failure_NotInitialized, "Device not initialized"); + return; + } + 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"); @@ -736,6 +765,10 @@ void fsm_msgSignIdentity(SignIdentity *msg) void fsm_msgEncryptMessage(EncryptMessage *msg) { + if (!storage_isInitialized()) { + fsm_sendFailure(FailureType_Failure_NotInitialized, "Device not initialized"); + return; + } if (!msg->has_pubkey) { fsm_sendFailure(FailureType_Failure_SyntaxError, "No public key provided"); return; @@ -792,6 +825,10 @@ void fsm_msgEncryptMessage(EncryptMessage *msg) void fsm_msgDecryptMessage(DecryptMessage *msg) { + if (!storage_isInitialized()) { + fsm_sendFailure(FailureType_Failure_NotInitialized, "Device not initialized"); + return; + } if (!msg->has_nonce) { fsm_sendFailure(FailureType_Failure_SyntaxError, "No nonce provided"); return;