#NEWLINE# def on_response( self , response ) : #NEWLINE# #INDENT# if ( ( not self . ssl ) or self . signature_tampered ) : #NEWLINE# #INDENT# return response #NEWLINE# #UNINDENT# response = ( self . buffer + response ) #NEWLINE# self . buffer = '' #NEWLINE# try : #NEWLINE# #INDENT# remaining = response #NEWLINE# new_response = '' #NEWLINE# while remaining : #NEWLINE# #INDENT# ( record , remaining ) = tls . parse_tls ( remaining , throw_on_incomplete = True ) #NEWLINE# version = record . version #NEWLINE# for ( i , message ) in enumerate ( record . messages ) : #NEWLINE# #INDENT# if ( isinstance ( message , HandshakeMessage ) and ( message . type == HandshakeMessage . TYPE . SERVER_KEY_EXCHANGE ) ) : #NEWLINE# #INDENT# tampered_record_bytes = self . _tamper_with_server_key_exchange ( record , i ) #NEWLINE# response = ( ( new_response + tampered_record_bytes ) + remaining ) #NEWLINE# self . signature_tampered = True #NEWLINE# return response #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# new_response += record . to_bytes ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# except tls . types . TlsNotEnoughDataError : #NEWLINE# #INDENT# self . buffer = response #NEWLINE# if ( len ( self . buffer ) > ( 2 ** 14 ) ) : #NEWLINE# #INDENT# response = self . buffer #NEWLINE# self . buffer = '' #NEWLINE# return self . buffer #NEWLINE# #UNINDENT# return '' #NEWLINE# #UNINDENT# return response