gourami

[UNMAINTAINED] Activitypub server in Rust
Log | Files | Refs | README | LICENSE

commit d882b28b1b83154416dd18a4b47ae1a5116ec0db
parent 80dca7315d2b5eb9eae507ddf62b2ac8275a4ffe
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Wed,  6 May 2020 10:25:15 -0500

Testing work for HTTP Signature verification

Diffstat:
MCargo.lock | 24+++++++++++++++++++-----
MCargo.toml | 2++
Msrc/ap.rs | 19++++++++++++++-----
3 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -329,6 +329,12 @@ dependencies = [ ] [[package]] +name = "data-encoding" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11c0346158a19b3627234e15596f5e465c360fcdb97d817bcb255e0510f5a788" + +[[package]] name = "derive_builder" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -608,6 +614,7 @@ dependencies = [ "bcrypt", "chrono", "clap", + "data-encoding", "diesel", "env_logger", "http-signature-normalization", @@ -618,6 +625,7 @@ dependencies = [ "rand 0.7.3", "regex", "reqwest", + "ring", "serde", "serde_json", "tokio", @@ -1122,6 +1130,12 @@ dependencies = [ ] [[package]] +name = "once_cell" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c601810575c99596d4afc46f78a678c80105117c379eb3650cf99b8a21ce5b" + +[[package]] name = "opaque-debug" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1619,13 +1633,13 @@ dependencies = [ [[package]] name = "ring" -version = "0.16.12" +version = "0.16.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ba5a8ec64ee89a76c98c549af81ff14813df09c3e6dc4766c3856da48597a0c" +checksum = "703516ae74571f24b465b4a1431e81e2ad51336cb0ded733a55a1aa3eccac196" dependencies = [ "cc", - "lazy_static", "libc", + "once_cell", "spin", "untrusted", "web-sys", @@ -2137,9 +2151,9 @@ checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" [[package]] name = "untrusted" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60369ef7a31de49bcb3f6ca728d4ba7300d9a1658f94c727d4cab8c8d9f4aece" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" diff --git a/Cargo.toml b/Cargo.toml @@ -10,6 +10,7 @@ askama = "0.8.0" bcrypt = "0.7.0" chrono = "0.4.11" clap = "2.33.0" +data-encoding = "2.2.0" diesel = { version = "1.4.4", features = ["sqlite", "r2d2"] } env_logger = "0.7.1" http-signature-normalization = "0.5.1" @@ -19,6 +20,7 @@ log = "0.4.8" maplit = "1.0.2" rand = "0.7.3" regex = "1.3.7" +ring = "0.16.13" reqwest = {version="0.10.4",features=["json", "blocking"]} serde = { version = "1.0.106", features = ["derive"] } serde_json = "1.0.52" diff --git a/src/ap.rs b/src/ap.rs @@ -1,3 +1,5 @@ +use ring::digest; +use data_encoding::HEXUPPER; use crate::db::conn::POOL; use crate::db::note::{NoteInput, RemoteNoteInput}; use crate::db::user::{NewRemoteUser, User}; @@ -205,7 +207,7 @@ pub trait HttpSignature { impl HttpSignature for reqwest::RequestBuilder { fn http_sign_outgoing(self) -> Result<reqwest::Request, Box<dyn std::error::Error>> { let req = self.build().unwrap(); - let config = Config::default().set_expiration(Duration::seconds(5)); + let config = Config::default().set_expiration(Duration::seconds(30)); // let server_key_id = let server_key_id: &str = &format!("{}/inbox", &env::var("GOURAMI_DOMAIN").unwrap()); let mut bt = std::collections::BTreeMap::new(); @@ -218,9 +220,11 @@ impl HttpSignature for reqwest::RequestBuilder { req.url().path().to_string() }; let unsigned = config.begin_sign(req.method().as_str(), &path_and_query, bt)?; + println!("{:?}", &unsigned); let sig_header = unsigned.sign(server_key_id.to_owned(), |signing_string| { - // sign here - Ok(signing_string.to_owned()) as Result<_, Box<dyn std::error::Error>> + let digest = digest::digest(&digest::SHA256, &signing_string.as_bytes()); + let hexencode = HEXUPPER.encode(digest.as_ref()); + Ok(hexencode) as Result<_, Box<dyn std::error::Error>> })? .signature_header(); println!("{:?}", sig_header); @@ -228,16 +232,21 @@ impl HttpSignature for reqwest::RequestBuilder { } } +fn verify_ap_message() { + +} + #[cfg(test)] mod tests { use super::*; + #[test] fn test_sign_outgoing_msg() { let body: Value = serde_json::from_str(r#"{"foo": "bar"}"#).unwrap(); let req = reqwest::Client::new() .post("https://localhost:3030") .json(&body) - .http_sign_outgoing(); + .http_sign_outgoing().unwrap(); } #[test] @@ -245,7 +254,7 @@ mod tests { // to write } - // #[test] + #[test] // TODO -- set env variales in test fn test_mastodon_create_status_example() { let create_note_mastodon: Value = serde_json::from_str(r#"{ "id": "https://mastodon.social/users/alexwennerberg/statuses/104028309437021899/activity",