0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-28 17:52:54 +01:00

ircd:Ⓜ️:user::keys: Consolidate cross signing keys update.

This commit is contained in:
Jason Volk 2023-04-27 17:03:22 -07:00
parent f9aeae5516
commit bbed809975
4 changed files with 67 additions and 64 deletions

View file

@ -36,6 +36,8 @@ struct ircd::m::user::keys
void cross_self(json::stack::object &) const; void cross_self(json::stack::object &) const;
void cross_user(json::stack::object &) const; void cross_user(json::stack::object &) const;
void update(const m::signing_key_update &) const;
keys(const m::user &user) keys(const m::user &user)
:user_room{user} :user_room{user}
{} {}

View file

@ -87,6 +87,57 @@ catch(const std::exception &e)
}; };
} }
void
ircd::m::user::keys::update(const m::signing_key_update &sku)
const
{
const m::user::id &user_id
{
json::get<"user_id"_>(sku)
};
const m::user::room room
{
user_id
};
const json::object &msk
{
json::get<"master_key"_>(sku)
};
const auto cross_master_id
{
json::get<"master_key"_>(sku)?
m::send(room, user_id, "ircd.cross_signing.master", "", msk):
m::event::id::buf{}
};
const json::object &ssk
{
json::get<"self_signing_key"_>(sku)
};
const auto cross_self_id
{
ssk?
m::send(room, user_id, "ircd.cross_signing.self", "", ssk):
m::event::id::buf{}
};
const json::object &usk
{
json::get<"user_signing_key"_>(sku)
};
const auto cross_user_id
{
usk && my(user_id)?
m::send(room, user_id, "ircd.cross_signing.user", "", usk):
m::event::id::buf{}
};
}
void void
ircd::m::user::keys::device(json::stack::object &out, ircd::m::user::keys::device(json::stack::object &out,
const string_view &device_id) const string_view &device_id)

View file

@ -66,52 +66,26 @@ ircd::m::post_keys_device_signing_upload(client &client,
auth["password"] auth["password"]
}; };
const m::user::room room const m::user user
{ {
request.user_id request.user_id
}; };
if(!room.user.is_password(password)) if(!user.is_password(password))
throw m::ACCESS_DENIED throw m::ACCESS_DENIED
{ {
"Incorrect password." "Incorrect password."
}; };
const json::object &msk const m::user::keys keys
{ {
request["master_key"] user
}; };
const auto master_id m::signing_key_update sku{request};
{ json::get<"user_id"_>(sku) = request.user_id;
msk?
send(room, request.user_id, "ircd.cross_signing.master", "", msk):
event::id::buf{}
};
const json::object &ssk keys.update(sku);
{
request["self_signing_key"]
};
const auto self_signing_id
{
ssk?
send(room, request.user_id, "ircd.cross_signing.self", "", ssk):
event::id::buf{}
};
const json::object &usk
{
request["user_signing_key"]
};
const auto user_signing_id
{
usk?
send(room, request.user_id, "ircd.cross_signing.user", "", usk):
event::id::buf{}
};
return resource::response return resource::response
{ {

View file

@ -56,53 +56,29 @@ try
if(user_id.host() != at<"origin"_>(event)) if(user_id.host() != at<"origin"_>(event))
return; return;
const json::object &msk if(!exists(user_id))
{
json::get<"master_key"_>(update)
};
const m::user::room room
{
user_id
};
if(!exists(room))
{ {
log::derror log::derror
{ {
m::log, "Refusing signing key update for unknown %s", m::log, "Refusing signing key update for unknown %s",
json::get<"user_id"_>(update), string_view{user_id},
}; };
return; return;
} }
const auto master_id const m::user::keys keys
{ {
msk? user_id
send(room, user_id, "ircd.cross_signing.master", "", msk):
m::event::id::buf{}
}; };
const json::object &ssk keys.update(update);
{
json::get<"self_signing_key"_>(update)
};
const auto self_id
{
ssk?
send(room, user_id, "ircd.cross_signing.self", "", ssk):
m::event::id::buf{}
};
log::info log::info
{ {
m::log, "Signing key update from :%s by %s master:%s self:%s", m::log, "Signing key update from '%s' for %s",
json::get<"origin"_>(event), json::get<"origin"_>(event),
json::get<"user_id"_>(update), json::get<"user_id"_>(update),
string_view{master_id},
string_view{self_id},
}; };
} }
catch(const ctx::interrupted &e) catch(const ctx::interrupted &e)
@ -113,7 +89,7 @@ catch(const std::exception &e)
{ {
log::derror log::derror
{ {
m::log, "m.signing_key_update from %s :%s", m::log, "m.signing_key_update from '%s' :%s",
json::get<"origin"_>(event), json::get<"origin"_>(event),
e.what(), e.what(),
}; };