Package tlslite :: Module handshakehelpers
[hide private]
[frames] | no frames]

Source Code for Module tlslite.handshakehelpers

 1  # Authors: 
 2  #   Karel Srot 
 3  # 
 4  # See the LICENSE file for legal information regarding use of this file. 
 5   
 6  """Class with various handshake helpers.""" 
 7   
 8  from .extensions import PaddingExtension 
9 10 11 -class HandshakeHelpers(object):
12 """ 13 This class encapsulates helper functions to be used with a TLS handshake. 14 15 @sort: alignUsingPaddingExtension 16 """ 17 18 @staticmethod
19 - def alignClientHelloPadding(clientHello):
20 """ 21 Align ClientHello using the Padding extension to 512 bytes at least. 22 23 @type clientHello: ClientHello 24 @param clientHello: ClientHello to be aligned 25 """ 26 # Check clientHello size if padding extension should be added 27 # we want to add the extension even when using just SSLv3 28 # cut-off 4 bytes with the Hello header (ClientHello type + Length) 29 clientHelloLength = len(clientHello.write()) - 4 30 if 256 <= clientHelloLength <= 511: 31 if clientHello.extensions is None: 32 clientHello.extensions = [] 33 # we need to recalculate the size after extension list addition 34 # results in extra 2 bytes, equals to 35 # clientHelloLength = len(clientHello.write()) - 4 36 clientHelloLength += 2 37 # we want to get 512 bytes in total, including the padding 38 # extension header (4B) 39 paddingExtensionInstance = PaddingExtension().create( 40 max(512 - clientHelloLength - 4, 0)) 41 clientHello.extensions.append(paddingExtensionInstance)
42