Skip to content

Commit

Permalink
Improved token input automation code to get rid of caps lock key usage (
Browse files Browse the repository at this point in the history
  • Loading branch information
akopachov authored Apr 29, 2023
1 parent 1020c3c commit bc1eab7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
8 changes: 4 additions & 4 deletions services/config/token_info_iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions services/hmac/sha_pad_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#include <string.h>

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);
}
}
Expand Down
31 changes: 15 additions & 16 deletions types/token_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 6 additions & 7 deletions workers/type-code-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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]);
Expand All @@ -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++;
Expand All @@ -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);
}

0 comments on commit bc1eab7

Please sign in to comment.