Beispiel #1
0
	def build_extended_cell(y, gy, streamID: int, circ_id: int, gx: str, recognized) -> Cell:
		"""
		The method to build the extended Cell object
		:param y:
		:param gy:
		:param streamID:
		:param circ_id:
		:param gx:
		:param recognized:
		:return: The Extended Cell
		"""
		gxy = CoreCryptoDH.compute_dh_shared_key(y, gx)
		kdf_dict = CoreCryptoRSA.kdf_tor(gxy)
		server_h_data = TapSHData(gy, kdf_dict['KH'])

		# Construct extended2 payload
		extended_cell_payload_relay = RelayExtendedPayload(RelayExtendedPayload.TAP_S_HANDSHAKE_LEN, server_h_data)

		# Calculate digest from the extended2 payload
		payload_dict = {
			'HLEN': extended_cell_payload_relay.HLEN,
			'HDATA': extended_cell_payload_relay.HDATA
		}
		digest = CoreCryptoMisc.calculate_digest(payload_dict)

		# Construct the Relay cell with extended2 payload which is the payload for the Cell class
		extended_cell_payload = RelayCellPayload(RelayCellPayload.RELAY_CMD_ENUM['EXTENDED2'], recognized, streamID,
		                                         digest, Cell.PAYLOAD_LEN - 11, extended_cell_payload_relay)
		# Construct the actual cell
		extended_cell = Cell(circ_id, Cell.CMD_ENUM['RELAY'], Cell.PAYLOAD_LEN, extended_cell_payload)
		return extended_cell
Beispiel #2
0
	def parse_encoded_extended_cell(cell_bytes: bytes) -> Cell:
		cell_tuple = Parser.parse_basic_cell(cell_bytes)
		relay_cell_payload_tuple = Parser.parse_encoded_relay_cell(cell_bytes)

		part_fmt_str1 = '=H'
		part_tuple1 = unpack(part_fmt_str1, relay_cell_payload_tuple[5][0:2])

		fmt_str = '=H' + str(part_tuple1[0]) + 's'
		relay_extended_payload_tuple = unpack(fmt_str, relay_cell_payload_tuple[5][0:2+part_tuple1[0]])

		h_data_fmt_str = '='+str(CC.DH_LEN)+'s'+str(CC.HASH_LEN)+'s'
		h_data_tuple = unpack(h_data_fmt_str, relay_extended_payload_tuple[1])

		server_h_data = TapSHData(h_data_tuple[0], h_data_tuple[1])

		relay_extended_payload = RelayExtendedPayload(relay_extended_payload_tuple[0], server_h_data)

		relay_cell_payload = RelayCellPayload(relay_cell_payload_tuple[0],
		                                      relay_cell_payload_tuple[1],
		                                      relay_cell_payload_tuple[2],
		                                      relay_cell_payload_tuple[3],
		                                      relay_cell_payload_tuple[4],
		                                      relay_extended_payload)

		extended_cell = Cell(cell_tuple[0], cell_tuple[1], cell_tuple[2], relay_cell_payload)

		return extended_cell
Beispiel #3
0
	def build_created_cell(y_bytes: bytes, gy_bytes: bytes, circ_id: int, gx_bytes: bytes) -> Cell:
		"""
		The method used to build a created/created2 cell object
		:param y_bytes: The diffie hellman private key bytes of the receiver
		:param gy_bytes: The diffie hellman public key bytes of the receiver
		:param circ_id: The circuit ID
		:param gx_bytes: The diffie hellman public key bytes of the sender
		:return: The created Cell object
		"""
		gxy = CoreCryptoDH.compute_dh_shared_key(gx_bytes, y_bytes)
		kdf_dict = CoreCryptoRSA.kdf_tor(gxy)

		server_h_data = TapSHData(gy_bytes, kdf_dict['KH'])
		created_cell_payload = CreatedCellPayload(CreatedCellPayload.TAP_S_HANDSHAKE_LEN, server_h_data)
		created_cell = Cell(circ_id, Cell.CMD_ENUM['CREATED2'], Cell.PAYLOAD_LEN, created_cell_payload)
		return created_cell
Beispiel #4
0
	def parse_encoded_created_cell(cell_bytes: bytes) -> Cell:

		cell_tuple = Parser.parse_basic_cell(cell_bytes)

		hlen = CreatedCellPayload.TAP_S_HANDSHAKE_LEN
		payload_fmt_str = '=H'+str(hlen)+'s'
		created_cell_payload_tuple = unpack(payload_fmt_str, cell_tuple[3][0:(2+hlen)])

		h_data_fmt_str = '='+str(CC.DH_LEN)+'s'+str(CC.HASH_LEN)+'s'
		h_data_tuple = unpack(h_data_fmt_str, created_cell_payload_tuple[1])

		server_h_data = TapSHData(h_data_tuple[0], h_data_tuple[1])

		created_cell_payload = CreatedCellPayload(created_cell_payload_tuple[0], server_h_data)

		created_cell = Cell(cell_tuple[0], cell_tuple[1], cell_tuple[2], created_cell_payload)

		return created_cell