2018-02-04 03:22:01 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
2017-10-03 13:12:54 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_M_KEYS_H
|
|
|
|
|
|
|
|
namespace ircd::m
|
|
|
|
{
|
2017-11-25 23:30:03 +01:00
|
|
|
struct keys;
|
2018-05-11 11:05:08 +02:00
|
|
|
|
2019-06-24 01:08:32 +02:00
|
|
|
bool expired(const m::keys &);
|
2019-05-01 23:19:08 +02:00
|
|
|
bool verify(const m::keys &, std::nothrow_t) noexcept;
|
|
|
|
void verify(const m::keys &);
|
2019-06-25 15:59:42 +02:00
|
|
|
|
|
|
|
std::ostream &pretty(std::ostream &, const m::keys &);
|
|
|
|
std::ostream &pretty_oneline(std::ostream &, const m::keys &);
|
2017-10-03 13:12:54 +02:00
|
|
|
}
|
|
|
|
|
2017-11-25 23:30:03 +01:00
|
|
|
/// Contains the public keys and proof of identity for a remote server.
|
|
|
|
///
|
|
|
|
/// A user who wishes to verify a signature from a remote server must have
|
|
|
|
/// the name of the server (origin) and the key_id. Calling the appropriate
|
|
|
|
/// static function of this class will attempt to fetch the key from the db
|
|
|
|
/// or make network requests, with valid response being saved to the db. Keys
|
|
|
|
/// are thus managed internally so the user doesn't supply a buffer or ever
|
|
|
|
/// construct this object; instead this object backed by internal db data is
|
|
|
|
/// presented in the supplied synchronous closure.
|
|
|
|
///
|
2017-10-03 13:12:54 +02:00
|
|
|
/// 2.2.1.1 Publishing Keys
|
|
|
|
///
|
|
|
|
/// Key Type, Description
|
|
|
|
/// server_name String, DNS name of the homeserver.
|
|
|
|
/// verify_keys Object, Public keys of the homeserver for verifying digital signatures.
|
|
|
|
/// old_verify_keys Object, The public keys that the server used to use and when it stopped using them.
|
|
|
|
/// signatures Object, Digital signatures for this object signed using the verify_keys.
|
|
|
|
/// valid_until_ts Integer, POSIX timestamp when the list of valid keys should be refreshed.
|
|
|
|
///
|
2017-11-25 23:30:03 +01:00
|
|
|
struct ircd::m::keys
|
2017-10-03 13:12:54 +02:00
|
|
|
:json::tuple
|
|
|
|
<
|
|
|
|
json::property<name::old_verify_keys, json::object>,
|
2019-06-25 16:00:46 +02:00
|
|
|
json::property<name::server_name, json::string>,
|
2017-10-03 13:12:54 +02:00
|
|
|
json::property<name::signatures, json::object>,
|
2019-12-21 23:24:58 +01:00
|
|
|
json::property<name::tls_fingerprints, json::array>,
|
2017-10-03 13:12:54 +02:00
|
|
|
json::property<name::valid_until_ts, time_t>,
|
|
|
|
json::property<name::verify_keys, json::object>
|
|
|
|
>
|
|
|
|
{
|
2019-06-22 01:41:43 +02:00
|
|
|
struct cache;
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
using queries = vector_view<const fed::key::server_key>; // <server, key_id>
|
2018-05-11 11:05:08 +02:00
|
|
|
using closure = std::function<void (const json::object &)>;
|
|
|
|
using closure_bool = std::function<bool (const json::object &)>;
|
2017-10-03 13:12:54 +02:00
|
|
|
|
2019-07-23 04:49:21 +02:00
|
|
|
static bool get(const queries &, const closure_bool &);
|
2020-04-22 03:29:44 +02:00
|
|
|
static bool get(const string_view &server_name, const closure &);
|
|
|
|
static bool get(const string_view &server_name, const string_view &key_id, const closure &);
|
|
|
|
static bool query(const string_view &query_server, const queries &, const closure_bool &);
|
2019-07-23 05:27:30 +02:00
|
|
|
static size_t fetch(const queries &);
|
2017-10-16 06:58:23 +02:00
|
|
|
|
2017-10-03 13:12:54 +02:00
|
|
|
using super_type::tuple;
|
|
|
|
using super_type::operator=;
|
|
|
|
};
|
2019-06-22 01:41:43 +02:00
|
|
|
|
|
|
|
struct ircd::m::keys::cache
|
|
|
|
{
|
2019-06-24 00:32:22 +02:00
|
|
|
static bool for_each(const string_view &server, const closure_bool &);
|
2019-08-28 01:10:15 +02:00
|
|
|
static bool has(const string_view &server, const string_view &key_id);
|
2019-06-22 01:41:43 +02:00
|
|
|
static bool get(const string_view &server, const string_view &key_id, const closure &);
|
|
|
|
static size_t set(const json::object &keys);
|
|
|
|
};
|