def collective_decryption(ct, auths=[]): try: #Generate ephimeral key G = EcGroup(nid=conf.EC_GROUP) tmp_priv = G.order().random() tmp_pub = tmp_priv * G.generator() #Encrypt with ephimeral key enc_ct = Classes.Ct.enc(tmp_pub, ct) for auth in auths: #Send for decryption to each authority json_obj_str = enc_ct.to_JSON() data = {'request':'partial_decrypt', 'contents': json_obj_str} #print data s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((auth, conf.AUTH_PORT)) #connect to authority SockExt.send_msg(s, json.dumps(data)) result = json.loads(SockExt.recv_msg(s)) enc_ct.b = EcPt.from_binary(binascii.unhexlify(result['return']),G) s.shutdown(socket.SHUT_RDWR) s.close() #Decrypt using the ephimeral private key value = enc_ct.dec(tmp_priv) #decrypt ct return value except Exception as e: #print "Exception during collective decryption: ", e return None
def ping(sock): try: rand = random.randint(1, 99999) data = {"request": "ping", "contents": {"value": rand}} SockExt.send_msg(sock, json.dumps(data)) result = json.loads(SockExt.recv_msg(sock)) if result["return"] == rand + 1: return True else: return False except Exception as e: print "Exception while pinging: ", e return False
def ping(sock): try: rand = random.randint(1, 99999) data = {'request':'ping', 'contents': {'value':rand}} SockExt.send_msg(sock, json.dumps(data)) result = json.loads(SockExt.recv_msg(sock)) if result['return'] == rand+1: return True else: return False except Exception as e: print "Exception while pinging: ", e return False