let default_listing_type = data.default_listing_type;
let default_sort_type = data.default_sort_type;
let password_encrypted = local_user_view.local_user.password_encrypted;
+ let public_key = local_user_view.person.public_key;
let person_form = PersonForm {
name: local_user_view.person.name,
local: None,
admin: None,
private_key: None,
- public_key: None,
+ public_key,
last_refreshed_at: None,
shared_inbox_url: None,
matrix_user_id,
banner,
nsfw: data.nsfw,
actor_id: Some(community_actor_id.to_owned()),
- private_key: Some(keypair.private_key),
- public_key: Some(keypair.public_key),
+ private_key: Some(Some(keypair.private_key)),
+ public_key: keypair.public_key,
followers_url: Some(generate_followers_url(&community_actor_id)?),
inbox_url: Some(generate_inbox_url(&community_actor_id)?),
shared_inbox_url: Some(Some(generate_shared_inbox_url(&community_actor_id)?)),
name: read_community.name,
title: data.title.to_owned().unwrap_or(read_community.title),
description: data.description.to_owned(),
+ public_key: read_community.public_key,
icon,
banner,
nsfw: data.nsfw,
name: data.username.to_owned(),
actor_id: Some(actor_id.clone()),
private_key: Some(Some(actor_keypair.private_key)),
- public_key: Some(Some(actor_keypair.public_key)),
+ public_key: actor_keypair.public_key,
inbox_url: Some(generate_inbox_url(&actor_id)?),
shared_inbox_url: Some(Some(generate_shared_inbox_url(&actor_id)?)),
admin: Some(no_admins),
title: "The Default Community".to_string(),
description: Some("The Default Community".to_string()),
actor_id: Some(actor_id.to_owned()),
- private_key: Some(main_community_keypair.private_key),
- public_key: Some(main_community_keypair.public_key),
+ private_key: Some(Some(main_community_keypair.private_key)),
+ public_key: main_community_keypair.public_key,
followers_url: Some(generate_followers_url(&actor_id)?),
inbox_url: Some(generate_inbox_url(&actor_id)?),
shared_inbox_url: Some(Some(generate_shared_inbox_url(&actor_id)?)),
}
}
- fn public_key(&self) -> Option<String> {
+ fn public_key(&self) -> String {
match self {
UserOrCommunity::User(p) => p.public_key(),
UserOrCommunity::Community(p) => p.public_key(),
let actor = ObjectId::<UserOrCommunity>::new(activity_data.actor)
.dereference(context, request_counter)
.await?;
- verify_signature(&request, &actor.public_key().context(location_info!())?)?;
+ verify_signature(&request, &actor.public_key())?;
// Do nothing if we received the same activity before
if is_activity_already_known(context.pool(), &activity_data.id).await? {
fn actor_id(&self) -> Url {
self.actor_id.to_owned().into()
}
- fn public_key(&self) -> Option<String> {
+ fn public_key(&self) -> String {
self.public_key.to_owned()
}
fn private_key(&self) -> Option<String> {
let community = parse_lemmy_community(&context).await;
assert_eq!(community.title, "Ten Forward");
- assert!(community.public_key.is_some());
assert!(!community.local);
assert_eq!(community.description.as_ref().unwrap().len(), 132);
admin: Some(false),
bot_account: Some(person.kind == UserTypes::Service),
private_key: None,
- public_key: Some(Some(person.public_key.public_key_pem)),
+ public_key: person.public_key.public_key_pem,
last_refreshed_at: Some(naive_now()),
inbox_url: Some(person.inbox.into()),
shared_inbox_url: Some(person.endpoints.shared_inbox.map(|s| s.into())),
self.actor_id.to_owned().into()
}
- fn public_key(&self) -> Option<String> {
+ fn public_key(&self) -> String {
self.public_key.to_owned()
}
let person = parse_lemmy_person(&context).await;
assert_eq!(person.display_name, Some("Jean-Luc Picard".to_string()));
- assert!(person.public_key.is_some());
assert!(!person.local);
assert_eq!(person.bio.as_ref().unwrap().len(), 39);
assert_eq!(person.actor_id, url.into());
assert_eq!(person.name, "lanodan");
- assert!(person.public_key.is_some());
assert!(!person.local);
assert_eq!(request_counter, 0);
assert_eq!(person.bio.as_ref().unwrap().len(), 873);
actor_id: Some(self.id.into()),
local: Some(false),
private_key: None,
- public_key: Some(self.public_key.public_key_pem),
+ public_key: self.public_key.public_key_pem,
last_refreshed_at: Some(naive_now()),
icon: Some(self.icon.map(|i| i.url.into())),
banner: Some(self.image.map(|i| i.url.into())),
use crate::{data::Data, signatures::PublicKey};
use activitystreams::chrono::NaiveDateTime;
-use anyhow::Context;
pub use lemmy_apub_lib_derive::*;
-use lemmy_utils::{location_info, LemmyError};
+use lemmy_utils::LemmyError;
use url::Url;
#[async_trait::async_trait(?Send)]
pub trait ActorType {
fn actor_id(&self) -> Url;
- // TODO: this should not be an option (needs db migration in lemmy)
- fn public_key(&self) -> Option<String>;
+ fn public_key(&self) -> String;
fn private_key(&self) -> Option<String>;
fn inbox_url(&self) -> Url;
Ok(PublicKey {
id: format!("{}#main-key", self.actor_id()),
owner: Box::new(self.actor_id()),
- public_key_pem: self.public_key().context(location_info!())?,
+ public_key_pem: self.public_key(),
})
}
}
let new_community = CommunityForm {
name: "TIL".into(),
title: "nada".to_owned(),
+ public_key: "nada".to_owned(),
..CommunityForm::default()
};
actor_id: inserted_community.actor_id.to_owned(),
local: true,
private_key: None,
- public_key: None,
+ public_key: "nada".to_owned(),
last_refreshed_at: inserted_community.published,
icon: None,
banner: None,
let new_person = PersonForm {
name: "holly".into(),
+ public_key: "nada".to_owned(),
..PersonForm::default()
};
bot_account: false,
admin: false,
private_key: None,
- public_key: None,
+ public_key: "nada".to_owned(),
last_refreshed_at: inserted_person.published,
inbox_url: inserted_person.inbox_url.to_owned(),
shared_inbox_url: None,
actor_id -> Varchar,
local -> Bool,
private_key -> Nullable<Text>,
- public_key -> Nullable<Text>,
+ public_key -> Text,
last_refreshed_at -> Timestamp,
icon -> Nullable<Varchar>,
banner -> Nullable<Varchar>,
bio -> Nullable<Text>,
local -> Bool,
private_key -> Nullable<Text>,
- public_key -> Nullable<Text>,
+ public_key -> Text,
last_refreshed_at -> Timestamp,
banner -> Nullable<Varchar>,
deleted -> Bool,
bio -> Nullable<Text>,
local -> Bool,
private_key -> Nullable<Text>,
- public_key -> Nullable<Text>,
+ public_key -> Text,
last_refreshed_at -> Timestamp,
banner -> Nullable<Varchar>,
deleted -> Bool,
bio -> Nullable<Text>,
local -> Bool,
private_key -> Nullable<Text>,
- public_key -> Nullable<Text>,
+ public_key -> Text,
last_refreshed_at -> Timestamp,
banner -> Nullable<Varchar>,
deleted -> Bool,
pub actor_id: DbUrl,
pub local: bool,
pub private_key: Option<String>,
- pub public_key: Option<String>,
+ pub public_key: String,
pub last_refreshed_at: chrono::NaiveDateTime,
pub icon: Option<DbUrl>,
pub banner: Option<DbUrl>,
pub nsfw: Option<bool>,
pub actor_id: Option<DbUrl>,
pub local: Option<bool>,
- pub private_key: Option<String>,
- pub public_key: Option<String>,
+ pub private_key: Option<Option<String>>,
+ pub public_key: String,
pub last_refreshed_at: Option<chrono::NaiveDateTime>,
pub icon: Option<Option<DbUrl>>,
pub banner: Option<Option<DbUrl>>,
pub bio: Option<String>,
pub local: bool,
pub private_key: Option<String>,
- pub public_key: Option<String>,
+ pub public_key: String,
pub last_refreshed_at: chrono::NaiveDateTime,
pub banner: Option<DbUrl>,
pub deleted: bool,
pub bio: Option<String>,
pub local: bool,
pub private_key: Option<String>,
- pub public_key: Option<String>,
+ pub public_key: String,
pub last_refreshed_at: chrono::NaiveDateTime,
pub banner: Option<DbUrl>,
pub deleted: bool,
pub bio: Option<String>,
pub local: bool,
pub private_key: Option<String>,
- pub public_key: Option<String>,
+ pub public_key: String,
pub last_refreshed_at: chrono::NaiveDateTime,
pub banner: Option<DbUrl>,
pub deleted: bool,
pub bio: Option<Option<String>>,
pub local: Option<bool>,
pub private_key: Option<Option<String>>,
- pub public_key: Option<Option<String>>,
+ pub public_key: String,
pub last_refreshed_at: Option<chrono::NaiveDateTime>,
pub banner: Option<Option<DbUrl>>,
pub deleted: Option<bool>,
--- /dev/null
+alter table community alter column public_key drop not null;
+alter table person alter column public_key drop not null;
--- /dev/null
+-- Delete the empty public keys
+delete from community where public_key is null;
+delete from person where public_key is null;
+
+-- Make it required
+alter table community alter column public_key set not null;
+alter table person alter column public_key set not null;
protocol_and_hostname,
)?),
private_key: Some(Some(keypair.private_key)),
- public_key: Some(Some(keypair.public_key)),
+ public_key: keypair.public_key,
last_refreshed_at: Some(naive_now()),
..PersonForm::default()
};
updated: None,
actor_id: Some(community_actor_id.to_owned()),
local: Some(ccommunity.local),
- private_key: Some(keypair.private_key),
- public_key: Some(keypair.public_key),
+ private_key: Some(Some(keypair.private_key)),
+ public_key: keypair.public_key,
last_refreshed_at: Some(naive_now()),
published: None,
icon: Some(ccommunity.icon.to_owned()),