Package tlslite :: Module messagesocket :: Class MessageSocket
[hide private]
[frames] | no frames]

Class MessageSocket

source code


TLS Record Layer socket that provides Message level abstraction

Because the record layer has a hard size limit on sent messages, they need to be fragmented before sending. Similarly, a single record layer record can include multiple handshake protocol messages (very common with ServerHello, Certificate and ServerHelloDone), as such, the user of RecordLayer needs to fragment those records into multiple messages. Unfortunately, fragmentation of messages requires some degree of knowledge about the messages passed and as such is outside scope of pure record layer implementation.

This class tries to provide a useful abstraction for handling Handshake protocol messages.

Instance Methods [hide private]
 
__init__(self, sock, defragmenter)
Apply TLS Record Layer abstraction to raw network socket.
source code
generator
flush(self)
Empty the queue of messages to write
source code
 
flushBlocking(self)
Blocking variant of flush
source code
generator
queueMessage(self, msg)
Queue message for sending
source code
 
queueMessageBlocking(self, msg)
Blocking variant of queueMessage
source code
generator
recvMessage(self)
Read next message in queue
source code
 
recvMessageBlocking(self)
Blocking variant of recvMessage
source code
generator
sendMessage(self, msg)
Fragment and send a message.
source code
 
sendMessageBlocking(self, msg)
Blocking variant of sendMessage
source code

Inherited from recordlayer.RecordLayer: addPadding, calcPendingStates, calcSSL2PendingStates, calculateMAC, changeReadState, changeWriteState, getCipherImplementation, getCipherName, isCBCMode, recvRecord, sendRecord, shutdown

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]
Instance Variables [hide private]
Defragmenter defragmenter
defragmenter used for read records
int recordSize
maximum size of records sent through socket.
tuple unfragmentedDataTypes
data types which will be passed as-read, TLS application_data by default

Inherited from recordlayer.RecordLayer: client, encryptThenMAC, handshake_finished, sock, version

Properties [hide private]

Inherited from recordlayer.RecordLayer: blockSize

Inherited from object: __class__

Method Details [hide private]

__init__(self, sock, defragmenter)
(Constructor)

source code 

Apply TLS Record Layer abstraction to raw network socket.

Parameters:
  • sock (socket.socket) - network socket to wrap
  • defragmenter (Defragmenter) - defragmenter to apply on the records read
Overrides: object.__init__

flush(self)

source code 

Empty the queue of messages to write

Will fragment the messages and write them in as little records as possible.

Returns: generator

queueMessage(self, msg)

source code 

Queue message for sending

If the message is of same type as messages in queue, the message is just added to queue.

If the message is of different type as messages in queue, the queue is flushed and then the message is queued.

Returns: generator

recvMessage(self)

source code 

Read next message in queue

will return a 0 or 1 if the read is blocking, a tuple of RecordHeader3 and Parser in case a message was received.

Returns: generator

sendMessage(self, msg)

source code 

Fragment and send a message.

If a messages already of same type reside in queue, the message if first added to it and then the queue is flushed.

If the message is of different type than the queue, the queue is flushed, the message is added to queue and the queue is flushed again.

Use the sendRecord() message if you want to send a message outside the queue, or a message of zero size.

Returns: generator

Instance Variable Details [hide private]

recordSize

maximum size of records sent through socket. Messages bigger than this size will be fragmented to smaller chunks. Setting it to higher value than the default 2^14 will make the implementation non RFC compliant and likely not interoperable with other peers.
Type:
int