Commit 64c6fa24 authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Add "mkelection" subcommand, that creates election.json from a template

parent 3c1c605d
......@@ -22,7 +22,7 @@
let usage () =
let cmd = Sys.argv.(0) in
Printf.eprintf
"Usage: %s { trustee-keygen | election | credgen } [--help] [<args>]
"Usage: %s { trustee-keygen | election | credgen | mkelection } [--help] [<args>]
To get help for a specific command, run: %s <command> --help\n"
cmd cmd;
exit 1
......@@ -37,5 +37,6 @@ let () =
| "trustee-keygen" -> Tkeygen.main ()
| "election" -> Election_tool.main ()
| "credgen" -> Credgen.main ()
| "mkelection" -> Mkelection.main ()
| _ -> usage ()
)
(**************************************************************************)
(* BELENIOS *)
(* *)
(* Copyright © 2012-2014 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 Util
open Serializable_t
module type PARAMS = sig
val group : (module Election.FF_GROUP)
val uuid : Uuidm.t
val template : template
end
module GetParams (X : sig end) : PARAMS = struct
let group = ref None
let uuid = ref None
let template = ref None
let speclist = Arg.([
"--group", String (fun s -> group := Some s), "file with group parameters";
"--uuid", String (fun s -> uuid := Some s), "UUID of the election";
"--template", String (fun s -> template := Some s), "file with election template";
])
let usage_msg =
Printf.sprintf "Usage: %s mkelection --group <file> --uuid <uuid> --template <file>" Sys.argv.(0)
let usage () =
Arg.usage speclist usage_msg;
exit 1
let die s = prerr_endline s; usage ()
let anon_fun x =
Printf.eprintf "I do not know what to do with %s\n" x;
usage ()
let () = Arg.parse speclist anon_fun usage_msg
let group = match !group with
| None -> die "--group is missing"
| Some fname ->
let ic = open_in fname in
let ls = Yojson.init_lexer () in
let lb = Lexing.from_channel ic in
let r = Serializable_j.read_ff_params ls lb in
close_in ic;
Election.finite_field r
let uuid = match !uuid with
| None -> die "--uuid is missing"
| Some uuid -> match Uuidm.of_string uuid with
| None -> die "invalid UUID"
| Some u -> u
let template = match !template with
| None -> die "--template is missing"
| Some fname ->
let ic = open_in fname in
let ls = Yojson.init_lexer () in
let lb = Lexing.from_channel ic in
let r = Serializable_j.read_template ls lb in
close_in ic;
r
end
module MakeElection (G : Election.FF_GROUP) (P : PARAMS) = struct
(* Setup group *)
assert (Election.check_finite_field G.group);;
module M = Election.MakeSimpleMonad(G);;
(* Setup trustees *)
module KG = Election.MakeSimpleDistKeyGen(G)(M);;
let public_keys =
let ic = open_in "public_keys.jsons" in
let raw_keys =
let rec loop xs =
match (try Some (input_line ic) with End_of_file -> None) with
| Some x -> loop (x::xs)
| None -> xs
in loop []
in
close_in ic;
let keys = List.map (fun x ->
Serializable_j.trustee_public_key_of_string Serializable_builtin_j.read_number x
) raw_keys |> Array.of_list in
assert (Array.forall KG.check keys);
keys
let y = KG.combine public_keys
(* Setup election *)
let {g; p; q} = G.group
let params = {
e_description = P.template.t_description;
e_name = P.template.t_name;
e_public_key = {ffpk_g = g; ffpk_p = p; ffpk_q = q; ffpk_y = y};
e_questions = P.template.t_questions;
e_uuid = P.uuid;
e_short_name = P.template.t_short_name;
}
(* Save to disk *)
open Serializable_j
let () = save_to "election.json" (write_params write_ff_pubkey) params
end
let main () =
let module P = GetParams (struct end) in
let module G = (val P.group : Election.FF_GROUP) in
let module X = MakeElection (G) (P) in
()
val main : unit -> unit
......@@ -88,6 +88,14 @@ type 'a params = {
} <ocaml field_prefix="e_">
<doc text="Election parameters relevant for creating a ballot.">
type template = {
description : string;
name : string;
questions : question list <ocaml repr="array">;
short_name : string;
} <ocaml field_prefix="t_">
<doc text="Election template.">
type 'a answer = {
choices : 'a ciphertext list <ocaml repr="array">;
individual_proofs : disjunctive_proof list <ocaml repr="array">;
......
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