Beispiel #1
0
	def shuffle_and_decrypt(self):
		random.shuffle(self.data_in)
		self.debug("Shuffling len = %d" % len(self.data_in))
		self.data_out = []
		for ctuple in self.data_in:
			(rem_round, ctext) = marshal.loads(ctuple)
			if rem_round != self.round_id:
				raise RuntimeError, "Mismatched round numbers (mine:%d, other:%d)" % (self.round_id, rem_round)

			new_ctext = AnonCrypto.decrypt_with_rsa(self.key1, ctext)	
			pickled = marshal.dumps((self.round_id, new_ctext))
			self.data_out.append(pickled)
Beispiel #2
0
    def shuffle_and_decrypt(self):
        random.shuffle(self.data_in)
        self.debug("Shuffling len = %d" % len(self.data_in))
        self.data_out = []
        for ctuple in self.data_in:
            (rem_round, ctext) = marshal.loads(ctuple)
            if rem_round != self.round_id:
                raise RuntimeError, "Mismatched round numbers (mine:%d, other:%d)" % (
                    self.round_id, rem_round)

            new_ctext = AnonCrypto.decrypt_with_rsa(self.key2, ctext)
            pickled = marshal.dumps((self.round_id, new_ctext))
            self.data_out.append(pickled)
Beispiel #3
0
	def decrypt_ciphers(self, keyset):
		priv_keys = {}
		for item in keyset:
			""" Verify signature on each key """
			item_str = AnonCrypto.verify(self.pub_keys, item)
			(r_id, r_roundid, r_keystr) = marshal.loads(item_str)
			if r_roundid != self.round_id:
				raise RuntimeError, 'Mismatched round numbers'
			priv_keys[r_id] = AnonCrypto.priv_key_from_str(r_keystr)

		plaintexts = []
		for cipher in self.final_ciphers:
			(r_round, cipher_prime) = marshal.loads(cipher)
			if r_round != self.round_id:
				raise RuntimeError, 'Mismatched round ids'
			for i in xrange(0, self.n_nodes):
				cipher_prime = AnonCrypto.decrypt_with_rsa(priv_keys[i], cipher_prime)
			plaintexts.append(self.unpackage_msg(cipher_prime))
		
		self.anon_data = plaintexts
Beispiel #4
0
    def decrypt_ciphers(self, keyset):
        priv_keys = {}
        for item in keyset:
            """ Verify signature on each key """
            item_str = AnonCrypto.verify(self.pub_keys, item)
            (r_id, r_roundid, r_keystr) = marshal.loads(item_str)
            if r_roundid != self.round_id:
                raise RuntimeError, 'Mismatched round numbers'
            priv_keys[r_id] = AnonCrypto.priv_key_from_str(r_keystr)

        plaintexts = []
        for cipher in self.final_ciphers:
            (r_round, cipher_prime) = marshal.loads(cipher)
            if r_round != self.round_id:
                raise RuntimeError, 'Mismatched round ids'
            for i in xrange(0, self.n_nodes):
                cipher_prime = AnonCrypto.decrypt_with_rsa(
                    priv_keys[i], cipher_prime)
            plaintexts.append(self.unpackage_msg(cipher_prime))

        self.anon_data = plaintexts
