Package tlslite :: Module extensions :: Class SNIExtension
[hide private]
[frames] | no frames]

type SNIExtension

source code


Class for handling Server Name Indication (server_name) extension from RFC 4366.

Note that while usually the client does advertise just one name, it is possible to provide a list of names, each of different type. The type is a single byte value (represented by ints), the names are opaque byte strings, in case of DNS host names (records of type 0) they are UTF-8 encoded domain names (without the ending dot).

Nested Classes [hide private]
ServerName
ServerName(name_type, name)
Instance Methods [hide private]
 
__init__(self)
Create an instance of SNIExtension.
source code
str
__repr__(self)
Return programmer-readable representation of extension
source code
SNIExtension
create(self, hostname=None, hostNames=None, serverNames=None)
Initializes an instance with provided hostname, host names or raw server names.
source code
SNIExtension
parse(self, p)
Deserialise the extension from on-the-wire data
source code
bytearray
write(self)
Returns encoded extension, as encoded on the wire
source code

Inherited from TLSExtension: __eq__

Inherited from TLSExtension (private): _newCreate, _oldCreate

Static Methods [hide private]

Inherited from TLSExtension (private): _parseExt

Class Variables [hide private]
Instance Variables [hide private]
bytearray extData
a byte array containing the value of the extension as to be written on the wire
int extType
a 2^16-1 limited integer specifying the type of the extension that it contains, e.g.
tuple of bytearrays hostNames
tuple of hostnames (server name records of type 0) advertised in the extension.
list of ServerName serverNames
list of all names advertised in extension.

Inherited from TLSExtension: serverType

Method Details [hide private]

__init__(self)
(Constructor)

source code 

Create an instance of SNIExtension.

See also: create and parse.

Parameters:
  • server - whether to select ClientHello or ServerHello version for parsing
  • extType - type of extension encoded as an integer, to be used by subclasses
Overrides: TLSExtension.__init__

__repr__(self)
(Representation operator)

source code 

Return programmer-readable representation of extension

Returns: str
Overrides: TLSExtension.__repr__

create(self, hostname=None, hostNames=None, serverNames=None)

source code 

Initializes an instance with provided hostname, host names or raw server names.

Any of the parameters may be None, in that case the list inside the extension won't be defined, if either hostNames or serverNames is an empty list, then the extension will define a list of lenght 0.

If multiple parameters are specified at the same time, then the resulting list of names will be concatenated in order of hostname, hostNames and serverNames last.

Parameters:
  • hostname (bytearray) - raw UTF-8 encoding of the host name
  • hostNames (list of bytearrays) - list of raw UTF-8 encoded host names
  • serverNames (list of ServerName) - pairs of name_type and name encoded as a namedtuple
Returns: SNIExtension
Overrides: TLSExtension.create

parse(self, p)

source code 

Deserialise the extension from on-the-wire data

The parser should not include the type or length of extension!

Parameters:
Returns: SNIExtension
Raises:
  • SyntaxError - when the internal sizes don't match the attached data
Overrides: TLSExtension.parse

write(self)

source code 

Returns encoded extension, as encoded on the wire

Returns: bytearray
an array of bytes formatted as they are supposed to be written on the wire, including the type, length and extension data
Raises:
  • AssertionError - when the object was not initialized
Overrides: TLSExtension.write

Instance Variable Details [hide private]

extData

a byte array containing the value of the extension as to be written on the wire
Type:
bytearray

extType

a 2^16-1 limited integer specifying the type of the extension that it contains, e.g. 0 indicates server name extension
Type:
int

hostNames

tuple of hostnames (server name records of type 0) advertised in the extension. Note that it may not include all names from client hello as the client can advertise other types. Also note that while it's not possible to change the returned array in place, it is possible to assign a new set of names. IOW, this won't work:
  sni_extension.hostNames[0] = bytearray(b'example.com')

while this will work:

  names = list(sni_extension.hostNames)
  names[0] = bytearray(b'example.com')
  sni_extension.hostNames = names
Type:
tuple of bytearrays

serverNames

list of all names advertised in extension. ServerName is a namedtuple with two elements, the first element (type) defines the type of the name (encoded as int) while the other (name) is a bytearray that carries the value. Known types are defined in tlslite.constants.NameType. The list will be empty if the on the wire extension had and empty list while it will be None if the extension was empty.
Type:
list of ServerName