Beispiel #1
0
	def build_create_cell_from_extend(circ_id: int, htype, hlen, hdata) -> Cell:
		"""
		The method used to build a Create cell from an Extend cell
		:param circ_id: The circuit ID
		:param htype: The Handshake type. TAP or ntor
		:param hlen: The Length of Handshake object
		:param hdata: The Handshake data object of type TapCHData
		:return: The create Cell object
		"""
		create_cell_payload = CreateCellPayload(htype, hlen, hdata)
		create_cell = Cell(circ_id, Cell.CMD_ENUM['CREATE2'], Cell.PAYLOAD_LEN, create_cell_payload)
		return create_cell
Beispiel #2
0
	def parse_encoded_create_cell(cell_bytes: bytes) -> Cell:
		cell_tuple = Parser.parse_basic_cell(cell_bytes)

		hlen = CreateCellPayload.CREATE_HANDSHAKE_LEN['TAP']
		payload_fmt_str = '=HH'+str(hlen)+'s'
		create_cell_payload_tuple = unpack(payload_fmt_str, cell_tuple[3][0:(2+2+hlen)])

		h_data_fmt_str = '='+str(CC.PK_PAD_LEN)+'s'+str(CC.KEY_LEN)+'s'+str(CC.PK_ENC_LEN - CC.PK_PAD_LEN - CC.KEY_LEN)+'s'+str(CC.DH_LEN-(CC.PK_ENC_LEN-CC.PK_PAD_LEN-CC.KEY_LEN))+'s'
		h_data_tuple = unpack(h_data_fmt_str, create_cell_payload_tuple[2])

		h_data = TapCHData(h_data_tuple[0], h_data_tuple[1], h_data_tuple[2], h_data_tuple[3])
		create_cell_payload = CreateCellPayload(create_cell_payload_tuple[0], create_cell_payload_tuple[1], h_data)
		create_cell = Cell(cell_tuple[0], cell_tuple[1], cell_tuple[2], create_cell_payload)

		return create_cell
Beispiel #3
0
	def build_create_cell(handshake_type: str, x_bytes: bytes, gx_bytes: bytes, circ_id: int, onion_key) -> Cell:
		"""
		The method used to build a Create/Create2 cell
 		:param x_bytes: The diffie hellman private key as a bytes object
		:param gx_bytes: The diffie hellman public key as a bytes object
		:param circ_id: The circuit ID
		:param onion_key: The onion key of the next hop used in hybrid_encrypt method
		:return: The create Cell object
		"""
		client_h_data = CoreCryptoRSA.hybrid_encrypt(gx_bytes, onion_key)
		create_cell_payload = CreateCellPayload(CreateCellPayload.CREATE_HANDSHAKE_TYPE[handshake_type],
												CreateCellPayload.CREATE_HANDSHAKE_LEN[handshake_type],
												client_h_data)
		create_cell = Cell(circ_id, Cell.CMD_ENUM['CREATE2'], Cell.PAYLOAD_LEN, create_cell_payload)
		return create_cell