0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 00:02:34 +01:00

modules/client/keys/signatures: Re-schematize signatures uploaded for keys and devices.

This commit is contained in:
Jason Volk 2023-04-24 12:32:59 -07:00
parent 8eb4de920c
commit 8b0cf48578
3 changed files with 68 additions and 36 deletions

View file

@ -43,6 +43,11 @@ ircd::m::resource::response
ircd::m::post_keys_signatures_upload(client &client, ircd::m::post_keys_signatures_upload(client &client,
const resource::request &request) const resource::request &request)
{ {
const auto src_device
{
m::user::tokens::device(std::nothrow, request.access_token)
};
for(const auto &[_user_id, devices_keys_] : request) for(const auto &[_user_id, devices_keys_] : request)
{ {
if(!valid(m::id::USER, _user_id)) if(!valid(m::id::USER, _user_id))
@ -58,27 +63,22 @@ ircd::m::post_keys_signatures_upload(client &client,
user_id user_id
}; };
const m::user::devices devices for(const auto &[target_id, device_keys] : json::object(devices_keys_))
{ {
user_id char buf[512];
}; const string_view state_key{fmt::sprintf
const json::object &devices_keys
{
devices_keys_
};
for(const auto &[_device_id, device_keys_] : devices_keys)
{
const m::device_keys device_keys
{ {
device_keys_ buf, "%s%s",
}; string_view{target_id},
target_id != src_device && src_device?
string_view{src_device}:
string_view{},
}};
const bool set send(user_room, user_id, "ircd.keys.signatures", state_key, json::object
{ {
devices.set(_device_id, "signatures", device_keys_) device_keys
}; });
} }
} }

View file

@ -38,13 +38,21 @@ ircd::m::sync::device_lists_linear(data &data)
assert(data.event); assert(data.event);
const m::event &event{*data.event}; const m::event &event{*data.event};
if(!startswith(json::get<"type"_>(event), "ircd.device"))
return false;
if(startswith(json::get<"type"_>(event), "ircd.device.signing")) const bool including
return false; {
false
|| startswith(json::get<"type"_>(event), "ircd.device")
|| startswith(json::get<"type"_>(event), "ircd.keys.signatures")
};
if(startswith(json::get<"type"_>(event), "ircd.device.one_time_key")) const bool excluding
{
false
|| startswith(json::get<"type"_>(event), "ircd.device.one_time_key")
};
if(!including || excluding)
return false; return false;
const m::user sender const m::user sender

View file

@ -272,17 +272,22 @@ _query_user_device(client &client,
if(!devices.has(device_id, "keys")) if(!devices.has(device_id, "keys"))
return; return;
const m::user::room user_room
{
devices.user.user_id
};
json::stack::object object json::stack::object object
{ {
out, device_id out, device_id
}; };
devices.get(std::nothrow, device_id, "keys", [&devices, &device_id, &object] devices.get(std::nothrow, device_id, "keys", [&user_room, &device_id, &object]
(const auto &event_idx, const json::object &device_keys) (const auto &, const json::object &device_keys)
{ {
const auto &user_id const auto &user_id
{ {
devices.user.user_id user_room.user.user_id
}; };
for(const auto &member : device_keys) for(const auto &member : device_keys)
@ -318,24 +323,43 @@ _query_user_device(client &client,
user_sigs, member user_sigs, member
}; };
devices.get(std::nothrow, device_id, "signatures", [&user_id, &user_sigs] const m::room::state state
(const auto &event_idx, const json::object &device_sigs)
{ {
const json::object device_sigs_sigs user_room
};
state.for_each("ircd.keys.signatures", [&user_id, &user_sigs, &device_id]
(const string_view &, const string_view &state_key, const auto &event_idx)
{
const auto &[target, source]
{ {
device_sigs["signatures"] rsplit(state_key, '%')
}; };
const json::object device_sigs_user_sigs if(target && target != device_id)
{ return true;
device_sigs_sigs[user_id]
};
for(const auto &member : device_sigs_user_sigs) m::get(std::nothrow, event_idx, "content", [&user_id, &user_sigs]
json::stack::member (const json::object &device_sigs)
{
const json::object device_sigs_sigs
{ {
user_sigs, member device_sigs["signatures"]
}; };
const json::object device_sigs_user_sigs
{
device_sigs_sigs[user_id]
};
for(const auto &member : device_sigs_user_sigs)
json::stack::member
{
user_sigs, member
};
});
return true;
}); });
}); });