From 1add5349ac51a6271531a3438bed040aa0f2df6c Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 4 Oct 2019 13:21:56 -0700 Subject: [PATCH] ircd::m::homeserver::key: Add the verify_keys generation subroutine. --- include/ircd/m/homeserver.h | 3 ++ matrix/homeserver.cc | 75 +++++++++++++++++++++---------------- 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/include/ircd/m/homeserver.h b/include/ircd/m/homeserver.h index 6a6248851..3851ab9f9 100644 --- a/include/ircd/m/homeserver.h +++ b/include/ircd/m/homeserver.h @@ -95,6 +95,9 @@ struct ircd::m::homeserver::key /// Current ed25519:ident string std::string public_key_id; + /// Current verify_keys (json::object) (m::keys) + std::string verify_keys; + key(const struct opts &); key() = default; }; diff --git a/matrix/homeserver.cc b/matrix/homeserver.cc index 9393bbaa6..9b8d0f491 100644 --- a/matrix/homeserver.cc +++ b/matrix/homeserver.cc @@ -208,6 +208,7 @@ ircd::m::homeserver::homeserver(const struct opts *const &opts) if(primary == this && dbs::events && sequence(*dbs::events) == 0) bootstrap(*this); + m::keys::cache::set(key->verify_keys); signon(*this); } @@ -324,49 +325,59 @@ ircd::m::homeserver::key::key(const struct opts &opts) { trunc(public_key_b64, 8) } +,verify_keys{[this, &opts] +() -> std::string { -/* - const json::members verify_keys_ - {{ - string_view{m::self::public_key_id}, - { - { "key", m::self::public_key_b64 } - } - }}; - - m::keys my_key; - json::get<"server_name"_>(my_key) = my_host(); - json::get<"old_verify_keys"_>(my_key) = "{}"; - - //TODO: conf - json::get<"valid_until_ts"_>(my_key) = - ircd::time() + milliseconds(1000UL * 60 * 60 * 24 * 180).count(); - - const json::strung verify_keys{verify_keys_}; // must be on stack until my_keys serialized. - json::get<"verify_keys"_>(my_key) = verify_keys; - - const json::strung presig + const json::strung verify_keys { - my_key + json::members + { + { public_key_id, json::member + { + "key", public_key_b64 + }} + } + }; + + const time_t ts + { + //TODO: XXX + ircd::time() + (1000 * 60 * 60 * 24 * 7) + }; + + m::keys key; + json::get<"server_name"_>(key) = opts.origin; + json::get<"old_verify_keys"_>(key) = "{}"; + json::get<"verify_keys"_>(key) = verify_keys; + json::get<"valid_until_ts"_>(key) = ts; + json::strung ret + { + key }; const ed25519::sig sig { - m::self::secret_key.sign(const_buffer{presig}) + secret_key.sign(const_buffer(ret)) }; - char signature[256]; - const json::strung signatures{json::members + char buf[2][512]; + const json::object sigs { - { my_host(), + json::stringify(mutable_buffer(buf[0]), json::members { - { string_view{m::self::public_key_id}, b64encode_unpadded(signature, sig) } - }} - }}; + { opts.origin, { public_key_id, b64encode_unpadded(buf[1], sig) } } + }) + }; - json::get<"signatures"_>(my_key) = signatures; - keys::cache::set(json::strung{my_key}); -*/ + json::get<"signatures"_>(key) = sigs; + ret = json::strung + { + key + }; + + return ret; +}()} +{ } //