Add some AP examples
Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
This commit is contained in:
parent
7eed71fe68
commit
205958b0cc
5 changed files with 235 additions and 9 deletions
|
@ -1,5 +1,7 @@
|
|||
# Fedivet
|
||||
|
||||
WIP! Not usable yet.
|
||||
|
||||
Software-defined Application Firewall for ActivityPub inboxes.
|
||||
|
||||
## Objective
|
||||
|
|
|
@ -16,6 +16,7 @@ use axum::{
|
|||
use client::ClientCache;
|
||||
use evaluate::{Disposition, Evaluator};
|
||||
use futures::TryStreamExt;
|
||||
use model::ap::Object;
|
||||
use model::{ap, error::MisskeyError};
|
||||
use network::stream::LimitedStream;
|
||||
use network::Either;
|
||||
|
@ -34,7 +35,7 @@ pub struct APRequestInfo<'r> {
|
|||
pub uri: &'r Uri,
|
||||
pub header: &'r HeaderMap,
|
||||
pub connect: &'r SocketAddr,
|
||||
pub activity: &'r Result<ap::Activity, (serde_json::Value, serde_json::Error)>,
|
||||
pub activity: &'r Result<ap::Activity<Object>, (serde_json::Value, serde_json::Error)>,
|
||||
}
|
||||
|
||||
impl Display for APRequestInfo<'_> {
|
||||
|
@ -195,7 +196,7 @@ impl<E: IntoResponse + 'static> ProxyApp<E> {
|
|||
})?;
|
||||
|
||||
let decode = {
|
||||
let activity_decode = serde_json::from_slice::<ap::Activity>(&body);
|
||||
let activity_decode = serde_json::from_slice::<ap::Activity<Object>>(&body);
|
||||
|
||||
match activity_decode {
|
||||
Ok(activity) => Ok(activity),
|
||||
|
|
|
@ -4,6 +4,13 @@ use std::collections::HashMap;
|
|||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum Either<A, B> {
|
||||
A(A),
|
||||
B(B),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum FlatArray<T> {
|
||||
|
@ -26,22 +33,31 @@ impl IntoIterator for FlatArray<Object> {
|
|||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Object {
|
||||
#[serde(rename = "@context")]
|
||||
pub context: String,
|
||||
pub context: FlatArray<Either<String, serde_json::Value>>,
|
||||
pub id: String,
|
||||
#[serde(rename = "type")]
|
||||
pub ty_: String,
|
||||
pub name: Option<String>,
|
||||
pub to: Option<Vec<String>>,
|
||||
pub cc: Option<Vec<String>>,
|
||||
pub bcc: Option<Vec<String>>,
|
||||
pub to: Option<FlatArray<String>>,
|
||||
pub cc: Option<FlatArray<String>>,
|
||||
pub bcc: Option<FlatArray<String>>,
|
||||
#[serde(flatten)]
|
||||
pub rest: HashMap<String, serde_json::Value>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Activity {
|
||||
pub struct Activity<O> {
|
||||
pub actor: Option<String>,
|
||||
pub object: Option<FlatArray<O>>,
|
||||
#[serde(flatten)]
|
||||
pub meta_obj: Object,
|
||||
pub actor: Option<String>,
|
||||
pub object: Option<FlatArray<Object>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct NoteObject {
|
||||
pub summary: Option<String>,
|
||||
#[serde(rename = "inReplyTo")]
|
||||
pub in_reply_to: Option<String>,
|
||||
#[serde(rename = "attributedTo")]
|
||||
pub attributed_to: Option<String>,
|
||||
}
|
||||
|
|
100
test-data/add.json
Normal file
100
test-data/add.json
Normal file
|
@ -0,0 +1,100 @@
|
|||
{
|
||||
"activity": {
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
{
|
||||
"ostatus": "http://ostatus.org#",
|
||||
"atomUri": "ostatus:atomUri",
|
||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"conversation": "ostatus:conversation",
|
||||
"sensitive": "as:sensitive",
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"votersCount": "toot:votersCount",
|
||||
"blurhash": "toot:blurhash",
|
||||
"focalPoint": {
|
||||
"@container": "@list",
|
||||
"@id": "toot:focalPoint"
|
||||
}
|
||||
}
|
||||
],
|
||||
"id": "https://wxw.moe/users/Rakaraka/statuses/113310421735740730/activity",
|
||||
"type": "Create",
|
||||
"actor": "https://wxw.moe/users/Rakaraka",
|
||||
"published": "2024-10-15T08:10:23Z",
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"cc": [
|
||||
"https://wxw.moe/users/Rakaraka/followers"
|
||||
],
|
||||
"object": {
|
||||
"id": "https://wxw.moe/users/Rakaraka/statuses/113310421735740730",
|
||||
"type": "Note",
|
||||
"summary": "p4g",
|
||||
"inReplyTo": "https://wxw.moe/users/Rakaraka/statuses/113310233102932476",
|
||||
"published": "2024-10-15T08:10:23Z",
|
||||
"url": "https://wxw.moe/@Rakaraka/113310421735740730",
|
||||
"attributedTo": "https://wxw.moe/users/Rakaraka",
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"cc": [
|
||||
"https://wxw.moe/users/Rakaraka/followers"
|
||||
],
|
||||
"sensitive": true,
|
||||
"atomUri": "https://wxw.moe/users/Rakaraka/statuses/113310421735740730",
|
||||
"inReplyToAtomUri": "https://wxw.moe/users/Rakaraka/statuses/113310233102932476",
|
||||
"conversation": "tag:wxw.moe,2023-12-25:objectId=60123443:objectType=Conversation",
|
||||
"content": "<p>哪些家伙啊我已经忘了</p>",
|
||||
"contentMap": {
|
||||
"zh-CN": "<p>哪些家伙啊我已经忘了</p>"
|
||||
},
|
||||
"attachment": [
|
||||
{
|
||||
"type": "Document",
|
||||
"mediaType": "image/jpeg",
|
||||
"url": "https://ovo.wxw.media/media_attachments/files/113/310/421/431/275/309/original/dacf0b5f7a6ffbd3.jpg",
|
||||
"name": null,
|
||||
"blurhash": "U35E$=_3%LM_of%fWAoy004nxut7D%afazog",
|
||||
"width": 2560,
|
||||
"height": 1600
|
||||
}
|
||||
],
|
||||
"tag": [],
|
||||
"replies": {
|
||||
"id": "https://wxw.moe/users/Rakaraka/statuses/113310421735740730/replies",
|
||||
"type": "Collection",
|
||||
"first": {
|
||||
"type": "CollectionPage",
|
||||
"next": "https://wxw.moe/users/Rakaraka/statuses/113310421735740730/replies?only_other_accounts=true&page=true",
|
||||
"partOf": "https://wxw.moe/users/Rakaraka/statuses/113310421735740730/replies",
|
||||
"items": []
|
||||
}
|
||||
}
|
||||
},
|
||||
"signature": {
|
||||
"type": "RsaSignature2017",
|
||||
"creator": "https://wxw.moe/users/Rakaraka#main-key",
|
||||
"created": "2024-10-15T08:10:23Z",
|
||||
"signatureValue": "AwYh68I8TMT/IIFJOrgH8grygH0xqNwG1cQrFeoCbtq9Tk8zJb4db5RCn7z01uGQtR0axhZFLYYfO9wrVoRpaqLt0xoN0qYjPl3vuIKq6gdRrs3jOt6++1qbFzN1NkkROZ6eMKJXNpx5DFFZ5a2Cz1p+OX4USpbrfeI1LpHFMHGUTuQ1rxElnsmjqQuI0P3ey1KDV90VbeVgL/hiEeL9CzInv8DNSu4iTAOyQICr1J4rB2jekjiimKn+S0T/wltxr90qBWNfh9DfEXyaT296YQQEEss46T6x7SEAbyHtkk3U/pJu54cNDXVDJZ7r14AZvWgS1dZQT8lAowc7kj/wAw=="
|
||||
}
|
||||
},
|
||||
"signature": {
|
||||
"scheme": "Signature",
|
||||
"params": {
|
||||
"keyId": "https://relay.nya.one/actor",
|
||||
"algorithm": "rsa-sha256",
|
||||
"headers": [
|
||||
"(request-target)",
|
||||
"host",
|
||||
"date",
|
||||
"digest",
|
||||
"content-type"
|
||||
],
|
||||
"signature": "bmD/7Mupw2SPhcnOvDVy1f94AWT9NjrBZG/W8aXjQQexCLPEGMIizru0A0/ZQ1154qkWIZKUuTF5uPNEf3l10DI5pLw6H9da/DhbSOXm9nrsvLXKHn/iBUNbBOuae/IHW6vw0MGgM/f4fGCbnkfG1zkHbwo71QU/dSGMDraizGQRY5F0MlDvMuhPorUXig2RZKtYa7JfIRjMeu4KirU9dVPKc2/SWJ/cLR85WK39Z3K+BUk5oyUmlmqBIc+xweO5fvA3CpWC0jIAbXHjsSCtr0T2/ZilEl3yLQ88vNs0jW/9Nx3TIa0By7liIQ+sBCuDXONgHB8+stJKV/nDMGclng=="
|
||||
},
|
||||
"signingString": "(request-target): post /inbox\nhost: mi.yumechi.jp\ndate: Tue, 15 Oct 2024 08:10:24 GMT\ndigest: SHA-256=iSGdvXYrd/E9f2nccsvHA9eRehwKNXB8lxGTOyTFvfQ=\ncontent-type: application/activity+json",
|
||||
"algorithm": "RSA-SHA256",
|
||||
"keyId": "https://relay.nya.one/actor"
|
||||
}
|
||||
}
|
107
test-data/add_masto.json
Normal file
107
test-data/add_masto.json
Normal file
|
@ -0,0 +1,107 @@
|
|||
{
|
||||
"activity": {
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
{
|
||||
"ostatus": "http://ostatus.org#",
|
||||
"atomUri": "ostatus:atomUri",
|
||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"conversation": "ostatus:conversation",
|
||||
"sensitive": "as:sensitive",
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"votersCount": "toot:votersCount",
|
||||
"Hashtag": "as:Hashtag"
|
||||
},
|
||||
"https://w3id.org/security/v1"
|
||||
],
|
||||
"id": "https://prattohome.com/users/ottoto2017/statuses/113310424711265323/activity",
|
||||
"type": "Create",
|
||||
"actor": "https://prattohome.com/users/ottoto2017",
|
||||
"published": "2024-10-15T08:11:09Z",
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"cc": [
|
||||
"https://prattohome.com/users/ottoto2017/followers"
|
||||
],
|
||||
"object": {
|
||||
"id": "https://prattohome.com/users/ottoto2017/statuses/113310424711265323",
|
||||
"type": "Note",
|
||||
"summary": null,
|
||||
"inReplyTo": null,
|
||||
"published": "2024-10-15T08:11:09Z",
|
||||
"url": "https://prattohome.com/@ottoto2017/113310424711265323",
|
||||
"attributedTo": "https://prattohome.com/users/ottoto2017",
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"cc": [
|
||||
"https://prattohome.com/users/ottoto2017/followers"
|
||||
],
|
||||
"sensitive": false,
|
||||
"atomUri": "https://prattohome.com/users/ottoto2017/statuses/113310424711265323",
|
||||
"inReplyToAtomUri": null,
|
||||
"conversation": "tag:prattohome.com,2024-10-15:objectId=21925483:objectType=Conversation",
|
||||
"content": "<p>「Googleは原子力エネルギーへの投資で連鎖反応を引き起こしたいと考えている 」: The Register</p><p>「グーグルは、自社のデータセンターやその他の事業の電源として原子力を求めている最新のテクノロジー巨人となった。</p><p>広告と検索の巨人は月曜日、 カイロス・パワーと呼ばれる企業が開発する複数の小型モジュール型原子炉(SMR)から原子力エネルギーを購入した と発表した。</p><p>カイロスは その技術を「低圧フッ化物塩冷却材と組み合わせた小石状のTRISO燃料を利用する、斬新で高度な原子炉技術である。この技術は、効率的かつ柔軟な蒸気サイクルを使用して、核分裂からの熱を電気に変換し、再生可能エネルギー源を補完する」と説明している 。 」</p><p>TRISOは「TRi構造等方性粒子燃料」の略称で、 米国エネルギー省によれば 「地球上で最も堅牢な核燃料」だという。 」</p><p>なにか良く分からないが、危ないぞ。</p><p><a href=\"https://www.theregister.com/2024/10/15/google_kairos_smr_nuclear_investment/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" translate=\"no\"><span class=\"invisible\">https://www.</span><span class=\"ellipsis\">theregister.com/2024/10/15/goo</span><span class=\"invisible\">gle_kairos_smr_nuclear_investment/</span></a></p><p><a href=\"https://prattohome.com/tags/prattohome\" class=\"mention hashtag\" rel=\"tag\">#<span>prattohome</span></a> <a href=\"https://prattohome.com/tags/TheRegister\" class=\"mention hashtag\" rel=\"tag\">#<span>TheRegister</span></a></p>",
|
||||
"contentMap": {
|
||||
"ja": "<p>「Googleは原子力エネルギーへの投資で連鎖反応を引き起こしたいと考えている 」: The Register</p><p>「グーグルは、自社のデータセンターやその他の事業の電源として原子力を求めている最新のテクノロジー巨人となった。</p><p>広告と検索の巨人は月曜日、 カイロス・パワーと呼ばれる企業が開発する複数の小型モジュール型原子炉(SMR)から原子力エネルギーを購入した と発表した。</p><p>カイロスは その技術を「低圧フッ化物塩冷却材と組み合わせた小石状のTRISO燃料を利用する、斬新で高度な原子炉技術である。この技術は、効率的かつ柔軟な蒸気サイクルを使用して、核分裂からの熱を電気に変換し、再生可能エネルギー源を補完する」と説明している 。 」</p><p>TRISOは「TRi構造等方性粒子燃料」の略称で、 米国エネルギー省によれば 「地球上で最も堅牢な核燃料」だという。 」</p><p>なにか良く分からないが、危ないぞ。</p><p><a href=\"https://www.theregister.com/2024/10/15/google_kairos_smr_nuclear_investment/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" translate=\"no\"><span class=\"invisible\">https://www.</span><span class=\"ellipsis\">theregister.com/2024/10/15/goo</span><span class=\"invisible\">gle_kairos_smr_nuclear_investment/</span></a></p><p><a href=\"https://prattohome.com/tags/prattohome\" class=\"mention hashtag\" rel=\"tag\">#<span>prattohome</span></a> <a href=\"https://prattohome.com/tags/TheRegister\" class=\"mention hashtag\" rel=\"tag\">#<span>TheRegister</span></a></p>"
|
||||
},
|
||||
"attachment": [],
|
||||
"tag": [
|
||||
{
|
||||
"type": "Hashtag",
|
||||
"href": "https://prattohome.com/tags/prattohome",
|
||||
"name": "#prattohome"
|
||||
},
|
||||
{
|
||||
"type": "Hashtag",
|
||||
"href": "https://prattohome.com/tags/theregister",
|
||||
"name": "#theregister"
|
||||
}
|
||||
],
|
||||
"replies": {
|
||||
"id": "https://prattohome.com/users/ottoto2017/statuses/113310424711265323/replies",
|
||||
"type": "Collection",
|
||||
"first": {
|
||||
"type": "CollectionPage",
|
||||
"next": "https://prattohome.com/users/ottoto2017/statuses/113310424711265323/replies?only_other_accounts=true&page=true",
|
||||
"partOf": "https://prattohome.com/users/ottoto2017/statuses/113310424711265323/replies",
|
||||
"items": []
|
||||
}
|
||||
},
|
||||
"likes": {
|
||||
"id": "https://prattohome.com/users/ottoto2017/statuses/113310424711265323/likes",
|
||||
"type": "Collection",
|
||||
"totalItems": 0
|
||||
},
|
||||
"shares": {
|
||||
"id": "https://prattohome.com/users/ottoto2017/statuses/113310424711265323/shares",
|
||||
"type": "Collection",
|
||||
"totalItems": 0
|
||||
}
|
||||
},
|
||||
"signature": {
|
||||
"type": "RsaSignature2017",
|
||||
"creator": "https://prattohome.com/users/ottoto2017#main-key",
|
||||
"created": "2024-10-15T08:11:09Z",
|
||||
"signatureValue": "pmYDDzhw4baglCmr14Q6hY+f763yCPe/b4P/2AcU2PDAVFzaiwmvGZUKNdsvQmlWUct2G2y08T0rzdO7gDf+4jH1wR9jHXXOSTTvORws5NqOnNah4WoRmzos05anuexQ85/9NfMjKXGKylEZ+L7Ear+AoyJ9GWfQzNbokLLTMZb2+h1i4gjnOBZQE4Iqo2qu5VgDcG+n+aJO/JNGezjUKrQY5nRW4/Gy7DUjWCxgySkqw1joYEUKZlxERIahcCbUKbpCMcAg4BXSBTB/sA838DVGMxppY5HryMtBxzUXLg0uMgeyzMNI5bgHYTrww57VZn5zH3CrhkKkcxNaFB8D7A=="
|
||||
}
|
||||
},
|
||||
"signature": {
|
||||
"scheme": "Signature",
|
||||
"params": {
|
||||
"keyId": "https://relay.fedibird.com/actor",
|
||||
"algorithm": "rsa-sha256",
|
||||
"headers": [
|
||||
"(request-target)",
|
||||
"host",
|
||||
"date",
|
||||
"digest"
|
||||
],
|
||||
"signature": "B0ePs8K92cigD3zECcjHabNXZhHTXNRUM1x1eW65bCRVCsY0Qr+fwMUKa2uMd9UJ3E/CmZlTSwXwo51HfcqY3/B7tU1k6l79TkKHMfPrFmGoF0fqR0lOqHu+XOPTbV3wjPASR7+vo9svTqp6+Krb2nS5pklJcYbGb8+8jGJli+H/sdvGpOJ9WW91z7hinAVcBW4MiCxsLx4cwXlVDeqoMyuWRfW8MLLg9IEbKtzGA/cdG22vXuvdS/i/nTlOX3NcbhqAWa55NllKfmpzUTdQwc9vlNazPLa0E90rsw42hwH4+asqNFS+QyQNZXdCtm2oJyYeYYSfZanilmGWcA=="
|
||||
},
|
||||
"signingString": "(request-target): post /inbox\nhost: mi.yumechi.jp\ndate: Tue, 15 Oct 2024 08:11:12 GMT\ndigest: SHA-256=4Cq6aJpVlRgkiSJ6zBpc5dgaC3kDBAdtpoB4N0d1RJs=",
|
||||
"algorithm": "RSA-SHA256",
|
||||
"keyId": "https://relay.fedibird.com/actor"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue