openc2lib.transfers.http.http_transfer

HTTP Transfer Protocol

This module defines implementation of the Transfer interface for the HTTP/HTTPs protocols. This implementation is mostly provided for research and development purposes, but it is not suitable for production environments.

The implementation follows the Specification for Transfer of OpenC2 Messages via HTTPS Version 1.1, which is indicated as the "Specification" in the following.

  1""" HTTP Transfer Protocol
  2
  3	This module defines implementation of the `Transfer` interface for the 
  4  	HTTP/HTTPs protocols. This implementation is mostly provided for 
  5	research and development purposes, but it is not suitable for production
  6	environments.
  7
  8	The implementation follows the Specification for Transfer of OpenC2 Messages via HTTPS
  9	Version 1.1, which is indicated as the "Specification" in the following.
 10"""
 11import dataclasses
 12import requests
 13import logging
 14import copy
 15
 16from flask import Flask, request, make_response
 17
 18import openc2lib as oc2
 19from openc2lib.transfers.http.message import Message
 20
 21
 22logger = logging.getLogger('openc2lib')
 23""" The logging facility in openc2lib """
 24
 25class HTTPTransfer(oc2.Transfer):
 26	""" HTTP Transfer Protocol
 27
 28		This class provides an implementation of the Specification. It builds on Flask and so it is not
 29		suitable for production environments.
 30
 31		Use `HTTPTransfer` to build OpenC2 communication stacks in `Producer` and `Consumer`.
 32	"""
 33	def __init__(self, host, port = 80, endpoint = '/.well-known/openc2', usessl=False):
 34		""" Builds the `HTTPTransfer` instance
 35
 36			The `host` and `port` parameters are used either for selecting the remote server (`Producer`) or
 37			for local binding (`Consumer`). This implementation only supports TCP as transport protocol.
 38			:param host: Hostname or IP address of the OpenC2 server.
 39			:param port: Transport port of the OpenC2 server.
 40			:param endpoint: The remote endpoint to contact the OpenC2 server (`Producer` only).
 41			:param usessl: Enable (`True`) or disable (`False`) SSL. Internal use only. Do not set this argument,
 42				use the `HTTPSTransfer` instead.
 43		"""
 44		self.host = host
 45		self.port = port
 46		self.endpoint = endpoint
 47		self.scheme = 'https' if usessl else 'http'
 48		self.url = f"{self.scheme}://{host}:{port}{endpoint}"
 49		self.ssl_context = None
 50
 51	def _tohttp(self, msg, encoder):
 52		""" Convert openc2lib `Message` to HTTP `Message` """
 53		m = Message()
 54		m.set(msg)
 55
 56		# Encode the data
 57		if encoder is not None:
 58			data = encoder.encode(m)
 59		else:
 60			data = oc2.Encoder().encode(m)
 61
 62		return data
 63
 64	def _fromhttp(self, hdr, data):
 65		""" Convert HTTP `Message` to openc2lib `Message` """
 66
 67		# TODO: Check the HTTP headers for version/encoding
 68		content_type =hdr['Content-type']
 69
 70		if not content_type.removeprefix('application/').startswith(oc2.Message.content_type):
 71			raise ValueError("Unsupported content type")
 72
 73		enctype = content_type.removeprefix('application/'+oc2.Message.content_type+'+').split(';')[0]
 74		try:
 75			encoder = oc2.Encoders[enctype].value
 76		except KeyError:
 77			raise ValueError("Unsupported encoding scheme: " + enctype)
 78
 79		# HTTP processing to extract the headers
 80		# and the transport body
 81		msg = encoder.decode(data, Message).get()
 82		msg.content_type = hdr['Content-type'].removeprefix('application/').split('+')[0]
 83		msg.version = oc2.Version.fromstr(hdr['Content-type'].split(';')[1].removeprefix("version="))
 84		msg.encoding = encoder
 85
 86		
 87		try:
 88			msg.status = msg.content['status']
 89		except:
 90			msg.status = None
 91
 92
 93		return msg, encoder
 94
 95
 96	# This function is used to send an HTTP request
 97	def send(self, msg, encoder):
 98		""" Sends OpenC2 message
 99
100			This method implements the required `Transfer` interface to send message to an OpenC2 server.
101			:param msg: The message to send (openc2lib `Message`).
102			:param encoder: The encoder to use for encoding the `msg`.
103			:return: An OpenC2  response (`Response`).
104		"""
105		# Convert the message to the specific HTTP representation
106		openc2data = self._tohttp(msg, encoder)
107
108		# Building the requested headers for the Request
109		content_type = f"application/{msg.content_type}+{encoder.getName()};version={msg.version}"
110		date = msg.created if msg.created else int(oc2.DateTime())
111		openc2headers={'Content-Type': content_type, 'Accept': content_type, 'Date': oc2.DateTime(date).httpdate()}
112
113		logger.info("Sending to %s", self.url)
114		logger.info(" -> body: %s", openc2data)
115
116		# Send the OpenC2 message and get the response
117		if self.scheme == 'https':
118			logger.warning("Certificate validation disabled!")
119		response = requests.post(self.url, data=openc2data, headers=openc2headers, verify=False)
120		logger.info("HTTP got response: %s", response)
121	
122		# TODO: How to manage HTTP response code? Can we safely assume they always match the Openc2 response?
123		try:
124			if response.text != "":
125				msg = self._fromhttp(response.headers, response.text)
126			else:
127				msg = None
128		except ValueError as e:
129			msg = oc2.Message(oc2.Content())
130			msg.status = response.status_code
131			logger.error("Unable to parse data: >%s<", response.text)
132			logger.error(str(e))
133
134		return msg
135
136	# This function is used to prepare the headers and content in a response
137	def _respond(self, msg, encoder):
138		""" Responds to received OpenC2 message """
139
140		headers = {}
141		if msg is not None:
142			if encoder is not None:
143				content_type = f"application/{msg.content_type}+{encoder.getName()};version={msg.version}"
144			else:	
145				content_type = f"text/plain"
146			headers['Content-Type']= content_type
147			date = msg.created if msg.created else int(oc2.DateTime())
148			data = self._tohttp(msg, encoder)
149		else:
150			content_type = None
151			data = None
152			date = int(oc2.DateTime())
153
154		# Date is currently autmatically inserted by Flask (probably 
155		# after I used 'make_response')
156		#headers['Date'] = oc2.DateTime(date).httpdate()
157
158		return headers, data
159
160	def _recv(self, headers, data):
161		""" Retrieve HTTP messages
162			
163			Internal function to convert Flask data into openc2lib `Message` structure and `Encoder`.
164			The `encoder` is derived from the HTTP header, to provide the ability to manage multiple
165			clients that use different encoding formats.
166			:param headers: HTTP headers.
167			:param data: HTTP body.
168			:return: An openc2lib `Message` (first) and an `Encoder` instance (second).
169		"""
170
171		logger.debug("Received body: %s", data)
172		msg, encoder = self._fromhttp(headers, data)
173		logger.info("Received command: %s", msg)
174  			
175		return msg, encoder
176	
177	def receive(self, callback, encoder):
178		""" Listen for incoming messages
179
180			This method implements the `Transfer` interface to listen for and receive OpenC2 messages.
181			The internal implementation uses `Flask` as HTTP server. The method invokes the `callback`
182			for each received message, which must be provided by a `Producer` to properly dispatch 
183			`Command`s to the relevant server(s). It also takes an `Encoder` that is used to create
184			responses to `Command`s encoded with unknown encoders.
185			:param callback: The function that is invoked to process OpenC2 messages.
186			:param encoder: Default `Encoder` instance to respond to unknown or wrong messages.
187			:return :None
188		"""
189		app = Flask(__name__)
190		app.config['OPENC2']=self
191		app.config['CALLBACK']=callback
192		app.config['ENCODER']=encoder
193
194		@app.route(self.endpoint, methods=['POST'])
195		def _consumer():
196			""" Serving endpoint for `Flask` """
197			server = app.config['OPENC2']
198			callback = app.config['CALLBACK']
199			encoder=app.config['ENCODER']
200			
201			try:
202				cmd, encoder = server._recv(request.headers, request.data.decode('UTF-8') )
203				# TODO: Add the code to answer according to 'response_requested'
204			except ValueError as e:
205				# TODO: Find better formatting (what should be returned if the request is not understood?)
206				content = oc2.Response(status=oc2.StatusCode.BADREQUEST, status_text=str(e))
207				resp = oc2.Message(content)
208				resp.content_type = oc2.Message.content_type
209				resp.version = oc2.Message.version
210				resp.encoder = encoder
211				resp.status=oc2.StatusCode.BADREQUEST
212			else:
213				logger.info("Received command: %s", cmd)
214				resp = callback(cmd)
215
216			
217			logger.debug("Got response: %s", resp)
218			
219			# TODO: Set HTTP headers as appropriate
220			hdrs, data = server._respond(resp, encoder)
221			logger.info("Sending response: %s", data)
222			httpresp = make_response(data if data is not None else "") 
223			httpresp.headers = hdrs
224
225			if data is None:
226				resp_code = 200
227			else:
228				resp_code = resp.status.value
229
230			return httpresp, resp_code
231
232		app.run(debug=True, host=self.host, port=self.port, ssl_context=self.ssl_context)
233
234
235class HTTPSTransfer(HTTPTransfer):
236	""" HTTP Transfer Protocol with SSL
237
238		This class provides an implementation of the Specification. It builds on Flask and so it is not
239		suitable for production environments.
240
241		Use `HTTPSTransfer` to build OpenC2 communication stacks in `Producer` and `Consumer`.
242		Usage and methods of `HTTPSTransfer` are semanthically the same as for `HTTPTransfer`.
243	"""
244	def __init__(self, host, port = 443, endpoint = '/.well-known/openc2'):
245		""" Builds the `HTTPSTransfer` instance
246
247			The `host` and `port` parameters are used either for selecting the remote server (`Producer`) or
248			for local binding (`Consumer`). This implementation only supports TCP as transport protocol.
249			:param host: Hostname or IP address of the OpenC2 server.
250			:param port: Transport port of the OpenC2 server.
251			:param endpoint: The remote endpoint to contact the OpenC2 server (`Producer` only).
252		"""
253		HTTPTransfer.__init__(self, host, port, endpoint, usessl=True)
254		self.ssl_context = "adhoc"
logger = <Logger openc2lib (WARNING)>

