Explorar el Código

Improved token input automation code to get rid of caps lock key usage (#147)

Alexander Kopachov hace 2 años
padre
commit
bc1eab7a1d

+ 4 - 4
services/config/token_info_iterator.c

@@ -68,7 +68,7 @@ static bool seek_to_token(size_t token_index, TokenInfoIteratorContext* context)
         direction = StreamDirectionBackward;
         direction = StreamDirectionBackward;
     }
     }
 
 
-    if (!stream_seek(stream, context->last_seek_offset, StreamOffsetFromStart)) {
+    if(!stream_seek(stream, context->last_seek_offset, StreamOffsetFromStart)) {
         return false;
         return false;
     }
     }
 
 
@@ -448,7 +448,6 @@ bool totp_token_info_iterator_go_to(TokenInfoIteratorContext* context, size_t to
 
 
         if(flipper_format_read_string(
         if(flipper_format_read_string(
                context->config_file, TOTP_CONFIG_KEY_TOKEN_SECRET, temp_str)) {
                context->config_file, TOTP_CONFIG_KEY_TOKEN_SECRET, temp_str)) {
-            
             if(token_info_set_secret(
             if(token_info_set_secret(
                    tokenInfo,
                    tokenInfo,
                    furi_string_get_cstr(temp_str),
                    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;
     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;
         tokenInfo->algo = SHA1;
     }
     }
 
 

+ 2 - 2
services/hmac/sha_pad_buffer.c

@@ -2,9 +2,9 @@
 #include <string.h>
 #include <string.h>
 
 
 void sha_pad_buffer(uint8_t* buffer, size_t size) {
 void sha_pad_buffer(uint8_t* buffer, size_t size) {
-    if (size > 0) {
+    if(size > 0) {
         buffer[0] = 0x80;
         buffer[0] = 0x80;
-        if (size > 1) {
+        if(size > 1) {
             memset(&buffer[1], 0, size - 1);
             memset(&buffer[1], 0, size - 1);
         }
         }
     }
     }

+ 15 - 16
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) {
 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;
     return true;

+ 6 - 7
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(
 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_press_fn,
     TOTP_AUTOMATION_KEY_HANDLER key_release_fn,
     TOTP_AUTOMATION_KEY_HANDLER key_release_fn,
     TokenAutomationFeature features) {
     TokenAutomationFeature features) {
@@ -47,8 +47,6 @@ void totp_type_code_worker_execute_automation(
     TokenAutomationFeature features) {
     TokenAutomationFeature features) {
     furi_delay_ms(500);
     furi_delay_ms(500);
     uint8_t i = 0;
     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) {
     while(i < code_buffer_size && code_buffer[i] != 0) {
         uint8_t char_index = CONVERT_CHAR_TO_DIGIT(code_buffer[i]);
         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;
         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);
         totp_type_code_worker_press_key(hid_kb_key, key_press_fn, key_release_fn, features);
         furi_delay_ms(get_keystroke_delay(features));
         furi_delay_ms(get_keystroke_delay(features));
         i++;
         i++;
@@ -74,7 +76,4 @@ void totp_type_code_worker_execute_automation(
         furi_delay_ms(get_keystroke_delay(features));
         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_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);
 }
 }