From 0fc16e787097c9d99be5aa7ac43443c516ca1951 Mon Sep 17 00:00:00 2001 From: Avery Date: Thu, 1 May 2025 12:34:11 +0200 Subject: [PATCH 1/3] Create workspace and move NotePoster and HitLock into workspace Workspace can share dependency versions and features between crates, this way we make sure that shared dependencies stay in sync. Currently serde, logging, and crypto are shared. --- .gitmodules | 3 - Cargo.lock | 236 ++++++++- Cargo.toml | 21 +- HitLock/Cargo.toml | 14 + {src => HitLock/src}/inbox.rs | 7 +- {src => HitLock/src}/main.rs | 3 - {src => HitLock/src}/users.rs | 0 {src => HitLock/src}/webfinger.rs | 0 NotePoster | 1 - NotePoster/Cargo.lock | 814 ++++++++++++++++++++++++++++++ NotePoster/Cargo.toml | 20 + NotePoster/src/main.rs | 86 ++++ NotePoster/src/note.json | 31 ++ NotePoster/src/private.pem | 28 + NotePoster/src/public.pem | 9 + flake.lock | 61 +++ flake.nix | 26 + 17 files changed, 1336 insertions(+), 24 deletions(-) create mode 100644 HitLock/Cargo.toml rename {src => HitLock/src}/inbox.rs (81%) rename {src => HitLock/src}/main.rs (92%) rename {src => HitLock/src}/users.rs (100%) rename {src => HitLock/src}/webfinger.rs (100%) delete mode 160000 NotePoster create mode 100644 NotePoster/Cargo.lock create mode 100644 NotePoster/Cargo.toml create mode 100644 NotePoster/src/main.rs create mode 100644 NotePoster/src/note.json create mode 100644 NotePoster/src/private.pem create mode 100644 NotePoster/src/public.pem create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitmodules b/.gitmodules index 078a0de..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "NotePoster"] - path = NotePoster - url = https://gitea.itycodes.org/itycodes/NotePoster diff --git a/Cargo.lock b/Cargo.lock index 2ae98e0..b44dfc6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -151,6 +151,12 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "base64ct" version = "1.7.3" @@ -184,6 +190,15 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" +[[package]] +name = "cc" +version = "1.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04da6a0d40b948dfc4fa8f5bbf402b0fc1a64a28dbf7d12ffd683550f2c1b63a" +dependencies = [ + "shlex", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -211,6 +226,15 @@ dependencies = [ "libc", ] +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -266,12 +290,37 @@ dependencies = [ "log", ] +[[package]] +name = "flate2" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -533,6 +582,22 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "noteposter" +version = "0.1.0" +dependencies = [ + "base64", + "httpdate", + "openssl", + "pkcs8", + "rand", + "rsa", + "serde", + "serde_json", + "sha2", + "ureq", +] + [[package]] name = "num-bigint-dig" version = "0.8.4" @@ -595,6 +660,44 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +[[package]] +name = "openssl" +version = "0.10.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fedfea7d58a1f73118430a55da6a286e7b044961736ce96a16a17068ea25e5da" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-sys" +version = "0.9.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e145e1651e858e820e4860f7b9c5e169bc1d8ce1c86043be79fa7b7634821847" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "parking_lot" version = "0.12.3" @@ -666,6 +769,12 @@ dependencies = [ "spki", ] +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + [[package]] name = "portable-atomic" version = "1.11.0" @@ -714,6 +823,7 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ + "libc", "rand_chacha", "rand_core", ] @@ -775,6 +885,20 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "rsa" version = "0.9.8" @@ -789,6 +913,7 @@ dependencies = [ "pkcs1", "pkcs8", "rand_core", + "sha2", "signature", "spki", "subtle", @@ -801,10 +926,9 @@ version = "0.1.0" dependencies = [ "axum", "env_logger", - "rsa", + "log", "serde", "serde_json", - "sha2", "tokio", ] @@ -814,6 +938,47 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustls" +version = "0.23.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df51b5869f3a441595eac5e8ff14d486ff285f7b8c0df8770e49c3b56351f0f0" +dependencies = [ + "log", + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c" + +[[package]] +name = "rustls-webpki" +version = "0.103.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fef8b8769aaccf73098557a87cd1816b4f9c7c16811c9c77142aa695c16f2c03" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.20" @@ -888,15 +1053,21 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.8" +version = "0.10.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", "cpufeatures", "digest", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signal-hook-registry" version = "1.4.5" @@ -1060,12 +1231,60 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "ureq" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7a3e9af6113ecd57b8c63d3cd76a385b2e3881365f1f489e54f49801d0c83ea" +dependencies = [ + "base64", + "flate2", + "log", + "percent-encoding", + "rustls", + "rustls-pemfile", + "rustls-pki-types", + "ureq-proto", + "utf-8", + "webpki-roots", +] + +[[package]] +name = "ureq-proto" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadf18427d33828c311234884b7ba2afb57143e6e7e69fda7ee883b624661e36" +dependencies = [ + "base64", + "http", + "httparse", + "log", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + [[package]] name = "utf8parse" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.5" @@ -1078,6 +1297,15 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "webpki-roots" +version = "0.26.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37493cadf42a2a939ed404698ded7fb378bf301b5011f973361779a3a74f8c93" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-sys" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index 41db2c0..c994d1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,16 @@ -[package] -name = "rust_fedi" -version = "0.1.0" -edition = "2024" +[workspace] +members = ["HitLock", "NotePoster"] +resolver = "2" -[dependencies] -axum = "0.8.3" +[workspace.dependencies] env_logger = "0.11.8" -rsa = "0.9.8" +log = "0.4.27" + +rand = "0.8" +base64 = "0.22.1" +openssl = "0.10.72" +pkcs8 = { version = "0.10.2", features = ["pem"] } +sha2 = "0.10.9" + serde = { version = "1.0.219", features = ["derive"] } serde_json = "1.0.140" -sha2 = "0.10.8" -tokio = { version = "1.44.2", features = ["full"] } diff --git a/HitLock/Cargo.toml b/HitLock/Cargo.toml new file mode 100644 index 0000000..dbc9e47 --- /dev/null +++ b/HitLock/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "rust_fedi" +version = "0.1.0" +edition = "2024" + +[dependencies] +tokio = { version = "1.44.2", features = ["full"] } +axum = "0.8.3" + +serde = { workspace = true } +serde_json = { workspace = true } + +env_logger = { workspace = true } +log = { workspace = true } diff --git a/src/inbox.rs b/HitLock/src/inbox.rs similarity index 81% rename from src/inbox.rs rename to HitLock/src/inbox.rs index 4662f1b..546591d 100644 --- a/src/inbox.rs +++ b/HitLock/src/inbox.rs @@ -1,7 +1,6 @@ -use axum::http::HeaderMap; use axum::body::Bytes; +use axum::http::HeaderMap; -use core::slice::SlicePattern; use std::fs::File; use std::io::Write; @@ -11,8 +10,8 @@ pub async fn inbox_post(headers: HeaderMap, bytes: Bytes) { res.write_all(&bytes).expect("Failed writing"); println!("Writing file"); }); - let json = String::from_utf8(Vec::from(bytes.as_slice())).expect("Invalid UTF-8"); - let json: serde_json::Value = serde_json::from_str(&json).expect("Invalid JSON"); + 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), diff --git a/src/main.rs b/HitLock/src/main.rs similarity index 92% rename from src/main.rs rename to HitLock/src/main.rs index 779c72c..7280435 100644 --- a/src/main.rs +++ b/HitLock/src/main.rs @@ -1,5 +1,3 @@ -#![feature(slice_pattern)] - mod inbox; mod users; mod webfinger; @@ -29,7 +27,6 @@ async fn main() { .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); diff --git a/src/users.rs b/HitLock/src/users.rs similarity index 100% rename from src/users.rs rename to HitLock/src/users.rs diff --git a/src/webfinger.rs b/HitLock/src/webfinger.rs similarity index 100% rename from src/webfinger.rs rename to HitLock/src/webfinger.rs diff --git a/NotePoster b/NotePoster deleted file mode 160000 index d594dbc..0000000 --- a/NotePoster +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d594dbc68635e746361a8ef0a0d0583d800c0506 diff --git a/NotePoster/Cargo.lock b/NotePoster/Cargo.lock new file mode 100644 index 0000000..0cfb295 --- /dev/null +++ b/NotePoster/Cargo.lock @@ -0,0 +1,814 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "base64ct" +version = "1.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89e25b6adfb930f02d1981565a6e5d9c547ac15a96606256d3b59040e5cd4ca3" + +[[package]] +name = "bitflags" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" + +[[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 = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" + +[[package]] +name = "cc" +version = "1.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04da6a0d40b948dfc4fa8f5bbf402b0fc1a64a28dbf7d12ffd683550f2c1b63a" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[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]] +name = "der" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", +] + +[[package]] +name = "flate2" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[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.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "http" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[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 = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[package]] +name = "libc" +version = "0.2.172" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" + +[[package]] +name = "libm" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9627da5196e5d8ed0b0495e61e518847578da83483c37288316d9b2e03a7f72" + +[[package]] +name = "log" +version = "0.4.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a" +dependencies = [ + "adler2", +] + +[[package]] +name = "noteposter" +version = "0.1.0" +dependencies = [ + "base64", + "httpdate", + "openssl", + "pkcs8", + "rand", + "rsa", + "serde", + "serde_json", + "sha2", + "ureq", +] + +[[package]] +name = "num-bigint-dig" +version = "0.8.4" +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", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "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.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "openssl" +version = "0.10.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fedfea7d58a1f73118430a55da6a286e7b044961736ce96a16a17068ea25e5da" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-sys" +version = "0.9.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e145e1651e858e820e4860f7b9c5e169bc1d8ce1c86043be79fa7b7634821847" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[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.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[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", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "untrusted", + "windows-sys", +] + +[[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 = "rustls" +version = "0.23.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df51b5869f3a441595eac5e8ff14d486ff285f7b8c0df8770e49c3b56351f0f0" +dependencies = [ + "log", + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c" + +[[package]] +name = "rustls-webpki" +version = "0.103.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fef8b8769aaccf73098557a87cd1816b4f9c7c16811c9c77142aa695c16f2c03" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "serde" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[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.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" + +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "typenum" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "ureq" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7a3e9af6113ecd57b8c63d3cd76a385b2e3881365f1f489e54f49801d0c83ea" +dependencies = [ + "base64", + "flate2", + "log", + "percent-encoding", + "rustls", + "rustls-pemfile", + "rustls-pki-types", + "ureq-proto", + "utf-8", + "webpki-roots", +] + +[[package]] +name = "ureq-proto" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadf18427d33828c311234884b7ba2afb57143e6e7e69fda7ee883b624661e36" +dependencies = [ + "base64", + "http", + "httparse", + "log", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "webpki-roots" +version = "0.26.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37493cadf42a2a939ed404698ded7fb378bf301b5011f973361779a3a74f8c93" +dependencies = [ + "rustls-pki-types", +] + +[[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-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 = "zerocopy" +version = "0.8.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/NotePoster/Cargo.toml b/NotePoster/Cargo.toml new file mode 100644 index 0000000..f0f9e7d --- /dev/null +++ b/NotePoster/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "noteposter" +version = "0.1.0" +edition = "2024" + +[dependencies] +ureq = "3.0.11" +httpdate = "1.0.3" + +rand = { workspace = true } +base64 = { workspace = true } +openssl = { workspace = true } +pkcs8 = { workspace = true } +sha2 = { workspace = true } + +serde = { workspace = true } +serde_json = { workspace = true } + +env_logger = { workspace = true } +log = { workspace = true } diff --git a/NotePoster/src/main.rs b/NotePoster/src/main.rs new file mode 100644 index 0000000..e249e46 --- /dev/null +++ b/NotePoster/src/main.rs @@ -0,0 +1,86 @@ +use base64::prelude::*; +use httpdate::fmt_http_date; +use openssl::hash::MessageDigest; +use openssl::pkey::PKey; +use openssl::sign::Signer; +use serde::{Deserialize, Serialize}; +use sha2::Digest; +use std::time::SystemTime; + +#[derive(Serialize, Deserialize)] +struct CreateActivity { + street: String, + city: String, +} + +fn sha256sum(bytes: &[u8]) -> String { + let mut hasher = sha2::Sha256::new(); + + hasher.update(bytes); + + return BASE64_STANDARD.encode(hasher.finalize()); +} + +fn main() { + let host = "estradiol.city"; + let path = "/users/ity/inbox"; + + let url = format!("https://{}{}", host, path); + + let key_id = "https://testing4host.com/users/test71/#main-key"; + + let json = include_bytes!("note.json"); + + let digest = format!("SHA-256={}", sha256sum(json)); + println!("digest: {}", digest); + + let date = fmt_http_date(SystemTime::now()); + + let mut headers = String::new(); + headers.push_str(format!("(request-target): post {}\n", path).as_str()); + headers.push_str(format!("host: {}\n", host).as_str()); + headers.push_str(format!("date: {}\n", date).as_str()); + headers.push_str(format!("digest: {}", digest).as_str()); + + println!("signed_string: {:?}", headers); + + let privkey_file = include_str!("private.pem"); + let pubkey_file = include_str!("public.pem"); + + let privkey = + PKey::private_key_from_pem(privkey_file.as_bytes()).expect("Failed decoding private.pem"); + let _pubkey = + PKey::public_key_from_pem(pubkey_file.as_bytes()).expect("Failed decoding public.pem"); + + let mut signer = Signer::new(MessageDigest::sha256(), &privkey).unwrap(); + signer.update(headers.as_bytes()).unwrap(); + let signature = BASE64_STANDARD.encode(signer.sign_to_vec().unwrap()); + + let header = format!( + "keyId=\"{}\",algorithm=\"rsa-sha256\",headers=\"(request-target) host date digest\",signature=\"{}\"", + key_id, signature + ); + + println!("header: {}", header); + + let response = ureq::post(url) + .header("Content-Type", "application/activity+json") + .header("Signature", header) + .header("host", host) + .header("date", date) + .header("digest", digest) + .send(json); + + match response { + Err(v) => println!("{:#?}", v), + Ok(v) => { + println!("Status: {}", v.status()); + println!( + "Response: {}", + v.into_body() + .read_to_string() + .expect("Invalid response: decode error") + ); + } + } +} diff --git a/NotePoster/src/note.json b/NotePoster/src/note.json new file mode 100644 index 0000000..9b38c63 --- /dev/null +++ b/NotePoster/src/note.json @@ -0,0 +1,31 @@ +{ + "actor":"https://testing4host.com/users/test71/", + "object":{ + "id": "https://testing4host.com/hello-world-4aaaaaaaaaaa3", + "type": "Note", + "published": "2025-04-23T17:17:11Z", + "attributedTo": "https://testing4host.com/users/test71/", + "inReplyTo": null, + "content": "

