2019-12-15 01:39:02 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <mutex>
|
|
|
|
|
2020-10-27 19:45:28 +03:00
|
|
|
#include <mtx/responses/crypto.hpp>
|
|
|
|
#include <mtxclient/crypto/objects.hpp>
|
2019-12-15 01:39:02 +03:00
|
|
|
|
2020-11-30 02:26:27 +03:00
|
|
|
struct DeviceAndMasterKeys
|
|
|
|
{
|
|
|
|
// map from device id or master key id to message_index
|
|
|
|
std::map<std::string, uint64_t> devices, master_keys;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SharedWithUsers
|
|
|
|
{
|
|
|
|
// userid to keys
|
|
|
|
std::map<std::string, DeviceAndMasterKeys> keys;
|
|
|
|
};
|
|
|
|
|
2019-12-15 01:39:02 +03:00
|
|
|
// Extra information associated with an outbound megolm session.
|
|
|
|
struct OutboundGroupSessionData
|
|
|
|
{
|
|
|
|
std::string session_id;
|
|
|
|
std::string session_key;
|
|
|
|
uint64_t message_index = 0;
|
2020-11-30 02:26:27 +03:00
|
|
|
|
|
|
|
// who has access to this session.
|
|
|
|
// Rotate, when a user leaves the room and share, when a user gets added.
|
|
|
|
SharedWithUsers initially, currently;
|
2019-12-15 01:39:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
to_json(nlohmann::json &obj, const OutboundGroupSessionData &msg);
|
|
|
|
void
|
|
|
|
from_json(const nlohmann::json &obj, OutboundGroupSessionData &msg);
|
|
|
|
|
|
|
|
struct OutboundGroupSessionDataRef
|
|
|
|
{
|
2020-11-27 06:56:44 +03:00
|
|
|
mtx::crypto::OutboundGroupSessionPtr session;
|
2019-12-15 01:39:02 +03:00
|
|
|
OutboundGroupSessionData data;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DevicePublicKeys
|
|
|
|
{
|
|
|
|
std::string ed25519;
|
|
|
|
std::string curve25519;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
to_json(nlohmann::json &obj, const DevicePublicKeys &msg);
|
|
|
|
void
|
|
|
|
from_json(const nlohmann::json &obj, DevicePublicKeys &msg);
|
|
|
|
|
|
|
|
//! Represents a unique megolm session identifier.
|
|
|
|
struct MegolmSessionIndex
|
|
|
|
{
|
|
|
|
//! The room in which this session exists.
|
|
|
|
std::string room_id;
|
|
|
|
//! The session_id of the megolm session.
|
|
|
|
std::string session_id;
|
|
|
|
//! The curve25519 public key of the sender.
|
|
|
|
std::string sender_key;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
to_json(nlohmann::json &obj, const MegolmSessionIndex &msg);
|
|
|
|
void
|
|
|
|
from_json(const nlohmann::json &obj, MegolmSessionIndex &msg);
|
|
|
|
|
2020-10-20 14:46:05 +03:00
|
|
|
struct StoredOlmSession
|
|
|
|
{
|
|
|
|
std::uint64_t last_message_ts = 0;
|
|
|
|
std::string pickled_session;
|
|
|
|
};
|
|
|
|
void
|
|
|
|
to_json(nlohmann::json &obj, const StoredOlmSession &msg);
|
|
|
|
void
|
|
|
|
from_json(const nlohmann::json &obj, StoredOlmSession &msg);
|
|
|
|
|
2020-10-08 00:03:14 +03:00
|
|
|
//! Verification status of a single user
|
|
|
|
struct VerificationStatus
|
|
|
|
{
|
|
|
|
//! True, if the users master key is verified
|
|
|
|
bool user_verified = false;
|
|
|
|
//! List of all devices marked as verified
|
|
|
|
std::vector<std::string> verified_devices;
|
|
|
|
};
|
|
|
|
|
|
|
|
//! In memory cache of verification status
|
|
|
|
struct VerificationStorage
|
|
|
|
{
|
|
|
|
//! mapping of user to verification status
|
|
|
|
std::map<std::string, VerificationStatus> status;
|
|
|
|
std::mutex verification_storage_mtx;
|
|
|
|
};
|
|
|
|
|
2020-07-06 19:02:21 +03:00
|
|
|
// this will store the keys of the user with whom a encrypted room is shared with
|
2020-10-02 02:14:42 +03:00
|
|
|
struct UserKeyCache
|
2020-06-28 18:31:34 +03:00
|
|
|
{
|
2020-10-02 02:14:42 +03:00
|
|
|
//! Device id to device keys
|
|
|
|
std::map<std::string, mtx::crypto::DeviceKeys> device_keys;
|
|
|
|
//! corss signing keys
|
|
|
|
mtx::crypto::CrossSigningKeys master_keys, user_signing_keys, self_signing_keys;
|
|
|
|
//! Sync token when nheko last fetched the keys
|
|
|
|
std::string updated_at;
|
|
|
|
//! Sync token when the keys last changed. updated != last_changed means they are outdated.
|
|
|
|
std::string last_changed;
|
2020-06-28 18:31:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2020-10-02 02:14:42 +03:00
|
|
|
to_json(nlohmann::json &j, const UserKeyCache &info);
|
2020-06-28 18:31:34 +03:00
|
|
|
void
|
2020-10-02 02:14:42 +03:00
|
|
|
from_json(const nlohmann::json &j, UserKeyCache &info);
|
2020-06-28 18:31:34 +03:00
|
|
|
|
2020-07-06 19:02:21 +03:00
|
|
|
// the reason these are stored in a seperate cache rather than storing it in the user cache is
|
2020-10-02 02:14:42 +03:00
|
|
|
// UserKeyCache stores only keys of users with which encrypted room is shared
|
|
|
|
struct VerificationCache
|
2020-06-28 18:31:34 +03:00
|
|
|
{
|
|
|
|
//! list of verified device_ids with device-verification
|
|
|
|
std::vector<std::string> device_verified;
|
2020-07-06 19:02:21 +03:00
|
|
|
//! list of devices the user blocks
|
2020-07-01 15:17:10 +03:00
|
|
|
std::vector<std::string> device_blocked;
|
2020-06-28 18:31:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2020-10-02 02:14:42 +03:00
|
|
|
to_json(nlohmann::json &j, const VerificationCache &info);
|
2020-06-28 18:31:34 +03:00
|
|
|
void
|
2020-10-02 02:14:42 +03:00
|
|
|
from_json(const nlohmann::json &j, VerificationCache &info);
|