Removed ext_activity_pub and bumped tower

This commit is contained in:
Natty 2023-04-21 20:07:24 +02:00
parent b772833384
commit 917178e1a2
Signed by: natty
GPG Key ID: BF6CB659ADEE60EC
6 changed files with 101 additions and 16 deletions

26
Cargo.lock generated
View File

@ -53,7 +53,7 @@ dependencies = [
"sync_wrapper", "sync_wrapper",
"tokio", "tokio",
"tower", "tower",
"tower-http", "tower-http 0.3.5",
"tower-layer", "tower-layer",
"tower-service", "tower-service",
] ]
@ -426,15 +426,11 @@ dependencies = [
"tokio", "tokio",
"toml", "toml",
"tower", "tower",
"tower-http", "tower-http 0.4.0",
"tracing", "tracing",
"tracing-subscriber", "tracing-subscriber",
] ]
[[package]]
name = "magnetar_activity_pub"
version = "0.1.0"
[[package]] [[package]]
name = "magnetar_core" name = "magnetar_core"
version = "0.1.0" version = "0.1.0"
@ -1111,6 +1107,24 @@ dependencies = [
"tower", "tower",
"tower-layer", "tower-layer",
"tower-service", "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", "tracing",
] ]

View File

@ -8,7 +8,6 @@ edition = "2021"
[workspace] [workspace]
members = [ members = [
".", ".",
"ext_activity_pub",
"ext_nodeinfo", "ext_nodeinfo",
"ext_webfinger", "ext_webfinger",
"core" "core"
@ -26,7 +25,7 @@ axum = "0.6"
hyper = { version = "0.14", features = ["full"] } hyper = { version = "0.14", features = ["full"] }
tokio = { version = "1.24", features = ["full"] } tokio = { version = "1.24", features = ["full"] }
tower = "0.4" 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-subscriber = { version = "0.3", features = ["env-filter"] }
tracing = "0.1" tracing = "0.1"

View File

@ -1,7 +0,0 @@
[package]
name = "magnetar_activity_pub"
version = "0.1.0"
edition = "2021"
[dependencies]

View File

@ -1 +0,0 @@

79
src/activity_pub.rs Normal file
View File

@ -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<MagnetarConfig>,
) -> Result<Json<serde_json::Value>, 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<Json<serde_json::Value>, 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"
})))
}

View File

@ -1,3 +1,4 @@
pub mod activity_pub;
pub mod config; pub mod config;
pub mod webfinger; pub mod webfinger;