def unpickle_pub_keys(self, msgs): """ Leader uses this method to unpack keys from other nodes """ addrs = [] key_dict = {} key_dict[self.id] = (self.key_from_file(1), AnonCrypto.sign(self.id, self.key1, self.key2.get_pubkey())) for data in msgs: (rem_id, rem_round, rem_ip, rem_port, rem_key1, rem_key2) = marshal.loads(data) self.debug("Unpickled msg from node %d" % (rem_id)) if rem_round != self.round_id: raise RuntimeError, "Mismatched round numbers! (mine: %d, other: %d)" % ( self.round_id, rem_round) self.debug("Before reading verification key") k1 = AnonCrypto.vk_key_from_str(rem_key1) self.pub_keys[rem_id] = (k1, k1) self.debug("Before reading public key") k2 = AnonCrypto.pub_key_from_str( AnonCrypto.verify(self.pub_keys, rem_key2)) self.pub_keys[rem_id] = (k1, k2) addrs.append((rem_ip, rem_port)) key_dict[rem_id] = (rem_key1, rem_key2) self.debug("After handling the keys") return (marshal.dumps((self.round_id, key_dict)), addrs)
def unpickle_keyset(self, keys): """ Non-leader nodes use this to decode leader's key msg """ (rem_round_id, keydict) = marshal.loads(keys) if rem_round_id != self.round_id: raise RuntimeError, "Mismatched round ids" for i in keydict: s1, s2 = keydict[i] k1 = AnonCrypto.vk_key_from_str(s1) #k1.check_key() self.pub_keys[i] = (k1, k1) k2 = AnonCrypto.pub_key_from_str( AnonCrypto.verify(self.pub_keys, s2)) #k2.check_key() self.pub_keys[i] = (k1, k2) self.info('Unpickled public keys')