6 use openssl::{pkey::PKey, rsa::Rsa};
8 use activitystreams::actor::{properties::ApActorProperties, Group};
9 use activitystreams::ext::Ext;
10 use actix_web::body::Body;
11 use actix_web::HttpResponse;
14 type GroupExt = Ext<Group, ApActorProperties>;
16 fn create_apub_response<T>(json: &T) -> HttpResponse<Body>
18 T: serde::ser::Serialize,
21 .content_type("application/activity+json")
25 pub enum EndpointType {
31 pub fn make_apub_endpoint(endpoint_type: EndpointType, name: &str) -> Url {
32 let point = match endpoint_type {
33 EndpointType::Community => "c",
34 EndpointType::User => "u",
35 EndpointType::Post => "p",
39 "{}://{}/federation/{}/{}",
40 get_apub_protocol_string(),
41 Settings::get().hostname,
48 pub fn get_apub_protocol_string() -> &'static str {
49 if Settings::get().federation.tls_enabled {
56 pub fn gen_keypair() -> (Vec<u8>, Vec<u8>) {
57 let rsa = Rsa::generate(2048).expect("sign::gen_keypair: key generation error");
58 let pkey = PKey::from_rsa(rsa).expect("sign::gen_keypair: parsing error");
62 .expect("sign::gen_keypair: public key encoding error"),
64 .private_key_to_pem_pkcs8()
65 .expect("sign::gen_keypair: private key encoding error"),
69 pub fn gen_keypair_str() -> (String, String) {
70 let (public_key, private_key) = gen_keypair();
71 (vec_bytes_to_str(public_key), vec_bytes_to_str(private_key))
74 fn vec_bytes_to_str(bytes: Vec<u8>) -> String {
75 String::from_utf8_lossy(&bytes).into_owned()