Commit aa8b2d08 authored by Stephane Glondu's avatar Stephane Glondu

Booth: smoother encryption phase

parent 0981411b
......@@ -112,6 +112,7 @@ let () = dispatch & function
copy_rule "belenios-tool.js" "src/tool/tool_js.js" "src/static/tool_js.js";
copy_rule "belenios-tool.html" "src/tool/belenios-tool.html" "src/static/belenios-tool.html";
copy_rule "encrypting.gif" "ext/booth/encrypting.gif" "src/static/encrypting.gif";
copy_rule "booth.js" "src/booth/booth.js" "src/static/booth.js";
copy_rule "vote.html" "src/booth/vote.html" "src/static/vote.html";
......
......@@ -77,10 +77,26 @@ let setNodeById id x =
let setDisplayById id x =
withElementById id (fun e -> e##style##display <- Js.string x)
let prng = lazy (pseudo_rng (random_string secure_rng 16))
module MakeLwtJsMonad (G : GROUP) = struct
type 'a t = unit -> 'a Lwt.t
let return x () = Lwt.return x
let bind x f () = Lwt.bind (x ()) (fun y -> f y ())
let fail x () = Lwt.fail x
let random q =
let size = Z.bit_length q / 8 + 1 in
fun () ->
lwt () = Lwt_js.yield () in
let r = random_string (Lazy.force prng) size in
Lwt.return Z.(of_bits r mod q)
end
let encryptBallot params cred plaintext () =
let module P = (val params : ELECTION_PARAMS) in
let module G = P.G in
let module M = Election.MakeSimpleMonad (G) in
let module M = MakeLwtJsMonad (G) in
let module E = Election.MakeElection (G) (M) in
let e = {
e_params = P.params;
......@@ -91,12 +107,15 @@ let encryptBallot params cred plaintext () =
let hex = derive_cred P.params.e_uuid cred in
Z.(of_string_base 16 hex mod G.q)
in
let b = E.create_ballot e ~sk (E.make_randomness e ()) plaintext () in
lwt randomness = E.make_randomness e () in
lwt b = E.create_ballot e ~sk randomness plaintext () in
let s = string_of_ballot G.write b in
setTextarea "ballot" s;
setNodeById "ballot_tracker" (sha256_b64 s);
setDisplayById "encrypting_div" "none";
setDisplayById "ballot_div" "block";
Dom_html.window##onbeforeunload <- Dom_html.no_handler
Dom_html.window##onbeforeunload <- Dom_html.no_handler;
Lwt.return ()
let rec createQuestionNode sk params question_div num_questions i prev (q, answers) next =
(* Create div element for the current question. [i] and [(q,
......@@ -207,7 +226,7 @@ let rec createQuestionNode sk params question_div num_questions i prev (q, answe
Dom.appendChild e ul;
) all_answers
);
installHandler "encrypt" (encryptBallot params sk all_answers);
Lwt_js_events.async (encryptBallot params sk all_answers);
setDisplayById "plaintext_div" "block";
Js._false
);
......
......@@ -52,7 +52,10 @@
Plaintext raw ballot:
<div><textarea id="choices" rows="1" cols="80" readonly="readonly"></textarea></div>
</div>
<div><button id="encrypt">Confirm and encrypt</button></div>
<div id="encrypting_div">
Please wait while your ballot is being encrypted...
<img src="encrypting.gif"/>
</div>
<div id="ballot_div" style="display:none;">
<form id="ballot_form" method="POST">
<div style="display:none;">
......@@ -64,11 +67,11 @@
<p>
Your ballot has been successfully encrypted!
Your smart ballot tracker is <span id="ballot_tracker"></span>.
Refresh this page to start again from the beginning.
</p>
<input type="submit" value="Submit"/>
<input type="submit" value="Confirm and submit"/>
</form>
</div>
<button onclick="location.reload();">Cancel</button>
</div>
</div>
</body>
......
......@@ -3,4 +3,5 @@ jsbn.js
jsbn2.js
random.js
booth.js
encrypting.gif
vote.html
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment