mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 04:58:49 +03:00
Clean up encrypted message handling
This commit is contained in:
parent
9825f1bbd0
commit
74f17bdc60
1 changed files with 53 additions and 51 deletions
104
src/Olm.cpp
104
src/Olm.cpp
|
@ -6,6 +6,7 @@
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
|
#include <mtx/responses/common.hpp>
|
||||||
#include <mtx/secret_storage.hpp>
|
#include <mtx/secret_storage.hpp>
|
||||||
|
|
||||||
#include "Cache.h"
|
#include "Cache.h"
|
||||||
|
@ -169,59 +170,60 @@ handle_olm_message(const OlmMessage &msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!payload.is_null()) {
|
if (!payload.is_null()) {
|
||||||
std::string msg_type = payload["type"];
|
mtx::events::collections::DeviceEvents device_event;
|
||||||
|
|
||||||
if (msg_type == to_string(mtx::events::EventType::KeyVerificationAccept)) {
|
{
|
||||||
ChatPage::instance()->receivedDeviceVerificationAccept(
|
std::string msg_type = payload["type"];
|
||||||
payload["content"]);
|
json event_array = json::array();
|
||||||
return;
|
event_array.push_back(payload);
|
||||||
} else if (msg_type ==
|
|
||||||
to_string(mtx::events::EventType::KeyVerificationRequest)) {
|
std::vector<mtx::events::collections::DeviceEvents> temp_events;
|
||||||
ChatPage::instance()->receivedDeviceVerificationRequest(
|
mtx::responses::utils::parse_device_events(event_array,
|
||||||
payload["content"], payload["sender"]);
|
temp_events);
|
||||||
return;
|
if (temp_events.empty()) {
|
||||||
} else if (msg_type ==
|
nhlog::crypto()->warn("Decrypted unknown event: {}",
|
||||||
to_string(mtx::events::EventType::KeyVerificationCancel)) {
|
payload.dump());
|
||||||
ChatPage::instance()->receivedDeviceVerificationCancel(
|
continue;
|
||||||
payload["content"]);
|
}
|
||||||
return;
|
device_event = temp_events.at(0);
|
||||||
} else if (msg_type ==
|
|
||||||
to_string(mtx::events::EventType::KeyVerificationKey)) {
|
|
||||||
ChatPage::instance()->receivedDeviceVerificationKey(
|
|
||||||
payload["content"]);
|
|
||||||
return;
|
|
||||||
} else if (msg_type ==
|
|
||||||
to_string(mtx::events::EventType::KeyVerificationMac)) {
|
|
||||||
ChatPage::instance()->receivedDeviceVerificationMac(
|
|
||||||
payload["content"]);
|
|
||||||
return;
|
|
||||||
} else if (msg_type ==
|
|
||||||
to_string(mtx::events::EventType::KeyVerificationStart)) {
|
|
||||||
ChatPage::instance()->receivedDeviceVerificationStart(
|
|
||||||
payload["content"], payload["sender"]);
|
|
||||||
return;
|
|
||||||
} else if (msg_type ==
|
|
||||||
to_string(mtx::events::EventType::KeyVerificationReady)) {
|
|
||||||
ChatPage::instance()->receivedDeviceVerificationReady(
|
|
||||||
payload["content"]);
|
|
||||||
return;
|
|
||||||
} else if (msg_type ==
|
|
||||||
to_string(mtx::events::EventType::KeyVerificationDone)) {
|
|
||||||
ChatPage::instance()->receivedDeviceVerificationDone(
|
|
||||||
payload["content"]);
|
|
||||||
return;
|
|
||||||
} else if (msg_type == to_string(mtx::events::EventType::RoomKey)) {
|
|
||||||
mtx::events::DeviceEvent<mtx::events::msg::RoomKey> roomKey =
|
|
||||||
payload;
|
|
||||||
create_inbound_megolm_session(roomKey, msg.sender_key);
|
|
||||||
return;
|
|
||||||
} else if (msg_type ==
|
|
||||||
to_string(mtx::events::EventType::ForwardedRoomKey)) {
|
|
||||||
mtx::events::DeviceEvent<mtx::events::msg::ForwardedRoomKey>
|
|
||||||
roomKey = payload;
|
|
||||||
import_inbound_megolm_session(roomKey);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using namespace mtx::events;
|
||||||
|
if (auto e =
|
||||||
|
std::get_if<DeviceEvent<msg::KeyVerificationAccept>>(&device_event)) {
|
||||||
|
ChatPage::instance()->receivedDeviceVerificationAccept(e->content);
|
||||||
|
} else if (auto e = std::get_if<DeviceEvent<msg::KeyVerificationRequest>>(
|
||||||
|
&device_event)) {
|
||||||
|
ChatPage::instance()->receivedDeviceVerificationRequest(e->content,
|
||||||
|
e->sender);
|
||||||
|
} else if (auto e = std::get_if<DeviceEvent<msg::KeyVerificationCancel>>(
|
||||||
|
&device_event)) {
|
||||||
|
ChatPage::instance()->receivedDeviceVerificationCancel(e->content);
|
||||||
|
} else if (auto e = std::get_if<DeviceEvent<msg::KeyVerificationKey>>(
|
||||||
|
&device_event)) {
|
||||||
|
ChatPage::instance()->receivedDeviceVerificationKey(e->content);
|
||||||
|
} else if (auto e = std::get_if<DeviceEvent<msg::KeyVerificationMac>>(
|
||||||
|
&device_event)) {
|
||||||
|
ChatPage::instance()->receivedDeviceVerificationMac(e->content);
|
||||||
|
} else if (auto e = std::get_if<DeviceEvent<msg::KeyVerificationStart>>(
|
||||||
|
&device_event)) {
|
||||||
|
ChatPage::instance()->receivedDeviceVerificationStart(e->content,
|
||||||
|
e->sender);
|
||||||
|
} else if (auto e = std::get_if<DeviceEvent<msg::KeyVerificationReady>>(
|
||||||
|
&device_event)) {
|
||||||
|
ChatPage::instance()->receivedDeviceVerificationReady(e->content);
|
||||||
|
} else if (auto e = std::get_if<DeviceEvent<msg::KeyVerificationDone>>(
|
||||||
|
&device_event)) {
|
||||||
|
ChatPage::instance()->receivedDeviceVerificationDone(e->content);
|
||||||
|
} else if (auto roomKey =
|
||||||
|
std::get_if<DeviceEvent<msg::RoomKey>>(&device_event)) {
|
||||||
|
create_inbound_megolm_session(*roomKey, msg.sender_key);
|
||||||
|
} else if (auto roomKey = std::get_if<DeviceEvent<msg::ForwardedRoomKey>>(
|
||||||
|
&device_event)) {
|
||||||
|
import_inbound_megolm_session(*roomKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue