mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 19:58:36 -07:00
Merge branch 'dev' of https://github.com/DarkFlippers/unleashed-firmware into xfw-dev
This commit is contained in:
@@ -31,6 +31,7 @@ struct TotpBtTypeCodeWorkerContext {
|
||||
char previous_bt_name[TOTP_BT_WORKER_BT_ADV_NAME_MAX_LEN];
|
||||
uint8_t previous_bt_mac[TOTP_BT_WORKER_BT_MAC_ADDRESS_LEN];
|
||||
#endif
|
||||
AutomationKeyboardLayout keyboard_layout;
|
||||
};
|
||||
|
||||
static inline bool totp_type_code_worker_stop_requested() {
|
||||
@@ -71,7 +72,8 @@ static void totp_type_code_worker_type_code(TotpBtTypeCodeWorkerContext* context
|
||||
&furi_hal_bt_hid_kb_release,
|
||||
context->code_buffer,
|
||||
context->code_buffer_size,
|
||||
context->flags);
|
||||
context->flags,
|
||||
context->keyboard_layout);
|
||||
furi_mutex_release(context->code_buffer_sync);
|
||||
}
|
||||
}
|
||||
@@ -117,11 +119,13 @@ void totp_bt_type_code_worker_start(
|
||||
TotpBtTypeCodeWorkerContext* context,
|
||||
char* code_buffer,
|
||||
uint8_t code_buffer_size,
|
||||
FuriMutex* code_buffer_sync) {
|
||||
FuriMutex* code_buffer_sync,
|
||||
AutomationKeyboardLayout keyboard_layout) {
|
||||
furi_check(context != NULL);
|
||||
context->code_buffer = code_buffer;
|
||||
context->code_buffer_size = code_buffer_size;
|
||||
context->code_buffer_sync = code_buffer_sync;
|
||||
context->keyboard_layout = keyboard_layout;
|
||||
context->thread = furi_thread_alloc();
|
||||
furi_thread_set_name(context->thread, "TOTPBtHidWorker");
|
||||
furi_thread_set_stack_size(context->thread, 1024);
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <furi/core/mutex.h>
|
||||
#include "../../types/automation_kb_layout.h"
|
||||
#include "../../services/config/constants.h"
|
||||
|
||||
#define TOTP_BT_KEYS_STORAGE_PATH EXT_PATH("authenticator/.bt_hid.keys")
|
||||
#define TOTP_BT_KEYS_STORAGE_PATH EXT_PATH("apps_data/totp/.bt_hid.keys")
|
||||
|
||||
typedef uint8_t TotpBtTypeCodeWorkerEvent;
|
||||
|
||||
@@ -49,12 +51,14 @@ void totp_bt_type_code_worker_free(TotpBtTypeCodeWorkerContext* context);
|
||||
* @param code_buffer code buffer to be used to automate
|
||||
* @param code_buffer_size code buffer size
|
||||
* @param code_buffer_sync code buffer synchronization primitive
|
||||
* @param keyboard_layout keyboard layout to be used
|
||||
*/
|
||||
void totp_bt_type_code_worker_start(
|
||||
TotpBtTypeCodeWorkerContext* context,
|
||||
char* code_buffer,
|
||||
uint8_t code_buffer_size,
|
||||
FuriMutex* code_buffer_sync);
|
||||
FuriMutex* code_buffer_sync,
|
||||
AutomationKeyboardLayout keyboard_layout);
|
||||
|
||||
/**
|
||||
* @brief Stops bluetooth token input automation worker
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "generate_totp_code.h"
|
||||
#include <furi/core/thread.h>
|
||||
#include "../../services/crypto/crypto.h"
|
||||
#include <furi/core/check.h>
|
||||
#include "../../services/crypto/crypto_facade.h"
|
||||
#include "../../services/totp/totp.h"
|
||||
#include "../../services/convert/convert.h"
|
||||
#include <furi_hal_rtc.h>
|
||||
@@ -14,7 +15,7 @@ struct TotpGenerateCodeWorkerContext {
|
||||
FuriMutex* code_buffer_sync;
|
||||
const TokenInfo* token_info;
|
||||
float timezone_offset;
|
||||
uint8_t* iv;
|
||||
const CryptoSettings* crypto_settings;
|
||||
TOTP_NEW_CODE_GENERATED_HANDLER on_new_code_generated_handler;
|
||||
void* on_new_code_generated_handler_context;
|
||||
TOTP_CODE_LIFETIME_CHANGED_HANDLER on_code_lifetime_changed_handler;
|
||||
@@ -69,7 +70,7 @@ static void generate_totp_code(
|
||||
if(token_info->token != NULL && token_info->token_length > 0) {
|
||||
size_t key_length;
|
||||
uint8_t* key = totp_crypto_decrypt(
|
||||
token_info->token, token_info->token_length, context->iv, &key_length);
|
||||
token_info->token, token_info->token_length, context->crypto_settings, &key_length);
|
||||
|
||||
int_token_to_str(
|
||||
totp_at(
|
||||
@@ -147,14 +148,14 @@ TotpGenerateCodeWorkerContext* totp_generate_code_worker_start(
|
||||
const TokenInfo* token_info,
|
||||
FuriMutex* code_buffer_sync,
|
||||
float timezone_offset,
|
||||
uint8_t* iv) {
|
||||
const CryptoSettings* crypto_settings) {
|
||||
TotpGenerateCodeWorkerContext* context = malloc(sizeof(TotpGenerateCodeWorkerContext));
|
||||
furi_check(context != NULL);
|
||||
context->code_buffer = code_buffer;
|
||||
context->token_info = token_info;
|
||||
context->code_buffer_sync = code_buffer_sync;
|
||||
context->timezone_offset = timezone_offset;
|
||||
context->iv = iv;
|
||||
context->crypto_settings = crypto_settings;
|
||||
context->thread = furi_thread_alloc();
|
||||
furi_thread_set_name(context->thread, "TOTPGenerateWorker");
|
||||
furi_thread_set_stack_size(context->thread, 2048);
|
||||
|
||||
@@ -38,7 +38,7 @@ enum TotGenerateCodeWorkerEvents {
|
||||
* @param token_info token info to be used to generate code
|
||||
* @param code_buffer_sync code buffer synchronization primitive
|
||||
* @param timezone_offset timezone offset to be used to generate code
|
||||
* @param iv initialization vector (IV) to be used to decrypt token secret
|
||||
* @param crypto_settings crypto settings
|
||||
* @return worker context
|
||||
*/
|
||||
TotpGenerateCodeWorkerContext* totp_generate_code_worker_start(
|
||||
@@ -46,7 +46,7 @@ TotpGenerateCodeWorkerContext* totp_generate_code_worker_start(
|
||||
const TokenInfo* token_info,
|
||||
FuriMutex* code_buffer_sync,
|
||||
float timezone_offset,
|
||||
uint8_t* iv);
|
||||
const CryptoSettings* crypto_settings);
|
||||
|
||||
/**
|
||||
* @brief Stops generate code worker
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
#include <furi/core/kernel.h>
|
||||
#include "../../services/convert/convert.h"
|
||||
|
||||
static const uint8_t hid_number_keys[] = {
|
||||
#define HID_KEYS_MAP_LENGTH (36)
|
||||
|
||||
static const uint8_t hid_qwerty_keys_map[HID_KEYS_MAP_LENGTH] = {
|
||||
HID_KEYBOARD_0, HID_KEYBOARD_1, HID_KEYBOARD_2, HID_KEYBOARD_3, HID_KEYBOARD_4,
|
||||
HID_KEYBOARD_5, HID_KEYBOARD_6, HID_KEYBOARD_7, HID_KEYBOARD_8, HID_KEYBOARD_9,
|
||||
HID_KEYBOARD_A, HID_KEYBOARD_B, HID_KEYBOARD_C, HID_KEYBOARD_D, HID_KEYBOARD_E,
|
||||
@@ -13,6 +15,16 @@ static const uint8_t hid_number_keys[] = {
|
||||
HID_KEYBOARD_U, HID_KEYBOARD_V, HID_KEYBOARD_W, HID_KEYBOARD_X, HID_KEYBOARD_Y,
|
||||
HID_KEYBOARD_Z};
|
||||
|
||||
static const uint8_t hid_azerty_keys_map[HID_KEYS_MAP_LENGTH] = {
|
||||
HID_KEYBOARD_0, HID_KEYBOARD_1, HID_KEYBOARD_2, HID_KEYBOARD_3, HID_KEYBOARD_4,
|
||||
HID_KEYBOARD_5, HID_KEYBOARD_6, HID_KEYBOARD_7, HID_KEYBOARD_8, HID_KEYBOARD_9,
|
||||
HID_KEYBOARD_Q, HID_KEYBOARD_B, HID_KEYBOARD_C, HID_KEYBOARD_D, HID_KEYBOARD_E,
|
||||
HID_KEYBOARD_F, HID_KEYBOARD_G, HID_KEYBOARD_H, HID_KEYBOARD_I, HID_KEYBOARD_J,
|
||||
HID_KEYBOARD_K, HID_KEYBOARD_L, HID_KEYBOARD_SEMICOLON, HID_KEYBOARD_N, HID_KEYBOARD_O,
|
||||
HID_KEYBOARD_P, HID_KEYBOARD_A, HID_KEYBOARD_R, HID_KEYBOARD_S, HID_KEYBOARD_T,
|
||||
HID_KEYBOARD_U, HID_KEYBOARD_V, HID_KEYBOARD_Z, HID_KEYBOARD_X, HID_KEYBOARD_Y,
|
||||
HID_KEYBOARD_W};
|
||||
|
||||
static uint32_t get_keystroke_delay(TokenAutomationFeature features) {
|
||||
if(features & TokenAutomationFeatureTypeSlower) {
|
||||
return 100;
|
||||
@@ -44,21 +56,38 @@ void totp_type_code_worker_execute_automation(
|
||||
TOTP_AUTOMATION_KEY_HANDLER key_release_fn,
|
||||
const char* code_buffer,
|
||||
uint8_t code_buffer_size,
|
||||
TokenAutomationFeature features) {
|
||||
TokenAutomationFeature features,
|
||||
AutomationKeyboardLayout keyboard_layout) {
|
||||
furi_delay_ms(500);
|
||||
uint8_t i = 0;
|
||||
char cb_char;
|
||||
|
||||
const uint8_t* keyboard_layout_dict;
|
||||
switch(keyboard_layout) {
|
||||
case AutomationKeyboardLayoutQWERTY:
|
||||
keyboard_layout_dict = &hid_qwerty_keys_map[0];
|
||||
break;
|
||||
case AutomationKeyboardLayoutAZERTY:
|
||||
keyboard_layout_dict = &hid_azerty_keys_map[0];
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
while(i < code_buffer_size && (cb_char = code_buffer[i]) != 0) {
|
||||
uint8_t char_index = CONVERT_CHAR_TO_DIGIT(cb_char);
|
||||
if(char_index > 9) {
|
||||
char_index = cb_char - 'A' + 10;
|
||||
}
|
||||
|
||||
if(char_index >= sizeof(hid_number_keys)) break;
|
||||
if(char_index >= HID_KEYS_MAP_LENGTH) break;
|
||||
|
||||
uint16_t hid_kb_key = hid_number_keys[char_index];
|
||||
if(char_index > 9) {
|
||||
uint16_t hid_kb_key = keyboard_layout_dict[char_index];
|
||||
|
||||
// For non-AZERTY press shift for all non-digit chars
|
||||
// For AZERTY press shift for all characters
|
||||
if(char_index > 9 || keyboard_layout == AutomationKeyboardLayoutAZERTY) {
|
||||
hid_kb_key |= KEY_MOD_LEFT_SHIFT;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include "../types/token_info.h"
|
||||
#include "../types/automation_kb_layout.h"
|
||||
|
||||
typedef bool (*TOTP_AUTOMATION_KEY_HANDLER)(uint16_t key);
|
||||
|
||||
@@ -11,10 +12,12 @@ typedef bool (*TOTP_AUTOMATION_KEY_HANDLER)(uint16_t key);
|
||||
* @param code_buffer code buffer to be typed
|
||||
* @param code_buffer_size code buffer size
|
||||
* @param features automation features
|
||||
* @param keyboard_layout keyboard layout to be used
|
||||
*/
|
||||
void totp_type_code_worker_execute_automation(
|
||||
TOTP_AUTOMATION_KEY_HANDLER key_press_fn,
|
||||
TOTP_AUTOMATION_KEY_HANDLER key_release_fn,
|
||||
const char* code_buffer,
|
||||
uint8_t code_buffer_size,
|
||||
TokenAutomationFeature features);
|
||||
TokenAutomationFeature features,
|
||||
AutomationKeyboardLayout keyboard_layout);
|
||||
@@ -15,6 +15,7 @@ struct TotpUsbTypeCodeWorkerContext {
|
||||
FuriThread* thread;
|
||||
FuriMutex* code_buffer_sync;
|
||||
FuriHalUsbInterface* usb_mode_prev;
|
||||
AutomationKeyboardLayout keyboard_layout;
|
||||
};
|
||||
|
||||
static void totp_type_code_worker_restore_usb_mode(TotpUsbTypeCodeWorkerContext* context) {
|
||||
@@ -45,7 +46,8 @@ static void totp_type_code_worker_type_code(TotpUsbTypeCodeWorkerContext* contex
|
||||
&furi_hal_hid_kb_release,
|
||||
context->code_buffer,
|
||||
context->code_buffer_size,
|
||||
context->flags);
|
||||
context->flags,
|
||||
context->keyboard_layout);
|
||||
furi_mutex_release(context->code_buffer_sync);
|
||||
|
||||
furi_delay_ms(100);
|
||||
@@ -83,7 +85,8 @@ static int32_t totp_type_code_worker_callback(void* context) {
|
||||
TotpUsbTypeCodeWorkerContext* totp_usb_type_code_worker_start(
|
||||
char* code_buffer,
|
||||
uint8_t code_buffer_size,
|
||||
FuriMutex* code_buffer_sync) {
|
||||
FuriMutex* code_buffer_sync,
|
||||
AutomationKeyboardLayout keyboard_layout) {
|
||||
TotpUsbTypeCodeWorkerContext* context = malloc(sizeof(TotpUsbTypeCodeWorkerContext));
|
||||
furi_check(context != NULL);
|
||||
context->code_buffer = code_buffer;
|
||||
@@ -91,6 +94,7 @@ TotpUsbTypeCodeWorkerContext* totp_usb_type_code_worker_start(
|
||||
context->code_buffer_sync = code_buffer_sync;
|
||||
context->thread = furi_thread_alloc();
|
||||
context->usb_mode_prev = NULL;
|
||||
context->keyboard_layout = keyboard_layout;
|
||||
furi_thread_set_name(context->thread, "TOTPUsbHidWorker");
|
||||
furi_thread_set_stack_size(context->thread, 1024);
|
||||
furi_thread_set_context(context->thread, context);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <furi/core/mutex.h>
|
||||
#include "../../types/automation_kb_layout.h"
|
||||
|
||||
typedef uint8_t TotpUsbTypeCodeWorkerEvent;
|
||||
|
||||
@@ -34,12 +35,14 @@ enum TotpUsbTypeCodeWorkerEvents {
|
||||
* @param code_buffer code buffer to be used to automate
|
||||
* @param code_buffer_size code buffer size
|
||||
* @param code_buffer_sync code buffer synchronization primitive
|
||||
* @param keyboard_layout keyboard layout to be used
|
||||
* @return worker context
|
||||
*/
|
||||
TotpUsbTypeCodeWorkerContext* totp_usb_type_code_worker_start(
|
||||
char* code_buffer,
|
||||
uint8_t code_buffer_size,
|
||||
FuriMutex* code_buffer_sync);
|
||||
FuriMutex* code_buffer_sync,
|
||||
AutomationKeyboardLayout keyboard_layout);
|
||||
|
||||
/**
|
||||
* @brief Stops USB token input automation worker
|
||||
|
||||
Reference in New Issue
Block a user