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
|
|
|
|
|
|
|
using namespace ircd;
|
|
|
|
|
2018-03-05 18:56:10 +01:00
|
|
|
mapi::header
|
|
|
|
IRCD_MODULE
|
2017-10-03 13:12:54 +02:00
|
|
|
{
|
2018-03-05 18:56:10 +01:00
|
|
|
"Federation 2.2.1.1 :Publishing Keys"
|
2017-10-03 13:12:54 +02:00
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource
|
2017-10-03 13:12:54 +02:00
|
|
|
server_resource
|
|
|
|
{
|
2018-03-05 18:56:10 +01:00
|
|
|
"/_matrix/key/v2/server/",
|
2017-10-03 13:12:54 +02:00
|
|
|
{
|
2017-12-12 21:26:39 +01:00
|
|
|
"federation 2.2.1.1: Publishing Keys",
|
2017-10-03 13:12:54 +02:00
|
|
|
resource::DIRECTORY,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-03-15 08:24:23 +01:00
|
|
|
conf::item<std::string>
|
|
|
|
occlusion_blacklist
|
|
|
|
{
|
|
|
|
{ "name", "ircd.key.occlude.blacklist" },
|
|
|
|
{ "default", "" },
|
|
|
|
};
|
|
|
|
|
|
|
|
conf::item<std::string>
|
|
|
|
occlusion_whitelist
|
|
|
|
{
|
|
|
|
{ "name", "ircd.key.occlude.whitelist" },
|
|
|
|
{ "default", "" },
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::response
|
2017-10-03 13:12:54 +02:00
|
|
|
handle_get(client &client,
|
2019-09-29 01:12:07 +02:00
|
|
|
const m::resource::request &request)
|
2017-10-03 13:12:54 +02:00
|
|
|
{
|
|
|
|
char key_id_buf[256];
|
|
|
|
const auto key_id
|
|
|
|
{
|
2020-10-16 06:54:19 +02:00
|
|
|
url::decode(key_id_buf, request.params)
|
2017-10-03 13:12:54 +02:00
|
|
|
};
|
|
|
|
|
2023-03-15 08:24:23 +01:00
|
|
|
const blackwhite::list acl
|
|
|
|
{
|
|
|
|
' ', occlusion_blacklist, occlusion_whitelist
|
|
|
|
};
|
|
|
|
|
|
|
|
char remote_buf[256];
|
|
|
|
const auto ip_str
|
|
|
|
{
|
|
|
|
occlusion_blacklist || occlusion_whitelist?
|
|
|
|
host(string(remote_buf, remote(client))):
|
|
|
|
string_view{}
|
|
|
|
};
|
|
|
|
|
|
|
|
const bool allow
|
|
|
|
{
|
|
|
|
acl(ip_str)
|
|
|
|
};
|
|
|
|
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
m::log, "%s requested key %s (%s)",
|
|
|
|
loghead(client),
|
|
|
|
key_id?: "*"_sv,
|
|
|
|
allow? "ALLOWED": "DENIED",
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!allow)
|
|
|
|
return m::resource::response
|
|
|
|
{
|
|
|
|
client, http::FORBIDDEN
|
|
|
|
};
|
|
|
|
|
2018-05-11 11:05:08 +02:00
|
|
|
m::keys::get(my_host(), key_id, [&client]
|
|
|
|
(const json::object &keys)
|
2017-10-03 13:12:54 +02:00
|
|
|
{
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::response
|
2018-05-11 11:05:08 +02:00
|
|
|
{
|
|
|
|
client, http::OK, keys
|
|
|
|
};
|
2017-10-03 13:12:54 +02:00
|
|
|
});
|
|
|
|
|
2018-05-11 11:05:08 +02:00
|
|
|
return {};
|
2017-10-03 13:12:54 +02:00
|
|
|
}
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::method
|
2018-03-05 18:56:10 +01:00
|
|
|
method_get
|
2017-10-03 13:12:54 +02:00
|
|
|
{
|
|
|
|
server_resource, "GET", handle_get
|
|
|
|
};
|