Beispiel #1
0
def castVote():
    data = request.json
    print(data)
    electionId = data["election"]
    selection = data["selection"]
    selection = [int(x) for x in selection]
    selection.sort()
    voterId = data["voterId"]
    votingCode = data["votingCode"]
    manipulatedPublicCredential = data["manipulatedPublicCredential"]
    manipulatedPublicKey = data["manipulatedPublicKey"]

    if len(selection) == 0:
        return make_error(400, "Empty selection")

    try:
        # prepare voteService
        voteSvc = VoteService(electionId)

        # perform action
        voteSvc.castVote(voterId, selection, votingCode,
                         manipulatedPublicCredential, manipulatedPublicKey)

        # retrieve and persist modified state
        patches = voteSvc.persist()
        syncPatches(electionId, SyncType.ROOM, patches)

    except Exception as e:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        return make_error(
            500, '%s:%s: %s. %s' %
            (fname, exc_tb.tb_lineno, e, traceback.format_exc()))

    return json.dumps({'result': 'success'})
def generateElectorateData():
    data = request.json
    electionId = data["election"]
    authorityId = data["authorityId"]

    try:
        # prepare voteService
        voteSvc = VoteService(electionId)

        # perform action
        voteSvc.generateElectorateData(authorityId)

        #patches = voteSvc.getJSONPatches()
        # retrieve and persist modified state
        patches = voteSvc.persist()
        syncPatches(electionId, SyncType.ROOM, patches)

        # update election status
        # voteSvc.updateStatus(1)
    except Exception as e:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        return make_error(500, '%s:%s: %s' % (fname, exc_tb.tb_lineno, e))

    return json.dumps({'result': 'success'})
Beispiel #3
0
def debugVotingSim():
    electionId = request.json["election"]
    from gmpy2 import mpz
    try:
        voteSvc = VoteService(electionId)  # prepare voteService
        #from chvote.Types import Ballot
        #voteSvc.bulletinBoard.confirmations[0].finalizations.append(1)
        #patches = voteSvc.persist()
        #syncPatches(electionId, SyncType.ROOM, patches)
        import app.utils.jsonpatch as jsonpatch
        import copy
        from chvote.Types import VoterConfirmation
        from app.utils.JsonParser import mpzconverter

        old = {'key': [{'someNumber': 0, 'someArray': [1, 2, 3]}]}

        new = {'key': [{'someNumber': 0, 'someArray': [1, 2, 3, 4]}]}

        patches = jsonpatch.make_patch(old, new)
    except Exception as e:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        return make_error(500, '%s:%s: %s' % (fname, exc_tb.tb_lineno, e))

    return json.dumps({'result': 'success'})
Beispiel #4
0
def startDecryptionPhase():
    data = request.json
    electionId = data["election"]
    try:
        # prepare voteService
        voteSvc = VoteService(electionId)

        voteSvc.startDecryption()

        # retrieve and persist modified state
        patches = voteSvc.persist()
        syncPatches(electionId, SyncType.ROOM, patches)
    except Exception as e:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        return make_error(500, '%s:%s: %s' % (fname, exc_tb.tb_lineno, e))

    return json.dumps({'id': str(id)})
Beispiel #5
0
def revealCode():
    data = request.json
    electionId = data["election"]
    voterId = int(data["voterId"])
    codeIndex = int(data["codeIndex"])

    try:
        # prepare voteService
        voteSvc = VoteService(electionId)

        # perform action
        voteSvc.revealCode(voterId, codeIndex)

        # retrieve and persist modified state
        patches = voteSvc.persist()
        syncPatches(electionId, SyncType.ROOM, patches)

    except Exception as e:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        return make_error(500, '%s:%s: %s' % (fname, exc_tb.tb_lineno, e))

    return json.dumps({'id': str(id)})
Beispiel #6
0
def setAutoMode():
    data = request.json
    electionId = data["election"]
    authorityId = data["authorityId"]
    value = data["value"]

    try:
        # prepare voteService
        voteSvc = VoteService(electionId)

        # perform action
        voteSvc.authorities[authorityId].autoCheck = value

        # retrieve and persist modified state
        patches = voteSvc.persist()
        syncPatches(electionId, SyncType.ROOM, patches)

    except Exception as e:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        return make_error(500, '%s:%s: %s' % (fname, exc_tb.tb_lineno, e))

    return json.dumps({'id': str(id)})
Beispiel #7
0
def abortVote():
    data = request.json
    electionId = data["election"]
    voterId = data["voterId"]

    try:
        # prepare voteService
        voteSvc = VoteService(electionId)

        # perform action
        voteSvc.abortVote(voterId)

        # retrieve and persist modified state
        patches = voteSvc.persist()
        syncPatches(electionId, SyncType.ROOM, patches)

    except Exception as e:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        return make_error(
            500, '%s:%s: %s. %s' %
            (fname, exc_tb.tb_lineno, e, traceback.format_exc()))

    return json.dumps({'result': 'success'})
Beispiel #8
0
def sendVotingCards():
    electionId = request.json["election"]

    try:
        voteSvc = VoteService(electionId)  # prepare voteService
        voteSvc.sendVotingCards()
        patches = voteSvc.persist()
        syncPatches(electionId, SyncType.ROOM, patches)

        # update election status
        voteSvc.updateStatus(3)
    except Exception as e:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        return make_error(500, '%s:%s: %s' % (fname, exc_tb.tb_lineno, e))

    return json.dumps({'result': 'success'})
Beispiel #9
0
def setUpElection():
    data = request.json
    electionId = data["election"]
    numberOfVoters = json.loads(data["numberOfVoters"])
    candidates = data["candidates"]
    countingCircles = json.loads(data["countingCircles"])
    numberOfSelections = data["numberOfSelections"]
    numberOfCandidates = data["numberOfCandidates"]
    titles = data["titles"]

    try:
        # validate vote parameters
        if len(candidates) != sum(numberOfCandidates):
            raise RuntimeError(
                "The numberOfCandidates must match the number of candidates")
        if numberOfVoters != len(countingCircles):
            raise RuntimeError(
                "The length of countingCircles must match the number of voters"
            )
        if len(numberOfSelections) != len(numberOfCandidates):
            raise RuntimeError(
                "The length of numberOfSelections must match the length of numberOfCandidates"
            )

        # prepare voteService
        voteSvc = VoteService(electionId)

        # perform action
        voteSvc.setupElection(numberOfVoters, countingCircles, candidates,
                              numberOfCandidates, numberOfSelections, titles)

        #patches = voteSvc.getJSONPatches()
        # retrieve and persist modified state
        patches = voteSvc.persist()
        syncPatches(electionId, SyncType.ROOM, patches)

        # update election status
        voteSvc.updateStatus(1)
    except Exception as e:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        return make_error(500, '%s:%s: %s' % (fname, exc_tb.tb_lineno, e))

    return json.dumps({'result': 'success'})