mirror of
https://github.com/matrix-construct/construct
synced 2024-12-25 23:14:13 +01:00
modules/federation/user_keys_claim: Implement 22.1 POST /user/keys/claim.
This commit is contained in:
parent
1680e5107b
commit
746689086a
1 changed files with 97 additions and 8 deletions
|
@ -10,10 +10,14 @@
|
|||
|
||||
using namespace ircd;
|
||||
|
||||
static m::resource::response
|
||||
post__user_keys_claim(client &client,
|
||||
const m::resource::request &request);
|
||||
|
||||
mapi::header
|
||||
IRCD_MODULE
|
||||
{
|
||||
"Federation 21 :End-to-End Encryption"
|
||||
"Federation 22 :End-to-End Encryption"
|
||||
};
|
||||
|
||||
m::resource
|
||||
|
@ -21,14 +25,10 @@ user_keys_claim_resource
|
|||
{
|
||||
"/_matrix/federation/v1/user/keys/claim",
|
||||
{
|
||||
"federation user keys claim",
|
||||
"Federation 22 :Claims one-time keys for use in pre-key messages.",
|
||||
}
|
||||
};
|
||||
|
||||
static m::resource::response
|
||||
post__user_keys_claim(client &client,
|
||||
const m::resource::request &request);
|
||||
|
||||
m::resource::method
|
||||
user_keys_claim__post
|
||||
{
|
||||
|
@ -42,8 +42,97 @@ m::resource::response
|
|||
post__user_keys_claim(client &client,
|
||||
const m::resource::request &request)
|
||||
{
|
||||
return m::resource::response
|
||||
const json::object &one_time_keys
|
||||
{
|
||||
client, http::NOT_FOUND
|
||||
request["one_time_keys"]
|
||||
};
|
||||
|
||||
m::resource::response::chunked response
|
||||
{
|
||||
client, http::OK
|
||||
};
|
||||
|
||||
json::stack out
|
||||
{
|
||||
response.buf, response.flusher()
|
||||
};
|
||||
|
||||
json::stack::object top
|
||||
{
|
||||
out
|
||||
};
|
||||
|
||||
json::stack::object response_keys
|
||||
{
|
||||
top, "one_time_keys"
|
||||
};
|
||||
|
||||
for(const auto &[user_id, devices] : one_time_keys)
|
||||
{
|
||||
const m::user::room user_room
|
||||
{
|
||||
user_id
|
||||
};
|
||||
|
||||
json::stack::object response_user
|
||||
{
|
||||
response_keys, user_id
|
||||
};
|
||||
|
||||
for(const auto &[device_id_, algorithm_] : json::object(devices))
|
||||
{
|
||||
const json::string &algorithm{algorithm_};
|
||||
const json::string &device_id{device_id_};
|
||||
const auto match{[&device_id]
|
||||
(const string_view &state_key)
|
||||
{
|
||||
return state_key == device_id;
|
||||
}};
|
||||
|
||||
char buf[m::event::TYPE_MAX_SIZE];
|
||||
const string_view type{fmt::sprintf
|
||||
{
|
||||
buf, "ircd.device.one_time_key|%s",
|
||||
algorithm
|
||||
}};
|
||||
|
||||
const m::room::type events
|
||||
{
|
||||
user_room, type, { -1UL, -1L }, true
|
||||
};
|
||||
|
||||
json::stack::object response_device
|
||||
{
|
||||
response_user, device_id
|
||||
};
|
||||
|
||||
events.for_each([&response_device, &match]
|
||||
(const string_view &type, const auto &, const m::event::idx &event_idx)
|
||||
{
|
||||
if(!m::query(std::nothrow, event_idx, "state_key", match))
|
||||
return true;
|
||||
|
||||
m::get(std::nothrow, event_idx, "content", [&response_device, type]
|
||||
(const json::object &content)
|
||||
{
|
||||
const auto algorithm
|
||||
{
|
||||
split(type, '|').second
|
||||
};
|
||||
|
||||
json::stack::member
|
||||
{
|
||||
response_device, algorithm, json::object
|
||||
{
|
||||
content[""] // device quirk
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue