about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2018-04-09T07·10+0200
committerVincent Ambo <tazjin@gmail.com>2018-04-09T07·10+0200
commitd91dec28f8aa1eacbcce697f232902ad09d79523 (patch)
tree0e9be05eb45d52f7788591fde105345f27ec693c /src
parentc07c46621960010b2a351f55a8255439362745f0 (diff)
fix(main): Generate random session key
Diffstat (limited to 'src')
-rw-r--r--src/main.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 2e2664a2cfe9..a68721729ac2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -19,6 +19,7 @@ extern crate chrono;
 extern crate env_logger;
 extern crate futures;
 extern crate r2d2;
+extern crate rand;
 extern crate reqwest;
 extern crate serde;
 extern crate url;
@@ -41,6 +42,7 @@ use db::*;
 use diesel::pg::PgConnection;
 use diesel::r2d2::{ConnectionManager, Pool};
 use std::env;
+use rand::{OsRng, Rng};
 use handlers::*;
 
 fn config(name: &str) -> String {
@@ -81,7 +83,14 @@ fn main() {
 
     info!("Initialising HTTP server ...");
     let bind_host = config_default("CONVERSE_BIND_HOST", "127.0.0.1:4567");
-    let key: &[u8] = &[0; 32]; // TODO: generate!
+    let key = {
+        let mut key_bytes = [0; 32];
+        let mut rng = OsRng::new()
+            .expect("Failed to retrieve RNG for key generation");
+        rng.fill_bytes(&mut key_bytes);
+
+        key_bytes
+    };
 
     server::new(move || {
         let template_path = concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*");