From 1bafa23e81c1991a2814ee7890853473f9d2d4be Mon Sep 17 00:00:00 2001 From: Avery Date: Thu, 1 May 2025 17:53:23 +0200 Subject: [PATCH] Logging for HitLock, implement IntoResponce for UserResponse, Use webfinger-rs crate for webfinger handling --- Cargo.lock | 647 +++++++++++++++++++++++++++++++++------ HitLock/Cargo.toml | 3 + HitLock/src/inbox.rs | 25 +- HitLock/src/main.rs | 72 ++++- HitLock/src/users.rs | 67 ++-- HitLock/src/webfinger.rs | 52 +--- 6 files changed, 696 insertions(+), 170 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b44dfc6..1543788 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "0.6.18" @@ -76,6 +91,26 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "async-convert" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d416feee97712e43152cd42874de162b8f9b77295b1c85e5d92725cc8310bae" +dependencies = [ + "async-trait", +] + +[[package]] +name = "async-trait" +version = "0.1.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "autocfg" version = "1.4.0" @@ -136,6 +171,31 @@ dependencies = [ "tracing", ] +[[package]] +name = "axum-extra" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45bf463831f5131b7d3c756525b305d40f1185b688565648a92e1392ca35713d" +dependencies = [ + "axum", + "axum-core", + "bytes", + "form_urlencoded", + "futures-util", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "serde", + "serde_html_form", + "serde_path_to_error", + "tower", + "tower-layer", + "tower-service", +] + [[package]] name = "backtrace" version = "0.3.74" @@ -179,10 +239,10 @@ dependencies = [ ] [[package]] -name = "byteorder" -version = "1.5.0" +name = "bumpalo" +version = "3.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" [[package]] name = "bytes" @@ -205,6 +265,19 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "serde", + "windows-link", +] + [[package]] name = "colorchoice" version = "1.0.3" @@ -217,6 +290,21 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + +[[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" @@ -245,6 +333,41 @@ dependencies = [ "typenum", ] +[[package]] +name = "darling" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "der" version = "0.7.10" @@ -256,6 +379,16 @@ dependencies = [ "zeroize", ] +[[package]] +name = "deranged" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" +dependencies = [ + "powerfmt", + "serde", +] + [[package]] name = "digest" version = "0.10.7" @@ -263,10 +396,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", ] +[[package]] +name = "document-features" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95249b50c6c185bee49034bcb378a49dc2b5dff0be90ff6616d31d64febab05d" +dependencies = [ + "litrs", +] + [[package]] name = "env_filter" version = "0.1.3" @@ -290,6 +431,12 @@ dependencies = [ "log", ] +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + [[package]] name = "flate2" version = "1.1.1" @@ -390,6 +537,24 @@ version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "http" version = "1.3.1" @@ -471,6 +636,58 @@ dependencies = [ "tower-service", ] +[[package]] +name = "iana-time-zone" +version = "0.1.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +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 = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + +[[package]] +name = "indexmap" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" +dependencies = [ + "equivalent", + "hashbrown 0.15.3", + "serde", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.1" @@ -508,12 +725,34 @@ dependencies = [ ] [[package]] -name = "lazy_static" -version = "1.5.0" +name = "js-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "kinded" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +checksum = "ce4bdbb2f423660b19f0e9f7115182214732d8dd5f840cd0a3aee3e22562f34c" dependencies = [ - "spin", + "kinded_macros", +] + +[[package]] +name = "kinded_macros" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a13b4ddc5dcb32f45dac3d6f606da2a52fdb9964a18427e63cd5ef6c0d13288d" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -523,10 +762,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" [[package]] -name = "libm" -version = "0.2.13" +name = "litrs" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9627da5196e5d8ed0b0495e61e518847578da83483c37288316d9b2e03a7f72" +checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5" [[package]] name = "lock_api" @@ -587,11 +826,12 @@ name = "noteposter" version = "0.1.0" dependencies = [ "base64", + "env_logger", "httpdate", + "log", "openssl", "pkcs8", "rand", - "rsa", "serde", "serde_json", "sha2", @@ -599,50 +839,42 @@ dependencies = [ ] [[package]] -name = "num-bigint-dig" -version = "0.8.4" +name = "num-conv" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" -dependencies = [ - "byteorder", - "lazy_static", - "libm", - "num-integer", - "num-iter", - "num-traits", - "rand", - "smallvec", - "zeroize", -] +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" [[package]] -name = "num-integer" -version = "0.1.46" +name = "num-traits" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ - "num-traits", + "autocfg", ] [[package]] -name = "num-iter" -version = "0.1.45" +name = "nutype" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +checksum = "3340cb6773b0794ecb3f62ff66631d580f57151d9415c10ee8a27a357aeb998b" dependencies = [ - "autocfg", - "num-integer", - "num-traits", + "nutype_macros", ] [[package]] -name = "num-traits" -version = "0.2.19" +name = "nutype_macros" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +checksum = "35c955e27d02868fe90b9c2dc901661fd7ed67ec382782bdc67c6aa8d2e957a9" dependencies = [ - "autocfg", - "libm", + "cfg-if", + "kinded", + "proc-macro2", + "quote", + "rustc_version", + "syn", + "urlencoding", ] [[package]] @@ -748,17 +980,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[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" @@ -790,6 +1011,12 @@ dependencies = [ "portable-atomic", ] +[[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" @@ -899,27 +1126,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "rsa" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78928ac1ed176a5ca1d17e578a1825f3d81ca54cf41053a592584b020cfd691b" -dependencies = [ - "const-oid", - "digest", - "num-bigint-dig", - "num-integer", - "num-traits", - "pkcs1", - "pkcs8", - "rand_core", - "sha2", - "signature", - "spki", - "subtle", - "zeroize", -] - [[package]] name = "rust_fedi" version = "0.1.0" @@ -930,6 +1136,9 @@ dependencies = [ "serde", "serde_json", "tokio", + "tower-layer", + "tower-service", + "webfinger-rs", ] [[package]] @@ -938,6 +1147,15 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + [[package]] name = "rustls" version = "0.23.26" @@ -997,6 +1215,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "semver" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" + [[package]] name = "serde" version = "1.0.219" @@ -1017,6 +1241,19 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_html_form" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d2de91cf02bbc07cde38891769ccd5d4f073d22a40683aa4bc7a95781aaa2c4" +dependencies = [ + "form_urlencoded", + "indexmap 2.9.0", + "itoa", + "ryu", + "serde", +] + [[package]] name = "serde_json" version = "1.0.140" @@ -1051,6 +1288,36 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_with" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6b6f7f2fcb69f747921f79f3926bd1e203fce4fef62c268dd3abfb6d86029aa" +dependencies = [ + "base64", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.9.0", + "serde", + "serde_derive", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d00caa5193a3c8362ac2b73be6b9e768aa5a4b2f721d8f4b339600c3cb51f8e" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "sha2" version = "0.10.9" @@ -1077,16 +1344,6 @@ dependencies = [ "libc", ] -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - [[package]] name = "smallvec" version = "1.14.0" @@ -1103,12 +1360,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" - [[package]] name = "spki" version = "0.7.3" @@ -1119,6 +1370,12 @@ dependencies = [ "der", ] +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "subtle" version = "2.6.1" @@ -1142,6 +1399,57 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +[[package]] +name = "thiserror" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "time" +version = "0.3.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" + +[[package]] +name = "time-macros" +version = "0.2.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tokio" version = "1.44.2" @@ -1207,9 +1515,21 @@ checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" dependencies = [ "log", "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tracing-core" version = "0.1.33" @@ -1231,6 +1551,12 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" + [[package]] name = "untrusted" version = "0.9.0" @@ -1267,6 +1593,12 @@ dependencies = [ "log", ] +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + [[package]] name = "utf-8" version = "0.7.6" @@ -1297,6 +1629,84 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "webfinger-rs" +version = "0.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6f7d55f92d53d3a5211d7a0a594acf1acc763618b56b88ea01e7bc2fe791343" +dependencies = [ + "async-convert", + "axum", + "axum-extra", + "document-features", + "http", + "nutype", + "percent-encoding", + "serde", + "serde_json", + "serde_with", + "thiserror", + "tracing", +] + [[package]] name = "webpki-roots" version = "0.26.10" @@ -1306,6 +1716,65 @@ dependencies = [ "rustls-pki-types", ] +[[package]] +name = "windows-core" +version = "0.61.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" + +[[package]] +name = "windows-result" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2ba9642430ee452d5a7aa78d72907ebe8cfda358e8cb7918a2050581322f97" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-sys" version = "0.52.0" diff --git a/HitLock/Cargo.toml b/HitLock/Cargo.toml index dbc9e47..edede64 100644 --- a/HitLock/Cargo.toml +++ b/HitLock/Cargo.toml @@ -6,6 +6,9 @@ edition = "2024" [dependencies] tokio = { version = "1.44.2", features = ["full"] } axum = "0.8.3" +tower-layer = "0.3.3" +tower-service = "0.3.3" +webfinger-rs = { version = "0.0.13", features = ["axum"] } serde = { workspace = true } serde_json = { workspace = true } diff --git a/HitLock/src/inbox.rs b/HitLock/src/inbox.rs index 546591d..2b2abca 100644 --- a/HitLock/src/inbox.rs +++ b/HitLock/src/inbox.rs @@ -1,19 +1,28 @@ use axum::body::Bytes; +use axum::extract::Path; use axum::http::HeaderMap; +use log::{debug, info}; use std::fs::File; use std::io::Write; -pub async fn inbox_post(headers: HeaderMap, bytes: Bytes) { - println!("Headers: {:#?}", headers); - let _ = File::create("./last.json").map(|mut res| { - res.write_all(&bytes).expect("Failed writing"); - println!("Writing file"); - }); +use crate::sanitize_printable; + +pub async fn inbox_post(Path(user): Path, headers: HeaderMap, bytes: Bytes) { + info!("Got post to inbox of user: {:?}", user); + debug!("With headers: {:#?}", headers); + File::create("./last.json") + .map(|mut res| { + res.write_all(&bytes).expect("Failed writing"); + println!("Writing file"); + }) + .expect("Failed to create file"); + let json = String::from_utf8(Vec::from(bytes)).expect("Invalid UTF-8"); let json: serde_json::Value = serde_json::from_str(&json).expect("Invalid JSON"); + match serde_json::to_string_pretty(&json) { - Ok(pretty_json) => println!("Received JSON:\n{}\n\n", pretty_json), - Err(err) => println!("Failed to format JSON: {}\n\n", err), + Ok(pretty_json) => info!("Received JSON:\n{}\n\n", sanitize_printable(&pretty_json)), + Err(err) => info!("Failed to format JSON: {}\n\n", err), } } diff --git a/HitLock/src/main.rs b/HitLock/src/main.rs index 7280435..2d8580b 100644 --- a/HitLock/src/main.rs +++ b/HitLock/src/main.rs @@ -2,31 +2,43 @@ mod inbox; mod users; mod webfinger; +use std::{ + fmt, + iter::once, + task::{Context, Poll}, +}; + use axum::{ Router, http::{StatusCode, Uri}, routing::{get, post}, }; use inbox::inbox_post; +use log::{info, trace}; +use tower_layer::Layer; +use tower_service::Service; use users::users_get; use webfinger::webfinger_get; const HOST: &'static str = "testing4host.com"; const USER: &'static str = "test71"; -async fn fallback(uri: Uri) -> (StatusCode, String) { - println!("Unknown url! {}", uri); - (StatusCode::NOT_FOUND, format!("No route for {uri}")) +fn init_logger() { + env_logger::builder() + .filter_level(log::LevelFilter::Info) + .parse_default_env() + .init() } #[tokio::main] async fn main() { - env_logger::init(); + init_logger(); let app = Router::new() .route("/", get(root)) .route("/.well-known/webfinger", get(webfinger_get)) .route("/users/{users}/", get(users_get)) + .route("/users/{users}", get(users_get)) .route("/inbox/{users}/", post(inbox_post)) .fallback(fallback); @@ -37,3 +49,55 @@ async fn main() { async fn root() -> &'static str { "Hello World!" } + +#[derive(Clone)] +pub struct TraceLayer; + +async fn fallback(uri: Uri) -> (StatusCode, String) { + info!("Unknown url! {}", uri); + (StatusCode::NOT_FOUND, format!("No route for {uri}")) +} + +impl Layer for TraceLayer { + type Service = TraceService; + + fn layer(&self, service: S) -> Self::Service { + TraceService { service } + } +} + +#[derive(Clone)] +pub struct TraceService { + service: S, +} + +impl Service for TraceService +where + S: Service, + Request: fmt::Debug, +{ + type Response = S::Response; + type Error = S::Error; + type Future = S::Future; + + fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { + self.service.poll_ready(cx) + } + + fn call(&mut self, request: Request) -> Self::Future { + trace!("request = {:?}", request); + self.service.call(request) + } +} + +fn sanitize_printable(src: &str) -> String { + src.chars() + .flat_map(|c| -> Box> { + if c.is_control() && !c.is_whitespace() { + Box::new(c.escape_unicode()) + } else { + Box::new(once(c)) + } + }) + .collect() +} diff --git a/HitLock/src/users.rs b/HitLock/src/users.rs index 40ce115..222364a 100644 --- a/HitLock/src/users.rs +++ b/HitLock/src/users.rs @@ -1,4 +1,8 @@ -use axum::{extract::Path, response::Response}; +use axum::{ + extract::Path, + response::{IntoResponse, Response}, +}; +use log::info; use serde::Serialize; use crate::USER; @@ -34,36 +38,39 @@ pub struct UsersResponse { public_key: UsersPublicKey, } -pub async fn users_get(Path(user): Path) -> Response { - println!("users: {}", user); +pub async fn users_get(Path(user): Path) -> UsersResponse { + info!("Got request for user: {:?}", user); assert_eq!(user, USER); - Response::builder() - .header("content-type", "application/activity+json; charset=utf-8") - .body( - serde_json::to_string(&UsersResponse { - context: vec!["https://www.w3.org/ns/activitystreams".to_string(), "https://w3id.org/security/v1".to_string()], - r#type: "Person".to_string(), - name: "Testing Slasher".to_string(), - id: "https://testing4host.com/users/test71/".to_string(), - inbox: "https://testing4host.com/inbox/test71/".to_string(), - outbox: "https://testing4host.com/outbox/test71/".to_string(), - followers: "https://testing4host.com/followers/test71/".to_string(), - following: "https://testing4host.com/following/test71/".to_string(), - summary: "Hi!".to_string(), - url: "https://testing4host.com/@test71/".to_string(), - published: "2024-07-13T00:00:00Z".to_string(), - tag: vec![], - attachment: vec![], - icon: "https://testing4host.com/avatar/test71".to_string(), - preferred_username: "test71".to_string(), - public_key: UsersPublicKey { - id: "https://testing4host.com/users/test71/#main-key".to_string(), - owner: "https://testing4host.com/users/test71/".to_string(), - public_key_pem: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuqubzHLVItM9522mUYSd\nFkpPs0GQalcXVKBFgBCz611fpRzKS5xSGQ8BUVSn/uGkYnOxnh1j41Nk59VUQqCe\nj6d2PUnASbQHc7hcUAPwsgXxZ2LR0z5YTflNIpymd5q3hMqv7NVf05LQnm1t+bbv\nIhiH382J70Ob5FYcae4Shtp5xeBA8IzD9Wo2DwNjH3oP83fybHIEOSofccXB+DI+\np6DZPg2E2/DPpXqVMTmwurlIYX/9jYKYALE9LwX0jY/60lRYkzag9Gr57nlEZH2g\nOOZiy2JmTSvwSWc2LfQyU789w/+b5x9E+lJl1uA4g5HN9F+nEadLRjeMIKyWFdq7\nywIDAQAB\n-----END PUBLIC KEY-----\n".to_string() } - }) + UsersResponse { + context: vec!["https://www.w3.org/ns/activitystreams".to_string(), "https://w3id.org/security/v1".to_string()], + r#type: "Person".to_string(), + name: "Testing Slasher".to_string(), + id: "https://testing4host.com/users/test71/".to_string(), + inbox: "https://testing4host.com/inbox/test71/".to_string(), + outbox: "https://testing4host.com/outbox/test71/".to_string(), + followers: "https://testing4host.com/followers/test71/".to_string(), + following: "https://testing4host.com/following/test71/".to_string(), + summary: "Hi!".to_string(), + url: "https://testing4host.com/@test71/".to_string(), + published: "2024-07-13T00:00:00Z".to_string(), + tag: vec![], + attachment: vec![], + icon: "https://testing4host.com/avatar/test71".to_string(), + preferred_username: "test71".to_string(), + public_key: UsersPublicKey { + id: "https://testing4host.com/users/test71/#main-key".to_string(), + owner: "https://testing4host.com/users/test71/".to_string(), + public_key_pem: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuqubzHLVItM9522mUYSd\nFkpPs0GQalcXVKBFgBCz611fpRzKS5xSGQ8BUVSn/uGkYnOxnh1j41Nk59VUQqCe\nj6d2PUnASbQHc7hcUAPwsgXxZ2LR0z5YTflNIpymd5q3hMqv7NVf05LQnm1t+bbv\nIhiH382J70Ob5FYcae4Shtp5xeBA8IzD9Wo2DwNjH3oP83fybHIEOSofccXB+DI+\np6DZPg2E2/DPpXqVMTmwurlIYX/9jYKYALE9LwX0jY/60lRYkzag9Gr57nlEZH2g\nOOZiy2JmTSvwSWc2LfQyU789w/+b5x9E+lJl1uA4g5HN9F+nEadLRjeMIKyWFdq7\nywIDAQAB\n-----END PUBLIC KEY-----\n".to_string() + } + } +} + +impl IntoResponse for UsersResponse { + fn into_response(self) -> Response { + Response::builder() + .header("content-type", "application/activity+json; charset=utf-8") + .body(serde_json::to_string(&self).unwrap().into()) .unwrap() - .into(), - ) - .unwrap() + } } diff --git a/HitLock/src/webfinger.rs b/HitLock/src/webfinger.rs index 99962c5..332fe06 100644 --- a/HitLock/src/webfinger.rs +++ b/HitLock/src/webfinger.rs @@ -1,30 +1,11 @@ -use axum::extract::Query; -use axum::response::Response; -use serde::{Deserialize, Serialize}; +use log::debug; +use webfinger_rs::{Link, Rel, WebFingerRequest, WebFingerResponse}; use crate::{HOST, USER}; -#[derive(Deserialize)] -pub struct WebfingerQuery { - resource: String, -} - -#[derive(Serialize)] -pub struct WebfingerResponse { - subject: String, - alias: Vec, - links: Vec, -} - -#[derive(Serialize)] -pub struct WebfigerLink { - rel: String, - r#type: String, - href: String, -} - -pub async fn webfinger_get(Query(WebfingerQuery { resource }): Query) -> Response { - println!("webfinger: {}", resource); +pub async fn webfinger_get(request: WebFingerRequest) -> WebFingerResponse { + let resource = request.resource.to_string(); + debug!("Got webfinger request for resource: {resource}"); let Some((typ, val)) = resource.split_once(':') else { panic!() }; @@ -34,20 +15,13 @@ pub async fn webfinger_get(Query(WebfingerQuery { resource }): Query