wip refactoring

This commit is contained in:
bain 2024-02-26 22:22:28 +01:00
parent cc56cbe0cf
commit dde44c88cc
Signed by: bain
GPG key ID: 31F0F25E3BED0B9B
3 changed files with 95 additions and 697 deletions

592
Cargo.lock generated
View file

@ -2,21 +2,6 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "addr2line"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]] [[package]]
name = "aead" name = "aead"
version = "0.3.2" version = "0.3.2"
@ -71,15 +56,6 @@ dependencies = [
"opaque-debug", "opaque-debug",
] ]
[[package]]
name = "aho-corasick"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "android-tzdata" name = "android-tzdata"
version = "0.1.1" version = "0.1.1"
@ -102,17 +78,12 @@ dependencies = [
"anyhow", "anyhow",
"async-std", "async-std",
"base64 0.21.7", "base64 0.21.7",
"chrono",
"handlebars",
"hex", "hex",
"lettre", "ring",
"ring 0.17.8",
"serde", "serde",
"serde_json", "serde_json",
"tide", "tide",
"toml", "toml",
"uuid",
"validator",
] ]
[[package]] [[package]]
@ -239,7 +210,7 @@ dependencies = [
"polling 2.8.0", "polling 2.8.0",
"rustix 0.37.27", "rustix 0.37.27",
"slab", "slab",
"socket2 0.4.10", "socket2",
"waker-fn", "waker-fn",
] ]
@ -317,7 +288,7 @@ dependencies = [
"rand 0.7.3", "rand 0.7.3",
"serde", "serde",
"serde_json", "serde_json",
"sha2 0.9.9", "sha2",
] ]
[[package]] [[package]]
@ -409,21 +380,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "backtrace"
version = "0.3.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837"
dependencies = [
"addr2line",
"cc",
"cfg-if 1.0.0",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]] [[package]]
name = "base-x" name = "base-x"
version = "0.2.11" version = "0.2.11"
@ -481,7 +437,7 @@ dependencies = [
"cfg-if 0.1.10", "cfg-if 0.1.10",
"constant_time_eq", "constant_time_eq",
"crypto-mac 0.8.0", "crypto-mac 0.8.0",
"digest 0.9.0", "digest",
] ]
[[package]] [[package]]
@ -493,15 +449,6 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
dependencies = [
"generic-array",
]
[[package]] [[package]]
name = "blocking" name = "blocking"
version = "1.5.1" version = "1.5.1"
@ -599,7 +546,7 @@ dependencies = [
"hmac 0.10.1", "hmac 0.10.1",
"percent-encoding", "percent-encoding",
"rand 0.8.5", "rand 0.8.5",
"sha2 0.9.9", "sha2",
"time", "time",
"version_check", "version_check",
] ]
@ -631,16 +578,6 @@ version = "0.8.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345"
[[package]]
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array",
"typenum",
]
[[package]] [[package]]
name = "crypto-mac" name = "crypto-mac"
version = "0.8.0" version = "0.8.0"
@ -679,38 +616,12 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[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",
"crypto-common",
]
[[package]] [[package]]
name = "discard" name = "discard"
version = "1.0.4" version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
[[package]]
name = "email-encoding"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbfb21b9878cf7a348dcb8559109aabc0ec40d69924bd706fa5149846c4fef75"
dependencies = [
"base64 0.21.7",
"memchr",
]
[[package]]
name = "email_address"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2153bd83ebc09db15bcbdc3e2194d901804952e3dc96967e1cd3b0c5c32d112"
[[package]] [[package]]
name = "equivalent" name = "equivalent"
version = "1.0.1" version = "1.0.1"
@ -895,16 +806,6 @@ dependencies = [
"syn 2.0.50", "syn 2.0.50",
] ]
[[package]]
name = "futures-rustls"
version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35bd3cf68c183738046838e300353e4716c674dc5e56890de4826801a6622a28"
dependencies = [
"futures-io",
"rustls",
]
[[package]] [[package]]
name = "futures-task" name = "futures-task"
version = "0.3.30" version = "0.3.30"
@ -918,10 +819,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"futures-io",
"futures-macro", "futures-macro",
"futures-task", "futures-task",
"memchr",
"pin-project-lite 0.2.13", "pin-project-lite 0.2.13",
"pin-utils", "pin-utils",
"slab", "slab",
@ -969,12 +868,6 @@ dependencies = [
"polyval", "polyval",
] ]
[[package]]
name = "gimli"
version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]] [[package]]
name = "gloo-timers" name = "gloo-timers"
version = "0.2.6" version = "0.2.6"
@ -987,20 +880,6 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "handlebars"
version = "5.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab283476b99e66691dee3f1640fea91487a8d81f50fb5ecc75538f8f8879a1e4"
dependencies = [
"log",
"pest",
"pest_derive",
"serde",
"serde_json",
"thiserror",
]
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.14.3" version = "0.14.3"
@ -1025,7 +904,7 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51ab2f639c231793c5f6114bdb9bbe50a7dbbfcd7c7c6bd8475dec2d991e964f" checksum = "51ab2f639c231793c5f6114bdb9bbe50a7dbbfcd7c7c6bd8475dec2d991e964f"
dependencies = [ dependencies = [
"digest 0.9.0", "digest",
"hmac 0.10.1", "hmac 0.10.1",
] ]
@ -1036,7 +915,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840" checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840"
dependencies = [ dependencies = [
"crypto-mac 0.8.0", "crypto-mac 0.8.0",
"digest 0.9.0", "digest",
] ]
[[package]] [[package]]
@ -1046,18 +925,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15" checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15"
dependencies = [ dependencies = [
"crypto-mac 0.10.0", "crypto-mac 0.10.0",
"digest 0.9.0", "digest",
]
[[package]]
name = "hostname"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867"
dependencies = [
"libc",
"match_cfg",
"winapi",
] ]
[[package]] [[package]]
@ -1100,12 +968,6 @@ version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904"
[[package]]
name = "httpdate"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
[[package]] [[package]]
name = "iana-time-zone" name = "iana-time-zone"
version = "0.1.60" version = "0.1.60"
@ -1129,27 +991,6 @@ dependencies = [
"cc", "cc",
] ]
[[package]]
name = "idna"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8"
dependencies = [
"matches",
"unicode-bidi",
"unicode-normalization",
]
[[package]]
name = "idna"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6"
dependencies = [
"unicode-bidi",
"unicode-normalization",
]
[[package]] [[package]]
name = "idna" name = "idna"
version = "0.5.0" version = "0.5.0"
@ -1160,12 +1001,6 @@ dependencies = [
"unicode-normalization", "unicode-normalization",
] ]
[[package]]
name = "if_chain"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb56e1aa765b4b4f3aadfab769793b7087bb03a4ea4920644a6d238e2df5b9ed"
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "2.2.3" version = "2.2.3"
@ -1226,41 +1061,6 @@ dependencies = [
"log", "log",
] ]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lettre"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76bd09637ae3ec7bd605b8e135e757980b3968430ff2b1a4a94fb7769e50166d"
dependencies = [
"async-std",
"async-trait",
"base64 0.21.7",
"email-encoding",
"email_address",
"fastrand 1.9.0",
"futures-io",
"futures-rustls",
"futures-util",
"hostname",
"httpdate",
"idna 0.3.0",
"mime",
"nom",
"once_cell",
"quoted_printable",
"rustls",
"rustls-pemfile",
"socket2 0.4.10",
"tokio",
"webpki-roots",
]
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.153" version = "0.2.153"
@ -1289,66 +1089,12 @@ dependencies = [
"value-bag", "value-bag",
] ]
[[package]]
name = "match_cfg"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4"
[[package]]
name = "matches"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5"
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.7.1" version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
[[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.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7"
dependencies = [
"adler",
]
[[package]]
name = "mio"
version = "0.8.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09"
dependencies = [
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys 0.48.0",
]
[[package]]
name = "nom"
version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
"memchr",
"minimal-lexical",
]
[[package]] [[package]]
name = "num-traits" name = "num-traits"
version = "0.2.18" version = "0.2.18"
@ -1358,15 +1104,6 @@ dependencies = [
"autocfg", "autocfg",
] ]
[[package]]
name = "object"
version = "0.32.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.19.0" version = "1.19.0"
@ -1391,51 +1128,6 @@ version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]]
name = "pest"
version = "2.7.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "219c0dcc30b6a27553f9cc242972b67f75b60eb0db71f0b5462f38b058c41546"
dependencies = [
"memchr",
"thiserror",
"ucd-trie",
]
[[package]]
name = "pest_derive"
version = "2.7.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22e1288dbd7786462961e69bfd4df7848c1e37e8b74303dbdab82c3a9cdd2809"
dependencies = [
"pest",
"pest_generator",
]
[[package]]
name = "pest_generator"
version = "2.7.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1381c29a877c6d34b8c176e734f35d7f7f5b3adaefe940cb4d1bb7af94678e2e"
dependencies = [
"pest",
"pest_meta",
"proc-macro2",
"quote",
"syn 2.0.50",
]
[[package]]
name = "pest_meta"
version = "2.7.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0934d6907f148c22a3acbda520c7eed243ad7487a30f51f6ce52b58b7077a8a"
dependencies = [
"once_cell",
"pest",
"sha2 0.10.8",
]
[[package]] [[package]]
name = "pin-project" name = "pin-project"
version = "1.1.4" version = "1.1.4"
@ -1532,30 +1224,6 @@ version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn 1.0.109",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]] [[package]]
name = "proc-macro-hack" name = "proc-macro-hack"
version = "0.5.20+deprecated" version = "0.5.20+deprecated"
@ -1580,12 +1248,6 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "quoted_printable"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3866219251662ec3b26fc217e3e05bf9c4f84325234dfb96bf0bf840889e49"
[[package]] [[package]]
name = "rand" name = "rand"
version = "0.7.3" version = "0.7.3"
@ -1657,50 +1319,6 @@ dependencies = [
"rand_core 0.5.1", "rand_core 0.5.1",
] ]
[[package]]
name = "regex"
version = "1.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]]
name = "ring"
version = "0.16.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc"
dependencies = [
"cc",
"libc",
"once_cell",
"spin 0.5.2",
"untrusted 0.7.1",
"web-sys",
"winapi",
]
[[package]] [[package]]
name = "ring" name = "ring"
version = "0.17.8" version = "0.17.8"
@ -1711,8 +1329,8 @@ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"getrandom 0.2.12", "getrandom 0.2.12",
"libc", "libc",
"spin 0.9.8", "spin",
"untrusted 0.9.0", "untrusted",
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
@ -1722,12 +1340,6 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56770675ebc04927ded3e60633437841581c285dc6236109ea25fbf3beb7b59e" checksum = "56770675ebc04927ded3e60633437841581c285dc6236109ea25fbf3beb7b59e"
[[package]]
name = "rustc-demangle"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
[[package]] [[package]]
name = "rustc_version" name = "rustc_version"
version = "0.2.3" version = "0.2.3"
@ -1764,63 +1376,12 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "rustls"
version = "0.21.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba"
dependencies = [
"log",
"ring 0.17.8",
"rustls-webpki 0.101.7",
"sct",
]
[[package]]
name = "rustls-pemfile"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c"
dependencies = [
"base64 0.21.7",
]
[[package]]
name = "rustls-webpki"
version = "0.100.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f6a5fc258f1c1276dfe3016516945546e2d5383911efc0fc4f1cdc5df3a4ae3"
dependencies = [
"ring 0.16.20",
"untrusted 0.7.1",
]
[[package]]
name = "rustls-webpki"
version = "0.101.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765"
dependencies = [
"ring 0.17.8",
"untrusted 0.9.0",
]
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.17" version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
[[package]]
name = "sct"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414"
dependencies = [
"ring 0.17.8",
"untrusted 0.9.0",
]
[[package]] [[package]]
name = "semver" name = "semver"
version = "0.9.0" version = "0.9.0"
@ -1929,24 +1490,13 @@ version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800"
dependencies = [ dependencies = [
"block-buffer 0.9.0", "block-buffer",
"cfg-if 1.0.0", "cfg-if 1.0.0",
"cpufeatures", "cpufeatures",
"digest 0.9.0", "digest",
"opaque-debug", "opaque-debug",
] ]
[[package]]
name = "sha2"
version = "0.10.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
dependencies = [
"cfg-if 1.0.0",
"cpufeatures",
"digest 0.10.7",
]
[[package]] [[package]]
name = "signal-hook-registry" name = "signal-hook-registry"
version = "1.4.1" version = "1.4.1"
@ -1975,22 +1525,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "socket2"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871"
dependencies = [
"libc",
"windows-sys 0.52.0",
]
[[package]]
name = "spin"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]] [[package]]
name = "spin" name = "spin"
version = "0.9.8" version = "0.9.8"
@ -2257,20 +1791,6 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.36.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931"
dependencies = [
"backtrace",
"libc",
"mio",
"pin-project-lite 0.2.13",
"socket2 0.5.6",
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "toml" name = "toml"
version = "0.7.8" version = "0.7.8"
@ -2327,12 +1847,6 @@ version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "ucd-trie"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9"
[[package]] [[package]]
name = "unicode-bidi" name = "unicode-bidi"
version = "0.3.15" version = "0.3.15"
@ -2364,12 +1878,6 @@ dependencies = [
"subtle", "subtle",
] ]
[[package]]
name = "untrusted"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
[[package]] [[package]]
name = "untrusted" name = "untrusted"
version = "0.9.0" version = "0.9.0"
@ -2383,76 +1891,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633"
dependencies = [ dependencies = [
"form_urlencoded", "form_urlencoded",
"idna 0.5.0", "idna",
"percent-encoding", "percent-encoding",
"serde", "serde",
] ]
[[package]]
name = "uuid"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a"
dependencies = [
"getrandom 0.2.12",
"rand 0.8.5",
"serde",
"uuid-macro-internal",
]
[[package]]
name = "uuid-macro-internal"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7abb14ae1a50dad63eaa768a458ef43d298cd1bd44951677bd10b732a9ba2a2d"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.50",
]
[[package]]
name = "validator"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f07b0a1390e01c0fc35ebb26b28ced33c9a3808f7f9fbe94d3cc01e233bfeed5"
dependencies = [
"idna 0.2.3",
"lazy_static",
"regex",
"serde",
"serde_derive",
"serde_json",
"url",
"validator_derive",
]
[[package]]
name = "validator_derive"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea7ed5e8cf2b6bdd64a6c4ce851da25388a89327b17b88424ceced6bd5017923"
dependencies = [
"if_chain",
"lazy_static",
"proc-macro-error",
"proc-macro2",
"quote",
"regex",
"syn 1.0.109",
"validator_types",
]
[[package]]
name = "validator_types"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2ddf34293296847abfc1493b15c6e2f5d3cd19f57ad7d22673bf4c6278da329"
dependencies = [
"proc-macro2",
"syn 1.0.109",
]
[[package]] [[package]]
name = "value-bag" name = "value-bag"
version = "1.7.0" version = "1.7.0"
@ -2591,15 +2034,6 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "webpki-roots"
version = "0.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b03058f88386e5ff5310d9111d53f48b17d732b401aeb83a8d5190f2ac459338"
dependencies = [
"rustls-webpki 0.100.3",
]
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.9" version = "0.3.9"

