2019-09-28 23:17:54 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2019 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.
|
|
|
|
|
|
|
|
namespace ircd::m
|
|
|
|
{
|
|
|
|
extern conf::item<bool> x_matrix_verify_origin;
|
|
|
|
extern conf::item<bool> x_matrix_verify_destination;
|
|
|
|
|
2020-04-13 01:50:23 +02:00
|
|
|
static string_view authenticate_bridge(const resource::method &, const client &, resource::request &);
|
|
|
|
static user::id authenticate_user(const resource::method &, const client &, resource::request &);
|
2019-09-28 23:17:54 +02:00
|
|
|
static string_view authenticate_node(const resource::method &, const client &, resource::request &);
|
|
|
|
}
|
|
|
|
|
2020-12-10 11:52:15 +01:00
|
|
|
decltype(ircd::m::resource::log)
|
|
|
|
ircd::m::resource::log
|
|
|
|
{
|
|
|
|
"m.resource"
|
|
|
|
};
|
|
|
|
|
2019-09-28 23:17:54 +02:00
|
|
|
decltype(ircd::m::x_matrix_verify_origin)
|
|
|
|
ircd::m::x_matrix_verify_origin
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.x_matrix.verify_origin" },
|
|
|
|
{ "default", true },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::x_matrix_verify_origin)
|
|
|
|
ircd::m::x_matrix_verify_destination
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.x_matrix.verify_destination" },
|
|
|
|
{ "default", true },
|
|
|
|
};
|
|
|
|
|
2022-07-18 06:39:10 +02:00
|
|
|
//
|
|
|
|
// m::resource
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::m::resource::resource(const string_view &path)
|
|
|
|
:m::resource
|
|
|
|
{
|
|
|
|
path, {},
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::m::resource::resource(const string_view &path,
|
|
|
|
struct opts opts)
|
|
|
|
:ircd::resource
|
|
|
|
{
|
|
|
|
path_canonize(path_buf, path), opts
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::m::resource::~resource()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::m::resource::params(const string_view &path)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
const auto prefix_tokens
|
|
|
|
{
|
|
|
|
token_count(this->path, '/')
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto version
|
|
|
|
{
|
|
|
|
path_version(path)
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto params_after
|
|
|
|
{
|
|
|
|
prefix_tokens? prefix_tokens - 1 + bool(version): 0
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto ret
|
|
|
|
{
|
|
|
|
tokens_after(path, '/', params_after)
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::resource &
|
|
|
|
ircd::m::resource::route(const string_view &path)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
thread_local char canon_buf[1024];
|
|
|
|
const string_view canon_path
|
|
|
|
{
|
|
|
|
path_canonize(canon_buf, path)
|
|
|
|
};
|
|
|
|
|
|
|
|
return mutable_cast(ircd::resource::route(canon_path));
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::m::resource::path_canonize(const mutable_buffer &buf,
|
|
|
|
const string_view &path)
|
|
|
|
{
|
|
|
|
const auto version
|
|
|
|
{
|
|
|
|
path_version(path)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!version)
|
|
|
|
return path;
|
|
|
|
|
|
|
|
const auto &[before, after]
|
|
|
|
{
|
|
|
|
tokens_split(path, '/', 2, 1)
|
|
|
|
};
|
|
|
|
|
|
|
|
mutable_buffer out{buf};
|
|
|
|
consume(out, copy(out, '/'));
|
|
|
|
consume(out, copy(out, before));
|
|
|
|
if(likely(after))
|
|
|
|
{
|
|
|
|
consume(out, copy(out, '/'));
|
|
|
|
consume(out, copy(out, after));
|
|
|
|
}
|
|
|
|
|
|
|
|
return string_view
|
|
|
|
{
|
|
|
|
data(buf), data(out)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::m::resource::path_version(const string_view &path)
|
|
|
|
{
|
|
|
|
const auto version
|
|
|
|
{
|
|
|
|
token(path, '/', 2, {})
|
|
|
|
};
|
|
|
|
|
2022-07-30 02:35:58 +02:00
|
|
|
const bool is_version
|
2022-07-18 06:39:10 +02:00
|
|
|
{
|
|
|
|
true
|
|
|
|
&& version.size() >= 2
|
|
|
|
&& (version[0] == 'v' || version[0] == 'r')
|
|
|
|
&& (version[1] >= '0' && version[1] <= '9')
|
|
|
|
};
|
|
|
|
|
2022-07-30 02:35:58 +02:00
|
|
|
const bool pass
|
|
|
|
{
|
|
|
|
false
|
|
|
|
|| is_version
|
|
|
|
|| version == "unstable"
|
|
|
|
};
|
|
|
|
|
2022-07-18 06:39:10 +02:00
|
|
|
return pass? version: string_view{};
|
|
|
|
}
|
|
|
|
|
2019-09-28 23:17:54 +02:00
|
|
|
//
|
|
|
|
// m::resource::method
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::m::resource::method::method(m::resource &resource,
|
|
|
|
const string_view &name,
|
|
|
|
handler function,
|
|
|
|
struct opts opts)
|
|
|
|
:ircd::resource::method
|
|
|
|
{
|
|
|
|
resource,
|
|
|
|
name,
|
|
|
|
std::bind(&method::handle, this, ph::_1, ph::_2),
|
|
|
|
std::move(opts),
|
|
|
|
}
|
|
|
|
,function
|
|
|
|
{
|
|
|
|
std::move(function)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::m::resource::method::~method()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::resource::response
|
|
|
|
ircd::m::resource::method::handle(client &client,
|
|
|
|
ircd::resource::request &request_)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
m::resource::request request
|
|
|
|
{
|
|
|
|
*this, client, request_
|
|
|
|
};
|
|
|
|
|
2020-12-10 11:52:15 +01:00
|
|
|
const string_view &ident
|
|
|
|
{
|
|
|
|
request.bridge_id?:
|
|
|
|
request.node_id?:
|
|
|
|
request.user_id?:
|
|
|
|
string_view{}
|
|
|
|
};
|
|
|
|
|
|
|
|
if(ident)
|
|
|
|
log::debug
|
|
|
|
{
|
2022-07-18 06:39:10 +02:00
|
|
|
log, "%s %s %s %s `%s'",
|
2023-02-09 19:12:11 +01:00
|
|
|
loghead(client),
|
2020-12-10 11:52:15 +01:00
|
|
|
ident,
|
|
|
|
request.head.method,
|
2022-07-18 06:39:10 +02:00
|
|
|
request.version?: "??"_sv,
|
2020-12-10 11:52:15 +01:00
|
|
|
request.head.path,
|
|
|
|
};
|
|
|
|
|
|
|
|
const bool cached_error
|
|
|
|
{
|
|
|
|
request.node_id
|
|
|
|
&& fed::errant(request.node_id)
|
|
|
|
};
|
|
|
|
|
2020-04-23 12:50:03 +02:00
|
|
|
// If we have an error cached from previously not being able to
|
|
|
|
// contact this origin we can clear that now that they're alive.
|
2020-12-10 11:52:15 +01:00
|
|
|
if(cached_error)
|
2019-09-28 23:17:54 +02:00
|
|
|
{
|
2020-04-23 12:50:03 +02:00
|
|
|
m::burst::opts opts;
|
|
|
|
m::burst::burst
|
|
|
|
{
|
|
|
|
request.node_id, opts
|
|
|
|
};
|
2019-09-28 23:17:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return function(client, request);
|
|
|
|
}
|
|
|
|
catch(const json::print_error &e)
|
|
|
|
{
|
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
http::INTERNAL_SERVER_ERROR, "M_NOT_JSON",
|
2023-02-18 02:22:53 +01:00
|
|
|
"Generator Protection :%s",
|
2019-09-28 23:17:54 +02:00
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
catch(const json::not_found &e)
|
|
|
|
{
|
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
http::BAD_REQUEST, "M_BAD_JSON",
|
2023-02-18 02:22:53 +01:00
|
|
|
"Required JSON field :%s",
|
2019-09-28 23:17:54 +02:00
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
catch(const json::error &e)
|
|
|
|
{
|
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
http::BAD_REQUEST, "M_NOT_JSON",
|
|
|
|
"%s",
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
catch(const ctx::timeout &e)
|
|
|
|
{
|
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
http::BAD_GATEWAY, "M_REQUEST_TIMEOUT",
|
|
|
|
"%s",
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// resource::request
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::m::resource::request::request(const method &method,
|
|
|
|
const client &client,
|
|
|
|
ircd::resource::request &r)
|
|
|
|
:ircd::resource::request
|
|
|
|
{
|
|
|
|
r
|
|
|
|
}
|
2022-07-18 06:39:10 +02:00
|
|
|
,version
|
|
|
|
{
|
|
|
|
path_version(head.path)
|
|
|
|
}
|
2020-04-12 23:27:32 +02:00
|
|
|
,authorization
|
2019-09-28 23:17:54 +02:00
|
|
|
{
|
2020-04-12 23:27:32 +02:00
|
|
|
split(head.authorization, ' ')
|
|
|
|
}
|
|
|
|
,access_token
|
|
|
|
{
|
|
|
|
iequals(authorization.first, "Bearer"_sv)?
|
|
|
|
authorization.second:
|
|
|
|
query["access_token"]
|
|
|
|
}
|
|
|
|
,x_matrix
|
|
|
|
{
|
|
|
|
!access_token && iequals(authorization.first, "X-Matrix"_sv)?
|
|
|
|
m::request::x_matrix{authorization.first, authorization.second}:
|
|
|
|
m::request::x_matrix{}
|
2019-09-28 23:17:54 +02:00
|
|
|
}
|
|
|
|
,node_id
|
|
|
|
{
|
|
|
|
// Server X-Matrix header verified here. Similar to client auth, origin
|
|
|
|
// which has been authed is referenced in the client.request. If the method
|
|
|
|
// requires, and auth fails or not provided, this function throws.
|
|
|
|
// Otherwise it returns a string_view of the origin name in
|
2020-04-12 23:55:54 +02:00
|
|
|
// request.node_id, or an empty string_view if an origin was not
|
2019-09-28 23:17:54 +02:00
|
|
|
// apropos for this request (i.e a client request rather than federation).
|
|
|
|
authenticate_node(method, client, *this)
|
|
|
|
}
|
|
|
|
,user_id
|
|
|
|
{
|
|
|
|
// Client access token verified here. On success, user_id owning the token
|
2020-04-12 23:55:54 +02:00
|
|
|
// is copied into the request structure. On failure, the method is
|
2019-09-28 23:17:54 +02:00
|
|
|
// checked to see if it requires authentication and if so, this throws.
|
|
|
|
authenticate_user(method, client, *this)
|
|
|
|
}
|
2020-04-13 01:50:23 +02:00
|
|
|
,bridge_id
|
|
|
|
{
|
|
|
|
// Application service access token verified here. Note that on success
|
|
|
|
// this function will set the user_id as well as the bridge_id.
|
|
|
|
authenticate_bridge(method, client, *this)
|
|
|
|
}
|
2019-09-28 23:17:54 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Authenticate a client based on access_token either in the query string or
|
|
|
|
/// in the Authentication bearer header. If a token is found the user_id owning
|
|
|
|
/// the token is copied into the request. If it is not found or it is invalid
|
|
|
|
/// then the method being requested is checked to see if it is required. If so
|
2020-04-13 01:50:23 +02:00
|
|
|
/// the appropriate exception is thrown. Note that if the access_token belongs
|
|
|
|
/// to a bridge (application service), the bridge_id is set accordingly.
|
|
|
|
ircd::m::user::id
|
2019-09-28 23:17:54 +02:00
|
|
|
ircd::m::authenticate_user(const resource::method &method,
|
|
|
|
const client &client,
|
|
|
|
resource::request &request)
|
|
|
|
{
|
2023-03-03 04:23:34 +01:00
|
|
|
static const auto auth_requires
|
|
|
|
{0
|
|
|
|
| resource::method::REQUIRES_AUTH
|
|
|
|
| resource::method::REQUIRES_OPER
|
|
|
|
};
|
|
|
|
|
2019-09-28 23:17:54 +02:00
|
|
|
assert(method.opts);
|
|
|
|
const auto requires_auth
|
|
|
|
{
|
2023-03-03 04:23:34 +01:00
|
|
|
method.opts->flags & auth_requires
|
2019-09-28 23:17:54 +02:00
|
|
|
};
|
|
|
|
|
2020-04-13 01:50:23 +02:00
|
|
|
if(!requires_auth && !request.access_token)
|
|
|
|
return {};
|
2020-04-12 23:27:32 +02:00
|
|
|
|
2020-04-13 01:50:23 +02:00
|
|
|
// Note that we still try to auth a token and obtain a user_id here even
|
|
|
|
// if the endpoint does not require auth; an auth'ed user may enjoy
|
|
|
|
// additional functionality if credentials provided.
|
|
|
|
if(requires_auth && !request.access_token)
|
2019-09-28 23:17:54 +02:00
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
http::UNAUTHORIZED, "M_MISSING_TOKEN",
|
|
|
|
"Credentials for this method are required but missing."
|
|
|
|
};
|
|
|
|
|
2020-04-13 01:50:23 +02:00
|
|
|
// Belay authentication to authenticate_bridge().
|
|
|
|
if(startswith(request.access_token, "bridge_"))
|
|
|
|
return {};
|
|
|
|
|
|
|
|
const m::room::id::buf tokens_room_id
|
|
|
|
{
|
|
|
|
"tokens", origin(my())
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::room::state tokens
|
|
|
|
{
|
|
|
|
tokens_room_id
|
|
|
|
};
|
|
|
|
|
|
|
|
const event::idx event_idx
|
|
|
|
{
|
|
|
|
tokens.get(std::nothrow, "ircd.access_token", request.access_token)
|
|
|
|
};
|
|
|
|
|
|
|
|
// The sender of the token is the user being authenticated.
|
|
|
|
const string_view sender
|
2019-09-28 23:17:54 +02:00
|
|
|
{
|
2020-04-13 01:50:23 +02:00
|
|
|
m::get(std::nothrow, event_idx, "sender", request.id_buf)
|
2019-09-28 23:17:54 +02:00
|
|
|
};
|
|
|
|
|
2020-04-13 01:50:23 +02:00
|
|
|
// Note that if the endpoint does not require auth and we were not
|
|
|
|
// successful in authenticating the provided token: we do not throw here;
|
|
|
|
// instead we continue as if no token was provided, and no user_id will
|
|
|
|
// be known to the requested endpoint.
|
|
|
|
if(requires_auth && !sender)
|
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
http::UNAUTHORIZED, "M_UNKNOWN_TOKEN",
|
|
|
|
"Credentials for this method are required but invalid."
|
|
|
|
};
|
|
|
|
|
2023-03-03 04:23:34 +01:00
|
|
|
// Operator access required for method.
|
|
|
|
if(method.opts->flags & resource::method::REQUIRES_OPER)
|
|
|
|
if(!is_oper(m::user::id(sender)))
|
|
|
|
throw m::ACCESS_DENIED
|
|
|
|
{
|
|
|
|
"You are not an operator."
|
|
|
|
};
|
|
|
|
|
2020-04-13 01:50:23 +02:00
|
|
|
return sender;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Authenticate an application service (bridge)
|
|
|
|
ircd::string_view
|
|
|
|
ircd::m::authenticate_bridge(const resource::method &method,
|
|
|
|
const client &client,
|
|
|
|
resource::request &request)
|
|
|
|
{
|
|
|
|
// Real user was already authenticated; not a bridge.
|
|
|
|
if(request.user_id)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
// No attempt at authenticating as a bridge; not a bridge.
|
|
|
|
if(!startswith(request.access_token, "bridge_"))
|
|
|
|
return {};
|
|
|
|
|
|
|
|
const m::room::id::buf tokens_room_id
|
2019-10-01 05:50:58 +02:00
|
|
|
{
|
|
|
|
"tokens", origin(my())
|
|
|
|
};
|
|
|
|
|
2019-09-28 23:17:54 +02:00
|
|
|
const m::room::state tokens
|
|
|
|
{
|
2020-04-13 01:50:23 +02:00
|
|
|
tokens_room_id
|
|
|
|
};
|
|
|
|
|
|
|
|
const event::idx event_idx
|
|
|
|
{
|
|
|
|
tokens.get(std::nothrow, "ircd.access_token", request.access_token)
|
2019-09-28 23:17:54 +02:00
|
|
|
};
|
|
|
|
|
2020-04-13 01:50:23 +02:00
|
|
|
// The sender of the token is the bridge's user_id, where the bridge_id
|
|
|
|
// is the localpart, but none of this is a puppetting/target user_id.
|
|
|
|
const string_view sender
|
2019-09-28 23:17:54 +02:00
|
|
|
{
|
2020-04-13 01:50:23 +02:00
|
|
|
m::get(std::nothrow, event_idx, "sender", request.id_buf)
|
|
|
|
};
|
2019-09-28 23:17:54 +02:00
|
|
|
|
2020-04-13 01:50:23 +02:00
|
|
|
// Note that unlike authenticate_user, if an as_token was proffered but is
|
|
|
|
// not valid, there is no possible fallback to unauthenticated mode and
|
|
|
|
// this must throw here.
|
|
|
|
if(!sender)
|
2019-09-28 23:17:54 +02:00
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
http::UNAUTHORIZED, "M_UNKNOWN_TOKEN",
|
|
|
|
"Credentials for this method are required but invalid."
|
|
|
|
};
|
|
|
|
|
2020-04-13 01:50:23 +02:00
|
|
|
// Find the user_id the bridge wants to masquerade as.
|
|
|
|
const string_view puppet_user_id
|
|
|
|
{
|
|
|
|
request.query["user_id"]
|
|
|
|
};
|
|
|
|
|
|
|
|
// Set the user credentials for the request at the discretion of the
|
|
|
|
// bridge. If the bridge did not supply a user_id then we set the value
|
|
|
|
// to the bridge's own agency. Note that we urldecode into the id_buf
|
|
|
|
// after the bridge_user_id; care not to overwrite it.
|
|
|
|
{
|
|
|
|
mutable_buffer buf(request.id_buf);
|
|
|
|
request.user_id = puppet_user_id?
|
|
|
|
url::decode(buf + size(sender), puppet_user_id):
|
|
|
|
sender;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return only the localname (that's the localpart not including sigil).
|
|
|
|
return m::user::id(sender).localname();
|
2019-09-28 23:17:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::m::authenticate_node(const resource::method &method,
|
|
|
|
const client &client,
|
|
|
|
resource::request &request)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
assert(method.opts);
|
|
|
|
const auto required
|
|
|
|
{
|
|
|
|
method.opts->flags & resource::method::VERIFY_ORIGIN
|
|
|
|
};
|
|
|
|
|
|
|
|
const bool supplied
|
|
|
|
{
|
2020-04-12 23:55:54 +02:00
|
|
|
!empty(request.x_matrix.origin)
|
2019-09-28 23:17:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if(!required && !supplied)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
if(required && !supplied)
|
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
http::UNAUTHORIZED, "M_MISSING_AUTHORIZATION",
|
2023-02-18 02:22:53 +01:00
|
|
|
"Required X-Matrix Authorization was not supplied."
|
2019-09-28 23:17:54 +02:00
|
|
|
};
|
|
|
|
|
2023-02-15 18:00:01 +01:00
|
|
|
const auto supplied_dest
|
2022-06-30 19:32:19 +02:00
|
|
|
{
|
2023-02-15 18:00:01 +01:00
|
|
|
request.x_matrix.destination
|
2022-06-30 19:32:19 +02:00
|
|
|
};
|
|
|
|
|
2023-02-15 18:00:01 +01:00
|
|
|
if(x_matrix_verify_destination && supplied_dest && !m::self::host(supplied_dest))
|
2022-06-30 19:32:19 +02:00
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
http::UNAUTHORIZED, "M_NOT_MY_DESTINATION",
|
2019-09-28 23:17:54 +02:00
|
|
|
"The X-Matrix Authorization destination '%s' is not recognized here.",
|
2023-02-15 18:00:01 +01:00
|
|
|
supplied_dest,
|
2019-09-28 23:17:54 +02:00
|
|
|
};
|
|
|
|
|
2023-02-15 18:00:01 +01:00
|
|
|
const auto destination
|
|
|
|
{
|
|
|
|
supplied_dest?: origin(my())
|
|
|
|
};
|
|
|
|
|
2019-09-28 23:17:54 +02:00
|
|
|
const m::request object
|
|
|
|
{
|
2020-04-12 23:55:54 +02:00
|
|
|
request.x_matrix.origin,
|
2023-02-15 18:00:01 +01:00
|
|
|
destination,
|
2020-04-12 23:27:32 +02:00
|
|
|
method.name,
|
|
|
|
request.head.uri,
|
|
|
|
request.content
|
2019-09-28 23:17:54 +02:00
|
|
|
};
|
|
|
|
|
2020-04-12 23:55:54 +02:00
|
|
|
if(x_matrix_verify_origin && !object.verify(request.x_matrix.key, request.x_matrix.sig))
|
2019-09-28 23:17:54 +02:00
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
http::FORBIDDEN, "M_INVALID_SIGNATURE",
|
|
|
|
"The X-Matrix Authorization is invalid."
|
|
|
|
};
|
|
|
|
|
2020-04-12 23:55:54 +02:00
|
|
|
return request.x_matrix.origin;
|
2019-09-28 23:17:54 +02:00
|
|
|
}
|
|
|
|
catch(const m::error &)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
2020-04-13 00:15:19 +02:00
|
|
|
thread_local char rembuf[128];
|
2019-09-28 23:17:54 +02:00
|
|
|
log::derror
|
|
|
|
{
|
2023-02-18 02:22:53 +01:00
|
|
|
resource::log, "X-Matrix Authorization from %s :%s",
|
2020-04-13 00:15:19 +02:00
|
|
|
string(rembuf, remote(client)),
|
2019-09-28 23:17:54 +02:00
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
http::UNAUTHORIZED, "M_UNKNOWN_ERROR",
|
2023-02-18 02:22:53 +01:00
|
|
|
"An error has prevented authorization :%s",
|
2019-09-28 23:17:54 +02:00
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|