diff --git a/Cargo.lock b/Cargo.lock
index 6fed2af..07c38b8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -21,6 +21,15 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234"
+[[package]]
+name = "aho-corasick"
+version = "0.7.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b476ce7103678b0c6d3d395dbbae31d48ff910bd28be979ba5d48c6351131d0d"
+dependencies = [
+ "memchr",
+]
+
[[package]]
name = "ansi_term"
version = "0.12.1"
@@ -216,6 +225,7 @@ dependencies = [
"http",
"image",
"js_int",
+ "jsonwebtoken",
"log",
"rand",
"reqwest",
@@ -844,6 +854,20 @@ dependencies = [
"serde",
]
+[[package]]
+name = "jsonwebtoken"
+version = "7.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "afabcc15e437a6484fc4f12d0fd63068fe457bf93f1c148d3d9649c60b103f32"
+dependencies = [
+ "base64",
+ "pem",
+ "ring",
+ "serde",
+ "serde_json",
+ "simple_asn1",
+]
+
[[package]]
name = "kernel32-sys"
version = "0.2.2"
@@ -1053,6 +1077,17 @@ dependencies = [
"winapi 0.3.9",
]
+[[package]]
+name = "num-bigint"
+version = "0.2.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304"
+dependencies = [
+ "autocfg",
+ "num-integer",
+ "num-traits",
+]
+
[[package]]
name = "num-integer"
version = "0.1.43"
@@ -1206,6 +1241,17 @@ dependencies = [
"syn",
]
+[[package]]
+name = "pem"
+version = "0.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "59698ea79df9bf77104aefd39cc3ec990cb9693fb59c3b0a70ddf2646fdffb4b"
+dependencies = [
+ "base64",
+ "once_cell",
+ "regex",
+]
+
[[package]]
name = "percent-encoding"
version = "2.1.0"
@@ -1409,7 +1455,10 @@ version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8963b85b8ce3074fecffde43b4b0dded83ce2f367dc8d363afc56679f3ee820b"
dependencies = [
+ "aho-corasick",
+ "memchr",
"regex-syntax",
+ "thread_local",
]
[[package]]
@@ -1918,6 +1967,17 @@ dependencies = [
"libc",
]
+[[package]]
+name = "simple_asn1"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "692ca13de57ce0613a363c8c2f1de925adebc81b04c923ac60c5488bb44abe4b"
+dependencies = [
+ "chrono",
+ "num-bigint",
+ "num-traits",
+]
+
[[package]]
name = "slab"
version = "0.4.2"
@@ -2067,9 +2127,9 @@ dependencies = [
[[package]]
name = "syn"
-version = "1.0.44"
+version = "1.0.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e03e57e4fcbfe7749842d53e24ccb9aa12b7252dbe5e91d2acad31834c8b8fdd"
+checksum = "ea9c5432ff16d6152371f808fb5a871cd67368171b09bb21b43df8e4a47a3556"
dependencies = [
"proc-macro2",
"quote",
diff --git a/Cargo.toml b/Cargo.toml
index 8b29be8..a4cc3b9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -59,6 +59,8 @@ ring = "0.16.15"
# Used when querying the SRV record of other servers
trust-dns-resolver = "0.19.5"
+jsonwebtoken = "7.2.0"
+
[features]
default = ["conduit_bin"]
conduit_bin = [] # TODO: add rocket to this when it is optional
diff --git a/src/client_server/account.rs b/src/client_server/account.rs
index 81119ba..50cdd3d 100644
--- a/src/client_server/account.rs
+++ b/src/client_server/account.rs
@@ -43,7 +43,7 @@ const GUEST_NAME_LENGTH: usize = 10;
get("/_matrix/client/r0/register/available", data = "
")
)]
pub async fn get_register_available_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
// Validate user id
@@ -85,7 +85,7 @@ pub async fn get_register_available_route(
post("/_matrix/client/r0/register", data = "")
)]
pub async fn register_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
if db.globals.registration_disabled() {
@@ -532,7 +532,7 @@ pub async fn register_route(
post("/_matrix/client/r0/account/password", data = "")
)]
pub async fn change_password_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -616,7 +616,7 @@ pub async fn whoami_route(body: Ruma) -> ConduitResult,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
diff --git a/src/client_server/alias.rs b/src/client_server/alias.rs
index 094e70a..00bede9 100644
--- a/src/client_server/alias.rs
+++ b/src/client_server/alias.rs
@@ -19,7 +19,7 @@ use rocket::{delete, get, put};
put("/_matrix/client/r0/directory/room/<_>", data = "")
)]
pub async fn create_alias_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
if db.rooms.id_from_alias(&body.room_alias)?.is_some() {
@@ -39,7 +39,7 @@ pub async fn create_alias_route(
delete("/_matrix/client/r0/directory/room/<_>", data = "")
)]
pub async fn delete_alias_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
db.rooms.set_alias(&body.room_alias, None, &db.globals)?;
@@ -54,14 +54,14 @@ pub async fn delete_alias_route(
get("/_matrix/client/r0/directory/room/<_>", data = "")
)]
pub async fn get_alias_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
get_alias_helper(&db, &body.room_alias).await
}
pub async fn get_alias_helper(
- db: &Database,
+ db: &Database<'static>,
room_alias: &RoomAliasId,
) -> ConduitResult {
if room_alias.server_name() != db.globals.server_name() {
diff --git a/src/client_server/backup.rs b/src/client_server/backup.rs
index c84af0a..11ffcb0 100644
--- a/src/client_server/backup.rs
+++ b/src/client_server/backup.rs
@@ -18,7 +18,7 @@ use rocket::{delete, get, post, put};
post("/_matrix/client/unstable/room_keys/version", data = "")
)]
pub async fn create_backup_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -36,7 +36,7 @@ pub async fn create_backup_route(
put("/_matrix/client/unstable/room_keys/version/<_>", data = "")
)]
pub async fn update_backup_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -53,7 +53,7 @@ pub async fn update_backup_route(
get("/_matrix/client/unstable/room_keys/version", data = "")
)]
pub async fn get_latest_backup_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -80,7 +80,7 @@ pub async fn get_latest_backup_route(
get("/_matrix/client/unstable/room_keys/version/<_>", data = "")
)]
pub async fn get_backup_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -106,7 +106,7 @@ pub async fn get_backup_route(
delete("/_matrix/client/unstable/room_keys/version/<_>", data = "")
)]
pub async fn delete_backup_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -124,7 +124,7 @@ pub async fn delete_backup_route(
put("/_matrix/client/unstable/room_keys/keys", data = "")
)]
pub async fn add_backup_keys_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -157,7 +157,7 @@ pub async fn add_backup_keys_route(
put("/_matrix/client/unstable/room_keys/keys/<_>", data = "")
)]
pub async fn add_backup_key_sessions_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -188,7 +188,7 @@ pub async fn add_backup_key_sessions_route(
put("/_matrix/client/unstable/room_keys/keys/<_>/<_>", data = "")
)]
pub async fn add_backup_key_session_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -216,7 +216,7 @@ pub async fn add_backup_key_session_route(
get("/_matrix/client/unstable/room_keys/keys", data = "")
)]
pub async fn get_backup_keys_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -231,7 +231,7 @@ pub async fn get_backup_keys_route(
get("/_matrix/client/unstable/room_keys/keys/<_>", data = "")
)]
pub async fn get_backup_key_sessions_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -248,7 +248,7 @@ pub async fn get_backup_key_sessions_route(
get("/_matrix/client/unstable/room_keys/keys/<_>/<_>", data = "")
)]
pub async fn get_backup_key_session_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -265,7 +265,7 @@ pub async fn get_backup_key_session_route(
delete("/_matrix/client/unstable/room_keys/keys", data = "")
)]
pub async fn delete_backup_keys_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -287,7 +287,7 @@ pub async fn delete_backup_keys_route(
delete("/_matrix/client/unstable/room_keys/keys/<_>", data = "")
)]
pub async fn delete_backup_key_sessions_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -309,7 +309,7 @@ pub async fn delete_backup_key_sessions_route(
delete("/_matrix/client/unstable/room_keys/keys/<_>/<_>", data = "")
)]
pub async fn delete_backup_key_session_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
diff --git a/src/client_server/config.rs b/src/client_server/config.rs
index dd8de64..ba11d18 100644
--- a/src/client_server/config.rs
+++ b/src/client_server/config.rs
@@ -17,7 +17,7 @@ use rocket::{get, put};
put("/_matrix/client/r0/user/<_>/account_data/<_>", data = "")
)]
pub async fn set_global_account_data_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -50,7 +50,7 @@ pub async fn set_global_account_data_route(
get("/_matrix/client/r0/user/<_>/account_data/<_>", data = "")
)]
pub async fn get_global_account_data_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
diff --git a/src/client_server/context.rs b/src/client_server/context.rs
index f2a8cd4..c73b9cc 100644
--- a/src/client_server/context.rs
+++ b/src/client_server/context.rs
@@ -11,7 +11,7 @@ use rocket::get;
get("/_matrix/client/r0/rooms/<_>/context/<_>", data = "")
)]
pub async fn get_context_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
diff --git a/src/client_server/device.rs b/src/client_server/device.rs
index 86ac511..d3554cc 100644
--- a/src/client_server/device.rs
+++ b/src/client_server/device.rs
@@ -17,7 +17,7 @@ use rocket::{delete, get, post, put};
get("/_matrix/client/r0/devices", data = "")
)]
pub async fn get_devices_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -36,7 +36,7 @@ pub async fn get_devices_route(
get("/_matrix/client/r0/devices/<_>", data = "")
)]
pub async fn get_device_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -54,7 +54,7 @@ pub async fn get_device_route(
put("/_matrix/client/r0/devices/<_>", data = "")
)]
pub async fn update_device_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -79,7 +79,7 @@ pub async fn update_device_route(
delete("/_matrix/client/r0/devices/<_>", data = "")
)]
pub async fn delete_device_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -127,7 +127,7 @@ pub async fn delete_device_route(
post("/_matrix/client/r0/delete_devices", data = "")
)]
pub async fn delete_devices_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
diff --git a/src/client_server/directory.rs b/src/client_server/directory.rs
index 202417e..92622c8 100644
--- a/src/client_server/directory.rs
+++ b/src/client_server/directory.rs
@@ -32,7 +32,7 @@ use rocket::{get, post, put};
post("/_matrix/client/r0/publicRooms", data = "")
)]
pub async fn get_public_rooms_filtered_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
get_public_rooms_filtered_helper(
@@ -51,7 +51,7 @@ pub async fn get_public_rooms_filtered_route(
get("/_matrix/client/r0/publicRooms", data = "")
)]
pub async fn get_public_rooms_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let response = get_public_rooms_filtered_helper(
@@ -79,7 +79,7 @@ pub async fn get_public_rooms_route(
put("/_matrix/client/r0/directory/list/room/<_>", data = "")
)]
pub async fn set_room_visibility_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
match body.visibility {
@@ -97,7 +97,7 @@ pub async fn set_room_visibility_route(
get("/_matrix/client/r0/directory/list/room/<_>", data = "")
)]
pub async fn get_room_visibility_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
Ok(get_room_visibility::Response {
@@ -111,7 +111,7 @@ pub async fn get_room_visibility_route(
}
pub async fn get_public_rooms_filtered_helper(
- db: &Database,
+ db: &Database<'static>,
server: Option<&ServerName>,
limit: Option,
since: Option<&str>,
diff --git a/src/client_server/keys.rs b/src/client_server/keys.rs
index 58c79da..97dd183 100644
--- a/src/client_server/keys.rs
+++ b/src/client_server/keys.rs
@@ -23,7 +23,7 @@ use rocket::{get, post};
post("/_matrix/client/r0/keys/upload", data = "")
)]
pub async fn upload_keys_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -71,7 +71,7 @@ pub async fn upload_keys_route(
post("/_matrix/client/r0/keys/query", data = "")
)]
pub async fn get_keys_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -151,7 +151,7 @@ pub async fn get_keys_route(
post("/_matrix/client/r0/keys/claim", data = "")
)]
pub async fn claim_keys_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let mut one_time_keys = BTreeMap::new();
@@ -184,7 +184,7 @@ pub async fn claim_keys_route(
post("/_matrix/client/unstable/keys/device_signing/upload", data = "")
)]
pub async fn upload_signing_keys_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -241,7 +241,7 @@ pub async fn upload_signing_keys_route(
post("/_matrix/client/unstable/keys/signatures/upload", data = "")
)]
pub async fn upload_signatures_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -301,7 +301,7 @@ pub async fn upload_signatures_route(
get("/_matrix/client/r0/keys/changes", data = "")
)]
pub async fn get_key_changes_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
diff --git a/src/client_server/media.rs b/src/client_server/media.rs
index 96874cc..9248eba 100644
--- a/src/client_server/media.rs
+++ b/src/client_server/media.rs
@@ -15,7 +15,7 @@ const MXC_LENGTH: usize = 32;
#[cfg_attr(feature = "conduit_bin", get("/_matrix/media/r0/config"))]
pub async fn get_media_config_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
) -> ConduitResult {
Ok(get_media_config::Response {
upload_size: db.globals.max_request_size().into(),
@@ -28,7 +28,7 @@ pub async fn get_media_config_route(
post("/_matrix/media/r0/upload", data = "")
)]
pub async fn create_content_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let mxc = format!(
@@ -53,7 +53,7 @@ pub async fn create_content_route(
get("/_matrix/media/r0/download/<_>/<_>", data = "")
)]
pub async fn get_content_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id);
@@ -100,7 +100,7 @@ pub async fn get_content_route(
get("/_matrix/media/r0/thumbnail/<_>/<_>", data = "")
)]
pub async fn get_content_thumbnail_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id);
diff --git a/src/client_server/membership.rs b/src/client_server/membership.rs
index 25cad85..79d9c5c 100644
--- a/src/client_server/membership.rs
+++ b/src/client_server/membership.rs
@@ -35,7 +35,7 @@ use rocket::{get, post};
post("/_matrix/client/r0/rooms/<_>/join", data = "")
)]
pub async fn join_room_by_id_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
join_room_by_id_helper(
@@ -53,7 +53,7 @@ pub async fn join_room_by_id_route(
post("/_matrix/client/r0/join/<_>", data = "")
)]
pub async fn join_room_by_id_or_alias_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let (servers, room_id) = match RoomId::try_from(body.room_id_or_alias.clone()) {
@@ -87,7 +87,7 @@ pub async fn join_room_by_id_or_alias_route(
post("/_matrix/client/r0/rooms/<_>/leave", data = "")
)]
pub async fn leave_room_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -138,7 +138,7 @@ pub async fn leave_room_route(
post("/_matrix/client/r0/rooms/<_>/invite", data = "")
)]
pub async fn invite_user_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -180,7 +180,7 @@ pub async fn invite_user_route(
post("/_matrix/client/r0/rooms/<_>/kick", data = "")
)]
pub async fn kick_user_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -232,7 +232,7 @@ pub async fn kick_user_route(
post("/_matrix/client/r0/rooms/<_>/ban", data = "")
)]
pub async fn ban_user_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -291,7 +291,7 @@ pub async fn ban_user_route(
post("/_matrix/client/r0/rooms/<_>/unban", data = "")
)]
pub async fn unban_user_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -342,7 +342,7 @@ pub async fn unban_user_route(
post("/_matrix/client/r0/rooms/<_>/forget", data = "")
)]
pub async fn forget_room_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -359,7 +359,7 @@ pub async fn forget_room_route(
get("/_matrix/client/r0/joined_rooms", data = "")
)]
pub async fn joined_rooms_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -379,7 +379,7 @@ pub async fn joined_rooms_route(
get("/_matrix/client/r0/rooms/<_>/members", data = "")
)]
pub async fn get_member_events_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -407,7 +407,7 @@ pub async fn get_member_events_route(
get("/_matrix/client/r0/rooms/<_>/joined_members", data = "")
)]
pub async fn joined_members_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -441,7 +441,7 @@ pub async fn joined_members_route(
}
async fn join_room_by_id_helper(
- db: &Database,
+ db: &Database<'static>,
sender_user: Option<&UserId>,
room_id: &RoomId,
servers: &[Box],
diff --git a/src/client_server/message.rs b/src/client_server/message.rs
index 327b9ab..622a3f7 100644
--- a/src/client_server/message.rs
+++ b/src/client_server/message.rs
@@ -18,7 +18,7 @@ use rocket::{get, put};
put("/_matrix/client/r0/rooms/<_>/send/<_>/<_>", data = "")
)]
pub async fn send_message_event_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -88,7 +88,7 @@ pub async fn send_message_event_route(
get("/_matrix/client/r0/rooms/<_>/messages", data = "")
)]
pub async fn get_message_events_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
diff --git a/src/client_server/presence.rs b/src/client_server/presence.rs
index e597c69..ad25dab 100644
--- a/src/client_server/presence.rs
+++ b/src/client_server/presence.rs
@@ -11,7 +11,7 @@ use rocket::put;
put("/_matrix/client/r0/presence/<_>/status", data = "")
)]
pub async fn set_presence_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
diff --git a/src/client_server/profile.rs b/src/client_server/profile.rs
index 22d13cb..212a714 100644
--- a/src/client_server/profile.rs
+++ b/src/client_server/profile.rs
@@ -20,7 +20,7 @@ use std::convert::TryInto;
put("/_matrix/client/r0/profile/<_>/displayname", data = "")
)]
pub async fn set_displayname_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -102,7 +102,7 @@ pub async fn set_displayname_route(
get("/_matrix/client/r0/profile/<_>/displayname", data = "")
)]
pub async fn get_displayname_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
Ok(get_display_name::Response {
@@ -116,7 +116,7 @@ pub async fn get_displayname_route(
put("/_matrix/client/r0/profile/<_>/avatar_url", data = "")
)]
pub async fn set_avatar_url_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -198,7 +198,7 @@ pub async fn set_avatar_url_route(
get("/_matrix/client/r0/profile/<_>/avatar_url", data = "")
)]
pub async fn get_avatar_url_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
Ok(get_avatar_url::Response {
@@ -212,7 +212,7 @@ pub async fn get_avatar_url_route(
get("/_matrix/client/r0/profile/<_>", data = "")
)]
pub async fn get_profile_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
if !db.users.exists(&body.user_id)? {
diff --git a/src/client_server/push.rs b/src/client_server/push.rs
index 05ba8d0..e6deac8 100644
--- a/src/client_server/push.rs
+++ b/src/client_server/push.rs
@@ -17,7 +17,7 @@ use rocket::{get, post, put};
get("/_matrix/client/r0/pushrules", data = "")
)]
pub async fn get_pushrules_all_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -41,7 +41,7 @@ pub async fn get_pushrules_all_route(
//data = ""
))]
pub async fn set_pushrule_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
//body: Ruma,
) -> ConduitResult {
// TODO
@@ -57,7 +57,7 @@ pub async fn set_pushrule_route(
put("/_matrix/client/r0/pushrules/<_>/<_>/<_>/enabled")
)]
pub async fn set_pushrule_enabled_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
) -> ConduitResult {
// TODO
warn!("TODO: set_pushrule_enabled_route");
@@ -76,7 +76,7 @@ pub async fn get_pushers_route() -> ConduitResult {
}
#[cfg_attr(feature = "conduit_bin", post("/_matrix/client/r0/pushers/set"))]
-pub async fn set_pushers_route(db: State<'_, Database>) -> ConduitResult {
+pub async fn set_pushers_route(db: State<'_, Database<'_>>) -> ConduitResult {
db.flush().await?;
Ok(get_pushers::Response {
diff --git a/src/client_server/read_marker.rs b/src/client_server/read_marker.rs
index f3e7211..7fe6bf6 100644
--- a/src/client_server/read_marker.rs
+++ b/src/client_server/read_marker.rs
@@ -14,7 +14,7 @@ use std::{collections::BTreeMap, time::SystemTime};
post("/_matrix/client/r0/rooms/<_>/read_markers", data = "")
)]
pub async fn set_read_marker_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
diff --git a/src/client_server/redact.rs b/src/client_server/redact.rs
index 6f7728a..5d9c9c3 100644
--- a/src/client_server/redact.rs
+++ b/src/client_server/redact.rs
@@ -13,7 +13,7 @@ use rocket::put;
put("/_matrix/client/r0/rooms/<_>/redact/<_>/<_>", data = "")
)]
pub async fn redact_event_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
diff --git a/src/client_server/room.rs b/src/client_server/room.rs
index fdc9529..2dac75e 100644
--- a/src/client_server/room.rs
+++ b/src/client_server/room.rs
@@ -21,7 +21,7 @@ use rocket::{get, post};
post("/_matrix/client/r0/createRoom", data = "")
)]
pub async fn create_room_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -333,7 +333,7 @@ pub async fn create_room_route(
get("/_matrix/client/r0/rooms/<_>/event/<_>", data = "")
)]
pub async fn get_room_event_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -360,7 +360,7 @@ pub async fn get_room_event_route(
post("/_matrix/client/r0/rooms/<_room_id>/upgrade", data = "")
)]
pub async fn upgrade_room_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
_room_id: String,
) -> ConduitResult {
diff --git a/src/client_server/search.rs b/src/client_server/search.rs
index 0950b25..bd96d26 100644
--- a/src/client_server/search.rs
+++ b/src/client_server/search.rs
@@ -12,7 +12,7 @@ use std::collections::BTreeMap;
post("/_matrix/client/r0/search", data = "")
)]
pub async fn search_events_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
diff --git a/src/client_server/session.rs b/src/client_server/session.rs
index c8775ef..3c70631 100644
--- a/src/client_server/session.rs
+++ b/src/client_server/session.rs
@@ -7,6 +7,13 @@ use ruma::{
},
UserId,
};
+use serde::Deserialize;
+
+#[derive(Debug, Deserialize)]
+struct Claims {
+ sub: String,
+ exp: usize,
+}
#[cfg(feature = "conduit_bin")]
use rocket::{get, post};
@@ -35,44 +42,61 @@ pub async fn get_login_types_route() -> ConduitResult
post("/_matrix/client/r0/login", data = "")
)]
pub async fn login_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
// Validate login method
- let user_id =
- // TODO: Other login methods
- if let (login::IncomingUserInfo::MatrixId(username), login::IncomingLoginInfo::Password { password }) =
- (&body.user, &body.login_info)
- {
- let user_id = UserId::parse_with_server_name(username.to_string(), db.globals.server_name())
- .map_err(|_| Error::BadRequest(
- ErrorKind::InvalidUsername,
- "Username is invalid."
- ))?;
- let hash = db.users.password_hash(&user_id)?
- .ok_or(Error::BadRequest(
- ErrorKind::Forbidden,
- "Wrong username or password."
- ))?;
+ let user_id = match &body.login_info {
+ login::IncomingLoginInfo::Password { password } => {
+ let username = if let login::IncomingUserInfo::MatrixId(matrix_id) = &body.user {
+ matrix_id
+ } else {
+ return Err(Error::BadRequest(ErrorKind::Forbidden, "Bad login type."));
+ };
+ let user_id = UserId::parse_with_server_name(username.to_owned(), db.globals.server_name())
+ .map_err(|_| {
+ Error::BadRequest(ErrorKind::InvalidUsername, "Username is invalid.")
+ })?;
+ let hash = db.users.password_hash(&user_id)?.ok_or(Error::BadRequest(
+ ErrorKind::Forbidden,
+ "Wrong username or password.",
+ ))?;
if hash.is_empty() {
return Err(Error::BadRequest(
ErrorKind::UserDeactivated,
- "The user has been deactivated"
+ "The user has been deactivated",
));
}
- let hash_matches =
- argon2::verify_encoded(&hash, password.as_bytes()).unwrap_or(false);
+ let hash_matches = argon2::verify_encoded(&hash, password.as_bytes()).unwrap_or(false);
if !hash_matches {
- return Err(Error::BadRequest(ErrorKind::Forbidden, "Wrong username or password."));
+ return Err(Error::BadRequest(
+ ErrorKind::Forbidden,
+ "Wrong username or password.",
+ ));
}
user_id
- } else {
- return Err(Error::BadRequest(ErrorKind::Forbidden, "Bad login type."));
- };
+ }
+ login::IncomingLoginInfo::Token { token } => {
+ if let Some(jwt_decoding_key) = db.globals.jwt_decoding_key() {
+ let token = jsonwebtoken::decode::(
+ &token,
+ &jwt_decoding_key,
+ &jsonwebtoken::Validation::default(),
+ )
+ .map_err(|_| Error::BadRequest(ErrorKind::InvalidUsername, "Token is invalid."))?;
+ let username = token.claims.sub;
+ UserId::parse_with_server_name(username, db.globals.server_name()).map_err(|_| {
+ Error::BadRequest(ErrorKind::InvalidUsername, "Username is invalid.")
+ })?
+ } else {
+ return Err(Error::BadRequest(ErrorKind::Unknown, "Token login is not supported (server has no jwt decoding key)."));
+ }
+ }
+ };
// Generate new device id if the user didn't specify one
let device_id = body
@@ -116,7 +140,7 @@ pub async fn login_route(
post("/_matrix/client/r0/logout", data = "")
)]
pub async fn logout_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -143,7 +167,7 @@ pub async fn logout_route(
post("/_matrix/client/r0/logout/all", data = "")
)]
pub async fn logout_all_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
diff --git a/src/client_server/state.rs b/src/client_server/state.rs
index ca6bdf7..9466485 100644
--- a/src/client_server/state.rs
+++ b/src/client_server/state.rs
@@ -24,7 +24,7 @@ use rocket::{get, put};
put("/_matrix/client/r0/rooms/<_>/state/<_>/<_>", data = "")
)]
pub async fn send_state_event_for_key_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -57,7 +57,7 @@ pub async fn send_state_event_for_key_route(
put("/_matrix/client/r0/rooms/<_>/state/<_>", data = "")
)]
pub async fn send_state_event_for_empty_key_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
// This just calls send_state_event_for_key_route
@@ -98,7 +98,7 @@ pub async fn send_state_event_for_empty_key_route(
get("/_matrix/client/r0/rooms/<_>/state", data = "")
)]
pub async fn get_state_events_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -143,7 +143,7 @@ pub async fn get_state_events_route(
get("/_matrix/client/r0/rooms/<_>/state/<_>/<_>", data = "")
)]
pub async fn get_state_events_for_key_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -193,7 +193,7 @@ pub async fn get_state_events_for_key_route(
get("/_matrix/client/r0/rooms/<_>/state/<_>", data = "")
)]
pub async fn get_state_events_for_empty_key_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -239,7 +239,7 @@ pub async fn get_state_events_for_empty_key_route(
}
pub async fn send_state_event_for_key_helper(
- db: &Database,
+ db: &Database<'_>,
sender: &UserId,
content: &AnyStateEventContent,
json: serde_json::Value,
diff --git a/src/client_server/sync.rs b/src/client_server/sync.rs
index 360691a..11532fa 100644
--- a/src/client_server/sync.rs
+++ b/src/client_server/sync.rs
@@ -30,7 +30,7 @@ use std::{
get("/_matrix/client/r0/sync", data = "")
)]
pub async fn sync_events_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -661,7 +661,7 @@ pub async fn sync_events_route(
}
fn share_encrypted_room(
- db: &Database,
+ db: &Database<'_>,
sender_user: &UserId,
user_id: &UserId,
ignore_room: &RoomId,
diff --git a/src/client_server/tag.rs b/src/client_server/tag.rs
index 7bbf9e8..092010b 100644
--- a/src/client_server/tag.rs
+++ b/src/client_server/tag.rs
@@ -14,7 +14,7 @@ use rocket::{delete, get, put};
put("/_matrix/client/r0/user/<_>/rooms/<_>/tags/<_>", data = "")
)]
pub async fn update_tag_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -50,7 +50,7 @@ pub async fn update_tag_route(
delete("/_matrix/client/r0/user/<_>/rooms/<_>/tags/<_>", data = "")
)]
pub async fn delete_tag_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -83,7 +83,7 @@ pub async fn delete_tag_route(
get("/_matrix/client/r0/user/<_>/rooms/<_>/tags", data = "")
)]
pub async fn get_tags_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
diff --git a/src/client_server/to_device.rs b/src/client_server/to_device.rs
index 8cc3e29..eb9f44e 100644
--- a/src/client_server/to_device.rs
+++ b/src/client_server/to_device.rs
@@ -13,7 +13,7 @@ use rocket::put;
put("/_matrix/client/r0/sendToDevice/<_>/<_>", data = "")
)]
pub async fn send_event_to_device_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
diff --git a/src/client_server/typing.rs b/src/client_server/typing.rs
index e90746e..574dc02 100644
--- a/src/client_server/typing.rs
+++ b/src/client_server/typing.rs
@@ -11,7 +11,7 @@ use rocket::put;
put("/_matrix/client/r0/rooms/<_>/typing/<_>", data = "")
)]
pub fn create_typing_event_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
diff --git a/src/client_server/user_directory.rs b/src/client_server/user_directory.rs
index 5829364..2adedb0 100644
--- a/src/client_server/user_directory.rs
+++ b/src/client_server/user_directory.rs
@@ -10,7 +10,7 @@ use rocket::post;
post("/_matrix/client/r0/user_directory/search", data = "")
)]
pub async fn search_users_route(
- db: State<'_, Database>,
+ db: State<'_, Database<'_>>,
body: Ruma>,
) -> ConduitResult {
let limit = u64::from(body.limit) as usize;
diff --git a/src/database.rs b/src/database.rs
index 51c3895..22611d1 100644
--- a/src/database.rs
+++ b/src/database.rs
@@ -21,8 +21,8 @@ use ruma::{DeviceId, UserId};
use std::{convert::TryFrom, fs::remove_dir_all};
#[derive(Clone)]
-pub struct Database {
- pub globals: globals::Globals,
+pub struct Database<'a> {
+ pub globals: globals::Globals<'a>,
pub users: users::Users,
pub uiaa: uiaa::Uiaa,
pub rooms: rooms::Rooms,
@@ -35,7 +35,7 @@ pub struct Database {
pub _db: sled::Db,
}
-impl Database {
+impl Database<'static> {
/// Tries to remove the old database but ignores all errors.
pub fn try_remove(server_name: &str) -> Result<()> {
let mut path = ProjectDirs::from("xyz", "koesters", "conduit")
diff --git a/src/database/account_data.rs b/src/database/account_data.rs
index 9a6a050..e3640b9 100644
--- a/src/database/account_data.rs
+++ b/src/database/account_data.rs
@@ -21,7 +21,7 @@ impl AccountData {
user_id: &UserId,
event_type: EventType,
data: &T,
- globals: &super::globals::Globals,
+ globals: &super::globals::Globals<'_>,
) -> Result<()> {
let mut prefix = room_id
.map(|r| r.to_string())
diff --git a/src/database/admin.rs b/src/database/admin.rs
index f8b2385..25b0688 100644
--- a/src/database/admin.rs
+++ b/src/database/admin.rs
@@ -17,7 +17,7 @@ pub struct Admin {
impl Admin {
pub fn start_handler(
&self,
- db: super::Database,
+ db: super::Database<'static>,
mut receiver: mpsc::UnboundedReceiver,
) {
tokio::spawn(async move {
diff --git a/src/database/globals.rs b/src/database/globals.rs
index 37f10ee..86c09c8 100644
--- a/src/database/globals.rs
+++ b/src/database/globals.rs
@@ -6,7 +6,7 @@ use std::{convert::TryInto, sync::Arc};
pub const COUNTER: &str = "c";
#[derive(Clone)]
-pub struct Globals {
+pub struct Globals<'a> {
pub(super) globals: sled::Tree,
keypair: Arc,
reqwest_client: reqwest::Client,
@@ -15,9 +15,10 @@ pub struct Globals {
registration_disabled: bool,
encryption_disabled: bool,
federation_enabled: bool,
+ jwt_decoding_key: Option>,
}
-impl Globals {
+impl Globals<'_> {
pub fn load(globals: sled::Tree, config: &rocket::Config) -> Result {
let bytes = &*globals
.update_and_fetch("keypair", utils::generate_keypair)?
@@ -53,14 +54,19 @@ impl Globals {
}
};
+ let jwt_decoding_key =
+ config.get_str("jwt_secret").map(|secret| jsonwebtoken::DecodingKey::from_secret(secret.as_bytes()).into_static()).ok();
+
Ok(Self {
globals,
keypair: Arc::new(keypair),
reqwest_client: reqwest::Client::new(),
server_name: config
.get_str("server_name")
- .unwrap_or("localhost")
- .to_string()
+ .map(std::string::ToString::to_string)
+ .unwrap_or_else(|_| {
+ std::env::var("SERVER_NAME").unwrap_or_else(|_| "localhost".to_string())
+ })
.try_into()
.map_err(|_| Error::BadConfig("Invalid server_name."))?,
max_request_size: config
@@ -71,6 +77,7 @@ impl Globals {
registration_disabled: config.get_bool("registration_disabled").unwrap_or(false),
encryption_disabled: config.get_bool("encryption_disabled").unwrap_or(false),
federation_enabled: config.get_bool("federation_enabled").unwrap_or(false),
+ jwt_decoding_key,
})
}
@@ -120,4 +127,8 @@ impl Globals {
pub fn federation_enabled(&self) -> bool {
self.federation_enabled
}
+
+ pub fn jwt_decoding_key(&self) -> Option<&jsonwebtoken::DecodingKey<'_>> {
+ self.jwt_decoding_key.as_ref()
+ }
}
diff --git a/src/database/key_backups.rs b/src/database/key_backups.rs
index a50e45e..f21f2fe 100644
--- a/src/database/key_backups.rs
+++ b/src/database/key_backups.rs
@@ -20,7 +20,7 @@ impl KeyBackups {
&self,
user_id: &UserId,
backup_metadata: &BackupAlgorithm,
- globals: &super::globals::Globals,
+ globals: &super::globals::Globals<'_>,
) -> Result {
let version = globals.next_count()?.to_string();
@@ -65,7 +65,7 @@ impl KeyBackups {
user_id: &UserId,
version: &str,
backup_metadata: &BackupAlgorithm,
- globals: &super::globals::Globals,
+ globals: &super::globals::Globals<'_>,
) -> Result {
let mut key = user_id.to_string().as_bytes().to_vec();
key.push(0xff);
@@ -130,7 +130,7 @@ impl KeyBackups {
room_id: &RoomId,
session_id: &str,
key_data: &KeyData,
- globals: &super::globals::Globals,
+ globals: &super::globals::Globals<'_>,
) -> Result<()> {
let mut key = user_id.to_string().as_bytes().to_vec();
key.push(0xff);
diff --git a/src/database/rooms.rs b/src/database/rooms.rs
index 8ab900f..15d5109 100644
--- a/src/database/rooms.rs
+++ b/src/database/rooms.rs
@@ -443,7 +443,7 @@ impl Rooms {
pdu_json: &serde_json::Value,
count: u64,
pdu_id: IVec,
- globals: &super::globals::Globals,
+ globals: &super::globals::Globals<'_>,
account_data: &super::account_data::AccountData,
admin: &super::admin::Admin,
) -> Result<()> {
@@ -597,7 +597,7 @@ impl Rooms {
pdu_builder: PduBuilder,
sender: &UserId,
room_id: &RoomId,
- globals: &super::globals::Globals,
+ globals: &super::globals::Globals<'_>,
sending: &super::sending::Sending,
admin: &super::admin::Admin,
account_data: &super::account_data::AccountData,
@@ -983,7 +983,7 @@ impl Rooms {
member_content: member::MemberEventContent,
sender: &UserId,
account_data: &super::account_data::AccountData,
- globals: &super::globals::Globals,
+ globals: &super::globals::Globals<'_>,
) -> Result<()> {
let membership = member_content.membership;
@@ -1150,7 +1150,7 @@ impl Rooms {
&self,
alias: &RoomAliasId,
room_id: Option<&RoomId>,
- globals: &super::globals::Globals,
+ globals: &super::globals::Globals<'_>,
) -> Result<()> {
if let Some(room_id) = room_id {
// New alias
diff --git a/src/database/rooms/edus.rs b/src/database/rooms/edus.rs
index 29f5407..23f838b 100644
--- a/src/database/rooms/edus.rs
+++ b/src/database/rooms/edus.rs
@@ -32,7 +32,7 @@ impl RoomEdus {
user_id: &UserId,
room_id: &RoomId,
event: EduEvent,
- globals: &super::super::globals::Globals,
+ globals: &super::super::globals::Globals<'_>,
) -> Result<()> {
let mut prefix = room_id.to_string().as_bytes().to_vec();
prefix.push(0xff);
@@ -99,7 +99,7 @@ impl RoomEdus {
room_id: &RoomId,
user_id: &UserId,
count: u64,
- globals: &super::super::globals::Globals,
+ globals: &super::super::globals::Globals<'_>,
) -> Result<()> {
let mut key = room_id.to_string().as_bytes().to_vec();
key.push(0xff);
@@ -151,7 +151,7 @@ impl RoomEdus {
user_id: &UserId,
room_id: &RoomId,
timeout: u64,
- globals: &super::super::globals::Globals,
+ globals: &super::super::globals::Globals<'_>,
) -> Result<()> {
let mut prefix = room_id.to_string().as_bytes().to_vec();
prefix.push(0xff);
@@ -177,7 +177,7 @@ impl RoomEdus {
&self,
user_id: &UserId,
room_id: &RoomId,
- globals: &super::super::globals::Globals,
+ globals: &super::super::globals::Globals<'_>,
) -> Result<()> {
let mut prefix = room_id.to_string().as_bytes().to_vec();
prefix.push(0xff);
@@ -211,7 +211,7 @@ impl RoomEdus {
fn typings_maintain(
&self,
room_id: &RoomId,
- globals: &super::super::globals::Globals,
+ globals: &super::super::globals::Globals<'_>,
) -> Result<()> {
let mut prefix = room_id.to_string().as_bytes().to_vec();
prefix.push(0xff);
@@ -259,7 +259,7 @@ impl RoomEdus {
pub fn last_typing_update(
&self,
room_id: &RoomId,
- globals: &super::super::globals::Globals,
+ globals: &super::super::globals::Globals<'_>,
) -> Result {
self.typings_maintain(room_id, globals)?;
@@ -313,7 +313,7 @@ impl RoomEdus {
user_id: &UserId,
room_id: &RoomId,
presence: ruma::events::presence::PresenceEvent,
- globals: &super::super::globals::Globals,
+ globals: &super::super::globals::Globals<'_>,
) -> Result<()> {
// TODO: Remove old entry? Or maybe just wipe completely from time to time?
@@ -364,7 +364,7 @@ impl RoomEdus {
pub fn presence_maintain(
&self,
rooms: &super::Rooms,
- globals: &super::super::globals::Globals,
+ globals: &super::super::globals::Globals<'_>,
) -> Result<()> {
let current_timestamp = utils::millis_since_unix_epoch();
@@ -431,7 +431,7 @@ impl RoomEdus {
room_id: &RoomId,
since: u64,
rooms: &super::Rooms,
- globals: &super::super::globals::Globals,
+ globals: &super::super::globals::Globals<'_>,
) -> Result> {
self.presence_maintain(rooms, globals)?;
diff --git a/src/database/sending.rs b/src/database/sending.rs
index e3fca4f..4d3611e 100644
--- a/src/database/sending.rs
+++ b/src/database/sending.rs
@@ -16,7 +16,7 @@ pub struct Sending {
}
impl Sending {
- pub fn start_handler(&self, globals: &super::globals::Globals, rooms: &super::rooms::Rooms) {
+ pub fn start_handler(&self, globals: &super::globals::Globals<'static>, rooms: &super::rooms::Rooms) {
let servernamepduids = self.servernamepduids.clone();
let servercurrentpdus = self.servercurrentpdus.clone();
let rooms = rooms.clone();
@@ -174,7 +174,7 @@ impl Sending {
async fn handle_event(
server: Box,
pdu_ids: Vec,
- globals: &super::globals::Globals,
+ globals: &super::globals::Globals<'static>,
rooms: &super::rooms::Rooms,
) -> std::result::Result<
(Box, send_transaction_message::v1::Response),
diff --git a/src/database/uiaa.rs b/src/database/uiaa.rs
index 381a701..b6da436 100644
--- a/src/database/uiaa.rs
+++ b/src/database/uiaa.rs
@@ -30,7 +30,7 @@ impl Uiaa {
auth: &IncomingAuthData,
uiaainfo: &UiaaInfo,
users: &super::users::Users,
- globals: &super::globals::Globals,
+ globals: &super::globals::Globals<'_>,
) -> Result<(bool, UiaaInfo)> {
if let IncomingAuthData::DirectRequest {
kind,
diff --git a/src/database/users.rs b/src/database/users.rs
index 2a03960..cdb138d 100644
--- a/src/database/users.rs
+++ b/src/database/users.rs
@@ -278,7 +278,7 @@ impl Users {
device_id: &DeviceId,
one_time_key_key: &DeviceKeyId,
one_time_key_value: &OneTimeKey,
- globals: &super::globals::Globals,
+ globals: &super::globals::Globals<'_>,
) -> Result<()> {
let mut key = user_id.to_string().as_bytes().to_vec();
key.push(0xff);
@@ -327,7 +327,7 @@ impl Users {
user_id: &UserId,
device_id: &DeviceId,
key_algorithm: &DeviceKeyAlgorithm,
- globals: &super::globals::Globals,
+ globals: &super::globals::Globals<'_>,
) -> Result