Commit ffcab5dd authored by Stephane Glondu's avatar Stephane Glondu
Browse files

JS version of derive_cred

parent 4e2a385b
......@@ -35,7 +35,30 @@ let sha256_b64 x =
let b64_encode_compact x = assert false
let derive_cred uuid x = assert false
let remove_dashes x =
let n = String.length x in
let res = Buffer.create n in
for i = 0 to n-1 do
let c = x.[i] in
if c <> '-' then Buffer.add_char res c;
done;
Buffer.contents res
let derive_cred uuid x =
let uuid = remove_dashes (Uuidm.to_string uuid) in
let salt = Js.Unsafe.meth_call sjcl "codec.hex.toBits"
[| Js.string uuid |> Js.Unsafe.inject |]
in
let derived = Js.Unsafe.meth_call sjcl "misc.pbkdf2"
[|
Js.string x |> Js.Unsafe.inject;
salt;
Js.Unsafe.inject 1000;
Js.Unsafe.inject 256;
|]
in
Js.Unsafe.meth_call sjcl "codec.hex.fromBits"
[| derived |] |> Js.to_string
type rng = unit -> unit
......
......@@ -41,6 +41,28 @@
</div>
<div id="credgen">
<h2>Credential management</h2>
<div>
<h3>Election parameters</h3>
<div>
UUID:
<div><textarea id="credgen_uuid" rows="1" cols="80"></textarea></div>
</div>
<div>
Group parameters:
<div><textarea id="credgen_group" rows="1" cols="80"></textarea></div>
</div>
</div>
<div>
<h3>Check a credential</h3>
<div>
Credential:
<div><textarea id="credgen_derive_input"></textarea></div>
<button id="do_credgen_derive">Generate public key</button>
</div>
<div>
<textarea id="credgen_derive_output" rows="1" cols="80" readonly="readonly"></textarea>
</div>
</div>
</div>
<div id="mkelection">
<h2>Election creation</h2>
......
......@@ -122,7 +122,24 @@ module Tkeygen = struct
let cmds = ["do_tkeygen", tkeygen]
end
let cmds = Tests.cmds @ Tkeygen.cmds
module Credgen = struct
open Tool_credgen
let derive () =
let module P : PARAMS = struct
let uuid = get_textarea "credgen_uuid"
let group = get_textarea "credgen_group"
end in
let module X = (val make (module P : PARAMS) : S) in
let cred = get_textarea "credgen_derive_input" in
set_textarea "credgen_derive_output" (X.derive cred)
let cmds = [
"do_credgen_derive", derive;
]
end
let cmds = Tests.cmds @ Tkeygen.cmds @ Credgen.cmds
let install_handlers () =
List.iter install_handler cmds
......
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