From 85d0048c22271fac371729ba7b14417a28bb6b48 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 25 Feb 2014 11:15:15 +0000 Subject: - support mesh's new NACK message - remove - python test skeleton for voting - encrypted votes - establish threshold key during ballot registration - ballot tool can request threshold public keys from authorities --- src/test/python/test_voting.conf | 5 ++ src/test/python/test_voting_single.py | 154 ++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 src/test/python/test_voting.conf create mode 100644 src/test/python/test_voting_single.py (limited to 'src/test') diff --git a/src/test/python/test_voting.conf b/src/test/python/test_voting.conf new file mode 100644 index 0000000..0684302 --- /dev/null +++ b/src/test/python/test_voting.conf @@ -0,0 +1,5 @@ +[arm] +DEFAULTSERVICES = mesh set consensus secretsharing + +[testbed] +OVERLAY_TOPOLOGY = CLIQUE diff --git a/src/test/python/test_voting_single.py b/src/test/python/test_voting_single.py new file mode 100644 index 0000000..630f92e --- /dev/null +++ b/src/test/python/test_voting_single.py @@ -0,0 +1,154 @@ +""" +Test the voting implementation with a single authority. +""" +import os +import subprocess +import time + + +NUM_AUTHORITIES = 1 +NUM_VOTERS = 1 + + +def wait_for_after(ts): + now = time.time() + if now < ts: + time.sleep(ts - now) + +def get_config(section, option, filename=None, expand=False): + args = ["gnunet-config"] + if filename is not None: + args.extend(["-c", filename]) + args.extend(["-s", section]) + args.extend(["-o", option]) + if expand: + args.extend(["-f"]) + return subprocess.check_output(args).strip() + + +def create_identity(name, config=None): + args = ["gnunet-identity", "-C", name] + if config is not None: + args.extend(["-c", config]) + subprocess.check_call(args) + +def get_identity_pubkey(name, config=None): + args = ["gnunet-identity", "-d", name] + if config is not None: + args.extend(["-c", config]) + out = subprocess.check_output(args) + components = out.split("-") + return components[-1].strip() + +testdir = subprocess.check_output(["mktemp", "-d", "test-voting-XXXXXXXXXX.d", "--tmpdir"]) +testdir = testdir.strip() +ballot = os.path.join(testdir, "ballot") +print "testdir", testdir + + +testbed_conf = "test_voting.conf" +env = os.environ.copy() +env["GNUNET_TESTING_PREFIX"] = testdir +testbed = subprocess.Popen(["gnunet-testbed-profiler", "-n", "-c", testbed_conf, "-p", "1"], env=env) + +ballot_filename = os.path.join(testdir, "ballot") + +conf = [] +conf.append(os.path.join(testdir, "0", "config")) + +for c in conf: + while not os.path.exists(c): + print "waiting for creation of", c + time.sleep(0.1) + +print "test dir:", testdir + + +# start authority +# FIXME: using gnunet-arm for this might be nicer, +auth = subprocess.Popen(["gnunet-daemon-ballot-tally", "-c", conf[0]]) + +private_key_filename = get_config("peer", "private_key", conf[0], expand=True) + +public_key = subprocess.check_output(["gnunet-ecc", "--print-public-key", private_key_filename]).strip() + +print "public key", public_key + +create_identity("voter0", conf[0]) +create_identity("issuer", conf[0]) +create_identity("groupca", conf[0]) + +print "created identities" + +ballot = open(ballot_filename, "w") + +now = int(time.time()) +TS_KEYGEN_START = now + 10 +TS_KEYGEN_END = now + 20 +TS_START = now + 20 +TS_CLOSING = now + 25 +TS_CONCLUDE = now + 45 +TS_QUERY = now + 65 +TS_END = now + 65 + +ballot.write("[authorities]\n") +ballot.write("auth0 = %s\n" % public_key) +ballot.write("[election]\n") +ballot.write("TOPIC = mytopic\n") +ballot.write("THRESHOLD = 1\n") +ballot.write("CHOICES = yes//no\n") +ballot.write("GROUP = mygroup\n") +ballot.write("CA_PUB = %s\n" % get_identity_pubkey("groupca", conf[0])) +ballot.write("TIMESTAMP_KEYGEN_START = %s\n" % TS_KEYGEN_START) +ballot.write("TIMESTAMP_KEYGEN_END = %s\n" % TS_KEYGEN_END) +ballot.write("TIMESTAMP_START = %s\n" % TS_START) +ballot.write("TIMESTAMP_CLOSING = %s\n" % TS_CLOSING) +ballot.write("TIMESTAMP_CONCLUDE = %s\n" % TS_CONCLUDE) +ballot.write("TIMESTAMP_QUERY = %s\n" % TS_QUERY) +ballot.write("TIMESTAMP_END = %s\n" % TS_END) + +ballot.close() + +groupcert_filename = os.path.join(testdir, "v0-cert") +groupcert_file = open(groupcert_filename, "w") + +v0_pub = get_identity_pubkey("voter0", conf[0]) + +subprocess.check_call(["gnunet-ballot-group-certify", "-c", conf[0], + "-g", "mygroup", "-e", "groupca", "-m", v0_pub], stdout=groupcert_file) + +groupcert_file.close() + +# register the ballot with authorities +subprocess.check_call(["gnunet-ballot", "-LINFO", "-i", ballot_filename, "-e", "issuer", "-c", conf[0]]) + +# register the ballot with authorities +subprocess.check_call(["gnunet-ballot", "-LINFO", "-r", ballot_filename, "-c", conf[0]]) + +wait_for_after(TS_KEYGEN_END) + +print "getting threshold public key" + +# get the threshold public key +subprocess.check_call(["gnunet-ballot", "-LDEBUG", "-k", ballot_filename, "-c", conf[0]]) + +print "threshold public key retrieved" + +# add voter's group information +subprocess.check_call(["gnunet-ballot", "-g", groupcert_filename, ballot_filename, "-c", conf[0]]) + +# actually vote ... +subprocess.check_call(["gnunet-ballot", "-x", "yes", ballot_filename, "-e", "voter0", "-c", conf[0]]) + +wait_for_after(TS_START) + +# submit the ballot with the vote +subprocess.check_call(["gnunet-ballot", "-s", ballot_filename, "-c", conf[0]]) + +wait_for_after(TS_QUERY) + +# query the result +subprocess.check_call(["gnunet-ballot", "-q", ballot_filename, "-c", conf[0]]) + +# FIXME: cleanup + -- cgit v1.2.3