tls package¶
Subpackages¶
Submodules¶
tls.alert_message module¶
tls.ciphersuites module¶
tls.exceptions module¶
tls.hello_message module¶
-
class
tls.hello_message.ClientHello(*args, **kw)¶ Bases:
objectAn object representing a ClientHello message.
-
classmethod
from_bytes(bytes)¶ Parse a
ClientHellostruct.Parameters: bytes – the bytes representing the input. Returns: ClientHello object.
-
classmethod
-
class
tls.hello_message.Extension(*args, **kw)¶ Bases:
objectAn object representing an Extension struct.
tls.message module¶
-
class
tls.message.Certificate(*args, **kw)¶ Bases:
objectAn object representing a Certificate struct.
-
classmethod
from_bytes(bytes)¶ Parse a
Certificatestruct.Parameters: bytes – the bytes representing the input. Returns: Certificate object.
-
classmethod
-
class
tls.message.CertificateRequest(*args, **kw)¶ Bases:
objectAn object representing a CertificateRequest struct.
-
classmethod
from_bytes(bytes)¶ Parse a
CertificateRequeststruct.Parameters: bytes – the bytes representing the input. Returns: CertificateRequest object.
-
classmethod
-
class
tls.message.Handshake(*args, **kw)¶ Bases:
objectAn object representing a Handshake struct.
-
classmethod
from_bytes(bytes)¶ Parse a
Handshakestruct.Parameters: bytes – the bytes representing the input. Returns: Handshake object.
-
classmethod
-
class
tls.message.PreMasterSecret(*args, **kw)¶ Bases:
objectAn object representing a PreMasterSecret struct.
-
classmethod
from_bytes(bytes)¶ Parse a
PreMasterSecretstruct.Parameters: bytes – the bytes representing the input. Returns: CertificateRequest object.
-
classmethod
tls.record module¶
-
class
tls.record.ProtocolVersion(*args, **kw)¶ Bases:
objectAn object representing a ProtocolVersion struct.
-
class
tls.record.TLSCiphertext(*args, **kw)¶ Bases:
objectAn object representing a TLSCiphertext struct.
-
classmethod
from_bytes(bytes)¶ Parse a
TLSCiphertextstruct.Parameters: bytes – the bytes representing the input. Returns: TLSCiphertext object.
-
classmethod
tls.utils module¶
-
tls.utils.EnumClass(type_field, type_enum)¶ Maps the members of an
enum.Enumto a single kind ofconstruct.Construct.Parameters: - type_field (
construct.Construct) – The construct that represents the enum’s members. The type of this should correspond to the enum members’ types; for instance, an enum with a maximum value of 65535 would use aconstruct.macros.UBInt16. - type_enum (
enum.Enum) – The enum to encode and decode.
- type_field (
-
tls.utils.EnumSwitch(type_field, type_enum, value_field, value_choices)¶ Maps the members of an
enum.Enumto arbitraryconstruct.Constructs(). It returns a tuple intended to be spliced into anotherconstruct.Construct()‘s definition:>>> from tls.utils import EnumSwitch >>> import construct, enum >>> class IntEnum(enum.Enum): ... VALUE = 1 ... >>> construct.Struct( ... "name", ... construct.UBInt8("an_integer"), ... *EnumSwitch(type_field=construct.UBInt8("type"), ... type_enum=IntEnum, ... value_field="value", ... value_choices={ ... IntEnum.VALUE: construct.UBInt8("first"), ... }) ... ) ... Struct('name')
Parameters: - type_field (
construct.Construct) – The construct that represents the enum’s members. The type of this should correspond to the enum members’ types, so an enum with a maximum value of 65535, for example, would use aconstruct.macros.UBInt16. - type_enum (
enum.Enum) – The enum to encode and decode. - value_field (
str) – The attribute name under which this value will be accessible. - value_choices (
dict) – A dictionary that maps members of type_enum to subconstructs. This followsconstruct.core.Switch()‘s API, so_default_will match any members without an explicit mapping.
Returns: A
tupleof the form (EnumClass(),construct.core.Switch())- type_field (
-
tls.utils.PrefixedBytes(name, length_field=FormatField('length'))¶ Length-prefixed binary data. This is like a
construct.macros.PascalString()that raises aconstrcut.AdaptationErrorwhen encoding something other thanbytes.Parameters: - name (
str) – The attribute name under which this value will be accessible. - length_field (a
construct.core.FormatField) – (optional) The prefixed length field. Defaults toconstruct.macros.UBInt8().
- name (
-
tls.utils.TLSPrefixedArray(subconn, length_name='length')¶ The TLS vector type. It specializes on another
construct.Constructand then encodes or decodes an arbitrarily long list or array of those constructs, prepending or reading a leading 16 bit length.Parameters: - subconn (construct.Construct) – The construct this array contains.
- length_field (
str) – (optional) The attribute name under which theconstruct.macros.UBInt16representing this array’s length will be accessible. You do not need to provide this when encoding a python sequence!