| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <mtx/events.hpp> |
| 8 |
#include <mtx/events/encrypted.hpp> |
| 9 |
#include <mtxclient/crypto/client.hpp> |
| 10 |
|
| 11 |
#include <QQmlEngine> |
| 12 |
|
| 13 |
#include <CacheCryptoStructs.h> |
| 14 |
|
| 15 |
namespace olm { |
| 16 |
Q_NAMESPACE |
| 17 |
QML_NAMED_ELEMENT(Olm) |
| 18 |
|
| 19 |
enum DecryptionErrorCode |
| 20 |
{ |
| 21 |
NoError, |
| 22 |
MissingSession, |
| 23 |
|
| 24 |
MissingSessionIndex, |
| 25 |
|
| 26 |
DbError, |
| 27 |
DecryptionFailed, |
| 28 |
ParsingFailed, |
| 29 |
ReplayAttack, |
| 30 |
}; |
| 31 |
Q_ENUM_NS(DecryptionErrorCode) |
| 32 |
|
| 33 |
struct DecryptionResult |
| 34 |
{ |
| 35 |
DecryptionErrorCode error; |
| 36 |
std::optional<std::string> error_message; |
| 37 |
std::optional<mtx::events::collections::TimelineEvents> event; |
| 38 |
}; |
| 39 |
|
| 40 |
struct OlmMessage |
| 41 |
{ |
| 42 |
std::string sender_key; |
| 43 |
std::string sender; |
| 44 |
|
| 45 |
using RecipientKey = std::string; |
| 46 |
std::map<RecipientKey, mtx::events::msg::OlmCipherContent> ciphertext; |
| 47 |
}; |
| 48 |
|
| 49 |
void |
| 50 |
from_json(const nlohmann::json &obj, OlmMessage &msg); |
| 51 |
|
| 52 |
mtx::crypto::OlmClient * |
| 53 |
client(); |
| 54 |
|
| 55 |
void |
| 56 |
handle_to_device_messages(const std::vector<mtx::events::collections::DeviceEvents> &msgs); |
| 57 |
|
| 58 |
nlohmann::json |
| 59 |
try_olm_decryption(const std::string &sender_key, |
| 60 |
const mtx::events::msg::OlmCipherContent &content); |
| 61 |
|
| 62 |
void |
| 63 |
handle_olm_message(const OlmMessage &msg, const UserKeyCache &otherUserDeviceKeys); |
| 64 |
|
| 65 |
|
| 66 |
void |
| 67 |
create_inbound_megolm_session(const mtx::events::DeviceEvent<mtx::events::msg::RoomKey> &roomKey, |
| 68 |
const std::string &sender_key, |
| 69 |
const std::string &sender_ed25519); |
| 70 |
void |
| 71 |
import_inbound_megolm_session( |
| 72 |
const mtx::events::DeviceEvent<mtx::events::msg::ForwardedRoomKey> &roomKey); |
| 73 |
void |
| 74 |
lookup_keybackup(const std::string &room, const std::string &session_id); |
| 75 |
void |
| 76 |
download_full_keybackup(); |
| 77 |
|
| 78 |
nlohmann::json |
| 79 |
handle_pre_key_olm_message(const std::string &sender, |
| 80 |
const std::string &sender_key, |
| 81 |
const mtx::events::msg::OlmCipherContent &content); |
| 82 |
|
| 83 |
mtx::events::msg::Encrypted |
| 84 |
encrypt_group_message_with_session(mtx::crypto::OutboundGroupSessionPtr &session, |
| 85 |
const std::string &device_id, |
| 86 |
nlohmann::json body); |
| 87 |
|
| 88 |
mtx::events::msg::Encrypted |
| 89 |
encrypt_group_message(const std::string &room_id, |
| 90 |
const std::string &device_id, |
| 91 |
nlohmann::json body); |
| 92 |
|
| 93 |
|
| 94 |
DecryptionResult |
| 95 |
decryptEvent(const MegolmSessionIndex &index, |
| 96 |
const mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> &event, |
| 97 |
bool dont_write_db = false); |
| 98 |
crypto::Trust |
| 99 |
calculate_trust(const std::string &user_id, |
| 100 |
const std::string &room_id, |
| 101 |
const mtx::events::msg::Encrypted &event); |
| 102 |
|
| 103 |
void |
| 104 |
mark_keys_as_published(); |
| 105 |
|
| 106 |
|
| 107 |
void |
| 108 |
send_key_request_for(mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> e, |
| 109 |
const std::string &request_id, |
| 110 |
bool cancel = false); |
| 111 |
|
| 112 |
void |
| 113 |
handle_key_request_message(const mtx::events::DeviceEvent<mtx::events::msg::KeyRequest> &); |
| 114 |
|
| 115 |
void |
| 116 |
send_megolm_key_to_device(const std::string &user_id, |
| 117 |
const std::string &device_id, |
| 118 |
const mtx::events::msg::ForwardedRoomKey &payload); |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
void |
| 123 |
send_encrypted_to_device_messages(const std::map<std::string, std::vector<std::string>> &targets, |
| 124 |
const mtx::events::collections::DeviceEvents &event, |
| 125 |
bool force_new_session = false); |
| 126 |
|
| 127 |
|
| 128 |
void |
| 129 |
request_cross_signing_keys(); |
| 130 |
|
| 131 |
void |
| 132 |
download_cross_signing_keys(); |
| 133 |
|
| 134 |
} |