From c964099c8cbaff194e3f6db66be820771e7a2482 Mon Sep 17 00:00:00 2001 From: Walter Doekes Date: Wed, 17 Aug 2022 18:23:13 +0200 Subject: [PATCH] Increment U2F counter before authentication (#1595) * 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 --- applications/u2f/u2f.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/applications/u2f/u2f.c b/applications/u2f/u2f.c index 94fd9f2da..767733ce6 100644 --- a/applications/u2f/u2f.c +++ b/applications/u2f/u2f.c @@ -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); @@ -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);