otupy.transfers.http.http_transfer.HTTPTransfer
- class HTTPTransfer(host, port=80, endpoint='/.well-known/openc2', usessl=False)
Bases:
TransferHTTP 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.
Methods
Listen for incoming messages
Sends OpenC2 message
- __init__(host, port=80, endpoint='/.well-known/openc2', usessl=False)
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.
- receive(callback, encoder)
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.
- Returns:
None
- send(msg, encoder)
Sends OpenC2 message
This method implements the required Transfer interface to send message to an OpenC2 server.
- Parameters:
msg – The message to send (otupy Message).
encoder – The encoder to use for encoding the msg.
- Returns:
An OpenC2 response (Response).