The logging facility in openc2lib

class HTTPTransfer(openc2lib.core.transfer.Transfer):
 26class HTTPTransfer(oc2.Transfer):
 27	""" HTTP Transfer Protocol
 28
 29		This class provides an implementation of the Specification. It builds on Flask and so it is not
 30		suitable for production environments.
 31
 32		Use `HTTPTransfer` to build OpenC2 communication stacks in `Producer` and `Consumer`.
 33	"""
 34	def __init__(self, host, port = 80, endpoint = '/.well-known/openc2', usessl=False):
 35		""" Builds the `HTTPTransfer` instance
 36
 37			The `host` and `port` parameters are used either for selecting the remote server (`Producer`) or
 38			for local binding (`Consumer`). This implementation only supports TCP as transport protocol.
 39			:param host: Hostname or IP address of the OpenC2 server.
 40			:param port: Transport port of the OpenC2 server.
 41			:param endpoint: The remote endpoint to contact the OpenC2 server (`Producer` only).
 42			:param usessl: Enable (`True`) or disable (`False`) SSL. Internal use only. Do not set this argument,
 43				use the `HTTPSTransfer` instead.
 44		"""
 45		self.host = host
 46		self.port = port
 47		self.endpoint = endpoint
 48		self.scheme = 'https' if usessl else 'http'
 49		self.url = f"{self.scheme}://{host}:{port}{endpoint}"
 50		self.ssl_context = None
 51
 52	def _tohttp(self, msg, encoder):
 53		""" Convert openc2lib `Message` to HTTP `Message` """
 54		m = Message()
 55		m.set(msg)
 56
 57		# Encode the data
 58		if encoder is not None:
 59			data = encoder.encode(m)
 60		else:
 61			data = oc2.Encoder().encode(m)
 62
 63		return data
 64
 65	def _fromhttp(self, hdr, data):
 66		""" Convert HTTP `Message` to openc2lib `Message` """
 67
 68		# TODO: Check the HTTP headers for version/encoding
 69		content_type =hdr['Content-type']
 70
 71		if not content_type.removeprefix('application/').startswith(oc2.Message.content_type):
 72			raise ValueError("Unsupported content type")
 73
 74		enctype = content_type.removeprefix('application/'+oc2.Message.content_type+'+').split(';')[0]
 75		try:
 76			encoder = oc2.Encoders[enctype].value
 77		except KeyError:
 78			raise ValueError("Unsupported encoding scheme: " + enctype)
 79
 80		# HTTP processing to extract the headers
 81		# and the transport body
 82		msg = encoder.decode(data, Message).get()
 83		msg.content_type = hdr['Content-type'].removeprefix('application/').split('+')[0]
 84		msg.version = oc2.Version.fromstr(hdr['Content-type'].split(';')[1].removeprefix("version="))
 85		msg.encoding = encoder
 86
 87		
 88		try:
 89			msg.status = msg.content['status']
 90		except:
 91			msg.status = None
 92
 93
 94		return msg, encoder
 95
 96
 97	# This function is used to send an HTTP request
 98	def send(self, msg, encoder):
 99		""" Sends OpenC2 message
100
101			This method implements the required `Transfer` interface to send message to an OpenC2 server.
102			:param msg: The message to send (openc2lib `Message`).
103			:param encoder: The encoder to use for encoding the `msg`.
104			:return: An OpenC2  response (`Response`).
105		"""
106		# Convert the message to the specific HTTP representation
107		openc2data = self._tohttp(msg, encoder)
108
109		# Building the requested headers for the Request
110		content_type = f"application/{msg.content_type}+{encoder.getName()};version={msg.version}"
111		date = msg.created if msg.created else int(oc2.DateTime())
112		openc2headers={'Content-Type': content_type, 'Accept': content_type, 'Date': oc2.DateTime(date).httpdate()}
113
114		logger.info("Sending to %s", self.url)
115		logger.info(" -> body: %s", openc2data)
116
117		# Send the OpenC2 message and get the response
118		if self.scheme == 'https':
119			logger.warning("Certificate validation disabled!")
120		response = requests.post(self.url, data=openc2data, headers=openc2headers, verify=False)
121		logger.info("HTTP got response: %s", response)
122	
123		# TODO: How to manage HTTP response code? Can we safely assume they always match the Openc2 response?
124		try:
125			if response.text != "":
126				msg = self._fromhttp(response.headers, response.text)
127			else:
128				msg = None
129		except ValueError as e:
130			msg = oc2.Message(oc2.Content())
131			msg.status = response.status_code
132			logger.error("Unable to parse data: >%s<", response.text)
133			logger.error(str(e))
134
135		return msg
136
137	# This function is used to prepare the headers and content in a response
138	def _respond(self, msg, encoder):
139		""" Responds to received OpenC2 message """
140
141		headers = {}
142		if msg is not None:
143			if encoder is not None:
144				content_type = f"application/{msg.content_type}+{encoder.getName()};version={msg.version}"
145			else:	
146				content_type = f"text/plain"
147			headers['Content-Type']= content_type
148			date = msg.created if msg.created else int(oc2.DateTime())
149			data = self._tohttp(msg, encoder)
150		else:
151			content_type = None
152			data = None
153			date = int(oc2.DateTime())
154
155		# Date is currently autmatically inserted by Flask (probably 
156		# after I used 'make_response')
157		#headers['Date'] = oc2.DateTime(date).httpdate()
158
159		return headers, data
160
161	def _recv(self, headers, data):
162		""" Retrieve HTTP messages
163			
164			Internal function to convert Flask data into openc2lib `Message` structure and `Encoder`.
165			The `encoder` is derived from the HTTP header, to provide the ability to manage multiple
166			clients that use different encoding formats.
167			:param headers: HTTP headers.
168			:param data: HTTP body.
169			:return: An openc2lib `Message` (first) and an `Encoder` instance (second).
170		"""
171
172		logger.debug("Received body: %s", data)
173		msg, encoder = self._fromhttp(headers, data)
174		logger.info("Received command: %s", msg)
175  			
176		return msg, encoder
177	
178	def receive(self, callback, encoder):
179		""" Listen for incoming messages
180
181			This method implements the `Transfer` interface to listen for and receive OpenC2 messages.
182			The internal implementation uses `Flask` as HTTP server. The method invokes the `callback`
183			for each received message, which must be provided by a `Producer` to properly dispatch 
184			`Command`s to the relevant server(s). It also takes an `Encoder` that is used to create
185			responses to `Command`s encoded with unknown encoders.
186			:param callback: The function that is invoked to process OpenC2 messages.
187			:param encoder: Default `Encoder` instance to respond to unknown or wrong messages.
188			:return :None
189		"""
190		app = Flask(__name__)
191		app.config['OPENC2']=self
192		app.config['CALLBACK']=callback
193		app.config['ENCODER']=encoder
194
195		@app.route(self.endpoint, methods=['POST'])
196		def _consumer():
197			""" Serving endpoint for `Flask` """
198			server = app.config['OPENC2']
199			callback = app.config['CALLBACK']
200			encoder=app.config['ENCODER']
201			
202			try:
203				cmd, encoder = server._recv(request.headers, request.data.decode('UTF-8') )
204				# TODO: Add the code to answer according to 'response_requested'
205			except ValueError as e:
206				# TODO: Find better formatting (what should be returned if the request is not understood?)
207				content = oc2.Response(status=oc2.StatusCode.BADREQUEST, status_text=str(e))
208				resp = oc2.Message(content)
209				resp.content_type = oc2.Message.content_type
210				resp.version = oc2.Message.version
211				resp.encoder = encoder
212				resp.status=oc2.StatusCode.BADREQUEST
213			else:
214				logger.info("Received command: %s", cmd)
215				resp = callback(cmd)
216
217			
218			logger.debug("Got response: %s", resp)
219			
220			# TODO: Set HTTP headers as appropriate
221			hdrs, data = server._respond(resp, encoder)
222			logger.info("Sending response: %s", data)
223			httpresp = make_response(data if data is not None else "") 
224			httpresp.headers = hdrs
225
226			if data is None:
227				resp_code = 200
228			else:
229				resp_code = resp.status.value
230
231			return httpresp, resp_code
232
233		app.run(debug=True, host=self.host, port=self.port, ssl_context=self.ssl_context)

