def registerVote(plainText, username, password): """Register plainText as the vote of user with given username and password""" if GlobalVariables.objects.filter(varname='electionState')[0].value != 'election': return False userlist = Users.objects.filter(username=username) #print len(userlist) if (len(userlist) == 0): return False assert(len(userlist) == 1) decryptedPrivateKey = cryptography.symmetricDecrypt(userlist[0].encryptedPrivateKey,password) certificate = cryptography.asymmetricSign(plainText,decryptedPrivateKey) key = RSA.importKey(decryptedPrivateKey) key = key.publickey().exportKey() assert(len(PublicKeys.objects.filter(publicKey=key)) == 1) publicKey = PublicKeys.objects.filter(publicKey=key)[0] challenobj = ChallengeStrings.objects.all() lenofcha = len(challenobj) rannum = lenofcha/2 '''get a random number''' p1 = Votes(plainText=plainText, certificate=certificate, publicKey=publicKey, challengeStr = challenobj[rannum]) p1.save() return True