From bc1eab7a1d346cf1653ea22500e9a3c921c9800b Mon Sep 17 00:00:00 2001 From: Alexander Kopachov Date: Sat, 29 Apr 2023 21:35:27 +0200 Subject: [PATCH] Improved token input automation code to get rid of caps lock key usage (#147) --- services/config/token_info_iterator.c | 8 +++---- services/hmac/sha_pad_buffer.c | 4 ++-- types/token_info.c | 31 +++++++++++++-------------- workers/type-code-common.c | 13 ++++++----- 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/services/config/token_info_iterator.c b/services/config/token_info_iterator.c index 86936bf33d4..f8cd3c64e58 100644 --- a/services/config/token_info_iterator.c +++ b/services/config/token_info_iterator.c @@ -68,7 +68,7 @@ static bool seek_to_token(size_t token_index, TokenInfoIteratorContext* context) direction = StreamDirectionBackward; } - if (!stream_seek(stream, context->last_seek_offset, StreamOffsetFromStart)) { + if(!stream_seek(stream, context->last_seek_offset, StreamOffsetFromStart)) { return false; } @@ -448,7 +448,6 @@ bool totp_token_info_iterator_go_to(TokenInfoIteratorContext* context, size_t to if(flipper_format_read_string( context->config_file, TOTP_CONFIG_KEY_TOKEN_SECRET, temp_str)) { - if(token_info_set_secret( tokenInfo, furi_string_get_cstr(temp_str), @@ -494,8 +493,9 @@ bool totp_token_info_iterator_go_to(TokenInfoIteratorContext* context, size_t to } uint32_t temp_data32; - if(!flipper_format_read_uint32(context->config_file, TOTP_CONFIG_KEY_TOKEN_ALGO, &temp_data32, 1)|| - !token_info_set_algo_from_int(tokenInfo, temp_data32)) { + if(!flipper_format_read_uint32( + context->config_file, TOTP_CONFIG_KEY_TOKEN_ALGO, &temp_data32, 1) || + !token_info_set_algo_from_int(tokenInfo, temp_data32)) { tokenInfo->algo = SHA1; } diff --git a/services/hmac/sha_pad_buffer.c b/services/hmac/sha_pad_buffer.c index 618178de857..badedbcc7d3 100644 --- a/services/hmac/sha_pad_buffer.c +++ b/services/hmac/sha_pad_buffer.c @@ -2,9 +2,9 @@ #include void sha_pad_buffer(uint8_t* buffer, size_t size) { - if (size > 0) { + if(size > 0) { buffer[0] = 0x80; - if (size > 1) { + if(size > 1) { memset(&buffer[1], 0, size - 1); } } diff --git a/types/token_info.c b/types/token_info.c index d6052ddb9b4..6810d021103 100644 --- a/types/token_info.c +++ b/types/token_info.c @@ -118,22 +118,21 @@ bool token_info_set_algo_from_str(TokenInfo* token_info, const FuriString* str) } bool token_info_set_algo_from_int(TokenInfo* token_info, uint8_t algo_code) { - switch (algo_code) - { - case SHA1: - token_info->algo = SHA1; - break; - case SHA256: - token_info->algo = SHA256; - break; - case SHA512: - token_info->algo = SHA512; - break; - case STEAM: - token_info->algo = STEAM; - break; - default: - return false; + switch(algo_code) { + case SHA1: + token_info->algo = SHA1; + break; + case SHA256: + token_info->algo = SHA256; + break; + case SHA512: + token_info->algo = SHA512; + break; + case STEAM: + token_info->algo = STEAM; + break; + default: + return false; } return true; diff --git a/workers/type-code-common.c b/workers/type-code-common.c index 1422c94fa14..194703872a5 100644 --- a/workers/type-code-common.c +++ b/workers/type-code-common.c @@ -30,7 +30,7 @@ static uint32_t get_keypress_delay(TokenAutomationFeature features) { } static void totp_type_code_worker_press_key( - uint8_t key, + uint16_t key, TOTP_AUTOMATION_KEY_HANDLER key_press_fn, TOTP_AUTOMATION_KEY_HANDLER key_release_fn, TokenAutomationFeature features) { @@ -47,8 +47,6 @@ void totp_type_code_worker_execute_automation( TokenAutomationFeature features) { furi_delay_ms(500); uint8_t i = 0; - totp_type_code_worker_press_key( - HID_KEYBOARD_CAPS_LOCK, key_press_fn, key_release_fn, features); while(i < code_buffer_size && code_buffer[i] != 0) { uint8_t char_index = CONVERT_CHAR_TO_DIGIT(code_buffer[i]); @@ -58,7 +56,11 @@ void totp_type_code_worker_execute_automation( if(char_index > 35) break; - uint8_t hid_kb_key = hid_number_keys[char_index]; + uint16_t hid_kb_key = hid_number_keys[char_index]; + if(char_index > 9) { + hid_kb_key |= KEY_MOD_LEFT_SHIFT; + } + totp_type_code_worker_press_key(hid_kb_key, key_press_fn, key_release_fn, features); furi_delay_ms(get_keystroke_delay(features)); i++; @@ -74,7 +76,4 @@ void totp_type_code_worker_execute_automation( furi_delay_ms(get_keystroke_delay(features)); totp_type_code_worker_press_key(HID_KEYBOARD_TAB, key_press_fn, key_release_fn, features); } - - totp_type_code_worker_press_key( - HID_KEYBOARD_CAPS_LOCK, key_press_fn, key_release_fn, features); } \ No newline at end of file