mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-23 11:21:32 +00:00
Use ActorType for sign/verify, instead of passing raw privatekey/actor_id
This commit is contained in:
parent
11acc7225e
commit
13ca47a3b4
11 changed files with 77 additions and 219 deletions
|
@ -17,12 +17,7 @@ pub fn populate_object_props(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send an activity to a list of recipients, using the correct headers etc.
|
/// Send an activity to a list of recipients, using the correct headers etc.
|
||||||
pub fn send_activity<A>(
|
pub fn send_activity<A>(activity: &A, actor: &dyn ActorType, to: Vec<String>) -> Result<(), Error>
|
||||||
activity: &A,
|
|
||||||
private_key: &str,
|
|
||||||
sender_id: &str,
|
|
||||||
to: Vec<String>,
|
|
||||||
) -> Result<(), Error>
|
|
||||||
where
|
where
|
||||||
A: Serialize + Debug,
|
A: Serialize + Debug,
|
||||||
{
|
{
|
||||||
|
@ -35,7 +30,7 @@ where
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let request = Request::post(t).header("Host", to_url.domain().unwrap());
|
let request = Request::post(t).header("Host", to_url.domain().unwrap());
|
||||||
let signature = sign(&request, private_key, sender_id)?;
|
let signature = sign(&request, actor)?;
|
||||||
let res = request
|
let res = request
|
||||||
.header("Signature", signature)
|
.header("Signature", signature)
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
|
|
|
@ -115,12 +115,7 @@ impl ApubObjectType for Comment {
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &create, true)?;
|
insert_activity(&conn, creator.id, &create, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&create, creator, community.get_follower_inboxes(&conn)?)?;
|
||||||
&create,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
community.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,12 +139,7 @@ impl ApubObjectType for Comment {
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &update, true)?;
|
insert_activity(&conn, creator.id, &update, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&update, creator, community.get_follower_inboxes(&conn)?)?;
|
||||||
&update,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
community.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,12 +163,7 @@ impl ApubObjectType for Comment {
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &delete, true)?;
|
insert_activity(&conn, creator.id, &delete, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&delete, creator, community.get_follower_inboxes(&conn)?)?;
|
||||||
&delete,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
community.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,12 +205,7 @@ impl ApubObjectType for Comment {
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &undo, true)?;
|
insert_activity(&conn, creator.id, &undo, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&undo, creator, community.get_follower_inboxes(&conn)?)?;
|
||||||
&undo,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
community.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,12 +229,7 @@ impl ApubObjectType for Comment {
|
||||||
|
|
||||||
insert_activity(&conn, mod_.id, &remove, true)?;
|
insert_activity(&conn, mod_.id, &remove, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&remove, mod_, community.get_follower_inboxes(&conn)?)?;
|
||||||
&remove,
|
|
||||||
&mod_.private_key.as_ref().unwrap(),
|
|
||||||
&mod_.actor_id,
|
|
||||||
community.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,12 +270,7 @@ impl ApubObjectType for Comment {
|
||||||
|
|
||||||
insert_activity(&conn, mod_.id, &undo, true)?;
|
insert_activity(&conn, mod_.id, &undo, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&undo, mod_, community.get_follower_inboxes(&conn)?)?;
|
||||||
&undo,
|
|
||||||
&mod_.private_key.as_ref().unwrap(),
|
|
||||||
&mod_.actor_id,
|
|
||||||
community.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -321,12 +291,7 @@ impl ApubLikeableType for Comment {
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &like, true)?;
|
insert_activity(&conn, creator.id, &like, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&like, creator, community.get_follower_inboxes(&conn)?)?;
|
||||||
&like,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
community.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,12 +314,7 @@ impl ApubLikeableType for Comment {
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &dislike, true)?;
|
insert_activity(&conn, creator.id, &dislike, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&dislike, creator, community.get_follower_inboxes(&conn)?)?;
|
||||||
&dislike,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
community.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,12 +349,7 @@ impl ApubLikeableType for Comment {
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &undo, true)?;
|
insert_activity(&conn, creator.id, &undo, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&undo, creator, community.get_follower_inboxes(&conn)?)?;
|
||||||
&undo,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
community.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,9 @@ impl ActorType for Community {
|
||||||
fn public_key(&self) -> String {
|
fn public_key(&self) -> String {
|
||||||
self.public_key.to_owned().unwrap()
|
self.public_key.to_owned().unwrap()
|
||||||
}
|
}
|
||||||
|
fn private_key(&self) -> String {
|
||||||
|
self.private_key.to_owned().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
/// As a local community, accept the follow request from a remote user.
|
/// As a local community, accept the follow request from a remote user.
|
||||||
fn send_accept_follow(&self, follow: &Follow, conn: &PgConnection) -> Result<(), Error> {
|
fn send_accept_follow(&self, follow: &Follow, conn: &PgConnection) -> Result<(), Error> {
|
||||||
|
@ -102,12 +105,7 @@ impl ActorType for Community {
|
||||||
|
|
||||||
insert_activity(&conn, self.creator_id, &accept, true)?;
|
insert_activity(&conn, self.creator_id, &accept, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&accept, self, vec![to])?;
|
||||||
&accept,
|
|
||||||
&self.private_key.to_owned().unwrap(),
|
|
||||||
&self.actor_id,
|
|
||||||
vec![to],
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,12 +126,7 @@ impl ActorType for Community {
|
||||||
// Note: For an accept, since it was automatic, no one pushed a button,
|
// Note: For an accept, since it was automatic, no one pushed a button,
|
||||||
// the community was the actor.
|
// the community was the actor.
|
||||||
// But for delete, the creator is the actor, and does the signing
|
// But for delete, the creator is the actor, and does the signing
|
||||||
send_activity(
|
send_activity(&delete, creator, self.get_follower_inboxes(&conn)?)?;
|
||||||
&delete,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
self.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,12 +159,7 @@ impl ActorType for Community {
|
||||||
// Note: For an accept, since it was automatic, no one pushed a button,
|
// Note: For an accept, since it was automatic, no one pushed a button,
|
||||||
// the community was the actor.
|
// the community was the actor.
|
||||||
// But for delete, the creator is the actor, and does the signing
|
// But for delete, the creator is the actor, and does the signing
|
||||||
send_activity(
|
send_activity(&undo, creator, self.get_follower_inboxes(&conn)?)?;
|
||||||
&undo,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
self.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,12 +180,7 @@ impl ActorType for Community {
|
||||||
// Note: For an accept, since it was automatic, no one pushed a button,
|
// Note: For an accept, since it was automatic, no one pushed a button,
|
||||||
// the community was the actor.
|
// the community was the actor.
|
||||||
// But for delete, the creator is the actor, and does the signing
|
// But for delete, the creator is the actor, and does the signing
|
||||||
send_activity(
|
send_activity(&remove, mod_, self.get_follower_inboxes(&conn)?)?;
|
||||||
&remove,
|
|
||||||
&mod_.private_key.as_ref().unwrap(),
|
|
||||||
&mod_.actor_id,
|
|
||||||
self.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,12 +212,7 @@ impl ActorType for Community {
|
||||||
// Note: For an accept, since it was automatic, no one pushed a button,
|
// Note: For an accept, since it was automatic, no one pushed a button,
|
||||||
// the community was the actor.
|
// the community was the actor.
|
||||||
// But for remove , the creator is the actor, and does the signing
|
// But for remove , the creator is the actor, and does the signing
|
||||||
send_activity(
|
send_activity(&undo, mod_, self.get_follower_inboxes(&conn)?)?;
|
||||||
&undo,
|
|
||||||
&mod_.private_key.as_ref().unwrap(),
|
|
||||||
&mod_.actor_id,
|
|
||||||
self.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ fn handle_follow(
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
let community = Community::read_from_name(&conn, &community_name)?;
|
let community = Community::read_from_name(&conn, &community_name)?;
|
||||||
|
|
||||||
verify(&request, &user.public_key.unwrap())?;
|
verify(&request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &follow, false)?;
|
insert_activity(&conn, user.id, &follow, false)?;
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ fn handle_undo_follow(
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
let community = Community::read_from_name(&conn, &community_name)?;
|
let community = Community::read_from_name(&conn, &community_name)?;
|
||||||
|
|
||||||
verify(&request, &user.public_key.unwrap())?;
|
verify(&request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &follow, false)?;
|
insert_activity(&conn, user.id, &follow, false)?;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::apub::ActorType;
|
||||||
use activitystreams::ext::Extension;
|
use activitystreams::ext::Extension;
|
||||||
use activitystreams::Actor;
|
|
||||||
use actix_web::HttpRequest;
|
use actix_web::HttpRequest;
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use http::request::Builder;
|
use http::request::Builder;
|
||||||
|
@ -33,9 +33,8 @@ pub fn generate_actor_keypair() -> Result<Keypair, Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Signs request headers with the given keypair.
|
/// Signs request headers with the given keypair.
|
||||||
/// TODO: would be nice to pass the sending actor in, instead of raw privatekey/id strings
|
pub fn sign(request: &Builder, actor: &dyn ActorType) -> Result<String, Error> {
|
||||||
pub fn sign(request: &Builder, private_key: &str, sender_id: &str) -> Result<String, Error> {
|
let signing_key_id = format!("{}#main-key", actor.actor_id());
|
||||||
let signing_key_id = format!("{}#main-key", sender_id);
|
|
||||||
|
|
||||||
let headers = request
|
let headers = request
|
||||||
.headers_ref()
|
.headers_ref()
|
||||||
|
@ -58,7 +57,7 @@ pub fn sign(request: &Builder, private_key: &str, sender_id: &str) -> Result<Str
|
||||||
headers,
|
headers,
|
||||||
)
|
)
|
||||||
.sign(signing_key_id, |signing_string| {
|
.sign(signing_key_id, |signing_string| {
|
||||||
let private_key = PKey::private_key_from_pem(private_key.as_bytes())?;
|
let private_key = PKey::private_key_from_pem(actor.private_key().as_bytes())?;
|
||||||
let mut signer = Signer::new(MessageDigest::sha256(), &private_key).unwrap();
|
let mut signer = Signer::new(MessageDigest::sha256(), &private_key).unwrap();
|
||||||
signer.update(signing_string.as_bytes()).unwrap();
|
signer.update(signing_string.as_bytes()).unwrap();
|
||||||
Ok(base64::encode(signer.sign_to_vec()?)) as Result<_, Error>
|
Ok(base64::encode(signer.sign_to_vec()?)) as Result<_, Error>
|
||||||
|
@ -68,7 +67,7 @@ pub fn sign(request: &Builder, private_key: &str, sender_id: &str) -> Result<Str
|
||||||
Ok(signature_header_value)
|
Ok(signature_header_value)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn verify(request: &HttpRequest, public_key: &str) -> Result<(), Error> {
|
pub fn verify(request: &HttpRequest, actor: &dyn ActorType) -> Result<(), Error> {
|
||||||
let headers = request
|
let headers = request
|
||||||
.headers()
|
.headers()
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -86,9 +85,10 @@ pub fn verify(request: &HttpRequest, public_key: &str) -> Result<(), Error> {
|
||||||
.verify(|signature, signing_string| -> Result<bool, Error> {
|
.verify(|signature, signing_string| -> Result<bool, Error> {
|
||||||
debug!(
|
debug!(
|
||||||
"Verifying with key {}, message {}",
|
"Verifying with key {}, message {}",
|
||||||
&public_key, &signing_string
|
&actor.public_key(),
|
||||||
|
&signing_string
|
||||||
);
|
);
|
||||||
let public_key = PKey::public_key_from_pem(public_key.as_bytes())?;
|
let public_key = PKey::public_key_from_pem(actor.public_key().as_bytes())?;
|
||||||
let mut verifier = Verifier::new(MessageDigest::sha256(), &public_key).unwrap();
|
let mut verifier = Verifier::new(MessageDigest::sha256(), &public_key).unwrap();
|
||||||
verifier.update(&signing_string.as_bytes()).unwrap();
|
verifier.update(&signing_string.as_bytes()).unwrap();
|
||||||
Ok(verifier.verify(&base64::decode(signature)?)?)
|
Ok(verifier.verify(&base64::decode(signature)?)?)
|
||||||
|
@ -130,4 +130,4 @@ impl PublicKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Extension<T> for PublicKeyExtension where T: Actor {}
|
impl<T> Extension<T> for PublicKeyExtension where T: activitystreams::Actor {}
|
||||||
|
|
|
@ -226,6 +226,7 @@ pub trait ActorType {
|
||||||
fn actor_id(&self) -> String;
|
fn actor_id(&self) -> String;
|
||||||
|
|
||||||
fn public_key(&self) -> String;
|
fn public_key(&self) -> String;
|
||||||
|
fn private_key(&self) -> String;
|
||||||
|
|
||||||
// These two have default impls, since currently a community can't follow anything,
|
// These two have default impls, since currently a community can't follow anything,
|
||||||
// and a user can't be followed (yet)
|
// and a user can't be followed (yet)
|
||||||
|
|
|
@ -134,12 +134,7 @@ impl ApubObjectType for Post {
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &create, true)?;
|
insert_activity(&conn, creator.id, &create, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&create, creator, community.get_follower_inboxes(&conn)?)?;
|
||||||
&create,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
community.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,12 +157,7 @@ impl ApubObjectType for Post {
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &update, true)?;
|
insert_activity(&conn, creator.id, &update, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&update, creator, community.get_follower_inboxes(&conn)?)?;
|
||||||
&update,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
community.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,12 +181,7 @@ impl ApubObjectType for Post {
|
||||||
insert_activity(&conn, self.creator_id, &delete, true)?;
|
insert_activity(&conn, self.creator_id, &delete, true)?;
|
||||||
|
|
||||||
let community = Community::read(conn, self.community_id)?;
|
let community = Community::read(conn, self.community_id)?;
|
||||||
send_activity(
|
send_activity(&delete, creator, community.get_follower_inboxes(&conn)?)?;
|
||||||
&delete,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
community.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,12 +221,7 @@ impl ApubObjectType for Post {
|
||||||
insert_activity(&conn, self.creator_id, &undo, true)?;
|
insert_activity(&conn, self.creator_id, &undo, true)?;
|
||||||
|
|
||||||
let community = Community::read(conn, self.community_id)?;
|
let community = Community::read(conn, self.community_id)?;
|
||||||
send_activity(
|
send_activity(&undo, creator, community.get_follower_inboxes(&conn)?)?;
|
||||||
&undo,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
community.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,12 +245,7 @@ impl ApubObjectType for Post {
|
||||||
insert_activity(&conn, mod_.id, &remove, true)?;
|
insert_activity(&conn, mod_.id, &remove, true)?;
|
||||||
|
|
||||||
let community = Community::read(conn, self.community_id)?;
|
let community = Community::read(conn, self.community_id)?;
|
||||||
send_activity(
|
send_activity(&remove, mod_, community.get_follower_inboxes(&conn)?)?;
|
||||||
&remove,
|
|
||||||
&mod_.private_key.as_ref().unwrap(),
|
|
||||||
&mod_.actor_id,
|
|
||||||
community.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn send_undo_remove(&self, mod_: &User_, conn: &PgConnection) -> Result<(), Error> {
|
fn send_undo_remove(&self, mod_: &User_, conn: &PgConnection) -> Result<(), Error> {
|
||||||
|
@ -308,12 +283,7 @@ impl ApubObjectType for Post {
|
||||||
insert_activity(&conn, mod_.id, &undo, true)?;
|
insert_activity(&conn, mod_.id, &undo, true)?;
|
||||||
|
|
||||||
let community = Community::read(conn, self.community_id)?;
|
let community = Community::read(conn, self.community_id)?;
|
||||||
send_activity(
|
send_activity(&undo, mod_, community.get_follower_inboxes(&conn)?)?;
|
||||||
&undo,
|
|
||||||
&mod_.private_key.as_ref().unwrap(),
|
|
||||||
&mod_.actor_id,
|
|
||||||
community.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -333,12 +303,7 @@ impl ApubLikeableType for Post {
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &like, true)?;
|
insert_activity(&conn, creator.id, &like, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&like, creator, community.get_follower_inboxes(&conn)?)?;
|
||||||
&like,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
community.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,12 +325,7 @@ impl ApubLikeableType for Post {
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &dislike, true)?;
|
insert_activity(&conn, creator.id, &dislike, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&dislike, creator, community.get_follower_inboxes(&conn)?)?;
|
||||||
&dislike,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
community.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,12 +359,7 @@ impl ApubLikeableType for Post {
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &undo, true)?;
|
insert_activity(&conn, creator.id, &undo, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&undo, creator, community.get_follower_inboxes(&conn)?)?;
|
||||||
&undo,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
community.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,12 +87,7 @@ impl ApubObjectType for PrivateMessage {
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &create, true)?;
|
insert_activity(&conn, creator.id, &create, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&create, creator, vec![to])?;
|
||||||
&create,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
vec![to],
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,12 +111,7 @@ impl ApubObjectType for PrivateMessage {
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &update, true)?;
|
insert_activity(&conn, creator.id, &update, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&update, creator, vec![to])?;
|
||||||
&update,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
vec![to],
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,12 +134,7 @@ impl ApubObjectType for PrivateMessage {
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &delete, true)?;
|
insert_activity(&conn, creator.id, &delete, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&delete, creator, vec![to])?;
|
||||||
&delete,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
vec![to],
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,12 +172,7 @@ impl ApubObjectType for PrivateMessage {
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &undo, true)?;
|
insert_activity(&conn, creator.id, &undo, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&undo, creator, vec![to])?;
|
||||||
&undo,
|
|
||||||
&creator.private_key.as_ref().unwrap(),
|
|
||||||
&creator.actor_id,
|
|
||||||
vec![to],
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ fn receive_create_post(
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &create, false)?;
|
insert_activity(&conn, user.id, &create, false)?;
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ fn receive_create_comment(
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &create, false)?;
|
insert_activity(&conn, user.id, &create, false)?;
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ fn receive_update_post(
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &update, false)?;
|
insert_activity(&conn, user.id, &update, false)?;
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ fn receive_like_post(
|
||||||
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &like, false)?;
|
insert_activity(&conn, user.id, &like, false)?;
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ fn receive_dislike_post(
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &dislike, false)?;
|
insert_activity(&conn, user.id, &dislike, false)?;
|
||||||
|
|
||||||
|
@ -347,7 +347,7 @@ fn receive_update_comment(
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &update, false)?;
|
insert_activity(&conn, user.id, &update, false)?;
|
||||||
|
|
||||||
|
@ -391,7 +391,7 @@ fn receive_like_comment(
|
||||||
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &like, false)?;
|
insert_activity(&conn, user.id, &like, false)?;
|
||||||
|
|
||||||
|
@ -446,7 +446,7 @@ fn receive_dislike_comment(
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &dislike, false)?;
|
insert_activity(&conn, user.id, &dislike, false)?;
|
||||||
|
|
||||||
|
@ -501,7 +501,7 @@ fn receive_delete_community(
|
||||||
.into_concrete::<GroupExt>()?;
|
.into_concrete::<GroupExt>()?;
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &delete, false)?;
|
insert_activity(&conn, user.id, &delete, false)?;
|
||||||
|
|
||||||
|
@ -563,7 +563,7 @@ fn receive_remove_community(
|
||||||
.into_concrete::<GroupExt>()?;
|
.into_concrete::<GroupExt>()?;
|
||||||
|
|
||||||
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
||||||
verify(request, &mod_.public_key.unwrap())?;
|
verify(request, &mod_)?;
|
||||||
|
|
||||||
insert_activity(&conn, mod_.id, &remove, false)?;
|
insert_activity(&conn, mod_.id, &remove, false)?;
|
||||||
|
|
||||||
|
@ -625,7 +625,7 @@ fn receive_delete_post(
|
||||||
.into_concrete::<PageExt>()?;
|
.into_concrete::<PageExt>()?;
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &delete, false)?;
|
insert_activity(&conn, user.id, &delete, false)?;
|
||||||
|
|
||||||
|
@ -689,7 +689,7 @@ fn receive_remove_post(
|
||||||
.into_concrete::<PageExt>()?;
|
.into_concrete::<PageExt>()?;
|
||||||
|
|
||||||
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
||||||
verify(request, &mod_.public_key.unwrap())?;
|
verify(request, &mod_)?;
|
||||||
|
|
||||||
insert_activity(&conn, mod_.id, &remove, false)?;
|
insert_activity(&conn, mod_.id, &remove, false)?;
|
||||||
|
|
||||||
|
@ -753,7 +753,7 @@ fn receive_delete_comment(
|
||||||
.into_concrete::<Note>()?;
|
.into_concrete::<Note>()?;
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &delete, false)?;
|
insert_activity(&conn, user.id, &delete, false)?;
|
||||||
|
|
||||||
|
@ -814,7 +814,7 @@ fn receive_remove_comment(
|
||||||
.into_concrete::<Note>()?;
|
.into_concrete::<Note>()?;
|
||||||
|
|
||||||
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
||||||
verify(request, &mod_.public_key.unwrap())?;
|
verify(request, &mod_)?;
|
||||||
|
|
||||||
insert_activity(&conn, mod_.id, &remove, false)?;
|
insert_activity(&conn, mod_.id, &remove, false)?;
|
||||||
|
|
||||||
|
@ -935,7 +935,7 @@ fn receive_undo_delete_comment(
|
||||||
.into_concrete::<Note>()?;
|
.into_concrete::<Note>()?;
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &delete, false)?;
|
insert_activity(&conn, user.id, &delete, false)?;
|
||||||
|
|
||||||
|
@ -996,7 +996,7 @@ fn receive_undo_remove_comment(
|
||||||
.into_concrete::<Note>()?;
|
.into_concrete::<Note>()?;
|
||||||
|
|
||||||
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
||||||
verify(request, &mod_.public_key.unwrap())?;
|
verify(request, &mod_)?;
|
||||||
|
|
||||||
insert_activity(&conn, mod_.id, &remove, false)?;
|
insert_activity(&conn, mod_.id, &remove, false)?;
|
||||||
|
|
||||||
|
@ -1057,7 +1057,7 @@ fn receive_undo_delete_post(
|
||||||
.into_concrete::<PageExt>()?;
|
.into_concrete::<PageExt>()?;
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &delete, false)?;
|
insert_activity(&conn, user.id, &delete, false)?;
|
||||||
|
|
||||||
|
@ -1121,7 +1121,7 @@ fn receive_undo_remove_post(
|
||||||
.into_concrete::<PageExt>()?;
|
.into_concrete::<PageExt>()?;
|
||||||
|
|
||||||
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
||||||
verify(request, &mod_.public_key.unwrap())?;
|
verify(request, &mod_)?;
|
||||||
|
|
||||||
insert_activity(&conn, mod_.id, &remove, false)?;
|
insert_activity(&conn, mod_.id, &remove, false)?;
|
||||||
|
|
||||||
|
@ -1185,7 +1185,7 @@ fn receive_undo_delete_community(
|
||||||
.into_concrete::<GroupExt>()?;
|
.into_concrete::<GroupExt>()?;
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &delete, false)?;
|
insert_activity(&conn, user.id, &delete, false)?;
|
||||||
|
|
||||||
|
@ -1247,7 +1247,7 @@ fn receive_undo_remove_community(
|
||||||
.into_concrete::<GroupExt>()?;
|
.into_concrete::<GroupExt>()?;
|
||||||
|
|
||||||
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
||||||
verify(request, &mod_.public_key.unwrap())?;
|
verify(request, &mod_)?;
|
||||||
|
|
||||||
insert_activity(&conn, mod_.id, &remove, false)?;
|
insert_activity(&conn, mod_.id, &remove, false)?;
|
||||||
|
|
||||||
|
@ -1334,7 +1334,7 @@ fn receive_undo_like_comment(
|
||||||
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &like, false)?;
|
insert_activity(&conn, user.id, &like, false)?;
|
||||||
|
|
||||||
|
@ -1384,7 +1384,7 @@ fn receive_undo_like_post(
|
||||||
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &like, false)?;
|
insert_activity(&conn, user.id, &like, false)?;
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,10 @@ impl ActorType for User_ {
|
||||||
self.public_key.to_owned().unwrap()
|
self.public_key.to_owned().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn private_key(&self) -> String {
|
||||||
|
self.private_key.to_owned().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
/// As a given local user, send out a follow request to a remote community.
|
/// As a given local user, send out a follow request to a remote community.
|
||||||
fn send_follow(&self, follow_actor_id: &str, conn: &PgConnection) -> Result<(), Error> {
|
fn send_follow(&self, follow_actor_id: &str, conn: &PgConnection) -> Result<(), Error> {
|
||||||
let mut follow = Follow::new();
|
let mut follow = Follow::new();
|
||||||
|
@ -75,12 +79,7 @@ impl ActorType for User_ {
|
||||||
|
|
||||||
insert_activity(&conn, self.id, &follow, true)?;
|
insert_activity(&conn, self.id, &follow, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&follow, self, vec![to])?;
|
||||||
&follow,
|
|
||||||
&self.private_key.as_ref().unwrap(),
|
|
||||||
&follow_actor_id,
|
|
||||||
vec![to],
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,12 +115,7 @@ impl ActorType for User_ {
|
||||||
|
|
||||||
insert_activity(&conn, self.id, &undo, true)?;
|
insert_activity(&conn, self.id, &undo, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&undo, self, vec![to])?;
|
||||||
&undo,
|
|
||||||
&self.private_key.as_ref().unwrap(),
|
|
||||||
&follow_actor_id,
|
|
||||||
vec![to],
|
|
||||||
)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ fn receive_accept(
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let community = get_or_fetch_and_upsert_remote_community(&community_uri, conn)?;
|
let community = get_or_fetch_and_upsert_remote_community(&community_uri, conn)?;
|
||||||
verify(request, &community.public_key.unwrap())?;
|
verify(request, &community)?;
|
||||||
|
|
||||||
let user = User_::read_from_name(&conn, username)?;
|
let user = User_::read_from_name(&conn, username)?;
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ fn receive_create_private_message(
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &create, false)?;
|
insert_activity(&conn, user.id, &create, false)?;
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ fn receive_update_private_message(
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &update, false)?;
|
insert_activity(&conn, user.id, &update, false)?;
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ fn receive_delete_private_message(
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &delete, false)?;
|
insert_activity(&conn, user.id, &delete, false)?;
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ fn receive_undo_delete_private_message(
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user)?;
|
||||||
|
|
||||||
insert_activity(&conn, user.id, &delete, false)?;
|
insert_activity(&conn, user.id, &delete, false)?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue