Ejemplo n.º 1
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
Ejemplo n.º 2
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