✖️ 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

700
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -11,8 +11,7 @@ actix-web = "4.2.1"
chrono = "0.4.22" chrono = "0.4.22"
env_logger = "0.9.3" env_logger = "0.9.3"
log = "0.4.17" log = "0.4.17"
pgp = "0.9.0" gnupg = { git = "https://git.hydrar.de/jmarya/gnupg-rs" }
rand = "0.8.5"
reqwest = "0.11.12" reqwest = "0.11.12"
serde = {version = "1.0.147", features = ["derive"] } serde = {version = "1.0.147", features = ["derive"] }
serde_json = "1.0.87" serde_json = "1.0.87"

View file

@ -1,17 +1,17 @@
FROM rust as builder FROM rust:buster as builder
COPY . /app COPY . /app
WORKDIR /app WORKDIR /app
RUN cargo build --release RUN cargo build --release
FROM ubuntu FROM debian
RUN apt-get update RUN apt-get update
RUN apt-get install -y gnupg RUN apt-get install -y gnupg ca-certificates
COPY --from=builder /app /app COPY --from=builder /app/target/release/me-site /app/me-site
WORKDIR /app WORKDIR /app
CMD ["/app/target/release/me-site"] CMD ["/app/me-site"]

View file

@ -6,7 +6,7 @@ services:
environment: environment:
TZ: Europe/Berlin TZ: Europe/Berlin
ports: ports:
- 1030:1030 - 1030:8080
volumes: volumes:
- ./config:/config - ./config:/config
- ./data:/data - ./data:/data

View file

@ -1,19 +1,11 @@
use pgp::crypto::SymmetricKeyAlgorithm;
use pgp::{Deserializable, Message, SignedPublicKey};
use std::io::Write; use std::io::Write;
pub fn encrypt(msg: String) -> String { pub fn encrypt(msg: String) -> String {
// err: Encryption is done twice let pgp = gnupg::GnuPG::new().unwrap();
let pub_key = let pub_key = pgp
SignedPublicKey::from_string(&*std::fs::read_to_string("/config/pub.key").unwrap()) .import_key(&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)
.unwrap(); .unwrap();
let c = pgp.encrypt(&pub_key, &msg).unwrap();
return c; return c;
} }

View file

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