HTTP Transfer Protocol

This class provides an implementation of the Specification. It builds on Flask and so it is not suitable for production environments.

Use HTTPTransfer to build OpenC2 communication stacks in Producer and Consumer.

HTTPTransfer(host, port=80, endpoint='/.well-known/openc2', usessl=False)
34	def __init__(self, host, port = 80, endpoint = '/.well-known/openc2', usessl=False):
35		""" Builds the `HTTPTransfer` instance
36
37			The `host` and `port` parameters are used either for selecting the remote server (`Producer`) or
38			for local binding (`Consumer`). This implementation only supports TCP as transport protocol.
39			:param host: Hostname or IP address of the OpenC2 server.
40			:param port: Transport port of the OpenC2 server.
41			:param endpoint: The remote endpoint to contact the OpenC2 server (`Producer` only).
42			:param usessl: Enable (`True`) or disable (`False`) SSL. Internal use only. Do not set this argument,
43				use the `HTTPSTransfer` instead.
44		"""
45		self.host = host
46		self.port = port
47		self.endpoint = endpoint
48		self.scheme = 'https' if usessl else 'http'
49		self.url = f"{self.scheme}://{host}:{port}{endpoint}"
50		self.ssl_context = None

Builds the HTTPTransfer instance

The host and port parameters are used either for selecting the remote server (Producer) or for local binding (Consumer). This implementation only supports TCP as transport protocol.

