From 76d90f09f247dfdbe07c34a412764c30ba30d300 Mon Sep 17 00:00:00 2001 From: Ginger Date: Fri, 4 Dec 2026 14:54:10 -0500 Subject: [PATCH] refactor: Replace openidconnect crate with openid crate --- Cargo.lock | 672 +++++------------------------ Cargo.toml | 14 +- src/core/Cargo.toml | 2 +- src/core/config/mod.rs | 23 +- src/service/Cargo.toml | 8 +- src/service/client/dns_resolver.rs | 15 - src/service/oidc/mod.rs | 326 +++++++------- src/web/Cargo.toml | 2 +- src/web/pages/account/login.rs | 6 +- src/web/pages/oidc/complete.rs | 15 +- 10 files changed, 286 insertions(+), 797 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ca3bfecfa..4200b18eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -503,7 +503,23 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.119", + "syn 3.0.10", +] + +[[package]] +name = "biscuit" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e28fc7c56c61743a01d0d1b73e4fed68b8a4f032ea3a2d4bb8c6520a33fc05a" +dependencies = [ + "chrono", + "data-encoding", + "num-bigint", + "num-traits", + "once_cell", + "ring", + "serde", + "serde_json", ] [[package]] @@ -569,15 +585,6 @@ dependencies = [ "alloc-stdlib", ] -[[package]] -name = "bs58" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" -dependencies = [ - "tinyvec", -] - [[package]] name = "built" version = "0.9.0" @@ -666,7 +673,7 @@ dependencies = [ "semver", "serde", "serde_json", - "thiserror 2.0.21", + "thiserror", ] [[package]] @@ -740,10 +747,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" dependencies = [ "iana-time-zone", - "js-sys", "num-traits", "serde", - "wasm-bindgen", "windows-link", ] @@ -950,10 +955,10 @@ dependencies = [ "http", "http-body-util", "hyper", - "itertools 0.15.0", + "itertools", "lettre", "rand 0.10.4", - "reqwest 0.13.5", + "reqwest", "ruma", "ruminuwuity", "serde", @@ -1009,7 +1014,7 @@ dependencies = [ "mimalloc", "nix 0.32.0", "num-traits", - "openidconnect", + "openid", "opentelemetry", "opentelemetry-prometheus", "opentelemetry-semantic-conventions", @@ -1018,7 +1023,7 @@ dependencies = [ "prometheus", "rand 0.10.4", "regex", - "reqwest 0.13.5", + "reqwest", "resolvematrix", "ruma", "sanitize-filename", @@ -1029,7 +1034,7 @@ dependencies = [ "sha2 0.11.3", "smallstr", "smallvec", - "thiserror 2.0.21", + "thiserror", "tikv-jemalloc-ctl", "tikv-jemalloc-sys", "tikv-jemallocator", @@ -1066,7 +1071,7 @@ dependencies = [ name = "conduwuit_macros" version = "26.11.0" dependencies = [ - "itertools 0.15.0", + "itertools", "proc-macro2", "quote", "syn 3.0.10", @@ -1128,20 +1133,19 @@ dependencies = [ "httpdate", "image", "ipaddress", - "itertools 0.15.0", + "itertools", "lettre", "log", "loole", "lru-cache", "mime", "nonzero_ext", - "openidconnect", + "openid", "opentelemetry", "p256 0.14.0", "rand 0.10.4", "regex", - "reqwest 0.12.28", - "reqwest 0.13.5", + "reqwest", "resolvematrix", "ruma", "ruminuwuity", @@ -1178,19 +1182,19 @@ dependencies = [ "futures", "lettre", "memory-serve", - "openidconnect", + "openid", "ruma", "serde", "serde_json", "serde_urlencoded", - "thiserror 2.0.21", + "thiserror", "tower-http 0.7.1", "tower-sec-fetch", "tower-sessions", "tower-sessions-core", "tracing", "url", - "validator", + "validator 0.21.0", ] [[package]] @@ -1594,18 +1598,8 @@ version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25ae13da2f202d56bd7f91c25fba009e7717a1e4a1cc98a76d844b65ae912e9d" dependencies = [ - "darling_core 0.23.0", - "darling_macro 0.23.0", -] - -[[package]] -name = "darling" -version = "0.24.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed17f5901b6630b993ca003def43f2f8ef4014fc13b047b57aad617ff32bc2ec" -dependencies = [ - "darling_core 0.24.1", - "darling_macro 0.24.1", + "darling_core", + "darling_macro", ] [[package]] @@ -1621,41 +1615,17 @@ dependencies = [ "syn 2.0.119", ] -[[package]] -name = "darling_core" -version = "0.24.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6837e2cf7485aaae18f86181d2f0e9a7ed297a025e220aeabf63fdebd3a2ddff" -dependencies = [ - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn 3.0.10", -] - [[package]] name = "darling_macro" version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3984ec7bd6cfa798e62b4a642426a5be0e68f9401cfc2a01e3fa9ea2fcdb8d" dependencies = [ - "darling_core 0.23.0", + "darling_core", "quote", "syn 2.0.119", ] -[[package]] -name = "darling_macro" -version = "0.24.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ac7135c3ef02b2f7833bbeb1be5ba7f966dcde8a87c6b87f65a778d71a02785" -dependencies = [ - "darling_core 0.24.1", - "quote", - "syn 3.0.10", -] - [[package]] name = "data-encoding" version = "2.11.1" @@ -1685,7 +1655,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" dependencies = [ "const-oid 0.9.6", - "pem-rfc7468 0.7.0", + "pem-rfc7468", "zeroize", ] @@ -1696,7 +1666,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a996a108feb8b427a6e12fcf6af4aa83409b79d72c15337d7741368131ee004" dependencies = [ "const-oid 0.10.3", - "pem-rfc7468 1.0.0", "zeroize", ] @@ -1801,12 +1770,6 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" -[[package]] -name = "dyn-clone" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" - [[package]] name = "ecdsa" version = "0.16.9" @@ -1894,7 +1857,7 @@ dependencies = [ "generic-array", "group 0.13.0", "hkdf 0.12.4", - "pem-rfc7468 0.7.0", + "pem-rfc7468", "pkcs8 0.10.2", "rand_core 0.6.4", "sec1 0.7.3", @@ -1915,7 +1878,6 @@ dependencies = [ "ff 0.14.0", "group 0.14.0", "hybrid-array", - "pem-rfc7468 1.0.0", "pkcs8 0.11.0", "rand_core 0.10.1", "sec1 0.8.1", @@ -2363,7 +2325,7 @@ dependencies = [ "futures-core", "futures-sink", "http", - "indexmap 2.14.2", + "indexmap", "slab", "tokio", "tokio-util", @@ -2398,12 +2360,6 @@ dependencies = [ "tokio-util", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "hashbrown" version = "0.16.1" @@ -2493,7 +2449,7 @@ dependencies = [ "ipnet", "jni", "rand 0.10.4", - "thiserror 2.0.21", + "thiserror", "tinyvec", "tokio", "tracing", @@ -2515,7 +2471,7 @@ dependencies = [ "rand 0.10.4", "ring", "serde", - "thiserror 2.0.21", + "thiserror", "tinyvec", "tracing", "url", @@ -2543,7 +2499,7 @@ dependencies = [ "serde", "smallvec", "system-configuration", - "thiserror 2.0.21", + "thiserror", "tokio", "tracing", ] @@ -2584,6 +2540,12 @@ dependencies = [ "digest 0.11.3", ] +[[package]] +name = "hmac-sha256" +version = "1.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad320b3b96fb2a455a0726d16efe0a5afdbd34b71dea5bc53b05ea057714d4e" + [[package]] name = "hostname" version = "0.4.2" @@ -2708,7 +2670,6 @@ dependencies = [ "hyper", "hyper-util", "rustls", - "rustls-native-certs", "tokio", "tokio-rustls", "tower-service", @@ -2911,17 +2872,6 @@ dependencies = [ "quick-error", ] -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", - "serde", -] - [[package]] name = "indexmap" version = "2.14.2" @@ -2985,15 +2935,6 @@ dependencies = [ "serde", ] -[[package]] -name = "itertools" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" -dependencies = [ - "either", -] - [[package]] name = "itertools" version = "0.15.0" @@ -3009,110 +2950,6 @@ version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" -[[package]] -name = "jiff" -version = "0.2.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "175dc66334db3b9ab9985bf8b61cfed50dc16d20964bb47f9e479adcae984a7f" -dependencies = [ - "jiff-core 0.1.8", - "jiff-static 0.2.46", - "jiff-tzdb-platform 0.1.3", - "log", - "portable-atomic", - "portable-atomic-util", - "serde_core", - "windows-link", -] - -[[package]] -name = "jiff" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "107f2e89536b6818514025f6787b0d94d819e54fe3b40365275fc753de485b3f" -dependencies = [ - "jiff-core 1.0.2", - "jiff-static 1.0.3", - "jiff-tzdb-platform 1.0.0", - "log", - "portable-atomic", - "portable-atomic-util", - "serde_core", - "windows-link", -] - -[[package]] -name = "jiff-core" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e599b80292e597019b8b3e392de3f4bea2959ddfb8c7dff60e035e9e311a2c1b" -dependencies = [ - "log", -] - -[[package]] -name = "jiff-core" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d44c923edf2bf456a982253f1a9ee1f6e89e421dffd0065d9b9a581da0def58f" -dependencies = [ - "log", -] - -[[package]] -name = "jiff-static" -version = "0.2.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7b1af7547d47354bc438d797e3854601bde8f8d185780c5ba4ab27afa54f1ba" -dependencies = [ - "jiff-core 0.1.8", - "proc-macro2", - "quote", - "syn 2.0.119", -] - -[[package]] -name = "jiff-static" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4996f71e569e3a3e32b925c28ef8f0027dc30bb1d594b33eeda409eea185f5c8" -dependencies = [ - "jiff-core 1.0.2", - "proc-macro2", - "quote", - "syn 3.0.10", -] - -[[package]] -name = "jiff-tzdb" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0980fca2cc272465bd60e82397607ba9f33add9e48defd77923301bbd03808f2" - -[[package]] -name = "jiff-tzdb" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12e71a1b68a875a44a33bb7a1dd84392cb77145a3367a552a3cfe6a4f5cf3afc" - -[[package]] -name = "jiff-tzdb-platform" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "875a5a69ac2bab1a891711cf5eccbec1ce0341ea805560dcd90b7a2e925132e8" -dependencies = [ - "jiff-tzdb 0.1.10", -] - -[[package]] -name = "jiff-tzdb-platform" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc65b284afcfa8f6cf189c7274c805505314a7ab975c60e1f548bff56525420e" -dependencies = [ - "jiff-tzdb 1.0.0", -] - [[package]] name = "jni" version = "0.22.4" @@ -3125,7 +2962,7 @@ dependencies = [ "jni-sys", "log", "simd_cesu8", - "thiserror 2.0.21", + "thiserror", "walkdir", "windows-link", ] @@ -3239,9 +3076,6 @@ name = "lazy_static" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb" -dependencies = [ - "spin", -] [[package]] name = "lettre" @@ -3289,12 +3123,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "libm" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" - [[package]] name = "libmimalloc-sys" version = "0.1.49" @@ -3699,22 +3527,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-bigint-dig" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e661dda6640fad38e827a6d4a310ff4763082116fe217f279885c97f511bb0b7" -dependencies = [ - "lazy_static", - "libm", - "num-integer", - "num-iter", - "num-traits", - "rand 0.8.8", - "smallvec", - "zeroize", -] - [[package]] name = "num-complex" version = "0.4.6" @@ -3767,7 +3579,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", - "libm", ] [[package]] @@ -3780,26 +3591,6 @@ dependencies = [ "libc", ] -[[package]] -name = "oauth2" -version = "5.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51e219e79014df21a225b1860a479e2dcd7cbd9130f4defd4bd0e191ea31d67d" -dependencies = [ - "base64 0.22.1", - "chrono", - "getrandom 0.2.17", - "http", - "rand 0.8.8", - "reqwest 0.12.28", - "serde", - "serde_json", - "serde_path_to_error", - "sha2 0.10.9", - "thiserror 1.0.69", - "url", -] - [[package]] name = "objc2" version = "0.6.5" @@ -3985,35 +3776,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] -name = "openidconnect" -version = "4.1.0" +name = "openid" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df0d098a59353679624d406825940139e2b2d554a52b64c9fb1b1bc42a11fe5c" +checksum = "d92f62c01cb19c6e3dbf34c84e4b0c774bcfbaa179b6397339754da145497bd7" dependencies = [ "base64 0.22.1", + "biscuit", "chrono", - "dyn-clone", - "ed25519-dalek", "getrandom 0.4.3", - "hmac 0.12.1", - "http", - "itertools 0.14.0", - "log", - "oauth2", - "p256 0.14.0", - "p384", - "rand 0.8.8", - "rsa", + "hmac-sha256", + "mime", + "reqwest", "serde", - "serde-value", "serde_json", - "serde_path_to_error", - "serde_plain", - "serde_with", - "sha2 0.10.9", - "subtle", - "thiserror 1.0.69", + "thiserror", "url", + "validator 0.20.0", ] [[package]] @@ -4032,7 +3811,7 @@ dependencies = [ "futures-sink", "js-sys", "pin-project-lite", - "thiserror 2.0.21", + "thiserror", "tracing", ] @@ -4046,7 +3825,7 @@ dependencies = [ "bytes", "http", "opentelemetry", - "reqwest 0.13.5", + "reqwest", ] [[package]] @@ -4078,8 +3857,8 @@ dependencies = [ "opentelemetry-proto", "opentelemetry_sdk", "prost", - "reqwest 0.13.5", - "thiserror 2.0.21", + "reqwest", + "thiserror", "tokio", "tonic", "tonic-types", @@ -4130,20 +3909,11 @@ dependencies = [ "percent-encoding", "portable-atomic", "rand 0.9.5", - "thiserror 2.0.21", + "thiserror", "tokio", "tokio-stream", ] -[[package]] -name = "ordered-float" -version = "2.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f19d67e5a2795c94e73e0bb1cc1a7edeb2e28efd39e2e1c9b7a40c1108b11c" -dependencies = [ - "num-traits", -] - [[package]] name = "os_info" version = "3.15.0" @@ -4185,20 +3955,6 @@ dependencies = [ "sha2 0.11.3", ] -[[package]] -name = "p384" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d17b851e6b3e378ab4ecb07fa2ed23f4d15f075735f8fec9fa1e7bdce5f8301f" -dependencies = [ - "ecdsa 0.17.0", - "elliptic-curve 0.14.3", - "fiat-crypto", - "primefield", - "primeorder 0.14.0", - "sha2 0.11.3", -] - [[package]] name = "parking" version = "2.2.1" @@ -4272,15 +4028,6 @@ dependencies = [ "base64ct", ] -[[package]] -name = "pem-rfc7468" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6305423e0e7738146434843d1694d621cce767262b2a86910beab705e4493d9" -dependencies = [ - "base64ct", -] - [[package]] name = "percent-encoding" version = "2.3.2" @@ -4294,7 +4041,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.14.2", + "indexmap", ] [[package]] @@ -4373,17 +4120,6 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c938015719552d665fd0553b90d96cd7ff58e83e4c061ca99e6bb78865a72752" -[[package]] -name = "pkcs1" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" -dependencies = [ - "der 0.7.10", - "pkcs8 0.10.2", - "spki 0.7.3", -] - [[package]] name = "pkcs8" version = "0.10.2" @@ -4441,15 +4177,6 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85" -[[package]] -name = "portable-atomic-util" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10ab3eb7f3becc3a1cbc4f2c6f20267996cfc1a6467a873763411b136a122715" -dependencies = [ - "portable-atomic", -] - [[package]] name = "potential_utf" version = "0.1.6" @@ -4593,7 +4320,7 @@ dependencies = [ "lazy_static", "memchr", "parking_lot", - "thiserror 2.0.21", + "thiserror", ] [[package]] @@ -4613,7 +4340,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad9c5423459fa2f729b8d9235fab810aa29628b171467744fc86d21460ad70d" dependencies = [ "anyhow", - "itertools 0.15.0", + "itertools", "proc-macro2", "quote", "syn 2.0.119", @@ -4673,7 +4400,7 @@ dependencies = [ "rustc-hash", "rustls", "socket2", - "thiserror 2.0.21", + "thiserror", "tokio", "tracing", "web-time", @@ -4696,7 +4423,7 @@ dependencies = [ "rustls", "rustls-pki-types", "slab", - "thiserror 2.0.21", + "thiserror", "tinyvec", "tracing", "web-time", @@ -4743,24 +4470,13 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" -[[package]] -name = "rand" -version = "0.8.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e058c7de0b26af77780c769414d6257830bb240f3c38477dbc2c16e5f54d6d4c" -dependencies = [ - "libc", - "rand_chacha 0.3.1", - "rand_core 0.6.4", -] - [[package]] name = "rand" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9ef1d0d795eb7d84685bca4f72f3649f064e6641543d3a8c415898726a57b41" dependencies = [ - "rand_chacha 0.9.0", + "rand_chacha", "rand_core 0.9.5", ] @@ -4775,16 +4491,6 @@ dependencies = [ "rand_core 0.10.1", ] -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core 0.6.4", -] - [[package]] name = "rand_chacha" version = "0.9.0" @@ -4837,26 +4543,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "ref-cast" -version = "1.0.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e440fb4e4b4147295338efb76001ab9e4efc0e5839df2c47fc5ac2381d365c3" -dependencies = [ - "ref-cast-impl", -] - -[[package]] -name = "ref-cast-impl" -version = "1.0.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92ecd8964f8453721699a1ed72037b0db49ce2f5a5138486ee89bed6f67cdf3a" -dependencies = [ - "proc-macro2", - "quote", - "syn 3.0.10", -] - [[package]] name = "regex" version = "1.13.2" @@ -4886,43 +4572,6 @@ version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d902046e6a28a1e4c3cab97258a0ce11e994903f01c2d97a9447a0b3df85f4f6" -[[package]] -name = "reqwest" -version = "0.12.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" -dependencies = [ - "base64 0.22.1", - "bytes", - "futures-core", - "http", - "http-body", - "http-body-util", - "hyper", - "hyper-rustls", - "hyper-util", - "js-sys", - "log", - "percent-encoding", - "pin-project-lite", - "rustls", - "rustls-native-certs", - "rustls-pki-types", - "serde", - "serde_json", - "serde_urlencoded", - "sync_wrapper", - "tokio", - "tokio-rustls", - "tower", - "tower-http 0.6.11", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", -] - [[package]] name = "reqwest" version = "0.13.5" @@ -4984,10 +4633,10 @@ dependencies = [ "hickory-resolver", "num-traits", "parking_lot", - "reqwest 0.13.5", + "reqwest", "serde", "serde_json", - "thiserror 2.0.21", + "thiserror", "tokio-stream", "tracing", ] @@ -5026,26 +4675,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "rsa" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8573f03f5883dcaebdfcf4725caa1ecb9c15b2ef50c43a07b816e06799bb12d" -dependencies = [ - "const-oid 0.9.6", - "digest 0.10.7", - "num-bigint-dig", - "num-integer", - "num-traits", - "pkcs1", - "pkcs8 0.10.2", - "rand_core 0.6.4", - "signature 2.2.0", - "spki 0.7.3", - "subtle", - "zeroize", -] - [[package]] name = "ruma" version = "0.18.0" @@ -5095,7 +4724,7 @@ dependencies = [ "serde", "serde_html_form", "serde_json", - "thiserror 2.0.21", + "thiserror", "url", "web-time", ] @@ -5112,7 +4741,7 @@ dependencies = [ "form_urlencoded", "getrandom 0.4.3", "http", - "indexmap 2.14.2", + "indexmap", "js_int", "konst", "percent-encoding", @@ -5123,7 +4752,7 @@ dependencies = [ "serde", "serde_html_form", "serde_json", - "thiserror 2.0.21", + "thiserror", "time", "tracing", "url", @@ -5139,7 +4768,7 @@ version = "0.36.0" source = "git+https://github.com/ruma/ruma.git?rev=d6621e1355419c5ef9a7c260b28ae1c0e6722b86#d6621e1355419c5ef9a7c260b28ae1c0e6722b86" dependencies = [ "as_variant", - "indexmap 2.14.2", + "indexmap", "js_int", "js_option", "pulldown-cmark", @@ -5147,7 +4776,7 @@ dependencies = [ "ruma-macros", "serde", "serde_json", - "thiserror 2.0.21", + "thiserror", "tracing", "web-time", "wildmatch", @@ -5172,7 +4801,7 @@ dependencies = [ "ruma-signatures", "serde", "serde_json", - "thiserror 2.0.21", + "thiserror", "tracing", ] @@ -5182,7 +4811,7 @@ version = "0.14.1" source = "git+https://github.com/ruma/ruma.git?rev=d6621e1355419c5ef9a7c260b28ae1c0e6722b86#d6621e1355419c5ef9a7c260b28ae1c0e6722b86" dependencies = [ "js_int", - "thiserror 2.0.21", + "thiserror", ] [[package]] @@ -5227,7 +4856,7 @@ dependencies = [ "ruma-events", "serde_json", "sha2 0.11.3", - "thiserror 2.0.21", + "thiserror", ] [[package]] @@ -5241,7 +4870,7 @@ dependencies = [ "ruma-signatures", "serde", "serde_json", - "thiserror 2.0.21", + "thiserror", "tracing", ] @@ -5418,7 +5047,7 @@ dependencies = [ "futures-util", "pin-project", "thingbuf", - "thiserror 2.0.21", + "thiserror", "unicode-segmentation", ] @@ -5455,30 +5084,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "schemars" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd191f9397d57d581cddd31014772520aa448f65ef991055d7f61582c65165f" -dependencies = [ - "dyn-clone", - "ref-cast", - "serde", - "serde_json", -] - -[[package]] -name = "schemars" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab508826f74a77ca9d5aba6ff19b522583ee3eaf28a19384ff3d0e5835fadf6e" -dependencies = [ - "dyn-clone", - "ref-cast", - "serde", - "serde_json", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -5563,7 +5168,7 @@ checksum = "d7bc7fb14982f395d53924f4feebd48c6cc136399c49ac2160dcf2b260e74b75" dependencies = [ "cfg_aliases", "httpdate", - "reqwest 0.13.5", + "reqwest", "sentry-backtrace", "sentry-contexts", "sentry-core", @@ -5681,7 +5286,7 @@ dependencies = [ "rand 0.10.4", "serde", "serde_json", - "thiserror 2.0.21", + "thiserror", "time", "url", "uuid", @@ -5704,7 +5309,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "969cde0349344dbbf58b5f9badbfb8f806db13969364eb8007c057ef687007d9" dependencies = [ "annotate-snippets", - "base64 0.22.1", + "base64 0.23.1", "encoding_rs_io", "granit-parser", "nohash-hasher", @@ -5714,16 +5319,6 @@ dependencies = [ "zmij", ] -[[package]] -name = "serde-value" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c" -dependencies = [ - "ordered-float", - "serde", -] - [[package]] name = "serde_core" version = "1.0.229" @@ -5751,7 +5346,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5cb47bbdfe5aaf62921705c1be39c4bde7da0ac74cb3d64f3038869c7097ae2f" dependencies = [ "form_urlencoded", - "indexmap 2.14.2", + "indexmap", "itoa", "serde_core", "zmij", @@ -5763,6 +5358,8 @@ version = "1.0.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" dependencies = [ + "foldhash", + "indexmap", "itoa", "memchr", "serde", @@ -5781,15 +5378,6 @@ dependencies = [ "serde_core", ] -[[package]] -name = "serde_plain" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1fc6db65a611022b23a0dec6975d63fb80a302cb3388835ff02c097258d50" -dependencies = [ - "serde", -] - [[package]] name = "serde_regex" version = "1.2.0" @@ -5830,40 +5418,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_with" -version = "3.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56cb1ca7c93ae63d6439b5250f6b6b040f7e121f32e5dd2f5d523dd4149b3204" -dependencies = [ - "base64 0.23.1", - "bs58", - "chrono", - "hex", - "indexmap 1.9.3", - "indexmap 2.14.2", - "jiff 0.2.46", - "jiff 1.0.3", - "schemars 0.9.0", - "schemars 1.2.3", - "serde_core", - "serde_json", - "serde_with_macros", - "time", -] - -[[package]] -name = "serde_with_macros" -version = "3.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff15a7c864bbec77d9586ca6822bc7c369bdf19e9243134a62b0b51ce26b31f" -dependencies = [ - "darling 0.24.1", - "proc-macro2", - "quote", - "syn 3.0.10", -] - [[package]] name = "serdect" version = "0.4.3" @@ -6060,12 +5614,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "spin" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3763264f6b73151db08c50ff20d7d8a0b8796e021cdea7ceedad07b80155fa0e" - [[package]] name = "spinning_top" version = "0.3.1" @@ -6234,7 +5782,7 @@ dependencies = [ "lazy-regex", "minimad", "serde", - "thiserror 2.0.21", + "thiserror", "unicode-width 0.1.14", ] @@ -6248,33 +5796,13 @@ dependencies = [ "pin-project", ] -[[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.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e" dependencies = [ - "thiserror-impl 2.0.21", -] - -[[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 2.0.119", + "thiserror-impl", ] [[package]] @@ -6463,7 +5991,7 @@ version = "1.2.3+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26b1f26e9485c1fa43ee89fe76e9f3fb9e2e52bb227f8594b4d687496b83d073" dependencies = [ - "indexmap 2.14.2", + "indexmap", "serde_core", "serde_spanned 1.1.3", "toml_datetime 1.1.3+spec-1.1.0", @@ -6496,7 +6024,7 @@ version = "0.22.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" dependencies = [ - "indexmap 2.14.2", + "indexmap", "serde", "serde_spanned 0.6.9", "toml_datetime 0.6.11", @@ -6510,7 +6038,7 @@ version = "0.25.21+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88497dab46de5bf343ec66b05c251e48c6213f3e9170c70a70a823f7abe886a4" dependencies = [ - "indexmap 2.14.2", + "indexmap", "toml_datetime 1.1.3+spec-1.1.0", "toml_parser", "winnow 1.0.5", @@ -6597,7 +6125,7 @@ checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" dependencies = [ "futures-core", "futures-util", - "indexmap 2.14.2", + "indexmap", "pin-project-lite", "slab", "sync_wrapper", @@ -6727,7 +6255,7 @@ dependencies = [ "rand 0.9.5", "serde", "serde_json", - "thiserror 2.0.21", + "thiserror", "time", "tokio", "tracing", @@ -6961,6 +6489,22 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "validator" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43fb22e1a008ece370ce08a3e9e4447a910e92621bb49b85d6e48a45397e7cfa" +dependencies = [ + "idna", + "once_cell", + "regex", + "serde", + "serde_derive", + "serde_json", + "url", + "validator_derive", +] + [[package]] name = "validator" version = "0.21.0" @@ -6982,7 +6526,7 @@ version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240e4b81c20a1d6d50d1d7265c658dfbd204e8b9ac4d80f3c931f39462196335" dependencies = [ - "darling 0.23.0", + "darling", "proc-macro-error3", "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 6926aa125..94fd67a98 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -166,15 +166,6 @@ features = [ "form", ] -# Needed for as long as openidconnect is on an outdated reqwest -[workspace.dependencies.reqwest_0_12] -package = "reqwest" -version = "0.12" -default-features = false -features = [ - "rustls-tls-native-roots-no-provider", -] - [workspace.dependencies.serde] version = "1.0.229" default-features = false @@ -422,10 +413,9 @@ default-features = false version = "0.11.0" default-features = false -[workspace.dependencies.openidconnect] -version = "4.1.0" +[workspace.dependencies.openid] +version = "0.26.0" default-features = false -features = ["reqwest"] # optional opentelemetry, performance measurements, flamegraphs, etc for performance measurements and monitoring [workspace.dependencies.opentelemetry] diff --git a/src/core/Cargo.toml b/src/core/Cargo.toml index 9377f57b0..5bf539106 100644 --- a/src/core/Cargo.toml +++ b/src/core/Cargo.toml @@ -117,7 +117,7 @@ prometheus.workspace = true lock_api.workspace = true hyper-util.workspace = true resolvematrix.workspace = true -openidconnect.workspace = true +openid.workspace = true libmimalloc-sys.optional = true libmimalloc-sys.workspace = true mimalloc.optional = true diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index 43a471d49..ec34c2d8b 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -23,7 +23,6 @@ use figment::providers::{Env, Format, Toml}; pub use figment::{Figment, value::Value as FigmentValue}; use governor::{DefaultKeyedRateLimiter, Quota, RateLimiter}; use lettre::message::Mailbox; -use openidconnect::{Audience, ClientId, ClientSecret, Scope}; use regex::RegexSet; use ruma::{ OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId, @@ -2802,15 +2801,15 @@ pub struct OidcConfig { /// automatically fetch the identity provider's metadata from this URL. /// Generally you should set this to the base domain your identity provider /// runs on. - pub discovery_url: String, + pub discovery_url: Url, /// The OAuth client ID for Continuwuity to use when communicating with the /// identity provider. - pub client_id: ClientId, + pub client_id: String, /// The OAuth client secret for Continuwuity to use when communicating with /// the identity provider. - pub client_secret: Option, + pub client_secret: Option, /// A path to a file which Continuwuity will read the client secret from. /// If this option is set, it will override `client_secret`. @@ -2826,19 +2825,7 @@ pub struct OidcConfig { /// /// default: ["profile"] #[serde(default = "default_additional_scopes")] - pub additional_scopes: Vec, - - /// Additional trusted audiences that Continuwuity will accept in the `aud` - /// claim of the OIDC token returned by the IDP. If your identity - /// provider includes other values in the `aud` claim in addition to the - /// client ID, they must be listed here for Continuwuity to accept them. - /// - /// Most deployments will not need to set this, because most identity - /// providers only include the client ID in the `aud` claim by default. - /// - /// default: [] - #[serde(default)] - pub additional_trusted_audiences: BTreeSet, + pub additional_scopes: Vec, /// The name of the identity provider. If this is set, the login page's /// button reads "Continue with " instead of just "Continue". @@ -3444,7 +3431,7 @@ fn default_unauthenticated_request_ratelimit() -> PerMinut PerMinuteRatelimiter::new(Quota::per_minute(30.try_into().unwrap())) } -fn default_additional_scopes() -> Vec { vec![Scope::new("profile".to_owned())] } +fn default_additional_scopes() -> Vec { vec!["profile".to_owned()] } // NOTE: This must be declared *after* every config struct in this file. The // example config generator writes sections in macro expansion order, and the diff --git a/src/service/Cargo.toml b/src/service/Cargo.toml index 49e57208a..cebf84e5d 100644 --- a/src/service/Cargo.toml +++ b/src/service/Cargo.toml @@ -130,10 +130,7 @@ yansi.workspace = true lettre.workspace = true resolvematrix.workspace = true serde_urlencoded.workspace = true -openidconnect.workspace = true -# We use this to set TLS backend features on the outdated reqwest bundled by openidconnect, -# which is necessary to call `danger_accept_invalid_certs`. -reqwest_0_12.workspace = true +openid.workspace = true rand.workspace = true [target.'cfg(all(unix, target_os = "linux"))'.dependencies] @@ -143,9 +140,6 @@ sd-notify.optional = true [lints] workspace = true -[package.metadata.cargo-shear] -ignored = ["reqwest_0_12"] - [dev-dependencies] opentelemetry.workspace = true rustls = { workspace = true, features = ["ring"] } diff --git a/src/service/client/dns_resolver.rs b/src/service/client/dns_resolver.rs index 97c534704..9dd20a374 100644 --- a/src/service/client/dns_resolver.rs +++ b/src/service/client/dns_resolver.rs @@ -44,18 +44,3 @@ impl reqwest::dns::Resolve for DnsResolver { }) } } - -// openidconnect is weird and vendors reqwest (?), therefore we have to -// completely re-implement Resolve with different types -impl openidconnect::reqwest::dns::Resolve for DnsResolver { - fn resolve(&self, name: openidconnect::reqwest::dns::Name) -> Resolving { - let resolver = self.resolver.clone(); - Box::pin(async move { - let lookup = resolver.lookup_ip(name.as_str()).await?; - let addrs: Addrs = Box::new(SocketAddrs { - iter: lookup.iter().collect::>().into_iter(), - }); - Ok(addrs) - }) - } -} diff --git a/src/service/oidc/mod.rs b/src/service/oidc/mod.rs index a1632baf9..9e6e05477 100644 --- a/src/service/oidc/mod.rs +++ b/src/service/oidc/mod.rs @@ -1,26 +1,19 @@ -use std::{collections::HashMap, net::IpAddr, str::FromStr, sync::Arc, time::Duration}; +use std::{ + collections::{HashMap, HashSet}, + net::IpAddr, + str::FromStr, + sync::Arc, +}; use async_trait::async_trait; use conduwuit::{ Result, SyncRwLock, config::{OidcConfig, OidcProfileKeyImportMode}, - debug, err, error, info, warn, + debug, err, error, info, utils, warn, }; use database::{Deserialized, Map}; use lettre::Address; -use openidconnect::{ - AdditionalClaims, AuthorizationCode, ClaimsVerificationError, ClientSecret, CsrfToken, - EmptyExtraTokenFields, EndpointMaybeSet, EndpointNotSet, EndpointSet, IdTokenClaims, - IdTokenFields, IssuerUrl, Nonce, PkceCodeChallenge, PkceCodeVerifier, RedirectUrl, - SignatureVerificationError, StandardErrorResponse, StandardTokenResponse, TokenResponse, - core::{ - CoreAuthDisplay, CoreAuthPrompt, CoreAuthenticationFlow, CoreErrorResponseType, - CoreGenderClaim, CoreJsonWebKey, CoreJweContentEncryptionAlgorithm, - CoreJwsSigningAlgorithm, CoreProviderMetadata, CoreRevocableToken, - CoreRevocationErrorResponse, CoreTokenIntrospectionResponse, CoreTokenType, - }, - reqwest, -}; +use openid::{Claims as _, Options, StandardClaims, Token}; use ruma::{ OwnedUserId, UserId, api::client::profile::PropagateTo, @@ -50,6 +43,7 @@ struct Data { openidsubjectprofilefield_url: Arc, } struct Services { + client: Dep, config: Dep, globals: Dep, media: Dep, @@ -58,56 +52,61 @@ struct Services { } struct OidcClient { + client_secret: String, config: OidcConfig, - client_secret: ClientSecret, - machine: SetOnce>>, - client: reqwest::Client, + client: SetOnce>>, } -type OidcClientMachine = openidconnect::Client< - AllClaims, - CoreAuthDisplay, - CoreGenderClaim, - CoreJweContentEncryptionAlgorithm, - CoreJsonWebKey, - CoreAuthPrompt, - StandardErrorResponse, - StandardTokenResponse< - IdTokenFields< - AllClaims, - EmptyExtraTokenFields, - CoreGenderClaim, - CoreJweContentEncryptionAlgorithm, - CoreJwsSigningAlgorithm, - >, - CoreTokenType, - >, - CoreTokenIntrospectionResponse, - CoreRevocableToken, - CoreRevocationErrorResponse, - EndpointSet, - EndpointNotSet, - EndpointNotSet, - EndpointNotSet, - EndpointMaybeSet, - EndpointMaybeSet, ->; - -pub type Claims = IdTokenClaims; +type IdpClient = openid::Client; #[derive(Clone, Debug, Deserialize, Serialize)] -pub struct AllClaims { +pub struct Claims { #[serde(flatten)] - pub claims: HashMap, + standard_claims: StandardClaims, + + #[serde(flatten)] + other_claims: HashMap, } -impl AdditionalClaims for AllClaims {} +impl Claims { + fn get(&self, key: &str) -> Option<&Value> { self.other_claims.get(key) } +} + +macro_rules! standard { + ($($field:ident: $type:ty),*$(,)?) => { + $( + fn $field(&self) -> $type { + self.standard_claims.$field() + } + )* + } +} + +impl openid::Claims for Claims { + standard! { + userinfo: &openid::Userinfo, + c_hash: Option<&String>, + at_hash: Option<&String>, + iss: &Url, + sub: &str, + aud: &openid::SingleOrMultiple, + exp: i64, + iat: i64, + auth_time: Option, + nonce: Option<&String>, + acr: Option<&String>, + amr: Option<&Vec>, + azp: Option<&String>, + } +} + +impl openid::CompactJson for Claims {} #[derive(Debug, Deserialize, Serialize)] pub struct PendingSession { - pkce_verifier: PkceCodeVerifier, - nonce: Nonce, - csrf_token: CsrfToken, + pkce_verifier: String, + nonce: String, + csrf_token: String, } pub enum SessionCompletionStatus { @@ -135,54 +134,33 @@ impl crate::Service for Service { fn build(args: crate::Args<'_>) -> Result> { Ok(Arc::new(Self { services: Services { + client: args.depend::("client"), config: args.depend::("config"), - globals: args.depend::("globals"), + globals: args.depend::("globals"), media: args.depend::("media"), - threepid: args.depend::("threepid"), - users: args.depend::("users"), + threepid: args.depend::("threepid"), + users: args.depend::("users"), }, runtime: args.server.runtime().clone(), - db: Data { - openidsubject_localpart: args.db["openidsubject_localpart"].clone(), + db: Data { + openidsubject_localpart: args.db["openidsubject_localpart"].clone(), openidsubjectprofilefield_url: args.db["openidsubjectprofilefield_url"].clone(), - }, - client: args.server.config.oauth.oidc.as_ref().map(|config| -> Result { - Ok(OidcClient { - config: config.clone(), - client_secret: if let Some(client_secret_file) = &config.client_secret_file { - std::fs::read_to_string(client_secret_file) - .map(|client_secret| client_secret.trim().to_owned()) - .map(ClientSecret::new) - .map_err(|err| err!("Failed to read OIDC client secret file: {err}"))? - } else if let Some(client_secret) = &config.client_secret { - client_secret.clone() - } else { - // The config check function should cause an early exit before this happens - panic!("neither client secret or client secret file were set"); - }, - machine: SetOnce::new(), - // This isn't in the client service because it has to use the `reqwest` shipped by `openidconnect` - client: reqwest::ClientBuilder::new() - .dns_resolver(args.depend::("client").reqwest_resolver.clone()) - .connect_timeout(Duration::from_secs(args.server.config.request_conn_timeout)) - .read_timeout(Duration::from_secs(args.server.config.request_timeout)) - .timeout(Duration::from_secs(args.server.config.request_total_timeout)) - .pool_idle_timeout(Duration::from_secs(args.server.config.request_idle_timeout)) - .pool_max_idle_per_host(args.server.config.request_idle_per_host.into()) - .user_agent(conduwuit::user_agent()) - .redirect(reqwest::redirect::Policy::none()) - .danger_accept_invalid_certs(args.server.config.allow_invalid_tls_certificates_yes_i_know_what_the_fuck_i_am_doing_with_this_and_i_know_this_is_insecure) - .build() - .expect("client should build") - })} - ).transpose()?, + }, + client: args + .server + .config + .oauth + .oidc + .clone() + .map(Self::create_client) + .transpose()?, })) } async fn worker(self: Arc) -> Result { - if let Some(OidcClient { machine, .. }) = &self.client { + if let Some(OidcClient { client, .. }) = &self.client { let discovered = self.discover().await?; - machine + client .set(SyncRwLock::new(Arc::new(discovered))) .expect("machine should be empty"); } @@ -198,13 +176,36 @@ impl Service { // into the media repository. Keep this synced with the list in the // doc comment for `profile_key_map` in the config. const IMAGE_PROFILE_KEYS: &[&str] = &["avatar_url", "chat.commet.profile_banner"]; + const NONCE_SIZE: usize = 32; const SERVER_MISCONFIGURED: &str = "Identity server is misconfigured. Contact your homeserver's administrator."; + fn create_nonce() -> String { utils::random_string(Self::NONCE_SIZE) } + + fn create_client(config: OidcConfig) -> Result { + let client_secret = if let Some(client_secret_file) = &config.client_secret_file { + std::fs::read_to_string(client_secret_file) + .map(|client_secret| client_secret.trim().to_owned()) + .map_err(|err| err!("Failed to read OIDC client secret file: {err}"))? + } else if let Some(client_secret) = &config.client_secret { + client_secret.clone() + } else { + // The config check function should cause an early exit before this + // happens + panic!("neither client secret or client secret file were set"); + }; + + Ok(OidcClient { + client_secret, + config, + client: SetOnce::new(), + }) + } + pub fn enabled(&self) -> bool { self.client.is_some() } - async fn discover(&self) -> Result { - let OidcClient { config, client_secret, client, .. } = + async fn discover(&self) -> Result { + let OidcClient { config, client_secret, .. } = self.client.as_ref().expect("oidc should be configured"); let redirect_url = self @@ -214,20 +215,15 @@ impl Service { .join(&format!("{}/oidc/complete", conduwuit::ROUTE_PREFIX)) .expect("redirect url should be valid"); - let provider_metadata = CoreProviderMetadata::discover_async( - IssuerUrl::new(config.discovery_url.clone()) - .map_err(|err| err!("Failed to parse OIDC discovery URL: {err}"))?, - client, - ) - .await - .map_err(|err| err!("Failed to discover OIDC provider metadata: {err}"))?; - - Ok(OidcClientMachine::from_provider_metadata( - provider_metadata, + IdpClient::discover_with_client( + self.services.client.external_resource.clone(), config.client_id.clone(), Some(client_secret.clone()), + Some(redirect_url.to_string()), + config.discovery_url.clone(), ) - .set_redirect_uri(RedirectUrl::from_url(redirect_url))) + .await + .map_err(|err| err!("Failed to discover OIDC provider metadata: {err}")) } pub fn provider_name(&self) -> Option { @@ -256,29 +252,32 @@ impl Service { } } - pub async fn begin_session(&self, prompt: Option) -> (PendingSession, Url) { - let OidcClient { machine, config, .. } = + pub async fn begin_session(&self, prompt: Option) -> (PendingSession, Url) { + let OidcClient { client, config, .. } = self.client.as_ref().expect("oidc should be configured"); - let machine = machine.wait().await.read().clone(); + let client = client.wait().await.read().clone(); - let (pkce_challenge, pkce_verifier) = PkceCodeChallenge::new_random_sha256(); + let csrf_token = Self::create_nonce(); + let nonce = Self::create_nonce(); - let mut auth_url = machine - .authorize_url( - CoreAuthenticationFlow::AuthorizationCode, - CsrfToken::new_random, - Nonce::new_random, - ) - .add_scopes(config.additional_scopes.iter().cloned()) - .set_pkce_challenge(pkce_challenge); + let (auth_url, pkce) = client.auth_url_with_new_pkce(&Options { + // The client will add the `openid` scope for us. + scope: Some(config.additional_scopes.join(" ")), + state: Some(csrf_token.clone()), + nonce: Some(nonce.clone()), + prompt: prompt.map(|prompt| HashSet::from_iter([prompt])), - if let Some(prompt) = prompt { - auth_url = auth_url.add_prompt(prompt); - } + ..Default::default() + }); - let (auth_url, csrf_token, nonce) = auth_url.url(); - - (PendingSession { pkce_verifier, nonce, csrf_token }, auth_url) + ( + PendingSession { + pkce_verifier: pkce.code_verifier().to_owned(), + nonce, + csrf_token, + }, + auth_url, + ) } pub async fn exchange_code( @@ -286,78 +285,77 @@ impl Service { session: PendingSession, response: AuthorizationCodeResponse, ) -> Result { - let Some(OidcClient { machine, client, config, .. }) = self.client.as_ref() else { + let Some(OidcClient { client, .. }) = self.client.as_ref() else { return Err("Delegated authentication is not enabled on this server."); }; - let current = machine.wait().await.read().clone(); + let current = client.wait().await.read().clone(); - if session.csrf_token.into_secret() != response.state { + if session.csrf_token != response.state { return Err("State mismatch."); } let token_response = current - .exchange_code(AuthorizationCode::new(response.code)) - .expect("machine should be configured correctly") - .set_pkce_verifier(session.pkce_verifier) - .request_async(client) + .request_token_pkce(&response.code, Some(&session.pkce_verifier)) .await + .map(Token::::from) .map_err(|err| { error!(error=?err, "Failed to exchange OIDC authorization code"); "Code exchange failed. The identity provider may be unreachable. Contact your \ homeserver's administrator." })?; - let Some(id_token) = token_response.id_token() else { + let Some(mut id_token) = token_response.id_token else { error!("Identity server did not return an id token"); return Err(Self::SERVER_MISCONFIGURED); }; - let verify = |machine: &OidcClientMachine| { - let verifier = - machine - .id_token_verifier() - .set_other_audience_verifier_fn(|audience| { - config.additional_trusted_audiences.contains(audience) - }); + if let Err(err) = current.decode_token(&mut id_token) { + error!(error=?err, "Failed to decode ID token"); + return Err(Self::SERVER_MISCONFIGURED); + } - id_token - .claims(&verifier, &session.nonce) - .map(ToOwned::to_owned) + let verify = |client: &IdpClient| { + client.validate_token(&id_token, Some(session.nonce.as_str()), None) }; let mut result = verify(¤t); if matches!( result, - Err(ClaimsVerificationError::SignatureVerification( - SignatureVerificationError::NoMatchingKey - )) + Err(openid::error::Error::Jose(openid::error::Jose::ValidationError( + openid::biscuit::errors::ValidationError::KeyNotFound + ))) ) { match self.discover().await { | Ok(discovered) => { info!("Refreshed OIDC provider metadata after an unknown signing key"); result = verify(&discovered); - *machine.wait().await.write() = Arc::new(discovered); + *client.wait().await.write() = Arc::new(discovered); }, | Err(err) => warn!("Failed to refresh OIDC provider metadata: {err}"), } } - let claims = result.map_err(|err| { - error!("Failed to verify id token claims: {err}"); - Self::SERVER_MISCONFIGURED - })?; + match result { + | Ok(()) => { + let (_, claims) = id_token.unwrap_decoded(); - info!(subject = claims.subject().as_str(), "Authenticated subject"); + info!(subject = claims.sub(), "Authenticated subject"); - Ok(claims) + Ok(claims) + }, + | Err(err) => { + error!("Failed to verify id token claims: {err}"); + Err(Self::SERVER_MISCONFIGURED) + }, + } } - #[tracing::instrument(skip(self, claims), fields(subject = claims.subject().to_string()))] + #[tracing::instrument(skip(self, claims), fields(subject = claims.sub().to_owned()))] pub async fn complete_session( &self, - claims: &Claims, + claims: Claims, supplied_user_id: Option, client_ip: &IpAddr, ) -> Result { @@ -365,21 +363,14 @@ impl Service { return Err("Delegated authentication is not enabled on this server."); }; - // this is a truly awful hack but we really need all the claims in a map - let all_claims = serde_json::to_value(claims) - .expect("should be able to serialize claims") - .as_object() - .expect("claims should be an object") - .to_owned(); + debug!(claims = ?claims.other_claims, "Got claims from the identity provider"); - debug!(?all_claims, "Got claims from the identity provider"); - - let subject = claims.subject().as_str(); + let subject = claims.sub().to_owned(); let user_id = if let Ok(localpart) = self .db .openidsubject_localpart - .get(subject) + .get(&subject) .await .deserialized::() { @@ -391,7 +382,7 @@ impl Service { } else { return Ok(SessionCompletionStatus::NeedsUserId); } - } else if let Some(preferred_username) = all_claims + } else if let Some(preferred_username) = claims .get(&config.preferred_username_claim) .and_then(|claim| claim.as_str()) { @@ -435,7 +426,7 @@ impl Service { }, }; - self.link_user(&user_id, subject); + self.link_user(&user_id, &subject); // Import profile fields if matches!(config.profile_key_import_mode, OidcProfileKeyImportMode::OnLogin) @@ -445,7 +436,7 @@ impl Service { ) && new_account_registered) { if let Some(email_claim) = &config.email_claim { - if let Some(email) = claims.email().map(|email| email.as_str()) + if let Some(email) = claims.get(email_claim).and_then(|email| email.as_str()) && let Ok(address) = Address::from_str(email) { if let Err(err) = self @@ -465,7 +456,6 @@ impl Service { } let user_id = user_id.clone(); - let subject = claims.subject().to_string(); let profile_key_map = config.profile_key_map.clone(); let openidsubjectprofilefield_url = self.db.openidsubjectprofilefield_url.clone(); let users = self.services.users.clone(); @@ -475,7 +465,7 @@ impl Service { // TODO: once we get support for full profile replacement, use // that logic instead for (field, claim) in &profile_key_map { - let Some(value) = all_claims.get(claim).cloned() else { + let Some(value) = claims.get(claim).cloned() else { warn!(?field, ?claim, "IDP provided no value for this mapped claim"); continue; }; diff --git a/src/web/Cargo.toml b/src/web/Cargo.toml index dd7187de9..10ae32c87 100644 --- a/src/web/Cargo.toml +++ b/src/web/Cargo.toml @@ -31,7 +31,7 @@ form_urlencoded = "1.2.2" futures.workspace = true lettre.workspace = true memory-serve = "2.4.0" -openidconnect.workspace = true +openid.workspace = true ruma.workspace = true serde.workspace = true serde_json.workspace = true diff --git a/src/web/pages/account/login.rs b/src/web/pages/account/login.rs index 44f9592d2..ca252c88a 100644 --- a/src/web/pages/account/login.rs +++ b/src/web/pages/account/login.rs @@ -7,7 +7,7 @@ use axum::{ routing::{get, on}, }; use conduwuit_api::client::handle_login; -use openidconnect::core::CoreAuthPrompt; +use openid::Prompt; use ruma::{ OwnedUserId, api::client::uiaa::{EmailUserIdentifier, MatrixUserIdentifier, UserIdentifier}, @@ -86,8 +86,8 @@ async fn route_login( let (session, redirect_url) = services .oidc .begin_session(match intent { - | Some(LoginIntent::SwitchAccounts) => Some(CoreAuthPrompt::SelectAccount), - | _ if reauthenticate => Some(CoreAuthPrompt::Consent), + | Some(LoginIntent::SwitchAccounts) => Some(Prompt::SelectAccount), + | _ if reauthenticate => Some(Prompt::Consent), | _ => None, }) .await; diff --git a/src/web/pages/oidc/complete.rs b/src/web/pages/oidc/complete.rs index f2e116eb8..9c6c1e07b 100644 --- a/src/web/pages/oidc/complete.rs +++ b/src/web/pages/oidc/complete.rs @@ -106,10 +106,7 @@ async fn route_complete( .await .expect("should be able to serialize oidc session"); - services - .oidc - .complete_session(&claims, None, &client_ip) - .await + Box::pin(services.oidc.complete_session(claims, None, &client_ip)).await }, | OidcSessionState::Authorized { claims } => { let supplied_user_id = if let Some(form) = form { @@ -166,10 +163,12 @@ async fn route_complete( None }; - services - .oidc - .complete_session(&claims, supplied_user_id, &client_ip) - .await + Box::pin( + services + .oidc + .complete_session(*claims, supplied_user_id, &client_ip), + ) + .await }, } .map_err(|err| WebError::BadRequest(err.to_owned()))?;