1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 14:58:09 +00:00

new message SetU2FCounter

This commit is contained in:
Jochen Hoenicke 2016-06-12 23:39:28 +02:00
parent 5e57a1ceaf
commit 120cfc148f
No known key found for this signature in database
GPG Key ID: 65B10C0466560648
8 changed files with 34 additions and 2 deletions

View File

@ -924,6 +924,12 @@ void fsm_msgWordAck(WordAck *msg)
recovery_word(msg->word); recovery_word(msg->word);
} }
void fsm_msgSetU2FCounter(SetU2FCounter *msg)
{
storage_setU2FCounter(msg->u2f_counter);
fsm_sendSuccess("U2F counter set");
}
#if DEBUG_LINK #if DEBUG_LINK
void fsm_msgDebugLinkGetState(DebugLinkGetState *msg) void fsm_msgDebugLinkGetState(DebugLinkGetState *msg)

View File

@ -57,6 +57,7 @@ void fsm_msgDecryptMessage(DecryptMessage *msg);
void fsm_msgEstimateTxSize(EstimateTxSize *msg); void fsm_msgEstimateTxSize(EstimateTxSize *msg);
void fsm_msgRecoveryDevice(RecoveryDevice *msg); void fsm_msgRecoveryDevice(RecoveryDevice *msg);
void fsm_msgWordAck(WordAck *msg); void fsm_msgWordAck(WordAck *msg);
void fsm_msgSetU2FCounter(SetU2FCounter *msg);
// debug message functions // debug message functions
#if DEBUG_LINK #if DEBUG_LINK

View File