Parameters
  • host: Hostname or IP address of the OpenC2 server.
  • port: Transport port of the OpenC2 server.
  • endpoint: The remote endpoint to contact the OpenC2 server (Producer only).
  • usessl: Enable (True) or disable (False) SSL. Internal use only. Do not set this argument, use the HTTPSTransfer instead.
host
port
endpoint
scheme
url
ssl_context
def send(self, msg, encoder):
 98	def send(self, msg, encoder):
 99		""" Sends OpenC2 message
100
101			This method implements the required `Transfer` interface to send message to an OpenC2 server.
102			:param msg: The message to send (openc2lib `Message`).
103			:param encoder: The encoder to use for encoding the `msg`.
104			:return: An OpenC2  response (`Response`).
105		"""
106		# Convert the message to the specific HTTP representation
107		openc2data = self._tohttp(msg, encoder)
108
109		# Building the requested headers for the Request
110		content_type = f"application/{msg.content_type}+{encoder.getName()};version={msg.version}"
111		date = msg.created if msg.created else int(oc2.DateTime())
112		openc2headers={'Content-Type': content_type, 'Accept': content_type, 'Date': oc2.DateTime(date).httpdate()}
113
114		logger.info("Sending to %s", self.url)
115		logger.info(" -> body: %s", openc2data)
116
117		# Send the OpenC2 message and get the response
118		if self.scheme == 'https':
119			logger.warning("Certificate validation disabled!")
120		response = requests.post(self.url, data=openc2data, headers=openc2headers, verify=False)
121		logger.info("HTTP got response: %s", response)
122	
123		# TODO: How to manage HTTP response code? Can we safely assume they always match the Openc2 response?
124		try:
125			if response.text != "":
126				msg = self._fromhttp(response.headers, response.text)
127			else:
128				msg = None
129		except ValueError as e:
130			msg = oc2.Message(oc2.Content())
131			msg.status = response.status_code
132			logger.error("Unable to parse data: >%s<", response.text)
133			logger.error(str(e))
134
135		return msg

