mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 01:38:35 -07:00
Temporarily backport app updates from apps repo
This commit is contained in:
@@ -72,17 +72,23 @@ static void generate_totp_code(
|
||||
uint8_t* key = totp_crypto_decrypt(
|
||||
token_info->token, token_info->token_length, context->crypto_settings, &key_length);
|
||||
|
||||
int_token_to_str(
|
||||
totp_at(
|
||||
uint64_t otp_code;
|
||||
if(token_info->type == TokenTypeTOTP) {
|
||||
otp_code = totp_at(
|
||||
get_totp_algo_impl(token_info->algo),
|
||||
key,
|
||||
key_length,
|
||||
current_ts,
|
||||
context->timezone_offset,
|
||||
token_info->duration),
|
||||
context->code_buffer,
|
||||
token_info->digits,
|
||||
token_info->algo);
|
||||
token_info->duration);
|
||||
} else if(token_info->type == TokenTypeHOTP) {
|
||||
otp_code = hotp_at(
|
||||
get_totp_algo_impl(token_info->algo), key, key_length, token_info->counter);
|
||||
} else {
|
||||
furi_crash("Unknown token type");
|
||||
}
|
||||
|
||||
int_token_to_str(otp_code, context->code_buffer, token_info->digits, token_info->algo);
|
||||
memset_s(key, key_length, 0, key_length);
|
||||
free(key);
|
||||
} else {
|
||||
@@ -116,14 +122,18 @@ static int32_t totp_generate_worker_callback(void* context) {
|
||||
continue;
|
||||
}
|
||||
|
||||
uint32_t curr_ts = furi_hal_rtc_get_timestamp();
|
||||
const bool is_time_based = token_info->type == TokenTypeTOTP;
|
||||
|
||||
uint32_t curr_ts = is_time_based ? furi_hal_rtc_get_timestamp() : 0;
|
||||
|
||||
bool time_left = false;
|
||||
if(flags & TotpGenerateCodeWorkerEventForceUpdate ||
|
||||
(time_left = (curr_ts % token_info->duration) == 0)) {
|
||||
(is_time_based && (time_left = (curr_ts % token_info->duration) == 0))) {
|
||||
if(furi_mutex_acquire(t_context->code_buffer_sync, FuriWaitForever) == FuriStatusOk) {
|
||||
generate_totp_code(t_context, token_info, curr_ts);
|
||||
curr_ts = furi_hal_rtc_get_timestamp();
|
||||
if(is_time_based) {
|
||||
curr_ts = furi_hal_rtc_get_timestamp();
|
||||
}
|
||||
furi_mutex_release(t_context->code_buffer_sync);
|
||||
if(t_context->on_new_code_generated_handler != NULL) {
|
||||
(*(t_context->on_new_code_generated_handler))(
|
||||
@@ -132,7 +142,8 @@ static int32_t totp_generate_worker_callback(void* context) {
|
||||
}
|
||||
}
|
||||
|
||||
if(t_context->on_code_lifetime_changed_handler != NULL) {
|
||||
if(t_context->on_code_lifetime_changed_handler != NULL &&
|
||||
token_info->type == TokenTypeTOTP) {
|
||||
(*(t_context->on_code_lifetime_changed_handler))(
|
||||
(float)(token_info->duration - curr_ts % token_info->duration) /
|
||||
(float)token_info->duration,
|
||||
@@ -196,4 +207,4 @@ void totp_generate_code_worker_set_lifetime_changed_handler(
|
||||
furi_check(context != NULL);
|
||||
context->on_code_lifetime_changed_handler = on_code_lifetime_changed_handler;
|
||||
context->on_code_lifetime_changed_handler_context = on_code_lifetime_changed_handler_context;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ enum TotGenerateCodeWorkerEvents {
|
||||
TotpGenerateCodeWorkerEventStop = 0b01,
|
||||
|
||||
/**
|
||||
* @brief Trigger token input automation
|
||||
* @brief Triggers OTP code generation
|
||||
*/
|
||||
TotpGenerateCodeWorkerEventForceUpdate = 0b10
|
||||
};
|
||||
@@ -83,4 +83,4 @@ void totp_generate_code_worker_set_code_generated_handler(
|
||||
void totp_generate_code_worker_set_lifetime_changed_handler(
|
||||
TotpGenerateCodeWorkerContext* context,
|
||||
TOTP_CODE_LIFETIME_CHANGED_HANDLER on_code_lifetime_changed_handler,
|
||||
void* on_code_lifetime_changed_handler_context);
|
||||
void* on_code_lifetime_changed_handler_context);
|
||||
|
||||
Reference in New Issue
Block a user