1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 17:38:39 +00:00

firmware: introduce protectAbortedByCancel

This commit is contained in:
Pavol Rusnak 2018-06-05 22:38:39 +02:00
parent 49d9fe4d13
commit df0bad4f09
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 13 additions and 10 deletions

View File

@ -114,6 +114,9 @@ void fsm_sendFailureDebug(FailureType code, const char *text, const char *source
void fsm_sendFailure(FailureType code, const char *text) void fsm_sendFailure(FailureType code, const char *text)
#endif #endif
{ {
if (protectAbortedByCancel) {
protectAbortedByCancel = false;
}
if (protectAbortedByInitialize) { if (protectAbortedByInitialize) {
fsm_msgInitialize((Initialize *)0); fsm_msgInitialize((Initialize *)0);
protectAbortedByInitialize = false; protectAbortedByInitialize = false;
@ -230,7 +233,7 @@ static bool fsm_layoutAddress(const char *address, const char *desc, bool ignore
if (protectButton(ButtonRequestType_ButtonRequest_Address, false)) { if (protectButton(ButtonRequestType_ButtonRequest_Address, false)) {
return true; return true;
} }
if (protectAbortedByInitialize) { if (protectAbortedByCancel || protectAbortedByInitialize) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
layoutHome(); layoutHome();
return false; return false;

View File

@ -34,6 +34,7 @@
#define MAX_WRONG_PINS 15 #define MAX_WRONG_PINS 15
bool protectAbortedByCancel = false;
bool protectAbortedByInitialize = false; bool protectAbortedByInitialize = false;
bool protectButton(ButtonRequestType type, bool confirm_only) bool protectButton(ButtonRequestType type, bool confirm_only)
@ -77,9 +78,8 @@ bool protectButton(ButtonRequestType type, bool confirm_only)
// check for Cancel / Initialize // check for Cancel / Initialize
if (msg_tiny_id == MessageType_MessageType_Cancel || msg_tiny_id == MessageType_MessageType_Initialize) { if (msg_tiny_id == MessageType_MessageType_Cancel || msg_tiny_id == MessageType_MessageType_Initialize) {
if (msg_tiny_id == MessageType_MessageType_Initialize) { protectAbortedByCancel = (msg_tiny_id == MessageType_MessageType_Cancel);
protectAbortedByInitialize = true; protectAbortedByInitialize = (msg_tiny_id == MessageType_MessageType_Initialize);
}
msg_tiny_id = 0xFFFF; msg_tiny_id = 0xFFFF;
result = false; result = false;
break; break;
@ -130,9 +130,8 @@ const char *requestPin(PinMatrixRequestType type, const char *text)
} }
if (msg_tiny_id == MessageType_MessageType_Cancel || msg_tiny_id == MessageType_MessageType_Initialize) { if (msg_tiny_id == MessageType_MessageType_Cancel || msg_tiny_id == MessageType_MessageType_Initialize) {
pinmatrix_done(0); pinmatrix_done(0);
if (msg_tiny_id == MessageType_MessageType_Initialize) { protectAbortedByCancel = (msg_tiny_id == MessageType_MessageType_Cancel);
protectAbortedByInitialize = true; protectAbortedByInitialize = (msg_tiny_id == MessageType_MessageType_Initialize);
}
msg_tiny_id = 0xFFFF; msg_tiny_id = 0xFFFF;
usbTiny(0); usbTiny(0);
return 0; return 0;
@ -182,6 +181,7 @@ bool protectPin(bool use_cached)
// wait one second // wait one second
usbSleep(1000); usbSleep(1000);
if (msg_tiny_id == MessageType_MessageType_Initialize) { if (msg_tiny_id == MessageType_MessageType_Initialize) {
protectAbortedByCancel = false;
protectAbortedByInitialize = true; protectAbortedByInitialize = true;
msg_tiny_id = 0xFFFF; msg_tiny_id = 0xFFFF;
usbTiny(0); usbTiny(0);
@ -263,9 +263,8 @@ bool protectPassphrase(void)
break; break;
} }
if (msg_tiny_id == MessageType_MessageType_Cancel || msg_tiny_id == MessageType_MessageType_Initialize) { if (msg_tiny_id == MessageType_MessageType_Cancel || msg_tiny_id == MessageType_MessageType_Initialize) {
if (msg_tiny_id == MessageType_MessageType_Initialize) { protectAbortedByCancel = (msg_tiny_id == MessageType_MessageType_Cancel);
protectAbortedByInitialize = true; protectAbortedByInitialize = (msg_tiny_id == MessageType_MessageType_Initialize);
}
msg_tiny_id = 0xFFFF; msg_tiny_id = 0xFFFF;
result = false; result = false;
break; break;

View File

@ -28,6 +28,7 @@ bool protectPin(bool use_cached);
bool protectChangePin(void); bool protectChangePin(void);
bool protectPassphrase(void); bool protectPassphrase(void);
extern bool protectAbortedByCancel;
extern bool protectAbortedByInitialize; extern bool protectAbortedByInitialize;
#endif #endif