0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-12 13:01:07 +01:00

ircd:Ⓜ️:event: Fix signature interface regression; optimize call path.

This commit is contained in:
Jason Volk 2020-02-23 22:44:14 -08:00
parent a0af97ae3e
commit 8baaf366c4
4 changed files with 48 additions and 17 deletions

View file

@ -43,6 +43,7 @@ namespace ircd::m
id::event make_id(const event &, const string_view &version, id::event::buf &buf);
json::object hashes(const mutable_buffer &, const event &);
event signatures(const mutable_buffer &, const m::event &, const string_view &origin);
event signatures(const mutable_buffer &, const m::event &);
event essential(event, const mutable_buffer &content);
@ -58,6 +59,7 @@ namespace ircd::m
sha256::buf hash(const event &);
ed25519::sig sign(const event &, const ed25519::sk &);
ed25519::sig sign(const event &, const string_view &origin);
ed25519::sig sign(const event &);
}

View file

@ -211,9 +211,22 @@ ircd::m::event::signatures(const mutable_buffer &out,
return json::stringify(mutable_buffer{out}, sigs);
}
ircd::m::event
ircd::m::signatures(const mutable_buffer &out,
const m::event &event)
{
const string_view &origin
{
at<"origin"_>(event)
};
return signatures(out, event, origin);
}
ircd::m::event
ircd::m::signatures(const mutable_buffer &out_,
const m::event &event_)
const m::event &event_,
const string_view &origin)
{
thread_local char content[event::MAX_SIZE];
m::event event
@ -222,19 +235,14 @@ ircd::m::signatures(const mutable_buffer &out_,
};
thread_local char buf[event::MAX_SIZE];
const json::object &preimage
const string_view &preimage
{
stringify(buf, event)
};
const ed25519::sig sig
const auto &secret_key
{
sign(preimage)
};
const auto &origin
{
json::at<"origin"_>(event)
m::secret_key(my(origin))
};
const string_view public_key_id
@ -242,12 +250,22 @@ ircd::m::signatures(const mutable_buffer &out_,
m::public_key_id(my(origin))
};
thread_local char sigb64buf[b64encode_size(sizeof(sig))];
const json::member my_sig
const ed25519::sig my_sig
{
event::sign(preimage, secret_key)
};
static const auto sigb64bufsz
{
b64encode_size(sizeof(my_sig))
};
thread_local char sigb64buf[sigb64bufsz];
const json::member my_sig_member
{
origin, json::members
{
{ public_key_id, b64encode_unpadded(sigb64buf, sig) }
{ public_key_id, b64encode_unpadded(sigb64buf, my_sig) }
}
};
@ -255,9 +273,9 @@ ircd::m::signatures(const mutable_buffer &out_,
thread_local std::array<json::member, SIG_MAX> sigs;
size_t i(0);
sigs.at(i++) = my_sig;
sigs.at(i++) = my_sig_member;
for(const auto &[host, sig] : json::get<"signatures"_>(event_))
if(!my_host(json::string(host)))
if(json::string(host) != origin)
sigs.at(i++) = { host, sig };
event = event_;
@ -303,9 +321,16 @@ ircd::m::sign(const event &event)
{
const string_view &origin
{
json::at<"origin"_>(event)
at<"origin"_>(event)
};
return sign(event, origin);
}
ircd::ed25519::sig
ircd::m::sign(const event &event,
const string_view &origin)
{
const auto &secret_key
{
m::secret_key(my(origin))

View file

@ -110,11 +110,15 @@ put__invite(client &client,
};
check_event(request, event);
const m::user::id target
{
at<"state_key"_>(event)
};
thread_local char sigs[4_KiB];
const m::event signed_event
{
signatures(sigs, event)
signatures(sigs, event, target.host())
};
const json::strung revent

View file

@ -184,7 +184,7 @@ put__invite(client &client,
thread_local char sigs[4_KiB];
m::event signed_event
{
signatures(sigs, event)
signatures(sigs, event, target.host())
};
signed_event.event_id = event_id;