def generate_voters_hash(self): """ look up the list of voters, make a big file, and hash it FIXME: for more than 1000 voters, need to loop multiple times """ 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)
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)
def set_public_key_from_json(self, public_key_json): """ get the public key and the hash, and add it Args: public_key_json: String, json dump Returns: """ public_key_and_proof = utils.from_json(public_key_json) self.public_key = algs.EGPublicKey.fromJSONDict(public_key_and_proof['public_key']) self.pok = algs.DLogProof.fromJSONDict(public_key_and_proof['pok']) # verify the pok if not self.public_key.verify_sk_proof(self.pok, algs.DLog_challenge_generator): raise Exception("bad pok for this public key") self.public_key_hash = utils.hash_b64(utils.to_json(self.public_key.toJSONDict()))
def generate_trustee(self, params): """ generate a trustee including the secret key, thus a helios-based trustee """ # FIXME: generate the keypair keypair = params.generate_keypair() # create the trustee trustee = Trustee(election=self) trustee.uuid = str(uuid.uuid4()) trustee.name = settings.DEFAULT_FROM_NAME trustee.email = settings.DEFAULT_FROM_EMAIL trustee.public_key = keypair.pk trustee.secret_key = keypair.sk # FIXME: compute it trustee.public_key_hash = utils.hash_b64(utils.to_json(trustee.public_key.toJSONDict())) trustee.pok = trustee.secret_key.prove_sk(algs.DLog_challenge_generator) trustee.save()
def generate_helios_trustee(self, params): """ generate a trustee including the secret key, thus a helios-based trustee """ # FIXME: generate the keypair keypair = params.generate_keypair() # create the trustee trustee = HeliosTrustee() trustee.election = self trustee.public_key = keypair.pk trustee.secret_key = keypair.sk trustee.secret = heliosutils.random_string(12) trustee.public_key_hash = utils.hash_b64(utils.to_json(EGPublicKey(y=trustee.public_key.p, p=trustee.public_key.p, q=trustee.public_key.p, g=trustee.public_key.p).toJSONDict())) trustee.pok = trustee.secret_key.prove_sk(algs.DLog_challenge_generator) return trustee
def get_hash(self): return utils.hash_b64(utils.to_json(self.toJSONDict()))