@ -71,6 +71,7 @@ static const struct MessagesMap_t MessagesMap[] = {
{'n', 'i', MessageType_MessageType_EstimateTxSize, EstimateTxSize_fields, (void (*)(void *))fsm_msgEstimateTxSize}, {'n', 'i', MessageType_MessageType_EstimateTxSize, EstimateTxSize_fields, (void (*)(void *))fsm_msgEstimateTxSize},
{'n', 'i', MessageType_MessageType_RecoveryDevice, RecoveryDevice_fields, (void (*)(void *))fsm_msgRecoveryDevice}, {'n', 'i', MessageType_MessageType_RecoveryDevice, RecoveryDevice_fields, (void (*)(void *))fsm_msgRecoveryDevice},
{'n', 'i', MessageType_MessageType_WordAck, WordAck_fields, (void (*)(void *))fsm_msgWordAck}, {'n', 'i', MessageType_MessageType_WordAck, WordAck_fields, (void (*)(void *))fsm_msgWordAck},
{'n', 'i', MessageType_MessageType_SetU2FCounter, SetU2FCounter_fields, (void (*)(void *))fsm_msgSetU2FCounter},
// out messages // out messages
{'n', 'o', MessageType_MessageType_Success, Success_fields, 0}, {'n', 'o', MessageType_MessageType_Success, Success_fields, 0},
{'n', 'o', MessageType_MessageType_Failure, Failure_fields, 0}, {'n', 'o', MessageType_MessageType_Failure, Failure_fields, 0},

View File

@ -380,6 +380,11 @@ const pb_field_t ECDHSessionKey_fields[2] = {
PB_LAST_FIELD PB_LAST_FIELD
}; };
const pb_field_t SetU2FCounter_fields[2] = {
PB_FIELD2( 1, UINT32 , OPTIONAL, STATIC , FIRST, SetU2FCounter, u2f_counter, u2f_counter, 0),
PB_LAST_FIELD
};
const pb_field_t FirmwareErase_fields[1] = { const pb_field_t FirmwareErase_fields[1] = {
PB_LAST_FIELD PB_LAST_FIELD
}; };
@ -456,7 +461,7 @@ const pb_field_t DebugLinkFlashErase_fields[2] = {
* numbers or field sizes that are larger than what can fit in 8 or 16 bit * numbers or field sizes that are larger than what can fit in 8 or 16 bit
* field descriptors. * field descriptors.
*/ */
STATIC_ASSERT((pb_membersize(Features, coins[0]) < 65536 && pb_membersize(PublicKey, node) < 65536 && pb_membersize(GetAddress, multisig) < 65536 && pb_membersize(LoadDevice, node) < 65536 && pb_membersize(SimpleSignTx, inputs[0]) < 65536 && pb_membersize(SimpleSignTx, outputs[0]) < 65536 && pb_membersize(SimpleSignTx, transactions[0]) < 65536 && pb_membersize(TxRequest, details) < 65536 && pb_membersize(TxRequest, serialized) < 65536 && pb_membersize(TxAck, tx) < 65536 && pb_membersize(SignIdentity, identity) < 65536 && pb_membersize(GetECDHSessionKey, identity) < 65536 && pb_membersize(DebugLinkState, node) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_Initialize_GetFeatures_Features_ClearSession_ApplySettings_ChangePin_Ping_Success_Failure_ButtonRequest_ButtonAck_PinMatrixRequest_PinMatrixAck_Cancel_PassphraseRequest_PassphraseAck_GetEntropy_Entropy_GetPublicKey_PublicKey_GetAddress_EthereumGetAddress_Address_EthereumAddress_WipeDevice_LoadDevice_ResetDevice_EntropyRequest_EntropyAck_RecoveryDevice_WordRequest_WordAck_SignMessage_VerifyMessage_MessageSignature_EncryptMessage_EncryptedMessage_DecryptMessage_DecryptedMessage_CipherKeyValue_CipheredKeyValue_EstimateTxSize_TxSize_SignTx_SimpleSignTx_TxRequest_TxAck_EthereumSignTx_EthereumTxRequest_EthereumTxAck_SignIdentity_SignedIdentity_GetECDHSessionKey_ECDHSessionKey_FirmwareErase_FirmwareUpload_DebugLinkDecision_DebugLinkGetState_DebugLinkState_DebugLinkStop_DebugLinkLog_DebugLinkMemoryRead_DebugLinkMemory_DebugLinkMemoryWrite_DebugLinkFlashErase) STATIC_ASSERT((pb_membersize(Features, coins[0]) < 65536 && pb_membersize(PublicKey, node) < 65536 && pb_membersize(GetAddress, multisig) < 65536 && pb_membersize(LoadDevice, node) < 65536 && pb_membersize(SimpleSignTx, inputs[0]) < 65536 && pb_membersize(SimpleSignTx, outputs[0]) < 65536 && pb_membersize(SimpleSignTx, transactions[0]) < 65536 && pb_membersize(TxRequest, details) < 65536 && pb_membersize(TxRequest, serialized) < 65536 && pb_membersize(TxAck, tx) < 65536 && pb_membersize(SignIdentity, identity) < 65536 && pb_membersize(GetECDHSessionKey, identity) < 65536 && pb_membersize(DebugLinkState, node) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_Initialize_GetFeatures_Features_ClearSession_ApplySettings_ChangePin_Ping_Success_Failure_ButtonRequest_ButtonAck_PinMatrixRequest_PinMatrixAck_Cancel_PassphraseRequest_PassphraseAck_GetEntropy_Entropy_GetPublicKey_PublicKey_GetAddress_EthereumGetAddress_Address_EthereumAddress_WipeDevice_LoadDevice_ResetDevice_EntropyRequest_EntropyAck_RecoveryDevice_WordRequest_WordAck_SignMessage_VerifyMessage_MessageSignature_EncryptMessage_EncryptedMessage_DecryptMessage_DecryptedMessage_CipherKeyValue_CipheredKeyValue_EstimateTxSize_TxSize_SignTx_SimpleSignTx_TxRequest_TxAck_EthereumSignTx_EthereumTxRequest_EthereumTxAck_SignIdentity_SignedIdentity_GetECDHSessionKey_ECDHSessionKey_SetU2FCounter_FirmwareErase_FirmwareUpload_DebugLinkDecision_DebugLinkGetState_DebugLinkState_DebugLinkStop_DebugLinkLog_DebugLinkMemoryRead_DebugLinkMemory_DebugLinkMemoryWrite_DebugLinkFlashErase)
#endif #endif
#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT) #if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT)

View File

@ -68,6 +68,7 @@ typedef enum _MessageType {
MessageType_MessageType_EthereumTxAck = 60, MessageType_MessageType_EthereumTxAck = 60,
MessageType_MessageType_GetECDHSessionKey = 61, MessageType_MessageType_GetECDHSessionKey = 61,
MessageType_MessageType_ECDHSessionKey = 62, MessageType_MessageType_ECDHSessionKey = 62,
MessageType_MessageType_SetU2FCounter = 63,
MessageType_MessageType_DebugLinkDecision = 100, MessageType_MessageType_DebugLinkDecision = 100,
MessageType_MessageType_DebugLinkGetState = 101, MessageType_MessageType_DebugLinkGetState = 101,
MessageType_MessageType_DebugLinkState = 102, MessageType_MessageType_DebugLinkState = 102,
@ -686,6 +687,11 @@ typedef struct _ResetDevice {
char label[33]; char label[33];
} ResetDevice; } ResetDevice;
typedef struct _SetU2FCounter {
bool has_u2f_counter;
uint32_t u2f_counter;
} SetU2FCounter;
typedef struct { typedef struct {
size_t size; size_t size;
uint8_t bytes[256]; uint8_t bytes[256];
@ -881,6 +887,7 @@ extern const uint32_t SimpleSignTx_lock_time_default;
#define SignedIdentity_init_default {false, "", false, {0, {0}}, false, {0, {0}}} #define SignedIdentity_init_default {false, "", false, {0, {0}}, false, {0, {0}}}
#define GetECDHSessionKey_init_default {false, IdentityType_init_default, false, {0, {0}}, false, ""} #define GetECDHSessionKey_init_default {false, IdentityType_init_default, false, {0, {0}}, false, ""}
#define ECDHSessionKey_init_default {false, {0, {0}}} #define ECDHSessionKey_init_default {false, {0, {0}}}
#define SetU2FCounter_init_default {false, 0}
#define FirmwareErase_init_default {0} #define FirmwareErase_init_default {0}
#define FirmwareUpload_init_default {{0, {0}}} #define FirmwareUpload_init_default {{0, {0}}}
#define DebugLinkDecision_init_default {0} #define DebugLinkDecision_init_default {0}
@ -946,6 +953,7 @@ extern const uint32_t SimpleSignTx_lock_time_default;
#define SignedIdentity_init_zero {false, "", false, {0, {0}}, false, {0, {0}}} #define SignedIdentity_init_zero {false, "", false, {0, {0}}, false, {0, {0}}}
#define GetECDHSessionKey_init_zero {false, IdentityType_init_zero, false, {0, {0}}, false, ""} #define GetECDHSessionKey_init_zero {false, IdentityType_init_zero, false, {0, {0}}, false, ""}
#define ECDHSessionKey_init_zero {false, {0, {0}}} #define ECDHSessionKey_init_zero {false, {0, {0}}}
#define SetU2FCounter_init_zero {false, 0}
#define FirmwareErase_init_zero {0} #define FirmwareErase_init_zero {0}
#define FirmwareUpload_init_zero {{0, {0}}} #define FirmwareUpload_init_zero {{0, {0}}}
#define DebugLinkDecision_init_zero {0} #define DebugLinkDecision_init_zero {0}
@ -1093,6 +1101,7 @@ extern const uint32_t SimpleSignTx_lock_time_default;
#define ResetDevice_pin_protection_tag 4 #define ResetDevice_pin_protection_tag 4
#define ResetDevice_language_tag 5 #define ResetDevice_language_tag 5
#define ResetDevice_label_tag 6 #define ResetDevice_label_tag 6
#define SetU2FCounter_u2f_counter_tag 1
#define SignIdentity_identity_tag 1 #define SignIdentity_identity_tag 1
#define SignIdentity_challenge_hidden_tag 2 #define SignIdentity_challenge_hidden_tag 2
#define SignIdentity_challenge_visual_tag 3 #define SignIdentity_challenge_visual_tag 3
@ -1181,6 +1190,7 @@ extern const pb_field_t SignIdentity_fields[5];
extern const pb_field_t SignedIdentity_fields[4]; extern const pb_field_t SignedIdentity_fields[4];
extern const pb_field_t GetECDHSessionKey_fields[4]; extern const pb_field_t GetECDHSessionKey_fields[4];
extern const pb_field_t ECDHSessionKey_fields[2]; extern const pb_field_t ECDHSessionKey_fields[2];
extern const pb_field_t SetU2FCounter_fields[2];
extern const pb_field_t FirmwareErase_fields[1]; extern const pb_field_t FirmwareErase_fields[1];
extern const pb_field_t FirmwareUpload_fields[2]; extern const pb_field_t FirmwareUpload_fields[2];
extern const pb_field_t DebugLinkDecision_fields[2]; extern const pb_field_t DebugLinkDecision_fields[2];
@ -1248,6 +1258,7 @@ extern const pb_field_t DebugLinkFlashErase_fields[2];
#define SignedIdentity_size 140 #define SignedIdentity_size 140
#define GetECDHSessionKey_size (107 + IdentityType_size) #define GetECDHSessionKey_size (107 + IdentityType_size)
#define ECDHSessionKey_size 67 #define ECDHSessionKey_size 67
#define SetU2FCounter_size 6
#define FirmwareErase_size 0 #define FirmwareErase_size 0
#define FirmwareUpload_size 2 #define FirmwareUpload_size 2
#define DebugLinkDecision_size 2 #define DebugLinkDecision_size 2

View File

@ -559,3 +559,10 @@ uint32_t storage_nextU2FCounter(void)
storage_check_flash_errors(); storage_check_flash_errors();
return storage.u2f_counter + storage_u2f_offset; return storage.u2f_counter + storage_u2f_offset;
} }
void storage_setU2FCounter(uint32_t u2fcounter)
{
storage.has_u2f_counter = true;
storage.u2f_counter = u2fcounter - storage_u2f_offset;
storage_commit();
}

View File

@ -62,6 +62,7 @@ bool storage_increasePinFails(uint32_t *pinfailptr);
uint32_t *storage_getPinFailsPtr(void); uint32_t *storage_getPinFailsPtr(void);
uint32_t storage_nextU2FCounter(void); uint32_t storage_nextU2FCounter(void);
void storage_setU2FCounter(uint32_t u2fcounter);
bool storage_isInitialized(void); bool storage_isInitialized(void);

@ -1 +1 @@
Subproject commit 70d8ac8f85f16a0a16019749402f26dcc635d841 Subproject commit 203d95b913903debbaab3333ea2416a7c37e0b95