0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-28 14:58:20 +02:00

modules/client/keys: Move existing into directory; stub remaining endpoints.

This commit is contained in:
Jason Volk 2019-02-20 18:34:22 -08:00
parent a3923e8374
commit 8f4795e387
6 changed files with 312 additions and 158 deletions

View file

@ -161,7 +161,6 @@ client_client_sync_la_SOURCES = client/sync.cc
client_client_presence_la_SOURCES = client/presence.cc
client_client_profile_la_SOURCES = client/profile.cc
client_client_devices_la_SOURCES = client/devices.cc
client_client_keys_la_SOURCES = client/keys.cc
client_client_pushers_la_SOURCES = client/pushers.cc
client_client_publicrooms_la_SOURCES = client/publicrooms.cc
client_client_createroom_la_SOURCES = client/createroom.cc
@ -186,7 +185,6 @@ client_module_LTLIBRARIES = \
client/client_presence.la \
client/client_profile.la \
client/client_devices.la \
client/client_keys.la \
client/client_pushers.la \
client/client_publicrooms.la \
client/client_createroom.la \
@ -340,6 +338,22 @@ client_module_LTLIBRARIES += \
client/client_sync_rooms_ephemeral_receipt.la \
###
#
# client/keys/
#
client_client_keys_upload_la_SOURCES = client/keys/upload.cc
client_client_keys_query_la_SOURCES = client/keys/query.cc
client_client_keys_claim_la_SOURCES = client/keys/claim.cc
client_client_keys_changes_la_SOURCES = client/keys/changes.cc
client_module_LTLIBRARIES += \
client/client_keys_upload.la \
client/client_keys_query.la \
client/client_keys_claim.la \
client/client_keys_changes.la \
###
###############################################################################
#
# /_matrix/key/

View file

@ -1,156 +0,0 @@
// 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.
using namespace ircd;
mapi::header
IRCD_MODULE
{
"Client 11.10.2 :End-to-End Encryption Keys"
};
ircd::resource
keys_upload_resource
{
"/_matrix/client/r0/keys/upload/",
{
"(11.10.2.1) Keys Upload",
resource::DIRECTORY,
}
};
ircd::resource::redirect::permanent
keys_upload_resource__unstable
{
"/_matrix/client/unstable/keys/upload/",
"/_matrix/client/r0/keys/upload/",
{
"(11.10.2.2) Keys Query",
resource::DIRECTORY,
}
};
ircd::resource
keys_query_resource
{
"/_matrix/client/r0/keys/query",
{
"(11.10.2.2) Keys Query",
}
};
ircd::resource::redirect::permanent
keys_query_resource__unstable
{
"/_matrix/client/unstable/keys/query",
"/_matrix/client/r0/keys/query",
{
"(11.10.2.2) Keys Query",
}
};
resource::response
post__keys_upload(client &client,
const resource::request &request)
{
const m::user::room user_room
{
request.user_id
};
const json::object &device_keys
{
request["device_keys"]
};
const json::object &one_time_keys
{
request["one_time_keys"]
};
if(!empty(device_keys))
{
const m::user::id &user_id
{
unquote(device_keys.at("user_id"))
};
if(user_id != request.user_id)
throw m::FORBIDDEN
{
"client 11.10.2.1: device_keys.user_id: "
"Must match the device ID used when logging in."
};
const m::id::device &device_id
{
unquote(device_keys.at("device_id"))
};
const json::array &algorithms
{
device_keys.at("algorithms")
};
const json::object &keys
{
device_keys.at("keys")
};
const json::object &signatures
{
device_keys.at("signatures")
};
}
const int64_t curve25519_count{0};
const int64_t signed_curve25519_count{0};
const json::members one_time_key_counts
{
{ "curve25519", curve25519_count },
{ "signed_curve25519", signed_curve25519_count },
};
return resource::response
{
client, json::members
{
{ "one_time_key_counts", one_time_key_counts },
}
};
}
resource::method
upload_method_post
{
keys_upload_resource, "POST", post__keys_upload,
{
upload_method_post.REQUIRES_AUTH
}
};
resource::response
post__keys_query(client &client,
const resource::request &request)
{
return resource::response
{
client, http::OK
};
}
resource::method
query_method_post
{
keys_query_resource, "POST", post__keys_query,
{
query_method_post.REQUIRES_AUTH
}
};

View file