Sexy Omega Giga Lesbian.

", + "to": "https://estradiol.city/users/ity", + "directMessage": true + }, + "id":"https://testing4host.com/posts/a78hbr30ngfqz7aaaaaamaaaaaafaff", + "type":"Create", + "to": [ + "https://estradiol.city/users/ity" + ], + "cc": [ + "https://estradiol.city/users/ity" + ], + "@context":[ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "toot":"http://joinmastodon.org/ns#", + "misskey":"https://misskey-hub.net/ns#", + "litepub": "http://litepub.social/ns#", + "directMessage": "litepub:directMessage" + } + ] +} diff --git a/NotePoster/src/private.pem b/NotePoster/src/private.pem new file mode 100644 index 0000000..9db01ea --- /dev/null +++ b/NotePoster/src/private.pem @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC6q5vMctUi0z3n +baZRhJ0WSk+zQZBqVxdUoEWAELPrXV+lHMpLnFIZDwFRVKf+4aRic7GeHWPjU2Tn +1VRCoJ6Pp3Y9ScBJtAdzuFxQA/CyBfFnYtHTPlhN+U0inKZ3mreEyq/s1V/TktCe +bW35tu8iGIffzYnvQ5vkVhxp7hKG2nnF4EDwjMP1ajYPA2Mfeg/zd/JscgQ5Kh9x +xcH4Mj6noNk+DYTb8M+lepUxObC6uUhhf/2NgpgAsT0vBfSNj/rSVFiTNqD0avnu +eURkfaA45mLLYmZNK/BJZzYt9DJTvz3D/5vnH0T6UmXW4DiDkc30X6cRp0tGN4wg +rJYV2rvLAgMBAAECggEAKu7HMXmDvbO5/B1C8GLAwlyrAf5lWZ/YNNV7xp2Q0+Qw +2EfL2yID29GQqwT+cmexKBeV1VjLHYCTp6Jv87b/YOjSD/yDZjAqupm/WYPeewNU +50NaIOyo4J4i+H/w5XdHGBqJ5b2ZgY61vopKjfFeBIiBz551R/tTwmtvs4lW5365 +Zxi27MEBbnjc+pb3QiRAvDo3Mb0y4eXXnSdjb7N9zZrHGhJR2ZC6i+zbmTQc3l+2 +xkgtGWcWD7l3qauM5EDkTib48tqN36oSHNddBlZ7MpYYFxKxbmo3M3rcgg9LUy8u +PRDYtr3+gG4m+T5kQqjcEG3jFgrbFz5sqDvoVNNMEQKBgQDnF5EtHjG67cmcn/1+ +/bwjWEiOSyLnKmIzU0xWNP/CxY/IKajaGqz6cGZnw3f3E6+5pOJNjlFU38kwCLRn +DqhyuSpb1lSklobtKlyZ4Ha8NMW8A+9EX0MlBg5IMdoopRanhBd7L6nHUStGwZ1u +J33KrsQiEHHT0ihKE4PBLim+cwKBgQDOylSdJX5XhZNlJjJOkZtdJqz2uEpL5eNc +HJbLE0LUuYzIgnFFPlNNqfBdw6H/ctGPCuVnjNpY3wzqxY6Zx0tAk+/MXsy+Uglz +05fjKZhvP/loLFakS/kJiBj8KvJssN/273gSL3Bf4W091Zk/XJXtnMUwhwbgkNJf +PFk1oi6fSQKBgDP8Wj1TGI7bpUolt6oUvHkbCB9yiaSFJVg0eey+uXaAaQr3TDPc +YmNoW7EmCNu9Qv+5NuuJg4RbX2/91U+FvaEpRH0qZxorfqjlqbU4CJ3oJT9Zhz7T +S1CN3zKgfFo+YS1ICtw8aa4b9WdScO7x1Vt+G0MqfeDP2x5m63HOx7c/AoGBAMJY +g+dhKnllD57bpCIVVJfaVmpVz3W/a8vRDqNyybeVX0u+1GfIaJAwK7hjuWeT6IFw +MyP7y+YEU2Z+H0RFemMJ5jAD1Jb2EO4rqa8UE7BSxrryGMe2oyojH6A3WLlwDj1M +2GL29L0X5wxbJ/jVsg6r7ONrs7nwQdbBp/HxJ7IJAoGBAK/iwgmf/Bqo4MRO/LLs +HOJM0X8d9aaTJaqCBEudNVAx8+0UsXyHt2bZUTX3LcCbjuPVGykPgkeORITB1Adz +ymAwPIrYP6C90YtWf3IEmLmQs2sOuZzCpKZqeWfUjW4FqbVDI9r+OqiB62Z3NmYb +D+TVXY37h9J21RUxmNIh5o2+ +-----END PRIVATE KEY----- diff --git a/NotePoster/src/public.pem b/NotePoster/src/public.pem new file mode 100644 index 0000000..72d77db --- /dev/null +++ b/NotePoster/src/public.pem @@ -0,0 +1,9 @@ +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuqubzHLVItM9522mUYSd +FkpPs0GQalcXVKBFgBCz611fpRzKS5xSGQ8BUVSn/uGkYnOxnh1j41Nk59VUQqCe +j6d2PUnASbQHc7hcUAPwsgXxZ2LR0z5YTflNIpymd5q3hMqv7NVf05LQnm1t+bbv +IhiH382J70Ob5FYcae4Shtp5xeBA8IzD9Wo2DwNjH3oP83fybHIEOSofccXB+DI+ +p6DZPg2E2/DPpXqVMTmwurlIYX/9jYKYALE9LwX0jY/60lRYkzag9Gr57nlEZH2g +OOZiy2JmTSvwSWc2LfQyU789w/+b5x9E+lJl1uA4g5HN9F+nEadLRjeMIKyWFdq7 +ywIDAQAB +-----END PUBLIC KEY----- diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..1f98193 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1745930157, + "narHash": "sha256-y3h3NLnzRSiUkYpnfvnS669zWZLoqqI6NprtLQ+5dck=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "46e634be05ce9dc6d4db8e664515ba10b78151ae", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..41b3fb4 --- /dev/null +++ b/flake.nix @@ -0,0 +1,26 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { + self, + nixpkgs, + flake-utils, + ... + } @ inputs: + flake-utils.lib.eachDefaultSystem (system: let + name = "HitLock"; + src = ./.; + pkgs = import nixpkgs { + inherit system; + }; + in { + devShells.default = pkgs.mkShell { + nativeBuildInputs = with pkgs; [pkg-config]; + buildInputs = with pkgs; [openssl]; + }; + }); +} -- 2.39.1 From 1bafa23e81c1991a2814ee7890853473f9d2d4be Mon Sep 17 00:00:00 2001 From: Avery Date: Thu, 1 May 2025 17:53:23 +0200 Subject: [PATCH 2/3] 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 Date: Thu, 1 May 2025 18:15:06 +0200 Subject: [PATCH 3/3] Print panic messages to the log --- HitLock/src/main.rs | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/HitLock/src/main.rs b/HitLock/src/main.rs index 2d8580b..7ec9f01 100644 --- a/HitLock/src/main.rs +++ b/HitLock/src/main.rs @@ -3,8 +3,9 @@ mod users; mod webfinger; use std::{ - fmt, + fmt::{self, Debug}, iter::once, + panic, task::{Context, Poll}, }; @@ -14,7 +15,7 @@ use axum::{ routing::{get, post}, }; use inbox::inbox_post; -use log::{info, trace}; +use log::{error, info, trace}; use tower_layer::Layer; use tower_service::Service; use users::users_get; @@ -34,13 +35,42 @@ fn init_logger() { async fn main() { init_logger(); + panic::set_hook(Box::new(|i| { + if let Some(loc) = i.location() { + if let Some(s) = i.payload().downcast_ref::<&str>() { + error!( + "Panicked at {}:{}:{}\n{}", + loc.file(), + loc.line(), + loc.column(), + sanitize_printable(s) + ); + } else if let Some(s) = i.payload().downcast_ref::() { + error!( + "Panicked at {}:{}:{}\n{}", + loc.file(), + loc.line(), + loc.column(), + sanitize_printable(s) + ); + } + } else { + if let Some(s) = i.payload().downcast_ref::<&str>() { + error!("Panicked\n{s:?}",); + } else if let Some(s) = i.payload().downcast_ref::() { + error!("Panicked\n{s:?}",); + } + } + })); + 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); + .fallback(fallback) + .layer(TraceLayer); let listener = tokio::net::TcpListener::bind("0.0.0.0:8000").await.unwrap(); axum::serve(listener, app).await.unwrap(); -- 2.39.1