1 use crate::settings::Settings;
2 use openssl::{pkey::PKey, rsa::Rsa};
3 use std::io::{Error, ErrorKind};
7 pub private_key: String,
8 pub public_key: String,
11 /// Generate the asymmetric keypair for ActivityPub HTTP signatures.
12 pub fn generate_actor_keypair() -> Result<Keypair, Error> {
13 let rsa = Rsa::generate(2048)?;
14 let pkey = PKey::from_rsa(rsa)?;
15 let public_key = pkey.public_key_to_pem()?;
16 let private_key = pkey.private_key_to_pem_pkcs8()?;
17 let key_to_string = |key| match String::from_utf8(key) {
19 Err(e) => Err(Error::new(
21 format!("Failed converting key to string: {}", e),
25 private_key: key_to_string(private_key)?,
26 public_key: key_to_string(public_key)?,
30 pub enum EndpointType {
38 pub fn get_apub_protocol_string() -> &'static str {
39 if Settings::get().federation.tls_enabled {
46 /// Generates the ActivityPub ID for a given object type and ID.
47 pub fn make_apub_endpoint(endpoint_type: EndpointType, name: &str) -> Url {
48 let point = match endpoint_type {
49 EndpointType::Community => "c",
50 EndpointType::User => "u",
51 EndpointType::Post => "post",
52 EndpointType::Comment => "comment",
53 EndpointType::PrivateMessage => "private_message",
58 get_apub_protocol_string(),
59 Settings::get().hostname,