demo.sh 1.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/bin/bash

set -e

BELENIOS=${BELENIOS:-$PWD}

alias belenios-tool=$BELENIOS/_build/belenios-tool

header () {
    echo
    echo "=-=-= $1 =-=-="
    echo
}

header "Setup election"

UUID=`uuidgen`
echo "UUID of the election is $UUID"

DIR=$BELENIOS/demo/data/$UUID
mkdir $DIR
cd $DIR

24 25 26 27
# Common options
uuid="--uuid $UUID"
group="--group $BELENIOS/demo/groups/default.json"

28
# Generate credentials
29
belenios-tool credgen $uuid $group --count 3
30 31 32 33
mv *.pubcreds public_creds.txt
mv *.privcreds private_creds.txt

# Generate trustee keys
34 35 36
belenios-tool trustee-keygen $group
belenios-tool trustee-keygen $group
belenios-tool trustee-keygen $group
37 38 39
cat *.pubkey > public_keys.jsons

# Generate election parameters
Stephane Glondu's avatar
Stephane Glondu committed
40
belenios-tool mkelection $uuid $group --template $BELENIOS/demo/templates/questions.json
41 42 43

header "Simulate votes"

44
cat private_creds.txt | while read id cred; do
Stephane Glondu's avatar
Stephane Glondu committed
45
    belenios-tool vote --privcred <(echo $cred) --ballot <(printf "[[1,0]]")
46
    echo "Voter $id voted" >&2
47 48 49 50 51 52 53
    echo >&2
done > ballots.tmp
mv ballots.tmp ballots.jsons

header "Perform decryption"

for u in *.privkey; do
54
    belenios-tool decrypt --privkey $u
55 56 57 58 59 60
    echo >&2
done > partial_decryptions.tmp
mv partial_decryptions.tmp partial_decryptions.jsons

header "Finalize tally"

61
belenios-tool finalize
62 63 64 65 66 67 68 69 70

echo
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
echo
echo "The simulated election was successful! Its result can be seen in"
echo "  $DIR/result.json"
echo
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
echo