本文整理汇总了Python中anon_crypto.AnonCrypto.sign_with_key方法的典型用法代码示例。如果您正苦于以下问题:Python AnonCrypto.sign_with_key方法的具体用法?Python AnonCrypto.sign_with_key怎么用?Python AnonCrypto.sign_with_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anon_crypto.AnonCrypto
的用法示例。
在下文中一共展示了AnonCrypto.sign_with_key方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: recv_interest_voucher
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import sign_with_key [as 别名]
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...")
示例2: accept_phase
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import sign_with_key [as 别名]
def accept_phase(self, ip, port, nonce):
# package and encrypt data
response = marshal.dumps((nonce, self.ip, self.gui_port))
cipher = AnonCrypto.sign_with_key(self.privKey, response)
# respond with ((ip, port), encrypted_data)
AnonNet.send_to_addr(ip, int(port), marshal.dumps(("accept", cipher)))
示例3: prepare_round
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import sign_with_key [as 别名]
def prepare_round(self):
# can't start round without 3 or more peers
if len(self.participants) < 3:
self.DEBUG("Not enough peers to start round!")
return
prepare_voucher = marshal.dumps(
(int(PREPARE_WAIT), int(1), copy.copy(self.participants), self.ip, self.gui_port, self.com_port)
)
cipher = AnonCrypto.sign_with_key(self.privKey, prepare_voucher)
for index, participant in enumerate(self.participants):
down_index = (index - 1) % len(self.participants)
up_index = (index + 1) % len(self.participants)
if (self.ip, self.gui_port, self.com_port) != (participant[1], participant[2], participant[3]):
AnonNet.send_to_addr(
participant[1],
participant[2],
marshal.dumps(("prepare:%s:%s:%s" % (index, down_index, up_index), cipher)),
)
self.DEBUG(
"Sending prepare to peer %s:%s at port %s" % (participant[1], participant[2], participant[3])
)
# after informing the participants, create your node
dn_idx = -1 % len(self.participants)
up_idx = 1
self.start_node(dn_idx, up_idx, self.participants, 0)
# start round after PREPARE_WAIT minutes
DelayTimer(PREPARE_WAIT, self.run_protocol).start()
示例4: initiate_round
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import sign_with_key [as 别名]
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()
示例5: drop_out
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import sign_with_key [as 别名]
def drop_out(self):
self.DEBUG("Dropping out of the clique")
# create dropout voucher (IP, PORT, PUBKEY)
dropout_voucher = marshal.dumps((self.ip, self.gui_port, self.public_key_string()))
# sign it
cipher = AnonCrypto.sign_with_key(self.privKey, dropout_voucher)
# give all peers signed voucher of your voluntary quitting
self.broadcast_to_all_peers(marshal.dumps(("quit", cipher)))
# empty peerlist and exit
self.nodes = []
self.update_peerlist()
示例6: expel_peer
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import sign_with_key [as 别名]
def expel_peer(self, ip, port):
self.DEBUG("IP/PORT to expel: %s:%s" % (ip, port))
# create voucher for peers to save
expel_voucher = marshal.dumps((self.ip, self.gui_port, ip, port, self.peer_public_key_string(ip, port)))
cipher = AnonCrypto.sign_with_key(self.privKey, expel_voucher)
self.broadcast_to_all_peers(marshal.dumps(("expel", cipher)))
# remove from peerlist
index = self.nodes.index((ip, int(port), self.peer_public_key_string(ip, port)))
self.nodes.pop(index)
self.update_peerlist()
self.DEBUG("Expelled!")
# save the voucher you sent out
self.save_voucher(self.ip, self.gui_port, cipher, "expelvoucher")
示例7: invite_phase
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import sign_with_key [as 别名]
def invite_phase(self, ip, port, pubkey):
# create nonce, # peers, vector containing (ip, port, pubkey) of all peers
nonce = 1
num_peers = len(self.nodes) + 1
peer_vector = [(self.ip, self.gui_port, self.public_key_string())]
for node in self.nodes:
hashkey = self.hash_peer(node[0], node[1])
if hashkey != self.hashkey:
peer_vector.append(node)
# package the text up into (nonce, N, [array of peer data])
invite = marshal.dumps((nonce, num_peers, peer_vector))
# sign it
cipher = AnonCrypto.sign_with_key(self.privKey, invite)
# send to invitee packaged with who it's coming from ((ip:port), signed(text))
AnonNet.send_to_addr(ip, int(port), marshal.dumps(("invite", cipher)))
示例8: inform_phase
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import sign_with_key [as 别名]
def inform_phase(self, data):
msg, key = marshal.loads(data)
# get corresponding public key to verify
(recv_nonce, new_ip, new_port) = marshal.loads(msg)
verified = self.verify(new_ip, new_port, data)
# decrypt and validate!
self.DEBUG("INFORMING: %s, %s, %s, %s" % (recv_nonce, new_ip, new_port, verified))
if verified:
self.DEBUG("SUCCESSFULLY INVITED/VALIDATED!")
self.add_peer(new_ip, new_port)
self.update_peerlist()
# broadcast to all peers, save voucher
voucher = marshal.dumps(
(self.ip, self.gui_port, new_ip, new_port, self.peer_public_key_string(new_ip, new_port))
)
sig_voucher = AnonCrypto.sign_with_key(self.privKey, voucher)
self.save_voucher(new_ip, new_port, sig_voucher, "voucher")
self.broadcast_to_all_peers(marshal.dumps(("inform", sig_voucher)))