|
@@ -4,6 +4,7 @@ typedef enum {
|
|
|
ESubGhzChatKeyMenuItems_NoEncryption,
|
|
ESubGhzChatKeyMenuItems_NoEncryption,
|
|
|
ESubGhzChatKeyMenuItems_Password,
|
|
ESubGhzChatKeyMenuItems_Password,
|
|
|
ESubGhzChatKeyMenuItems_HexKey,
|
|
ESubGhzChatKeyMenuItems_HexKey,
|
|
|
|
|
+ ESubGhzChatKeyMenuItems_GenKey,
|
|
|
} ESubGhzChatKeyMenuItems;
|
|
} ESubGhzChatKeyMenuItems;
|
|
|
|
|
|
|
|
static void key_menu_cb(void* context, uint32_t index)
|
|
static void key_menu_cb(void* context, uint32_t index)
|
|
@@ -11,6 +12,8 @@ static void key_menu_cb(void* context, uint32_t index)
|
|
|
furi_assert(context);
|
|
furi_assert(context);
|
|
|
ESubGhzChatState* state = context;
|
|
ESubGhzChatState* state = context;
|
|
|
|
|
|
|
|
|
|
+ uint8_t key[KEY_BITS / 8];
|
|
|
|
|
+
|
|
|
switch(index) {
|
|
switch(index) {
|
|
|
case ESubGhzChatKeyMenuItems_NoEncryption:
|
|
case ESubGhzChatKeyMenuItems_NoEncryption:
|
|
|
state->encrypted = false;
|
|
state->encrypted = false;
|
|
@@ -30,6 +33,29 @@ static void key_menu_cb(void* context, uint32_t index)
|
|
|
ESubGhzChatEvent_KeyMenuHexKey);
|
|
ESubGhzChatEvent_KeyMenuHexKey);
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
|
|
+ case ESubGhzChatKeyMenuItems_GenKey:
|
|
|
|
|
+ /* generate a random key */
|
|
|
|
|
+ furi_hal_random_fill_buf(key, KEY_BITS / 8);
|
|
|
|
|
+
|
|
|
|
|
+ /* initiate the crypto context */
|
|
|
|
|
+ bool ret = crypto_ctx_set_key(state->crypto_ctx, key);
|
|
|
|
|
+
|
|
|
|
|
+ /* cleanup */
|
|
|
|
|
+ crypto_explicit_bzero(key, sizeof(key));
|
|
|
|
|
+
|
|
|
|
|
+ if (!ret) {
|
|
|
|
|
+ crypto_ctx_clear(state->crypto_ctx);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /* set encrypted flag and enter the chat */
|
|
|
|
|
+ state->encrypted = true;
|
|
|
|
|
+ enter_chat(state);
|
|
|
|
|
+
|
|
|
|
|
+ scene_manager_handle_custom_event(state->scene_manager,
|
|
|
|
|
+ ESubGhzChatEvent_KeyMenuGenKey);
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
default:
|
|
default:
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
@@ -69,6 +95,14 @@ void scene_on_enter_key_menu(void* context)
|
|
|
key_menu_cb,
|
|
key_menu_cb,
|
|
|
state
|
|
state
|
|
|
);
|
|
);
|
|
|
|
|
+ menu_add_item(
|
|
|
|
|
+ state->menu,
|
|
|
|
|
+ "Generate Key",
|
|
|
|
|
+ NULL,
|
|
|
|
|
+ ESubGhzChatKeyMenuItems_GenKey,
|
|
|
|
|
+ key_menu_cb,
|
|
|
|
|
+ state
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
view_dispatcher_switch_to_view(state->view_dispatcher, ESubGhzChatView_Menu);
|
|
view_dispatcher_switch_to_view(state->view_dispatcher, ESubGhzChatView_Menu);
|
|
|
}
|
|
}
|
|
@@ -88,6 +122,7 @@ bool scene_on_event_key_menu(void* context, SceneManagerEvent event)
|
|
|
switch(event.event) {
|
|
switch(event.event) {
|
|
|
/* switch to message input scene */
|
|
/* switch to message input scene */
|
|
|
case ESubGhzChatEvent_KeyMenuNoEncryption:
|
|
case ESubGhzChatEvent_KeyMenuNoEncryption:
|
|
|
|
|
+ case ESubGhzChatEvent_KeyMenuGenKey:
|
|
|
scene_manager_next_scene(state->scene_manager,
|
|
scene_manager_next_scene(state->scene_manager,
|
|
|
ESubGhzChatScene_ChatInput);
|
|
ESubGhzChatScene_ChatInput);
|
|
|
consumed = true;
|
|
consumed = true;
|
|
@@ -107,6 +142,7 @@ bool scene_on_event_key_menu(void* context, SceneManagerEvent event)
|
|
|
consumed = true;
|
|
consumed = true;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case SceneManagerEventTypeBack:
|
|
case SceneManagerEventTypeBack:
|