Commit 2af23346 authored by Stephane Glondu's avatar Stephane Glondu

Threshold: client-side of key establishment protocol

parent ff595842
......@@ -6,6 +6,7 @@ src/static/placeholder.png
src/static/belenios-tool.html.otarget
src/static/vote.html.otarget
src/static/tool_js_tkeygen.js
src/static/tool_js_ttkeygen.js
src/static/tool_js_credgen.js
src/static/tool_js_questions.js
src/static/tool_js_pd.js
......@@ -132,6 +132,7 @@ let () = dispatch & function
copy_rule "booth.js" "src/booth/booth.js" "src/static/booth.js";
copy_rule "tool_js_tkeygen.js" "src/tool/tool_js_tkeygen.js" "src/static/tool_js_tkeygen.js";
copy_rule "tool_js_ttkeygen.js" "src/tool/tool_js_ttkeygen.js" "src/static/tool_js_ttkeygen.js";
copy_rule "tool_js_credgen.js" "src/tool/tool_js_credgen.js" "src/static/tool_js_credgen.js";
copy_rule "tool_js_questions.js" "src/tool/tool_js_questions.js" "src/static/tool_js_questions.js";
copy_rule "tool_js_pd.js" "src/tool/tool_js_pd.js" "src/static/tool_js_pd.js";
......
(**************************************************************************)
(* BELENIOS *)
(* *)
(* Copyright © 2012-2017 Inria *)
(* *)
(* This program is free software: you can redistribute it and/or modify *)
(* it under the terms of the GNU Affero General Public License as *)
(* published by the Free Software Foundation, either version 3 of the *)
(* License, or (at your option) any later version, with the additional *)
(* exemption that compiling, linking, and/or using OpenSSL is allowed. *)
(* *)
(* This program is distributed in the hope that it will be useful, but *)
(* WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *)
(* Affero General Public License for more details. *)
(* *)
(* You should have received a copy of the GNU Affero General Public *)
(* License along with this program. If not, see *)
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open Platform
open Serializable_j
open Signatures
open Common
open Tool_js_common
let gen_cert e _ =
let group = get_textarea "group" in
let module G = (val Group.of_string group : GROUP) in
let module P = Trustees.MakePKI (G) (DirectRandom) in
let module C = Trustees.MakeChannels (G) (DirectRandom) (P) in
let module T = Trustees.MakePedersen (G) (DirectRandom) (P) (C) in
let key, cert = T.step1 () in
let id = sha256_hex cert.s_message in
e##innerHTML <- Js.string "";
let t = document##createTextNode (Js.string (Printf.sprintf "Certificate %s has been generated!" id)) in
Dom.appendChild e t;
let data_uri = Js.string ("data:text/plain," ^ key) in
ignore (Dom_html.window##open_ (data_uri, Js.string id, Js.null));
let cert = string_of_cert cert in
set_textarea "data" cert;
alert "The private key has been open in a new window (or tab). Please save it before submitting the certificate!";
Js._false
let proceed step e textarea _ =
let group = get_textarea "group" in
let key =
let r = ref "" in
Js.Opt.iter (Dom_html.CoerceTo.textarea textarea) (fun x -> r := Js.to_string x##value);
!r
in
let certs = certs_of_string (get_textarea "certs") in
let threshold = int_of_string (get_textarea "threshold") in
let module G = (val Group.of_string group : GROUP) in
let module P = Trustees.MakePKI (G) (DirectRandom) in
let module C = Trustees.MakeChannels (G) (DirectRandom) (P) in
let module T = Trustees.MakePedersen (G) (DirectRandom) (P) (C) in
match step with
| 3 ->
let polynomial = T.step3 certs key threshold in
e##innerHTML <- Js.string "";
set_textarea "data" (string_of_polynomial polynomial);
Js._false
| 5 ->
let vinput = get_textarea "vinput" in
let vinput = vinput_of_string vinput in
let voutput = T.step5 certs key vinput in
e##innerHTML <- Js.string "";
set_textarea "data" (string_of_voutput G.write voutput);
Js._false
| _ ->
alert "Unexpected state!";
Js._false
let fill_interactivity _ =
Js.Opt.iter
(document##getElementById (Js.string "interactivity"))
(fun e ->
let step = int_of_string (get_textarea "step") in
match step with
| 0 ->
let t = document##createTextNode (Js.string "Waiting for the election administrator to set the threshold...") in
Dom.appendChild e t
| 2 | 4 | 6 ->
let t = document##createTextNode (Js.string "Waiting for the other trustees...") in
Dom.appendChild e t
| 7 ->
let t = document##createTextNode (Js.string "The key establishment protocol is finished!") in
Dom.appendChild e t
| 1 ->
let b = document##createElement (Js.string "button") in
let t = document##createTextNode (Js.string "Generate certificate") in
b##onclick <- Dom_html.handler (gen_cert e);
Dom.appendChild b t;
Dom.appendChild e b;
| 3 | 5 ->
let div = document##createElement (Js.string "div") in
let t = document##createTextNode (Js.string "Private key: ") in
Dom.appendChild div t;
let textarea = document##createElement (Js.string "textarea") in
Dom.appendChild div textarea;
Dom.appendChild e div;
let b = document##createElement (Js.string "button") in
let t = document##createTextNode (Js.string "Proceed") in
b##onclick <- Dom_html.handler (proceed step e textarea);
Dom.appendChild b t;
Dom.appendChild e b;
| _ ->
alert "Unexpected state!"
);
Js._false
let () =
Dom_html.window##onload <- Dom_html.handler fill_interactivity;
......@@ -1086,11 +1086,16 @@ let election_setup_threshold_trustee token uuid se () =
match x.stt_cert with
| None -> accu
| Some c -> c :: accu
) [] ts |> Array.of_list
) [] ts |> List.rev |> Array.of_list
in return {certs}
in
let threshold =
match se.se_threshold with
| None -> 0
| Some t -> t
in
let inputs =
div [
div ~a:[a_style "display:none;"] [
div [
pcdata "Step: ";
unsafe_textarea "step" (match trustee.stt_step with None -> "0" | Some x -> string_of_int x);
......@@ -1103,6 +1108,10 @@ let election_setup_threshold_trustee token uuid se () =
pcdata "Certificates: ";
unsafe_textarea "certs" (string_of_certs certs);
];
div [
pcdata "Threshold: ";
unsafe_textarea "threshold" (string_of_int threshold);
];
div [
pcdata "Vinput: ";
unsafe_textarea "vinput" (match trustee.stt_vinput with None -> "" | Some x -> string_of_vinput x);
......@@ -1117,16 +1126,28 @@ let election_setup_threshold_trustee token uuid se () =
div [
div [
pcdata "Data: ";
textarea ~name:data ();
textarea ~a:[a_id "data"] ~name:data ();
];
div [string_input ~input_type:`Submit ~value:"Submit" ()];
];
]
) token
in
let interactivity =
div
~a:[a_id "interactivity"]
[
script ~a:[a_src (uri_of_string (fun () -> "../static/sjcl.js"))] (pcdata "");
script ~a:[a_src (uri_of_string (fun () -> "../static/jsbn.js"))] (pcdata "");
script ~a:[a_src (uri_of_string (fun () -> "../static/jsbn2.js"))] (pcdata "");
script ~a:[a_src (uri_of_string (fun () -> "../static/random.js"))] (pcdata "");
script ~a:[a_src (uri_of_string (fun () -> "../static/tool_js_ttkeygen.js"))] (pcdata "");
]
in
let content = [
div_link;
inputs;
interactivity;
form;
]
in
......
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