2020-03-29 01:10:32 +01:00
|
|
|
// The Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) The Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2020 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
|
|
|
|
{
|
|
|
|
static resource::response get_room_keys_version(client &, const resource::request &);
|
|
|
|
extern resource::method room_keys_version_get;
|
|
|
|
|
|
|
|
static resource::response put_room_keys_version(client &, const resource::request &);
|
|
|
|
extern resource::method room_keys_version_put;
|
|
|
|
|
|
|
|
static resource::response delete_room_keys_version(client &, const resource::request &);
|
|
|
|
extern resource::method room_keys_version_delete;
|
|
|
|
|
|
|
|
static resource::response post_room_keys_version(client &, const resource::request &);
|
|
|
|
extern resource::method room_keys_version_post;
|
|
|
|
|
|
|
|
extern resource room_keys_version;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::mapi::header
|
|
|
|
IRCD_MODULE
|
|
|
|
{
|
|
|
|
"Client (undocumented) :e2e Room Keys Version"
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::room_keys_version)
|
|
|
|
ircd::m::room_keys_version
|
|
|
|
{
|
|
|
|
"/_matrix/client/unstable/room_keys/version",
|
|
|
|
{
|
|
|
|
"(undocumented) Room Keys Version",
|
|
|
|
resource::DIRECTORY,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// POST
|
|
|
|
//
|
|
|
|
|
|
|
|
decltype(ircd::m::room_keys_version_post)
|
|
|
|
ircd::m::room_keys_version_post
|
|
|
|
{
|
|
|
|
room_keys_version, "POST", post_room_keys_version,
|
|
|
|
{
|
2021-02-19 15:44:27 +01:00
|
|
|
room_keys_version_post.REQUIRES_AUTH |
|
|
|
|
room_keys_version_post.RATE_LIMITED
|
2020-03-29 01:10:32 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ircd::m::resource::response
|
|
|
|
ircd::m::post_room_keys_version(client &client,
|
|
|
|
const resource::request &request)
|
|
|
|
{
|
2020-03-31 02:16:25 +02:00
|
|
|
const json::string &algorithm
|
|
|
|
{
|
|
|
|
request["algorithm"]
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::object &auth_data
|
|
|
|
{
|
|
|
|
request["auth_data"]
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::string &public_key
|
|
|
|
{
|
|
|
|
auth_data["public_key"]
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::object &signatures
|
|
|
|
{
|
|
|
|
auth_data["signatures"]
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::device::id::buf device_id
|
|
|
|
{
|
2020-04-02 02:14:51 +02:00
|
|
|
m::user::tokens::device(request.access_token)
|
2020-03-31 02:16:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const m::user::room user_room
|
|
|
|
{
|
|
|
|
request.user_id
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto event_id
|
|
|
|
{
|
|
|
|
m::send(user_room, request.user_id, "ircd.room_keys.version", json::object
|
|
|
|
{
|
|
|
|
request
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::value version
|
|
|
|
{
|
|
|
|
lex_cast(m::index(event_id)), json::STRING
|
|
|
|
};
|
2020-03-29 01:10:32 +01:00
|
|
|
|
|
|
|
return resource::response
|
|
|
|
{
|
2020-03-31 02:16:25 +02:00
|
|
|
client, json::members
|
|
|
|
{
|
|
|
|
{ "version", version }
|
|
|
|
}
|
2020-03-29 01:10:32 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// DELETE
|
|
|
|
//
|
|
|
|
|
|
|
|
decltype(ircd::m::room_keys_version_delete)
|
|
|
|
ircd::m::room_keys_version_delete
|
|
|
|
{
|
|
|
|
room_keys_version, "DELETE", delete_room_keys_version,
|
|
|
|
{
|
2021-02-19 15:44:27 +01:00
|
|
|
room_keys_version_delete.REQUIRES_AUTH |
|
|
|
|
room_keys_version_delete.RATE_LIMITED
|
2020-03-29 01:10:32 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ircd::m::resource::response
|
|
|
|
ircd::m::delete_room_keys_version(client &client,
|
|
|
|
const resource::request &request)
|
|
|
|
{
|
2020-03-31 04:10:42 +02:00
|
|
|
if(request.parv.size() < 1)
|
|
|
|
throw m::NEED_MORE_PARAMS
|
|
|
|
{
|
|
|
|
"version path parameter required",
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::user::room user_room
|
|
|
|
{
|
|
|
|
request.user_id
|
|
|
|
};
|
|
|
|
|
|
|
|
const event::idx event_idx
|
|
|
|
{
|
|
|
|
lex_cast<event::idx>(request.parv[0])
|
|
|
|
};
|
|
|
|
|
|
|
|
if(m::room_id(event_idx) != user_room.room_id)
|
|
|
|
throw m::ACCESS_DENIED
|
|
|
|
{
|
|
|
|
"Event idx:%lu is not in your room",
|
|
|
|
event_idx,
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto event_id
|
|
|
|
{
|
|
|
|
m::event_id(event_idx)
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto redact_id
|
|
|
|
{
|
|
|
|
m::redact(user_room, request.user_id, event_id, "deleted by client")
|
|
|
|
};
|
2020-03-29 01:10:32 +01:00
|
|
|
|
|
|
|
return resource::response
|
|
|
|
{
|
2020-03-31 04:10:42 +02:00
|
|
|
client, http::OK
|
2020-03-29 01:10:32 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// PUT
|
|
|
|
//
|
|
|
|
|
|
|
|
decltype(ircd::m::room_keys_version_put)
|
|
|
|
ircd::m::room_keys_version_put
|
|
|
|
{
|
|
|
|
room_keys_version, "PUT", put_room_keys_version,
|
|
|
|
{
|
2021-02-19 15:44:27 +01:00
|
|
|
room_keys_version_put.REQUIRES_AUTH |
|
|
|
|
room_keys_version_put.RATE_LIMITED
|
2020-03-29 01:10:32 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ircd::m::resource::response
|
|
|
|
ircd::m::put_room_keys_version(client &client,
|
|
|
|
const resource::request &request)
|
|
|
|
{
|
|
|
|
|
|
|
|
return resource::response
|
|
|
|
{
|
|
|
|
client, http::NOT_IMPLEMENTED
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// GET
|
|
|
|
//
|
|
|
|
|
|
|
|
decltype(ircd::m::room_keys_version_get)
|
|
|
|
ircd::m::room_keys_version_get
|
|
|
|
{
|
|
|
|
room_keys_version, "GET", get_room_keys_version,
|
|
|
|
{
|
2021-02-19 15:44:27 +01:00
|
|
|
room_keys_version_get.REQUIRES_AUTH |
|
|
|
|
room_keys_version_get.RATE_LIMITED
|
2020-03-29 01:10:32 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ircd::m::resource::response
|
|
|
|
ircd::m::get_room_keys_version(client &client,
|
|
|
|
const resource::request &request)
|
|
|
|
{
|
2020-03-31 03:11:01 +02:00
|
|
|
const m::user::room user_room
|
|
|
|
{
|
|
|
|
request.user_id
|
|
|
|
};
|
2020-03-29 01:10:32 +01:00
|
|
|
|
2020-03-31 03:11:01 +02:00
|
|
|
event::idx event_idx
|
2020-03-29 01:10:32 +01:00
|
|
|
{
|
2020-03-31 03:11:01 +02:00
|
|
|
request.parv.size() >= 1?
|
|
|
|
lex_cast<event::idx>(request.parv[0]):
|
|
|
|
0UL
|
2020-03-29 01:10:32 +01:00
|
|
|
};
|
2020-03-31 03:11:01 +02:00
|
|
|
|
|
|
|
if(!event_idx)
|
|
|
|
{
|
|
|
|
const m::room::type events
|
|
|
|
{
|
|
|
|
user_room, "ircd.room_keys.version"
|
|
|
|
};
|
|
|
|
|
|
|
|
events.for_each([&event_idx]
|
|
|
|
(const auto &, const auto &, const event::idx &_event_idx)
|
|
|
|
{
|
2020-03-31 04:10:42 +02:00
|
|
|
if(m::redacted(_event_idx))
|
|
|
|
return true;
|
|
|
|
|
2020-03-31 03:11:01 +02:00
|
|
|
event_idx = _event_idx;
|
|
|
|
return false; // false to break after this first hit
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!event_idx)
|
2020-05-11 11:10:54 +02:00
|
|
|
throw m::NOT_FOUND
|
2020-03-31 03:11:01 +02:00
|
|
|
{
|
2020-05-11 11:10:54 +02:00
|
|
|
"No version found.",
|
2020-03-31 03:11:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if(m::room_id(event_idx) != user_room.room_id)
|
|
|
|
throw m::ACCESS_DENIED
|
|
|
|
{
|
|
|
|
"Event idx:%lu is not in your room",
|
|
|
|
event_idx,
|
|
|
|
};
|
|
|
|
|
2020-03-31 04:10:42 +02:00
|
|
|
if(m::redacted(event_idx))
|
2020-05-11 11:10:54 +02:00
|
|
|
throw m::NOT_FOUND
|
2020-03-31 04:10:42 +02:00
|
|
|
{
|
2020-05-11 11:10:54 +02:00
|
|
|
"No version found.",
|
2020-03-31 04:10:42 +02:00
|
|
|
};
|
|
|
|
|
2020-03-31 03:11:01 +02:00
|
|
|
m::get(event_idx, "content", [&client, &event_idx]
|
|
|
|
(const json::object &content)
|
|
|
|
{
|
|
|
|
const json::value version
|
|
|
|
{
|
|
|
|
lex_cast(event_idx), json::STRING
|
|
|
|
};
|
|
|
|
|
|
|
|
resource::response
|
|
|
|
{
|
|
|
|
client, json::members
|
|
|
|
{
|
|
|
|
{ "version", version },
|
|
|
|
{ "algorithm", content["algorithm"] },
|
|
|
|
{ "auth_data", content["auth_data"] },
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
return {}; // Responded from closure
|
2020-03-29 01:10:32 +01:00
|
|
|
}
|