Skip to content

Commit

Permalink
Increment U2F counter before authentication (#1595)
Browse files Browse the repository at this point in the history
* Fix U2F counter endianness
* Increment U2F counter before using it
* U2F: increment counter before use
* U2F: don't increment on U2fCheckOnly

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
  • Loading branch information
wdoekes and skotopes committed Aug 17, 2022
1 parent 831da59 commit c964099
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions applications/u2f/u2f.c
Expand Up @@ -277,8 +277,8 @@ static uint16_t u2f_authenticate(U2fData* U2F, uint8_t* buf) {
}
U2F->user_present = false;

// The 4 byte counter is represented in big endian
be_u2f_counter = lfs_tobe32(U2F->counter);
// The 4 byte counter is represented in big endian. Increment it before use
be_u2f_counter = lfs_tobe32(U2F->counter + 1);

// Generate hash
sha256_start(&sha_ctx);
Expand Down Expand Up @@ -318,8 +318,8 @@ static uint16_t u2f_authenticate(U2fData* U2F, uint8_t* buf) {
uint8_t signature_len = u2f_der_encode_signature(resp->signature, signature);
memcpy(resp->signature + signature_len, state_no_error, 2);

FURI_LOG_D(TAG, "Counter: %lu", U2F->counter);
U2F->counter++;
FURI_LOG_D(TAG, "Counter: %lu", U2F->counter);
u2f_data_cnt_write(U2F->counter);

if(U2F->callback != NULL) U2F->callback(U2fNotifyAuthSuccess, U2F->context);
Expand Down

0 comments on commit c964099

Please sign in to comment.