6 use openssl::{pkey::PKey, rsa::Rsa};
8 use actix_web::body::Body;
9 use actix_web::HttpResponse;
12 fn create_apub_response<T>(json: &T) -> HttpResponse<Body>
14 T: serde::ser::Serialize,
17 .content_type("application/activity+json")
21 pub enum EndpointType {
27 pub fn make_apub_endpoint(endpoint_type: EndpointType, name: &str) -> Url {
28 let point = match endpoint_type {
29 EndpointType::Community => "c",
30 EndpointType::User => "u",
31 EndpointType::Post => "p",
35 "{}://{}/federation/{}/{}",
36 get_apub_protocol_string(),
37 Settings::get().hostname,
44 pub fn get_apub_protocol_string() -> &'static str {
45 if Settings::get().federation.tls_enabled {
52 pub fn gen_keypair() -> (Vec<u8>, Vec<u8>) {
53 let rsa = Rsa::generate(2048).expect("sign::gen_keypair: key generation error");
54 let pkey = PKey::from_rsa(rsa).expect("sign::gen_keypair: parsing error");
58 .expect("sign::gen_keypair: public key encoding error"),
60 .private_key_to_pem_pkcs8()
61 .expect("sign::gen_keypair: private key encoding error"),
65 pub fn gen_keypair_str() -> (String, String) {
66 let (public_key, private_key) = gen_keypair();
67 (vec_bytes_to_str(public_key), vec_bytes_to_str(private_key))
70 fn vec_bytes_to_str(bytes: Vec<u8>) -> String {
71 String::from_utf8_lossy(&bytes).into_owned()