1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 04:18:10 +00:00

feat(legacy): Add state sanity check to fsm_msg*Ack() functions.

This commit is contained in:
Andrew Kozlik 2022-02-17 10:44:40 +01:00 committed by Martin Milata
parent 458d6e1b4b
commit 4c60f80f44
5 changed files with 41 additions and 1 deletions

View File

@ -100,6 +100,12 @@ static uint8_t msg_resp[MSG_OUT_DECODED_SIZE] __attribute__((aligned));
return; \ return; \
} }
#define CHECK_UNLOCKED \
if (!session_isUnlocked()) { \
layoutHome(); \
return; \
}
#define CHECK_PARAM(cond, errormsg) \ #define CHECK_PARAM(cond, errormsg) \
if (!(cond)) { \ if (!(cond)) { \
fsm_sendFailure(FailureType_Failure_DataError, (errormsg)); \ fsm_sendFailure(FailureType_Failure_DataError, (errormsg)); \

View File

@ -146,6 +146,8 @@ void fsm_msgSignTx(const SignTx *msg) {
} }
void fsm_msgTxAck(TxAck *msg) { void fsm_msgTxAck(TxAck *msg) {
CHECK_UNLOCKED
CHECK_PARAM(msg->has_tx, _("No transaction provided")); CHECK_PARAM(msg->has_tx, _("No transaction provided"));
signing_txack(&(msg->tx)); signing_txack(&(msg->tx));

View File

@ -516,7 +516,11 @@ void fsm_msgRecoveryDevice(const RecoveryDevice *msg) {
msg->has_u2f_counter ? msg->u2f_counter : 0, dry_run); msg->has_u2f_counter ? msg->u2f_counter : 0, dry_run);
} }
void fsm_msgWordAck(const WordAck *msg) { recovery_word(msg->word); } void fsm_msgWordAck(const WordAck *msg) {
CHECK_UNLOCKED
recovery_word(msg->word);
}
void fsm_msgSetU2FCounter(const SetU2FCounter *msg) { void fsm_msgSetU2FCounter(const SetU2FCounter *msg) {
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL, layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL,

View File

@ -125,6 +125,8 @@ void fsm_msgEthereumSignTxEIP1559(const EthereumSignTxEIP1559 *msg) {
} }
void fsm_msgEthereumTxAck(const EthereumTxAck *msg) { void fsm_msgEthereumTxAck(const EthereumTxAck *msg) {
CHECK_UNLOCKED
ethereum_signing_txack(msg); ethereum_signing_txack(msg);
} }

View File

@ -97,6 +97,8 @@ void fsm_msgStellarSignTx(const StellarSignTx *msg) {
} }
void fsm_msgStellarCreateAccountOp(const StellarCreateAccountOp *msg) { void fsm_msgStellarCreateAccountOp(const StellarCreateAccountOp *msg) {
CHECK_UNLOCKED
if (!stellar_confirmCreateAccountOp(msg)) return; if (!stellar_confirmCreateAccountOp(msg)) return;
if (stellar_allOperationsConfirmed()) { if (stellar_allOperationsConfirmed()) {
@ -115,6 +117,8 @@ void fsm_msgStellarCreateAccountOp(const StellarCreateAccountOp *msg) {
} }
void fsm_msgStellarPaymentOp(const StellarPaymentOp *msg) { void fsm_msgStellarPaymentOp(const StellarPaymentOp *msg) {
CHECK_UNLOCKED
// This will display additional dialogs to the user // This will display additional dialogs to the user
if (!stellar_confirmPaymentOp(msg)) return; if (!stellar_confirmPaymentOp(msg)) return;
@ -136,6 +140,8 @@ void fsm_msgStellarPaymentOp(const StellarPaymentOp *msg) {
void fsm_msgStellarPathPaymentStrictReceiveOp( void fsm_msgStellarPathPaymentStrictReceiveOp(
const StellarPathPaymentStrictReceiveOp *msg) { const StellarPathPaymentStrictReceiveOp *msg) {
CHECK_UNLOCKED
if (!stellar_confirmPathPaymentStrictReceiveOp(msg)) return; if (!stellar_confirmPathPaymentStrictReceiveOp(msg)) return;
if (stellar_allOperationsConfirmed()) { if (stellar_allOperationsConfirmed()) {
@ -155,6 +161,8 @@ void fsm_msgStellarPathPaymentStrictReceiveOp(
void fsm_msgStellarPathPaymentStrictSendOp( void fsm_msgStellarPathPaymentStrictSendOp(
const StellarPathPaymentStrictSendOp *msg) { const StellarPathPaymentStrictSendOp *msg) {
CHECK_UNLOCKED
if (!stellar_confirmPathPaymentStrictSendOp(msg)) return; if (!stellar_confirmPathPaymentStrictSendOp(msg)) return;
if (stellar_allOperationsConfirmed()) { if (stellar_allOperationsConfirmed()) {
@ -173,6 +181,8 @@ void fsm_msgStellarPathPaymentStrictSendOp(
} }
void fsm_msgStellarManageBuyOfferOp(const StellarManageBuyOfferOp *msg) { void fsm_msgStellarManageBuyOfferOp(const StellarManageBuyOfferOp *msg) {
CHECK_UNLOCKED
if (!stellar_confirmManageBuyOfferOp(msg)) return; if (!stellar_confirmManageBuyOfferOp(msg)) return;
if (stellar_allOperationsConfirmed()) { if (stellar_allOperationsConfirmed()) {
@ -191,6 +201,8 @@ void fsm_msgStellarManageBuyOfferOp(const StellarManageBuyOfferOp *msg) {
} }
void fsm_msgStellarManageSellOfferOp(const StellarManageSellOfferOp *msg) { void fsm_msgStellarManageSellOfferOp(const StellarManageSellOfferOp *msg) {
CHECK_UNLOCKED
if (!stellar_confirmManageSellOfferOp(msg)) return; if (!stellar_confirmManageSellOfferOp(msg)) return;
if (stellar_allOperationsConfirmed()) { if (stellar_allOperationsConfirmed()) {
@ -210,6 +222,8 @@ void fsm_msgStellarManageSellOfferOp(const StellarManageSellOfferOp *msg) {
void fsm_msgStellarCreatePassiveSellOfferOp( void fsm_msgStellarCreatePassiveSellOfferOp(
const StellarCreatePassiveSellOfferOp *msg) { const StellarCreatePassiveSellOfferOp *msg) {
CHECK_UNLOCKED
if (!stellar_confirmCreatePassiveSellOfferOp(msg)) return; if (!stellar_confirmCreatePassiveSellOfferOp(msg)) return;
if (stellar_allOperationsConfirmed()) { if (stellar_allOperationsConfirmed()) {
@ -228,6 +242,8 @@ void fsm_msgStellarCreatePassiveSellOfferOp(
} }
void fsm_msgStellarSetOptionsOp(const StellarSetOptionsOp *msg) { void fsm_msgStellarSetOptionsOp(const StellarSetOptionsOp *msg) {
CHECK_UNLOCKED
if (!stellar_confirmSetOptionsOp(msg)) return; if (!stellar_confirmSetOptionsOp(msg)) return;
if (stellar_allOperationsConfirmed()) { if (stellar_allOperationsConfirmed()) {
@ -246,6 +262,8 @@ void fsm_msgStellarSetOptionsOp(const StellarSetOptionsOp *msg) {
} }
void fsm_msgStellarChangeTrustOp(const StellarChangeTrustOp *msg) { void fsm_msgStellarChangeTrustOp(const StellarChangeTrustOp *msg) {
CHECK_UNLOCKED
if (!stellar_confirmChangeTrustOp(msg)) return; if (!stellar_confirmChangeTrustOp(msg)) return;
if (stellar_allOperationsConfirmed()) { if (stellar_allOperationsConfirmed()) {
@ -264,6 +282,8 @@ void fsm_msgStellarChangeTrustOp(const StellarChangeTrustOp *msg) {
} }
void fsm_msgStellarAllowTrustOp(const StellarAllowTrustOp *msg) { void fsm_msgStellarAllowTrustOp(const StellarAllowTrustOp *msg) {
CHECK_UNLOCKED
if (!stellar_confirmAllowTrustOp(msg)) return; if (!stellar_confirmAllowTrustOp(msg)) return;
if (stellar_allOperationsConfirmed()) { if (stellar_allOperationsConfirmed()) {
@ -282,6 +302,8 @@ void fsm_msgStellarAllowTrustOp(const StellarAllowTrustOp *msg) {
} }
void fsm_msgStellarAccountMergeOp(const StellarAccountMergeOp *msg) { void fsm_msgStellarAccountMergeOp(const StellarAccountMergeOp *msg) {
CHECK_UNLOCKED
if (!stellar_confirmAccountMergeOp(msg)) return; if (!stellar_confirmAccountMergeOp(msg)) return;
if (stellar_allOperationsConfirmed()) { if (stellar_allOperationsConfirmed()) {
@ -300,6 +322,8 @@ void fsm_msgStellarAccountMergeOp(const StellarAccountMergeOp *msg) {
} }
void fsm_msgStellarManageDataOp(const StellarManageDataOp *msg) { void fsm_msgStellarManageDataOp(const StellarManageDataOp *msg) {
CHECK_UNLOCKED
if (!stellar_confirmManageDataOp(msg)) return; if (!stellar_confirmManageDataOp(msg)) return;
if (stellar_allOperationsConfirmed()) { if (stellar_allOperationsConfirmed()) {
@ -318,6 +342,8 @@ void fsm_msgStellarManageDataOp(const StellarManageDataOp *msg) {
} }
void fsm_msgStellarBumpSequenceOp(const StellarBumpSequenceOp *msg) { void fsm_msgStellarBumpSequenceOp(const StellarBumpSequenceOp *msg) {
CHECK_UNLOCKED
if (!stellar_confirmBumpSequenceOp(msg)) return; if (!stellar_confirmBumpSequenceOp(msg)) return;
if (stellar_allOperationsConfirmed()) { if (stellar_allOperationsConfirmed()) {