fix(main): Generate random session key

This commit is contained in:
Vincent Ambo 2018-04-09 09:10:28 +02:00
parent c07c466219
commit d91dec28f8
3 changed files with 12 additions and 1 deletions

1
Cargo.lock generated
View file

@ -267,6 +267,7 @@ dependencies = [
"hyper 0.11.25 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.11.25 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"r2d2 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "r2d2 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -22,3 +22,4 @@ reqwest = "0.8"
frank_jwt = "3.0" frank_jwt = "3.0"
serde_json = "1.0" serde_json = "1.0"
hyper = "*" hyper = "*"
rand = "0.4"

View file

@ -19,6 +19,7 @@ extern crate chrono;
extern crate env_logger; extern crate env_logger;
extern crate futures; extern crate futures;
extern crate r2d2; extern crate r2d2;
extern crate rand;
extern crate reqwest; extern crate reqwest;
extern crate serde; extern crate serde;
extern crate url; extern crate url;
@ -41,6 +42,7 @@ use db::*;
use diesel::pg::PgConnection; use diesel::pg::PgConnection;
use diesel::r2d2::{ConnectionManager, Pool}; use diesel::r2d2::{ConnectionManager, Pool};
use std::env; use std::env;
use rand::{OsRng, Rng};
use handlers::*; use handlers::*;
fn config(name: &str) -> String { fn config(name: &str) -> String {
@ -81,7 +83,14 @@ fn main() {
info!("Initialising HTTP server ..."); info!("Initialising HTTP server ...");
let bind_host = config_default("CONVERSE_BIND_HOST", "127.0.0.1:4567"); 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 || { server::new(move || {
let template_path = concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*"); let template_path = concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*");