Sends OpenC2 message

This method implements the required Transfer interface to send message to an OpenC2 server.

Parameters
  • msg: The message to send (openc2lib Message).
  • encoder: The encoder to use for encoding the msg.
Returns

An OpenC2 response (Response).

def receive(self, callback, encoder):
178	def receive(self, callback, encoder):
179		""" Listen for incoming messages
180
181			This method implements the `Transfer` interface to listen for and receive OpenC2 messages.
182			The internal implementation uses `Flask` as HTTP server. The method invokes the `callback`
183			for each received message, which must be provided by a `Producer` to properly dispatch 
184			`Command`s to the relevant server(s). It also takes an `Encoder` that is used to create
185			responses to `Command`s encoded with unknown encoders.
186			:param callback: The function that is invoked to process OpenC2 messages.
187			:param encoder: Default `Encoder` instance to respond to unknown or wrong messages.
188			:return :None
189		"""
190		app = Flask(__name__)
191		app.config['OPENC2']=self
192		app.config['CALLBACK']=callback
193		app.config['ENCODER']=encoder
194
195		@app.route(self.endpoint, methods=['POST'])
196		def _consumer():
197			""" Serving endpoint for `Flask` """
198			server = app.config['OPENC2']
199			callback = app.config['CALLBACK']
200			encoder=app.config['ENCODER']
201			
202			try:
203				cmd, encoder = server._recv(request.headers, request.data.decode('UTF-8') )
204				# TODO: Add the code to answer according to 'response_requested'
205			except ValueError as e:
206				# TODO: Find better formatting (what should be returned if the request is not understood?)
207				content = oc2.Response(status=oc2.StatusCode.BADREQUEST, status_text=str(e))
208				resp = oc2.Message(content)
209				resp.content_type = oc2.Message.content_type
210				resp.version = oc2.Message.version
211				resp.encoder = encoder
212				resp.status=oc2.StatusCode.BADREQUEST
213			else:
214				logger.info("Received command: %s", cmd)
215				resp = callback(cmd)
216
217			
218			logger.debug("Got response: %s", resp)
219			
220			# TODO: Set HTTP headers as appropriate
221			hdrs, data = server._respond(resp, encoder)
222			logger.info("Sending response: %s", data)
223			httpresp = make_response(data if data is not None else "") 
224			httpresp.headers = hdrs
225
226			if data is None:
227				resp_code = 200
228			else:
229				resp_code = resp.status.value
230
231			return httpresp, resp_code
232
233		app.run(debug=True, host=self.host, port=self.port, ssl_context=self.ssl_context)