View file

@ -6,17 +6,12 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
tide = { version = "0.16.0", features = [] }
async-std = { version = "1.8.0", features = ["attributes"] } async-std = { version = "1.8.0", features = ["attributes"] }
tide = { version = "0.16.0", features = [] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
ring = { version = "0.17.8", features = ["std"] } ring = { version = "0.17.8", features = ["std"] }
anyhow = "1.0.70" anyhow = "1.0.70"
base64 = "0.21.0" base64 = "0.21.0"
uuid = { version = "1.3.0", features = ["v4", "fast-rng", "macro-diagnostics", "serde"] }
toml = "0.7.3" toml = "0.7.3"
validator = { version = "0.15", features = ["derive"] }
lettre = { version = "0.10.4", default-features = false, features = ["async-std1-rustls-tls", "builder", "hostname", "smtp-transport"] }
chrono = "0.4.24"
serde_json = "1.0"
hex = "0.4.3" hex = "0.4.3"
handlebars = "5.1.0"

View file

@ -4,6 +4,7 @@ use async_std::fs::File;
use async_std::sync::Mutex; use async_std::sync::Mutex;
use ring::rand::SecureRandom; use ring::rand::SecureRandom;
use ring::rand::SystemRandom; use ring::rand::SystemRandom;
use serde_json::Value;
use std::collections::HashMap; use std::collections::HashMap;
use std::collections::LinkedList; use std::collections::LinkedList;
use std::env; use std::env;
@ -16,43 +17,23 @@ use tide::prelude::json;
use tide::Request; use tide::Request;
use tide::Response; use tide::Response;
use toml::Table; use toml::Table;
use validator::ValidationErrors;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use async_std::io::ReadExt; use async_std::io::ReadExt;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use handlebars::Handlebars;
use std::error::Error; use std::error::Error;
use std::fmt; use std::fmt;
use base64::{engine::general_purpose as base64_coder, Engine as _}; use base64::{engine::general_purpose as base64_coder, Engine as _};
#[derive(Debug)] #[derive(Deserialize, Clone)]
pub struct ClientError { pub struct Client {
pub status_code: u16, pub name: String,
pub code: String, pub client_secret: String,
pub message: String, pub redirect_uris: Vec<String>,
} }
impl ClientError {
pub fn new(status_code: u16, code: &str, message: &str) -> Self {
Self {
status_code,
code: code.to_owned(),
message: message.to_owned(),
}
}
}
impl fmt::Display for ClientError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}: {} ({})", self.status_code, self.code, self.message)
}
}
impl Error for ClientError {}
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct Config { pub struct Config {
pub host: String, pub host: String,
@ -64,13 +45,6 @@ pub struct Config {
pub salt: String, pub salt: String,
} }
#[derive(Deserialize, Clone)]
pub struct Client {
pub name: String,
pub client_secret: String,
pub redirect_uris: Vec<String>,
}
impl Config { impl Config {
pub async fn from_file(file: &mut File) -> Result<Config> { pub async fn from_file(file: &mut File) -> Result<Config> {
let mut buf = String::new(); let mut buf = String::new();
@ -83,22 +57,6 @@ impl Config {
} }
async fn error_handler(mut res: tide::Response) -> tide::Result { async fn error_handler(mut res: tide::Response) -> tide::Result {
if let Some(err) = res.downcast_error::<ClientError>() {
let status = err.status_code;
res.set_body(json!({
"code": err.code,
"message": err.message,
}));
res.set_status(status);
}
if let Some(err) = res.downcast_error::<ValidationErrors>() {
res.set_body(json!({
"code": "validation_error",
"message": "Invalid input",
"errors": err
}));
res.set_status(422);
}
if let Some(err) = res.downcast_error::<OAuthError>() { if let Some(err) = res.downcast_error::<OAuthError>() {
res.set_body(tide::Body::from_json(err)?); res.set_body(tide::Body::from_json(err)?);
res.set_status(400); res.set_status(400);
@ -127,17 +85,15 @@ async fn authorize(req: Request<AppState>) -> tide::Result {
.get(&q.client_id) .get(&q.client_id)
.ok_or(OAuthError::new("invalid_client", "Unknown client"))?; .ok_or(OAuthError::new("invalid_client", "Unknown client"))?;
// return the login page
if q.uid.is_none() { if q.uid.is_none() {
#[derive(Serialize)]
struct Fill<'a> {
name: &'a str,
issuer_name: &'a str
}
return Ok(Response::builder(200) return Ok(Response::builder(200)
.body( .body(
req.state() // I could use a rendering library here, but its literally as simple as replacing
.handlebars // two strings.
.render("login-page", &Fill { name: &i.name, issuer_name: &req.state().issuer_name })?, include_str!("authorization.html")
.replace("{{name}}", &i.name)
.replace("{{issuer_name}}", &req.state().issuer_name),
) )
.header("Content-Type", "text/html") .header("Content-Type", "text/html")
.into()); .into());
@ -145,15 +101,11 @@ async fn authorize(req: Request<AppState>) -> tide::Result {
let uid = q.uid.unwrap(); let uid = q.uid.unwrap();
println!("Hello {},", uid);
// check redirect uri validity // check redirect uri validity
if i.redirect_uris.iter().all(|r| r.as_str() != q.redirect_uri) { if i.redirect_uris.iter().all(|r| r.as_str() != q.redirect_uri) {
return Err(ClientError::new(400, "bad_redirect", "invalid redirect uri").into()); return Err(OAuthError::new("invalid_redirect", "").into());
} }
println!("You logged into \"{}\"", i.name);
let random = SystemRandom::new(); let random = SystemRandom::new();
let mut salt = [0u8; 32]; let mut salt = [0u8; 32];
random.fill(&mut salt)?; random.fill(&mut salt)?;
@ -241,24 +193,17 @@ impl fmt::Display for OAuthError {
impl Error for OAuthError {} impl Error for OAuthError {}
fn create_id_token( fn create_id_token_claims(
app_state: &AppState, salt: &str,
issuer_uri: &str,
client_id: &str, client_id: &str,
uid: &str, uid: &str,
nonce: Option<String>, nonce: Option<String>,
) -> anyhow::Result<String> { ) -> anyhow::Result<Value> {
let header = base64_coder::URL_SAFE_NO_PAD.encode(
json!({
"alg": "RS256",
"typ": "JWT"
})
.to_string(),
);
let now = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs(); let now = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
use ring::hmac; use ring::hmac;
let mangler = hmac::Key::new(hmac::HMAC_SHA256, (app_state.salt.clone() + uid).as_bytes()); let mangler = hmac::Key::new(hmac::HMAC_SHA256, (salt.to_owned() + uid).as_bytes());
let mangle = |what: &str| { let mangle = |what: &str| {
let tag = hmac::sign(&mangler, (what.to_owned() + client_id).as_bytes()); let tag = hmac::sign(&mangler, (what.to_owned() + client_id).as_bytes());
@ -284,7 +229,7 @@ fn create_id_token(
// way to know who is who. // way to know who is who.
let mut body = json!({ let mut body = json!({
"kid": "master", "kid": "master",
"iss": app_state.issuer_uri, "iss": issuer_uri,
"sub": mangle("sub")[0..32], "sub": mangle("sub")[0..32],
"aud": client_id, "aud": client_id,
"exp": now+600, "exp": now+600,
@ -300,7 +245,33 @@ fn create_id_token(
body["nonce"] = nonce.into(); body["nonce"] = nonce.into();
} }
let claims = base64_coder::URL_SAFE_NO_PAD.encode(body.to_string()); Ok(body)
}
fn create_id_token(
app_state: &AppState,
client_id: &str,
uid: &str,
nonce: Option<String>,
) -> anyhow::Result<String> {
let header = base64_coder::URL_SAFE_NO_PAD.encode(
json!({
"alg": "RS256",
"typ": "JWT"
})
.to_string(),
);
let claims = base64_coder::URL_SAFE_NO_PAD.encode(
create_id_token_claims(
&app_state.salt,
&app_state.issuer_uri,
client_id,
uid,
nonce,
)?
.to_string(),
);
let message = format!("{}.{}", &header, &claims); let message = format!("{}.{}", &header, &claims);
@ -368,7 +339,8 @@ async fn authenticate(mut req: Request<AppState>) -> tide::Result {
// authorization code. It's always the client's fault, so we don't care really. // authorization code. It's always the client's fault, so we don't care really.
let code_info = { let code_info = {
let mut auths = req.state().authorizations.lock().await; let mut auths = req.state().authorizations.lock().await;
auths.auths auths
.auths
.remove(&body.code) .remove(&body.code)
.ok_or(OAuthError::new("invalid_grant", "code not valid")) .ok_or(OAuthError::new("invalid_grant", "code not valid"))
}?; }?;
@ -399,7 +371,6 @@ async fn authenticate(mut req: Request<AppState>) -> tide::Result {
// "plain", then I guess its fine // "plain", then I guess its fine
}; };
// Needs constant time equality checking since we might be comparing plain text. // Needs constant time equality checking since we might be comparing plain text.
// This is a non-issue when using the S265 method // This is a non-issue when using the S265 method
if ring::constant_time::verify_slices_are_equal( if ring::constant_time::verify_slices_are_equal(
@ -423,7 +394,8 @@ async fn authenticate(mut req: Request<AppState>) -> tide::Result {
async fn jwks(req: Request<AppState>) -> tide::Result { async fn jwks(req: Request<AppState>) -> tide::Result {
let pk: ring::rsa::PublicKeyComponents<Vec<u8>> = req.state().signing_key.public().into(); let pk: ring::rsa::PublicKeyComponents<Vec<u8>> = req.state().signing_key.public().into();
Ok(Response::builder(200).body(json!({ Ok(Response::builder(200)
.body(json!({
"keys": [{ "keys": [{
"kty": "RSA", "kty": "RSA",
"kid": "master", "kid": "master",
@ -431,12 +403,14 @@ async fn jwks(req: Request<AppState>) -> tide::Result {
"n": base64_coder::URL_SAFE_NO_PAD.encode(pk.n), "n": base64_coder::URL_SAFE_NO_PAD.encode(pk.n),
"e": base64_coder::URL_SAFE_NO_PAD.encode(pk.e), "e": base64_coder::URL_SAFE_NO_PAD.encode(pk.e),
}], }],
})).into()) }))
.into())
} }
async fn configuration_endpoint(req: Request<AppState>) -> tide::Result { async fn configuration_endpoint(req: Request<AppState>) -> tide::Result {
let uri = Url::parse(&req.state().issuer_uri)?; let uri = Url::parse(&req.state().issuer_uri)?;
Ok(Response::builder(200).body(json!({ Ok(Response::builder(200)
.body(json!({
"issuer": uri, "issuer": uri,
"authorization_endpoint": uri.join("/authorize")?, "authorization_endpoint": uri.join("/authorize")?,
"token_endpoint": uri.join("/token")?, "token_endpoint": uri.join("/token")?,
@ -444,7 +418,8 @@ async fn configuration_endpoint(req: Request<AppState>) -> tide::Result {
"response_types_supported": ["code", "id_token"], "response_types_supported": ["code", "id_token"],
"subject_types_supported": ["pairwise"], "subject_types_supported": ["pairwise"],
"id_token_signing_alg_values_supported": ["RS256"], "id_token_signing_alg_values_supported": ["RS256"],
})).into()) }))
.into())
} }
pub struct AuthStore { pub struct AuthStore {
@ -460,7 +435,6 @@ pub struct AppState {
pub issuer_name: String, pub issuer_name: String,
pub signing_key: Arc<ring::rsa::KeyPair>, pub signing_key: Arc<ring::rsa::KeyPair>,
pub salt: String, pub salt: String,
pub handlebars: Arc<Handlebars<'static>>,
} }
pub struct PKCE { pub struct PKCE {
@ -478,26 +452,19 @@ pub struct Authorization {
} }
#[async_std::main] #[async_std::main]
async fn main() -> tide::Result<()> { async fn main() -> anyhow::Result<()> {
log::start(); // log::start();
let mut conf_file = let mut conf_file =
File::open(env::var("CONFIG_FILE").unwrap_or("config.toml".to_owned())).await?; File::open(env::var("CONFIG_FILE").unwrap_or("config.toml".to_owned())).await?;
let config = Config::from_file(&mut conf_file).await?; let config = Config::from_file(&mut conf_file).await?;
let mut clients: HashMap<String, Client> = HashMap::new(); let mut clients: HashMap<String, Client> = HashMap::new();
for c in config.clients { for c in config.clients {
let client_id = c.0; clients.insert(c.0, c.1.try_into()?);
let info: Client = c.1.try_into()?;
clients.insert(client_id, info);
} }
let key_data = fs::read(config.rsa_key_file).await?; let key_data = fs::read(&config.rsa_key_file).await?;
let mut handlebars = Handlebars::new();
handlebars.register_template_string("login-page", include_str!("authorization.html"))?;
let mut app = tide::with_state(AppState { let mut app = tide::with_state(AppState {
clients: Arc::new(clients), clients: Arc::new(clients),
@ -508,8 +475,9 @@ async fn main() -> tide::Result<()> {
issuer_uri: config.issuer_uri, issuer_uri: config.issuer_uri,
issuer_name: config.issuer_name, issuer_name: config.issuer_name,
salt: config.salt, salt: config.salt,
signing_key: Arc::new(ring::rsa::KeyPair::from_pkcs8(&key_data)?), signing_key: Arc::new(
handlebars: Arc::new(handlebars), ring::rsa::KeyPair::from_pkcs8(&key_data)?,
),
}); });
app.with(tide::utils::After(error_handler)); app.with(tide::utils::After(error_handler));
@ -517,7 +485,8 @@ async fn main() -> tide::Result<()> {
app.at("/authorize").get(authorize); app.at("/authorize").get(authorize);
app.at("/token").post(authenticate); app.at("/token").post(authenticate);
app.at("/jwks").get(jwks); app.at("/jwks").get(jwks);
app.at("/.well-known/openid-configuration").get(configuration_endpoint); app.at("/.well-known/openid-configuration")
.get(configuration_endpoint);
app.listen(format!("{}:{}", config.host, config.port)) app.listen(format!("{}:{}", config.host, config.port))
.await?; .await?;