Skip to content

Commit 0483d8f

Browse files
committed
* Fixed "Add new token" scene.
* Added UID as IV modifier if user is not using PIN
1 parent 9c1d1b9 commit 0483d8f

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

services/config/config.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,18 @@ void totp_config_file_load_base(PluginState* const plugin_state) {
231231
flipper_format_rewind(fff_data_file);
232232

233233
uint32_t crypto_size;
234-
if (flipper_format_get_value_count(fff_data_file, TOTP_CONFIG_KEY_CRYPTO_VERIFY, &crypto_size)) {
234+
if (flipper_format_get_value_count(fff_data_file, TOTP_CONFIG_KEY_CRYPTO_VERIFY, &crypto_size) && crypto_size > 0) {
235235
plugin_state->crypto_verify_data = malloc(sizeof(uint8_t) * crypto_size);
236236
plugin_state->crypto_verify_data_length = crypto_size;
237237
if (!flipper_format_read_hex(fff_data_file, TOTP_CONFIG_KEY_CRYPTO_VERIFY, plugin_state->crypto_verify_data, crypto_size)) {
238238
FURI_LOG_D(LOGGING_TAG, "Missing crypto verify token");
239239
free(plugin_state->crypto_verify_data);
240240
plugin_state->crypto_verify_data = NULL;
241+
plugin_state->crypto_verify_data_length = 0;
241242
}
243+
} else {
244+
plugin_state->crypto_verify_data = NULL;
245+
plugin_state->crypto_verify_data_length = 0;
242246
}
243247

244248
flipper_format_rewind(fff_data_file);

services/crypto/crypto.c

+21-1
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,29 @@ void totp_crypto_seed_iv(PluginState* plugin_state, uint8_t* pin, uint8_t pin_le
5656

5757
memcpy(&plugin_state->iv[0], &plugin_state->base_iv[0], TOTP_IV_SIZE);
5858
if (pin != NULL && pin_length > 0) {
59-
for (uint8_t i = 0; i < pin_length; i++) {
59+
uint8_t max_i;
60+
if (pin_length > TOTP_IV_SIZE) {
61+
max_i = TOTP_IV_SIZE;
62+
} else {
63+
max_i = pin_length;
64+
}
65+
66+
for (uint8_t i = 0; i < max_i; i++) {
6067
plugin_state->iv[i] = plugin_state->iv[i] ^ (uint8_t)(pin[i] * (i + 1));
6168
}
69+
} else {
70+
uint8_t max_i;
71+
size_t uid_size = furi_hal_version_uid_size();
72+
if (uid_size > TOTP_IV_SIZE) {
73+
max_i = TOTP_IV_SIZE;
74+
} else {
75+
max_i = uid_size;
76+
}
77+
78+
const uint8_t* uid = furi_hal_version_uid();
79+
for(uint8_t i = 0; i < max_i; i++) {
80+
plugin_state->iv[i] = plugin_state->iv[i] ^ uid[i];
81+
}
6282
}
6383

6484
if (plugin_state->crypto_verify_data == NULL) {

totp_app.c

+20-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queu
3737
furi_message_queue_put(event_queue, &event, FuriWaitForever);
3838
}
3939

40-
static void totp_state_init(PluginState* const plugin_state) {
40+
static bool totp_state_init(PluginState* const plugin_state) {
4141
plugin_state->gui = furi_record_open(RECORD_GUI);
4242
plugin_state->notification = furi_record_open(RECORD_NOTIFICATION);
4343
plugin_state->dialogs = furi_record_open(RECORD_DIALOGS);
@@ -61,8 +61,20 @@ static void totp_state_init(PluginState* const plugin_state) {
6161
totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication, NULL);
6262
} else {
6363
totp_crypto_seed_iv(plugin_state, NULL, 0);
64-
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
64+
if (totp_crypto_verify_key(plugin_state)) {
65+
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
66+
} else {
67+
FURI_LOG_E(LOGGING_TAG, "Digital signature verification failed. Looks like conf file was created on another flipper and can't be used on any other");
68+
DialogMessage* message = dialog_message_alloc();
69+
dialog_message_set_buttons(message, "Exit", NULL, NULL);
70+
dialog_message_set_text(message, "Digital signature verification failed", SCREEN_WIDTH_CENTER, SCREEN_HEIGHT_CENTER, AlignCenter, AlignCenter);
71+
dialog_message_show(plugin_state->dialogs, message);
72+
dialog_message_free(message);
73+
return false;
74+
}
6575
}
76+
77+
return true;
6678
}
6779

6880
static void dispose_plugin_state(PluginState* plugin_state) {
@@ -94,7 +106,11 @@ int32_t totp_app() {
94106
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
95107
PluginState* plugin_state = malloc(sizeof(PluginState));
96108

97-
totp_state_init(plugin_state);
109+
if (!totp_state_init(plugin_state)) {
110+
FURI_LOG_E(LOGGING_TAG, "App state initialization failed\r\n");
111+
dispose_plugin_state(plugin_state);
112+
return 254;
113+
}
98114

99115
ValueMutex state_mutex;
100116
if(!init_mutex(&state_mutex, plugin_state, sizeof(PluginState))) {
@@ -126,7 +142,7 @@ int32_t totp_app() {
126142
}
127143

128144
processing = totp_scene_director_handle_event(&event, plugin_state);
129-
} else if (plugin_state->current_scene != TotpSceneAuthentication && furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) {
145+
} else if (plugin_state->pin_set && plugin_state->current_scene != TotpSceneAuthentication && furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) {
130146
totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication, NULL);
131147
}
132148

types/token_info.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void token_info_set_secret(TokenInfo* token_info, const char* base32_token_secre
2626

2727
token_info->token = totp_crypto_encrypt(plain_secret, plain_secret_length, iv, &token_info->token_length);
2828

29-
memset(plain_secret, 0, token_info->token_length);
29+
memset(plain_secret, 0, token_secret_length);
3030
free(plain_secret);
3131
}
3232

0 commit comments

Comments
 (0)