summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2017-01-16 20:07:50 +0700
committerDaniil Baturin <daniil@baturin.org>2017-01-16 20:07:50 +0700
commitf8b5879fed1d5185a931206fd2784825567947ae (patch)
tree10de3a49238bb835fc1622df74ea013cb3fa461d /src
parent1032bd5008dace98bd1c8910f8b586658646568b (diff)
downloadvyconf-f8b5879fed1d5185a931206fd2784825567947ae.tar.gz
vyconf-f8b5879fed1d5185a931206fd2784825567947ae.zip
Add a function for making secure session tokens.
Right now it uses a SHA-1 sum of 30 random bits. I hope that's secure enough.
Diffstat (limited to 'src')
-rw-r--r--src/vyconfd.ml7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/vyconfd.ml b/src/vyconfd.ml
index f8dde8c..0e3340f 100644
--- a/src/vyconfd.ml
+++ b/src/vyconfd.ml
@@ -2,6 +2,9 @@ open Lwt
open Defaults
open Vyconf_config
+(* On UNIX, self_init uses /dev/random for seed *)
+let () = Random.self_init ()
+
let () = Lwt_log.add_rule "*" Lwt_log.Info
(* Default VyConf configuration *)
@@ -11,6 +14,7 @@ let log_file = ref None
(* Global data *)
+
(* Command line arguments *)
let args = [
("--no-daemon", Arg.Unit (fun () -> daemonize := false),
@@ -23,6 +27,9 @@ let args = [
]
let usage = "Usage: " ^ Sys.argv.(0) ^ " [options]"
+let make_session_token () =
+ Sha1.string (string_of_int (Random.bits ())) |> Sha1.to_hex
+
let rec handle_connection ic oc () =
let open Vyconf_pb in
try%lwt