| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <QObject> |
| 8 |
#include <QQmlEngine> |
| 9 |
|
| 10 |
#include <map> |
| 11 |
#include <mutex> |
| 12 |
#include <set> |
| 13 |
|
| 14 |
#include <mtx/responses/crypto.hpp> |
| 15 |
#include <mtxclient/crypto/objects.hpp> |
| 16 |
|
| 17 |
namespace mtx::events::msg { |
| 18 |
struct Encrypted; |
| 19 |
} |
| 20 |
|
| 21 |
namespace crypto { |
| 22 |
Q_NAMESPACE |
| 23 |
QML_NAMED_ELEMENT(Crypto) |
| 24 |
|
| 25 |
|
| 26 |
enum Trust |
| 27 |
{ |
| 28 |
Unverified, |
| 29 |
MessageUnverified, |
| 30 |
|
| 31 |
TOFU, |
| 32 |
|
| 33 |
Verified, |
| 34 |
}; |
| 35 |
Q_ENUM_NS(Trust) |
| 36 |
} |
| 37 |
|
| 38 |
struct DeviceKeysToMsgIndex |
| 39 |
{ |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
std::map<std::string, uint32_t> deviceids; |
| 44 |
}; |
| 45 |
|
| 46 |
struct SharedWithUsers |
| 47 |
{ |
| 48 |
|
| 49 |
std::map<std::string, DeviceKeysToMsgIndex> keys; |
| 50 |
}; |
| 51 |
|
| 52 |
|
| 53 |
struct GroupSessionData |
| 54 |
{ |
| 55 |
uint64_t timestamp = 0; |
| 56 |
uint32_t message_index = 0; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
bool trusted = false; |
| 61 |
|
| 62 |
|
| 63 |
std::string sender_key; |
| 64 |
|
| 65 |
std::string sender_claimed_ed25519_key; |
| 66 |
std::vector<std::string> forwarding_curve25519_key_chain; |
| 67 |
|
| 68 |
|
| 69 |
std::map<uint32_t, std::string> indices; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
SharedWithUsers currently; |
| 74 |
}; |
| 75 |
|
| 76 |
void |
| 77 |
to_json(nlohmann::json &obj, const GroupSessionData &msg); |
| 78 |
void |
| 79 |
from_json(const nlohmann::json &obj, GroupSessionData &msg); |
| 80 |
|
| 81 |
struct OutboundGroupSessionDataRef |
| 82 |
{ |
| 83 |
mtx::crypto::OutboundGroupSessionPtr session; |
| 84 |
GroupSessionData data; |
| 85 |
}; |
| 86 |
|
| 87 |
struct DevicePublicKeys |
| 88 |
{ |
| 89 |
std::string ed25519; |
| 90 |
std::string curve25519; |
| 91 |
}; |
| 92 |
|
| 93 |
void |
| 94 |
to_json(nlohmann::json &obj, const DevicePublicKeys &msg); |
| 95 |
void |
| 96 |
from_json(const nlohmann::json &obj, DevicePublicKeys &msg); |
| 97 |
|
| 98 |
|
| 99 |
struct MegolmSessionIndex |
| 100 |
{ |
| 101 |
MegolmSessionIndex() = default; |
| 102 |
MegolmSessionIndex(std::string room_id_, const mtx::events::msg::Encrypted &e); |
| 103 |
|
| 104 |
|
| 105 |
std::string room_id; |
| 106 |
|
| 107 |
std::string session_id; |
| 108 |
}; |
| 109 |
|
| 110 |
void |
| 111 |
to_json(nlohmann::json &obj, const MegolmSessionIndex &msg); |
| 112 |
void |
| 113 |
from_json(const nlohmann::json &obj, MegolmSessionIndex &msg); |
| 114 |
|
| 115 |
struct StoredOlmSession |
| 116 |
{ |
| 117 |
std::uint64_t last_message_ts = 0; |
| 118 |
std::string pickled_session; |
| 119 |
}; |
| 120 |
void |
| 121 |
to_json(nlohmann::json &obj, const StoredOlmSession &msg); |
| 122 |
void |
| 123 |
from_json(const nlohmann::json &obj, StoredOlmSession &msg); |
| 124 |
|
| 125 |
|
| 126 |
struct VerificationStatus |
| 127 |
{ |
| 128 |
|
| 129 |
crypto::Trust user_verified = crypto::Trust::Unverified; |
| 130 |
|
| 131 |
std::set<std::string> verified_devices; |
| 132 |
|
| 133 |
std::map<std::string, crypto::Trust> verified_device_keys; |
| 134 |
|
| 135 |
int unverified_device_count = 0; |
| 136 |
|
| 137 |
bool no_keys = false; |
| 138 |
}; |
| 139 |
|
| 140 |
|
| 141 |
struct VerificationStorage |
| 142 |
{ |
| 143 |
|
| 144 |
std::map<std::string, VerificationStatus> status; |
| 145 |
std::mutex verification_storage_mtx; |
| 146 |
}; |
| 147 |
|
| 148 |
|
| 149 |
struct SecretsStorage |
| 150 |
{ |
| 151 |
|
| 152 |
std::map<std::string, std::string> secrets; |
| 153 |
std::mutex mtx; |
| 154 |
}; |
| 155 |
|
| 156 |
|
| 157 |
struct UserKeyCache |
| 158 |
{ |
| 159 |
|
| 160 |
std::map<std::string, mtx::crypto::DeviceKeys> device_keys; |
| 161 |
|
| 162 |
mtx::crypto::CrossSigningKeys master_keys, user_signing_keys, self_signing_keys; |
| 163 |
|
| 164 |
std::string updated_at; |
| 165 |
|
| 166 |
std::string last_changed; |
| 167 |
|
| 168 |
bool master_key_changed = false; |
| 169 |
|
| 170 |
std::set<std::string> seen_device_keys; |
| 171 |
|
| 172 |
std::set<std::string> seen_device_ids; |
| 173 |
}; |
| 174 |
|
| 175 |
void |
| 176 |
to_json(nlohmann::json &j, const UserKeyCache &info); |
| 177 |
void |
| 178 |
from_json(const nlohmann::json &j, UserKeyCache &info); |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
struct VerificationCache |
| 183 |
{ |
| 184 |
|
| 185 |
std::set<std::string> device_verified; |
| 186 |
|
| 187 |
std::set<std::string> device_blocked; |
| 188 |
}; |
| 189 |
|
| 190 |
void |
| 191 |
to_json(nlohmann::json &j, const VerificationCache &info); |
| 192 |
void |
| 193 |
from_json(const nlohmann::json &j, VerificationCache &info); |
| 194 |
|
| 195 |
struct OnlineBackupVersion |
| 196 |
{ |
| 197 |
|
| 198 |
std::string version; |
| 199 |
|
| 200 |
std::string algorithm; |
| 201 |
}; |
| 202 |
|
| 203 |
void |
| 204 |
to_json(nlohmann::json &j, const OnlineBackupVersion &info); |
| 205 |
void |
| 206 |
from_json(const nlohmann::json &j, OnlineBackupVersion &info); |