Skip to content

Commit

Permalink
Merge pull request #59 from lucid-kv/improve-encryption
Browse files Browse the repository at this point in the history
Improve Encryption
  • Loading branch information
Clint.Network authored Mar 1, 2020
2 parents e6788a2 + ac350f9 commit d5c80d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
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

0 comments on commit d5c80d5

Please sign in to comment.