2 Commits

Author SHA1 Message Date
e6b347f90f Can get current user identity 2025-02-03 22:34:13 +01:00
8df3afe75e Include payload in integrity controls 2025-02-03 20:50:25 +01:00
10 changed files with 585 additions and 52 deletions

490
Cargo.lock generated
View File

@@ -235,7 +235,7 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0"
dependencies = [
"crypto-common",
"crypto-common 0.1.6",
"generic-array",
]
@@ -390,6 +390,12 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
[[package]]
name = "as_variant"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f38fa22307249f86fb7fad906fcae77f2564caeb56d7209103c551cd1cf4798f"
[[package]]
name = "askama"
version = "0.12.1"
@@ -434,6 +440,34 @@ dependencies = [
"nom",
]
[[package]]
name = "assign"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f093eed78becd229346bf859eec0aa4dd7ddde0757287b2b4107a1f09c80002"
[[package]]
name = "async-stream"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b5a71a6f37880a80d1d7f19efd781e4b5de42c88f0722cc13bcb6cc2cfe8476"
dependencies = [
"async-stream-impl",
"futures-core",
"pin-project-lite",
]
[[package]]
name = "async-stream-impl"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "async-trait"
version = "0.1.85"
@@ -577,6 +611,15 @@ dependencies = [
"generic-array",
]
[[package]]
name = "block-buffer"
version = "0.11.0-rc.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fd016a0ddc7cb13661bf5576073ce07330a693f8608a1320b4e20561cc12cdc"
dependencies = [
"hybrid-array",
]
[[package]]
name = "brotli"
version = "6.0.0"
@@ -671,7 +714,7 @@ version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
dependencies = [
"crypto-common",
"crypto-common 0.1.6",
"inout",
]
@@ -765,6 +808,12 @@ version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8"
[[package]]
name = "const-oid"
version = "0.10.0-rc.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68ff6be19477a1bd5441f382916a89bc2a0b2c35db6d41e0f6e8538bf6d6463f"
[[package]]
name = "const-random"
version = "0.1.18"
@@ -785,6 +834,12 @@ dependencies = [
"tiny-keccak",
]
[[package]]
name = "const_panic"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2459fc9262a1aa204eb4b5764ad4f189caec88aea9634389c0a25f8be7f6265e"
[[package]]
name = "constant_time_eq"
version = "0.3.1"
@@ -809,7 +864,7 @@ dependencies = [
"hmac",
"percent-encoding",
"rand 0.8.5",
"sha2",
"sha2 0.10.8",
"subtle",
"time",
"version_check",
@@ -878,6 +933,17 @@ dependencies = [
"typenum",
]
[[package]]
name = "crypto-common"
version = "0.2.0-rc.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0b8ce8218c97789f16356e7896b3714f26c2ee1079b79c0b7ae7064bb9089fa"
dependencies = [
"getrandom 0.2.15",
"hybrid-array",
"rand_core 0.6.4",
]
[[package]]
name = "ct-codecs"
version = "1.1.3"
@@ -893,13 +959,19 @@ dependencies = [
"cipher",
]
[[package]]
name = "date_header"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c03c416ed1a30fbb027ef484ba6ab6f80e1eada675e1a2b92fd673c045a1f1d"
[[package]]
name = "der"
version = "0.7.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0"
dependencies = [
"const-oid",
"const-oid 0.9.6",
"pem-rfc7468",
"zeroize",
]
@@ -954,12 +1026,23 @@ version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"const-oid",
"crypto-common",
"block-buffer 0.10.4",
"const-oid 0.9.6",
"crypto-common 0.1.6",
"subtle",
]
[[package]]
name = "digest"
version = "0.11.0-pre.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf2e3d6615d99707295a9673e889bf363a04b2a466bd320c65a72536f7577379"
dependencies = [
"block-buffer 0.11.0-rc.3",
"const-oid 0.10.0-rc.3",
"crypto-common 0.2.0-rc.1",
]
[[package]]
name = "displaydoc"
version = "0.2.5"
@@ -987,7 +1070,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca"
dependencies = [
"der",
"digest",
"digest 0.10.7",
"elliptic-curve",
"rfc6979",
"signature",
@@ -1012,7 +1095,7 @@ checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47"
dependencies = [
"base16ct",
"crypto-bigint",
"digest",
"digest 0.10.7",
"ff",
"generic-array",
"group",
@@ -1244,16 +1327,13 @@ dependencies = [
[[package]]
name = "getrandom"
version = "0.3.0-rc.0"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a78f88e84d239c7f2619ae8b091603c26208e1cb322571f5a29d6806f56ee5e"
checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8"
dependencies = [
"cfg-if",
"js-sys",
"libc",
"rustix",
"wasi 0.13.3+wasi-0.2.2",
"wasm-bindgen",
"windows-targets",
]
@@ -1361,7 +1441,7 @@ version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
dependencies = [
"digest",
"digest 0.10.7",
]
[[package]]
@@ -1376,7 +1456,7 @@ version = "1.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a8575493d277c9092b988c780c94737fb9fd8651a1001e16bee3eccfc1baedb"
dependencies = [
"digest",
"digest 0.10.7",
]
[[package]]
@@ -1385,7 +1465,7 @@ version = "1.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0b3a0f572aa8389d325f5852b9e0a333a15b0f86ecccbb3fdb6e97cd86dc67c"
dependencies = [
"digest",
"digest 0.10.7",
]
[[package]]
@@ -1469,6 +1549,15 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "hybrid-array"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2d35805454dc9f8662a98d6d61886ffe26bd465f5960e0e55345c70d5c0d2a9"
dependencies = [
"typenum",
]
[[package]]
name = "hyper"
version = "1.5.2"
@@ -1717,6 +1806,7 @@ checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652"
dependencies = [
"equivalent",
"hashbrown 0.15.2",
"serde",
]
[[package]]
@@ -1768,6 +1858,24 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "js_int"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d937f95470b270ce8b8950207715d71aa8e153c0d44c6684d59397ed4949160a"
dependencies = [
"serde",
]
[[package]]
name = "js_option"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68421373957a1593a767013698dbf206e2b221eefe97a44d98d18672ff38423c"
dependencies = [
"serde",
]
[[package]]
name = "jwt-simple"
version = "0.12.11"
@@ -1804,10 +1912,30 @@ dependencies = [
"ecdsa",
"elliptic-curve",
"once_cell",
"sha2",
"sha2 0.10.8",
"signature",
]
[[package]]
name = "konst"
version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4381b9b00c55f251f2ebe9473aef7c117e96828def1a7cb3bd3f0f903c6894e9"
dependencies = [
"const_panic",
"konst_kernel",
"typewit",
]
[[package]]
name = "konst_kernel"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4b1eb7788f3824c629b1116a7a9060d6e898c358ebff59070093d51103dcc3c"
dependencies = [
"typewit",
]
[[package]]
name = "language-tags"
version = "0.3.2"
@@ -1894,6 +2022,12 @@ version = "0.4.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f"
[[package]]
name = "maplit"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
[[package]]
name = "matrix_gateway"
version = "0.1.0"
@@ -1903,6 +2037,8 @@ dependencies = [
"actix-web",
"anyhow",
"askama",
"base16ct",
"bytes",
"chrono",
"clap",
"env_logger",
@@ -1913,11 +2049,13 @@ dependencies = [
"light-openid",
"log",
"mime_guess",
"rand 0.9.0-beta.3",
"rand 0.9.0",
"ruma",
"rust-embed",
"rust-s3",
"serde",
"serde_json",
"sha2 0.11.0-pre.4",
"thiserror 2.0.11",
"urlencoding",
"uuid",
@@ -2172,7 +2310,7 @@ dependencies = [
"ecdsa",
"elliptic-curve",
"primeorder",
"sha2",
"sha2 0.10.8",
]
[[package]]
@@ -2184,7 +2322,7 @@ dependencies = [
"ecdsa",
"elliptic-curve",
"primeorder",
"sha2",
"sha2 0.10.8",
]
[[package]]
@@ -2326,6 +2464,15 @@ dependencies = [
"elliptic-curve",
]
[[package]]
name = "proc-macro-crate"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b"
dependencies = [
"toml_edit",
]
[[package]]
name = "proc-macro2"
version = "1.0.93"
@@ -2377,12 +2524,12 @@ dependencies = [
[[package]]
name = "rand"
version = "0.9.0-beta.3"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fccbfebb3972a41a31c605a59207d9fba5489b9a87d9d87024cb6df73a32ec7"
checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94"
dependencies = [
"rand_chacha 0.9.0-beta.1",
"rand_core 0.9.0-beta.1",
"rand_chacha 0.9.0",
"rand_core 0.9.0",
"zerocopy 0.8.14",
]
@@ -2398,12 +2545,12 @@ dependencies = [
[[package]]
name = "rand_chacha"
version = "0.9.0-beta.1"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f16da77124f4ee9fabd55ce6540866e9101431863b4876de58b68797f331adf2"
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
dependencies = [
"ppv-lite86",
"rand_core 0.9.0-beta.1",
"rand_core 0.9.0",
]
[[package]]
@@ -2417,11 +2564,11 @@ dependencies = [
[[package]]
name = "rand_core"
version = "0.9.0-beta.1"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a98fa0b8309344136abe6244130311e76997e546f76fae8054422a7539b43df7"
checksum = "b08f3c9802962f7e1b25113931d94f43ed9725bebc59db9d0c3e9a23b67e15ff"
dependencies = [
"getrandom 0.3.0-rc.0",
"getrandom 0.3.1",
"zerocopy 0.8.14",
]
@@ -2569,21 +2716,164 @@ version = "0.9.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47c75d7c5c6b673e58bf54d8544a9f432e3a925b0e80f7cd3602ab5c50c55519"
dependencies = [
"const-oid",
"digest",
"const-oid 0.9.6",
"digest 0.10.7",
"num-bigint-dig",
"num-integer",
"num-traits",
"pkcs1",
"pkcs8",
"rand_core 0.6.4",
"sha2",
"sha2 0.10.8",
"signature",
"spki",
"subtle",
"zeroize",
]
[[package]]
name = "ruma"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d6fea33e3d17b9e009fefb3f175ca7fd40b1e7d1e72444478fd1b28611eb50a"
dependencies = [
"assign",
"js_int",
"js_option",
"ruma-client",
"ruma-client-api",
"ruma-common",
"ruma-events",
"web-time",
]
[[package]]
name = "ruma-client"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7df765f1917f28ef0bf307b19c2c845be4fc2bb77f76e00b1eafbfa8921f7952"
dependencies = [
"as_variant",
"assign",
"async-stream",
"bytes",
"futures-core",
"http 1.2.0",
"http-body-util",
"hyper",
"hyper-tls",
"hyper-util",
"ruma-client-api",
"ruma-common",
"serde_html_form",
"tracing",
]
[[package]]
name = "ruma-client-api"
version = "0.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23989b539eceeaad01ba089ad307788f90a29bac2e5f730ff0a523eeae3fa1d7"
dependencies = [
"as_variant",
"assign",
"bytes",
"date_header",
"http 1.2.0",
"js_int",
"js_option",
"maplit",
"ruma-common",
"ruma-events",
"serde",
"serde_html_form",
"serde_json",
"thiserror 2.0.11",
"url",
"web-time",
]
[[package]]
name = "ruma-common"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1058c04b8dd62f4fba71c9f65112fb79bc332438d11aefe1e8edf67b7fb58a98"
dependencies = [
"as_variant",
"base64 0.22.1",
"bytes",
"form_urlencoded",
"http 1.2.0",
"indexmap",
"js_int",
"konst",
"percent-encoding",
"rand 0.8.5",
"regex",
"ruma-identifiers-validation",
"ruma-macros",
"serde",
"serde_html_form",
"serde_json",
"thiserror 2.0.11",
"time",
"tracing",
"url",
"uuid",
"web-time",
"wildmatch",
]
[[package]]
name = "ruma-events"
version = "0.30.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff1b8e15942e35ba56004429bc0845f481281f903e86957973a08ec08f8d06f0"
dependencies = [
"as_variant",
"indexmap",
"js_int",
"js_option",
"percent-encoding",
"regex",
"ruma-common",
"ruma-identifiers-validation",
"ruma-macros",
"serde",
"serde_json",
"thiserror 2.0.11",
"tracing",
"url",
"web-time",
"wildmatch",
]
[[package]]
name = "ruma-identifiers-validation"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ad674b5e5368c53a2c90fde7dac7e30747004aaf7b1827b72874a25fc06d4d8"
dependencies = [
"js_int",
"thiserror 2.0.11",
]
[[package]]
name = "ruma-macros"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1182e83ee5cd10121974f163337b16af68a93eedfc7cdbdbd52307ac7e1d743"
dependencies = [
"cfg-if",
"proc-macro-crate",
"proc-macro2",
"quote",
"ruma-identifiers-validation",
"serde",
"syn",
"toml",
]
[[package]]
name = "rust-embed"
version = "8.5.0"
@@ -2614,7 +2904,7 @@ version = "8.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e5347777e9aacb56039b0e1f28785929a8a3b709e87482e7442c72e7c12529d"
dependencies = [
"sha2",
"sha2 0.10.8",
"walkdir",
]
@@ -2655,7 +2945,7 @@ dependencies = [
"serde",
"serde_derive",
"serde_json",
"sha2",
"sha2 0.10.8",
"thiserror 1.0.69",
"time",
"tokio",
@@ -2848,6 +3138,19 @@ dependencies = [
"syn",
]
[[package]]
name = "serde_html_form"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d2de91cf02bbc07cde38891769ccd5d4f073d22a40683aa4bc7a95781aaa2c4"
dependencies = [
"form_urlencoded",
"indexmap",
"itoa",
"ryu",
"serde",
]
[[package]]
name = "serde_json"
version = "1.0.137"
@@ -2860,6 +3163,15 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_spanned"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1"
dependencies = [
"serde",
]
[[package]]
name = "serde_urlencoded"
version = "0.7.1"
@@ -2880,7 +3192,7 @@ checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
"digest 0.10.7",
]
[[package]]
@@ -2891,7 +3203,18 @@ checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
"digest 0.10.7",
]
[[package]]
name = "sha2"
version = "0.11.0-pre.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "540c0893cce56cdbcfebcec191ec8e0f470dd1889b6e7a0b503e310a94a168f5"
dependencies = [
"cfg-if",
"cpufeatures",
"digest 0.11.0-pre.9",
]
[[package]]
@@ -2915,7 +3238,7 @@ version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de"
dependencies = [
"digest",
"digest 0.10.7",
"rand_core 0.6.4",
]
@@ -3225,6 +3548,40 @@ dependencies = [
"tokio",
]
[[package]]
name = "toml"
version = "0.8.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.22.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02a8b472d1a3d7c18e2d61a489aee3453fd9031c33e4f55bd533f4a7adca1bee"
dependencies = [
"indexmap",
"serde",
"serde_spanned",
"toml_datetime",
"winnow",
]
[[package]]
name = "tower"
version = "0.5.2"
@@ -3260,9 +3617,21 @@ checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
dependencies = [
"log",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.33"
@@ -3290,6 +3659,21 @@ version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "typewit"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb77c29baba9e4d3a6182d51fa75e3215c7fd1dab8f4ea9d107c716878e55fc0"
dependencies = [
"typewit_proc_macros",
]
[[package]]
name = "typewit_proc_macros"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e36a83ea2b3c704935a01b4642946aadd445cea40b10935e3f8bd8052b8193d6"
[[package]]
name = "unicase"
version = "2.8.1"
@@ -3314,7 +3698,7 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea"
dependencies = [
"crypto-common",
"crypto-common 0.1.6",
"subtle",
]
@@ -3333,6 +3717,7 @@ dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
"serde",
]
[[package]]
@@ -3518,6 +3903,22 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "web-time"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb"
dependencies = [
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "wildmatch"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68ce1ab1f8c62655ebe1350f589c61e505cf94d385bc6a12899442d9081e71fd"
[[package]]
name = "winapi-util"
version = "0.1.9"
@@ -3648,6 +4049,15 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "winnow"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86e376c75f4f43f44db463cf729e0d3acbf954d13e22c51e26e4c264b4ab545f"
dependencies = [
"memchr",
]
[[package]]
name = "wit-bindgen-rt"
version = "0.33.0"

View File

@@ -16,7 +16,7 @@ actix-web = "4"
actix-session = { version = "0.10.1", features = ["redis-session"] }
light-openid = "1.0.2"
thiserror = "2.0.11"
rand = "0.9.0-beta.3"
rand = "0.9.0"
rust-embed = "8.5.0"
mime_guess = "2.0.5"
askama = "0.12.1"
@@ -26,4 +26,8 @@ ipnet = { version = "2.11.0", features = ["serde"] }
chrono = "0.4.39"
futures-util = "0.3.31"
jwt-simple = { version = "0.12.11", default-features=false, features=["pure-rust"] }
actix-remote-ip = "0.1.0"
actix-remote-ip = "0.1.0"
bytes = "1.9.0"
sha2 = "0.11.0-pre.4"
base16ct = "0.2.0"
ruma = { version = "0.12.0", features = ["client-api-c", "client-ext-client-api", "client-hyper-native-tls", "rand"] }

View File

@@ -31,6 +31,10 @@ struct Args {
#[arg(short('X'), long, default_value = "GET")]
method: String,
/// Payload SHA256 digest
#[arg(short('D'), long)]
payload_digest: Option<String>,
/// Request URI
uri: String,
@@ -59,6 +63,7 @@ fn main() {
custom: TokenClaims {
method: args.method.to_string(),
uri: args.uri,
payload_sha256: args.payload_digest.clone(),
},
};

View File

@@ -20,7 +20,7 @@ pub struct AppConfig {
/// Matrix API origin
#[clap(short, long, env, default_value = "http://127.0.0.1:8448")]
pub matrix_api: String,
pub matrix_homeserver: String,
/// Redis connection hostname
#[clap(long, env, default_value = "localhost")]

View File

@@ -1,27 +1,38 @@
use crate::user::{APIClient, APIClientID, UserConfig, UserID};
use crate::server::HttpFailure;
use crate::user::{APIClient, APIClientID, RumaClient, UserConfig, UserID};
use crate::utils::curr_time;
use actix_remote_ip::RemoteIP;
use actix_web::dev::Payload;
use actix_web::{FromRequest, HttpRequest};
use bytes::Bytes;
use jwt_simple::common::VerificationOptions;
use jwt_simple::prelude::{Duration, HS256Key, MACLike};
use ruma::api::{IncomingResponse, OutgoingRequest};
use sha2::{Digest, Sha256};
use std::net::IpAddr;
use std::str::FromStr;
pub struct APIClientAuth {
pub user: UserConfig,
client: APIClient,
payload: Option<Vec<u8>>,
pub client: APIClient,
pub payload: Option<Vec<u8>>,
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct TokenClaims {
#[serde(rename = "met")]
pub method: String,
pub uri: String,
#[serde(rename = "pay", skip_serializing_if = "Option::is_none")]
pub payload_sha256: Option<String>,
}
impl APIClientAuth {
async fn extract_auth(req: &HttpRequest, remote_ip: IpAddr) -> Result<Self, actix_web::Error> {
async fn extract_auth(
req: &HttpRequest,
remote_ip: IpAddr,
payload_bytes: Option<Bytes>,
) -> Result<Self, actix_web::Error> {
let Some(token) = req.headers().get("x-client-auth") else {
return Err(actix_web::error::ErrorBadRequest(
"Missing authentication header!",
@@ -85,7 +96,7 @@ impl APIClientAuth {
// Decode JWT
let key = HS256Key::from_bytes(client.secret.as_bytes());
let mut verif = VerificationOptions::default();
verif.max_validity = Some(Duration::from_mins(15));
verif.max_validity = Some(Duration::from_mins(20));
let claims = match key.verify_token::<TokenClaims>(jwt_token, Some(verif)) {
Ok(t) => t,
Err(e) => {
@@ -129,7 +140,27 @@ impl APIClientAuth {
));
}
// TODO : handle payload
let payload = match (payload_bytes, claims.custom.payload_sha256) {
(None, _) => None,
(Some(_), None) => {
return Err(actix_web::error::ErrorBadRequest(
"A payload digest must be included in the JWT when the request has a payload!",
));
}
(Some(payload), Some(provided_digest)) => {
let computed_digest = base16ct::lower::encode_string(&Sha256::digest(&payload));
if computed_digest != provided_digest {
log::error!(
"Expected digest {provided_digest} but computed {computed_digest}!"
);
return Err(actix_web::error::ErrorBadRequest(
"Computed digest is different from the one provided in the JWT!",
));
}
Some(payload.to_vec())
}
};
// Update last use (if needed)
if client.need_update_last_used() {
@@ -145,10 +176,26 @@ impl APIClientAuth {
Ok(Self {
client: client.clone(),
payload: None,
payload,
user,
})
}
/// Get an instance of Matrix client
pub async fn client(&self) -> anyhow::Result<RumaClient> {
self.user.matrix_client().await
}
/// Send request to matrix server
pub async fn send_request<R: OutgoingRequest<IncomingResponse = E>, E: IncomingResponse>(
&self,
request: R,
) -> anyhow::Result<E, HttpFailure> {
match self.client().await?.send_request(request).await {
Ok(e) => Ok(e),
Err(e) => Err(HttpFailure::MatrixClientError(e.to_string())),
}
}
}
impl FromRequest for APIClientAuth {
@@ -163,6 +210,24 @@ impl FromRequest for APIClientAuth {
Err(e) => return Box::pin(async { Err(e) }),
};
Box::pin(async move { Self::extract_auth(&req, remote_ip.0).await })
let mut payload = payload.take();
Box::pin(async move {
let payload_bytes = match Bytes::from_request(&req, &mut payload).await {
Ok(b) => {
if b.is_empty() {
None
} else {
Some(b)
}
}
Err(e) => {
log::error!("Failed to extract request payload! {e}");
None
}
};
Self::extract_auth(&req, remote_ip.0, payload_bytes).await
})
}
}

View File

@@ -48,6 +48,7 @@ async fn main() -> std::io::Result<()> {
// API routes
.route("/api", web::get().to(api::api_home))
.route("/api", web::post().to(api::api_home))
.route("/api/account/whoami", web::get().to(api::account::who_am_i))
})
.bind(&AppConfig::get().listen_address)?
.run()

23
src/server/api/account.rs Normal file
View File

@@ -0,0 +1,23 @@
use crate::extractors::client_auth::APIClientAuth;
use crate::server::HttpResult;
use actix_web::HttpResponse;
use ruma::api::client::account;
use ruma::DeviceId;
#[derive(serde::Serialize)]
struct WhoAmIResponse {
user_id: String,
device_id: Option<String>,
}
/// Get current user identity
pub async fn who_am_i(auth: APIClientAuth) -> HttpResult {
let res = auth
.send_request(account::whoami::v3::Request::default())
.await?;
Ok(HttpResponse::Ok().json(WhoAmIResponse {
user_id: res.user_id.to_string(),
device_id: res.device_id.as_deref().map(DeviceId::to_string),
}))
}

View File

@@ -2,6 +2,8 @@ use crate::extractors::client_auth::APIClientAuth;
use crate::server::HttpResult;
use actix_web::HttpResponse;
pub mod account;
/// API Home route
pub async fn api_home(auth: APIClientAuth) -> HttpResult {
Ok(HttpResponse::Ok().body(format!("Welcome user {}!", auth.user.user_id.0)))

View File

@@ -1,6 +1,7 @@
use actix_web::http::StatusCode;
use actix_web::{HttpResponse, ResponseError};
use std::error::Error;
use std::fmt::Debug;
pub mod api;
pub mod web_ui;
@@ -21,6 +22,10 @@ pub enum HttpFailure {
FetchUserConfig(anyhow::Error),
#[error("an unspecified internal error occurred: {0}")]
InternalError(#[from] anyhow::Error),
#[error("a matrix api client error occurred: {0}")]
MatrixApiClientError(#[from] ruma::api::client::Error),
#[error("a matrix client error occurred: {0}")]
MatrixClientError(String),
}
impl ResponseError for HttpFailure {
@@ -37,4 +42,4 @@ impl ResponseError for HttpFailure {
}
}
pub type HttpResult = std::result::Result<HttpResponse, HttpFailure>;
pub type HttpResult = Result<HttpResponse, HttpFailure>;

View File

@@ -8,10 +8,15 @@ use crate::app_config::AppConfig;
use crate::constants::TOKEN_LEN;
use crate::utils::{curr_time, format_time, rand_str};
type HttpClient = ruma::client::http_client::HyperNativeTls;
pub type RumaClient = ruma::Client<HttpClient>;
#[derive(Error, Debug)]
pub enum UserError {
#[error("failed to fetch user configuration: {0}")]
FetchUserConfig(S3Error),
#[error("missing matrix token")]
MissingMatrixToken,
}
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
@@ -220,4 +225,17 @@ impl UserConfig {
pub fn find_client_by_id_mut(&mut self, id: &APIClientID) -> Option<&mut APIClient> {
self.clients.iter_mut().find(|c| &c.id == id)
}
/// Get a matrix client instance for the current user
pub async fn matrix_client(&self) -> anyhow::Result<RumaClient> {
if self.matrix_token.is_empty() {
return Err(UserError::MissingMatrixToken.into());
}
Ok(ruma::Client::builder()
.homeserver_url(AppConfig::get().matrix_homeserver.to_string())
.access_token(Some(self.matrix_token.clone()))
.build()
.await?)
}
}