예제 #1
0
def public_key_form(request):
    if request.method == "POST":
        # get the public key and the hash, and add it
        key = Key()
        key.name = request.POST['name']
        key.email = request.POST['email']
        public_key_and_proof_enc = utils.from_json(
            request.POST['public_key_json_enc'])
        public_key_enc = algs.EGPublicKey.fromJSONDict(
            public_key_and_proof_enc['public_key'])
        pok_enc = algs.DLogProof.fromJSONDict(public_key_and_proof_enc['pok'])

        # verify the pok
        if not public_key_enc.verify_sk_proof(pok_enc, algs.DLog_challenge_generator):
            raise Exception("bad pok for public key encrypting")
        key.public_key_encrypt = utils.to_json(public_key_enc.to_dict())
        key.pok_encrypt = utils.to_json(pok_enc.to_dict())
        key.public_key_encrypt_hash = cryptoutils.hash_b64(
            key.public_key_encrypt)

        public_key_and_proof_sign = utils.from_json(
            request.POST['public_key_json_sign'])
        public_key_sign = algs.EGPublicKey.fromJSONDict(
            public_key_and_proof_sign['public_key'])
        pok_sign = algs.DLogProof.fromJSONDict(
            public_key_and_proof_sign['pok'])

        # verify the pok
        if not public_key_sign.verify_sk_proof(pok_sign, algs.DLog_challenge_generator):
            raise Exception("bad pok for public key signing")
        key.public_key_signing = utils.to_json(public_key_sign.to_dict())
        key.pok_signing = utils.to_json(pok_sign.to_dict())
        key.public_key_signing_hash = cryptoutils.hash_b64(
            key.public_key_signing)

        key.save()
        # send a note to admin
        try:
            election.admin.send_message(
                "pk upload, " + "%s uploaded a pk for communication." % (key.name))
        except:
            # oh well, no message sent
            pass

        return HttpResponseRedirect('/bulletin_board/')

    """
    A key generator with the current params, like the trustee home but without a specific election.
    """
    eg_params_json = utils.to_json(ELGAMAL_PARAMS_LD_OBJECT.toJSONDict())

    return render_template(request, "election_publickeygenerator", {'eg_params_json': eg_params_json})
예제 #2
0
    def voter_id_hash(self):
        if self.voter_login_id:
            # for backwards compatibility with v3.0, and since it doesn't matter
            # too much if we hash the email or the unique login ID here.
            value_to_hash = self.voter_login_id
        else:
            value_to_hash = self.voter_id

        try:
            return utils.hash_b64(value_to_hash)
        except:
            try:
                return utils.hash_b64(value_to_hash.encode("latin-1"))
            except:
                return utils.hash_b64(value_to_hash.encode("utf-8"))
예제 #3
0
파일: models.py 프로젝트: pgerakios/zeus
  def voter_id_hash(self):
    if self.voter_login_id:
      # for backwards compatibility with v3.0, and since it doesn't matter
      # too much if we hash the email or the unique login ID here.
      value_to_hash = self.voter_login_id
    else:
      value_to_hash = self.voter_id

    try:
      return utils.hash_b64(value_to_hash)
    except:
      try:
        return utils.hash_b64(value_to_hash.encode('latin-1'))
      except:
        return utils.hash_b64(value_to_hash.encode('utf-8'))
예제 #4
0
 def generate(self, m, secret_key, p, q, g):
     while True:
         hash = utils.hash_b64(m)
         hash_dec = utils.encode_string_to_decimal(hash)
         k = algs.Utils.random_k_relative_prime_p_1(p)
         k_inv = algs.Utils.inverse(k, p - 1)
         x = secret_key.x
         r = pow(g, k, p)
         s = ((hash_dec - x * r) * k_inv) % (p - 1)
         if s != 1:
             self.s = s
             self.r = r
             return None
예제 #5
0
    def generate_voters_hash(self):
        """
    look up the list of voters, make a big file, and hash it
    """

        # FIXME: for now we don't generate this voters hash:
        return

        if self.openreg:
            self.voters_hash = None
        else:
            voters = Voter.get_by_election(self)
            voters_json = utils.to_json([v.toJSONDict() for v in voters])
            self.voters_hash = utils.hash_b64(voters_json)
예제 #6
0
파일: models.py 프로젝트: pgerakios/zeus
  def generate_voters_hash(self):
    """
    look up the list of voters, make a big file, and hash it
    """

    # FIXME: for now we don't generate this voters hash:
    return

    if self.openreg:
      self.voters_hash = None
    else:
      voters = Voter.get_by_election(self)
      voters_json = utils.to_json([v.toJSONDict() for v in voters])
      self.voters_hash = utils.hash_b64(voters_json)
예제 #7
0
    def verify(self, m, public_key, p, q, g):
        correct = True
        y = public_key.y
        hash = utils.hash_b64(m)
        hash_dec = utils.encode_string_to_decimal(hash)
        if self.r >= p:
            correct = False
        if self.s >= p - 1:
            correct = False
        val = (pow(y, self.r, p) * pow(self.r, self.s, p)) % p
        if (pow(g, hash_dec, p) != val):
            correct = False

        return correct
예제 #8
0
def create_cast_vote(encrypted_vote, voter, request):
    '''Create cast vote and verify and store.'''
    vote_fingerprint = cryptoutils.hash_b64(encrypted_vote)
    vote = datatypes.LDObject.fromDict(
        cryptoutils.from_json(encrypted_vote),
        type_hint='legacy/EncryptedVote').wrapped_obj
    cast_ip = request.META.get('REMOTE_ADDR', None)
    cast_vote_params = {
        'vote': vote,
        'voter': voter,
        'vote_hash': vote_fingerprint,
        'cast_at': timezone.now(),
        'cast_ip': cast_ip
    }
    cast_vote = CastVote(**cast_vote_params)
    cast_vote.save()

    # launch the verification task
    cast_vote_verify_and_store(cast_vote.id)
예제 #9
0
 def hash(self):
     s = self.serialize()
     import logging; logging.debug('--------serialize-------------%s' %(s))
     logging.debug('--------serialize-------------%s' %(cryptoutils.hash_b64(s)))
     return cryptoutils.hash_b64(s)
예제 #10
0
파일: __init__.py 프로젝트: Pmaene/Helios
 def hash(self):
     s = self.serialize()
     return cryptoutils.hash_b64(s)
예제 #11
0
    def encrypted_tally_hash(self):
        if not self.encrypted_tally:
            return None

        return utils.hash_b64(self.encrypted_tally.toJSON())
 def hash(self):
     s = self.serialize()
     return cryptoutils.hash_b64(s)
예제 #13
0
파일: homomorphic.py 프로젝트: grnet/zeus
def tally_hash(election):
    if not election.encrypted_tally:
      return None

    return utils.hash_b64(election.encrypted_tally.toJSON())
예제 #14
0
def tally_hash(election):
    if not election.encrypted_tally:
        return None

    return utils.hash_b64(election.encrypted_tally.toJSON())