mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-02 19:40:57 +00:00
extract CHECK_PIN and CHECK_PIN_UNCACHED
This commit is contained in:
parent
0ef70164a5
commit
a122615663
@ -70,6 +70,18 @@ static uint8_t msg_resp[MSG_OUT_SIZE] __attribute__ ((aligned));
|
|||||||
return; \
|
return; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define CHECK_PIN \
|
||||||
|
if (!protectPin(true)) { \
|
||||||
|
layoutHome(); \
|
||||||
|
return; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CHECK_PIN_UNCACHED \
|
||||||
|
if (!protectPin(false)) { \
|
||||||
|
layoutHome(); \
|
||||||
|
return; \
|
||||||
|
}
|
||||||
|
|
||||||
void fsm_sendSuccess(const char *text)
|
void fsm_sendSuccess(const char *text)
|
||||||
{
|
{
|
||||||
RESP_INIT(Success);
|
RESP_INIT(Success);
|
||||||
@ -184,10 +196,7 @@ void fsm_msgPing(Ping *msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (msg->has_pin_protection && msg->pin_protection) {
|
if (msg->has_pin_protection && msg->pin_protection) {
|
||||||
if (!protectPin(true)) {
|
CHECK_PIN
|
||||||
layoutHome();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg->has_passphrase_protection && msg->passphrase_protection) {
|
if (msg->has_passphrase_protection && msg->passphrase_protection) {
|
||||||
@ -227,10 +236,9 @@ void fsm_msgChangePin(ChangePin *msg)
|
|||||||
layoutHome();
|
layoutHome();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!protectPin(false)) {
|
|
||||||
layoutHome();
|
CHECK_PIN_UNCACHED
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (removal) {
|
if (removal) {
|
||||||
storage_setPin(0);
|
storage_setPin(0);
|
||||||
fsm_sendSuccess("PIN removed");
|
fsm_sendSuccess("PIN removed");
|
||||||
@ -300,10 +308,7 @@ void fsm_msgGetPublicKey(GetPublicKey *msg)
|
|||||||
|
|
||||||
CHECK_INITIALIZED
|
CHECK_INITIALIZED
|
||||||
|
|
||||||
if (!protectPin(true)) {
|
CHECK_PIN
|
||||||
layoutHome();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *curve = SECP256K1_NAME;
|
const char *curve = SECP256K1_NAME;
|
||||||
if (msg->has_ecdsa_curve_name) {
|
if (msg->has_ecdsa_curve_name) {
|
||||||
@ -409,10 +414,7 @@ void fsm_msgSignTx(SignTx *msg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!protectPin(true)) {
|
CHECK_PIN
|
||||||
layoutHome();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const CoinType *coin = fsm_getCoin(msg->coin_name);
|
const CoinType *coin = fsm_getCoin(msg->coin_name);
|
||||||
if (!coin) return;
|
if (!coin) return;
|
||||||
@ -444,10 +446,7 @@ void fsm_msgEthereumSignTx(EthereumSignTx *msg)
|
|||||||
{
|
{
|
||||||
CHECK_INITIALIZED
|
CHECK_INITIALIZED
|
||||||
|
|
||||||
if (!protectPin(true)) {
|
CHECK_PIN
|
||||||
layoutHome();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count);
|
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
@ -476,10 +475,9 @@ void fsm_msgCipherKeyValue(CipherKeyValue *msg)
|
|||||||
fsm_sendFailure(FailureType_Failure_SyntaxError, "Value length must be a multiple of 16");
|
fsm_sendFailure(FailureType_Failure_SyntaxError, "Value length must be a multiple of 16");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!protectPin(true)) {
|
|
||||||
layoutHome();
|
CHECK_PIN
|
||||||
return;
|
|
||||||
}
|
|
||||||
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count);
|
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
@ -564,10 +562,9 @@ void fsm_msgApplySettings(ApplySettings *msg)
|
|||||||
fsm_sendFailure(FailureType_Failure_SyntaxError, "No setting provided");
|
fsm_sendFailure(FailureType_Failure_SyntaxError, "No setting provided");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!protectPin(true)) {
|
|
||||||
layoutHome();
|
CHECK_PIN
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (msg->has_label) {
|
if (msg->has_label) {
|
||||||
storage_setLabel(msg->label);
|
storage_setLabel(msg->label);
|
||||||
}
|
}
|
||||||
@ -591,10 +588,7 @@ void fsm_msgGetAddress(GetAddress *msg)
|
|||||||
|
|
||||||
CHECK_INITIALIZED
|
CHECK_INITIALIZED
|
||||||
|
|
||||||
if (!protectPin(true)) {
|
CHECK_PIN
|
||||||
layoutHome();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const CoinType *coin = fsm_getCoin(msg->coin_name);
|
const CoinType *coin = fsm_getCoin(msg->coin_name);
|
||||||
if (!coin) return;
|
if (!coin) return;
|
||||||
@ -653,10 +647,7 @@ void fsm_msgEthereumGetAddress(EthereumGetAddress *msg)
|
|||||||
|
|
||||||
CHECK_INITIALIZED
|
CHECK_INITIALIZED
|
||||||
|
|
||||||
if (!protectPin(true)) {
|
CHECK_PIN
|
||||||
layoutHome();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count);
|
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
@ -707,10 +698,7 @@ void fsm_msgSignMessage(SignMessage *msg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!protectPin(true)) {
|
CHECK_PIN
|
||||||
layoutHome();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const CoinType *coin = fsm_getCoin(msg->coin_name);
|
const CoinType *coin = fsm_getCoin(msg->coin_name);
|
||||||
if (!coin) return;
|
if (!coin) return;
|
||||||
@ -782,10 +770,7 @@ void fsm_msgSignIdentity(SignIdentity *msg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!protectPin(true)) {
|
CHECK_PIN
|
||||||
layoutHome();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t hash[32];
|
uint8_t hash[32];
|
||||||
if (!msg->has_identity || cryptoIdentityFingerprint(&(msg->identity), hash) == 0) {
|
if (!msg->has_identity || cryptoIdentityFingerprint(&(msg->identity), hash) == 0) {
|
||||||
@ -861,10 +846,7 @@ void fsm_msgGetECDHSessionKey(GetECDHSessionKey *msg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!protectPin(true)) {
|
CHECK_PIN
|
||||||
layoutHome();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t hash[32];
|
uint8_t hash[32];
|
||||||
if (!msg->has_identity || cryptoIdentityFingerprint(&(msg->identity), hash) == 0) {
|
if (!msg->has_identity || cryptoIdentityFingerprint(&(msg->identity), hash) == 0) {
|
||||||
@ -925,10 +907,9 @@ void fsm_msgEncryptMessage(EncryptMessage *msg)
|
|||||||
if (signing) {
|
if (signing) {
|
||||||
const CoinType *coin = fsm_getCoin(msg->coin_name);
|
const CoinType *coin = fsm_getCoin(msg->coin_name);
|
||||||
if (!coin) return;
|
if (!coin) return;
|
||||||
if (!protectPin(true)) {
|
|
||||||
layoutHome();
|
CHECK_PIN
|
||||||
return;
|
|
||||||
}
|
|
||||||
node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count);
|
node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
hdnode_get_address_raw(node, coin->address_type, address_raw);
|
hdnode_get_address_raw(node, coin->address_type, address_raw);
|
||||||
@ -973,10 +954,9 @@ void fsm_msgDecryptMessage(DecryptMessage *msg)
|
|||||||
fsm_sendFailure(FailureType_Failure_SyntaxError, "Invalid nonce provided");
|
fsm_sendFailure(FailureType_Failure_SyntaxError, "Invalid nonce provided");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!protectPin(true)) {
|
|
||||||
layoutHome();
|
CHECK_PIN
|
||||||
return;
|
|
||||||
}
|
|
||||||
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count);
|
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user