From 917178e1a2c178fb9edf753de63058ff134c16bc Mon Sep 17 00:00:00 2001 From: Natty Date: Fri, 21 Apr 2023 20:07:24 +0200 Subject: [PATCH] Removed ext_activity_pub and bumped tower --- Cargo.lock | 26 +++++++++--- Cargo.toml | 3 +- ext_activity_pub/Cargo.toml | 7 ---- ext_activity_pub/src/lib.rs | 1 - src/activity_pub.rs | 79 +++++++++++++++++++++++++++++++++++++ src/main.rs | 1 + 6 files changed, 101 insertions(+), 16 deletions(-) delete mode 100644 ext_activity_pub/Cargo.toml delete mode 100644 ext_activity_pub/src/lib.rs create mode 100644 src/activity_pub.rs diff --git a/Cargo.lock b/Cargo.lock index a2babaf..f82cfc8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -53,7 +53,7 @@ dependencies = [ "sync_wrapper", "tokio", "tower", - "tower-http", + "tower-http 0.3.5", "tower-layer", "tower-service", ] @@ -426,15 +426,11 @@ dependencies = [ "tokio", "toml", "tower", - "tower-http", + "tower-http 0.4.0", "tracing", "tracing-subscriber", ] -[[package]] -name = "magnetar_activity_pub" -version = "0.1.0" - [[package]] name = "magnetar_core" version = "0.1.0" @@ -1111,6 +1107,24 @@ dependencies = [ "tower", "tower-layer", "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d1d42a9b3f3ec46ba828e8d376aec14592ea199f70a06a548587ecd1c4ab658" +dependencies = [ + "bitflags", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-range-header", + "pin-project-lite", + "tower-layer", + "tower-service", "tracing", ] diff --git a/Cargo.toml b/Cargo.toml index a240a17..7070fbf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ edition = "2021" [workspace] members = [ ".", - "ext_activity_pub", "ext_nodeinfo", "ext_webfinger", "core" @@ -26,7 +25,7 @@ axum = "0.6" hyper = { version = "0.14", features = ["full"] } tokio = { version = "1.24", features = ["full"] } tower = "0.4" -tower-http = { version = "0.3", features = ["cors", "trace"] } +tower-http = { version = "0.4", features = ["cors", "trace"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] } tracing = "0.1" diff --git a/ext_activity_pub/Cargo.toml b/ext_activity_pub/Cargo.toml deleted file mode 100644 index d38ecba..0000000 --- a/ext_activity_pub/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "magnetar_activity_pub" -version = "0.1.0" -edition = "2021" - - -[dependencies] diff --git a/ext_activity_pub/src/lib.rs b/ext_activity_pub/src/lib.rs deleted file mode 100644 index 8b13789..0000000 --- a/ext_activity_pub/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/activity_pub.rs b/src/activity_pub.rs new file mode 100644 index 0000000..c9b3d40 --- /dev/null +++ b/src/activity_pub.rs @@ -0,0 +1,79 @@ +use crate::config::{MagnetarConfig, MagnetarNetworking}; +use axum::extract::State; +use axum::http::StatusCode; +use axum::Json; +use rsa::pkcs1::{EncodeRsaPublicKey, LineEnding}; +use rsa::{RsaPrivateKey, RsaPublicKey}; +use serde_json::json; + +pub async fn handle_actor_get( + State(MagnetarConfig { + networking: MagnetarNetworking { host, .. }, + .. + }): State, +) -> Result, StatusCode> { + let mut rng = rand::thread_rng(); + let bits = 2048; + let priv_key = RsaPrivateKey::new(&mut rng, bits).expect("failed to generate a key"); + let pub_key = RsaPublicKey::from(&priv_key); + + let public_key_pkcs1_pem = pub_key + .to_pkcs1_pem(LineEnding::LF) + .expect("TODO: panic message"); + + Ok(Json(json!({ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1" + ], + + "id": format!("https://{host}/actor"), + "type": "Person", + "preferredUsername": "alice", + "inbox": format!("https://{host}/inbox"), + + "publicKey": { + "id": "https://my-example.com/actor#main-key", + "owner": "https://my-example.com/actor", + "publicKeyPem": public_key_pkcs1_pem + } + }))) +} + +pub async fn handle_outbox_get() -> Result, StatusCode> { + Ok(Json(json!({ + "@context" : [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "Emoji" : "toot:Emoji", + "Hashtag" : "as:Hashtag", + "PropertyValue" : "schema:PropertyValue", + "_misskey_content" : "misskey:_misskey_content", + "_misskey_quote" : "misskey:_misskey_quote", + "_misskey_reaction" : "misskey:_misskey_reaction", + "_misskey_talk" : "misskey:_misskey_talk", + "_misskey_votes" : "misskey:_misskey_votes", + "discoverable" : "toot:discoverable", + "featured" : "toot:featured", + "fedibird" : "http://fedibird.com/ns#", + "isCat" : "misskey:isCat", + "manuallyApprovesFollowers" : "as:manuallyApprovesFollowers", + "misskey" : "https://misskey-hub.net/ns#", + "movedToUri" : "as:movedTo", + "quoteUri" : "fedibird:quoteUri", + "quoteUrl" : "as:quoteUrl", + "schema" : "http://schema.org#", + "sensitive" : "as:sensitive", + "toot" : "http://joinmastodon.org/ns#", + "value" : "schema:value", + "vcard" : "http://www.w3.org/2006/vcard/ns#" + } + ], + "first" : "https://astolfo.social/users/9awy7u3l76/outbox?page=true", + "id" : "https://astolfo.social/users/9awy7u3l76/outbox", + "last" : "https://astolfo.social/users/9awy7u3l76/outbox?page=true&since_id=000000000000000000000000", + "totalItems" : 1413, + "type" : "OrderedCollection" + }))) +} diff --git a/src/main.rs b/src/main.rs index a561d02..cd7e2de 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +pub mod activity_pub; pub mod config; pub mod webfinger;