Listen for incoming messages

This method implements the Transfer interface to listen for and receive OpenC2 messages. The internal implementation uses Flask as HTTP server. The method invokes the callback for each received message, which must be provided by a Producer to properly dispatch Commands to the relevant server(s). It also takes an Encoder that is used to create responses to Commands encoded with unknown encoders.

Parameters
  • callback: The function that is invoked to process OpenC2 messages.
  • encoder: Default Encoder instance to respond to unknown or wrong messages. :return :None
class HTTPSTransfer(HTTPTransfer):
236class HTTPSTransfer(HTTPTransfer):
237	""" HTTP Transfer Protocol with SSL
238
239		This class provides an implementation of the Specification. It builds on Flask and so it is not
240		suitable for production environments.
241
242		Use `HTTPSTransfer` to build OpenC2 communication stacks in `Producer` and `Consumer`.
243		Usage and methods of `HTTPSTransfer` are semanthically the same as for `HTTPTransfer`.
244	"""
245	def __init__(self, host, port = 443, endpoint = '/.well-known/openc2'):
246		""" Builds the `HTTPSTransfer` instance
247
248			The `host` and `port` parameters are used either for selecting the remote server (`Producer`) or
249			for local binding (`Consumer`). This implementation only supports TCP as transport protocol.
250			:param host: Hostname or IP address of the OpenC2 server.
251			:param port: Transport port of the OpenC2 server.
252			:param endpoint: The remote endpoint to contact the OpenC2 server (`Producer` only).
253		"""
254		HTTPTransfer.__init__(self, host, port, endpoint, usessl=True)
255		self.ssl_context = "adhoc"

