tls package

Submodules

tls.alert_message module

class tls.alert_message.Alert(*args, **kw)

Bases: object

An object representing an Alert message.

classmethod from_bytes(bytes)

Parse an Alert struct.

Parameters:bytes – the bytes representing the input.
Returns:Alert object.

tls.ciphersuites module

tls.exceptions module

tls.hello_message module

class tls.hello_message.ClientHello(*args, **kw)

Bases: object

An object representing a ClientHello message.

classmethod from_bytes(bytes)

Parse a ClientHello struct.

Parameters:bytes – the bytes representing the input.
Returns:ClientHello object.
class tls.hello_message.Extension(*args, **kw)

Bases: object

An object representing an Extension struct.

class tls.hello_message.ProtocolVersion(*args, **kw)

Bases: object

An object representing a ProtocolVersion struct.

class tls.hello_message.Random(*args, **kw)

Bases: object

An object representing a Random struct.

class tls.hello_message.ServerHello(*args, **kw)

Bases: object

An object representing a ServerHello message.

classmethod from_bytes(bytes)

Parse a ServerHello struct.

Parameters:bytes – the bytes representing the input.
Returns:ServerHello object.

tls.message module

class tls.message.ASN1Cert(*args, **kw)

Bases: object

An object representing ASN.1 Certificate

class tls.message.Certificate(*args, **kw)

Bases: object

An object representing a Certificate struct.

classmethod from_bytes(bytes)

Parse a Certificate struct.

Parameters:bytes – the bytes representing the input.
Returns:Certificate object.
class tls.message.CertificateRequest(*args, **kw)

Bases: object

An object representing a CertificateRequest struct.

classmethod from_bytes(bytes)

Parse a CertificateRequest struct.

Parameters:bytes – the bytes representing the input.
Returns:CertificateRequest object.
class tls.message.Handshake(*args, **kw)

Bases: object

An object representing a Handshake struct.

classmethod from_bytes(bytes)

Parse a Handshake struct.

Parameters:bytes – the bytes representing the input.
Returns:Handshake object.
class tls.message.HelloRequest

Bases: object

An object representing a HelloRequest struct.

class tls.message.PreMasterSecret(*args, **kw)

Bases: object

An object representing a PreMasterSecret struct.

classmethod from_bytes(bytes)

Parse a PreMasterSecret struct.

Parameters:bytes – the bytes representing the input.
Returns:CertificateRequest object.
class tls.message.ServerDHParams(*args, **kw)

Bases: object

An object representing a ServerDHParams struct.

classmethod from_bytes(bytes)

Parse a ServerDHParams struct.

Parameters:bytes – the bytes representing the input.
Returns:ServerDHParams object.
class tls.message.ServerHelloDone

Bases: object

An object representing a ServerHelloDone struct.

class tls.message.SignatureAndHashAlgorithm(*args, **kw)

Bases: object

An object representing a SignatureAndHashAlgorithm struct.

tls.record module

class tls.record.ProtocolVersion(*args, **kw)

Bases: object

An object representing a ProtocolVersion struct.

class tls.record.TLSCiphertext(*args, **kw)

Bases: object

An object representing a TLSCiphertext struct.

classmethod from_bytes(bytes)

Parse a TLSCiphertext struct.

Parameters:bytes – the bytes representing the input.
Returns:TLSCiphertext object.
class tls.record.TLSCompressed(*args, **kw)

Bases: object

An object representing a TLSCompressed struct.

classmethod from_bytes(bytes)

Parse a TLSCompressed struct.

Parameters:bytes – the bytes representing the input.
Returns:TLSCompressed object.
class tls.record.TLSPlaintext(*args, **kw)

Bases: object

An object representing a TLSPlaintext struct.

classmethod from_bytes(bytes)

Parse a TLSPlaintext struct.

Parameters:bytes – the bytes representing the input.
Returns:TLSPlaintext object.

tls.utils module

tls.utils.EnumClass(type_field, type_enum)

Maps the members of an enum.Enum to a single kind of construct.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 a construct.macros.UBInt16.
  • type_enum (enum.Enum) – The enum to encode and decode.
tls.utils.EnumSwitch(type_field, type_enum, value_field, value_choices)

Maps the members of an enum.Enum to arbitrary construct.Constructs(). It returns a tuple intended to be spliced into another construct.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 a construct.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 follows construct.core.Switch()‘s API, so _default_ will match any members without an explicit mapping.
Returns:

A tuple of the form (EnumClass(), construct.core.Switch())

tls.utils.PrefixedBytes(name, length_field=FormatField('length'))

Length-prefixed binary data. This is like a construct.macros.PascalString() that raises a constrcut.AdaptationError when encoding something other than bytes.

Parameters:
tls.utils.TLSPrefixedArray(subconn, length_name='length')

The TLS vector type. It specializes on another construct.Construct and 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 the construct.macros.UBInt16 representing this array’s length will be accessible. You do not need to provide this when encoding a python sequence!
tls.utils.UBInt24(name)

A 24-bit integer.

Parameters:name (str) – The attribute name under which this value will be accessible.

Module contents