Remove dependency on activitypub module from config::main

This commit is contained in:
silverpill 2023-02-07 18:28:19 +00:00
parent 8289aeaf41
commit eeae9e3ad7
6 changed files with 25 additions and 27 deletions

View file

@ -8,11 +8,15 @@ use serde_json::{json, Value};
use crate::activitypub::{
constants::{
ACTOR_KEY_SUFFIX,
AP_CONTEXT,
W3ID_SECURITY_CONTEXT,
},
identifiers::{local_actor_id, LocalActorCollection},
identifiers::{
local_actor_id,
local_actor_key_id,
local_instance_actor_id,
LocalActorCollection,
},
receiver::parse_property_value,
vocabulary::{IDENTITY_PROOF, IMAGE, LINK, PERSON, PROPERTY_VALUE, SERVICE},
};
@ -259,7 +263,7 @@ pub fn get_local_actor(
let private_key = deserialize_private_key(&user.private_key)?;
let public_key_pem = get_public_key_pem(&private_key)?;
let public_key = PublicKey {
id: format!("{}{}", actor_id, ACTOR_KEY_SUFFIX),
id: local_actor_key_id(&actor_id),
owner: actor_id.clone(),
public_key_pem: public_key_pem,
};
@ -332,12 +336,12 @@ pub fn get_local_actor(
pub fn get_instance_actor(
instance: &Instance,
) -> Result<Actor, ActorKeyError> {
let actor_id = instance.actor_id();
let actor_id = local_instance_actor_id(&instance.url());
let actor_inbox = LocalActorCollection::Inbox.of(&actor_id);
let actor_outbox = LocalActorCollection::Outbox.of(&actor_id);
let public_key_pem = get_public_key_pem(&instance.actor_key)?;
let public_key = PublicKey {
id: instance.actor_key_id(),
id: local_actor_key_id(&actor_id),
owner: actor_id.clone(),
public_key_pem: public_key_pem,
};

View file

@ -7,5 +7,3 @@ pub const AP_CONTEXT: &str = "https://www.w3.org/ns/activitystreams";
pub const AP_PUBLIC: &str = "https://www.w3.org/ns/activitystreams#Public";
pub const W3ID_SECURITY_CONTEXT: &str = "https://w3id.org/security/v1";
pub const W3ID_DATA_INTEGRITY_CONTEXT: &str = "https://w3id.org/security/data-integrity/v1";
pub const ACTOR_KEY_SUFFIX: &str = "#main-key";

View file

@ -30,8 +30,8 @@ use crate::models::{
};
use crate::utils::crypto_rsa::deserialize_private_key;
use super::actors::types::Actor;
use super::constants::{AP_MEDIA_TYPE, ACTOR_KEY_SUFFIX};
use super::identifiers::local_actor_id;
use super::constants::AP_MEDIA_TYPE;
use super::identifiers::{local_actor_id, local_actor_key_id};
use super::queues::OutgoingActivityJobData;
#[derive(thiserror::Error, Debug)]
@ -136,14 +136,11 @@ async fn deliver_activity_worker(
recipients: Vec<Recipient>,
) -> Result<(), DelivererError> {
let actor_key = deserialize_private_key(&sender.private_key)?;
let actor_key_id = format!(
"{}{}",
local_actor_id(
let actor_id = local_actor_id(
&instance.url(),
&sender.profile.username,
),
ACTOR_KEY_SUFFIX,
);
let actor_key_id = local_actor_key_id(&actor_id);
let activity_signed = if is_object_signed(&activity) {
log::warn!("activity is already signed");
activity

View file

@ -7,6 +7,7 @@ use serde_json::Value;
use crate::activitypub::{
actors::types::Actor,
constants::AP_MEDIA_TYPE,
identifiers::{local_actor_key_id, local_instance_actor_id},
types::Object,
};
use crate::config::Instance;
@ -90,12 +91,14 @@ async fn send_request(
};
if !instance.is_private {
// Only public instance can send signed request
let instance_actor_id = local_instance_actor_id(&instance.url());
let instance_actor_key_id = local_actor_key_id(&instance_actor_id);
let headers = create_http_signature(
Method::GET,
url,
"",
&instance.actor_key,
&instance.actor_key_id(),
&instance_actor_key_id,
)?;
request_builder = request_builder
.header("Host", headers.host)

View file

@ -3,6 +3,8 @@ use uuid::Uuid;
use crate::errors::ValidationError;
const ACTOR_KEY_SUFFIX: &str = "#main-key";
pub enum LocalActorCollection {
Inbox,
Outbox,
@ -58,6 +60,10 @@ pub fn local_instance_actor_id(instance_url: &str) -> String {
format!("{}/actor", instance_url)
}
pub fn local_actor_key_id(actor_id: &str) -> String {
format!("{}{}", actor_id, ACTOR_KEY_SUFFIX)
}
pub fn local_object_id(instance_url: &str, internal_object_id: &Uuid) -> String {
format!("{}/objects/{}", instance_url, internal_object_id)
}

View file

@ -9,8 +9,6 @@ use serde::{
};
use url::Url;
use crate::activitypub::constants::ACTOR_KEY_SUFFIX;
use crate::activitypub::identifiers::local_instance_actor_id;
use crate::utils::urls::guess_protocol;
use super::blockchain::BlockchainConfig;
@ -183,14 +181,6 @@ impl Instance {
self._url.host_str().unwrap().to_string()
}
pub fn actor_id(&self) -> String {
local_instance_actor_id(&self.url())
}
pub fn actor_key_id(&self) -> String {
format!("{}{}", self.actor_id(), ACTOR_KEY_SUFFIX)
}
pub fn agent(&self) -> String {
format!(
"Mitra {version}; {instance_url}",