Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Encryption #59

Merged
merged 2 commits into from
Mar 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{

use app_dirs::{AppDataType, AppDirsError};
use log::LevelFilter;
use rand::Rng;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Configuration {
Expand Down Expand Up @@ -49,8 +50,8 @@ impl Default for Configuration {
},
encryption: Encryption {
enabled: false,
private_key: String::new(),
iv: String::new(),
private_key: hex::encode(rand::thread_rng().gen::<[u8; 24]>()),
iv: hex::encode(rand::thread_rng().gen::<[u8; 16]>()),
},
webui: WebUI { enabled: false },
store: Store { max_limit: 7340032 },
Expand Down
16 changes: 12 additions & 4 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@ impl Server {

let mut encryption_key = None;
if configuration.encryption.enabled {
encryption_key = Some([
configuration.encryption.private_key.as_str(),
configuration.encryption.iv.as_str(),
]);
if configuration.encryption.private_key.is_empty() {
panic!("The private key must be filled.");
}
else if configuration.encryption.iv.is_empty() {
panic!("The initialization vector must be filled.")
}
else {
encryption_key = Some([
configuration.encryption.private_key.as_str(),
configuration.encryption.iv.as_str(),
]);
}
}
let store = Arc::new(KvStore::new(encryption_key));
let store = warp::any().map(move || store.clone());
Expand Down