From 0b3ec2b47674c0b1579be0a58c0487723bc1d1b6 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 20 Mar 2018 18:46:20 -0700 Subject: [PATCH] ircd::m: Convenience to close over decoded ed25519::pk directly. --- include/ircd/m/keys.h | 2 ++ ircd/m/m.cc | 20 ++++++++++++++++++++ ircd/m/request.cc | 33 ++++++++++++++------------------- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/include/ircd/m/keys.h b/include/ircd/m/keys.h index 472a4191d..9e0babc6c 100644 --- a/include/ircd/m/keys.h +++ b/include/ircd/m/keys.h @@ -65,12 +65,14 @@ struct ircd::m::keys public: using closure = std::function; using key_closure = std::function; // remember to unquote()!!! + using ed25519_closure = std::function; static void get(const string_view &server_name, const string_view &key_id, const string_view &query_server, const closure &); static void get(const string_view &server_name, const closure &); static void get(const string_view &server_name, const string_view &key_id, const closure &); static void get(const string_view &server_name, const string_view &key_id, const key_closure &); + static void get(const string_view &server_name, const string_view &key_id, const ed25519_closure &); using super_type::tuple; using super_type::operator=; diff --git a/ircd/m/m.cc b/ircd/m/m.cc index 62b0f05aa..274c6436e 100644 --- a/ircd/m/m.cc +++ b/ircd/m/m.cc @@ -353,6 +353,26 @@ std::string ircd::m::self::tls_cert_der_sha256_b64 {}; +void +ircd::m::keys::get(const string_view &server_name, + const string_view &key_id, + const ed25519_closure &closure) +{ + get(server_name, key_id, key_closure{[&closure] + (const string_view &keyb64) + { + const ed25519::pk pk + { + [&keyb64](auto &buf) + { + b64decode(buf, unquote(keyb64)); + } + }; + + closure(pk); + }}); +} + void ircd::m::keys::get(const string_view &server_name, const string_view &key_id, diff --git a/ircd/m/request.cc b/ircd/m/request.cc index 4962964c0..dc5f9ce18 100644 --- a/ircd/m/request.cc +++ b/ircd/m/request.cc @@ -154,35 +154,30 @@ const bool ircd::m::request::verify(const string_view &key, - const string_view &sig) + const string_view &sig_) const { - const ed25519::sig _sig + const ed25519::sig sig { - [&sig](auto &buf) + [&sig_](auto &buf) { - b64decode(buf, sig); + b64decode(buf, sig_); } }; - const ed25519::pk pk + const auto &origin { - [this, &key](auto &buf) - { - const auto &origin - { - unquote(at<"origin"_>(*this)) - }; - - m::keys::get(origin, key, [&buf] - (const string_view &key) - { - b64decode(buf, unquote(key)); - }); - } + unquote(at<"origin"_>(*this)) }; - return verify(pk, _sig); + bool verified{false}; + m::keys::get(origin, key, [this, &verified, &sig] + (const ed25519::pk &pk) + { + verified = verify(pk, sig); + }); + + return verified; } bool