コード例 #1
0
ファイル: serializers.py プロジェクト: alesansaa/decide
class MixnetSerializer(serializers.HyperlinkedModelSerializer):
    auths = AuthSerializer(many=True)
    pubkey = KeySerializer()

    class Meta:
        model = Mixnet
        fields = ('voting_id', 'auths', 'pubkey')
コード例 #2
0
ファイル: serializers.py プロジェクト: javdc/prueba-decide
class VotingSerializer(serializers.HyperlinkedModelSerializer):
    parties = PartySerializer(many=True)
    pub_key = KeySerializer()
    auths = AuthSerializer(many=True)
    class Meta:
        model = Voting
        fields = ('id', 'name', 'desc', 'blank_vote', 'parties', 'start_date',
                  'end_date', 'pub_key', 'auths', 'tally', 'postproc')
コード例 #3
0
class VotingSerializer(serializers.HyperlinkedModelSerializer):
    question = QuestionSerializer(many=True)
    pub_key = KeySerializer()
    auths = AuthSerializer(many=True)

    class Meta:
        model = Voting
        fields = ('id', 'name', 'desc', 'question', 'points', 'start_date',
                  'end_date', 'pub_key', 'auths', 'tally', 'postproc')
コード例 #4
0
ファイル: serializers.py プロジェクト: antcarluq/decide
class VotingSerializer(serializers.HyperlinkedModelSerializer):
    #question = QuestionSerializer(many=False)
    candidatures = CandidateGroupSerializer(many=True) 
    pub_key = KeySerializer()
    auths = AuthSerializer(many=True)

    class Meta:
        model = Voting
        fields = ('id', 'name', 'desc', 'candidatures', 'start_date',
                  'end_date', 'pub_key', 'auths', 'tally', 'postproc')
コード例 #5
0
class VotingSerializer(serializers.HyperlinkedModelSerializer):
    question = QuestionSerializer(many=False)
    pub_key = KeySerializer()
    auths = AuthSerializer(many=True)
    candidates = CandidateSerializer(many=True)

    class Meta:
        model = Voting
        fields = ('id', 'name', 'desc', 'question', 'start_date', 'candidates',
                  'escanios', 'end_date', 'min_age', 'max_age', 'pub_key',
                  'auths', 'customURL', 'tally', 'postproc')
コード例 #6
0
    def create(self, request):
        """
        This create a new mixnet and public key

         * auths: [ {"name": str, "url": str} ]
         * voting: id
         * position: int / nullable
         * key: { "p": int, "g": int } / nullable
        """

        auths = request.data.get("auths")
        voting = request.data.get("voting")
        key = request.data.get("key", {"p": 0, "g": 0})
        position = request.data.get("position", 0)
        p, g = int(key["p"]), int(key["g"])

        dbauths = []
        for auth in auths:
            isme = auth["url"] == settings.BASEURL
            a, _ = Auth.objects.get_or_create(name=auth["name"],
                                              url=auth["url"],
                                              me=isme)
            dbauths.append(a)

        mn = Mixnet(voting_id=voting, auth_position=position)
        mn.save()

        for a in dbauths:
            mn.auths.add(a)

        mn.gen_key(p, g)

        data = { "key": { "p": mn.key.p, "g": mn.key.g } }
        # chained call to the next auth to gen the key
        resp = mn.chain_call("/", data)
        if resp:
            y = (resp["y"] * mn.key.y) % mn.key.p
        else:
            y = mn.key.y

        pubkey = Key(p=mn.key.p, g=mn.key.g, y=y)
        pubkey.save()
        mn.pubkey = pubkey
        mn.save()

        return  Response(KeySerializer(pubkey, many=False).data)
コード例 #7
0
    def create(self, request):
        """
        Creates a new mixnet and public key. A mixnet is a series of authorities and certain common properties.
         * auths: [ {"name": str, "url": str} ]
         * voting: id
         * position: int / nullable
         * key: { "p": int, "g": int } / nullable
        """
        if (settings.IS_TEST == False):

            try:
                # Retrieves the token from the request
                token = request.data.get("token")
                # Asks the auth module for user info
                response = mods.post('authentication',
                                     entry_point="/getuser/",
                                     json={"token": token},
                                     response=True)
                # Returns a negative response if the user is not an administrator
                if (not response.json()["is_staff"]):
                    return HttpResponseForbidden("Forbidden")
            except:
                return HttpResponseForbidden("Forbidden")

        # Authorities: different authorities in charge of shuffling and decrypting. Can be in the same system or not

        auths = request.data.get("auths")

        # Voting the mixnet is assigned to, specified by an ID
        voting = request.data.get("voting")

        # Information for creating a public key
        key = request.data.get("key", {"p": 0, "g": 0})

        # Position of the "self" authority in the chain
        position = request.data.get("position", 0)

        # Extracts key data from request
        p, g = int(key["p"]), int(key["g"])

        # Gets, or creates if not created, authorities from the database based on request info
        dbauths = []
        for auth in auths:
            # If the URL of the authority is the same as the URL of the server, it is a local authority and gets special treatment
            isme = auth["url"] == settings.BASEURL
            # Checks if an authority with that name and URL exists and creates it if not
            a, _ = Auth.objects.get_or_create(name=auth["name"],
                                              url=auth["url"],
                                              me=isme)
            dbauths.append(a)

        # Creates and saves the mixnet object with the voting and position. Keys and authority are added later
        mn = Mixnet(voting_id=voting, auth_position=position)
        mn.save()

        # Adds authorities to the newly saved mixnet object
        for a in dbauths:
            mn.auths.add(a)

        # Generates local key part using specified key parameters
        mn.gen_key(p, g)

        # Encodes the key data
        data = {"key": {"p": mn.key.p, "g": mn.key.g}}

        # Makes a chain call to the next authorities to generate the key
        resp = mn.chain_call("/", data)

        # If the call is answered, makes the key with the information attained
        if resp:
            y = (resp["y"] * mn.key.y) % mn.key.p
        # If the call is not answered, that means there is only one authority and does not need to make a multiple-authority key
        else:
            y = mn.key.y

        # Creates and saves the public key object
        pubkey = Key(p=mn.key.p, g=mn.key.g, y=y)
        pubkey.save()

        # Associates the public key with this mixnet
        mn.pubkey = pubkey
        mn.save()

        # Returns the public key to be used to cypher the votes
        return Response(KeySerializer(pubkey, many=False).data)