HTTP Transfer Protocol with SSL

This class provides an implementation of the Specification. It builds on Flask and so it is not suitable for production environments.

Use HTTPSTransfer to build OpenC2 communication stacks in Producer and Consumer. Usage and methods of HTTPSTransfer are semanthically the same as for HTTPTransfer.

HTTPSTransfer(host, port=443, endpoint='/.well-known/openc2')
245	def __init__(self, host, port = 443, endpoint = '/.well-known/openc2'):
246		""" Builds the `HTTPSTransfer` instance
247
248			The `host` and `port` parameters are used either for selecting the remote server (`Producer`) or
249			for local binding (`Consumer`). This implementation only supports TCP as transport protocol.
250			:param host: Hostname or IP address of the OpenC2 server.
251			:param port: Transport port of the OpenC2 server.
252			:param endpoint: The remote endpoint to contact the OpenC2 server (`Producer` only).
253		"""
254		HTTPTransfer.__init__(self, host, port, endpoint, usessl=True)
255		self.ssl_context = "adhoc"

Builds the HTTPSTransfer instance

The host and port parameters are used either for selecting the remote server (Producer) or for local binding (Consumer). This implementation only supports TCP as transport protocol.

Parameters
  • host: Hostname or IP address of the OpenC2 server.
  • port: Transport port of the OpenC2 server.
  • endpoint: The remote endpoint to contact the OpenC2 server (Producer only).
ssl_context