Beispiel #5
0
    def run_phase3(self):
        self.advance_phase()
        self.info("Starting data transmission phase")

        self.responses = []
        self.go_flag = False

        """
		We put all of the pseudo-random strings in a tar file
		for transmission.
		"""
        handle, self.tar_filename = tempfile.mkstemp()
        tar = tarfile.open(name=self.tar_filename, mode="w")  # Create new archive
        # dereference = True)

        """ For each transmission slot... """
        for i in xrange(0, self.n_nodes):
            debug("Processing data for msg slot %d" % i)
            slot_data = self.msg_data[i]
            msg_len = slot_data[0]
            enc_seeds = slot_data[1]
            hashes = slot_data[2]

            if enc_seeds[self.id] == self.my_seed:
                """ If this is my seed, use the cheating message. """
                self.go_flag = True
                self.responses.append(self.dfilename)
                tar.add(self.cip_file, "%d" % (self.id))
            else:
                """ If this is not my msg slot, decrypt seed assigned to me. """
                seed = AnonCrypto.decrypt_with_rsa(self.key1, enc_seeds[self.id])
                h_val, fname = self.generate_prng_file(seed, msg_len)

                if h_val != hashes[self.id]:
                    for q in xrange(0, len(hashes)):
                        self.debug("> %d - %s" % (q, hashes[q]))
                    raise RuntimeError, "Mismatched hash values"

                """
				Label each file in the tar with this node's id so that nodes can
				match the files to the message hashes.
				"""
                tar.add(fname, "%d" % (self.id))
        tar.close()

        if not self.go_flag:
            raise RuntimeError, "My ciphertext is missing"

        if self.am_leader():
            fnames = AnonNet.recv_file_from_n(self.sockets)
            fnames.append(self.tar_filename)
            self.message_tar = self.generate_msg_tar(fnames)

            """ Broadcast final messages """
            self.debug("Broadcasting msg tar")
            self.broadcast_file_to_all_nodes(self.message_tar)
            self.debug("Sent msg tar")
        else:
            AnonNet.send_file_to_sock(self.leader_socket, self.tar_filename)
            self.debug("Waiting for msg tar")
            self.message_tar = AnonNet.recv_file_from_sock(self.leader_socket)
            self.debug("Got for msg tar")
Beispiel #6
0
	def run_phase3(self):
		self.advance_phase()
		self.info("Starting data transmission phase")

		self.responses = []
		self.go_flag = False

		"""
		We put all of the pseudo-random strings in a tar file
		for transmission.
		"""
		handle, self.tar_filename = tempfile.mkstemp()
		tar = tarfile.open(
				name = self.tar_filename,
				mode = 'w') # Create new archive
#dereference = True)

		""" For each transmission slot... """
		for i in xrange(0, self.n_nodes):
			debug("Processing data for msg slot %d" % i)
			slot_data = self.msg_data[i]
			msg_len = slot_data[0]
			enc_seeds = slot_data[1]
			hashes = slot_data[2]

			if enc_seeds[self.id] == self.my_seed:
				""" If this is my seed, use the cheating message. """
				self.go_flag = True
				self.responses.append(self.dfilename)
				tar.add(self.cip_file, "%d" % (self.id))
			else:
				""" If this is not my msg slot, decrypt seed assigned to me. """
				seed = AnonCrypto.decrypt_with_rsa(self.key1, enc_seeds[self.id])
				h_val, fname = self.generate_prng_file(seed, msg_len)


				if h_val != hashes[self.id]:
					for q in xrange(0, len(hashes)):
						self.debug("> %d - %s" % (q, hashes[q]))
					raise RuntimeError, 'Mismatched hash values'

				"""
				Label each file in the tar with this node's id so that nodes can
				match the files to the message hashes.
				"""
				tar.add(fname, "%d" % (self.id))
		tar.close()

		if not self.go_flag:
			raise RuntimeError, 'My ciphertext is missing'

		if self.am_leader():
			fnames = AnonNet.recv_file_from_n(self.sockets)
			fnames.append(self.tar_filename)
			self.message_tar = self.generate_msg_tar(fnames)
			
			""" Broadcast final messages """
			self.debug("Broadcasting msg tar")
			self.broadcast_file_to_all_nodes(self.message_tar)
			self.debug("Sent msg tar")
		else:
			AnonNet.send_file_to_sock(self.leader_socket, self.tar_filename)
			self.debug("Waiting for msg tar")
			self.message_tar = AnonNet.recv_file_from_sock(self.leader_socket)
			self.debug("Got for msg tar")