From 10e43f6de1bfabf5a1736eeb48dfe5b820122217 Mon Sep 17 00:00:00 2001 From: Alex Emmet <111742636+Alex-Emmet@users.noreply.github.com> Date: Fri, 3 Jul 2026 16:19:12 +0200 Subject: [PATCH] [WIP] MTP migration --- Cargo.lock | 219 +++++++++++++++++++--------- Cargo.toml | 2 +- src/main.rs | 6 +- src/server/api.rs | 9 +- src/transport/omikron_connection.rs | 94 +++++++----- 5 files changed, 211 insertions(+), 119 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4e5fdac..36da87b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,7 +50,7 @@ dependencies = [ "mime", "percent-encoding", "pin-project-lite", - "rand 0.10.1", + "rand 0.10.2", "sha1 0.11.0", "smallvec", "tokio", @@ -222,6 +222,16 @@ dependencies = [ "generic-array", ] +[[package]] +name = "aead" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1973cfbc1a2daf9cf550e74e1f088c28e7f7d8c1e1418fb6c9dc5184b7e84c99" +dependencies = [ + "crypto-common 0.2.2", + "inout 0.2.2", +] + [[package]] name = "aes" version = "0.8.4" @@ -229,19 +239,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" dependencies = [ "cfg-if", - "cipher", + "cipher 0.4.4", "cpufeatures 0.2.17", ] [[package]] -name = "aes-gcm" -version = "0.10.3" +name = "aes" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" +checksum = "f1fc76eaeac4c9164506c466d4ffdd8ec9d0c5bf57ee97177c4d8eceb3a0e138" dependencies = [ - "aead", - "aes", - "cipher", + "cipher 0.5.2", + "cpubits", + "cpufeatures 0.3.0", +] + +[[package]] +name = "aes-gcm" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdf011db2e21ce0d575593d749db5554b47fed37aff429e4dc50bc91ac93a028" +dependencies = [ + "aead 0.6.1", + "aes 0.9.1", + "cipher 0.5.2", "ctr", "ghash", "subtle", @@ -313,7 +334,7 @@ dependencies = [ "nom", "num-traits", "rusticata-macros", - "thiserror", + "thiserror 2.0.18", "time", ] @@ -505,9 +526,9 @@ checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" [[package]] name = "aws-lc-rs" -version = "1.17.0" +version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ec2f1fc3ec205783a5da9a7e6c1509cc69dedf09a1949e412c1e18469326d00" +checksum = "4342d8937fc7e5dd9b1c60292261c0670c882a2cd1719cfc11b1af41731e32ad" dependencies = [ "aws-lc-sys", "untrusted 0.7.1", @@ -516,14 +537,15 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.41.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a2f9779ce85b93ab6170dd940ad0169b5766ff848247aff13bb788b832fe3f4" +checksum = "6d9ceb1da931507a12f4fccea479dccd00da1943e1b4ae72d8e502d707361444" dependencies = [ "cc", "cmake", "dunce", "fs_extra", + "pkg-config", ] [[package]] @@ -681,7 +703,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" dependencies = [ "cfg-if", - "cipher", + "cipher 0.4.4", "cpufeatures 0.2.17", ] @@ -702,9 +724,9 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" dependencies = [ - "aead", + "aead 0.5.2", "chacha20 0.9.1", - "cipher", + "cipher 0.4.4", "poly1305", "zeroize", ] @@ -716,10 +738,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" dependencies = [ "crypto-common 0.1.7", - "inout", + "inout 0.1.4", "zeroize", ] +[[package]] +name = "cipher" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c" +dependencies = [ + "block-buffer 0.12.1", + "crypto-common 0.2.2", + "inout 0.2.2", +] + [[package]] name = "cmake" version = "0.1.58" @@ -818,6 +851,12 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "cpubits" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae" + [[package]] name = "cpufeatures" version = "0.2.17" @@ -899,11 +938,11 @@ dependencies = [ [[package]] name = "ctr" -version = "0.9.2" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" +checksum = "baaca1c4b237092596f64d571e9db6ce4109c4ef9742e27590f1709594461f21" dependencies = [ - "cipher", + "cipher 0.5.2", ] [[package]] @@ -1441,11 +1480,10 @@ dependencies = [ [[package]] name = "ghash" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1" +checksum = "2eecf2d5dc9b66b732b97707a0210906b1d30523eb773193ab777c0c84b3e8d5" dependencies = [ - "opaque-debug", "polyval", ] @@ -1867,6 +1905,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "inout" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4250ce6452e92010fdf7268ccc5d14faa80bb12fc741938534c58f16804e03c7" +dependencies = [ + "hybrid-array", +] + [[package]] name = "instant" version = "0.1.13" @@ -1911,7 +1958,7 @@ dependencies = [ "jni-sys", "log", "simd_cesu8", - "thiserror", + "thiserror 2.0.18", "walkdir", "windows-link", ] @@ -2038,14 +2085,14 @@ checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" [[package]] name = "libredox" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f02ab6bace2054fb888a3c16f990117b579d14a3088e472d63c6011fa185c9d3" +checksum = "c943259e342f1e06ff2da7a83eabdfe7f92ce10262688dbf1895ff0b3e6e4652" dependencies = [ "bitflags 2.13.0", "libc", "plain", - "redox_syscall 0.8.1", + "redox_syscall 0.9.0", ] [[package]] @@ -2233,7 +2280,7 @@ dependencies = [ [[package]] name = "mtp" version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#41528ef7178982e70cb5789a437d863a7a35426c" +source = "git+https://git.methanium.net/methanium/mtp#8dc8b54b26544554f98d7af32200d6bf9a01d300" dependencies = [ "mtp-client", "mtp-codec", @@ -2247,7 +2294,7 @@ dependencies = [ [[package]] name = "mtp-client" version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#41528ef7178982e70cb5789a437d863a7a35426c" +source = "git+https://git.methanium.net/methanium/mtp#8dc8b54b26544554f98d7af32200d6bf9a01d300" dependencies = [ "mtp-codec", "mtp-common", @@ -2260,7 +2307,7 @@ dependencies = [ [[package]] name = "mtp-codec" version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#41528ef7178982e70cb5789a437d863a7a35426c" +source = "git+https://git.methanium.net/methanium/mtp#8dc8b54b26544554f98d7af32200d6bf9a01d300" dependencies = [ "base64", "byteorder", @@ -2273,18 +2320,18 @@ dependencies = [ [[package]] name = "mtp-common" version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#41528ef7178982e70cb5789a437d863a7a35426c" +source = "git+https://git.methanium.net/methanium/mtp#8dc8b54b26544554f98d7af32200d6bf9a01d300" dependencies = [ "quinn", "rustls", - "thiserror", + "thiserror 2.0.18", "wtransport", ] [[package]] name = "mtp-crypto" version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#41528ef7178982e70cb5789a437d863a7a35426c" +source = "git+https://git.methanium.net/methanium/mtp#8dc8b54b26544554f98d7af32200d6bf9a01d300" dependencies = [ "chacha20poly1305", "ed25519-dalek", @@ -2295,13 +2342,14 @@ dependencies = [ "rand_core 0.6.4", "serde", "sha2 0.11.0", + "thiserror 1.0.69", "zeroize", ] [[package]] name = "mtp-host" version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#41528ef7178982e70cb5789a437d863a7a35426c" +source = "git+https://git.methanium.net/methanium/mtp#8dc8b54b26544554f98d7af32200d6bf9a01d300" dependencies = [ "mtp-codec", "mtp-common", @@ -2314,7 +2362,7 @@ dependencies = [ [[package]] name = "mtp-transport" version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#41528ef7178982e70cb5789a437d863a7a35426c" +source = "git+https://git.methanium.net/methanium/mtp#8dc8b54b26544554f98d7af32200d6bf9a01d300" dependencies = [ "log", "mtp-codec", @@ -2328,7 +2376,7 @@ dependencies = [ [[package]] name = "mtp-type-map" version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#41528ef7178982e70cb5789a437d863a7a35426c" +source = "git+https://git.methanium.net/methanium/mtp#8dc8b54b26544554f98d7af32200d6bf9a01d300" dependencies = [ "serde", "serde_yaml", @@ -2346,9 +2394,9 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +checksum = "c863e9ab5e7bf9c99ba75e1050f1e4d624ae87ed3532d6238ffbdc7b585dbbe6" dependencies = [ "num-integer", "num-traits", @@ -2447,7 +2495,7 @@ dependencies = [ "sqlx", "strum", "strum_macros", - "thiserror", + "thiserror 2.0.18", "tokio", "uuid", "x448", @@ -2640,19 +2688,18 @@ checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" dependencies = [ "cpufeatures 0.2.17", "opaque-debug", - "universal-hash", + "universal-hash 0.5.1", ] [[package]] name = "polyval" -version = "0.6.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25" +checksum = "7dfc63250416fea14f5749b90725916a6c903f599d51cb635aa7a52bfd03eede" dependencies = [ - "cfg-if", - "cpufeatures 0.2.17", - "opaque-debug", - "universal-hash", + "cpubits", + "cpufeatures 0.3.0", + "universal-hash 0.6.1", ] [[package]] @@ -2708,7 +2755,7 @@ dependencies = [ "rustc-hash", "rustls", "socket2 0.6.4", - "thiserror", + "thiserror 2.0.18", "tokio", "tracing", "web-time", @@ -2730,7 +2777,7 @@ dependencies = [ "rustls", "rustls-pki-types", "slab", - "thiserror", + "thiserror 2.0.18", "tinyvec", "tracing", "web-time", @@ -2794,9 +2841,9 @@ dependencies = [ [[package]] name = "rand" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207" +checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" dependencies = [ "chacha20 0.10.1", "getrandom 0.4.3", @@ -2877,9 +2924,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b44b894f2a6e36457d665d1e08c3866add6ed5e70050c1b4ba8a8ddedb02ce7" +checksum = "c5102a6aaa05aa011a238e178e6bca86d2cb56fc9f586d37cb80f5bca6e07759" dependencies = [ "bitflags 2.13.0", ] @@ -2993,9 +3040,9 @@ dependencies = [ [[package]] name = "rustc-hash" -version = "2.1.2" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" [[package]] name = "rustc_version" @@ -3081,9 +3128,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.14.1" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30a7197ae7eb376e574fe940d068c30fe0462554a3ddbe4eca7838e049c937a9" +checksum = "764899a24af3980067ee14bc143654f297b22eaebfe3c7b6b211920a5a59b046" dependencies = [ "web-time", "zeroize", @@ -3506,7 +3553,7 @@ dependencies = [ "serde_json", "sha2 0.10.9", "smallvec", - "thiserror", + "thiserror 2.0.18", "tracing", "url", ] @@ -3586,7 +3633,7 @@ dependencies = [ "smallvec", "sqlx-core", "stringprep", - "thiserror", + "thiserror 2.0.18", "tracing", "whoami", ] @@ -3623,7 +3670,7 @@ dependencies = [ "smallvec", "sqlx-core", "stringprep", - "thiserror", + "thiserror 2.0.18", "tracing", "whoami", ] @@ -3647,7 +3694,7 @@ dependencies = [ "serde", "serde_urlencoded", "sqlx-core", - "thiserror", + "thiserror 2.0.18", "tracing", "url", ] @@ -3745,13 +3792,33 @@ dependencies = [ "libc", ] +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + [[package]] name = "thiserror" version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" dependencies = [ - "thiserror-impl", + "thiserror-impl 2.0.18", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -3767,9 +3834,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.51" +version = "0.3.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85c17d80feb7334b40c484e45ed1a5273dfd8bfda537c3be2e74a06a6686f327" +checksum = "18dfaaeddcb932337b5e7866ee7d0ce9b76d2fd092997146f187ec09b4558a50" dependencies = [ "deranged", "num-conv", @@ -3787,9 +3854,9 @@ checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109" [[package]] name = "time-macros" -version = "0.2.30" +version = "0.2.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcef1a61bdb119096e153208ec5cbec23944ce8bca13be5c7f60c634f7403935" +checksum = "c431b87111666e491a90baa837f914fb45cd5dc3c268591b0220ff5057f2085f" dependencies = [ "num-conv", "time-core", @@ -4009,6 +4076,16 @@ dependencies = [ "subtle", ] +[[package]] +name = "universal-hash" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4987bdc12753382e0bec4a65c50738ffaabc998b9cdd1f952fb5f39b0048a96" +dependencies = [ + "crypto-common 0.2.2", + "ctutils", +] + [[package]] name = "unsafe-libyaml" version = "0.2.11" @@ -4529,7 +4606,7 @@ dependencies = [ "rustls-pki-types", "sha2 0.11.0", "socket2 0.6.4", - "thiserror", + "thiserror 2.0.18", "time", "tokio", "tracing", @@ -4546,7 +4623,7 @@ checksum = "d5867c629e4252f7439d82315923daaf27f4fa442410d51b78ab93ef4c432a11" dependencies = [ "httlib-huffman", "octets", - "thiserror", + "thiserror 2.0.18", "url", ] @@ -4587,7 +4664,7 @@ dependencies = [ "nom", "oid-registry", "rusticata-macros", - "thiserror", + "thiserror 2.0.18", "time", ] @@ -4724,7 +4801,7 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb2a05c7c36fde6c09b08576c9f7fb4cda705990f73b58fe011abf7dfb24168b" dependencies = [ - "aes", + "aes 0.8.4", "arbitrary", "bzip2", "constant_time_eq", @@ -4747,9 +4824,9 @@ dependencies = [ [[package]] name = "zlib-rs" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "977347db8caa080403f6b6b7c1cda9479a8e869316f7e13a59b19076a40f94e3" +checksum = "5431d5661c32445236631278f27946e444ddafe4684cac70b185272d4f9c52d5" [[package]] name = "zmij" diff --git a/Cargo.toml b/Cargo.toml index f227b9e..e9a78f4 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ edition = "2024" [dependencies] mtp = { git = "https://git.methanium.net/methanium/mtp", features = [ "host", - "crypto", + "crypto" ] } actix-web = { version = "4.12.1", features = ["rustls-0_23"] } diff --git a/src/main.rs b/src/main.rs index 9429e59..c54fba3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,12 +26,8 @@ fn load_keyring() -> Keyring { .expect("Invalid KEYRING env var: not valid base64"); Keyring::from_bytes(&bytes).expect("Invalid KEYRING env var: failed to deserialize") } -pub fn get_keyring() -> &'static Keyring { - static KEYRING: Lazy = Lazy::new(load_keyring); - &KEYRING -} pub fn get_public_key_bundle() -> PublicKeyBundle { - get_keyring().public_key_bundle() + load_keyring().public_key_bundle() } #[tokio::main] diff --git a/src/server/api.rs b/src/server/api.rs index c9a1c59..219d5fc 100644 --- a/src/server/api.rs +++ b/src/server/api.rs @@ -1,16 +1,13 @@ use crate::get_public_key_bundle; use crate::sql::sql; +use crate::sql::sql::{get_by_user_id, get_omikron_by_id}; use crate::sql::user_online_tracker::get_iota_primary_omikron_connection; use crate::transport::omikron_manager::get_random_omikron; use crate::util::file_util::get_directory; -use crate::{ - sql::sql::{get_by_user_id, get_omikron_by_id}, -}; use actix_web::HttpResponse; use actix_web::http::{StatusCode, header}; use base64::Engine as _; use json::JsonValue; -use mtp_crypto::PublicKeyBundle; pub async fn handle(path: &str, body_string: Option) -> HttpResponse { if path == "OPTIONS" { @@ -196,7 +193,9 @@ pub async fn handle(path: &str, body_string: Option) -> HttpResponse { let mut res = JsonValue::new_object(); res["status"] = "success".into(); let bundle = get_public_key_bundle(); - res["public_key"] = base64::engine::general_purpose::STANDARD.encode(bundle.to_bytes()).into(); + res["public_key"] = base64::engine::general_purpose::STANDARD + .encode(bundle.as_bytes()) + .into(); (StatusCode::OK, res.dump()) } diff --git a/src/transport/omikron_connection.rs b/src/transport/omikron_connection.rs index cc53520..982db94 100644 --- a/src/transport/omikron_connection.rs +++ b/src/transport/omikron_connection.rs @@ -1,5 +1,5 @@ use crate::{ - get_private_key, get_public_key, log, log_cv_in, log_cv_out, log_err, log_in, + get_keyring, get_public_key_bundle, log, log_cv_in, log_cv_out, log_err, log_in, server::short_link::add_short_link, sql::{ connection_status::UserStatus, @@ -7,14 +7,14 @@ use crate::{ user_online_tracker::{self}, }, transport::omikron_manager, - util::{crypto_helper::encrypt, file_util::load_file_vec, logger::PrintType}, + util::{file_util::load_file_vec, logger::PrintType}, }; use base64::{Engine as _, engine::general_purpose::STANDARD}; use dashmap::DashMap; -use mtp::codec::{CommunicationType, CommunicationValue, DataType, DataValue}; +use mtp::{codec::{CommunicationType, CommunicationValue, DataType, DataValue}, host::{HostConfig, MTPHost}}; use mtp::transport::{Host, Policy, Receiver, SendMode, Sender, host}; -use std::net::{IpAddr, Ipv4Addr}; use rand::{Rng, distributions::Alphanumeric}; +use std::net::{IpAddr, Ipv4Addr}; use std::{ sync::Arc, time::{Duration, Instant}, @@ -268,11 +268,12 @@ impl OmikronConnection { log!("Stored State"); - let challenge_clone = challenge.clone(); - let private_key = get_private_key(); + let challenge_clone: String = challenge.clone(); + let private_key = get_keyring(); let public_key_for_encrypt = omikron_pub_key; let encrypted = tokio::task::spawn_blocking(move || { + challenge_clone encrypt(private_key, public_key_for_encrypt, &challenge_clone) .map_err(|_| OmikronError::AuthenticationFailed) }) @@ -286,7 +287,7 @@ impl OmikronConnection { .with_id(cv.get_id()) .add_typed_default( DataType::PublicKey, - DataValue::Str(STANDARD.encode(get_public_key().as_bytes())), + DataValue::Str(STANDARD.encode(get_public_key_bundle().as_bytes())), ) .add_typed_default(DataType::Content, DataValue::Str(encrypted)); @@ -579,7 +580,10 @@ impl OmikronConnection { .add_typed_default(DataType::PublicKey, DataValue::Str(public_key)) .add_typed_default(DataType::UserId, DataValue::SignedNumber(id.into())) .add_typed_default(DataType::IotaId, DataValue::SignedNumber(iota_id.into())) - .add_typed_default(DataType::SubLevel, DataValue::SignedNumber(sub_level as i128)) + .add_typed_default( + DataType::SubLevel, + DataValue::SignedNumber(sub_level as i128), + ) .add_typed_default(DataType::SubEnd, DataValue::SignedNumber(sub_end.into())); // Display name (fallback to username) @@ -594,7 +598,8 @@ impl OmikronConnection { response = response.add_typed_default(DataType::About, DataValue::Str(a)); } if let Some(av) = avatar { - response = response.add_typed_default(DataType::Avatar, DataValue::Str(STANDARD.encode(av))); + response = + response.add_typed_default(DataType::Avatar, DataValue::Str(STANDARD.encode(av))); } // Online status @@ -612,7 +617,10 @@ impl OmikronConnection { DataType::OnlineStatus, DataValue::Str(display_status.to_string()), ); - response = response.add_typed_default(DataType::OmikronId, DataValue::SignedNumber(us.omikron_id.into())); + response = response.add_typed_default( + DataType::OmikronId, + DataValue::SignedNumber(us.omikron_id.into()), + ); } else { response = response.add_typed_default( DataType::OnlineStatus, @@ -706,7 +714,8 @@ impl OmikronConnection { .add_typed_default(DataType::IotaId, DataValue::SignedNumber(iota_id.into())); if let Some(uid) = user_id { - response = response.add_typed_default(DataType::UserId, DataValue::SignedNumber(uid.into())); + response = + response.add_typed_default(DataType::UserId, DataValue::SignedNumber(uid.into())); } if let Some(uname) = username { response = response.add_typed_default(DataType::Username, DataValue::Str(uname)); @@ -730,7 +739,10 @@ impl OmikronConnection { let register_id = sql::get_register_id().await; let response = CommunicationValue::new(CommunicationType::GetRegister) .with_id(cv.get_id()) - .add_typed_default(DataType::UserId, DataValue::SignedNumber(register_id as i128)); + .add_typed_default( + DataType::UserId, + DataValue::SignedNumber(register_id as i128), + ); self.send(&response).await } @@ -763,7 +775,10 @@ impl OmikronConnection { let response = CommunicationValue::new(CommunicationType::CompleteRegisterIota) .with_id(cv.get_id()) - .add_typed_default(DataType::IotaId, DataValue::SignedNumber(new_iota_id.into())); + .add_typed_default( + DataType::IotaId, + DataValue::SignedNumber(new_iota_id.into()), + ); self.send(&response).await } Err(e) => { @@ -919,7 +934,10 @@ impl OmikronConnection { let response = CommunicationValue::new(CommunicationType::ErrorInternal) .with_id(cv.get_id()) - .add_typed_default(DataType::ErrorType, DataValue::Str(error_message)); + .add_typed_default( + DataType::ErrorType, + DataValue::Str(error_message), + ); self.send(&response).await } } else { @@ -986,8 +1004,14 @@ impl OmikronConnection { .map(|(sender, amount)| { let tm = mtp::type_map::TypeMap::latest(); DataValue::Container(vec![ - (DataType::SenderId.to_id(&tm), DataValue::SignedNumber(sender.into())), - (DataType::Amount.to_id(&tm), DataValue::SignedNumber(amount.into())), + ( + DataType::SenderId.to_id(&tm), + DataValue::SignedNumber(sender.into()), + ), + ( + DataType::Amount.to_id(&tm), + DataValue::SignedNumber(amount.into()), + ), ]) }) .collect(), @@ -1033,7 +1057,10 @@ impl OmikronConnection { // Sync with other Omikron clients let sync_cv = CommunicationValue::new(CommunicationType::ReadNotification) .with_receiver(receiver_id as u64) - .add_typed_default(DataType::SenderId, DataValue::SignedNumber(other_id.into())); + .add_typed_default( + DataType::SenderId, + DataValue::SignedNumber(other_id.into()), + ); crate::transport::omikron_manager::send_to_user(receiver_id, &sync_cv).await; } } @@ -1070,7 +1097,10 @@ impl OmikronConnection { // Sync with other Omikron clients let push_cv = CommunicationValue::new(CommunicationType::PushNotification) .with_receiver(receiver_id as u64) - .add_typed_default(DataType::SenderId, DataValue::SignedNumber(sender_id.into())); + .add_typed_default( + DataType::SenderId, + DataValue::SignedNumber(sender_id.into()), + ); crate::transport::omikron_manager::send_to_user(receiver_id, &push_cv).await; } Ok(()) @@ -1099,7 +1129,10 @@ impl OmikronConnection { }; let tm = mtp::type_map::TypeMap::latest(); let mut map = Vec::new(); - map.push((DataType::UserId.to_id(&tm), DataValue::SignedNumber(user_id.into()))); + map.push(( + DataType::UserId.to_id(&tm), + DataValue::SignedNumber(user_id.into()), + )); map.push((DataType::UserState.to_id(&tm), DataValue::Str(status_str))); states.push(DataValue::Container(map)); } @@ -1192,29 +1225,16 @@ pub async fn start(port: u16) -> Result<(), Box> { let key_pem = load_file_vec("certs", "transport_key.pem").expect("Error loading Keyfile"); - let mut host: Host = host( - IpAddr::from(Ipv4Addr::new(0, 0, 0, 0)), + let mut host: MTPHost = MTPHost::new( + HostConfig::new( + IpAddr::from(Ipv4Addr::new(0, 0, 0, 0)), port, cert_pem, key_pem, - Policy { - send_mode: SendMode::SingleStreamPerMessage, - max_message_size: 1_000_000_000, - close_frame_len: u32::MAX, - application_close_code: 0, - open_stream_timeout: Duration::from_millis(2_000), - write_timeout: Duration::from_millis(2_000), - accept_stream_timeout: Duration::from_millis(10_000), - read_timeout: Duration::from_millis(30_000), - keep_alive_interval: Some(Duration::from_secs(6)), - max_idle_timeout: Some(Duration::from_secs(30)), - force_close_delay: Duration::from_millis(300), - max_transient_recv_errors: 20, - transient_recv_backoff: Duration::from_millis(100), - receiver_queue_capacity: 1000, - }, + ) ) .await?; + log!("OmikronServer listening on port {}", port); while let Some((sender, mut receiver)) = host.next().await {