✖️ replace pgp crate

This commit is contained in:
JMARyA 2022-11-14 22:07:09 +01:00
parent 31c20fff10
commit 4ddadfdce9
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
6 changed files with 30 additions and 704 deletions

View file

@ -1,19 +1,11 @@
use pgp::crypto::SymmetricKeyAlgorithm;
use pgp::{Deserializable, Message, SignedPublicKey};
use std::io::Write;
pub fn encrypt(msg: String) -> String {
// err: Encryption is done twice
let pub_key =
SignedPublicKey::from_string(&*std::fs::read_to_string("/config/pub.key").unwrap())
.unwrap()
.0;
let mut rng = rand::thread_rng();
let c = Message::new_literal("msg", &msg)
.encrypt_to_keys(&mut rng, SymmetricKeyAlgorithm::AES128, &[&pub_key])
.unwrap()
.to_armored_string(None)
let pgp = gnupg::GnuPG::new().unwrap();
let pub_key = pgp
.import_key(&std::fs::read_to_string("/config/pub.key").unwrap())
.unwrap();
let c = pgp.encrypt(&pub_key, &msg).unwrap();
return c;
}

View file

@ -13,8 +13,7 @@ pub struct MessageForm {
#[post("/message")]
pub async fn message_post(r: HttpRequest, f: Form<MessageForm>) -> impl Responder {
let config: &web::Data<config::Config> = r.app_data().unwrap();
let cipher = crate::msg::encrypt(f.message.to_string());
crate::msg::save_msg(cipher, &f.msg_name.to_string());
crate::msg::save_msg(f.message.clone(), &f.msg_name.to_string());
crate::notification::notify(
&format!("New Message from {}", f.msg_name.to_string()),
"New Message",