From d7200e03b621e0e4831954d02e37ee4fe35761cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 3 Sep 2026 03:16:17 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20OIDC=20single=20sign-on=20=E2=80=94=20p?= =?UTF-8?q?rovider,=20client=20crate,=20izlek=20migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - im-core: turso store (users, invites, sessions, OIDC clients, auth codes, refresh tokens, signing keys), argon2 passwords ported from izlek-core, RFC 6238 TOTP (hmac 0.13 + sha1 0.11), hand-rolled RS256 JWT over rsa 0.9, XChaCha20-Poly1305 sealing under im.key - im-web: topcoat server — login / TOTP / invite / enroll pages in İzlek's instrument skin (style/main.scss, grass build.rs), OIDC authorize + token + userinfo + JWKS + discovery, CLI: invite, create-client - im-client: drop-in OIDC client for topcoat apps — PKCE S256, JWKS-validated id_tokens, transparent refresh rotation, encrypted session cookie, demo example app - im-migrate: one-time izlek.db import, argon2 hashes verbatim, mapping CSV Verified live in a browser: invite -> password -> TOTP enrolment (QR) -> demo app OIDC handshake (silent via central session) and a full interactive password+TOTP login landing on the app's protected page with claims. --- .gitignore | 8 + Cargo.lock | 5330 +++++++++++++++++++++++++++++ Cargo.toml | 45 + config/im.toml | 12 + crates/im-client/Cargo.toml | 45 + crates/im-client/examples/demo.rs | 66 + crates/im-client/src/lib.rs | 710 ++++ crates/im-core/Cargo.toml | 58 + crates/im-core/src/accounts.rs | 510 +++ crates/im-core/src/keys.rs | 156 + crates/im-core/src/lib.rs | 23 + crates/im-core/src/model.rs | 100 + crates/im-core/src/oidc.rs | 552 +++ crates/im-core/src/secret.rs | 153 + crates/im-core/src/sessions.rs | 128 + crates/im-core/src/store.rs | 227 ++ crates/im-core/src/totp.rs | 199 ++ crates/im-migrate/Cargo.toml | 17 + crates/im-migrate/src/main.rs | 373 ++ crates/im-web/Cargo.toml | 47 + crates/im-web/assets/main.css | 341 ++ crates/im-web/build.rs | 17 + crates/im-web/src/auth.rs | 197 ++ crates/im-web/src/config.rs | 95 + crates/im-web/src/layout.rs | 48 + crates/im-web/src/main.rs | 197 ++ crates/im-web/src/oidc.rs | 361 ++ crates/im-web/src/pages.rs | 417 +++ crates/im-web/src/server.rs | 149 + style/main.scss | 374 ++ 30 files changed, 10955 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 config/im.toml create mode 100644 crates/im-client/Cargo.toml create mode 100644 crates/im-client/examples/demo.rs create mode 100644 crates/im-client/src/lib.rs create mode 100644 crates/im-core/Cargo.toml create mode 100644 crates/im-core/src/accounts.rs create mode 100644 crates/im-core/src/keys.rs create mode 100644 crates/im-core/src/lib.rs create mode 100644 crates/im-core/src/model.rs create mode 100644 crates/im-core/src/oidc.rs create mode 100644 crates/im-core/src/secret.rs create mode 100644 crates/im-core/src/sessions.rs create mode 100644 crates/im-core/src/store.rs create mode 100644 crates/im-core/src/totp.rs create mode 100644 crates/im-migrate/Cargo.toml create mode 100644 crates/im-migrate/src/main.rs create mode 100644 crates/im-web/Cargo.toml create mode 100644 crates/im-web/assets/main.css create mode 100644 crates/im-web/build.rs create mode 100644 crates/im-web/src/auth.rs create mode 100644 crates/im-web/src/config.rs create mode 100644 crates/im-web/src/layout.rs create mode 100644 crates/im-web/src/main.rs create mode 100644 crates/im-web/src/oidc.rs create mode 100644 crates/im-web/src/pages.rs create mode 100644 crates/im-web/src/server.rs create mode 100644 style/main.scss diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fb2078c --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +/target +/im.db +/im.db-shm +/im.db-wal +/im.key +/im-migrate-mapping.csv +/public/* +!/public/.gitkeep diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..0bc3871 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,5330 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "aead" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" +dependencies = [ + "crypto-common 0.1.7", + "generic-array", +] + +[[package]] +name = "aegis" +version = "0.9.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58541132f980da31e9aa99f7bdee69bc84bf1e168b9b91ef2dbe8abb7b4ce5dd" +dependencies = [ + "cc", + "softaes", +] + +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures 0.2.17", +] + +[[package]] +name = "aes-gcm" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" +dependencies = [ + "aead", + "aes", + "cipher", + "ctr", + "ghash", + "subtle", +] + +[[package]] +name = "ahash" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba" +dependencies = [ + "memchr", +] + +[[package]] +name = "alloc-no-stdlib" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" + +[[package]] +name = "alloc-stdlib" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e76a019e91224d279006ff972f1e984179a6e9feb050adba6ce8274aef23195" +dependencies = [ + "alloc-no-stdlib", +] + +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + +[[package]] +name = "allocator-api2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c880a97d28a3681c0267bd29cff89621202715b065127cd445fa0f0fe0aa2880" + +[[package]] +name = "android_system_properties" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + +[[package]] +name = "anstyle-parse" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.61.2", +] + +[[package]] +name = "antithesis_sdk" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08410fcac93669a476c006cd6c4512ac1e2b30fd117231a5d55d8a2c76599b82" +dependencies = [ + "libc", + "libloading", + "linkme", + "once_cell", + "rand 0.8.8", + "rustc_version_runtime", + "serde", + "serde_json", +] + +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + +[[package]] +name = "anymap3" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5dfbc6d8d2675589ccbe4d0fd61df2419075625f8c1a62325e718e2b0049f9" + +[[package]] +name = "arc-swap" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c049c0be4daef0b145cb3555416b3b8ef5b7888a38aea1a3a155801fe7b0810b" +dependencies = [ + "rustversion", +] + +[[package]] +name = "argon2" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "134c52ddac6d63c576bef8168db10c83c49c26444ecbc68060fef078925a901c" +dependencies = [ + "base64ct", + "blake2", + "cpufeatures 0.3.1", + "password-hash", +] + +[[package]] +name = "aristo" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcdeefa800110050103e2459a2f8dbdbd560ad046e30f1f87e24ce19c2cb8bde" +dependencies = [ + "aristo-macros", +] + +[[package]] +name = "aristo-macros" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d64a66d21a80182b35b1741997a6d2456911f54b7eb1918aa4e2382fc205268d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "assoc" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfdc70193dadb9d7287fa4b633f15f90c876915b31f6af17da307fc59c9859a8" + +[[package]] +name = "async-compression" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "515a1f282e33d55983c499d7e9e87082e81cbc32974825bf9032f928392d5844" +dependencies = [ + "compression-codecs", + "compression-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "async-trait" +version = "0.1.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.4", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "aws-lc-rs" +version = "1.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b281d307588d634de920874890732659e2e7672f72b5e10e81badc1a8a83621e" +dependencies = [ + "aws-lc-sys", + "zeroize", +] + +[[package]] +name = "aws-lc-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bff6c3b54fad79a2e60b8102caf565819711497c1f5f092f49508e2f5c31b27" +dependencies = [ + "cc", + "cmake", + "dunce", + "fs_extra", + "pkg-config", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "base64" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" + +[[package]] +name = "base64ct" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" + +[[package]] +name = "bigdecimal" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d6867f1565b3aad85681f1015055b087fcfd840d6aeee6eee7f2da317603695" +dependencies = [ + "autocfg", + "libm", + "num-bigint", + "num-integer", + "num-traits", +] + +[[package]] +name = "bindgen" +version = "0.69.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "itertools 0.12.1", + "lazy_static", + "lazycell", + "log", + "prettyplease 0.2.37", + "proc-macro2", + "quote", + "regex", + "rustc-hash 1.1.0", + "shlex 1.3.0", + "syn 2.0.119", + "which", +] + +[[package]] +name = "bitflags" +version = "2.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b588b76d00fde79687d7646a9b5bdf3cc0f655e0bbd080335a95d7e96f3587da" + +[[package]] +name = "bitpacking" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96a7139abd3d9cebf8cd6f920a389cf3dc9576172e32f4563f188cae3c3eb019" +dependencies = [ + "crunchy", +] + +[[package]] +name = "bitvec" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddcec3d12c579d40898fe0a9a358a803c23e9c52ca3c425707f81c9436211837" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "blake2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b5d4d889834ee8ecfc0f8426ad30faf7cdcb10f741a8e6d7224d95325479f6f" +dependencies = [ + "digest 0.11.3", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-buffer" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa" +dependencies = [ + "hybrid-array", +] + +[[package]] +name = "bon" +version = "3.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e3fac94a66da67200398458a25412bcc3f9b6443b5119a6cad9cf3ccfcd8cc6" +dependencies = [ + "bon-macros", +] + +[[package]] +name = "bon-macros" +version = "3.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4654961ad0494e4774c5c60b4cb4cd0ae9b9d92d039d901638b1dba97ebebf5" +dependencies = [ + "darling", + "ident_case", + "prettyplease 0.3.0", + "proc-macro2", + "quote", + "syn 3.0.4", +] + +[[package]] +name = "branches" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7436b21fd6195415058eb41c9090e156b556bc7e0377bb57c5c026a421521525" +dependencies = [ + "rustc_version", +] + +[[package]] +name = "brotli" +version = "8.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc91aac060a7a1e25823bdccbfb6af1875b88f17c6daac97894eed8207166b3" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", + "brotli-decompressor", +] + +[[package]] +name = "brotli-decompressor" +version = "5.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a32acac15fe1967bc3986b2a6347dffc965602354ea6f450ad07e8bfd253583" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "bytemuck" +version = "1.25.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95832e849adfb21180ccb6826a99da14e5d266ae5c2e668e1602cf234f153797" +dependencies = [ + "bytemuck_derive", +] + +[[package]] +name = "bytemuck_derive" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0e56a716f1e132ff6bf4bdac1c944a3fcdc1cae65f70a4a2a1ac3b401d2d1f" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.4", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + +[[package]] +name = "cc" +version = "1.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ad534f4357a5264cce5019c989cf66a4f0dc4e0d1b1d15f8aacec0ff7360273" +dependencies = [ + "find-msvc-tools", + "jobserver", + "libc", + "shlex 2.0.1", +] + +[[package]] +name = "census" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f4c707c6a209cbe82d10abd08e1ea8995e9ea937d2550646e02798948992be0" + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom 7.1.3", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + +[[package]] +name = "cfg_block" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18758054972164c3264f7c8386f5fc6da6114cb46b619fd365d4e3b2dc3ae487" + +[[package]] +name = "chacha20" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures 0.2.17", +] + +[[package]] +name = "chacha20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.1", + "rand_core 0.10.1", +] + +[[package]] +name = "chacha20poly1305" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" +dependencies = [ + "aead", + "chacha20 0.9.1", + "cipher", + "poly1305", + "zeroize", +] + +[[package]] +name = "chrono" +version = "0.4.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common 0.1.7", + "inout", + "zeroize", +] + +[[package]] +name = "clang-sys" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "157a8ba7b480713b56f4c09fd13fc3e0a22a5dfab8097ba61cbc5feef950788a" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "clap" +version = "4.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "473c7e07f409a8d772161724aa8db6a765a2532a70f9667eeb7b49d3d02fbdca" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b48fea5a88e9ae728a2dcbedbfc0e730f7d60da42e1cb049a83c9fb8b789889" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_lex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" + +[[package]] +name = "cmake" +version = "0.1.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678" +dependencies = [ + "cc", +] + +[[package]] +name = "cmov" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a" + +[[package]] +name = "codemap" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e769b5c8c8283982a987c6e948e540254f1058d5a74b8794914d4ef5fc2a24" + +[[package]] +name = "colorchoice" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" + +[[package]] +name = "combine" +version = "4.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfc320937d09e6de266b31b9afb480f197d7a861be86be7cb2ea7e5d1bfffc5e" +dependencies = [ + "bytes", + "memchr", +] + +[[package]] +name = "compression-codecs" +version = "0.4.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fe67f2944eef52fc7b106b8c9450d243a88701a0c065f7f57235e76abaed7df" +dependencies = [ + "brotli", + "compression-core", + "flate2", + "memchr", +] + +[[package]] +name = "compression-core" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e8ccc4ea9f6acc32d102c0f6d471d11d913ad15f20c04de743374861fa1d414" + +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "const-oid" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" + +[[package]] +name = "cookie" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a373e3602691c3cdea496d2f0ee5935151e6168fe87739483c463db1b2f2f87" +dependencies = [ + "aes-gcm", + "base64 0.22.1", + "hkdf", + "hmac 0.12.1", + "percent-encoding", + "rand 0.8.8", + "sha2 0.10.9", + "subtle", + "time", + "version_check", +] + +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "cpufeatures" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32c" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a47af21622d091a8f0fb295b88bc886ac74efcc613efc19f5d0b21de5c89e47" +dependencies = [ + "rustc_version", +] + +[[package]] +name = "crc32fast" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8498c871161e1742aaa9d52551b2d6ebdd4c3d45a3be423e3728f33b955be550" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d85363c37faeca707aef026efa9f3b34d077bce547e48f770770625c6013679e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5181e0de7b61eb03a81e347d6dd8797bae9da5146707b51077e2d71a54ec0ceb" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d6914041f254d6e9176c01941b21115dcfb7089e55135a35411081bd106ef3f" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61803da095bee82a81bb1a452ecc25d3b2f1416d1897eb86430c6159ef717c17" + +[[package]] +name = "crunchy" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "typenum", +] + +[[package]] +name = "crypto-common" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" +dependencies = [ + "hybrid-array", +] + +[[package]] +name = "ctr" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" +dependencies = [ + "cipher", +] + +[[package]] +name = "ctutils" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5515a3834141de9eafb9717ad39eea8247b5674e6066c404e8c4b365d2a29e" +dependencies = [ + "cmov", +] + +[[package]] +name = "darling" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed17f5901b6630b993ca003def43f2f8ef4014fc13b047b57aad617ff32bc2ec" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[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.4", +] + +[[package]] +name = "darling_macro" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ac7135c3ef02b2f7833bbeb1be5ba7f966dcde8a87c6b87f65a778d71a02785" +dependencies = [ + "darling_core", + "quote", + "syn 3.0.4", +] + +[[package]] +name = "data-encoding" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4583a4551df46e2792f82ceeac45e850d2e2d5debba0b91f102385cda5b11f06" + +[[package]] +name = "datasketches" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c286de4e81ea2590afc24d754e0f83810c566f50a1388fa75ebd57928c0d9745" + +[[package]] +name = "der" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +dependencies = [ + "const-oid 0.9.6", + "pem-rfc7468", + "zeroize", +] + +[[package]] +name = "deranged" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" +dependencies = [ + "serde_core", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "const-oid 0.9.6", + "crypto-common 0.1.7", + "subtle", +] + +[[package]] +name = "digest" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" +dependencies = [ + "block-buffer 0.12.1", + "const-oid 0.10.2", + "crypto-common 0.2.2", + "ctutils", +] + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.4", +] + +[[package]] +name = "downcast-rs" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "117240f60069e65410b3ae1bb213295bd828f707b5bec6596a1afc8793ce0cbc" + +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + +[[package]] +name = "either" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "252afb9ae5eaa683babdc6a068b3f5726eb19e05070c731f9b2a23a7c3e8ed34" + +[[package]] +name = "elsa" +version = "1.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9abf33c656a7256451ebb7d0082c5a471820c31269e49d807c538c252352186e" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "email-encoding" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "420b9da095f052ea597503e39073b5b3c522f7db933fbac202d91d24492693fd" +dependencies = [ + "base64 0.23.1", + "memchr", +] + +[[package]] +name = "email_address" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e079f19b08ca6239f47f8ba8509c11cf3ea30095831f7fed61441475edd8c449" + +[[package]] +name = "env_filter" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900d271a03799a1ee8d1ca9b19893b48ca674a9284fefcfb85f05e74ed314217" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de671bd27a75a797dc9ae289ba1e77276e75e2026408aab65185384e2d5cd3f6" +dependencies = [ + "env_filter", + "log", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "erased-serde" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2add8a07dd6a8d93ff627029c51de145e12686fbc36ecb298ac22e74cf02dec" +dependencies = [ + "serde", + "serde_core", + "typeid", +] + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "fastbloom" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7f34442dbe69c60fe8eaf58a8cafff81a1f278816d8ab4db255b3bef4ac3c4" +dependencies = [ + "getrandom 0.3.4", + "libm", + "siphasher", +] + +[[package]] +name = "fastdivide" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afc2bd4d5a73106dd53d10d73d3401c2f32730ba2c0b93ddb888a8983680471" + +[[package]] +name = "fastrand" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" + +[[package]] +name = "find-msvc-tools" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d45db016d36b838f563236e9193d0ee6ce38f3f68b6c94e914b4929c96bbb890" + +[[package]] +name = "flate2" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e634e2e0ebac1ee034020da1ca582e17ffe4e0f5e985823721e168928136dcb" +dependencies = [ + "crc32fast", + "miniz_oxide", + "zlib-rs", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "fs4" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8640e34b88f7652208ce9e88b1a37a2ae95227d84abec377ccd3c5cfeb141ed4" +dependencies = [ + "rustix 1.1.4", + "windows-sys 0.59.0", +] + +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "futures-channel" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-io" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" + +[[package]] +name = "futures-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.4", +] + +[[package]] +name = "futures-sink" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "genawaiter" +version = "0.99.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c86bd0361bcbde39b13475e6e36cb24c329964aa2611be285289d1e4b751c1a0" +dependencies = [ + "genawaiter-macro", +] + +[[package]] +name = "genawaiter-macro" +version = "0.99.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b32dfe1fdfc0bbde1f22a5da25355514b5e450c33a6af6770884c8750aedfbc" + +[[package]] +name = "generator" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3b854b0e584ead1a33f18b2fcad7cf7be18b3875c78816b753639aa501513ae" +dependencies = [ + "cc", + "cfg-if", + "libc", + "log", + "rustversion", + "windows-link", + "windows-result", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi 5.3.0", + "wasip2", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi 6.0.0", + "rand_core 0.10.1", + "wasm-bindgen", +] + +[[package]] +name = "ghash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1" +dependencies = [ + "opaque-debug", + "polyval", +] + +[[package]] +name = "glob" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b" + +[[package]] +name = "grass" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7a68216437ef68f0738e48d6c7bb9e6e6a92237e001b03d838314b068f33c94" +dependencies = [ + "clap", + "getrandom 0.2.17", + "grass_compiler", +] + +[[package]] +name = "grass_compiler" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d9e3df7f0222ce5184154973d247c591d9aadc28ce7a73c6cd31100c9facff6" +dependencies = [ + "codemap", + "indexmap", + "lasso", + "once_cell", + "phf", + "rand 0.8.8", +] + +[[package]] +name = "h2" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef8e5e5a340588f4452631496976cf8636d4a7ecf600239fdc27615d2530bc16" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "allocator-api2 0.2.21", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +dependencies = [ + "allocator-api2 0.2.21", + "equivalent", + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e17592d60ebacc7d5e169f4663c5f84f9161cc90328abcfe8456f41e4dfcb284" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac 0.12.1", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "hmac" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f" +dependencies = [ + "digest 0.11.3", +] + +[[package]] +name = "home" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "hostname" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "617aaa3557aef3810a6369d0a99fac8a080891b68bd9f9812a1eeda0c0730cbd" +dependencies = [ + "cfg-if", + "libc", + "windows-link", +] + +[[package]] +name = "htmlescape" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9025058dae765dee5070ec375f591e2ba14638c63feff74f13805a72e523163" + +[[package]] +name = "http" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hybrid-array" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707114b52a152fa7bdb290cd7cd5912d9467273b6d74e21b8d81aca1f8533f6b" +dependencies = [ + "typenum", +] + +[[package]] +name = "hyper" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b501faa50e7a26c3d3560ca625132f4078a17771f4810baf70475ae48cbe43" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "base64 0.22.1", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collator" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08984ed58ac439ebf3e13d2cf26b0c46a60afcd21721c1d14087c0b240344dda" +dependencies = [ + "icu_collator_data", + "icu_collections", + "icu_locale_core", + "icu_locale_fallback", + "icu_normalizer", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "zerovec", +] + +[[package]] +name = "icu_collator_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d7e54efdddeb1208c08dd5d32b53a879ac00d2d3d051b2255fd26821d16368" + +[[package]] +name = "icu_collections" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "785f595c61ef57169a467eeed7b4b6936a66f6cacbb116a96ee86da983251bf4" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_locale_data", + "icu_locale_fallback", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb" +dependencies = [ + "displaydoc", + "litemap", + "serde", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locale_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d37d91460e362a5cf58907cd7ce871411775ee6294e49a5cc8e6cec16dfa75ea" + +[[package]] +name = "icu_locale_fallback" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "251af8e57c9400e3eb58242fe5b8b1152b2a64fdf4cf632f923c38ccee6f2fa9" +dependencies = [ + "icu_locale_core", + "icu_locale_fallback_data", + "icu_provider", + "potential_utf", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locale_fallback_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "decf2a22ec8fa68f1a0c1129a3f8583f8f8bc24e8b9ccbe98ead99f62a4dc3a8" + +[[package]] +name = "icu_normalizer" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f9cf5f235641ed274641dd81c3f28d870e276763d0797aeeab72317b1c646f" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0" + +[[package]] +name = "icu_properties" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e7ca276ad3145661a65914e6daf131ca5120cd3dcee8f8f3214b8875184a148" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e590f038c1464a96894fd6d10127e90a8be4509f56ff7ecef851b15cee0b7caa" + +[[package]] +name = "icu_provider" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d27bbb9d3abbefac45d55f647c9de1d44aafcd1186eb91879afef17c396c3e73" +dependencies = [ + "displaydoc", + "icu_locale_core", + "serde", + "stable_deref_trait", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "im-client" +version = "0.1.0" +dependencies = [ + "base64 0.22.1", + "chacha20poly1305", + "http", + "rand 0.10.2", + "rand_core 0.6.4", + "reqwest", + "rsa", + "serde", + "serde_json", + "sha2 0.10.9", + "sha2 0.11.0", + "subtle", + "thiserror", + "time", + "tokio", + "topcoat", +] + +[[package]] +name = "im-core" +version = "0.1.0" +dependencies = [ + "argon2", + "base64 0.22.1", + "chacha20poly1305", + "data-encoding", + "hmac 0.13.0", + "rand 0.10.2", + "rand_core 0.6.4", + "rsa", + "serde", + "serde_json", + "sha1 0.11.0", + "sha2 0.10.9", + "sha2 0.11.0", + "subtle", + "tempfile", + "thiserror", + "time", + "tokio", + "turso", + "ulid", +] + +[[package]] +name = "im-migrate" +version = "0.1.0" +dependencies = [ + "tempfile", + "thiserror", + "time", + "tokio", + "turso", + "ulid", +] + +[[package]] +name = "im-web" +version = "0.1.0" +dependencies = [ + "base64 0.22.1", + "data-encoding", + "grass", + "http", + "im-core", + "lettre", + "qrcode", + "serde", + "serde_json", + "thiserror", + "time", + "tokio", + "toml", + "topcoat", + "ulid", +] + +[[package]] +name = "indexmap" +version = "2.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07aa2048142242915a31d35844fb311e0e53fcca590c3a0a40dcf1b841fa09eb" +dependencies = [ + "equivalent", + "hashbrown 0.17.1", +] + +[[package]] +name = "inout" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +dependencies = [ + "generic-array", +] + +[[package]] +name = "intrusive-collections" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "189d0897e4cbe8c75efedf3502c18c887b05046e59d28404d4d8e46cbc4d1e86" +dependencies = [ + "memoffset", +] + +[[package]] +name = "inventory" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4f0c30c76f2f4ccee3fe55a2435f691ca00c0e4bd87abe4f4a851b1d4dac39b" +dependencies = [ + "rustversion", +] + +[[package]] +name = "io-uring" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d64d8ca234d152948ceaede1f419b6a83983a5ecccaac05fb337a809c96d3aa6" +dependencies = [ + "bitflags", + "cfg-if", + "libc", +] + +[[package]] +name = "ipnet" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a756c3fac73139e83f14c2d742155dd2b78d3ee56597b419a0579b7bdd6dd78" + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "jni" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5efd9a482cf3a427f00d6b35f14332adc7902ce91efb778580e180ff90fa3498" +dependencies = [ + "cfg-if", + "combine", + "jni-macros", + "jni-sys", + "log", + "simd_cesu8", + "thiserror", + "walkdir", + "windows-link", +] + +[[package]] +name = "jni-macros" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00109accc170f0bdb141fed3e393c565b6f5e072365c3bd58f5b062591560a3" +dependencies = [ + "proc-macro2", + "quote", + "rustc_version", + "simd_cesu8", + "syn 2.0.119", +] + +[[package]] +name = "jni-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6377a88cb3910bee9b0fa88d4f42e1d2da8e79915598f65fb0c7ee14c878af2" +dependencies = [ + "jni-sys-macros", +] + +[[package]] +name = "jni-sys-macros" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264" +dependencies = [ + "quote", + "syn 2.0.119", +] + +[[package]] +name = "jobserver" +version = "0.1.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3" +dependencies = [ + "getrandom 0.4.3", + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0c1080212aad755ea003d18543e8768dd432c48819efd73a7bf1e39b7a5a3a" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] +name = "lasso" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e14eda50a3494b3bf7b9ce51c52434a761e383d7238ce1dd5dcec2fbc13e9fb" +dependencies = [ + "hashbrown 0.14.5", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "lettre" +version = "0.11.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2c646bd5cc763b1087b15493e29a64be6147ba8f19342004fa52048ee596eae" +dependencies = [ + "async-trait", + "base64 0.23.1", + "email-encoding", + "email_address", + "fastrand", + "futures-io", + "futures-util", + "hostname", + "httpdate", + "idna", + "mime", + "nom 8.0.0", + "percent-encoding", + "quoted_printable", + "rustls", + "socket2", + "tokio", + "tokio-rustls", + "url", + "webpki-roots", +] + +[[package]] +name = "levenshtein_automata" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c2cdeb66e45e9f36bfad5bbdb4d2384e70936afbee843c6f6543f0c551ebb25" + +[[package]] +name = "libc" +version = "0.2.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" + +[[package]] +name = "libloading" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" +dependencies = [ + "cfg-if", + "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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a45a52f43e1c16f667ccfe4dd8c85b7f7c204fd5e3bf46c5b0db9a5c3c0b8e9" +dependencies = [ + "cc", +] + +[[package]] +name = "linkme" +version = "0.3.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3045e122bd98aef8ec3ad58ce84f0791f64e70163d1a02710af4aa11a4d54cc5" +dependencies = [ + "linkme-impl", +] + +[[package]] +name = "linkme-impl" +version = "0.3.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77060ebe535362c3da75682cd17b0431017b6e7c5661e714fc69a7ad017d1301" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.4", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "litemap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" + +[[package]] +name = "loom" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "419e0dc8046cb947daa77eb95ae174acfbddb7673b4151f56d1eed8e93fbfaca" +dependencies = [ + "cfg-if", + "generator", + "scoped-tls", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "lru" +version = "0.16.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f66e8d5d03f609abc3a39e6f08e4164ebf1447a732906d39eb9b99b7919ef39" +dependencies = [ + "hashbrown 0.16.1", +] + +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + +[[package]] +name = "lz4_flex" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef0d4ed8669f8f8826eb00dc878084aa8f253506c4fd5e8f58f5bce72ddb97e" + +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "matchit" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8863b587001c1b9a8a4e36008cebc6b3612cb1226fe2de94858e06092687b608" + +[[package]] +name = "measure_time" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51c55d61e72fc3ab704396c5fa16f4c184db37978ae4e94ca8959693a235fc0e" +dependencies = [ + "log", +] + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "memmap2" +version = "0.9.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1219ed1b7f229ee7104d281dd01d6802fe28bb6e95d292942c4daacdeb798c0" +dependencies = [ + "libc", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "miette" +version = "7.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f98efec8807c63c752b5bd61f862c165c115b0a35685bdcfd9238c7aeb592b7" +dependencies = [ + "cfg-if", + "miette-derive", + "unicode-width", +] + +[[package]] +name = "miette-derive" +version = "7.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db5b29714e950dbb20d5e6f74f9dcec4edbcc1067bb7f8ed198c097b8c1a818b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "mimalloc" +version = "0.1.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d4139bb28d14ad1facf21d5eb8825051b326e172d216b39f6d31df53cc97862" +dependencies = [ + "libmimalloc-sys", +] + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "miniz_oxide" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "mio" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b18443e9c262bfe8fa82f51666e2642c53393f7e5c27b3e1aeab922cff5b9d8" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "murmurhash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2195bf6aa996a481483b29d62a7663eed3fe39600c460e323f8ff41e90bdd89b" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "nom" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405" +dependencies = [ + "memchr", +] + +[[package]] +name = "nu-ansi-term" +version = "0.50.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "num-bigint" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c89e69e7e0f03bea5ef08013795c25018e101932225a656383bd384495ecc367" +dependencies = [ + "num-integer", + "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-conv" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441" + +[[package]] +name = "num-integer" +version = "0.1.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ce2d95d4b3734dc35aa2f45e1aa22cd416814592a4f9d9205e11affd5b8e10b" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92800bd69a1eac91786bcfe9da64a897eb72911b8dc3095decbd07429e8048b" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + +[[package]] +name = "oneshot" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "269bca4c2591a28585d6bf10d9ed0332b7d76900a1b02bec41bdc3a2cdcda107" + +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" + +[[package]] +name = "openssl-probe" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" + +[[package]] +name = "ordered-float" +version = "5.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c9e0d9b23589f26070720bac724174bfec1083e82f7854cdd0267518343c0" +dependencies = [ + "num-traits", +] + +[[package]] +name = "ownedbytes" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fbd56f7631767e61784dc43f8580f403f4475bd4aaa4da003e6295e1bab4a7e" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "owo-colors" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" + +[[package]] +name = "pack1" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b7bb0ecf2e447b1f20ee94ee79ef6eed1e9d4b3c36ce1903b9dea3bf205523" +dependencies = [ + "bytemuck", +] + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "password-hash" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aab41826031698d6ffcd9cff78ef56ef998e39dc7e5067cdfebe373842d4723b" +dependencies = [ + "getrandom 0.4.3", + "phc", +] + +[[package]] +name = "pastey" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ee67f1008b1ba2321834326597b8e186293b049a023cdef258527550b9935b4" + +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "phc" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44dc769b75f93afdddd8c7fa12d685292ddeff1e66f7f0f3a234cf1818afe892" +dependencies = [ + "base64ct", + "ctutils", + "getrandom 0.4.3", +] + +[[package]] +name = "phf" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078" +dependencies = [ + "phf_macros", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d" +dependencies = [ + "phf_shared", + "rand 0.8.8", +] + +[[package]] +name = "phf_macros" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f84ac04429c13a7ff43785d75ad27569f2951ce0ffd30a3321230db2fc727216" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "phf_shared" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" + +[[package]] +name = "polling" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0e4f59085d47d8241c88ead0f274e8a0cb551f3625263c05eb8dd897c34218" +dependencies = [ + "cfg-if", + "concurrent-queue", + "hermit-abi", + "pin-project-lite", + "rustix 1.1.4", + "windows-sys 0.61.2", +] + +[[package]] +name = "poly1305" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" +dependencies = [ + "cpufeatures 0.2.17", + "opaque-debug", + "universal-hash", +] + +[[package]] +name = "polyval" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", + "opaque-debug", + "universal-hash", +] + +[[package]] +name = "potential_utf" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" +dependencies = [ + "serde_core", + "writeable", + "zerovec", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn 2.0.119", +] + +[[package]] +name = "prettyplease" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bfe0f4c752e450fc2faf62654f1c134747922825d5b04ca717b8874f41a40c0" +dependencies = [ + "proc-macro2", + "syn 3.0.4", +] + +[[package]] +name = "proc-macro-crate" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "prost" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528ac67416ff8646872a3c02cad9cc4ee5dc9f9540c9b10771855c95cb2e5ae1" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b570b25f7617e43d59005d0990ccb79e950a423952cea19671b7a876da390adf" +dependencies = [ + "anyhow", + "itertools 0.14.0", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "qrcode" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d68782463e408eb1e668cf6152704bd856c78c5b6417adaee3203d8f4c1fc9ec" + +[[package]] +name = "quinn" +version = "0.11.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c1a41e437b6bbd489372cd4971de128e85c855f56c57f283d20ff016cf7c0a8" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash 2.1.3", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04759210543be93709136e28212294a659ef5001836ff4eab4d663e4529bba83" +dependencies = [ + "aws-lc-rs", + "bytes", + "getrandom 0.4.3", + "lru-slab", + "rand 0.10.2", + "rand_pcg 0.10.2", + "ring", + "rustc-hash 2.1.3", + "rustls", + "rustls-pki-types", + "slab", + "thiserror", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35a133f956daabe89a61a685c2649f13d82d5aa4bd5d12d1277e1072a21c0694" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.61.2", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "quoted_printable" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "478e0585659a122aa407eb7e3c0e1fa51b1d8a870038bd29f0cf4a8551eea972" + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[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_core 0.9.5", +] + +[[package]] +name = "rand" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" +dependencies = [ + "chacha20 0.10.2", + "getrandom 0.4.3", + "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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.5", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.17", +] + +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", +] + +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + +[[package]] +name = "rand_pcg" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e" +dependencies = [ + "rand_core 0.6.4", +] + +[[package]] +name = "rand_pcg" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a" +dependencies = [ + "rand_core 0.10.1", +] + +[[package]] +name = "rapidhash" +version = "4.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5da7e78a036ce858e8d55b7e7dc8ba3a88b78350fd2155d3591bbd966b58589e" +dependencies = [ + "rustversion", +] + +[[package]] +name = "rayon" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb39b166781f92d482534ef4b4b1b2568f42613b53e5b6c160e24cfbfa30926d" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +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.4", +] + +[[package]] +name = "regex" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" + +[[package]] +name = "reqwest" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "219c5811de6525e5416c7d5d53bb656d3afdbc6c5af816e0802bcfa42dbdc1c3" +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", + "quinn", + "rustls", + "rustls-pki-types", + "rustls-platform-verifier", + "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 = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "roaring" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18bd8a37d17a58532776dcdf6041ce64929adca78e8489d5cacbafe99229d3e1" +dependencies = [ + "bytemuck", + "byteorder", +] + +[[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", + "rand_core 0.6.4", + "signature", + "spki", + "subtle", + "zeroize", +] + +[[package]] +name = "rust-stemmers" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e46a2036019fdb888131db7a4c847a1063a7493f971ed94ea82c67eada63ca54" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustc_version_runtime" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dd18cd2bae1820af0b6ad5e54f4a51d0f3fcc53b05f845675074efcc7af071d" +dependencies = [ + "rustc_version", + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys 0.4.15", + "windows-sys 0.59.0", +] + +[[package]] +name = "rustix" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys 0.12.1", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls" +version = "0.23.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0283386ce02abc0151e1761d08802dfe86c173b0b494af5cbc086574e453da06" +dependencies = [ + "aws-lc-rs", + "log", + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-native-certs" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dab5152771c58876a2146916e53e35057e1a4dfa2b9df0f0305b07f611fdea4d" +dependencies = [ + "openssl-probe", + "rustls-pki-types", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pki-types" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-platform-verifier" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d1e2536ce4f35f4846aa13bff16bd0ff40157cdb14cc056c7b14ba41233ba0" +dependencies = [ + "core-foundation", + "core-foundation-sys", + "jni", + "log", + "once_cell", + "rustls", + "rustls-native-certs", + "rustls-platform-verifier-android", + "rustls-webpki", + "security-framework", + "security-framework-sys", + "webpki-root-certs", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls-platform-verifier-android" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" + +[[package]] +name = "rustls-webpki" +version = "0.103.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2" +dependencies = [ + "aws-lc-rs", + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schannel" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91c1b7e4904c873ef0710c1f407dde2e6287de2bebc1bbbf7d430bb7cbffd939" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "security-framework" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.4", +] + +[[package]] +name = "serde_json" +version = "1.0.151" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + +[[package]] +name = "serde_spanned" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a978451301f4db1d02937a4ab3ccce137717b81826e79b7d49ffe3244a13c3b8" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", + "digest 0.10.7", +] + +[[package]] +name = "sha1" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aacc4cc499359472b4abe1bf11d0b12e688af9a805fa5e3016f9a386dc2d0214" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.1", + "digest 0.11.3", +] + +[[package]] +name = "sha1_smol" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbfa15b3dddfee50a0fff136974b3e1bde555604ba463834a7eb7deb6417705d" + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", + "digest 0.10.7", +] + +[[package]] +name = "sha2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "446ba717509524cb3f22f17ecc096f10f4822d76ab5c0b9822c5f9c284e825f4" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.1", + "digest 0.11.3", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "shuttle" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab17edba38d63047f46780cf7360acf7467fec2c048928689a5c1dd1c2b4e31" +dependencies = [ + "assoc", + "bitvec", + "cfg-if", + "generator", + "hex", + "owo-colors", + "rand 0.8.8", + "rand_core 0.6.4", + "rand_pcg 0.3.1", + "scoped-tls", + "smallvec", + "tracing", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest 0.10.7", + "rand_core 0.6.4", +] + +[[package]] +name = "simd-adler32" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" + +[[package]] +name = "simd_cesu8" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11031e251abf8611c80f460e19dbdeb54a66db918e49c65a7065b46ac7aec520" +dependencies = [ + "rustc_version", + "simdutf8", +] + +[[package]] +name = "simdutf8" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" + +[[package]] +name = "simsimd" +version = "6.5.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4fb3bc3cdce07a7d7d4caa4c54f8aa967f6be41690482b54b24100a2253fa70" +dependencies = [ + "cc", +] + +[[package]] +name = "siphasher" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649" + +[[package]] +name = "sketches-ddsketch" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "513c3f5f732bfd6fbb187619c2dfe9d2f25f1a2976f01d575f0fd329d565df56" +dependencies = [ + "serde", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9be42f50aa861c555654aa3a37f52f4b1074bacf4e48fe0ef7fa584e80f1f0f" + +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "softaes" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45e14297decde697ddf377c25752aead0927d5cfc89c2684d2af96901a4ceeea" + +[[package]] +name = "spin" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3763264f6b73151db08c50ff20d7d8a0b8796e021cdea7ceedad07b80155fa0e" + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "strum" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.119", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "symlink" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7973cce6668464ea31f176d85b13c7ab3bba2cb3b77a2ed26abd7801688010a" + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6275cddf4610d1775e6d1fe9469b2e77d0f39fd98fb7450901b821e0c53649f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "tantivy" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edde6a10743fff00a4e1a8c9ef020bf5f3cbad301b7d2d39f2b07f123c4eac07" +dependencies = [ + "aho-corasick", + "arc-swap", + "base64 0.22.1", + "bitpacking", + "bon", + "byteorder", + "census", + "crc32fast", + "crossbeam-channel", + "datasketches", + "downcast-rs", + "fastdivide", + "fnv", + "fs4", + "htmlescape", + "itertools 0.14.0", + "levenshtein_automata", + "log", + "lru", + "lz4_flex", + "measure_time", + "memmap2", + "once_cell", + "oneshot", + "rayon", + "regex", + "rust-stemmers", + "rustc-hash 2.1.3", + "serde", + "serde_json", + "sketches-ddsketch", + "smallvec", + "tantivy-bitpacker", + "tantivy-columnar", + "tantivy-common", + "tantivy-fst", + "tantivy-query-grammar", + "tantivy-stacker", + "tantivy-tokenizer-api", + "tempfile", + "thiserror", + "time", + "typetag", + "uuid", + "winapi", +] + +[[package]] +name = "tantivy-bitpacker" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fed3d674429bcd2de5d0a6d1aa5495fed8afd9c5ecce993019caf7615f53fa4" +dependencies = [ + "bitpacking", +] + +[[package]] +name = "tantivy-columnar" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c57166f5bcfd478f370ab8445afb4678dce44801fa5ce5c451aaf8595583c5dc" +dependencies = [ + "downcast-rs", + "fastdivide", + "itertools 0.14.0", + "serde", + "tantivy-bitpacker", + "tantivy-common", + "tantivy-sstable", + "tantivy-stacker", +] + +[[package]] +name = "tantivy-common" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbf10915aa75da3c3b0d58b58853d2e889efbaf32d4982a4c3715dde6bba23e5" +dependencies = [ + "async-trait", + "byteorder", + "ownedbytes", + "serde", + "time", +] + +[[package]] +name = "tantivy-fst" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d60769b80ad7953d8a7b2c70cdfe722bbcdcac6bccc8ac934c40c034d866fc18" +dependencies = [ + "byteorder", + "regex-syntax", + "utf8-ranges", +] + +[[package]] +name = "tantivy-query-grammar" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfadb8526b6da90704feb293b0701a6aae62ea14983143344be2dc5ce30f1d82" +dependencies = [ + "fnv", + "nom 7.1.3", + "ordered-float", + "serde", + "serde_json", +] + +[[package]] +name = "tantivy-sstable" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a2cfc3ac5164cbadc28965ffb145a8f47582a60ae5897859ad8d4316596c606" +dependencies = [ + "futures-util", + "itertools 0.14.0", + "tantivy-bitpacker", + "tantivy-common", + "tantivy-fst", + "zstd", +] + +[[package]] +name = "tantivy-stacker" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cbb051742da9d53ca9e8fff43a9b10e319338b24e2c0e15d0372df19ffeb951" +dependencies = [ + "murmurhash32", + "tantivy-common", +] + +[[package]] +name = "tantivy-tokenizer-api" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac258c2c6390673f2685813afeeafcb8c4e0ee7de8dd3fc46838dcc37263f98" +dependencies = [ + "serde", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "getrandom 0.4.3", + "once_cell", + "rustix 1.1.4", + "windows-sys 0.61.2", +] + +[[package]] +name = "thiserror" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.4", +] + +[[package]] +name = "thread_local" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad99c4c6d32803332c548b1af0540b357b3f5fc0be8f6c6bfe8b2e6ae784070" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "time" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134" +dependencies = [ + "deranged", + "num-conv", + "powerfmt", + "serde_core", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109" + +[[package]] +name = "time-macros" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e689342a48d2ea927c87ea50cabf8594854bf940e9310208848d680d668ed85" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tinystr" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643" +dependencies = [ + "displaydoc", + "serde_core", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb4ebadaa0af04fab11ae01eb5f9fdb5f9c5b875506e210e71c07873528baa7f" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.4", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-tungstenite" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f72a05e828585856dacd553fba484c242c46e391fb0e58917c942ee9202915c" +dependencies = [ + "futures-util", + "log", + "tokio", + "tungstenite", +] + +[[package]] +name = "tokio-util" +version = "0.7.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "494815d09bf52b5548659851081238f0ca39ff638363907596da739561c62c52" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "libc", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "toml" +version = "1.1.5+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12c0ba9680044b4ce98d391a62094047eada0d64860b80166c39f4a6b5640785" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow", +] + +[[package]] +name = "toml_datetime" +version = "1.1.1+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_edit" +version = "0.25.13+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6975367e4d2ef766d86af01ffad14b622fecc8d4357a998fbc4deb6e9bacaf9b" +dependencies = [ + "indexmap", + "toml_datetime", + "toml_parser", + "winnow", +] + +[[package]] +name = "toml_parser" +version = "1.1.3+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d38ac1cf9b95face32296c0a3ede1fdc270627c9d9c02a7274dd6d960dc4d56" +dependencies = [ + "winnow", +] + +[[package]] +name = "toml_writer" +version = "1.1.2+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2" + +[[package]] +name = "topcoat" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "050c11e7b0e146a2b1eb15855abd5fa03e2754eb880922f8b6cab5ec71cac5aa" +dependencies = [ + "futures-util", + "inventory", + "serde", + "serde_urlencoded", + "tokio", + "tokio-tungstenite", + "topcoat-asset", + "topcoat-cookie", + "topcoat-core", + "topcoat-core-macro", + "topcoat-font", + "topcoat-font-macro", + "topcoat-mail", + "topcoat-router", + "topcoat-router-macro", + "topcoat-runtime", + "topcoat-runtime-macro", + "topcoat-session", + "topcoat-view", + "topcoat-view-macro", +] + +[[package]] +name = "topcoat-asset" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a72e4ba8cb6a9d29613a25c2151e72d887b4a79b3f179b497734eed0e65ea702" +dependencies = [ + "http", + "memchr", + "serde", + "sha2 0.11.0", + "thiserror", + "tokio", + "toml", + "topcoat-core", + "topcoat-router", + "topcoat-view", +] + +[[package]] +name = "topcoat-cookie" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f68c83654c4bf075f667d39463cd38ef0be9fee057054454b06612efe16e7a37" +dependencies = [ + "cookie", + "getrandom 0.2.17", + "http", + "serde", + "serde_json", + "topcoat-core", + "topcoat-router", +] + +[[package]] +name = "topcoat-core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f94adaa301d7a4b949d650fa803323c00cc8ffa8bf1984511c1ec5d390b6c6" +dependencies = [ + "anyhow", + "anymap3", + "elsa", + "http", + "pin-project-lite", + "siphasher", + "thiserror", + "tokio", +] + +[[package]] +name = "topcoat-core-grammar" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0756aa9285794c155624494bc563d56859e35205313db883a89d7dabfa6d0393" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "topcoat-core-macro" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4908dba6268c8592be73e9059cdefa053066e1b1bc879c1c9a5d8d3b6e97aad" +dependencies = [ + "quote", + "syn 2.0.119", + "topcoat-core-grammar", +] + +[[package]] +name = "topcoat-font" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7b8308aff65f46bbe2f58371fc9823db596236bd0ea3c9d87de6534fd977e60" +dependencies = [ + "heck", + "inventory", + "serde", + "serde_json", + "topcoat-asset", + "topcoat-core", + "topcoat-router", + "topcoat-view", + "topcoat-view-macro", +] + +[[package]] +name = "topcoat-font-grammar" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b7d68e226827fb7531d0dba69cb74fa7b82515f8428fd1a75f556f5a2bf87c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", + "topcoat-core-grammar", + "topcoat-font", +] + +[[package]] +name = "topcoat-font-macro" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e655c430bcb380f879603ea750c6222ade2ff3ade33869d9eaa32e3fc49f5469" +dependencies = [ + "quote", + "syn 2.0.119", + "topcoat-font-grammar", +] + +[[package]] +name = "topcoat-mail" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "959c9c32172ad3840f94c589a29bd143c072661c9abf2215a68fd76440ed2300" +dependencies = [ + "lettre", + "thiserror", + "time", + "topcoat-core", + "topcoat-router", + "topcoat-view", +] + +[[package]] +name = "topcoat-router" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e062bd348df5647f6904f4f4045b3c92c08c4a8826196e8e91a51aade00b5764" +dependencies = [ + "bytes", + "form_urlencoded", + "futures-core", + "heck", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "inventory", + "matchit", + "percent-encoding", + "ref-cast", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "tokio", + "topcoat-core", + "topcoat-view", + "tower", + "tower-http 0.7.1", +] + +[[package]] +name = "topcoat-router-grammar" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c052423d2aa4039036f1ac5567d1e2dac48897602d34561b3024a87830e5bdce" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.119", + "topcoat-core-grammar", +] + +[[package]] +name = "topcoat-router-macro" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cea98692b786bab3adda35a60d71981f60b2a98c6e7105ac92e582b7c9ce9cab" +dependencies = [ + "quote", + "syn 2.0.119", + "topcoat-router-grammar", +] + +[[package]] +name = "topcoat-runtime" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dea200c86ca554bab7410f09cae8790a8adcbfd8f306eb78db7092ca71f8aae" +dependencies = [ + "inventory", + "ref-cast", + "serde", + "serde_json", + "topcoat-asset", + "topcoat-core", + "topcoat-router", + "topcoat-view", + "uuid", +] + +[[package]] +name = "topcoat-runtime-grammar" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87b73f7e4e10f49e006a71dd43e8ee629c76c08451acbc51faa7ec5b6952c53c" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "serde_json", + "syn 2.0.119", + "topcoat-core-grammar", + "topcoat-runtime", + "uuid", +] + +[[package]] +name = "topcoat-runtime-macro" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dc3e4e245abcaea6af780437cae072e8f2157c9852ec5b3058a658c61b9e0bf" +dependencies = [ + "quote", + "syn 2.0.119", + "topcoat-runtime-grammar", +] + +[[package]] +name = "topcoat-session" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e079e8c5a63987d7f929ab05a75922feab1fe390a9cfa2c101eb35829e67eac2" +dependencies = [ + "base64 0.22.1", + "getrandom 0.4.3", + "sha2 0.11.0", + "thiserror", + "tokio", + "topcoat-cookie", + "topcoat-core", + "topcoat-router", + "web-time", +] + +[[package]] +name = "topcoat-view" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5904449bd6f633759d187fa621ded68178b551428c297959fd53d8fb91f3e6f6" +dependencies = [ + "futures-core", + "futures-util", + "http", + "itoa", + "memchr", + "pin-project-lite", + "smallvec", + "topcoat-core", +] + +[[package]] +name = "topcoat-view-grammar" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bf4293156d7c5fa7960edc573b686eb27426dcd888bfbe9e532304178cdda24" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.119", + "topcoat-core-grammar", + "topcoat-view", +] + +[[package]] +name = "topcoat-view-macro" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58ab2b200eda4516abdb543f307006d83fedd3681b871d2042c17106c688f716" +dependencies = [ + "quote", + "syn 2.0.119", + "topcoat-view-grammar", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", + "url", +] + +[[package]] +name = "tower-http" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08a05a66a4fdd61cbbe0a1d755ffe0ca6aba159dd4820936a0ff8a8278245b9c" +dependencies = [ + "async-compression", + "bitflags", + "bytes", + "futures-core", + "http", + "http-body", + "percent-encoding", + "pin-project-lite", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-appender" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "050686193eb999b4bb3bc2acfa891a13da00f79734704c4b8b4ef1a10b368a3c" +dependencies = [ + "crossbeam-channel", + "symlink", + "thiserror", + "time", + "tracing-subscriber", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex-automata", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "tungstenite" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c01152af293afb9c7c2a57e4b559c5620b421f6d133261c60dd2d0cdb38e6b8" +dependencies = [ + "bytes", + "data-encoding", + "http", + "httparse", + "log", + "rand 0.9.5", + "sha1 0.10.7", + "thiserror", +] + +[[package]] +name = "turso" +version = "0.8.0-pre.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1bd06e73738d6f5077ce0107eaa2147cd94cf14c4d04001745e4e6d59af3540" +dependencies = [ + "mimalloc", + "thiserror", + "tracing", + "tracing-subscriber", + "turso_core", + "turso_sdk_kit", + "turso_sync_sdk_kit", +] + +[[package]] +name = "turso_core" +version = "0.8.0-pre.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae723f6e4b3271dfa3d3e11dedab5b9146c278409fe948bdfccc2658af8a09eb" +dependencies = [ + "aegis", + "aes", + "aes-gcm", + "allocator-api2 0.4.0", + "antithesis_sdk", + "arc-swap", + "aristo", + "bigdecimal", + "bitflags", + "branches", + "bumpalo", + "bytemuck", + "cfg_aliases", + "cfg_block", + "chrono", + "crc32c", + "crossbeam-epoch", + "crossbeam-utils", + "either", + "fallible-iterator", + "fastbloom", + "getrandom 0.2.17", + "getrandom 0.3.4", + "hex", + "icu_collator", + "icu_locale", + "intrusive-collections", + "io-uring", + "libc", + "libloading", + "libm", + "loom", + "miette", + "num-bigint", + "num-traits", + "pack1", + "parking_lot", + "pastey", + "polling", + "rand 0.9.5", + "rapidhash", + "regex", + "regex-syntax", + "roaring", + "rustc-hash 2.1.3", + "rustix 1.1.4", + "ryu", + "serde_json", + "shuttle", + "simdutf8", + "simsimd", + "smallvec", + "strum", + "strum_macros", + "tantivy", + "tempfile", + "thiserror", + "tracing", + "tracing-subscriber", + "turso_ext", + "turso_macros", + "turso_parser", + "twox-hash", + "uncased", + "uuid", + "windows-sys 0.61.2", +] + +[[package]] +name = "turso_ext" +version = "0.8.0-pre.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9704b1b4b5dc8dbdc56fd4c3a44fb7be47d91e9d240cada262a1d6f55b0fc08" +dependencies = [ + "chrono", + "getrandom 0.4.3", + "turso_macros", +] + +[[package]] +name = "turso_macros" +version = "0.8.0-pre.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c72bcec01a1828c7494cd7f12a7d6749897eb579681bc1de401b4a6c7f3c1d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "turso_parser" +version = "0.8.0-pre.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e32af53f89c67f2d202e25ea9c4913f596e85fcddaf587295ae8e1f404599960" +dependencies = [ + "bitflags", + "memchr", + "miette", + "strum", + "strum_macros", + "thiserror", + "turso_macros", +] + +[[package]] +name = "turso_sdk_kit" +version = "0.8.0-pre.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b87629a08b9094ad88297c58a2944c7419502e0894b8246b8826faf075c46aef" +dependencies = [ + "bindgen", + "env_logger", + "parking_lot", + "tracing", + "tracing-appender", + "tracing-subscriber", + "turso_core", + "turso_ext", + "turso_sdk_kit_macros", +] + +[[package]] +name = "turso_sdk_kit_macros" +version = "0.8.0-pre.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1997cad4d7bf270b76ee9bcfe444bc97d3f256bb78bba2962992ea0ca607997e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "turso_sync_engine" +version = "0.8.0-pre.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67446281acc75626ae0ac6cabac9de088368dea04c0930a868dc9f891b409eba" +dependencies = [ + "base64 0.22.1", + "bytes", + "crc32c", + "genawaiter", + "http", + "libc", + "prost", + "roaring", + "serde", + "serde_json", + "thiserror", + "tracing", + "turso_core", + "turso_parser", + "uuid", +] + +[[package]] +name = "turso_sync_sdk_kit" +version = "0.8.0-pre.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20d7933b7eb770ec8fa280d4d372dba60b251c959e117559b31ebc7c503ec007" +dependencies = [ + "bindgen", + "env_logger", + "genawaiter", + "parking_lot", + "tracing", + "tracing-appender", + "tracing-subscriber", + "turso_core", + "turso_sdk_kit", + "turso_sdk_kit_macros", + "turso_sync_engine", +] + +[[package]] +name = "twox-hash" +version = "2.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5283634e518fe9e82c7b20520bb4bc209009fd16c82077c802f8111ecbb0117a" +dependencies = [ + "rand 0.10.2", +] + +[[package]] +name = "typeid" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c" + +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + +[[package]] +name = "typetag" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c90e86058a30d42a1a928dfb4b49bb33c98c3a2b4909492e6b0881cd94798ec2" +dependencies = [ + "erased-serde", + "inventory", + "once_cell", + "serde", + "typetag-impl", +] + +[[package]] +name = "typetag-impl" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f153acc4e99a5f2a5aefa09fb078be54e26271b2813f6041200b224c098d8328" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.4", +] + +[[package]] +name = "ulid" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "470dbf6591da1b39d43c14523b2b469c86879a53e8b758c8e090a470fe7b1fbe" +dependencies = [ + "rand 0.9.5", + "web-time", +] + +[[package]] +name = "uncased" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1b88fcfe09e89d3866a5c11019378088af2d24c3fbd4f0543f96b479ec90697" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "universal-hash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" +dependencies = [ + "crypto-common 0.1.7", + "subtle", +] + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8-ranges" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcfc827f90e53a02eaef5e535ee14266c1d569214c6aa70133a624d8a3164ba" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "uuid" +version = "1.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5772d71c9be8a8a6ac2117d949c5b224c1b72241bb611d9a3012edcf8af7812" +dependencies = [ + "getrandom 0.4.3", + "js-sys", + "serde_core", + "sha1_smol", + "wasm-bindgen", +] + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.4+wasi-0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b70935747edd64d89de3efa29d73789b806c15798f8e7dca4d8ac356b50ce70" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b7777d5cc23d0e91404e53ce2d5e8ec7acae3026b16233dba62cd3246457950" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77775f8f3f7217702089053b94958f8f54061a3f663417df76e19cbdcca29bc1" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e11d33f857dc2fb11b8bc75aee111aa9cbeb12cd9f25efd3d4c2a3dd4e235284" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 2.0.119", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef64dbcc55df09c7e5a46182d181c2cfa3e925f3da937ea764728b4bbb9dcbf" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-sys" +version = "0.3.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c435338968042f4f59a557f690a253676d47ce13ceb55d70100e7facf6620a30" +dependencies = [ + "js-sys", + "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 = "webpki-root-certs" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b96554aa2acc8ccdb7e1c9a58a7a68dd5d13bccc69cd124cb09406db612a1c9b" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "webpki-roots" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix 0.38.44", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b97319f7b8343df12cc98938e5c3eb436064524c8d2b4e30a1d3a36eecdf81" +dependencies = [ + "memchr", +] + +[[package]] +name = "wit-bindgen" +version = "0.57.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" + +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "yoke" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556764e583adb45a9f8d413c2a147fa7e8d821e48e12b14fd560b607998b75eb" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2ab42fc20575779bd240faa45f94a74256f755c0fa9e89f0ede20d91d0cdfc1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" + +[[package]] +name = "zerotrie" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "zerovec" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0464e17806c1d976d5cba29399c7f08e516e279e2ba493f63123b5fca67dd8" +dependencies = [ + "serde", + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34df6fc39dbd26ddc9c10e6a2984476e13acce22e64e4487636ef494369225da" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.4", +] + +[[package]] +name = "zlib-rs" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34b31d188d9d685a4f9c7b46d6e36631b07058d2cfe190267adce54dc230bf12" + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" + +[[package]] +name = "zstd" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "7.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f49c4d5f0abb602a93fb8736af2a4f4dd9512e36f7f570d66e65ff867ed3b9d" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.16+zstd.1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e19ebc2adc8f83e43039e79776e3fda8ca919132d68a1fed6a5faca2683748" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..e825be1 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,45 @@ +[workspace] +resolver = "3" +members = [ + "crates/im-core", + "crates/im-web", + "crates/im-client", + "crates/im-migrate", +] + +[workspace.package] +version = "0.1.0" +edition = "2024" +repository = "https://github.com/DizeyLab/im" + +[workspace.dependencies] +im-core = { path = "crates/im-core", default-features = false } +serde = { version = "1.0.229", features = ["derive"] } +serde_json = "1.0.145" +thiserror = "2.0.20" +ulid = "1" +time = { version = "0.3.55", features = ["serde", "formatting", "parsing", "macros"] } +tokio = { version = "1.53.1", features = ["full"] } +turso = "=0.8.0-pre.7" +argon2 = "0.6.0" +rand = "0.10.2" +sha2 = "0.11.0" +subtle = "2.6.1" +chacha20poly1305 = "0.10.1" +base64 = "0.22.1" +toml = "1" +async-trait = "0.1.92" + +[profile.release] +codegen-units = 1 +lto = true + +# What the deploy builds. Fat LTO and one codegen unit buy the last few +# percent by optimizing the whole program in a single non-parallel pass — +# worth it for something CPU-bound, not for a server whose time goes to +# SQLite, TLS and the network. Thin LTO still optimizes across crates, in +# parallel, so `release` stays available for when the trade is worth making. +[profile.dist] +inherits = "release" +lto = "thin" +codegen-units = 16 diff --git a/config/im.toml b/config/im.toml new file mode 100644 index 0000000..1f5f44d --- /dev/null +++ b/config/im.toml @@ -0,0 +1,12 @@ +database = "im.db" +listen = "127.0.0.1:7650" +issuer = "http://127.0.0.1:7650" + +# Without an [smtp] table the server runs in dev mode: invite links are +# printed to stdout instead of mailed. +# [smtp] +# host = "smtp.example.com" +# port = 465 +# username = "..." +# password = "..." +# from = "im " diff --git a/crates/im-client/Cargo.toml b/crates/im-client/Cargo.toml new file mode 100644 index 0000000..51aba56 --- /dev/null +++ b/crates/im-client/Cargo.toml @@ -0,0 +1,45 @@ +[package] +name = "im-client" +version.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +description = "Drop-in OIDC client for topcoat apps authenticating against im" + +[dependencies] +topcoat = { version = "0.6.2", default-features = false, features = [ + "router", + "cookie", +] } +serde.workspace = true +serde_json.workspace = true +thiserror.workspace = true +time.workspace = true +tokio.workspace = true +base64.workspace = true +rand.workspace = true +sha2.workspace = true +subtle.workspace = true +chacha20poly1305.workspace = true +# rsa 0.9 verifies through the digest 0.10 traits, so its hasher comes from +# the sha2 0.10 line; the workspace sha2 0.11 stays for PKCE. +sha2-for-rsa = { package = "sha2", version = "0.10", features = ["oid"] } +rsa = "0.9.10" +reqwest = { version = "0.13.4", default-features = false, features = [ + "rustls", + "json", + "form", +] } + +[dev-dependencies] +topcoat = { version = "0.6.2", default-features = false, features = [ + "router", + "cookie", + "view", + "serve", + "discover", +] } +http = "1.5" +# Tests generate their own RSA keys, and rsa 0.9's RNG is the rand_core 0.6 +# line. +rand_core06 = { package = "rand_core", version = "0.6.4", features = ["getrandom"] } diff --git a/crates/im-client/examples/demo.rs b/crates/im-client/examples/demo.rs new file mode 100644 index 0000000..24d7071 --- /dev/null +++ b/crates/im-client/examples/demo.rs @@ -0,0 +1,66 @@ +//! The smallest topcoat app that signs in through im. Used by the +//! integration smoke test, and the reference for every app that follows. +//! +//! ```sh +//! IM_ISSUER=http://127.0.0.1:7650 \ +//! IM_CLIENT_ID= \ +//! IM_CLIENT_SECRET= \ +//! cargo run -p im-client --example demo +//! ``` +//! +//! The cookie key below is a fixed development value so restarts keep +use topcoat::Result; +use topcoat::context::Cx; +use topcoat::cookie::RouterBuilderCookieExt; +use topcoat::router::response::{IntoResponse, Response}; +use topcoat::router::{HeaderValue, Router, RouterBuilderDiscoverExt, StatusCode, header, route}; + +const DEV_COOKIE_KEY: [u8; 32] = [42u8; 32]; + +#[route(GET "/")] +async fn home(cx: &Cx) -> Result { + Ok(match im_client::current_user(cx).await { + Some(user) => format!( + "signed in as {} <{}>\n/me shows the claims, /auth/logout signs out of this app\n", + user.name, user.email + ), + None => "not signed in\n/auth/login?next=/me to begin\n".to_string(), + }) +} + +#[route(GET "/me")] +async fn me(cx: &Cx) -> Result { + match im_client::current_user(cx).await { + Some(user) => { + topcoat::router::content::Json(serde_json::to_value(user).unwrap()).into_response(cx) + } + None => ( + StatusCode::SEE_OTHER, + [( + header::LOCATION, + HeaderValue::from_static("/auth/login?next=/me"), + )], + ) + .into_response(cx), + } +} + +#[tokio::main] +async fn main() { + let config = im_client::Config { + issuer: std::env::var("IM_ISSUER").unwrap_or("http://127.0.0.1:7650".into()), + client_id: std::env::var("IM_CLIENT_ID").expect("IM_CLIENT_ID"), + client_secret: std::env::var("IM_CLIENT_SECRET").expect("IM_CLIENT_SECRET"), + redirect_uri: "http://127.0.0.1:7656/auth/callback".into(), + cookie_name: "demo_session".into(), + cookie_key: DEV_COOKIE_KEY, + }; + let router = im_client::mount(Router::builder().discover().cookies(), config).build(); + let listener = tokio::net::TcpListener::bind("127.0.0.1:7656") + .await + .expect("failed to bind 127.0.0.1:7656"); + println!("demo listening on http://127.0.0.1:7656"); + topcoat::serve_until(listener, router, std::future::pending()) + .await + .expect("server error"); +} diff --git a/crates/im-client/src/lib.rs b/crates/im-client/src/lib.rs new file mode 100644 index 0000000..b09f457 --- /dev/null +++ b/crates/im-client/src/lib.rs @@ -0,0 +1,710 @@ +//! im-client: drop-in OIDC client for topcoat apps authenticating against im. +//! +//! An app adds three things: `im_client::mount(builder, config)` when it +//! builds its router, `.discover()` as usual (the `/auth/login`, +//! `/auth/callback`, `/auth/logout` routes register themselves), and +//! `im_client::current_user(cx)` wherever it needs the person. +//! +//! The model: im holds the central session; this crate holds the app's side +//! of it — an encrypted cookie with the identity claims and the refresh +//! token. When the access token ages out, `current_user` silently rotates it +//! against im; when im has revoked the central session, the rotation is +//! refused and the app sees a signed-out user. + +use base64::Engine; +use base64::engine::general_purpose::URL_SAFE_NO_PAD as b64url; +use chacha20poly1305::aead::Aead; +use chacha20poly1305::{KeyInit, XChaCha20Poly1305, XNonce}; +use rand::Rng; +use serde::{Deserialize, Serialize}; +use sha2::{Digest, Sha256}; +use subtle::ConstantTimeEq; +use time::OffsetDateTime; +use topcoat::context::{Cx, try_app_context}; +use topcoat::cookie::{Cookie, Cookies, cookie, cookies}; +use topcoat::router::response::{IntoResponse, Response}; +use topcoat::router::{HeaderValue, RouterBuilder, StatusCode, header, route}; + +// --------------------------------------------------------------------------- +// Configuration and state +// --------------------------------------------------------------------------- + +/// Everything the app knows about its im registration. `client_secret` and +/// `cookie_key` are secrets: the first authenticates the app to im, the +/// second seals the browser cookies this crate writes. +#[derive(Clone)] +pub struct Config { + /// im's base URL, e.g. `http://127.0.0.1:7650` or `https://auth.example.com`. + pub issuer: String, + pub client_id: String, + pub client_secret: String, + /// Must exactly match one of the URIs registered with im. + pub redirect_uri: String, + /// The app's session cookie name, e.g. `izlek_session`. + pub cookie_name: String, + /// 32 bytes, generated once per app and kept out of the repository. + pub cookie_key: [u8; 32], +} + +/// The registered state: the config, one HTTP client, and the JWKS cache. +pub struct ImClient { + config: Config, + http: reqwest::Client, + jwks: tokio::sync::RwLock>, +} + +struct JwksCache { + fetched_at: OffsetDateTime, + /// kid -> public key + keys: Vec<(String, rsa::RsaPublicKey)>, +} + +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error("http: {0}")] + Http(String), + #[error("im refused: {0}")] + Refused(String), + #[error("bad token: {0}")] + Token(String), +} + +pub type Result = std::result::Result; + +impl ImClient { + pub fn new(config: Config) -> Self { + ImClient { + config, + http: reqwest::Client::new(), + jwks: tokio::sync::RwLock::new(None), + } + } +} + +/// Registers the client state on the router. The routes themselves register +/// through `discover()` — call it as usual. +pub fn mount(builder: RouterBuilder, config: Config) -> RouterBuilder { + builder.app_context(ImClient::new(config)) +} + +fn client(cx: &Cx) -> &ImClient { + try_app_context::(cx).expect("im_client::mount was called on the router") +} + +/// The authenticated person, if this browser has one. Transparently refreshes +/// against im when the access token has aged out; `None` means signed out. +pub async fn current_user(cx: &Cx) -> Option { + let state = client(cx); + let sealed = cookies(cx).get(&state.config.cookie_name)?; + let mut session: Session = open_json(&state.config.cookie_key, sealed.value())?; + if session.access_exp > OffsetDateTime::now_utc().unix_timestamp() { + return Some(session.user()); + } + match refresh(cx, state, &mut session).await { + Ok(()) => { + set_session_cookie(cx, state, &session); + Some(session.user()) + } + Err(_) => { + clear_cookie(cx, &state.config.cookie_name); + None + } + } +} + +/// Who this browser is, from the claims. +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct User { + pub sub: String, + pub email: String, + pub name: String, +} + +// --------------------------------------------------------------------------- +// The app session cookie +// --------------------------------------------------------------------------- + +#[derive(Serialize, Deserialize)] +struct Session { + user: User, + refresh_token: String, + access_exp: i64, +} + +impl Session { + fn user(&self) -> User { + self.user.clone() + } +} + +/// The in-flight login: PKCE verifier, state, nonce, and where to land after. +#[derive(Serialize, Deserialize)] +struct InFlight { + verifier: String, + state: String, + nonce: String, + next: String, + exp: i64, +} + +const IN_FLIGHT_MINUTES: i64 = 10; + +fn seal(key: &[u8; 32], plaintext: &[u8]) -> String { + let cipher = XChaCha20Poly1305::new(key.into()); + let mut nonce_bytes = [0u8; 24]; + rand::rng().fill_bytes(&mut nonce_bytes); + let ciphertext = cipher + .encrypt(XNonce::from_slice(&nonce_bytes), plaintext) + .expect("XChaCha20-Poly1305 cannot fail on a payload this small"); + let mut payload = nonce_bytes.to_vec(); + payload.extend_from_slice(&ciphertext); + b64url.encode(payload) +} + +fn open(key: &[u8; 32], sealed: &str) -> Option> { + let payload = b64url.decode(sealed).ok()?; + if payload.len() < 24 { + return None; + } + let (nonce_bytes, ciphertext) = payload.split_at(24); + let cipher = XChaCha20Poly1305::new(key.into()); + cipher + .decrypt(XNonce::from_slice(nonce_bytes), ciphertext) + .ok() +} + +fn seal_json(key: &[u8; 32], value: &T) -> String { + seal(key, &serde_json::to_vec(value).expect("plain data")) +} + +fn open_json Deserialize<'de>>(key: &[u8; 32], sealed: &str) -> Option { + serde_json::from_slice(&open(key, sealed)?).ok() +} + +fn app_cookies(cx: &Cx) -> impl Cookies { + cookies(cx) + .default_secure(client(cx).config.issuer.starts_with("https://")) + .default_http_only(true) + .default_same_site(topcoat::cookie::SameSite::Lax) + .default_path("/") +} + +fn set_session_cookie(cx: &Cx, state: &ImClient, session: &Session) { + let name = state.config.cookie_name.clone(); + app_cookies(cx).add(cookie! { + name = seal_json(&state.config.cookie_key, session); + Path = "/"; + HttpOnly; + SameSite = Lax; + MaxAge = time::Duration::days(30) + }); +} + +fn clear_cookie(cx: &Cx, name: &str) { + app_cookies(cx).remove(Cookie::build((name.to_string(), "")).path("/").build()); +} + +// --------------------------------------------------------------------------- +// Routes +// --------------------------------------------------------------------------- + +fn see(cx: &Cx, location: &str) -> Result { + ( + StatusCode::SEE_OTHER, + [(header::LOCATION, HeaderValue::from_str(location).unwrap())], + ) + .into_response(cx) +} + +/// A `next` worth honoring: a local absolute path, never `//elsewhere`. +fn safe_next(raw: &str) -> &str { + if raw.starts_with('/') && !raw.starts_with("//") { + raw + } else { + "/" + } +} + +/// A JWKS older than this is refreshed before the next validation. +const JWKS_TTL_SECONDS: i64 = 3600; + +async fn jwks_stale(state: &ImClient) -> bool { + match state.jwks.read().await.as_ref() { + None => true, + Some(cache) => { + cache.fetched_at < OffsetDateTime::now_utc() - time::Duration::seconds(JWKS_TTL_SECONDS) + } + } +} + +fn query_value(query: &str, key: &str) -> Option { + query.split('&').find_map(|pair| { + let (k, v) = pair.split_once('=')?; + (k == key).then(|| urldecode(v)) + }) +} + +/// Percent-decodes a query value (`+` is a space, form-style). +fn urldecode(raw: &str) -> String { + let bytes = raw.as_bytes(); + let mut out = Vec::with_capacity(bytes.len()); + let mut i = 0; + while i < bytes.len() { + match bytes[i] { + b'+' => { + out.push(b' '); + i += 1; + } + b'%' if i + 2 < bytes.len() => { + let hex = std::str::from_utf8(&bytes[i + 1..i + 3]).unwrap_or(""); + match u8::from_str_radix(hex, 16) { + Ok(byte) => { + out.push(byte); + i += 3; + } + Err(_) => { + out.push(b'%'); + i += 1; + } + } + } + byte => { + out.push(byte); + i += 1; + } + } + } + String::from_utf8_lossy(&out).into_owned() +} + +fn random_b64(bytes: usize) -> String { + let mut buf = vec![0u8; bytes]; + rand::rng().fill_bytes(&mut buf); + b64url.encode(buf) +} + +/// Sends the browser to im's `/authorize` with a fresh PKCE pair. +#[route(GET "/auth/login")] +async fn im_login(cx: &Cx) -> Result { + let state = client(cx); + let query = topcoat::router::request::uri(cx) + .query() + .unwrap_or("") + .to_string(); + let next = safe_next(query_value(&query, "next").as_deref().unwrap_or("/")).to_string(); + + let flight = InFlight { + verifier: random_b64(32), + state: random_b64(16), + nonce: random_b64(16), + next, + exp: OffsetDateTime::now_utc().unix_timestamp() + IN_FLIGHT_MINUTES * 60, + }; + let challenge = b64url.encode(Sha256::digest(flight.verifier.as_bytes())); + let cookie_name = format!("{}_pkce", state.config.cookie_name); + app_cookies(cx).add(cookie! { + cookie_name = seal_json(&state.config.cookie_key, &flight); + Path = "/"; + HttpOnly; + SameSite = Lax; + MaxAge = time::Duration::minutes(IN_FLIGHT_MINUTES) + }); + + let url = format!( + "{}/authorize?response_type=code&client_id={}&redirect_uri={}&scope=openid%20profile%20email&state={}&nonce={}&code_challenge={}&code_challenge_method=S256", + state.config.issuer, + state.config.client_id, + urlencoded(&state.config.redirect_uri), + flight.state, + flight.nonce, + challenge, + ); + see(cx, &url) +} + +/// im's answer lands here: exchange the code, validate the id_token, mint +/// the app session. +#[route(GET "/auth/callback")] +async fn im_callback(cx: &Cx) -> Result { + let state = client(cx); + let query = topcoat::router::request::uri(cx) + .query() + .unwrap_or("") + .to_string(); + if let Some(error) = query_value(&query, "error") { + return see(cx, &format!("/?auth_error={error}")); + } + let (Some(code), Some(presented_state)) = + (query_value(&query, "code"), query_value(&query, "state")) + else { + return see(cx, "/?auth_error=invalid_request"); + }; + let cookie_name = format!("{}_pkce", state.config.cookie_name); + let flight: Option = cookies(cx) + .get(&cookie_name) + .and_then(|c| open_json(&state.config.cookie_key, c.value())); + let Some(flight) = flight else { + return see(cx, "/?auth_error=invalid_request"); + }; + clear_cookie(cx, &cookie_name); + if flight.exp <= OffsetDateTime::now_utc().unix_timestamp() + || flight + .state + .as_bytes() + .ct_eq(presented_state.as_bytes()) + .unwrap_u8() + != 1 + { + return see(cx, "/?auth_error=invalid_state"); + } + + match exchange_code(state, &code, &flight).await { + Ok(session) => { + set_session_cookie(cx, state, &session); + see(cx, &flight.next) + } + Err(_) => see(cx, "/?auth_error=exchange_failed"), + } +} + +/// Signs out of the app only. To end the central session too, post to im's +/// `/logout` — a link there is a silent re-login, by design. +#[route(GET "/auth/logout")] +async fn im_logout(cx: &Cx) -> Result { + clear_cookie(cx, &client(cx).config.cookie_name); + see(cx, "/") +} + +fn urlencoded(raw: &str) -> String { + let mut out = String::with_capacity(raw.len()); + for byte in raw.bytes() { + match byte { + b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => { + out.push(byte as char) + } + _ => out.push_str(&format!("%{byte:02X}")), + } + } + out +} + +// --------------------------------------------------------------------------- +// Token exchange, refresh, validation +// --------------------------------------------------------------------------- + +#[derive(Deserialize)] +struct TokenAnswer { + /// Present on the wire; the app reads identity from the id_token and + /// never calls userinfo, so the access token is carried, not used. + #[serde(rename = "access_token")] + _access_token: String, + refresh_token: String, + id_token: String, + expires_in: i64, +} + +async fn exchange_code(state: &ImClient, code: &str, flight: &InFlight) -> Result { + let answer: TokenAnswer = state + .http + .post(format!("{}/token", state.config.issuer)) + .form(&[ + ("grant_type", "authorization_code"), + ("code", code), + ("redirect_uri", &state.config.redirect_uri), + ("client_id", &state.config.client_id), + ("client_secret", &state.config.client_secret), + ("code_verifier", &flight.verifier), + ]) + .send() + .await + .map_err(|e| Error::Http(e.to_string()))? + .error_for_status() + .map_err(|e| Error::Refused(e.to_string()))? + .json() + .await + .map_err(|e| Error::Http(e.to_string()))?; + let claims = validate_id_token(state, &answer.id_token).await?; + if claims["nonce"].as_str() != Some(flight.nonce.as_str()) { + return Err(Error::Token("nonce mismatch".into())); + } + Ok(session_from(&answer, claims)) +} + +async fn refresh(cx: &Cx, state: &ImClient, session: &mut Session) -> Result<()> { + let _ = cx; + let answer: TokenAnswer = state + .http + .post(format!("{}/token", state.config.issuer)) + .form(&[ + ("grant_type", "refresh_token"), + ("refresh_token", &session.refresh_token), + ("client_id", &state.config.client_id), + ("client_secret", &state.config.client_secret), + ]) + .send() + .await + .map_err(|e| Error::Http(e.to_string()))? + .error_for_status() + .map_err(|e| Error::Refused(e.to_string()))? + .json() + .await + .map_err(|e| Error::Http(e.to_string()))?; + let claims = validate_id_token(state, &answer.id_token).await?; + *session = session_from(&answer, claims); + Ok(()) +} + +fn session_from(answer: &TokenAnswer, claims: serde_json::Value) -> Session { + Session { + user: User { + sub: claims["sub"].as_str().unwrap_or_default().to_string(), + email: claims["email"].as_str().unwrap_or_default().to_string(), + name: claims["name"].as_str().unwrap_or_default().to_string(), + }, + refresh_token: answer.refresh_token.clone(), + access_exp: OffsetDateTime::now_utc().unix_timestamp() + answer.expires_in, + } +} + +/// Validates an id_token: RS256 against im's JWKS, issuer, audience, expiry. +/// The nonce is the caller's to check (only the callback holds one). +async fn validate_id_token(state: &ImClient, token: &str) -> Result { + let parts: Vec<&str> = token.split('.').collect(); + if parts.len() != 3 { + return Err(Error::Token("not a compact JWT".into())); + } + let header: serde_json::Value = serde_json::from_slice( + &b64url + .decode(parts[0]) + .map_err(|e| Error::Token(e.to_string()))?, + ) + .map_err(|e| Error::Token(e.to_string()))?; + if header["alg"] != "RS256" { + return Err(Error::Token("unexpected alg".into())); + } + let kid = header["kid"] + .as_str() + .ok_or_else(|| Error::Token("no kid".into()))? + .to_string(); + + if jwks_stale(state).await { + refetch_jwks(state).await?; + } + let key = match cached_key(state, &kid).await { + Some(key) => key, + None => { + refetch_jwks(state).await?; + cached_key(state, &kid) + .await + .ok_or_else(|| Error::Token("unknown kid after refetch".into()))? + } + }; + + verify_claims(&parts, &key, &state.config.issuer, &state.config.client_id) +} + +/// The pure half of [`validate_id_token`]: signature, issuer, audience, +/// expiry. Split out so the test suite signs its own tokens without standing +/// a server up. +fn verify_claims( + parts: &[&str], + key: &rsa::RsaPublicKey, + issuer: &str, + client_id: &str, +) -> Result { + use rsa::signature::Verifier; + let signature_bytes = b64url + .decode(parts[2]) + .map_err(|e| Error::Token(e.to_string()))?; + let signature = rsa::pkcs1v15::Signature::try_from(signature_bytes.as_slice()) + .map_err(|e| Error::Token(e.to_string()))?; + let verifying = rsa::pkcs1v15::VerifyingKey::::new(key.clone()); + verifying + .verify(format!("{}.{}", parts[0], parts[1]).as_bytes(), &signature) + .map_err(|_| Error::Token("bad signature".into()))?; + + let claims: serde_json::Value = serde_json::from_slice( + &b64url + .decode(parts[1]) + .map_err(|e| Error::Token(e.to_string()))?, + ) + .map_err(|e| Error::Token(e.to_string()))?; + if claims["iss"].as_str() != Some(issuer) { + return Err(Error::Token("wrong issuer".into())); + } + if claims["aud"].as_str() != Some(client_id) { + return Err(Error::Token("wrong audience".into())); + } + match claims["exp"].as_i64() { + Some(exp) if exp > OffsetDateTime::now_utc().unix_timestamp() => {} + _ => return Err(Error::Token("expired".into())), + } + Ok(claims) +} + +async fn cached_key(state: &ImClient, kid: &str) -> Option { + state + .jwks + .read() + .await + .as_ref()? + .keys + .iter() + .find(|(k, _)| k == kid) + .map(|(_, key)| key.clone()) +} + +/// Fetches and caches im's JWKS. Cached for an hour at most; an unknown kid +/// forces an immediate refetch above. +async fn refetch_jwks(state: &ImClient) -> Result<()> { + let doc: serde_json::Value = state + .http + .get(format!("{}/jwks.json", state.config.issuer)) + .send() + .await + .map_err(|e| Error::Http(e.to_string()))? + .error_for_status() + .map_err(|e| Error::Refused(e.to_string()))? + .json() + .await + .map_err(|e| Error::Http(e.to_string()))?; + let mut keys = Vec::new(); + for jwk in doc["keys"].as_array().into_iter().flatten() { + let (Some(kid), Some(n), Some(e)) = + (jwk["kid"].as_str(), jwk["n"].as_str(), jwk["e"].as_str()) + else { + continue; + }; + let (Ok(n), Ok(e)) = (b64url.decode(n), b64url.decode(e)) else { + continue; + }; + let key = rsa::RsaPublicKey::new( + rsa::BigUint::from_bytes_be(&n), + rsa::BigUint::from_bytes_be(&e), + ) + .map_err(|err| Error::Token(format!("bad jwk {kid}: {err}")))?; + keys.push((kid.to_string(), key)); + } + *state.jwks.write().await = Some(JwksCache { + fetched_at: OffsetDateTime::now_utc(), + keys, + }); + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + use rsa::signature::{SignatureEncoding, Signer}; + + fn keypair() -> (rsa::RsaPrivateKey, rsa::RsaPublicKey) { + // 2048-bit generation is slow for a unit test; 1024 is the smallest + // rsa 0.9 accepts and the signature math under test is identical. + let private = rsa::RsaPrivateKey::new(&mut rand_core06::OsRng, 1024).unwrap(); + let public = private.to_public_key(); + (private, public) + } + + fn sign(claims: serde_json::Value, key: &rsa::RsaPrivateKey) -> String { + let header = serde_json::json!({"alg": "RS256", "typ": "JWT", "kid": "test"}); + let mut out = b64url.encode(header.to_string()); + out.push('.'); + out.push_str(&b64url.encode(claims.to_string())); + let signing = rsa::pkcs1v15::SigningKey::::new(key.clone()); + let signature = signing.sign(out.as_bytes()); + format!("{}.{}", out, b64url.encode(signature.to_bytes())) + } + + fn good_claims() -> serde_json::Value { + serde_json::json!({ + "iss": "http://im.test", + "sub": "user-1", + "aud": "client-1", + "exp": OffsetDateTime::now_utc().unix_timestamp() + 600, + "iat": OffsetDateTime::now_utc().unix_timestamp(), + "email": "ann@example.com", + "name": "Ann", + }) + } + + #[test] + fn valid_token_validates() { + let (private, public) = keypair(); + let token = sign(good_claims(), &private); + let parts: Vec<&str> = token.split('.').collect(); + let claims = verify_claims(&parts, &public, "http://im.test", "client-1").unwrap(); + assert_eq!(claims["sub"], "user-1"); + } + + #[test] + fn tampered_payload_rejected() { + let (private, public) = keypair(); + let token = sign(good_claims(), &private); + let parts: Vec<&str> = token.split('.').collect(); + let forged_payload = b64url.encode(r#"{"sub":"mallory"}"#); + let forged = vec![parts[0], forged_payload.as_str(), parts[2]]; + assert!(verify_claims(&forged, &public, "http://im.test", "client-1").is_err()); + } + + #[test] + fn wrong_key_rejected() { + let (private, _) = keypair(); + let (_, other_public) = keypair(); + let token = sign(good_claims(), &private); + let parts: Vec<&str> = token.split('.').collect(); + assert!(verify_claims(&parts, &other_public, "http://im.test", "client-1").is_err()); + } + + #[test] + fn wrong_audience_rejected() { + let (private, public) = keypair(); + let token = sign(good_claims(), &private); + let parts: Vec<&str> = token.split('.').collect(); + assert!(verify_claims(&parts, &public, "http://im.test", "another-app").is_err()); + } + + #[test] + fn wrong_issuer_rejected() { + let (private, public) = keypair(); + let token = sign(good_claims(), &private); + let parts: Vec<&str> = token.split('.').collect(); + assert!(verify_claims(&parts, &public, "https://elsewhere.example", "client-1").is_err()); + } + + #[test] + fn expired_rejected() { + let (private, public) = keypair(); + let mut claims = good_claims(); + claims["exp"] = (OffsetDateTime::now_utc().unix_timestamp() - 10).into(); + let token = sign(claims, &private); + let parts: Vec<&str> = token.split('.').collect(); + assert!(verify_claims(&parts, &public, "http://im.test", "client-1").is_err()); + } + + #[test] + fn pkce_rfc7636_vector() { + // RFC 7636 Appendix B. + let verifier = "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"; + let challenge = b64url.encode(Sha256::digest(verifier.as_bytes())); + assert_eq!(challenge, "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM"); + } + + #[test] + fn cookie_seal_roundtrip() { + let key = [7u8; 32]; + let session = Session { + user: User { + sub: "u".into(), + email: "e".into(), + name: "n".into(), + }, + refresh_token: "r".into(), + access_exp: 1, + }; + let sealed = seal_json(&key, &session); + let back: Session = open_json(&key, &sealed).unwrap(); + assert_eq!(back.refresh_token, "r"); + assert!(open_json::(&[8u8; 32], &sealed).is_none()); + assert!(open_json::(&key, "garbage").is_none()); + } +} diff --git a/crates/im-core/Cargo.toml b/crates/im-core/Cargo.toml new file mode 100644 index 0000000..9e001a8 --- /dev/null +++ b/crates/im-core/Cargo.toml @@ -0,0 +1,58 @@ +[package] +name = "im-core" +version.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +description = "im domain model and storage: users, invites, sessions, OIDC material" + +[features] +# The domain vocabulary (record shapes, id wrappers) compiles anywhere. +# Everything that touches a database, a password or a CSPRNG lives behind +# `server` (same contract as izlek-core). +default = ["server"] +server = [ + "dep:argon2", + "dep:base64", + "dep:chacha20poly1305", + "dep:data-encoding", + "dep:hmac", + "dep:rand", + "dep:rand_core", + "dep:rsa", + "dep:sha1", + "dep:sha2", + "dep:sha2-for-rsa", + "dep:subtle", + "dep:tokio", + "dep:turso", + "dep:ulid", +] + +[dependencies] +argon2 = { workspace = true, optional = true } +base64 = { workspace = true, optional = true } +chacha20poly1305 = { workspace = true, optional = true } +data-encoding = { version = "2.11.1", optional = true } +hmac = { version = "0.13.0", optional = true } +rand = { workspace = true, optional = true } +# rsa 0.9 sits on the rand_core 0.6 / digest 0.10 trait lines, so its RNG +# and its hasher come from those lines, not the workspace's rand 0.10 / +# sha2 0.11. sha2 0.11 stays for token digests. +rand_core = { version = "0.6.4", features = ["getrandom"], optional = true } +rsa = { version = "0.9.10", optional = true } +sha1 = { version = "0.11.0", optional = true } +sha2 = { workspace = true, optional = true } +sha2-for-rsa = { package = "sha2", version = "0.10", features = ["oid"], optional = true } +subtle = { workspace = true, optional = true } +serde.workspace = true +serde_json.workspace = true +thiserror.workspace = true +time.workspace = true +tokio = { workspace = true, optional = true } +turso = { workspace = true, optional = true } +ulid = { workspace = true, optional = true } + +[dev-dependencies] +tokio.workspace = true +tempfile = "3" diff --git a/crates/im-core/src/accounts.rs b/crates/im-core/src/accounts.rs new file mode 100644 index 0000000..f4e4bd0 --- /dev/null +++ b/crates/im-core/src/accounts.rs @@ -0,0 +1,510 @@ +//! Accounts: passwords, invites, and the rules around them. Ported from +//! izlek-core's `auth.rs`/`accounts.rs` — same product family, same author. +//! +//! Two different jobs, deliberately kept apart: +//! +//! * **Passwords** are low-entropy and chosen by a person, so they go through +//! Argon2id with deliberately expensive parameters. +//! * **Tokens** — invites, session cookies, client secrets, auth codes — are +//! 256 bits from a CSPRNG. There is nothing to brute-force, so they are +//! stored as a plain SHA-256 digest. + +use argon2::password_hash::phc::PasswordHash; +use argon2::password_hash::{PasswordHasher, PasswordVerifier}; +use argon2::{Algorithm, Argon2, Params, Version}; +use base64::Engine; +use base64::engine::general_purpose::URL_SAFE_NO_PAD as base64url; +use rand::Rng; +use serde::{Deserialize, Serialize}; +use sha2::{Digest, Sha256}; +use subtle::ConstantTimeEq; + +use crate::model::{Invite, User, UserId}; +use crate::store::{self, Result, Store, StoreError, backend}; + +/// Argon2id at the OWASP Password Storage Cheat Sheet's recommended second +/// configuration: 19 MiB of memory, two iterations, one lane. +pub const ARGON2_MEMORY_KIB: u32 = 19 * 1024; +pub const ARGON2_ITERATIONS: u32 = 2; +pub const ARGON2_PARALLELISM: u32 = 1; + +/// How many bytes of randomness every token carries. +pub const TOKEN_BYTES: usize = 32; + +/// The shortest password this service accepts. +/// +/// Named because the form that takes a new password carries it too — as +/// `minlength`, so the browser enforces the rule where it is being broken +/// rather than the server explaining it afterwards. Two places, one number. +pub const MIN_PASSWORD_CHARS: usize = 10; + +/// How long an invite stays valid. +pub const INVITE_DAYS: i64 = 7; + +/// A password rule the person's choice broke. The wording is the wording on +/// the invite-acceptance screen. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, thiserror::Error)] +pub enum PasswordProblem { + #[error("at least 10 characters")] + TooShort, + #[error("not your address or your name")] + LooksLikeYou, + /// The "new" password is the one already in force — the walk-away + /// mistake, refused by name rather than silently succeeding. + #[error("that's your current password")] + IsCurrent, +} + +#[derive(Debug, thiserror::Error)] +pub enum AccountError { + #[error("database: {0}")] + Backend(String), + #[error("wrong email or password")] + InvalidCredentials, + #[error("this invite is not valid")] + InviteInvalid, + #[error("this invite has expired")] + InviteExpired, + #[error("this invite was already used")] + InviteSpent, + #[error("an account with this address already exists")] + EmailTaken, + #[error("password: {0}")] + Password(#[from] PasswordProblem), + #[error("password hashing failed: {0}")] + Hashing(String), +} + +impl From for AccountError { + fn from(e: StoreError) -> Self { + AccountError::Backend(e.to_string()) + } +} + +fn argon2() -> Argon2<'static> { + let params = Params::new( + ARGON2_MEMORY_KIB, + ARGON2_ITERATIONS, + ARGON2_PARALLELISM, + None, + ) + .expect("argon2 parameters are constants and are in range"); + Argon2::new(Algorithm::Argon2id, Version::V0x13, params) +} + +/// Hashes a password into a PHC string, salt included. +pub fn hash_password(password: &str) -> std::result::Result { + argon2() + .hash_password(password.as_bytes()) + .map(|h| h.to_string()) + .map_err(|e| AccountError::Hashing(e.to_string())) +} + +/// Checks a password against a stored PHC string. +/// +/// The parameters come from the stored hash, not from [`argon2`], so raising +/// the cost later does not lock anyone out — and hashes migrated from İzlek +/// verify unchanged. +pub fn verify_password(password: &str, phc: &str) -> bool { + match PasswordHash::new(phc) { + Ok(parsed) => argon2() + .verify_password(password.as_bytes(), &parsed) + .is_ok(), + Err(_) => false, + } +} + +/// A PHC string for a password nobody knows, used to keep the miss path as +/// expensive as the hit path. +/// +/// Without this, "no such address" answers before Argon2 would have finished +/// and the response time tells an attacker what the wording refuses to. +pub fn dummy_password_hash() -> &'static str { + // Minted once over 256 bits of randomness that was never written down. + "$argon2id$v=19$m=19456,t=2,p=1$0JjUMrLBpJG7lzg5bxZhMQ$iGpGXBNDAaHV9jqDxDcCyuIEIV33kJ1IAPt0XCh753Q" +} + +/// Burns the same work a real verify would, and always fails. +/// +/// Call this on every path where a lookup missed, before answering. +pub fn dummy_verify(password: &str) { + let _ = verify_password(password, dummy_password_hash()); +} + +/// A freshly minted secret. The plaintext exists only here and in the one +/// place that shows it; the database gets [`Token::hash`]. +#[derive(Clone)] +pub struct Token { + plaintext: String, +} + +impl Token { + /// 256 bits from the thread CSPRNG, base64url-no-pad encoded. + pub fn mint() -> Self { + let mut bytes = [0u8; TOKEN_BYTES]; + rand::rng().fill_bytes(&mut bytes); + Self { + plaintext: base64url.encode(bytes), + } + } + + /// The value that goes in the link or the cookie. Shown exactly once. + pub fn expose(&self) -> &str { + &self.plaintext + } + + /// The value that goes in the database. + pub fn hash(&self) -> String { + hash_token(&self.plaintext) + } +} + +impl std::fmt::Debug for Token { + /// A token must not reach a log through a stray `{:?}`. + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str("Token(redacted)") + } +} + +/// SHA-256 of a token, hex encoded. Tokens are full-entropy, so a fast digest +/// is the right primitive here. +pub fn hash_token(plaintext: &str) -> String { + let mut hasher = Sha256::new(); + hasher.update(plaintext.as_bytes()); + hex(&hasher.finalize()) +} + +/// Compares two token digests without leaking where they diverge. +pub fn digests_match(a: &str, b: &str) -> bool { + a.as_bytes().ct_eq(b.as_bytes()).into() +} + +pub(crate) fn hex(bytes: &[u8]) -> String { + let mut out = String::with_capacity(bytes.len() * 2); + for byte in bytes { + out.push_str(&format!("{byte:02x}")); + } + out +} + +/// The rules the invite-acceptance screen states, checked server-side. +pub fn check_password( + password: &str, + email: &str, + display_name: &str, +) -> std::result::Result<(), PasswordProblem> { + // Counted in characters, not bytes: a ten-character password is ten + // characters whatever alphabet it is in. + if password.chars().count() < MIN_PASSWORD_CHARS { + return Err(PasswordProblem::TooShort); + } + + let folded = password.to_lowercase(); + let local_part = email.split('@').next().unwrap_or(email); + let mut forbidden = vec![email.to_lowercase(), local_part.to_lowercase()]; + forbidden.extend( + display_name + .split_whitespace() + .map(|word| word.to_lowercase()), + ); + for needle in forbidden { + // Short words ("de", "van") would forbid too much to be useful. + if needle.chars().count() >= 3 && folded.contains(&needle) { + return Err(PasswordProblem::LooksLikeYou); + } + } + Ok(()) +} + +// --------------------------------------------------------------------------- +// Invites and users +// --------------------------------------------------------------------------- + +/// Creates an invite for `email`, returning the raw token to put in the mail. +/// The row holds only its digest. +pub async fn create_invite( + store: &Store, + email: &str, + invited_by: Option, +) -> std::result::Result { + let token = Token::mint(); + let now = store::now(); + let expires = now + time::Duration::days(INVITE_DAYS); + store + .conn + .execute( + "INSERT INTO invites (token, email, invited_by, created_at, expires_at) \ + VALUES (?1, ?2, ?3, ?4, ?5)", + turso::params![ + token.hash(), + email, + invited_by.map(|id| id.to_string()), + store::stamp(now)?, + store::stamp(expires)?, + ], + ) + .await + .map_err(backend)?; + Ok(token) +} + +/// Looks an invite up by its raw token. Expiry and spent-ness are the +/// caller's to rule on — this answers what the row says. +pub async fn invite_by_token(store: &Store, token: &str) -> Result> { + let mut rows = store + .conn + .query( + "SELECT email, invited_by, created_at, expires_at, accepted_at \ + FROM invites WHERE token = ?1", + turso::params![hash_token(token)], + ) + .await + .map_err(backend)?; + let Some(row) = rows.next().await.map_err(backend)? else { + return Ok(None); + }; + Ok(Some(Invite { + email: store::text(&row, 0)?, + invited_by: store::opt_text(&row, 1)?.map(UserId::from), + created_at: store::parse_stamp(&store::text(&row, 2)?)?, + expires_at: store::parse_stamp(&store::text(&row, 3)?)?, + accepted_at: match store::opt_text(&row, 4)? { + Some(raw) => Some(store::parse_stamp(&raw)?), + None => None, + }, + })) +} + +/// Turns a valid invite into a user. The invite is marked accepted in the +/// same transaction as the user insert, so a token can never mint two +/// accounts. +pub async fn create_user_from_invite( + store: &Store, + token: &str, + name: &str, + password: &str, +) -> std::result::Result { + let invite = invite_by_token(store, token) + .await? + .ok_or(AccountError::InviteInvalid)?; + if invite.accepted_at.is_some() { + return Err(AccountError::InviteSpent); + } + if invite.expires_at < store::now() { + return Err(AccountError::InviteExpired); + } + check_password(password, &invite.email, name)?; + let user = User { + id: UserId::mint(), + email: invite.email.clone(), + name: name.to_string(), + totp_confirmed: false, + disabled: false, + created_at: store::now(), + }; + let password_hash = hash_password(password)?; + + store + .conn + .execute("BEGIN IMMEDIATE", ()) + .await + .map_err(backend)?; + let outcome = async { + store + .conn + .execute( + "INSERT INTO users (id, email, name, password_hash, created_at) \ + VALUES (?1, ?2, ?3, ?4, ?5)", + turso::params![ + user.id.to_string(), + user.email.clone(), + user.name.clone(), + password_hash, + store::stamp(user.created_at)?, + ], + ) + .await + .map_err(|e| { + let text = e.to_string().to_lowercase(); + if text.contains("constraint") || text.contains("unique") { + AccountError::EmailTaken + } else { + AccountError::Backend(e.to_string()) + } + })?; + store + .conn + .execute( + "UPDATE invites SET accepted_at = ?1 WHERE token = ?2 AND accepted_at IS NULL", + turso::params![store::stamp(store::now())?, hash_token(token)], + ) + .await + .map_err(|e| AccountError::Backend(e.to_string()))?; + Ok::<_, AccountError>(()) + } + .await; + match outcome { + Ok(()) => { + store.conn.execute("COMMIT", ()).await.map_err(backend)?; + Ok(user) + } + Err(e) => { + let _ = store.conn.execute("ROLLBACK", ()).await; + Err(e) + } + } +} + +/// Verifies an email+password pair, returning the user on success. Disabled +/// accounts are refused with the same wording as a wrong password, and every +/// miss path burns an Argon2 run so timing does not say which one it was. +pub async fn verify_login( + store: &Store, + email: &str, + password: &str, +) -> std::result::Result { + let mut rows = store + .conn + .query( + "SELECT id, email, name, password_hash, totp_confirmed, disabled, created_at \ + FROM users WHERE email = ?1 COLLATE NOCASE", + turso::params![email], + ) + .await + .map_err(backend)?; + let Some(row) = rows.next().await.map_err(backend)? else { + dummy_verify(password); + return Err(AccountError::InvalidCredentials); + }; + let user = User { + id: UserId::from(store::text(&row, 0)?), + email: store::text(&row, 1)?, + name: store::text(&row, 2)?, + totp_confirmed: store::int(&row, 4)? != 0, + disabled: store::int(&row, 5)? != 0, + created_at: store::parse_stamp(&store::text(&row, 6)?)?, + }; + let phc = store::text(&row, 3)?; + if !verify_password(password, &phc) || user.disabled { + return Err(AccountError::InvalidCredentials); + } + Ok(user) +} + +/// Looks a user up by id — what sessions and tokens resolve to. +pub async fn user_by_id(store: &Store, id: &UserId) -> Result> { + let mut rows = store + .conn + .query( + "SELECT id, email, name, totp_confirmed, disabled, created_at \ + FROM users WHERE id = ?1", + turso::params![id.to_string()], + ) + .await + .map_err(backend)?; + let Some(row) = rows.next().await.map_err(backend)? else { + return Ok(None); + }; + Ok(Some(User { + id: UserId::from(store::text(&row, 0)?), + email: store::text(&row, 1)?, + name: store::text(&row, 2)?, + totp_confirmed: store::int(&row, 3)? != 0, + disabled: store::int(&row, 4)? != 0, + created_at: store::parse_stamp(&store::text(&row, 5)?)?, + })) +} + +#[cfg(test)] +mod tests { + use super::*; + + async fn fixture() -> Store { + Store::open(Path::new(":memory:")).await.unwrap() + } + + use std::path::Path; + + #[test] + fn password_roundtrip() { + let phc = hash_password("correct horse battery staple").unwrap(); + assert!(verify_password("correct horse battery staple", &phc)); + assert!(!verify_password("wrong horse battery staple", &phc)); + } + + #[test] + fn password_rules() { + assert_eq!( + check_password("short", "a@b.c", "Ann"), + Err(PasswordProblem::TooShort) + ); + assert_eq!( + check_password("ann.smith-99", "ann.smith@x.y", "Ann Smith"), + Err(PasswordProblem::LooksLikeYou) + ); + assert!(check_password("tDLr9!mZQ2xv", "ann.smith@x.y", "Ann Smith").is_ok()); + } + + #[test] + fn token_hash_is_not_the_token() { + let token = Token::mint(); + assert_ne!(token.expose(), token.hash()); + assert_eq!(token.hash().len(), 64, "sha256 hex"); + } + + #[tokio::test] + async fn invite_to_user_to_login() { + let store = fixture().await; + let token = create_invite(&store, "ann@example.com", None) + .await + .unwrap(); + let invite = invite_by_token(&store, token.expose()) + .await + .unwrap() + .unwrap(); + assert_eq!(invite.email, "ann@example.com"); + assert!(invite.accepted_at.is_none()); + + let user = create_user_from_invite(&store, token.expose(), "Ann", "tDLr9!mZQ2xv") + .await + .unwrap(); + assert_eq!(user.email, "ann@example.com"); + + // The invite is spent: a second use is refused. + assert!(matches!( + create_user_from_invite(&store, token.expose(), "Ann", "tDLr9!mZQ2xv").await, + Err(AccountError::InviteSpent) + )); + + let logged = verify_login(&store, "ANN@example.com", "tDLr9!mZQ2xv") + .await + .unwrap(); + assert_eq!(logged.id, user.id); + assert!(matches!( + verify_login(&store, "ann@example.com", "wrong-password").await, + Err(AccountError::InvalidCredentials) + )); + assert!(matches!( + verify_login(&store, "nobody@example.com", "tDLr9!mZQ2xv").await, + Err(AccountError::InvalidCredentials) + )); + } + + #[tokio::test] + async fn duplicate_email_is_refused() { + let store = fixture().await; + let first = create_invite(&store, "ann@example.com", None) + .await + .unwrap(); + create_user_from_invite(&store, first.expose(), "Ann", "tDLr9!mZQ2xv") + .await + .unwrap(); + let second = create_invite(&store, "ann@example.com", None) + .await + .unwrap(); + assert!(matches!( + create_user_from_invite(&store, second.expose(), "Ann Two", "tDLr9!mZQ2xv").await, + Err(AccountError::EmailTaken) + )); + } +} diff --git a/crates/im-core/src/keys.rs b/crates/im-core/src/keys.rs new file mode 100644 index 0000000..e64b0b6 --- /dev/null +++ b/crates/im-core/src/keys.rs @@ -0,0 +1,156 @@ +//! JWT signing keys: RSA-2048 pairs generated on first boot, sealed at rest, +//! published as a JWKS. +//! +//! The private half never leaves this module unsealed: the database holds the +//! XChaCha20-Poly1305 envelope of its PKCS#8 DER under `im.key`, and only +//! `active_signing_key` (signing) and `jwks` (the public half) cross the +//! boundary. +use rsa::pkcs8::{DecodePrivateKey, DecodePublicKey, EncodePrivateKey, EncodePublicKey}; +use rsa::traits::PublicKeyParts; +use rsa::{RsaPrivateKey, RsaPublicKey}; +use sha2::Digest; + +use crate::accounts::hex; +use crate::secret; +use crate::store::{self, Result, Store, StoreError, backend}; + +/// The active signing key, generating and storing one on first boot. +/// +/// `kid` is a fingerprint of the public half, so a key's id is stable across +/// restarts and a JWKS consumer can match header to key without guessing. +pub async fn active_signing_key(store: &Store) -> Result<(String, RsaPrivateKey)> { + let mut rows = store + .conn + .query( + "SELECT kid, private_der_enc FROM signing_keys WHERE active = 1 \ + ORDER BY created_at DESC LIMIT 1", + (), + ) + .await + .map_err(backend)?; + if let Some(row) = rows.next().await.map_err(backend)? { + let kid = store::text(&row, 0)?; + let sealed = store::text(&row, 1)?; + let der = secret::open(store.key(), &sealed) + .ok_or_else(|| StoreError::Corrupt("signing key does not open".into()))?; + let key = RsaPrivateKey::from_pkcs8_der(&der) + .map_err(|e| StoreError::Corrupt(format!("signing key: {e}")))?; + return Ok((kid, key)); + } + + let mut rng = rand_core::OsRng; + let key = RsaPrivateKey::new(&mut rng, 2048) + .map_err(|e| StoreError::Backend(format!("key generation: {e}")))?; + let public_der = key + .to_public_key() + .to_public_key_der() + .map_err(|e| StoreError::Backend(format!("public der: {e}")))? + .as_bytes() + .to_vec(); + let private_der = key + .to_pkcs8_der() + .map_err(|e| StoreError::Backend(format!("private der: {e}")))? + .as_bytes() + .to_vec(); + let kid = kid_of(&public_der); + store + .conn + .execute( + "INSERT INTO signing_keys (kid, private_der_enc, public_der, created_at) \ + VALUES (?1, ?2, ?3, ?4)", + turso::params![ + kid.clone(), + secret::seal(store.key(), &private_der), + public_der, + store::stamp(store::now())?, + ], + ) + .await + .map_err(backend)?; + Ok((kid, key)) +} + +/// A key id: the first 16 hex of the public half's SHA-256. +fn kid_of(public_der: &[u8]) -> String { + hex(&sha2::Sha256::digest(public_der))[..16].to_string() +} + +/// Every active public key as a JWKS document. +pub async fn jwks(store: &Store) -> Result { + use base64::Engine; + let mut rows = store + .conn + .query( + "SELECT kid, public_der FROM signing_keys WHERE active = 1 ORDER BY created_at", + (), + ) + .await + .map_err(backend)?; + let mut keys = Vec::new(); + while let Some(row) = rows.next().await.map_err(backend)? { + let kid = store::text(&row, 0)?; + let der = row.get::>(1).map_err(backend)?; + let public = RsaPublicKey::from_public_key_der(&der) + .map_err(|e| StoreError::Corrupt(format!("public key {kid}: {e}")))?; + let b64 = base64::engine::general_purpose::URL_SAFE_NO_PAD; + keys.push(serde_json::json!({ + "kty": "RSA", + "use": "sig", + "alg": "RS256", + "kid": kid, + "n": b64.encode(public.n().to_bytes_be()), + "e": b64.encode(public.e().to_bytes_be()), + })); + } + Ok(serde_json::json!({ "keys": keys })) +} + +/// The public half of an active key, by id — what JWT verification looks up. +pub async fn public_key_by_kid(store: &Store, kid: &str) -> Result> { + let mut rows = store + .conn + .query( + "SELECT public_der FROM signing_keys WHERE kid = ?1 AND active = 1", + turso::params![kid], + ) + .await + .map_err(backend)?; + let Some(row) = rows.next().await.map_err(backend)? else { + return Ok(None); + }; + let der = row.get::>(0).map_err(backend)?; + RsaPublicKey::from_public_key_der(&der) + .map(Some) + .map_err(|e| StoreError::Corrupt(format!("public key {kid}: {e}"))) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[tokio::test] + async fn key_is_generated_once_and_reopened() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("im.db"); + let (kid, first) = { + let store = Store::open(&path).await.unwrap(); + let (kid, key) = active_signing_key(&store).await.unwrap(); + // A second ask returns the same key rather than generating. + let (kid2, _) = active_signing_key(&store).await.unwrap(); + assert_eq!(kid, kid2); + (kid, key) + }; + // A fresh store over the same database + im.key opens the same key. + let store = Store::open(&path).await.unwrap(); + let (kid2, second) = active_signing_key(&store).await.unwrap(); + assert_eq!(kid, kid2); + assert_eq!(first.to_public_key(), second.to_public_key()); + + let doc = jwks(&store).await.unwrap(); + let keys = doc["keys"].as_array().unwrap(); + assert_eq!(keys.len(), 1); + assert_eq!(keys[0]["kid"].as_str().unwrap(), kid); + assert_eq!(keys[0]["kty"], "RSA"); + assert_eq!(keys[0]["alg"], "RS256"); + } +} diff --git a/crates/im-core/src/lib.rs b/crates/im-core/src/lib.rs new file mode 100644 index 0000000..9ba82e6 --- /dev/null +++ b/crates/im-core/src/lib.rs @@ -0,0 +1,23 @@ +//! im-core: domain model and storage for im, the IzlekLab SSO. +//! +//! `model` is the shared vocabulary (id wrappers, record shapes) and compiles +//! anywhere. Everything that touches a database, a password, a signing key or +//! a CSPRNG lives behind the `server` feature so none of it can ship to a +//! browser bundle — the same contract izlek-core keeps. + +#[cfg(feature = "server")] +pub mod accounts; +#[cfg(feature = "server")] +pub mod keys; +#[cfg(feature = "server")] +pub mod oidc; +#[cfg(feature = "server")] +mod secret; +#[cfg(feature = "server")] +pub mod sessions; +#[cfg(feature = "server")] +pub mod store; +#[cfg(feature = "server")] +pub mod totp; + +pub mod model; diff --git a/crates/im-core/src/model.rs b/crates/im-core/src/model.rs new file mode 100644 index 0000000..bd163c3 --- /dev/null +++ b/crates/im-core/src/model.rs @@ -0,0 +1,100 @@ +//! Record shapes shared by every im crate. +//! +//! No crypto, no database, no CSPRNG here: this module compiles anywhere, +//! including a browser bundle. Id wrappers are plain newtypes; minting lives +//! behind the `server` feature where `ulid` is available. + +use serde::{Deserialize, Serialize}; +use time::OffsetDateTime; + +macro_rules! id_wrapper { + ($name:ident, $doc:literal) => { + #[doc = $doc] + #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] + #[serde(transparent)] + pub struct $name(pub String); + + impl $name { + /// A fresh ULID — sortable, URL-safe, unguessable enough for an id. + #[cfg(feature = "server")] + pub fn mint() -> Self { + Self(ulid::Ulid::new().to_string()) + } + + pub fn as_str(&self) -> &str { + &self.0 + } + } + + impl std::fmt::Display for $name { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(&self.0) + } + } + + impl From for $name { + fn from(raw: String) -> Self { + Self(raw) + } + } + }; +} + +id_wrapper!(UserId, "A user's id — the OIDC `sub` claim."); +id_wrapper!(ClientId, "An OIDC client's id."); + +/// A registered user. `password_hash` and the TOTP material never leave +/// `accounts`/`totp` — this shape is what the rest of the system sees. +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct User { + pub id: UserId, + pub email: String, + pub name: String, + pub totp_confirmed: bool, + pub disabled: bool, + pub created_at: OffsetDateTime, +} + +/// An outstanding (or spent) invite, as stored. The raw token exists only in +/// the mail that carried it; the row holds its digest. +#[derive(Debug, Clone)] +pub struct Invite { + pub email: String, + pub invited_by: Option, + pub created_at: OffsetDateTime, + pub expires_at: OffsetDateTime, + pub accepted_at: Option, +} + +/// An OIDC relying party registered with im. +#[derive(Debug, Clone)] +pub struct OidcClient { + pub client_id: ClientId, + pub name: String, + pub secret_hash: String, + pub redirect_uris: Vec, + pub created_at: OffsetDateTime, +} + +/// An authorization code mid-exchange. Consumed exactly once. +#[derive(Debug, Clone)] +pub struct AuthCode { + pub client_id: ClientId, + pub user_id: UserId, + pub redirect_uri: String, + pub nonce: Option, + pub code_challenge: String, + /// The central session that minted this code — the refresh token issued + /// off it binds to the same session, so logout kills the chain. + pub session_hash: String, + pub expires_at: OffsetDateTime, +} + +/// A refresh token row, post-lookup. +#[derive(Debug, Clone)] +pub struct RefreshToken { + pub user_id: UserId, + pub client_id: ClientId, + pub session_hash: String, + pub expires_at: OffsetDateTime, +} diff --git a/crates/im-core/src/oidc.rs b/crates/im-core/src/oidc.rs new file mode 100644 index 0000000..a10eea1 --- /dev/null +++ b/crates/im-core/src/oidc.rs @@ -0,0 +1,552 @@ +//! The OIDC provider half: relying-party registration, authorization codes, +//! refresh tokens, and the hand-rolled RS256 JWT the endpoints mint. +//! +//! JWT is hand-rolled on purpose: both ends of the wire are ours, the format +//! is `base64url(header).base64url(payload).base64url(signature)` and nothing +//! more, and a third crate in the trust path buys nothing. + +use base64::Engine; +use base64::engine::general_purpose::URL_SAFE_NO_PAD as b64url; +use rsa::RsaPrivateKey; +use rsa::signature::{SignatureEncoding, Signer}; + +use crate::accounts::{Token, digests_match, hash_token}; +use crate::model::{AuthCode, ClientId, OidcClient, RefreshToken, UserId}; +use crate::store::{self, Result, Store, StoreError, backend}; + +/// How long an authorization code lives, in seconds. +pub const CODE_SECONDS: i64 = 60; +/// How long an access/id token lives, in seconds. +pub const TOKEN_SECONDS: i64 = 15 * 60; +/// How long a refresh token lives. +pub const REFRESH_DAYS: i64 = 30; + +#[derive(Debug, thiserror::Error)] +pub enum OidcError { + #[error("database: {0}")] + Backend(String), + #[error("unknown client")] + UnknownClient, + #[error("bad client secret")] + BadSecret, +} + +impl From for OidcError { + fn from(e: StoreError) -> Self { + OidcError::Backend(e.to_string()) + } +} + +/// Signs `claims` into a compact RS256 JWT under `kid`. +pub fn sign_jwt(claims: &serde_json::Value, kid: &str, key: &RsaPrivateKey) -> String { + let header = serde_json::json!({ "alg": "RS256", "typ": "JWT", "kid": kid }); + let mut out = b64url.encode(header.to_string()); + out.push('.'); + out.push_str(&b64url.encode(claims.to_string())); + let signing = rsa::pkcs1v15::SigningKey::::new(key.clone()); + let signature = signing.sign(out.as_bytes()); + out.push('.'); + out.push_str(&b64url.encode(signature.to_bytes())); + out +} + +// --------------------------------------------------------------------------- +// Clients +// --------------------------------------------------------------------------- + +/// Registers a relying party, returning its id and the raw client secret — +/// shown exactly once; the row holds the digest. +pub async fn create_client( + store: &Store, + name: &str, + redirect_uris: Vec, +) -> Result<(ClientId, Token)> { + let id = ClientId::mint(); + let secret = Token::mint(); + store + .conn + .execute( + "INSERT INTO oidc_clients (client_id, name, secret_hash, redirect_uris, created_at) \ + VALUES (?1, ?2, ?3, ?4, ?5)", + turso::params![ + id.to_string(), + name, + secret.hash(), + serde_json::to_string(&redirect_uris) + .map_err(|e| StoreError::Corrupt(format!("redirect_uris: {e}")))?, + store::stamp(store::now())?, + ], + ) + .await + .map_err(backend)?; + Ok((id, secret)) +} + +/// Looks a client up by its public id. +pub async fn client_by_id(store: &Store, client_id: &str) -> Result> { + let mut rows = store + .conn + .query( + "SELECT client_id, name, secret_hash, redirect_uris, created_at \ + FROM oidc_clients WHERE client_id = ?1", + turso::params![client_id], + ) + .await + .map_err(backend)?; + let Some(row) = rows.next().await.map_err(backend)? else { + return Ok(None); + }; + Ok(Some(read_client(&row)?)) +} + +fn read_client(row: &turso::Row) -> Result { + let uris_raw = store::text(row, 3)?; + Ok(OidcClient { + client_id: ClientId::from(store::text(row, 0)?), + name: store::text(row, 1)?, + secret_hash: store::text(row, 2)?, + redirect_uris: serde_json::from_str(&uris_raw) + .map_err(|e| StoreError::Corrupt(format!("redirect_uris {uris_raw:?}: {e}")))?, + created_at: store::parse_stamp(&store::text(row, 4)?)?, + }) +} + +/// Constant-time client-secret check. +pub fn verify_client_secret(client: &OidcClient, secret: &str) -> bool { + digests_match(&client.secret_hash, &hash_token(secret)) +} + +// --------------------------------------------------------------------------- +// Authorization codes +// --------------------------------------------------------------------------- + +/// Mints an authorization code for a completed login. Raw code returned; the +/// row holds the digest. +pub async fn create_auth_code( + store: &Store, + client_id: &ClientId, + user: &UserId, + redirect_uri: &str, + nonce: Option, + challenge: &str, + session_hash: &str, +) -> Result { + let code = Token::mint(); + store + .conn + .execute( + "INSERT INTO auth_codes \ + (code_hash, client_id, user_id, redirect_uri, nonce, code_challenge, session_hash, expires_at) \ + VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)", + turso::params![ + code.hash(), + client_id.to_string(), + user.to_string(), + redirect_uri, + nonce, + challenge, + session_hash, + store::stamp(store::now() + time::Duration::seconds(CODE_SECONDS))?, + ], + ) + .await + .map_err(backend)?; + Ok(code) +} + +/// Consumes a code: returns its row exactly once. The SELECT and the +/// `consumed_at` stamp run inside one immediate transaction, so two parallel +/// exchanges of the same code cannot both succeed. +pub async fn consume_auth_code(store: &Store, code: &str) -> Result> { + let hash = hash_token(code); + store + .conn + .execute("BEGIN IMMEDIATE", ()) + .await + .map_err(backend)?; + let outcome = async { + let mut rows = store + .conn + .query( + "SELECT client_id, user_id, redirect_uri, nonce, code_challenge, session_hash, \ + expires_at, consumed_at FROM auth_codes WHERE code_hash = ?1", + turso::params![hash.clone()], + ) + .await + .map_err(backend)?; + let Some(row) = rows.next().await.map_err(backend)? else { + return Ok(None); + }; + if store::opt_text(&row, 7)?.is_some() { + return Ok(None); + } + if store::parse_stamp(&store::text(&row, 6)?)? < store::now() { + return Ok(None); + } + store + .conn + .execute( + "UPDATE auth_codes SET consumed_at = ?1 WHERE code_hash = ?2", + turso::params![store::stamp(store::now())?, hash], + ) + .await + .map_err(backend)?; + Ok(Some(AuthCode { + client_id: ClientId::from(store::text(&row, 0)?), + user_id: UserId::from(store::text(&row, 1)?), + redirect_uri: store::text(&row, 2)?, + nonce: store::opt_text(&row, 3)?, + code_challenge: store::text(&row, 4)?, + session_hash: store::text(&row, 5)?, + expires_at: store::parse_stamp(&store::text(&row, 6)?)?, + })) + } + .await; + match outcome { + Ok(found) => { + store.conn.execute("COMMIT", ()).await.map_err(backend)?; + Ok(found) + } + Err(e) => { + let _ = store.conn.execute("ROLLBACK", ()).await; + Err(e) + } + } +} + +// --------------------------------------------------------------------------- +// Refresh tokens +// --------------------------------------------------------------------------- + +/// Issues a refresh token bound to the central session that minted it, so +/// revoking the session retires every token the apps are still holding. +pub async fn issue_refresh( + store: &Store, + user: &UserId, + client_id: &ClientId, + session_hash: &str, +) -> Result { + let token = Token::mint(); + store + .conn + .execute( + "INSERT INTO refresh_tokens \ + (token_hash, user_id, client_id, session_hash, expires_at) \ + VALUES (?1, ?2, ?3, ?4, ?5)", + turso::params![ + token.hash(), + user.to_string(), + client_id.to_string(), + session_hash, + store::stamp(store::now() + time::Duration::days(REFRESH_DAYS))?, + ], + ) + .await + .map_err(backend)?; + Ok(token) +} + +/// Rotates a refresh token: the presented one is revoked, a fresh one is +/// minted against the same session, and the new raw token plus the old row +/// come back. `None` for unknown, expired, or revoked tokens — and for tokens +/// whose central session is gone, which is what makes SSO logout global. +pub async fn rotate_refresh(store: &Store, token: &str) -> Result> { + let hash = hash_token(token); + store + .conn + .execute("BEGIN IMMEDIATE", ()) + .await + .map_err(backend)?; + let outcome = async { + let mut rows = store + .conn + .query( + "SELECT user_id, client_id, session_hash, expires_at, revoked_at \ + FROM refresh_tokens WHERE token_hash = ?1", + turso::params![hash.clone()], + ) + .await + .map_err(backend)?; + let Some(row) = rows.next().await.map_err(backend)? else { + return Ok(None); + }; + if store::opt_text(&row, 4)?.is_some() { + return Ok(None); + } + if store::parse_stamp(&store::text(&row, 3)?)? < store::now() { + return Ok(None); + } + let record = RefreshToken { + user_id: UserId::from(store::text(&row, 0)?), + client_id: ClientId::from(store::text(&row, 1)?), + session_hash: store::text(&row, 2)?, + expires_at: store::parse_stamp(&store::text(&row, 3)?)?, + }; + // The session that minted this token must still be alive. + let mut sessions = store + .conn + .query( + "SELECT expires_at, revoked_at FROM sessions WHERE token_hash = ?1", + turso::params![record.session_hash.clone()], + ) + .await + .map_err(backend)?; + let Some(session) = sessions.next().await.map_err(backend)? else { + return Ok(None); + }; + if store::opt_text(&session, 1)?.is_some() { + return Ok(None); + } + if store::parse_stamp(&store::text(&session, 0)?)? < store::now() { + return Ok(None); + } + + let now = store::stamp(store::now())?; + store + .conn + .execute( + "UPDATE refresh_tokens SET revoked_at = ?1 WHERE token_hash = ?2", + turso::params![now.clone(), hash.clone()], + ) + .await + .map_err(backend)?; + let fresh = issue_refresh( + store, + &record.user_id, + &record.client_id, + &record.session_hash, + ) + .await?; + Ok(Some((fresh, record))) + } + .await; + match outcome { + Ok(found) => { + store.conn.execute("COMMIT", ()).await.map_err(backend)?; + Ok(found) + } + Err(e) => { + let _ = store.conn.execute("ROLLBACK", ()).await; + Err(e) + } + } +} + +// --------------------------------------------------------------------------- +// Verification (the provider half: /userinfo and future introspection) +// --------------------------------------------------------------------------- + +/// RFC 7636 S256: `base64url(sha256(verifier))` must equal the challenge the +/// `/authorize` call stored. +pub fn pkce_matches(challenge: &str, verifier: &str) -> bool { + use sha2::Digest; + let computed = b64url.encode(sha2::Sha256::digest(verifier.as_bytes())); + crate::accounts::digests_match(challenge, &computed) +} + +/// Verifies a compact JWT im minted: RS256 signature against the active key +/// named by `kid`, `aud` equal to `audience`, `exp` in the future. Returns +/// the claims on success, `None` for every way a token can fail — unknown +/// key, bad signature, wrong audience, expired — which all read the same to +/// the caller: this token does not authenticate anyone. +/// +/// `iss` is the caller's to check: the issuer string is configuration the +/// core crate does not hold. +pub async fn verify_jwt( + store: &Store, + token: &str, + audience: Option<&str>, +) -> Result> { + use rsa::signature::Verifier; + + let parts: Vec<&str> = token.split('.').collect(); + if parts.len() != 3 { + return Ok(None); + } + let Ok(header_bytes) = b64url.decode(parts[0]) else { + return Ok(None); + }; + let Ok(header) = serde_json::from_slice::(&header_bytes) else { + return Ok(None); + }; + if header["alg"] != "RS256" { + return Ok(None); + } + let Some(kid) = header["kid"].as_str() else { + return Ok(None); + }; + let Some(public) = crate::keys::public_key_by_kid(store, kid).await? else { + return Ok(None); + }; + let Ok(signature_bytes) = b64url.decode(parts[2]) else { + return Ok(None); + }; + let Ok(signature) = rsa::pkcs1v15::Signature::try_from(signature_bytes.as_slice()) else { + return Ok(None); + }; + let verifying = rsa::pkcs1v15::VerifyingKey::::new(public); + if verifying + .verify(format!("{}.{}", parts[0], parts[1]).as_bytes(), &signature) + .is_err() + { + return Ok(None); + } + let Ok(claims_bytes) = b64url.decode(parts[1]) else { + return Ok(None); + }; + let Ok(claims) = serde_json::from_slice::(&claims_bytes) else { + return Ok(None); + }; + if let Some(audience) = audience { + if claims["aud"].as_str() != Some(audience) { + return Ok(None); + } + } + let Some(exp) = claims["exp"].as_i64() else { + return Ok(None); + }; + if exp <= store::now().unix_timestamp() { + return Ok(None); + } + Ok(Some(claims)) +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::accounts::{create_invite, create_user_from_invite}; + use crate::sessions::create_session; + use rsa::signature::Verifier; + use std::path::Path; + + async fn fixture() -> (Store, ClientId, UserId) { + let store = Store::open(Path::new(":memory:")).await.unwrap(); + let (client_id, _secret) = + create_client(&store, "demo", vec!["http://app/callback".into()]) + .await + .unwrap(); + let invite = create_invite(&store, "ann@example.com", None) + .await + .unwrap(); + let user = create_user_from_invite(&store, invite.expose(), "Ann", "tDLr9!mZQ2xv") + .await + .unwrap(); + (store, client_id, user.id) + } + + #[tokio::test] + async fn jwt_structure_and_signature() { + let store = Store::open(Path::new(":memory:")).await.unwrap(); + let (kid, key) = crate::keys::active_signing_key(&store).await.unwrap(); + let token = sign_jwt( + &serde_json::json!({ "iss": "im", "sub": "u1", "exp": 1i64 }), + &kid, + &key, + ); + let parts: Vec<&str> = token.split('.').collect(); + assert_eq!(parts.len(), 3); + let header: serde_json::Value = + serde_json::from_slice(&b64url.decode(parts[0]).unwrap()).unwrap(); + assert_eq!(header["alg"], "RS256"); + assert_eq!(header["kid"].as_str().unwrap(), kid); + let claims: serde_json::Value = + serde_json::from_slice(&b64url.decode(parts[1]).unwrap()).unwrap(); + assert_eq!(claims["sub"], "u1"); + + let verifying = + rsa::pkcs1v15::VerifyingKey::::new(key.to_public_key()); + let signature = + rsa::pkcs1v15::Signature::try_from(b64url.decode(parts[2]).unwrap().as_slice()) + .unwrap(); + verifying + .verify(format!("{}.{}", parts[0], parts[1]).as_bytes(), &signature) + .unwrap(); + // A tampered payload must not verify. + let forged = format!("{}.{}", parts[0], b64url.encode(r#"{"sub":"mallory"}"#)); + assert!(verifying.verify(forged.as_bytes(), &signature).is_err()); + } + + #[tokio::test] + async fn auth_code_is_single_use() { + let (store, client_id, user_id) = fixture().await; + let code = create_auth_code( + &store, + &client_id, + &user_id, + "http://app/callback", + None, + "challenge", + "session-hash", + ) + .await + .unwrap(); + let first = consume_auth_code(&store, code.expose()).await.unwrap(); + assert!(first.is_some()); + assert_eq!(first.unwrap().code_challenge, "challenge"); + assert!( + consume_auth_code(&store, code.expose()) + .await + .unwrap() + .is_none() + ); + } + + #[tokio::test] + async fn refresh_rotates_and_dies_with_session() { + let (store, client_id, user_id) = fixture().await; + let session = create_session(&store, &user_id).await.unwrap(); + let token = issue_refresh(&store, &user_id, &client_id, &session.hash()) + .await + .unwrap(); + + let (fresh, old) = rotate_refresh(&store, token.expose()) + .await + .unwrap() + .unwrap(); + assert_eq!(old.user_id, user_id); + // The old token is spent. + assert!( + rotate_refresh(&store, token.expose()) + .await + .unwrap() + .is_none() + ); + // The fresh one works. + assert!( + rotate_refresh(&store, fresh.expose()) + .await + .unwrap() + .is_some() + ); + + // Revoking the central session retires the refresh chain. + let session2 = create_session(&store, &user_id).await.unwrap(); + let token2 = issue_refresh(&store, &user_id, &client_id, &session2.hash()) + .await + .unwrap(); + crate::sessions::revoke_session(&store, session2.expose()) + .await + .unwrap(); + assert!( + rotate_refresh(&store, token2.expose()) + .await + .unwrap() + .is_none() + ); + } + + #[tokio::test] + async fn client_secret_verifies_constant_time() { + let (store, client_id, _) = fixture().await; + let client = client_by_id(&store, &client_id.to_string()) + .await + .unwrap() + .unwrap(); + assert!(!verify_client_secret(&client, "wrong")); + assert!( + client + .redirect_uris + .contains(&"http://app/callback".to_string()) + ); + } +} diff --git a/crates/im-core/src/secret.rs b/crates/im-core/src/secret.rs new file mode 100644 index 0000000..a858672 --- /dev/null +++ b/crates/im-core/src/secret.rs @@ -0,0 +1,153 @@ +//! At-rest encryption for secrets, ported from izlek-core's `store/secret.rs` +//! (same product family, same author). +//! +//! The column holds ciphertext, and the key that opens it lives in a second +//! file (`im.key`, beside the database) that a database backup does not +//! automatically include. +//! +//! The envelope is `v1:` followed by base64 of a 24-byte XChaCha20-Poly1305 +//! nonce and the sealed bytes it protects. + +use std::io; +use std::path::Path; + +use base64::Engine; +use base64::engine::general_purpose::STANDARD as base64; +use chacha20poly1305::aead::Aead; +use chacha20poly1305::{KeyInit, XChaCha20Poly1305, XNonce}; +use rand::Rng; + +/// A key is 32 raw bytes; nothing here derives it from a password, because +/// there is no password to derive it from — it is the thing that protects +/// one. +pub const KEY_BYTES: usize = 32; +pub type Key = [u8; KEY_BYTES]; + +const PREFIX: &str = "v1:"; +const NONCE_BYTES: usize = 24; + +/// True for a value already in our envelope. +#[cfg(test)] +pub fn is_sealed(value: &str) -> bool { + value.starts_with(PREFIX) +} + +/// Encrypts `plaintext` under `key`, returning the envelope ready to store. +/// +/// A fresh random nonce is drawn every call, so sealing the same secret twice +/// gives two different strings. XChaCha20-Poly1305's 24-byte nonce is wide +/// enough that "draw at random and never track reuse" is safe for the volume +/// of writes an SSO produces. +pub fn seal(key: &Key, plaintext: &[u8]) -> String { + let cipher = XChaCha20Poly1305::new(key.into()); + let mut nonce_bytes = [0u8; NONCE_BYTES]; + rand::rng().fill_bytes(&mut nonce_bytes); + let nonce = XNonce::from_slice(&nonce_bytes); + let ciphertext = cipher + .encrypt(nonce, plaintext) + .expect("XChaCha20-Poly1305 cannot fail to encrypt a plaintext this small"); + let mut payload = Vec::with_capacity(NONCE_BYTES + ciphertext.len()); + payload.extend_from_slice(&nonce_bytes); + payload.extend_from_slice(&ciphertext); + format!("{PREFIX}{}", base64.encode(payload)) +} + +/// Reverses [`seal`]. `None` covers every way this can fail to come back — +/// not our prefix, not valid base64, too short to hold a nonce, wrong key, +/// or a tampered/truncated ciphertext that fails the Poly1305 tag check. +pub fn open(key: &Key, sealed: &str) -> Option> { + let body = sealed.strip_prefix(PREFIX)?; + let payload = base64.decode(body).ok()?; + if payload.len() < NONCE_BYTES { + return None; + } + let (nonce_bytes, ciphertext) = payload.split_at(NONCE_BYTES); + let cipher = XChaCha20Poly1305::new(key.into()); + let nonce = XNonce::from_slice(nonce_bytes); + cipher.decrypt(nonce, ciphertext).ok() +} + +/// Reads the key at `path`, generating and writing a fresh one (mode 0600, +/// where the platform has modes) if the file is not there yet. +/// +/// Called once, at [`crate::store::Store::open`] — the key is loaded, not +/// re-read per query, so a corrupted key file is a boot-time failure, not a +/// per-request one. +pub fn load_or_create_key(path: &Path) -> io::Result { + match std::fs::read(path) { + Ok(bytes) => { + let key: Key = bytes.try_into().map_err(|bytes: Vec| { + io::Error::new( + io::ErrorKind::InvalidData, + format!( + "{} holds {} bytes, not the {KEY_BYTES} of a key", + path.display(), + bytes.len() + ), + ) + })?; + Ok(key) + } + Err(e) if e.kind() == io::ErrorKind::NotFound => { + let mut key = [0u8; KEY_BYTES]; + rand::rng().fill_bytes(&mut key); + std::fs::write(path, key)?; + restrict(path)?; + Ok(key) + } + Err(e) => Err(e), + } +} + +/// Best-effort 0600; platforms without modes simply skip the call. +#[cfg(unix)] +fn restrict(path: &Path) -> io::Result<()> { + use std::os::unix::fs::PermissionsExt; + std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o600)) +} + +#[cfg(not(unix))] +fn restrict(_path: &Path) -> io::Result<()> { + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn seal_roundtrip() { + let key = [7u8; KEY_BYTES]; + let sealed = seal(&key, b"a totp secret"); + assert!(is_sealed(&sealed)); + assert_eq!( + open(&key, &sealed).as_deref(), + Some(b"a totp secret".as_slice()) + ); + } + + #[test] + fn seal_is_randomized() { + let key = [7u8; KEY_BYTES]; + assert_ne!(seal(&key, b"same"), seal(&key, b"same")); + } + + #[test] + fn open_rejects_garbage() { + let key = [7u8; KEY_BYTES]; + assert_eq!(open(&key, "plaintext"), None); + assert_eq!(open(&key, "v1:not-base64!!!"), None); + assert_eq!(open(&key, "v1:c2hvcnQ"), None); + let wrong = [8u8; KEY_BYTES]; + assert_eq!(open(&wrong, &seal(&key, b"x")), None); + } + + #[test] + fn key_file_is_stable_across_opens() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("im.key"); + let first = load_or_create_key(&path).unwrap(); + let second = load_or_create_key(&path).unwrap(); + assert_eq!(first, second, "a second open reuses the same key"); + } +} diff --git a/crates/im-core/src/sessions.rs b/crates/im-core/src/sessions.rs new file mode 100644 index 0000000..895d39a --- /dev/null +++ b/crates/im-core/src/sessions.rs @@ -0,0 +1,128 @@ +//! Central sessions: the `im_session` cookie's server half. +//! +//! A session is what makes SSO single: once a browser holds one, every app's +//! `/authorize` round-trip is a silent redirect. Revoking a session also +//! revokes every refresh token bound to it — that is what "log me out +//! everywhere" means here. + +use crate::accounts::{Token, hash_token}; +use crate::model::{User, UserId}; +use crate::store::{self, Result, Store, backend}; + +/// How long a central session lives. +pub const SESSION_DAYS: i64 = 30; + +/// Creates a session for `user`, returning the raw cookie token. The row +/// holds only its digest. +pub async fn create_session(store: &Store, user: &UserId) -> Result { + let token = Token::mint(); + let now = store::now(); + store + .conn + .execute( + "INSERT INTO sessions (token_hash, user_id, created_at, expires_at) \ + VALUES (?1, ?2, ?3, ?4)", + turso::params![ + token.hash(), + user.to_string(), + store::stamp(now)?, + store::stamp(now + time::Duration::days(SESSION_DAYS))?, + ], + ) + .await + .map_err(backend)?; + Ok(token) +} + +/// Resolves a raw cookie token to its user. `None` for unknown, expired, +/// revoked, or disabled — every one of them is "please log in again". +pub async fn resolve_session(store: &Store, token: &str) -> Result> { + let mut rows = store + .conn + .query( + "SELECT user_id, expires_at, revoked_at FROM sessions WHERE token_hash = ?1", + turso::params![hash_token(token)], + ) + .await + .map_err(backend)?; + let Some(row) = rows.next().await.map_err(backend)? else { + return Ok(None); + }; + if store::opt_text(&row, 2)?.is_some() { + return Ok(None); + } + if store::parse_stamp(&store::text(&row, 1)?)? < store::now() { + return Ok(None); + } + let user_id = UserId::from(store::text(&row, 0)?); + match crate::accounts::user_by_id(store, &user_id).await? { + Some(user) if !user.disabled => Ok(Some(user)), + _ => Ok(None), + } +} + +/// Revokes a session and every refresh token bound to it. +pub async fn revoke_session(store: &Store, token: &str) -> Result<()> { + let now = store::stamp(store::now())?; + let hash = hash_token(token); + store + .conn + .execute( + "UPDATE sessions SET revoked_at = ?1 WHERE token_hash = ?2 AND revoked_at IS NULL", + turso::params![now.clone(), hash.clone()], + ) + .await + .map_err(backend)?; + store + .conn + .execute( + "UPDATE refresh_tokens SET revoked_at = ?1 WHERE session_hash = ?2 AND revoked_at IS NULL", + turso::params![now, hash], + ) + .await + .map_err(backend)?; + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::accounts::{create_invite, create_user_from_invite}; + use std::path::Path; + + async fn fixture() -> (Store, UserId) { + let store = Store::open(Path::new(":memory:")).await.unwrap(); + let invite = create_invite(&store, "ann@example.com", None) + .await + .unwrap(); + let user = create_user_from_invite(&store, invite.expose(), "Ann", "tDLr9!mZQ2xv") + .await + .unwrap(); + (store, user.id) + } + + #[tokio::test] + async fn session_roundtrip_and_revoke() { + let (store, user_id) = fixture().await; + let token = create_session(&store, &user_id).await.unwrap(); + let user = resolve_session(&store, token.expose()) + .await + .unwrap() + .unwrap(); + assert_eq!(user.id, user_id); + + revoke_session(&store, token.expose()).await.unwrap(); + assert!( + resolve_session(&store, token.expose()) + .await + .unwrap() + .is_none() + ); + assert!( + resolve_session(&store, "not-a-token") + .await + .unwrap() + .is_none() + ); + } +} diff --git a/crates/im-core/src/store.rs b/crates/im-core/src/store.rs new file mode 100644 index 0000000..58bc415 --- /dev/null +++ b/crates/im-core/src/store.rs @@ -0,0 +1,227 @@ +//! The turso store: connection, schema, and the conventions every module +//! queries through. + +use std::path::Path; + +use time::OffsetDateTime; +use time::format_description::well_known::Rfc3339; +use turso::{Builder, Connection, Row}; + +use crate::secret::{self, Key}; + +#[derive(Debug, thiserror::Error)] +pub enum StoreError { + #[error("database: {0}")] + Backend(String), + #[error("corrupt row: {0}")] + Corrupt(String), + #[error("io: {0}")] + Io(#[from] std::io::Error), +} + +pub type Result = std::result::Result; + +pub(crate) fn backend(e: E) -> StoreError { + StoreError::Backend(e.to_string()) +} + +/// The schema, authoritative. Every table is `IF NOT EXISTS` so `migrate()` +/// is idempotent and safe to run on every boot. +pub const SCHEMA: &str = " +CREATE TABLE IF NOT EXISTS users ( + id TEXT PRIMARY KEY, + email TEXT NOT NULL UNIQUE COLLATE NOCASE, + name TEXT NOT NULL, + password_hash TEXT NOT NULL, + totp_secret BLOB, + totp_confirmed INTEGER NOT NULL DEFAULT 0, + disabled INTEGER NOT NULL DEFAULT 0, + created_at TEXT NOT NULL +); +CREATE TABLE IF NOT EXISTS invites ( + token TEXT PRIMARY KEY, + email TEXT NOT NULL, + invited_by TEXT, + created_at TEXT NOT NULL, + expires_at TEXT NOT NULL, + accepted_at TEXT +); +CREATE TABLE IF NOT EXISTS sessions ( + token_hash TEXT PRIMARY KEY, + user_id TEXT NOT NULL REFERENCES users(id), + created_at TEXT NOT NULL, + expires_at TEXT NOT NULL, + revoked_at TEXT +); +CREATE TABLE IF NOT EXISTS oidc_clients ( + client_id TEXT PRIMARY KEY, + name TEXT NOT NULL, + secret_hash TEXT NOT NULL, + redirect_uris TEXT NOT NULL, + created_at TEXT NOT NULL +); +CREATE TABLE IF NOT EXISTS auth_codes ( + code_hash TEXT PRIMARY KEY, + client_id TEXT NOT NULL REFERENCES oidc_clients(client_id), + user_id TEXT NOT NULL REFERENCES users(id), + redirect_uri TEXT NOT NULL, + nonce TEXT, + code_challenge TEXT NOT NULL, + session_hash TEXT NOT NULL, + expires_at TEXT NOT NULL, + consumed_at TEXT +); +CREATE TABLE IF NOT EXISTS refresh_tokens ( + token_hash TEXT PRIMARY KEY, + user_id TEXT NOT NULL REFERENCES users(id), + client_id TEXT NOT NULL REFERENCES oidc_clients(client_id), + session_hash TEXT NOT NULL REFERENCES sessions(token_hash), + expires_at TEXT NOT NULL, + revoked_at TEXT +); +CREATE TABLE IF NOT EXISTS signing_keys ( + kid TEXT PRIMARY KEY, + private_der_enc BLOB NOT NULL, + public_der BLOB NOT NULL, + created_at TEXT NOT NULL, + active INTEGER NOT NULL DEFAULT 1 +); +"; + +/// One database handle with the at-rest key beside it. Turso is a +/// single-writer engine; one connection per store, like izlek-core. +pub struct Store { + pub(crate) conn: Connection, + pub(crate) key: Key, +} + +impl Store { + /// Opens (creating if needed) the database at `path` and runs the schema + /// migration. `:memory:` gives a test store with a fresh throwaway key. + pub async fn open(path: &Path) -> Result { + let raw = path + .to_str() + .ok_or_else(|| StoreError::Corrupt("path is not utf-8".into()))?; + let db = Builder::new_local(raw).build().await.map_err(backend)?; + let conn = db.connect().map_err(backend)?; + let store = Store { + conn, + key: load_key(path)?, + }; + store.migrate().await?; + Ok(store) + } + + /// Applies the schema inside one immediate transaction; safe to re-run. + pub async fn migrate(&self) -> Result<()> { + self.conn + .execute("BEGIN IMMEDIATE", ()) + .await + .map_err(backend)?; + if let Err(e) = self.conn.execute_batch(SCHEMA).await { + let _ = self.conn.execute("ROLLBACK", ()).await; + return Err(backend(e)); + } + self.conn.execute("COMMIT", ()).await.map_err(backend)?; + Ok(()) + } + + /// The at-rest encryption key for this database. + pub(crate) fn key(&self) -> &Key { + &self.key + } + + /// Seals a small value for a cookie (the pending-login marker), so its + /// contents are neither readable nor forgeable client-side. + pub fn seal_value(&self, plaintext: &[u8]) -> String { + secret::seal(&self.key, plaintext) + } + + /// Reverses [`Store::seal_value`]; `None` for anything we did not seal. + pub fn open_value(&self, sealed: &str) -> Option> { + secret::open(&self.key, sealed) + } +} + +/// The key for `path`'s database. `:memory:` has no directory to anchor a +/// sibling file to, so it gets a key generated fresh in memory — every +/// in-memory store is its own, unrelated encryption domain. +fn load_key(path: &Path) -> Result { + if path.as_os_str() == ":memory:" { + let mut key = [0u8; secret::KEY_BYTES]; + rand::Rng::fill_bytes(&mut rand::rng(), &mut key); + return Ok(key); + } + let dir = path + .parent() + .filter(|d| !d.as_os_str().is_empty()) + .unwrap_or_else(|| Path::new(".")); + secret::load_or_create_key(&dir.join("im.key")).map_err(StoreError::Io) +} + +pub(crate) fn now() -> OffsetDateTime { + OffsetDateTime::now_utc() +} + +pub(crate) fn stamp(at: OffsetDateTime) -> Result { + at.format(&Rfc3339) + .map_err(|e| StoreError::Corrupt(format!("timestamp: {e}"))) +} + +pub(crate) fn parse_stamp(raw: &str) -> Result { + OffsetDateTime::parse(raw, &Rfc3339) + .map_err(|e| StoreError::Corrupt(format!("timestamp {raw:?}: {e}"))) +} + +pub(crate) fn text(row: &Row, idx: usize) -> Result { + row.get::(idx).map_err(backend) +} + +pub(crate) fn opt_text(row: &Row, idx: usize) -> Result> { + row.get::>(idx).map_err(backend) +} +pub(crate) fn int(row: &Row, idx: usize) -> Result { + row.get::(idx).map_err(backend) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[tokio::test] + async fn migrate_is_idempotent() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("im.db"); + let store = Store::open(&path).await.unwrap(); + store.migrate().await.unwrap(); + store.migrate().await.unwrap(); + let mut rows = store + .conn + .query("SELECT name FROM sqlite_master WHERE type = 'table'", ()) + .await + .unwrap(); + let mut tables = Vec::new(); + while let Some(row) = rows.next().await.unwrap() { + tables.push(text(&row, 0).unwrap()); + } + for expected in [ + "users", + "invites", + "sessions", + "oidc_clients", + "auth_codes", + "refresh_tokens", + "signing_keys", + ] { + assert!(tables.contains(&expected.to_string()), "missing {expected}"); + } + } + + #[tokio::test] + async fn key_file_lives_beside_database() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("im.db"); + let _store = Store::open(&path).await.unwrap(); + assert!(dir.path().join("im.key").exists()); + } +} diff --git a/crates/im-core/src/totp.rs b/crates/im-core/src/totp.rs new file mode 100644 index 0000000..6f31d51 --- /dev/null +++ b/crates/im-core/src/totp.rs @@ -0,0 +1,199 @@ +//! TOTP (RFC 6238): the second factor. HMAC-SHA1, 30-second steps, 6 digits, +//! one step of clock drift accepted in either direction. +//! +//! The secret is 160 bits; the database holds it sealed (`secret.rs`), the +//! setup page shows it base32-encoded, and authenticator apps take the +//! `otpauth://` URI from [`totp_uri`]. + +use crate::model::UserId; +use crate::secret; +use crate::store::{self, Result, Store, backend}; +use data_encoding::BASE32_NOPAD; +use hmac::digest::KeyInit; +use hmac::{Hmac, Mac}; +use sha1::Sha1; +use time::OffsetDateTime; + +/// How long one step is, in seconds. +pub const STEP_SECONDS: u64 = 30; + +/// A fresh 160-bit secret. +pub fn generate_secret() -> [u8; 20] { + let mut secret = [0u8; 20]; + rand::Rng::fill_bytes(&mut rand::rng(), &mut secret); + secret +} + +/// The secret in the form authenticator apps and humans copy: base32, no +/// padding, grouped every four characters. +pub fn display_secret(secret: &[u8; 20]) -> String { + let raw = BASE32_NOPAD.encode(secret); + raw.as_bytes() + .chunks(4) + .map(|chunk| std::str::from_utf8(chunk).unwrap()) + .collect::>() + .join(" ") +} + +/// The `otpauth://` URI a QR code carries. +pub fn totp_uri(issuer: &str, email: &str, secret: &[u8; 20]) -> String { + let encoded = BASE32_NOPAD.encode(secret); + format!( + "otpauth://totp/{issuer}:{email}?secret={encoded}&issuer={issuer}&algorithm=SHA1&digits=6&period={STEP_SECONDS}" + ) +} + +/// The 6-digit code for `secret` at instant `at`. +pub fn totp_code(secret: &[u8; 20], at: OffsetDateTime) -> String { + code_at_step(secret, at.unix_timestamp() as u64 / STEP_SECONDS) +} + +fn code_at_step(secret: &[u8; 20], step: u64) -> String { + let mut mac = + as KeyInit>::new_from_slice(secret).expect("HMAC accepts keys of any length"); + mac.update(&step.to_be_bytes()); + let digest = mac.finalize().into_bytes(); + let offset = (digest[19] & 0x0f) as usize; + let binary = u32::from_be_bytes([ + digest[offset] & 0x7f, + digest[offset + 1], + digest[offset + 2], + digest[offset + 3], + ]); + format!("{:06}", binary % 1_000_000) +} + +/// Checks a user-typed code, accepting one step of drift either way. The +/// comparison runs over every candidate regardless of where the match is, so +/// the answer's timing does not narrow the search. +pub fn verify_totp(secret: &[u8; 20], code: &str, at: OffsetDateTime) -> bool { + let step = at.unix_timestamp() as u64 / STEP_SECONDS; + let mut found = false; + for candidate in [step.wrapping_sub(1), step, step.wrapping_add(1)] { + let expected = code_at_step(secret, candidate); + found |= + subtle::ConstantTimeEq::ct_eq(expected.as_bytes(), code.as_bytes()).unwrap_u8() == 1; + } + found +} + +// --------------------------------------------------------------------------- +// Storage +// --------------------------------------------------------------------------- + +/// Stores a freshly generated secret, sealed, unconfirmed until the user +/// proves their app agrees (`confirm_totp`). +pub async fn set_totp(store: &Store, user: &UserId, secret_bytes: &[u8; 20]) -> Result<()> { + let sealed = secret::seal(store.key(), secret_bytes); + store + .conn + .execute( + "UPDATE users SET totp_secret = ?1, totp_confirmed = 0 WHERE id = ?2", + turso::params![sealed, user.to_string()], + ) + .await + .map_err(backend)?; + Ok(()) +} + +/// Marks the stored secret confirmed — called after one successful code. +pub async fn confirm_totp(store: &Store, user: &UserId) -> Result<()> { + store + .conn + .execute( + "UPDATE users SET totp_confirmed = 1 WHERE id = ?1", + turso::params![user.to_string()], + ) + .await + .map_err(backend)?; + Ok(()) +} + +/// The user's sealed secret, opened: `(secret, confirmed)`, or `None` when +/// TOTP was never set up. A sealed value that no longer opens (wrong key, +/// damaged ciphertext) reads as `None` — the user re-enrolls. +pub async fn totp_secret(store: &Store, user: &UserId) -> Result> { + let mut rows = store + .conn + .query( + "SELECT totp_secret, totp_confirmed FROM users WHERE id = ?1", + turso::params![user.to_string()], + ) + .await + .map_err(backend)?; + let Some(row) = rows.next().await.map_err(backend)? else { + return Ok(None); + }; + let confirmed = store::int(&row, 1)? != 0; + let Some(sealed) = store::opt_text(&row, 0)? else { + return Ok(None); + }; + let Some(bytes) = secret::open(store.key(), &sealed) else { + return Ok(None); + }; + let Ok(secret_bytes) = <[u8; 20]>::try_from(bytes.as_slice()) else { + return Ok(None); + }; + Ok(Some((secret_bytes, confirmed))) +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::accounts::{create_invite, create_user_from_invite}; + use std::path::Path; + use time::macros::datetime; + + /// RFC 6238 Appendix B, SHA-1 test key "12345678901234567890". + const RFC_KEY: &[u8; 20] = b"12345678901234567890"; + + #[test] + fn rfc6238_sha1_vectors() { + // (unix time, expected 6-digit truncation of the 8-digit vector) + let cases = [ + (59i64, "94287082"), + (1111111109, "07081804"), + (1111111111, "14050471"), + (1234567890, "89005924"), + (2000000000, "69279037"), + (20000000000, "65353130"), + ]; + for (at, expected8) in cases { + let step = at as u64 / STEP_SECONDS; + let got = code_at_step(RFC_KEY, step); + let expected = &expected8[2..]; + assert_eq!(got, expected, "at {at}"); + } + } + + #[test] + fn verify_accepts_one_step_of_drift() { + let at = datetime!(2026-09-03 12:00:00 UTC); + let step = at.unix_timestamp() as u64 / STEP_SECONDS; + for (delta, ok) in [(-1i64, true), (0, true), (1, true), (2, false), (-2, false)] { + let code = code_at_step(RFC_KEY, (step as i64 + delta) as u64); + assert_eq!(verify_totp(RFC_KEY, &code, at), ok, "delta {delta}"); + } + } + + #[tokio::test] + async fn store_roundtrip_and_confirm() { + let store = Store::open(Path::new(":memory:")).await.unwrap(); + let invite = create_invite(&store, "ann@example.com", None) + .await + .unwrap(); + let user = create_user_from_invite(&store, invite.expose(), "Ann", "tDLr9!mZQ2xv") + .await + .unwrap(); + + assert!(totp_secret(&store, &user.id).await.unwrap().is_none()); + let secret = generate_secret(); + set_totp(&store, &user.id, &secret).await.unwrap(); + let (stored, confirmed) = totp_secret(&store, &user.id).await.unwrap().unwrap(); + assert_eq!(stored, secret); + assert!(!confirmed); + confirm_totp(&store, &user.id).await.unwrap(); + let (_, confirmed) = totp_secret(&store, &user.id).await.unwrap().unwrap(); + assert!(confirmed); + } +} diff --git a/crates/im-migrate/Cargo.toml b/crates/im-migrate/Cargo.toml new file mode 100644 index 0000000..9143f05 --- /dev/null +++ b/crates/im-migrate/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "im-migrate" +version.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +description = "One-time import of izlek.db accounts into an im database" + +[dependencies] +turso.workspace = true +tokio.workspace = true +thiserror.workspace = true +time.workspace = true +ulid.workspace = true + +[dev-dependencies] +tempfile = "3" diff --git a/crates/im-migrate/src/main.rs b/crates/im-migrate/src/main.rs new file mode 100644 index 0000000..5f8481f --- /dev/null +++ b/crates/im-migrate/src/main.rs @@ -0,0 +1,373 @@ +//! im-migrate: one-time import of İzlek accounts into an im database. +//! +//! ```sh +//! im-migrate --izlek /path/izlek.db --im /path/im.db [--mapping /path/out.csv] +//! ``` +//! +//! İzlek's `user` table keeps `password_hash` NULL for a member who never +//! signed in; those rows are skipped and reported, because there is no +//! password to migrate and the SSO's invite flow is their way in. Everyone +//! else crosses with the argon2 PHC string verbatim — it verifies unchanged. +//! +//! The mapping CSV (`izlek_user_id,im_sub`) is what İzlek's follow-up batch +//! uses to link its local rows to SSO subject ids. It covers every user that +//! exists in im afterwards, imported this run or already present. + +use std::path::{Path, PathBuf}; + +use time::OffsetDateTime; +use time::format_description::well_known::Rfc3339; +use turso::Builder; + +/// im's schema, duplicated literally from im-core's `store::SCHEMA` — the +/// tool stays dependency-free of im-core so a build of this binary never +/// drags the argon2/rsa tree along. +const IM_SCHEMA: &str = " +CREATE TABLE IF NOT EXISTS users ( + id TEXT PRIMARY KEY, + email TEXT NOT NULL UNIQUE COLLATE NOCASE, + name TEXT NOT NULL, + password_hash TEXT NOT NULL, + totp_secret BLOB, + totp_confirmed INTEGER NOT NULL DEFAULT 0, + disabled INTEGER NOT NULL DEFAULT 0, + created_at TEXT NOT NULL +); +CREATE TABLE IF NOT EXISTS invites ( + token TEXT PRIMARY KEY, + email TEXT NOT NULL, + invited_by TEXT, + created_at TEXT NOT NULL, + expires_at TEXT NOT NULL, + accepted_at TEXT +); +CREATE TABLE IF NOT EXISTS sessions ( + token_hash TEXT PRIMARY KEY, + user_id TEXT NOT NULL REFERENCES users(id), + created_at TEXT NOT NULL, + expires_at TEXT NOT NULL, + revoked_at TEXT +); +CREATE TABLE IF NOT EXISTS oidc_clients ( + client_id TEXT PRIMARY KEY, + name TEXT NOT NULL, + secret_hash TEXT NOT NULL, + redirect_uris TEXT NOT NULL, + created_at TEXT NOT NULL +); +CREATE TABLE IF NOT EXISTS auth_codes ( + code_hash TEXT PRIMARY KEY, + client_id TEXT NOT NULL REFERENCES oidc_clients(client_id), + user_id TEXT NOT NULL REFERENCES users(id), + redirect_uri TEXT NOT NULL, + nonce TEXT, + code_challenge TEXT NOT NULL, + session_hash TEXT NOT NULL, + expires_at TEXT NOT NULL, + consumed_at TEXT +); +CREATE TABLE IF NOT EXISTS refresh_tokens ( + token_hash TEXT PRIMARY KEY, + user_id TEXT NOT NULL REFERENCES users(id), + client_id TEXT NOT NULL REFERENCES oidc_clients(client_id), + session_hash TEXT NOT NULL REFERENCES sessions(token_hash), + expires_at TEXT NOT NULL, + revoked_at TEXT +); +CREATE TABLE IF NOT EXISTS signing_keys ( + kid TEXT PRIMARY KEY, + private_der_enc BLOB NOT NULL, + public_der BLOB NOT NULL, + created_at TEXT NOT NULL, + active INTEGER NOT NULL DEFAULT 1 +); +"; + +#[derive(Debug)] +struct Args { + izlek: PathBuf, + im: PathBuf, + mapping: PathBuf, +} + +#[derive(Debug, thiserror::Error)] +enum MigrateError { + #[error("{0}")] + Usage(String), + #[error("database: {0}")] + Backend(String), + #[error("io: {0}")] + Io(#[from] std::io::Error), +} + +type Result = std::result::Result; + +fn backend(e: E) -> MigrateError { + MigrateError::Backend(e.to_string()) +} + +fn parse_args() -> Result { + let mut izlek = None; + let mut im = None; + let mut mapping = None; + let mut args = std::env::args().skip(1); + while let Some(arg) = args.next() { + match arg.as_str() { + "--izlek" => izlek = args.next().map(PathBuf::from), + "--im" => im = args.next().map(PathBuf::from), + "--mapping" => mapping = args.next().map(PathBuf::from), + other => { + return Err(MigrateError::Usage(format!( + "unknown option {other}\nusage: im-migrate --izlek --im [--mapping out.csv]" + ))); + } + } + } + match (izlek, im) { + (Some(izlek), Some(im)) => Ok(Args { + izlek, + im, + mapping: mapping.unwrap_or_else(|| PathBuf::from("im-migrate-mapping.csv")), + }), + _ => Err(MigrateError::Usage( + "usage: im-migrate --izlek --im [--mapping out.csv]".into(), + )), + } +} + +/// One İzlek user row worth migrating. +struct IzlekUser { + id: String, + email: String, + name: String, + password_hash: String, +} + +async fn read_izlek_users(path: &Path) -> Result<(Vec, usize)> { + let db = Builder::new_local(path.to_str().unwrap()) + .build() + .await + .map_err(backend)?; + let conn = db.connect().map_err(backend)?; + let mut rows = conn + .query( + "SELECT id, email, display_name, password_hash FROM user ORDER BY created_at", + (), + ) + .await + .map_err(backend)?; + let mut users = Vec::new(); + let mut skipped_no_password = 0; + while let Some(row) = rows.next().await.map_err(backend)? { + let hash: Option = row.get(3).map_err(backend)?; + let Some(hash) = hash else { + skipped_no_password += 1; + continue; + }; + users.push(IzlekUser { + id: row.get(0).map_err(backend)?, + email: row.get(1).map_err(backend)?, + name: row.get(2).map_err(backend)?, + password_hash: hash, + }); + } + Ok((users, skipped_no_password)) +} + +struct Report { + imported: usize, + already_present: usize, + skipped_no_password: usize, +} + +async fn run(args: &Args) -> Result { + let (users, skipped_no_password) = read_izlek_users(&args.izlek).await?; + + let db = Builder::new_local(args.im.to_str().unwrap()) + .build() + .await + .map_err(backend)?; + let conn = db.connect().map_err(backend)?; + conn.execute_batch(IM_SCHEMA).await.map_err(backend)?; + + let mut report = Report { + imported: 0, + already_present: 0, + skipped_no_password, + }; + let mut mapping = String::from("izlek_user_id,im_sub\n"); + + conn.execute("BEGIN IMMEDIATE", ()).await.map_err(backend)?; + let outcome = async { + for user in &users { + let mut existing = conn + .query( + "SELECT id FROM users WHERE email = ?1 COLLATE NOCASE", + turso::params![user.email.clone()], + ) + .await + .map_err(backend)?; + if let Some(row) = existing.next().await.map_err(backend)? { + let sub: String = row.get(0).map_err(backend)?; + report.already_present += 1; + mapping.push_str(&format!("{},{sub}\n", user.id)); + continue; + } + let sub = ulid::Ulid::new().to_string(); + conn.execute( + "INSERT INTO users (id, email, name, password_hash, created_at) \ + VALUES (?1, ?2, ?3, ?4, ?5)", + turso::params![ + sub.clone(), + user.email.clone(), + user.name.clone(), + user.password_hash.clone(), + OffsetDateTime::now_utc() + .format(&Rfc3339) + .map_err(backend)?, + ], + ) + .await + .map_err(backend)?; + report.imported += 1; + mapping.push_str(&format!("{},{sub}\n", user.id)); + } + Ok::<_, MigrateError>(()) + } + .await; + match outcome { + Ok(()) => { + conn.execute("COMMIT", ()).await.map_err(backend)?; + } + Err(e) => { + let _ = conn.execute("ROLLBACK", ()).await; + return Err(e); + } + } + + std::fs::write(&args.mapping, mapping)?; + Ok(report) +} + +#[tokio::main] +async fn main() { + let args = match parse_args() { + Ok(args) => args, + Err(MigrateError::Usage(text)) => { + eprintln!("{text}"); + std::process::exit(2); + } + Err(e) => { + eprintln!("im-migrate: {e}"); + std::process::exit(1); + } + }; + match run(&args).await { + Ok(report) => { + println!( + "im-migrate {} -> {}", + args.izlek.display(), + args.im.display() + ); + println!( + " {} imported, {} already present, {} skipped (never set a password)", + report.imported, report.already_present, report.skipped_no_password + ); + println!(" mapping {}", args.mapping.display()); + } + Err(e) => { + eprintln!("im-migrate: {e}"); + std::process::exit(1); + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + async fn seed_izlek(path: &Path) { + let db = Builder::new_local(path.to_str().unwrap()) + .build() + .await + .unwrap(); + let conn = db.connect().unwrap(); + conn.execute_batch( + "CREATE TABLE user ( + id TEXT PRIMARY KEY, + workspace_id TEXT NOT NULL, + email TEXT NOT NULL, + display_name TEXT NOT NULL, + role TEXT NOT NULL, + password_hash TEXT, + created_at TEXT NOT NULL + );", + ) + .await + .unwrap(); + conn.execute( + "INSERT INTO user VALUES ('iz-1', 'w1', 'ann@example.com', 'Ann', 'admin', \ + '$argon2id$v=19$m=19456,t=2,p=1$0JjUMrLBpJG7lzg5bxZhMQ$iGpGXBNDAaHV9jqDxDcCyuIEIV33kJ1IAPt0XCh753Q', '2026-01-01T00:00:00Z')", + (), + ) + .await + .unwrap(); + conn.execute( + "INSERT INTO user VALUES ('iz-2', 'w1', 'bob@example.com', 'Bob', 'member', NULL, '2026-01-02T00:00:00Z')", + (), + ) + .await + .unwrap(); + } + + #[tokio::test] + async fn import_is_verbatim_and_idempotent() { + let dir = tempfile::tempdir().unwrap(); + let izlek = dir.path().join("izlek.db"); + let im = dir.path().join("im.db"); + let mapping = dir.path().join("mapping.csv"); + seed_izlek(&izlek).await; + + let args = Args { + izlek: izlek.clone(), + im: im.clone(), + mapping: mapping.clone(), + }; + let first = run(&args).await.unwrap(); + assert_eq!(first.imported, 1); + assert_eq!(first.skipped_no_password, 1); + + // Re-running imports nothing and still maps every user. + let second = run(&args).await.unwrap(); + assert_eq!(second.imported, 0); + assert_eq!(second.already_present, 1); + + let csv = std::fs::read_to_string(&mapping).unwrap(); + assert!(csv.contains("iz-1,"), "mapping covers the imported user"); + + let db = Builder::new_local(im.to_str().unwrap()) + .build() + .await + .unwrap(); + let conn = db.connect().unwrap(); + let mut rows = conn + .query( + "SELECT email, name, password_hash, totp_confirmed, disabled FROM users", + (), + ) + .await + .unwrap(); + let row = rows.next().await.unwrap().unwrap(); + let email: String = row.get(0).unwrap(); + let hash: String = row.get(2).unwrap(); + assert_eq!(email, "ann@example.com"); + assert_eq!( + hash, + "$argon2id$v=19$m=19456,t=2,p=1$0JjUMrLBpJG7lzg5bxZhMQ$iGpGXBNDAaHV9jqDxDcCyuIEIV33kJ1IAPt0XCh753Q", + "the PHC string crosses verbatim" + ); + assert_eq!(row.get::(3).unwrap(), 0); + assert_eq!(row.get::(4).unwrap(), 0); + assert!(rows.next().await.unwrap().is_none(), "exactly one row"); + } +} diff --git a/crates/im-web/Cargo.toml b/crates/im-web/Cargo.toml new file mode 100644 index 0000000..a018371 --- /dev/null +++ b/crates/im-web/Cargo.toml @@ -0,0 +1,47 @@ +[package] +name = "im-web" +version.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +description = "im web app: topcoat UI, OIDC endpoints and the server" +build = "build.rs" + +[dependencies] +topcoat = { version = "0.6.2", default-features = false, features = [ + "router", + "view", + "runtime", + "asset", + "cookie", + "discover", + "serve", + "compression", +] } +im-core = { workspace = true, features = ["server"] } +serde.workspace = true +serde_json.workspace = true +time.workspace = true +thiserror.workspace = true +tokio.workspace = true +ulid.workspace = true +base64.workspace = true +toml.workspace = true +data-encoding = "2.11.1" +qrcode = { version = "0.14.1", default-features = false, features = ["svg"] } +# TLS through rustls with the ring provider: no OpenSSL on the deployment box, +# and no system certificate store to be missing inside a container. +lettre = { version = "0.11.23", default-features = false, features = [ + "smtp-transport", + "builder", + "tokio1-rustls", + "ring", + "webpki-roots", + "pool", +] } + +[build-dependencies] +grass = "0.13" + +[dev-dependencies] +http = "1.5" diff --git a/crates/im-web/assets/main.css b/crates/im-web/assets/main.css new file mode 100644 index 0000000..fc217fa --- /dev/null +++ b/crates/im-web/assets/main.css @@ -0,0 +1,341 @@ +:root { + color-scheme: light; + --bg: #f2f2f0; + --surface: #fbfbfa; + --border: #dcdcd8; + --border-strong: #d0d0cb; + --border-soft: #d3d3ce; + --ink: #1a1b1d; + --muted: #6b7078; + --muted-soft: #6b7078; + --accent: #46557b; + --accent-tint: #eef0f5; + --accent-ink: #2f3c5c; + --accent-strong: #5a6a94; + --field-bg: #f5f5f3; + --panel-sunken: #eeeeec; + --danger: #a04a24; + --danger-tint-alt: #fbf1ec; + --danger-border-soft: #eddcd3; + --positive: #5c7b46; + --positive-tint: #eef3e9; + --positive-border: #d3e0c6; + --font-sans: system-ui, sans-serif; + --font-mono: "IBM Plex Mono", ui-monospace, monospace; + --control-h-lg: 40px; + --radius: 3px; + --radius-sm: var(--radius); + --radius-lg: 3px; + --shadow-2: none; + --dur-fast: 120ms; + --ease: ease-out; +} + +@media (prefers-color-scheme: dark) { + :root { + color-scheme: dark; + --bg: #0d0e10; + --surface: #14161a; + --border: #23262c; + --border-strong: #2e323a; + --border-soft: #1f2226; + --ink: #e6e4de; + --muted: #7d8590; + --muted-soft: #4a4f58; + --accent: #8ba1e8; + --accent-tint: rgba(139, 161, 232, 0.14); + --accent-ink: #b9c6ee; + --accent-strong: #7e93d9; + --field-bg: #101216; + --panel-sunken: #101216; + --danger: #e0906a; + --danger-tint-alt: rgba(224, 144, 106, 0.05); + --danger-border-soft: rgba(224, 144, 106, 0.3); + --positive: #9db98a; + --positive-tint: rgba(157, 185, 138, 0.13); + --positive-border: rgba(157, 185, 138, 0.4); + } +} +* { + box-sizing: border-box; +} + +body { + margin: 0; + background: var(--bg); + color: var(--ink); + font-family: var(--font-sans); + font-size: 14px; + line-height: 1.45; + -webkit-font-smoothing: antialiased; +} + +a { + color: var(--accent); + transition: color var(--dur-fast) var(--ease); +} +a:hover { + color: var(--accent-ink); +} + +body:has(.auth-stage) { + height: 100vh; + height: 100dvh; + overflow: hidden; + display: flex; + flex-direction: column; +} +body:has(.auth-stage) > * { + flex: none; +} +body:has(.auth-stage) > .auth-stage { + flex: 1; + min-height: 0; + overflow-y: auto; + scrollbar-width: none; +} +body:has(.auth-stage) > .auth-stage::-webkit-scrollbar { + display: none; +} + +.auth-stage { + min-height: 100vh; + min-height: 100dvh; + display: flex; + align-items: center; + justify-content: center; + padding: 0 40px 40px; +} + +.auth-column { + width: 520px; + max-width: 100%; + display: flex; + flex-direction: column; + gap: 10px; +} + +.wordmark { + display: flex; + align-items: center; + justify-content: center; + gap: 10px; + text-decoration: none; + color: inherit; + padding: 6px 0; +} +.wordmark:hover { + color: inherit; +} +.wordmark-mark { + flex: none; + display: block; + width: 24px; + height: 24px; +} +.wordmark-tittle { + fill: var(--accent); +} +.wordmark-text { + font-family: var(--font-mono); + font-size: 18px; + font-weight: 500; + letter-spacing: 0.02em; +} + +.auth-card { + background: var(--surface); + border: 1px solid var(--border); + border-radius: var(--radius-lg); + padding: 28px; + display: flex; + flex-direction: column; + gap: 18px; + box-shadow: var(--shadow-2); +} +.auth-card form { + display: flex; + flex-direction: column; + gap: 20px; +} + +.auth-head { + display: flex; + flex-direction: column; + gap: 6px; +} + +.auth-title { + font-size: 18px; + font-weight: 600; + letter-spacing: -0.01em; +} + +.auth-sub { + font-size: 13px; + color: var(--muted); + line-height: 1.5; +} + +.auth-field { + display: flex; + flex-direction: column; + gap: 6px; +} + +.auth-label { + font-family: var(--font-mono); + font-size: 10px; + letter-spacing: 0.08em; + color: var(--muted-soft); +} + +.auth-locked { + display: flex; + align-items: center; + gap: 8px; + height: 40px; + padding: 0 12px; + background: var(--panel-sunken); + border: 1px solid var(--border-strong); + border-radius: var(--radius); +} + +.auth-locked-value { + font-family: var(--font-mono); + font-size: 13px; + color: var(--muted); + flex-grow: 1; +} + +.auth-input { + height: 40px; + padding: 0 12px; + background: var(--field-bg); + border: 1px solid var(--border-strong); + border-radius: var(--radius); + color: var(--ink); + font-family: var(--font-sans); + font-size: 13px; + width: 100%; +} +.auth-input:focus { + outline: none; + border-color: var(--accent); + box-shadow: 0 0 0 2px var(--accent-tint); +} +.auth-input:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 1px; +} +.auth-input:user-invalid { + border-color: var(--danger); +} + +.auth-input-mono { + font-family: var(--font-mono); +} + +.auth-submit { + height: var(--control-h-lg); + display: flex; + align-items: center; + justify-content: center; + gap: 8px; + background: var(--accent); + color: var(--surface); + border: 0; + border-radius: var(--radius); + cursor: pointer; + font-family: var(--font-sans); +} +.auth-submit:disabled { + opacity: 0.45; + cursor: default; +} +.auth-submit:focus-visible { + outline: 2px solid var(--accent-ink); + outline-offset: 2px; +} + +.auth-submit-text { + font-size: 13px; + font-weight: 600; +} + +.auth-problem { + font-size: 13px; + color: var(--danger); + background: var(--danger-tint-alt); + border: 1px solid var(--danger-border-soft); + border-radius: var(--radius); + padding: 10px 12px; +} + +.auth-note { + font-size: 13px; + color: var(--muted); + background: var(--panel-sunken); + border: 1px solid var(--border-soft); + border-radius: var(--radius); + padding: 10px 12px; +} + +.auth-ok { + font-size: 13px; + color: var(--positive); + background: var(--positive-tint); + border: 1px solid var(--positive-border); + border-radius: var(--radius); + padding: 10px 12px; +} + +.auth-secret { + font-family: var(--font-mono); + font-size: 14px; + letter-spacing: 0.06em; + text-align: center; + background: var(--panel-sunken); + border: 1px solid var(--border-soft); + border-radius: var(--radius); + padding: 10px 12px; + user-select: all; +} + +.auth-qr { + display: flex; + justify-content: center; +} +.auth-qr svg { + width: 200px; + height: 200px; + background: #fff; + border: 1px solid var(--border); + border-radius: var(--radius); + padding: 12px; +} + +.auth-alt { + font-size: 12px; + color: var(--muted); + text-decoration: none; + align-self: center; +} +.auth-alt:hover { + color: var(--accent-ink); +} + +.auth-footer { + font-family: var(--font-mono); + font-size: 10px; + letter-spacing: 0.08em; + color: var(--muted-soft); + text-align: center; + padding-top: 4px; +} + +@media (max-width: 720px) { + .auth-stage { + padding: 0 16px 24px; + } +} diff --git a/crates/im-web/build.rs b/crates/im-web/build.rs new file mode 100644 index 0000000..944205d --- /dev/null +++ b/crates/im-web/build.rs @@ -0,0 +1,17 @@ +//! Compiles `style/main.scss` to `assets/main.css` under this crate's +//! manifest directory, where `asset!("assets/main.css")` in `layout.rs` +//! expects to find it. Crate-relative rather than `OUT_DIR`-relative so the +//! asset's id does not churn with every profile/build-hash — the same +//! contract izlek-web's build script keeps. + +fn main() { + let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); + let scss = format!("{manifest_dir}/../../style/main.scss"); + println!("cargo:rerun-if-changed={scss}"); + + let css = grass::from_path(&scss, &grass::Options::default()) + .unwrap_or_else(|err| panic!("failed to compile {scss}: {err}")); + let out_dir = format!("{manifest_dir}/assets"); + std::fs::create_dir_all(&out_dir).expect("failed to create assets/"); + std::fs::write(format!("{out_dir}/main.css"), &css).expect("failed to write assets/main.css"); +} diff --git a/crates/im-web/src/auth.rs b/crates/im-web/src/auth.rs new file mode 100644 index 0000000..0dedcd2 --- /dev/null +++ b/crates/im-web/src/auth.rs @@ -0,0 +1,197 @@ +//! The form handlers behind the pages. Every one answers a plain 303: the +//! page it lands on reads `?error=` / `?ok=` back on render — im serves no +//! client-side script, so there is no action value to answer with. + +use im_core::accounts::{self, AccountError}; +use im_core::model::UserId; +use serde::Deserialize; +use topcoat::Result; +use topcoat::context::Cx; +use topcoat::router::content::Form; +use topcoat::router::{HeaderName, StatusCode, header, route}; + +use crate::server::{self, PendingPurpose}; + +type Redirect = Result<(StatusCode, [(HeaderName, String); 1])>; + +fn see(location: String) -> Redirect { + Ok((StatusCode::SEE_OTHER, [(header::LOCATION, location)])) +} + +/// Percent-encodes a value for a query pair. The `back` a login carries is +/// always a local `/authorize?...` URL, which is full of `?&=` of its own. +fn urlencode(raw: &str) -> String { + let mut out = String::with_capacity(raw.len()); + for byte in raw.bytes() { + match byte { + b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => { + out.push(byte as char) + } + _ => out.push_str(&format!("%{byte:02X}")), + } + } + out +} + +/// A `back` worth honoring: a local absolute path, never `//elsewhere`. +/// Anything else — including a full URL — becomes the front door. +fn safe_back(raw: &str) -> &str { + if raw.starts_with('/') && !raw.starts_with("//") { + raw + } else { + "/" + } +} + +#[derive(Deserialize)] +pub struct LoginForm { + email: String, + password: String, + #[serde(default)] + back: Option, +} + +#[route(POST "/login")] +async fn login(cx: &Cx, Form(input): Form) -> Redirect { + let back = safe_back(input.back.as_deref().unwrap_or("/")).to_string(); + match accounts::verify_login(&server::app(cx).store, &input.email, &input.password).await { + Ok(user) if user.totp_confirmed => { + let sealed = server::mint_pending(cx, &user.id, PendingPurpose::Login, back); + server::set_pending_cookie(cx, sealed); + see("/login/totp".to_string()) + } + Ok(user) => { + // Accounts enrol TOTP at invite time, so this is the path for one + // created before that rule — sign it in, enrolment comes next. + let token = im_core::sessions::create_session(&server::app(cx).store, &user.id).await?; + server::set_session_cookie(cx, token.expose()); + see(back) + } + Err(_) => see(format!("/login?error=bad_login&back={}", urlencode(&back))), + } +} + +#[derive(Deserialize)] +pub struct TotpForm { + code: String, +} + +#[route(POST "/login/totp")] +async fn login_totp(cx: &Cx, Form(input): Form) -> Redirect { + let Some(pending) = server::opened_pending(cx) else { + return see("/login".to_string()); + }; + if pending.purpose != PendingPurpose::Login { + return see("/login".to_string()); + } + let store = &server::app(cx).store; + let user_id = UserId::from(pending.user.clone()); + let ok = match accounts::user_by_id(store, &user_id).await? { + Some(user) => match im_core::totp::totp_secret(store, &user.id).await? { + Some((secret, confirmed)) => { + confirmed + && im_core::totp::verify_totp( + &secret, + input.code.trim(), + time::OffsetDateTime::now_utc(), + ) + } + None => false, + }, + None => false, + }; + if !ok { + return see("/login/totp?error=bad_code".to_string()); + } + let token = im_core::sessions::create_session(store, &user_id).await?; + server::clear_pending_cookie(cx); + server::set_session_cookie(cx, token.expose()); + see(pending.back) +} + +#[derive(Deserialize)] +pub struct InviteForm { + token: String, + name: String, + password: String, + password_confirm: String, +} + +#[route(POST "/invite")] +async fn invite(cx: &Cx, Form(input): Form) -> Redirect { + if input.password != input.password_confirm { + return see(format!("/invite/{}?error=passwords_differ", input.token)); + } + let store = &server::app(cx).store; + let user = match accounts::create_user_from_invite( + store, + &input.token, + input.name.trim(), + &input.password, + ) + .await + { + Ok(user) => user, + Err(problem) => { + let code = match problem { + AccountError::InviteInvalid => "invite_invalid", + AccountError::InviteExpired => "invite_expired", + AccountError::InviteSpent => "invite_spent", + AccountError::EmailTaken => "email_taken", + AccountError::Password(im_core::accounts::PasswordProblem::TooShort) => { + "password_too_short" + } + AccountError::Password(im_core::accounts::PasswordProblem::LooksLikeYou) => { + "password_personal" + } + _ => { + return Err(topcoat::Error::from(std::io::Error::other( + problem.to_string(), + ))); + } + }; + return see(format!("/invite/{}?error={code}", input.token)); + } + }; + // TOTP enrolment is not optional: the account exists from here, and the + // enrolment page is the only way forward. + let secret = im_core::totp::generate_secret(); + im_core::totp::set_totp(store, &user.id, &secret).await?; + let sealed = server::mint_pending(cx, &user.id, PendingPurpose::Enroll, "/".to_string()); + server::set_pending_cookie(cx, sealed); + see("/enroll".to_string()) +} + +#[route(POST "/enroll")] +async fn enroll(cx: &Cx, Form(input): Form) -> Redirect { + let Some(pending) = server::opened_pending(cx) else { + return see("/login".to_string()); + }; + if pending.purpose != PendingPurpose::Enroll { + return see("/login".to_string()); + } + let store = &server::app(cx).store; + let user_id = UserId::from(pending.user); + let Some((secret, _)) = im_core::totp::totp_secret(store, &user_id).await? else { + return see("/login?error=enroll_first".to_string()); + }; + if !im_core::totp::verify_totp(&secret, input.code.trim(), time::OffsetDateTime::now_utc()) { + return see("/enroll?error=bad_code".to_string()); + } + im_core::totp::confirm_totp(store, &user_id).await?; + let token = im_core::sessions::create_session(store, &user_id).await?; + server::clear_pending_cookie(cx); + server::set_session_cookie(cx, token.expose()); + see("/?ok=enrolled".to_string()) +} + +/// "Sign out everywhere": the central session dies, and with it every +/// refresh token any app is still holding — see `sessions::revoke_session`. +#[route(POST "/logout")] +async fn logout(cx: &Cx) -> Redirect { + if let Some(token) = server::presented_session(cx) { + im_core::sessions::revoke_session(&server::app(cx).store, &token).await?; + } + server::clear_session_cookie(cx); + see("/".to_string()) +} diff --git a/crates/im-web/src/config.rs b/crates/im-web/src/config.rs new file mode 100644 index 0000000..38c3ef8 --- /dev/null +++ b/crates/im-web/src/config.rs @@ -0,0 +1,95 @@ +//! `config/im.toml`: read before anything is opened, written with development +//! defaults if it is not there yet — the same contract izlek-core's `Config` +//! keeps. A broken key stops the boot with its name in the message. + +use std::path::{Path, PathBuf}; + +use serde::Deserialize; + +const PATH: &str = "config/im.toml"; + +const DEFAULTS: &str = r#"database = "im.db" +listen = "127.0.0.1:7650" +issuer = "http://127.0.0.1:7650" +"#; + +#[derive(Clone)] +pub struct Config { + pub database: PathBuf, + pub listen: std::net::SocketAddr, + /// The OIDC issuer — the public base URL every endpoint address and every + /// `iss` claim derives from. + pub issuer: String, + pub smtp: Option, +} + +#[derive(Clone, Deserialize)] +pub struct Smtp { + pub host: String, + pub port: u16, + pub username: String, + pub password: String, + pub from: String, +} + +#[derive(Deserialize)] +struct Raw { + database: Option, + listen: Option, + issuer: Option, + smtp: Option, +} + +impl Config { + pub fn load() -> std::result::Result { + let path = Path::new(PATH); + if !path.exists() { + if let Some(dir) = path.parent() { + std::fs::create_dir_all(dir) + .map_err(|e| format!("cannot create {}: {e}", dir.display()))?; + } + std::fs::write(path, DEFAULTS).map_err(|e| format!("cannot write {PATH}: {e}"))?; + } + let text = std::fs::read_to_string(path).map_err(|e| format!("cannot read {PATH}: {e}"))?; + let raw: Raw = toml::from_str(&text).map_err(|e| format!("{PATH}: {e}"))?; + let issuer = raw + .issuer + .unwrap_or_else(|| "http://127.0.0.1:7650".to_string()); + if !issuer.starts_with("http://") && !issuer.starts_with("https://") { + return Err(format!("{PATH}: issuer {issuer:?} must be an http(s) URL")); + } + Ok(Config { + database: PathBuf::from(raw.database.unwrap_or_else(|| "im.db".to_string())), + listen: raw + .listen + .unwrap_or_else(|| "127.0.0.1:7650".to_string()) + .parse() + .map_err(|e| format!("{PATH}: listen: {e}"))?, + issuer: issuer.trim_end_matches('/').to_string(), + smtp: raw.smtp, + }) + } + + /// Cookies are `Secure` only when the issuer is https — the dev issuer is + /// plain http, and a Secure cookie over it would never stick. + pub fn is_secure(&self) -> bool { + self.issuer.starts_with("https://") + } + + /// The startup log lines: which file, which address, which issuer. + pub fn report(&self) -> Vec { + vec![ + format!("database {}", self.database.display()), + format!("listen {}", self.listen), + format!("issuer {}", self.issuer), + format!( + "mail {}", + if self.smtp.is_some() { + "smtp" + } else { + "stdout (dev)" + } + ), + ] + } +} diff --git a/crates/im-web/src/layout.rs b/crates/im-web/src/layout.rs new file mode 100644 index 0000000..a897e41 --- /dev/null +++ b/crates/im-web/src/layout.rs @@ -0,0 +1,48 @@ +//! The document shell every im page renders through. No hydration, no +//! runtime script: pages are plain HTML forms, posted hard. + +use topcoat::Result; +use topcoat::asset::{Asset, asset}; +use topcoat::context::Cx; +use topcoat::view::view; + +/// `style/main.scss`, compiled by `build.rs` into `assets/main.css`. +const STYLE: Asset = asset!("assets/main.css"); + +/// The mark, in the word as it is in the name: lower case, the Turkish +/// tittle. Text-only here — the auth card is the whole chrome. +pub async fn wordmark(cx: &Cx) -> Result { + view! { + cx => + + "im" + + } +} + +/// A full document around an already-rendered stage — the same way +/// izlek-web's `#[layout]` receives its slot. +pub async fn shell(cx: &Cx, title: &str, stage: Result) -> Result { + let stage = stage?; + view! { + cx => + + + + + + + + + (title) + + + + (stage) + + + } +} diff --git a/crates/im-web/src/main.rs b/crates/im-web/src/main.rs new file mode 100644 index 0000000..613a0a4 --- /dev/null +++ b/crates/im-web/src/main.rs @@ -0,0 +1,197 @@ +//! im — the IzlekLab SSO. Server by default; `invite` and `create-client` +//! are the admin surface until there is a settings screen. + +use std::sync::Arc; + +use im_core::store::Store; +use topcoat::Result; +use topcoat::asset::RouterBuilderAssetExt; +use topcoat::cookie::RouterBuilderCookieExt; +use topcoat::router::{Router, RouterBuilderDiscoverExt, route}; + +mod auth; +mod config; +mod layout; +mod oidc; +mod pages; +mod server; + +use config::Config; + +#[route(GET "/healthz")] +async fn healthz() -> Result<&'static str> { + Ok("ok") +} + +#[tokio::main] +async fn main() { + let args: Vec = std::env::args().collect(); + let config = match Config::load() { + Ok(config) => config, + Err(problem) => { + eprintln!("im: {problem}"); + std::process::exit(2); + } + }; + + match args.get(1).map(String::as_str) { + None => serve(config).await, + Some("invite") => { + let Some(email) = args.get(2) else { + eprintln!("usage: im-web invite "); + std::process::exit(2); + }; + invite(config, email).await; + } + Some("create-client") => { + let (Some(name), uris) = (args.get(2), args.get(3..).unwrap_or(&[])) else { + eprintln!("usage: im-web create-client [more-uris...]"); + std::process::exit(2); + }; + if uris.is_empty() { + eprintln!("usage: im-web create-client [more-uris...]"); + std::process::exit(2); + } + create_client(config, name, uris).await; + } + Some(other) => { + eprintln!( + "im: unknown command {other:?} (expected: invite, create-client, or none to serve)" + ); + std::process::exit(2); + } + } +} + +async fn open_store(config: &Config) -> Arc { + Arc::new( + Store::open(&config.database) + .await + .expect("failed to open the database"), + ) +} + +/// `im-web invite `: creates the invite, mails it when SMTP is +/// configured, prints the link otherwise (dev mode). +async fn invite(config: Config, email: &str) { + let store = open_store(&config).await; + let token = im_core::accounts::create_invite(&store, email, None) + .await + .expect("failed to create the invite"); + let link = format!("{}/invite/{}", config.issuer, token.expose()); + match build_mailer(&config) { + Some(mailer) => { + let message = lettre::Message::builder() + .from( + config + .smtp + .as_ref() + .unwrap() + .from + .parse() + .expect("smtp.from"), + ) + .to(email.parse().expect("invite email")) + .subject("You're invited") + .body(format!( + "You've been invited. This link is yours for {} days:\n\n{link}\n", + im_core::accounts::INVITE_DAYS + )) + .expect("invite mail"); + use lettre::AsyncTransport; + mailer + .send(message) + .await + .expect("failed to send the invite"); + println!("im invite mailed to {email}"); + } + None => println!("im invite for {email}: {link}"), + } +} + +/// `im-web create-client `: registers a relying party and +/// prints the secret exactly once. +async fn create_client(config: Config, name: &str, uris: &[String]) { + let store = open_store(&config).await; + let (id, secret) = im_core::oidc::create_client(&store, name, uris.to_vec()) + .await + .expect("failed to create the client"); + println!("im client {name}"); + println!(" client_id {id}"); + println!(" client_secret {}", secret.expose()); + println!(" (the secret is shown once; its digest is all the database keeps)"); +} + +fn build_mailer(config: &Config) -> Option> { + let smtp = config.smtp.as_ref()?; + let creds = lettre::transport::smtp::authentication::Credentials::new( + smtp.username.clone(), + smtp.password.clone(), + ); + Some( + lettre::AsyncSmtpTransport::::relay(&smtp.host) + .expect("smtp relay") + .port(smtp.port) + .credentials(creds) + .build(), + ) +} + +async fn serve(config: Config) { + for line in config.report() { + println!("im {line}"); + } + let store = open_store(&config).await; + let app = server::App { + store, + config: config.clone(), + }; + + // The bundle beside the executable is the only stylesheet this process + // can serve — `topcoat asset bundle -p im-web` produces it. + let bundle = topcoat::asset::AssetBundle::load().unwrap_or_else(|err| { + eprintln!("im: the asset bundle beside the executable failed to load: {err}"); + eprintln!("im: run `topcoat asset bundle -p im-web` first"); + std::process::exit(2); + }); + + let router = Router::builder() + .discover() + .cookies() + .assets(bundle) + .app_context(app) + .build(); + + // `topcoat::start` binds HOST/PORT from the environment; the listen + // address is a config/im.toml decision, so the listener is bound + // explicitly against the same value the boot log just printed. + let listener = tokio::net::TcpListener::bind(config.listen) + .await + .expect("failed to bind the listen address"); + topcoat::serve_until(listener, router, shutdown_signal()) + .await + .expect("server error"); +} + +/// Resolves when the process is asked to stop: Ctrl+C, or `SIGTERM` from a +/// service manager. +async fn shutdown_signal() { + let ctrl_c = async { + tokio::signal::ctrl_c() + .await + .expect("failed to install the Ctrl+C handler"); + }; + #[cfg(unix)] + let terminate = async { + tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate()) + .expect("failed to install the SIGTERM handler") + .recv() + .await; + }; + #[cfg(not(unix))] + let terminate = std::future::pending::<()>(); + tokio::select! { + () = ctrl_c => {}, + () = terminate => {}, + } +} diff --git a/crates/im-web/src/oidc.rs b/crates/im-web/src/oidc.rs new file mode 100644 index 0000000..902f2af --- /dev/null +++ b/crates/im-web/src/oidc.rs @@ -0,0 +1,361 @@ +//! The OIDC surface: discovery, JWKS, authorize, token, userinfo. The pages +//! are for people; these are for apps — im-client first, any OIDC-speaking +//! client after. + +use im_core::model::{ClientId, UserId}; +use im_core::oidc; +use serde::Deserialize; +use topcoat::Result; +use topcoat::context::Cx; +use topcoat::router::content::{Form, Json}; +use topcoat::router::request::{headers, uri}; +use topcoat::router::response::{IntoResponse, Response}; +use topcoat::router::{HeaderValue, StatusCode, header, route}; + +use crate::server::{self, App}; + +fn app(cx: &Cx) -> &App { + server::app(cx) +} + +/// A JSON OIDC error: `{"error": code}` with the matching status. +fn oidc_error(cx: &Cx, status: StatusCode, code: &str) -> Result { + (status, Json(serde_json::json!({ "error": code }))).into_response(cx) +} + +#[route(GET "/.well-known/openid-configuration")] +async fn discovery(cx: &Cx) -> Result> { + let issuer = &app(cx).config.issuer; + Ok(Json(serde_json::json!({ + "issuer": issuer, + "authorization_endpoint": format!("{issuer}/authorize"), + "token_endpoint": format!("{issuer}/token"), + "userinfo_endpoint": format!("{issuer}/userinfo"), + "jwks_uri": format!("{issuer}/jwks.json"), + "response_types_supported": ["code"], + "grant_types_supported": ["authorization_code", "refresh_token"], + "subject_types_supported": ["public"], + "id_token_signing_alg_values_supported": ["RS256"], + "scopes_supported": ["openid", "profile", "email"], + "claims_supported": ["iss", "sub", "aud", "exp", "iat", "nonce", "email", "name"], + "code_challenge_methods_supported": ["S256"], + }))) +} + +#[route(GET "/jwks.json")] +async fn jwks(cx: &Cx) -> Result> { + Ok(Json(im_core::keys::jwks(&app(cx).store).await?)) +} + +// --------------------------------------------------------------------------- +// /authorize +// --------------------------------------------------------------------------- + +/// The OIDC error redirect: only ever sent after the client AND the exact +/// redirect_uri have checked out — otherwise the answer is a bare 400, never +// a redirect to an address a stranger supplied. +fn authorize_error( + cx: &Cx, + redirect_uri: &str, + state: Option<&str>, + error: &str, +) -> Result { + let sep = if redirect_uri.contains('?') { '&' } else { '?' }; + let mut location = format!("{redirect_uri}{sep}error={error}"); + if let Some(state) = state { + location.push_str(&format!("&state={state}")); + } + ( + StatusCode::SEE_OTHER, + [( + header::LOCATION, + HeaderValue::from_str(&location).unwrap_or_else(|_| HeaderValue::from_static("/")), + )], + ) + .into_response(cx) +} + +fn bad_request(cx: &Cx) -> Result { + (StatusCode::BAD_REQUEST, "invalid request").into_response(cx) +} + +/// Percent-encodes a value for a query pair — the `back` a login carries is +/// a local `/authorize?...` URL, full of `?&=` of its own. +fn urlencode(raw: &str) -> String { + let mut out = String::with_capacity(raw.len()); + for byte in raw.bytes() { + match byte { + b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => { + out.push(byte as char) + } + _ => out.push_str(&format!("%{byte:02X}")), + } + } + out +} + +#[route(GET "/authorize")] +async fn authorize(cx: &Cx) -> Result { + let query = uri(cx).query().unwrap_or("").to_string(); + let get = |key: &str| crate::pages::query_value(&query, key); + + // Client identity first: nothing redirects anywhere until both the client + // and the exact redirect_uri are known-good. + let Some(client_id) = get("client_id") else { + return bad_request(cx); + }; + let Some(client) = oidc::client_by_id(&app(cx).store, &client_id).await? else { + return bad_request(cx); + }; + let Some(redirect_uri) = get("redirect_uri") else { + return bad_request(cx); + }; + if !client.redirect_uris.contains(&redirect_uri) { + return bad_request(cx); + } + let state = get("state"); + + if get("response_type").as_deref() != Some("code") { + return authorize_error( + cx, + &redirect_uri, + state.as_deref(), + "unsupported_response_type", + ); + } + let scope = get("scope").unwrap_or_default(); + let scopes: Vec<&str> = scope.split(' ').collect(); + if !scopes.contains(&"openid") + || !scopes + .iter() + .all(|s| ["openid", "profile", "email"].contains(s)) + { + return authorize_error(cx, &redirect_uri, state.as_deref(), "invalid_scope"); + } + let Some(challenge) = get("code_challenge") else { + return authorize_error(cx, &redirect_uri, state.as_deref(), "invalid_request"); + }; + if get("code_challenge_method").as_deref() != Some("S256") { + return authorize_error(cx, &redirect_uri, state.as_deref(), "invalid_request"); + } + + // The central session is the whole point: a browser that already signed + // in (password and second factor both behind it) gets its code without + // seeing a form at all. + let presented = server::presented_session(cx); + let user = match &presented { + Some(token) => im_core::sessions::resolve_session(&app(cx).store, token).await?, + None => None, + }; + let Some(user) = user else { + let back = format!("/authorize?{query}"); + let location = format!("/login?back={}", urlencode(&back)); + return ( + StatusCode::SEE_OTHER, + [(header::LOCATION, HeaderValue::from_str(&location).unwrap())], + ) + .into_response(cx); + }; + let session_hash = im_core::accounts::hash_token(presented.as_deref().unwrap_or_default()); + let code = oidc::create_auth_code( + &app(cx).store, + &client.client_id, + &user.id, + &redirect_uri, + get("nonce"), + &challenge, + &session_hash, + ) + .await?; + let sep = if redirect_uri.contains('?') { '&' } else { '?' }; + let mut location = format!("{redirect_uri}{sep}code={}", code.expose()); + if let Some(state) = state { + location.push_str(&format!("&state={state}")); + } + ( + StatusCode::SEE_OTHER, + [(header::LOCATION, HeaderValue::from_str(&location).unwrap())], + ) + .into_response(cx) +} + +// --------------------------------------------------------------------------- +// /token +// --------------------------------------------------------------------------- + +#[derive(Deserialize)] +struct TokenForm { + grant_type: String, + code: Option, + redirect_uri: Option, + client_id: Option, + client_secret: Option, + code_verifier: Option, + refresh_token: Option, +} + +/// Signs the pair of tokens for `user` toward `client`. +async fn mint_tokens( + cx: &Cx, + user: &im_core::model::User, + client_id: &ClientId, + nonce: Option, +) -> Result<(String, String)> { + let now = time::OffsetDateTime::now_utc().unix_timestamp(); + let issuer = &app(cx).config.issuer; + let (kid, key) = im_core::keys::active_signing_key(&app(cx).store).await?; + let id_claims = serde_json::json!({ + "iss": issuer, + "sub": user.id.as_str(), + "aud": client_id.as_str(), + "exp": now + oidc::TOKEN_SECONDS, + "iat": now, + "email": user.email, + "name": user.name, + "nonce": nonce, + }); + let access_claims = serde_json::json!({ + "iss": issuer, + "sub": user.id.as_str(), + "aud": client_id.as_str(), + "exp": now + oidc::TOKEN_SECONDS, + "iat": now, + "scope": "openid profile email", + }); + Ok(( + oidc::sign_jwt(&access_claims, &kid, &key), + oidc::sign_jwt(&id_claims, &kid, &key), + )) +} + +fn token_answer(cx: &Cx, access: String, id: String, refresh: String) -> Result { + Json(serde_json::json!({ + "access_token": access, + "token_type": "Bearer", + "expires_in": oidc::TOKEN_SECONDS, + "refresh_token": refresh, + "id_token": id, + })) + .into_response(cx) +} + +#[route(POST "/token")] +async fn exchange(cx: &Cx, Form(input): Form) -> Result { + let Some(client_id) = input.client_id else { + return oidc_error(cx, StatusCode::BAD_REQUEST, "invalid_request"); + }; + let Some(client) = oidc::client_by_id(&app(cx).store, &client_id).await? else { + return oidc_error(cx, StatusCode::UNAUTHORIZED, "invalid_client"); + }; + let Some(secret) = input.client_secret else { + return oidc_error(cx, StatusCode::UNAUTHORIZED, "invalid_client"); + }; + if !oidc::verify_client_secret(&client, &secret) { + return oidc_error(cx, StatusCode::UNAUTHORIZED, "invalid_client"); + } + + match input.grant_type.as_str() { + "authorization_code" => { + let (Some(code), Some(redirect_uri), Some(verifier)) = + (input.code, input.redirect_uri, input.code_verifier) + else { + return oidc_error(cx, StatusCode::BAD_REQUEST, "invalid_request"); + }; + let Some(consumed) = oidc::consume_auth_code(&app(cx).store, &code).await? else { + return oidc_error(cx, StatusCode::BAD_REQUEST, "invalid_grant"); + }; + if consumed.client_id != client.client_id + || consumed.redirect_uri != redirect_uri + || !oidc::pkce_matches(&consumed.code_challenge, &verifier) + { + return oidc_error(cx, StatusCode::BAD_REQUEST, "invalid_grant"); + } + let Some(user) = + im_core::accounts::user_by_id(&app(cx).store, &consumed.user_id).await? + else { + return oidc_error(cx, StatusCode::BAD_REQUEST, "invalid_grant"); + }; + if user.disabled { + return oidc_error(cx, StatusCode::BAD_REQUEST, "invalid_grant"); + } + let (access, id) = mint_tokens(cx, &user, &client.client_id, consumed.nonce).await?; + let refresh = oidc::issue_refresh( + &app(cx).store, + &user.id, + &client.client_id, + &consumed.session_hash, + ) + .await?; + token_answer(cx, access, id, refresh.expose().to_string()) + } + "refresh_token" => { + let Some(presented) = input.refresh_token else { + return oidc_error(cx, StatusCode::BAD_REQUEST, "invalid_request"); + }; + let Some((fresh, old)) = oidc::rotate_refresh(&app(cx).store, &presented).await? else { + return oidc_error(cx, StatusCode::BAD_REQUEST, "invalid_grant"); + }; + if old.client_id != client.client_id { + return oidc_error(cx, StatusCode::BAD_REQUEST, "invalid_grant"); + } + let Some(user) = im_core::accounts::user_by_id(&app(cx).store, &old.user_id).await? + else { + return oidc_error(cx, StatusCode::BAD_REQUEST, "invalid_grant"); + }; + if user.disabled { + return oidc_error(cx, StatusCode::BAD_REQUEST, "invalid_grant"); + } + let (access, id) = mint_tokens(cx, &user, &client.client_id, None).await?; + token_answer(cx, access, id, fresh.expose().to_string()) + } + _ => oidc_error(cx, StatusCode::BAD_REQUEST, "unsupported_grant_type"), + } +} + +// --------------------------------------------------------------------------- +// /userinfo +// --------------------------------------------------------------------------- + +#[route(GET "/userinfo")] +async fn userinfo(cx: &Cx) -> Result { + let presented = headers(cx) + .get(header::AUTHORIZATION) + .and_then(|value| value.to_str().ok()) + .and_then(|value| value.strip_prefix("Bearer ")) + .map(str::to_string); + let Some(presented) = presented else { + return ( + StatusCode::UNAUTHORIZED, + [(header::WWW_AUTHENTICATE, HeaderValue::from_static("Bearer"))], + ) + .into_response(cx); + }; + // Signature and expiry first; the audience is checked against the client + // registry, not a fixed value — any registered app may ask. + let Some(claims) = oidc::verify_jwt(&app(cx).store, &presented, None).await? else { + return oidc_error(cx, StatusCode::UNAUTHORIZED, "invalid_token"); + }; + let Some(aud) = claims["aud"].as_str() else { + return oidc_error(cx, StatusCode::UNAUTHORIZED, "invalid_token"); + }; + if oidc::client_by_id(&app(cx).store, aud).await?.is_none() { + return oidc_error(cx, StatusCode::UNAUTHORIZED, "invalid_token"); + } + let Some(sub) = claims["sub"].as_str() else { + return oidc_error(cx, StatusCode::UNAUTHORIZED, "invalid_token"); + }; + let Some(user) = + im_core::accounts::user_by_id(&app(cx).store, &UserId::from(sub.to_string())).await? + else { + return oidc_error(cx, StatusCode::UNAUTHORIZED, "invalid_token"); + }; + if user.disabled { + return oidc_error(cx, StatusCode::UNAUTHORIZED, "invalid_token"); + } + Json(serde_json::json!({ + "sub": user.id.as_str(), + "email": user.email, + "name": user.name, + })) + .into_response(cx) +} diff --git a/crates/im-web/src/pages.rs b/crates/im-web/src/pages.rs new file mode 100644 index 0000000..e760bb2 --- /dev/null +++ b/crates/im-web/src/pages.rs @@ -0,0 +1,417 @@ +//! The pages: sign-in, the second factor, invite acceptance, TOTP enrolment, +//! and the signed-in landing. Every page is server-rendered on every request; +//! a refused form post comes back as `?error=` on the query and the +//! page reads it out. + +use im_core::accounts::MIN_PASSWORD_CHARS; +use topcoat::Result; +use topcoat::context::Cx; +use topcoat::router::error::see_other; +use topcoat::router::response::{IntoResponse, Response}; +use topcoat::router::{page, path_param, route}; +use topcoat::view::view; + +use crate::layout::{shell, wordmark}; +use crate::server::{self, PendingPurpose}; + +path_param!(token); + +/// What a refusal code reads as on the page. The code travels through the +/// URL; the sentence never does. +pub fn error_text(code: &str) -> &'static str { + match code { + "bad_login" => "Wrong email or password.", + "bad_code" => "That code didn't match — try again.", + "invite_invalid" => "This invite link is not valid.", + "invite_expired" => "This invite has expired. Ask for a fresh one.", + "invite_spent" => "This invite was already used.", + "email_taken" => "An account with this address already exists.", + "password_too_short" => "The password needs at least 10 characters.", + "password_personal" => "The password can't contain your address or your name.", + "passwords_differ" => "The two passwords don't match.", + "enroll_first" => "Set up your second factor first.", + _ => "Something went wrong. Try again.", + } +} + +/// The refusal this request carries back, if any. Values come percent- +/// decoded: `redirect_uri=http%3A%2F%2F…` must equal the registered URI. +pub fn query_value(query: &str, key: &str) -> Option { + query.split('&').find_map(|pair| { + let (k, v) = pair.split_once('=')?; + (k == key).then(|| urldecode(v)) + }) +} + +/// Percent-decodes a query value (`+` is a space, form-style). +pub fn urldecode(raw: &str) -> String { + let bytes = raw.as_bytes(); + let mut out = Vec::with_capacity(bytes.len()); + let mut i = 0; + while i < bytes.len() { + match bytes[i] { + b'+' => { + out.push(b' '); + i += 1; + } + b'%' if i + 2 < bytes.len() => { + let hex = std::str::from_utf8(&bytes[i + 1..i + 3]).unwrap_or(""); + match u8::from_str_radix(hex, 16) { + Ok(byte) => { + out.push(byte); + i += 3; + } + Err(_) => { + out.push(b'%'); + i += 1; + } + } + } + byte => { + out.push(byte); + i += 1; + } + } + } + String::from_utf8_lossy(&out).into_owned() +} + +fn current_query(cx: &Cx) -> String { + topcoat::router::request::uri(cx) + .query() + .unwrap_or("") + .to_string() +} + +/// The front door: the sign-in card, or the signed-in landing when the +/// browser already holds a session. +#[page("/")] +async fn landing(cx: &Cx) -> Result { + match server::current_user(cx).await { + Some(user) => signed_in(cx, &user).await, + None => login_card(cx).await, + } +} + +/// `/login` is the same card with a `back` it must keep: the `/authorize` +/// call the browser was in the middle of. +#[page("/login")] +async fn login(cx: &Cx) -> Result { + login_card(cx).await +} + +async fn login_card(cx: &Cx) -> Result { + let query = current_query(cx); + let back = query_value(&query, "back").unwrap_or_else(|| "/".to_string()); + let error = query_value(&query, "error"); + let stage = view! { + cx => +
+
+ (wordmark(cx).await?) +
+
+
"Sign in"
+
"One account for everything IzlekLab."
+
+ if let Some(code) = error { +
(error_text(&code))
+ } +
+ + + + +
+
+ +
+
+ }; + shell(cx, "Sign in · im", stage).await +} + +/// The second factor. Reached only with a pending-login cookie; without one +/// the request starts over at the sign-in card. +#[route(GET "/login/totp")] +async fn totp(cx: &Cx) -> Result { + match server::opened_pending(cx) { + Some(pending) if pending.purpose == PendingPurpose::Login => { + let query = current_query(cx); + let error = query_value(&query, "error"); + let stage = view! { + cx => +
+
+ (wordmark(cx).await?) +
+
+
"Two-factor code"
+
"The 6-digit code from your authenticator."
+
+ if let Some(code) = error { +
(error_text(&code))
+ } +
+ + +
+
+ +
+
+ }; + shell(cx, "Two-factor · im", stage).await?.into_response(cx) + } + _ => see_other("/login").into_response(cx), + } +} + +/// The invited member's first screen: name and password, address locked to +/// what the invite carries. +#[route(GET "/invite/{token}")] +async fn invite(cx: &Cx) -> Result { + let token: &str = path_param::(cx); + let invite = im_core::accounts::invite_by_token(&server::app(cx).store, token).await?; + let query = current_query(cx); + let error = query_value(&query, "error"); + + let usable = matches!( + &invite, + Some(invite) if invite.accepted_at.is_none() && invite.expires_at > time::OffsetDateTime::now_utc() + ); + let stage = if usable { + let invite = invite.expect("usable implies Some"); + view! { + cx => +
+
+ (wordmark(cx).await?) +
+
+
"You're invited"
+
"Pick a name and a password. Next step sets up two-factor sign-in."
+
+ if let Some(code) = error { +
(error_text(&code))
+ } +
+ +
+ "Email" +
+ (invite.email) +
+
+ + + + +
+
+ +
+
+ } + } else { + let code = match &invite { + None => "invite_invalid", + Some(i) if i.accepted_at.is_some() => "invite_spent", + _ => "invite_expired", + }; + view! { + cx => +
+
+ (wordmark(cx).await?) +
+
+
"This link doesn't work"
+
+
(error_text(code))
+ "Back to sign in" +
+
+
+ } + }; + shell(cx, "You're invited · im", stage) + .await? + .into_response(cx) +} + +/// TOTP enrolment: the QR, the manual key, and the first code that proves +/// the authenticator agrees. Reached with a pending-enroll cookie, set when +/// the account was created. +#[route(GET "/enroll")] +async fn enroll(cx: &Cx) -> Result { + let Some(pending) = server::opened_pending(cx) else { + return see_other("/login").into_response(cx); + }; + if pending.purpose != PendingPurpose::Enroll { + return see_other("/login").into_response(cx); + } + let user = im_core::accounts::user_by_id( + &server::app(cx).store, + &im_core::model::UserId::from(pending.user.clone()), + ) + .await? + .ok_or_else(|| topcoat::Error::from(std::io::Error::other("pending user is gone")))?; + let Some((secret, _confirmed)) = + im_core::totp::totp_secret(&server::app(cx).store, &user.id).await? + else { + return see_other("/login?error=enroll_first").into_response(cx); + }; + + let issuer = &server::app(cx).config.issuer; + let uri = im_core::totp::totp_uri("im", &user.email, &secret); + let qr = qrcode::QrCode::new(uri.as_bytes()) + .and_then(|code| { + Ok::<_, qrcode::types::QrError>( + code.render::() + .min_dimensions(200, 200) + .build(), + ) + }) + .map_err(|e| topcoat::Error::from(std::io::Error::other(format!("qr: {e}"))))?; + let manual = im_core::totp::display_secret(&secret); + let _ = issuer; + let query = current_query(cx); + let error = query_value(&query, "error"); + + let stage = view! { + cx => +
+
+ (wordmark(cx).await?) +
+
+
"Set up two-factor"
+
"Scan with your authenticator, then type the 6-digit code it shows."
+
+ if let Some(code) = error { +
(error_text(&code))
+ } +
(topcoat::view::Unescaped::new_unchecked(qr))
+
(manual)
+
+ + +
+
+ +
+
+ }; + shell(cx, "Two-factor setup · im", stage) + .await? + .into_response(cx) +} + +/// The signed-in landing. im is an auth service, not an app: this page is +/// the proof of session, the way out, and nothing more. +async fn signed_in(cx: &Cx, user: &im_core::model::User) -> Result { + let query = current_query(cx); + let ok = query_value(&query, "ok"); + let stage = view! { + cx => +
+
+ (wordmark(cx).await?) +
+
+
(format!("Signed in as {}", user.name))
+
(user.email.clone())
+
+ if ok.as_deref() == Some("enrolled") { +
"Two-factor sign-in is on. You're all set."
+ } +
+ +
+
+ +
+
+ }; + shell(cx, "im", stage).await +} diff --git a/crates/im-web/src/server.rs b/crates/im-web/src/server.rs new file mode 100644 index 0000000..0cca7d2 --- /dev/null +++ b/crates/im-web/src/server.rs @@ -0,0 +1,149 @@ +//! Shared request plumbing: the app context, the two cookies (`im_session` +//! for a completed login, `im_pending` for the ten minutes between password +//! and second factor), and the refusal codes a redirect carries back to the +//! page that posted the form. +//! +//! im serves no client-side script, so there is no refusal-carrying layer as +//! in İzlek: every form post answers a plain 303 whose query names the +//! refusal, and the page reads it back on render. + +use std::sync::Arc; + +use im_core::model::User; +use im_core::store::Store; +use topcoat::context::{Cx, try_app_context}; +use topcoat::cookie::{Cookie, Cookies, cookie, cookies}; + +use crate::config::Config; + +pub const SESSION_COOKIE: &str = "im_session"; +pub const PENDING_COOKIE: &str = "im_pending"; + +/// The pending marker's lifetime: long enough to find the authenticator, +/// short enough to not be a session. +pub const PENDING_MINUTES: i64 = 10; + +pub struct App { + pub store: Arc, + pub config: Config, +} + +pub fn app(cx: &Cx) -> &App { + try_app_context::(cx).expect("the router always carries the App") +} + +/// The application cookie jar, with the attributes every im cookie wants. +fn app_cookies(cx: &Cx) -> impl Cookies { + cookies(cx) + .default_secure(app(cx).config.is_secure()) + .default_http_only(true) + .default_same_site(topcoat::cookie::SameSite::Lax) + .default_path("/") +} + +/// The session cookie value this request presented, if it presented one. +pub fn presented_session(cx: &Cx) -> Option { + cookies(cx) + .get(SESSION_COOKIE) + .map(|c| c.value().to_string()) +} + +pub fn presented_pending(cx: &Cx) -> Option { + cookies(cx) + .get(PENDING_COOKIE) + .map(|c| c.value().to_string()) +} + +/// Writes the session cookie. `HttpOnly` so script cannot read it, `Secure` +/// (on https issuers) so it never crosses plain HTTP, `SameSite=Lax` so +/// another site's form cannot post with it — and so the top-level redirect +/// back from `/authorize` still carries it. +pub fn set_session_cookie(cx: &Cx, token: &str) { + app_cookies(cx).add(cookie! { + SESSION_COOKIE = token.to_owned(); + Path = "/"; + HttpOnly; + SameSite = Lax; + MaxAge = time::Duration::days(im_core::sessions::SESSION_DAYS) + }); +} + +pub fn set_pending_cookie(cx: &Cx, sealed: String) { + app_cookies(cx).add(cookie! { + PENDING_COOKIE = sealed; + Path = "/"; + HttpOnly; + SameSite = Lax; + MaxAge = time::Duration::minutes(PENDING_MINUTES) + }); +} + +/// Removes the session cookie from this browser. The server-side revocation +/// is what actually ends the session; this only tidies the client. +pub fn clear_session_cookie(cx: &Cx) { + app_cookies(cx).remove(Cookie::build((SESSION_COOKIE, "")).path("/").build()); +} + +pub fn clear_pending_cookie(cx: &Cx) { + app_cookies(cx).remove(Cookie::build((PENDING_COOKIE, "")).path("/").build()); +} + +/// The person behind this request, resolved through the central session. +pub async fn current_user(cx: &Cx) -> Option { + let token = presented_session(cx)?; + im_core::sessions::resolve_session(&app(cx).store, &token) + .await + .ok() + .flatten() +} + +// --------------------------------------------------------------------------- +// The pending marker: between password and TOTP, between invite and enrolment +// --------------------------------------------------------------------------- + +#[derive(Debug, serde::Serialize, serde::Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum PendingPurpose { + /// Password verified, TOTP code still owed. + Login, + /// Account created, TOTP enrolment still owed. + Enroll, +} + +#[derive(Debug, serde::Serialize, serde::Deserialize)] +pub struct Pending { + pub user: String, + pub purpose: PendingPurpose, + /// The `/authorize` URL the login is in the middle of, urlencoded as it + /// arrived; `/` when there is none. + pub back: String, + pub exp: i64, +} + +pub fn mint_pending( + cx: &Cx, + user: &im_core::model::UserId, + purpose: PendingPurpose, + back: String, +) -> String { + let pending = Pending { + user: user.to_string(), + purpose, + back, + exp: time::OffsetDateTime::now_utc().unix_timestamp() + PENDING_MINUTES * 60, + }; + let json = serde_json::to_string(&pending).expect("Pending is plain data"); + app(cx).store.seal_value(json.as_bytes()) +} + +/// Opens the pending cookie this request presented. `None` for absent, +/// forged, or expired — all three mean "start the login over". +pub fn opened_pending(cx: &Cx) -> Option { + let sealed = presented_pending(cx)?; + let bytes = app(cx).store.open_value(&sealed)?; + let pending: Pending = serde_json::from_slice(&bytes).ok()?; + if pending.exp <= time::OffsetDateTime::now_utc().unix_timestamp() { + return None; + } + Some(pending) +} diff --git a/style/main.scss b/style/main.scss new file mode 100644 index 0000000..763d961 --- /dev/null +++ b/style/main.scss @@ -0,0 +1,374 @@ +// im — the IzlekLab SSO. One screen family: the auth card. The palette, +// rhythm and idioms are İzlek's "instrument" skin (warm-gray ground, quiet +// borders, the same accent family), lifted from izlek/style/main.scss so the +// two products read as one family. +// +// İzlek flips themes through a per-user `data-theme` setting; im has no +// settings screen, so dark follows `prefers-color-scheme`. The token set is +// the subset of İzlek's that the auth screens read. + +// Instrument, light (defaults; also the no-JS fallback). +:root { + color-scheme: light; + --bg: #f2f2f0; + --surface: #fbfbfa; + --border: #dcdcd8; + --border-strong: #d0d0cb; + --border-soft: #d3d3ce; + --ink: #1a1b1d; + --muted: #6b7078; + --muted-soft: #6b7078; + --accent: #46557b; + --accent-tint: #eef0f5; + --accent-ink: #2f3c5c; + --accent-strong: #5a6a94; + + --field-bg: #f5f5f3; + --panel-sunken: #eeeeec; + + --danger: #a04a24; + --danger-tint-alt: #fbf1ec; + --danger-border-soft: #eddcd3; + + --positive: #5c7b46; + --positive-tint: #eef3e9; + --positive-border: #d3e0c6; + + --font-sans: system-ui, sans-serif; + --font-mono: 'IBM Plex Mono', ui-monospace, monospace; + + --control-h-lg: 40px; + --radius: 3px; + --radius-sm: var(--radius); + --radius-lg: 3px; + --shadow-2: none; + + --dur-fast: 120ms; + --ease: ease-out; +} + +// Instrument, dark: near-black neutral-cool; tint fills go translucent and +// tint borders go alpha so the ground shows through. +@media (prefers-color-scheme: dark) { + :root { + color-scheme: dark; + --bg: #0d0e10; + --surface: #14161a; + --border: #23262c; + --border-strong: #2e323a; + --border-soft: #1f2226; + --ink: #e6e4de; + --muted: #7d8590; + --muted-soft: #4a4f58; + --accent: #8ba1e8; + --accent-tint: rgba(139, 161, 232, 0.14); + --accent-ink: #b9c6ee; + --accent-strong: #7e93d9; + + --field-bg: #101216; + --panel-sunken: #101216; + + --danger: #e0906a; + --danger-tint-alt: rgba(224, 144, 106, 0.05); + --danger-border-soft: rgba(224, 144, 106, 0.3); + + --positive: #9db98a; + --positive-tint: rgba(157, 185, 138, 0.13); + --positive-border: rgba(157, 185, 138, 0.4); + } +} + +* { box-sizing: border-box; } + +body { + margin: 0; + background: var(--bg); + color: var(--ink); + font-family: var(--font-sans); + font-size: 14px; + line-height: 1.45; + -webkit-font-smoothing: antialiased; +} + +a { + color: var(--accent); + transition: color var(--dur-fast) var(--ease); + &:hover { color: var(--accent-ink); } +} + +// --- Account screens (the whole product, today) ---------------------------- + +// The card centers in the viewport; a card taller than it (a landscape +// phone) pans inside the stage instead of growing the document. +body:has(.auth-stage) { + height: 100vh; + height: 100dvh; + overflow: hidden; + display: flex; + flex-direction: column; + + > * { flex: none; } + > .auth-stage { + flex: 1; + min-height: 0; + overflow-y: auto; + scrollbar-width: none; + + &::-webkit-scrollbar { display: none; } + } +} + +.auth-stage { + min-height: 100vh; + min-height: 100dvh; + display: flex; + align-items: center; + justify-content: center; + padding: 0 40px 40px; +} + +.auth-column { + width: 520px; + max-width: 100%; + display: flex; + flex-direction: column; + gap: 10px; +} + +// The brand lockup. Lower case, and not by taste: capitalised, the dotted +// `i` becomes `I` and the name reads as the English word. The tittle is the +// Turkish one, in the word as it is in the mark. +.wordmark { + display: flex; + align-items: center; + justify-content: center; + gap: 10px; + text-decoration: none; + color: inherit; + padding: 6px 0; + + &:hover { color: inherit; } + + &-mark { + flex: none; + display: block; + width: 24px; + height: 24px; + } + + &-tittle { fill: var(--accent); } + + &-text { + font-family: var(--font-mono); + font-size: 18px; + font-weight: 500; + letter-spacing: 0.02em; + } +} + +.auth-card { + background: var(--surface); + border: 1px solid var(--border); + border-radius: var(--radius-lg); + padding: 28px; + display: flex; + flex-direction: column; + gap: 18px; + box-shadow: var(--shadow-2); + + form { + display: flex; + flex-direction: column; + gap: 20px; + } +} + +.auth-head { + display: flex; + flex-direction: column; + gap: 6px; +} + +.auth-title { + font-size: 18px; + font-weight: 600; + letter-spacing: -0.01em; +} + +.auth-sub { + font-size: 13px; + color: var(--muted); + line-height: 1.5; +} + +.auth-field { + display: flex; + flex-direction: column; + gap: 6px; +} + +.auth-label { + font-family: var(--font-mono); + font-size: 10px; + letter-spacing: 0.08em; + color: var(--muted-soft); +} + +// The address an invited member signs in as: shown, never edited. +.auth-locked { + display: flex; + align-items: center; + gap: 8px; + height: 40px; + padding: 0 12px; + background: var(--panel-sunken); + border: 1px solid var(--border-strong); + border-radius: var(--radius); +} + +.auth-locked-value { + font-family: var(--font-mono); + font-size: 13px; + color: var(--muted); + flex-grow: 1; +} + +.auth-input { + height: 40px; + padding: 0 12px; + background: var(--field-bg); + border: 1px solid var(--border-strong); + border-radius: var(--radius); + color: var(--ink); + font-family: var(--font-sans); + font-size: 13px; + width: 100%; + + &:focus { + outline: none; + border-color: var(--accent); + box-shadow: 0 0 0 2px var(--accent-tint); + } + + &:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 1px; + } + + &:user-invalid { + border-color: var(--danger); + } +} + +.auth-input-mono { + font-family: var(--font-mono); +} + +.auth-submit { + height: var(--control-h-lg); + display: flex; + align-items: center; + justify-content: center; + gap: 8px; + background: var(--accent); + color: var(--surface); + border: 0; + border-radius: var(--radius); + cursor: pointer; + font-family: var(--font-sans); + + &:disabled { + opacity: 0.45; + cursor: default; + } + + &:focus-visible { + outline: 2px solid var(--accent-ink); + outline-offset: 2px; + } +} + +.auth-submit-text { + font-size: 13px; + font-weight: 600; +} + +.auth-problem { + font-size: 13px; + color: var(--danger); + background: var(--danger-tint-alt); + border: 1px solid var(--danger-border-soft); + border-radius: var(--radius); + padding: 10px 12px; +} + +.auth-note { + font-size: 13px; + color: var(--muted); + background: var(--panel-sunken); + border: 1px solid var(--border-soft); + border-radius: var(--radius); + padding: 10px 12px; +} + +// The one thing that says "this worked": a confirmed TOTP enrolment, an +// issued invite. +.auth-ok { + font-size: 13px; + color: var(--positive); + background: var(--positive-tint); + border: 1px solid var(--positive-border); + border-radius: var(--radius); + padding: 10px 12px; +} + +// The manual TOTP key: monospace, selectable, broken into four-letter groups. +.auth-secret { + font-family: var(--font-mono); + font-size: 14px; + letter-spacing: 0.06em; + text-align: center; + background: var(--panel-sunken); + border: 1px solid var(--border-soft); + border-radius: var(--radius); + padding: 10px 12px; + user-select: all; +} + +// The enrolment QR, centered, with quiet ground so the modules stay scannable +// in either theme. +.auth-qr { + display: flex; + justify-content: center; + + svg { + width: 200px; + height: 200px; + background: #fff; + border: 1px solid var(--border); + border-radius: var(--radius); + padding: 12px; + } +} + +.auth-alt { + font-size: 12px; + color: var(--muted); + text-decoration: none; + align-self: center; + + &:hover { color: var(--accent-ink); } +} + +.auth-footer { + font-family: var(--font-mono); + font-size: 10px; + letter-spacing: 0.08em; + color: var(--muted-soft); + text-align: center; + padding-top: 4px; +} + +@media (max-width: 720px) { + .auth-stage { padding: 0 16px 24px; } +}