def recv_interest_voucher(self, data): msg, key = marshal.loads(data) (nonce, leader_ip, leader_gui_port, leader_com_port) = marshal.loads(msg) self.DEBUG( "Start round voucher from %s:%s, communicating at port %s" % (leader_ip, leader_gui_port, leader_com_port) ) # get the path to the file you want to share self.emit(SIGNAL("getSharedFilename()")) verified = self.verify(leader_ip, leader_gui_port, data) """ generate temporary keys for this round so leader can aggregate """ self.gen_temp_keys() temp1_str = AnonCrypto.pub_key_to_str(self.pubgenkey1) temp2_str = AnonCrypto.pub_key_to_str(self.pubgenkey2) """ default to random file of 128 bytes if you don't have anything to share """ if verified: if os.path.exists(self.shared_filename): self.DEBUG("You are sharing file %s" % (self.shared_filename)) else: self.DEBUG("Not a valid file path, continuing without sharing...") # respond with your interest self.DEBUG("Verified leader, participating as %s:%s at port %s" % (self.ip, self.gui_port, self.com_port)) response = marshal.dumps((nonce, self.ip, self.gui_port, self.com_port, temp1_str, temp2_str)) cipher = AnonCrypto.sign_with_key(self.privKey, response) AnonNet.send_to_addr(leader_ip, int(leader_gui_port), marshal.dumps(("interested", cipher))) else: self.DEBUG("Unkown leader, opting out...")
def recv_interest_voucher(self, data): msg, key = marshal.loads(data) (nonce, leader_ip, leader_gui_port, leader_com_port) = marshal.loads(msg) self.DEBUG("Start round voucher from %s:%s, communicating at port %s" % (leader_ip, leader_gui_port, leader_com_port)) # get the path to the file you want to share self.emit(SIGNAL("getSharedFilename()")) verified = self.verify(leader_ip, leader_gui_port, data) """ generate temporary keys for this round so leader can aggregate """ self.gen_temp_keys() temp1_str = AnonCrypto.pub_key_to_str(self.pubgenkey1) temp2_str = AnonCrypto.pub_key_to_str(self.pubgenkey2) """ default to random file of 128 bytes if you don't have anything to share """ if verified: if os.path.exists(self.shared_filename): self.DEBUG("You are sharing file %s" % (self.shared_filename)) else: self.DEBUG("Not a valid file path, continuing without sharing...") # respond with your interest self.DEBUG("Verified leader, participating as %s:%s at port %s" % (self.ip, self.gui_port, self.com_port)) response = marshal.dumps((nonce,self.ip,self.gui_port,self.com_port,temp1_str,temp2_str)) cipher = AnonCrypto.sign_with_key(self.privKey, response) AnonNet.send_to_addr(leader_ip, int(leader_gui_port), marshal.dumps(("interested", cipher))) else: self.DEBUG("Unkown leader, opting out...")
def phase0b_msg(self): """ Message the leader sends to all other nodes. """ newdict = {} for i in xrange(0, self.n_nodes): k1, k2 = self.pub_keys[i] newdict[i] = (AnonCrypto.pub_key_to_str(k1), AnonCrypto.pub_key_to_str(k2)) return marshal.dumps((self.round_id, newdict))
def phase0b_msg(self): """ Message the leader sends to all other nodes. """ newdict = {} for i in xrange(0, self.n_nodes): k1,k2 = self.pub_keys[i] newdict[i] = ( AnonCrypto.pub_key_to_str(k1), AnonCrypto.pub_key_to_str(k2)) return marshal.dumps((self.round_id, newdict))
def phase1_msg(self): """ Message that non-leader nodes send to the leader. """ #ToDo: Generate the hash of the encryption keys and send it instead of the keys themselves # for the equivocation check. return marshal.dumps( (self.id, self.round_id, self.ip, self.port, self.key_from_file(1), AnonCrypto.sign(self.id, self.key1, AnonCrypto.pub_key_to_str(self.key2)))) return marshal.dumps((self.round_id, newdict))
def initiate_round(self): self.DEBUG("I initiated a dissent round! Finding collaborators...") # get the path to the file you want to share self.emit(SIGNAL("getSharedFilename()")) nonce = int(1) self.participants = [] self.distrusted_peers = [] """ generate temporary keys for this round, add to participants """ self.gen_temp_keys() temp1_str = AnonCrypto.pub_key_to_str(self.pubgenkey1) temp2_str = AnonCrypto.pub_key_to_str(self.pubgenkey2) """ initiate round with a signed voucher containing relevant information """ my_voucher = marshal.dumps((nonce, self.ip, self.gui_port, self.com_port, temp1_str, temp2_str)) cipher = AnonCrypto.sign_with_key(self.privKey, my_voucher) """ make sure you have something to share first """ if os.path.exists(self.shared_filename): self.DEBUG("You are sharing file %s" % (self.shared_filename)) else: self.DEBUG("Not a valid file path, share something to start a round!") return # add yourself as leader in the participants list (entry 0) self.participants.append((cipher, self.ip, self.gui_port, self.com_port)) self.emit(SIGNAL("getDistrustedPeers()")) # ask if peers are interested interest_voucher = marshal.dumps((nonce, self.ip, self.gui_port, self.com_port)) cipher = AnonCrypto.sign_with_key(self.privKey, interest_voucher) self.broadcast_to_all_peers(marshal.dumps(("interested?", cipher))) # allow one minute to receive all replies, then initiate round with those peers DelayTimer(INTEREST_WAIT, self.prepare_round).start()
def initiate_round(self): self.DEBUG("I initiated a dissent round! Finding collaborators...") # get the path to the file you want to share self.emit(SIGNAL("getSharedFilename()")) nonce = int(1) self.participants = [] self.distrusted_peers = [] """ generate temporary keys for this round, add to participants """ self.gen_temp_keys() temp1_str = AnonCrypto.pub_key_to_str(self.pubgenkey1) temp2_str = AnonCrypto.pub_key_to_str(self.pubgenkey2) """ initiate round with a signed voucher containing relevant information """ my_voucher = marshal.dumps((nonce,self.ip,self.gui_port,self.com_port,temp1_str,temp2_str)) cipher = AnonCrypto.sign_with_key(self.privKey, my_voucher) """ make sure you have something to share first """ if os.path.exists(self.shared_filename): self.DEBUG("You are sharing file %s" % (self.shared_filename)) else: self.DEBUG("Not a valid file path, share something to start a round!") return # add yourself as leader in the participants list (entry 0) self.participants.append((cipher, self.ip, self.gui_port, self.com_port)) self.emit(SIGNAL("getDistrustedPeers()")) # ask if peers are interested interest_voucher = marshal.dumps((nonce, self.ip, self.gui_port, self.com_port)) cipher = AnonCrypto.sign_with_key(self.privKey, interest_voucher) self.broadcast_to_all_peers(marshal.dumps(("interested?",cipher))) # allow one minute to receive all replies, then initiate round with those peers DelayTimer(INTEREST_WAIT, self.prepare_round).start()
def peer_public_key_string(self, ip, port): hashkey = self.hash_peer(ip, port) key = M2Crypto.RSA.load_pub_key("state/%s.pub" % hashkey) return AnonCrypto.pub_key_to_str(key)
def public_key_string(self): return AnonCrypto.pub_key_to_str(self.pubKey)
def peer_public_key_string(self, ip, port): hashkey = self.hash_peer(ip, port) key = M2Crypto.RSA.load_pub_key("state/%s.pub" % hashkey) return AnonCrypto.pub_key_to_str(key)
def public_key_string(self): return AnonCrypto.pub_key_to_str(self.pubKey)