Callbacks Module
- class mtf.network_port.tls.helpers.callbacks.MsgParser
Parses TLS messages and extracts relevant information.
- tls1_3: bool
- parse_tls_message(direction: int, content_type: int, data: bytes)
Parses a TLS message based on its content type.
- Args:
direction (int): The direction of the message (incoming or outgoing). content_type (int): The type of TLS content. data (bytes): The raw TLS message data.
- Returns:
Parsed TLS message or None if the content type is unhandled.
- check_content_type(content_type, content_type_check)
Checks if the given content type matches the expected type.
- Args:
content_type (int): The content type of the message. content_type_check (int): The expected content type.
- Returns:
bool: True if the content type matches, otherwise False.
- check_parser_func_type(parser_func, data, type)
Calls the appropriate parser function for a given TLS content type.
- Args:
parser_func (function): The parser function for the given content type. data (bytes): The TLS message data. content_type (int): The TLS content type.
- Returns:
Parsed data or logs a debug message if unhandled.
- parse_client_hello(data)
Parses a ClientHello message from a TLS handshake.
- Args:
data (bytes): The raw ClientHello message.
- Returns:
ClientHello: Parsed ClientHello data.
- parse_server_hello(data)
Parses a ServerHello message from a TLS handshake.
- Args:
data (bytes): The raw ServerHello message.
- Returns:
ServerHello: Parsed ServerHello data.
- parse_server_hello_done(data)
Parses a ServerHelloDone message from a TLS handshake.
- Args:
data (bytes): The raw ServerHelloDone message.
- Returns:
ServerHelloDone: Parsed ServerHelloDone data.
- parse_encrypted_extensions(data)
Parses an EncryptedExtensions message from TLS 1.3 handshake.
- Args:
data (bytes): The raw EncryptedExtensions message.
- Returns:
EncryptedExtensions: Parsed EncryptedExtensions data.
- parse_client_key_exchange(data)
Parses a ClientKeyExchange message from a TLS handshake.
- Args:
data (bytes): The raw ClientKeyExchange message.
- Returns:
PskClientKeyExchange: Parsed ClientKeyExchange data.
- parse_server_key_exchange(data)
Parses a ServerKeyExchange message from a TLS handshake.
- Args:
data (bytes): The raw ServerKeyExchange message.
- Returns:
PskServerKeyExchange: Parsed ServerKeyExchange data.
- parse_change_cipher_spec(data)
Parses a ChangeCipherSpec message.
- Args:
data (bytes): The raw ChangeCipherSpec message.
- Returns:
ChangeCipherSpec: Parsed ChangeCipherSpec data.
- parse_certificate_request(data)
Parses a CertificateRequest message from a TLS handshake.
- Args:
data (bytes): The raw CertificateRequest message.
- Returns:
CertificateRequest: Parsed CertificateRequest data.
- parse_certificate(data, direction)
Parses a Certificate message from a TLS handshake.
- Args:
data (bytes): The raw Certificate message. direction (int): The direction of the handshake (client or server).
- Returns:
CertificateMessage: Parsed Certificate data.
- parse_certificate_verify(data)
Parses a CertificateVerify message from a TLS handshake.
- Args:
data (bytes): The raw CertificateVerify message.
- Returns:
CertificateVerify: Parsed CertificateVerify data.
- parse_finished(data)
Parses a Finished message from a TLS handshake.
- Args:
data (bytes): The raw Finished message.
- Returns:
Finished: Parsed Finished message data.
- parse_alert(data)
Parses an Alert message from TLS.
- Args:
data (bytes): The raw Alert message.
- Returns:
Alert: Parsed Alert message data.
- parse_session_ticket(data)
Parses a SessionTicket message from TLS.
- Args:
data (bytes): The raw SessionTicket message.
- Returns:
SessionTicket: Parsed SessionTicket data.
- class mtf.network_port.tls.helpers.callbacks.MsgCallback
Handles setting the message callback for SSL communication.
- handshake_info
- msg_parser
- set_msg_callback(callback)
Sets the message callback function for SSL context.
- Args:
callback (function): The function to be used as a callback for SSL messages.
- check_handshake_message(msg_type: TlsMessage, secure_version, tls_manager: Any, psk_key: bytes) bool
Checks if a specific TLS handshake message type has been sent or received.
This method verifies whether a given handshake message type (msg_type) has been exchanged by the TLS client. It updates _handshake_info with messages retrieved from TlsClientManager if the list is empty.
If the specified handshake message is found in _handshake_info, it is removed from the list and the function returns True. Otherwise, it logs that the message was not sent or received and returns False.
- Args:
msg_type (TlsMessage): The type of TLS handshake message to check.
- Returns:
bool: True if the message was found, otherwise False.
- msg_cb(write_p: int, content_type: int, data: bytes) None
Callback function for handling messages.
- Args:
write_p (int): The direction of the message (incoming or outgoing). content_type (int): The type of TLS content. data (bytes): The raw TLS message data.
- Returns:
None
- get_callback_message(msg_type: Any)
Retrieves a callback message based on the given TLS message type.
- Args:
msg_type (TlsMessage): The type of TLS message for which the callback message is required.
- Returns:
The handshake message corresponding to the provided message type.