@ -0,0 +1,55 @@
// 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.
using namespace ircd;
mapi::header
IRCD_MODULE
{
"Client 14.11.5.2 :Key management API"
};
ircd::resource
changes_resource
{
"/_matrix/client/r0/keys/changes",
{
"(14.11.5.2.4) Keys changes",
}
};
ircd::resource::redirect::permanent
changes_resource__unstable
{
"/_matrix/client/unstable/keys/changes",
"/_matrix/client/r0/keys/changes",
{
"(14.11.5.2.4) Keys changes",
}
};
resource::response
get__keys_changes(client &client,
const resource::request &request)
{
return resource::response
{
client, http::OK
};
}
resource::method
method_get
{
changes_resource, "GET", get__keys_changes,
{
method_get.REQUIRES_AUTH
}
};

View file

@ -0,0 +1,55 @@
// 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.
using namespace ircd;
mapi::header
IRCD_MODULE
{
"Client 14.11.5.2 :Key management API"
};
ircd::resource
claim_resource
{
"/_matrix/client/r0/keys/claim",
{
"(14.11.5.2.2) Keys claim",
}
};
ircd::resource::redirect::permanent
claim_resource__unstable
{
"/_matrix/client/unstable/keys/claim",
"/_matrix/client/r0/keys/claim",
{
"(14.11.5.2.2) Keys claim",
}
};
resource::response
post__keys_claim(client &client,
const resource::request &request)
{
return resource::response
{
client, http::OK
};
}
resource::method
method_post
{
claim_resource, "POST", post__keys_claim,
{
method_post.REQUIRES_AUTH
}
};

View file

@ -0,0 +1,55 @@
// 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.
using namespace ircd;
mapi::header
IRCD_MODULE
{
"Client 14.11.5.2 :Key management API"
};
ircd::resource
query_resource
{
"/_matrix/client/r0/keys/query",
{
"(14.11.5.2.2) Keys query",
}
};
ircd::resource::redirect::permanent
query_resource__unstable
{
"/_matrix/client/unstable/keys/query",
"/_matrix/client/r0/keys/query",
{
"(14.11.5.2.2) Keys query",
}
};
resource::response
post__keys_query(client &client,
const resource::request &request)
{
return resource::response
{
client, http::OK
};
}
resource::method
method_post
{
query_resource, "POST", post__keys_query,
{
method_post.REQUIRES_AUTH
}
};

View file

@ -0,0 +1,131 @@
// 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.
using namespace ircd;
mapi::header
IRCD_MODULE
{
"Client 14.11.5.2 :Key management API"
};
ircd::resource
upload_resource
{
"/_matrix/client/r0/keys/upload",
{
"(14.11.5.2.1) Keys Upload",
resource::DIRECTORY
}
};
ircd::resource::redirect::permanent
upload_resource__unstable
{
"/_matrix/client/unstable/keys/upload",
"/_matrix/client/r0/keys/upload",
{
"(14.11.5.2.1) Keys Upload",
resource::DIRECTORY
}
};
static void
upload_device_keys(client &,
const resource::request &,
const m::device_keys &);
resource::response
post__keys_upload(client &client,
const resource::request &request)
{
const m::user::room user_room
{
request.user_id
};
const json::object &device_keys
{
request["device_keys"]
};
if(!empty(device_keys))
upload_device_keys(client, request, device_keys);
const json::object &one_time_keys
{
request["one_time_keys"]
};
const int64_t curve25519_count{0};
const int64_t signed_curve25519_count{0};
const json::members one_time_key_counts
{
{ "curve25519", curve25519_count },
{ "signed_curve25519", signed_curve25519_count },
};
return resource::response
{
client, json::members
{
{ "one_time_key_counts", one_time_key_counts },
}
};
}
void
upload_device_keys(client &client,
const resource::request &request,
const m::device_keys &device_keys)
{
if(at<"user_id"_>(device_keys) != request.user_id)
throw m::FORBIDDEN
{
"client 14.11.5.2.1: device_keys.user_id: "
"Must match the user_id used when logging in."
};
const m::device::id::buf device_id
{
m::user::get_device_from_access_token(request.access_token)
};
if(at<"device_id"_>(device_keys) != device_id)
throw m::FORBIDDEN
{
"client 14.11.5.2.1: device_keys.device_id: "
"Must match the device_id used when logging in."
};
const json::array &algorithms
{
at<"algorithms"_>(device_keys)
};
const json::object &keys
{
at<"keys"_>(device_keys)
};
const json::object &signatures
{
at<"signatures"_>(device_keys)
};
}
resource::method
method_post
{
upload_resource, "POST", post__keys_upload,
{
method_post.REQUIRES_AUTH
}
};