From e34d12922c15c416792f268baed0fd8e7c549ae2 Mon Sep 17 00:00:00 2001 From: Bat Date: Thu, 21 Jun 2018 22:12:24 +0100 Subject: [PATCH] Serialize publicKey in Person representation --- src/models/users.rs | 14 +++++++++++--- src/routes/user.rs | 3 +-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/models/users.rs b/src/models/users.rs index 538cc868..9a3f7760 100644 --- a/src/models/users.rs +++ b/src/models/users.rs @@ -27,7 +27,7 @@ use webfinger::*; use BASE_URL; use activity_pub::{ - ap_url, ActivityStream, Id, IntoId, ApSignature, + ap_url, ActivityStream, Id, IntoId, ApSignature, PublicKey, inbox::{Inbox, WithInbox}, sign::{Signer, gen_keypair} }; @@ -315,7 +315,7 @@ impl User { PKey::from_rsa(Rsa::private_key_from_pem(self.private_key.clone().unwrap().as_ref()).unwrap()).unwrap() } - pub fn into_activity(&self, _conn: &PgConnection) -> Person { + pub fn into_activity(&self, _conn: &PgConnection) -> CustomPerson { let mut actor = Person::default(); actor.object_props.set_id_string(self.ap_url.clone()).expect("User::into_activity: id error"); actor.object_props.set_name_string(self.display_name.clone()).expect("User::into_activity: name error"); @@ -328,7 +328,15 @@ impl User { let mut endpoints = Endpoint::default(); endpoints.set_shared_inbox_string(ap_url(format!("{}/inbox/", BASE_URL.as_str()))).expect("User::into_activity: endpoints.sharedInbox error"); actor.ap_actor_props.set_endpoints_endpoint(endpoints).expect("User::into_activity: endpoints error"); - actor + + let mut public_key = PublicKey::default(); + public_key.set_id_string(format!("{}#main-key", self.ap_url)).expect("Blog::into_activity: publicKey.id error"); + public_key.set_owner_string(self.ap_url.clone()).expect("Blog::into_activity: publicKey.owner error"); + public_key.set_public_key_pem_string(self.public_key.clone()).expect("Blog::into_activity: publicKey.publicKeyPem error"); + let mut ap_signature = ApSignature::default(); + ap_signature.set_public_key_publickey(public_key).expect("Blog::into_activity: publicKey error"); + + CustomPerson::new(actor, ap_signature) } pub fn to_json(&self, conn: &PgConnection) -> serde_json::Value { diff --git a/src/routes/user.rs b/src/routes/user.rs index 2f9ae0b3..a2bbfc0b 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -1,6 +1,5 @@ use activitypub::{ activity::Follow, - actor::Person, collection::OrderedCollection }; use rocket::{request::Form, @@ -110,7 +109,7 @@ fn followers(name: String, conn: DbConn, account: Option) -> Template { } #[get("/@/", format = "application/activity+json", rank = 1)] -fn activity_details(name: String, conn: DbConn) -> ActivityStream { +fn activity_details(name: String, conn: DbConn) -> ActivityStream { let user = User::find_local(&*conn, name).unwrap(); ActivityStream::new(user.into_activity(&*conn)) }