Skip to content

Commit

Permalink
FIxed #172 (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
akopachov authored Jul 28, 2023
1 parent 19fbbe0 commit 0604b90
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ App(
],
stack_size=2 * 1024,
order=20,
fap_version="3.0",
fap_version="3.2",
fap_author="Alexander Kopachov (@akopachov)",
fap_description="Software-based TOTP authenticator for Flipper Zero device",
fap_weburl="https://github.com/akopachov/flipper-zero_authenticator",
Expand Down
14 changes: 8 additions & 6 deletions cli/cli_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ extern const char* TOTP_CLI_COLOR_INFO;
#define TOTP_CLI_PRINTF_INFO(format, ...) \
TOTP_CLI_PRINTF_COLORFUL(TOTP_CLI_COLOR_INFO, format, ##__VA_ARGS__)

#define TOTP_CLI_LOCK_UI(plugin_state) \
Scene __previous_scene = plugin_state->current_scene; \
totp_scene_director_activate_scene(plugin_state, TotpSceneStandby)

#define TOTP_CLI_UNLOCK_UI(plugin_state) \
totp_scene_director_activate_scene(plugin_state, __previous_scene)
#define TOTP_CLI_LOCK_UI(plugin_state) \
Scene __previous_scene = plugin_state->current_scene; \
totp_scene_director_activate_scene(plugin_state, TotpSceneStandby); \
totp_scene_director_force_redraw(plugin_state)

#define TOTP_CLI_UNLOCK_UI(plugin_state) \
totp_scene_director_activate_scene(plugin_state, __previous_scene); \
totp_scene_director_force_redraw(plugin_state)

/**
* @brief Checks whether user is authenticated and entered correct PIN.
Expand Down
4 changes: 4 additions & 0 deletions services/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,10 @@ bool totp_config_file_update_encryption(
return false;
}

if(!totp_crypto_check_key_slot(new_crypto_key_slot)) {
return false;
}

uint8_t old_iv[CRYPTO_IV_LENGTH];
memcpy(&old_iv[0], &plugin_state->iv[0], CRYPTO_IV_LENGTH);

Expand Down
29 changes: 16 additions & 13 deletions services/crypto/crypto_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ uint8_t* totp_crypto_encrypt_v2(
*encrypted_data_length = plain_data_aligned_length;

furi_check(
furi_hal_crypto_store_load_key(key_slot, iv) &&
furi_hal_crypto_encrypt(
plain_data_aligned, encrypted_data, plain_data_aligned_length) &&
furi_hal_crypto_store_unload_key(key_slot),
"Encryption failed");
furi_hal_crypto_store_load_key(key_slot, iv), "Encryption failed: store_load_key");
furi_check(
furi_hal_crypto_encrypt(plain_data_aligned, encrypted_data, plain_data_aligned_length),
"Encryption failed: encrypt");
furi_check(
furi_hal_crypto_store_unload_key(key_slot), "Encryption failed: store_unload_key");

memset_s(plain_data_aligned, plain_data_aligned_length, 0, plain_data_aligned_length);
free(plain_data_aligned);
Expand All @@ -59,10 +60,12 @@ uint8_t* totp_crypto_encrypt_v2(
*encrypted_data_length = plain_data_length;

furi_check(
furi_hal_crypto_store_load_key(key_slot, iv) &&
furi_hal_crypto_encrypt(plain_data, encrypted_data, plain_data_length) &&
furi_hal_crypto_store_unload_key(key_slot),
"Encryption failed");
furi_hal_crypto_store_load_key(key_slot, iv), "Encryption failed: store_load_key");
furi_check(
furi_hal_crypto_encrypt(plain_data, encrypted_data, plain_data_length),
"Encryption failed: encrypt");
furi_check(
furi_hal_crypto_store_unload_key(key_slot), "Encryption failed: store_unload_key");
}

return encrypted_data;
Expand All @@ -77,11 +80,11 @@ uint8_t* totp_crypto_decrypt_v2(
*decrypted_data_length = encrypted_data_length;
uint8_t* decrypted_data = malloc(*decrypted_data_length);
furi_check(decrypted_data != NULL);
furi_check(furi_hal_crypto_store_load_key(key_slot, iv), "Decryption failed: store_load_key");
furi_check(
furi_hal_crypto_store_load_key(key_slot, iv) &&
furi_hal_crypto_decrypt(encrypted_data, decrypted_data, encrypted_data_length) &&
furi_hal_crypto_store_unload_key(key_slot),
"Decryption failed");
furi_hal_crypto_decrypt(encrypted_data, decrypted_data, encrypted_data_length),
"Decryption failed: decrypt");
furi_check(furi_hal_crypto_store_unload_key(key_slot), "Decryption failed: store_unload_key");
return decrypted_data;
}

Expand Down
1 change: 1 addition & 0 deletions totp_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ static bool on_user_idle(void* context) {
if(plugin_state->current_scene != TotpSceneAuthentication &&
plugin_state->current_scene != TotpSceneStandby) {
totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication);
totp_scene_director_force_redraw(plugin_state);
return true;
}

Expand Down

0 comments on commit 0604b90

Please sign in to comment.