<s> from coro . ssh . util import packet as ssh_packet <EOL> from coro . ssh . util import debug as ssh_debug <EOL> class SSH_Key_Exchange : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT:none>' <EOL> wants_signature_host_key = <NUM_LIT:0> <EOL> wants_encryption_host_key = <NUM_LIT:0> <EOL> shared_secret = None <EOL> exchange_hash = None <EOL> session_id = None <EOL> c2s_version_string = '<STR_LIT>' <EOL> s2c_version_string = '<STR_LIT>' <EOL> s2c_kexinit_packet = '<STR_LIT>' <EOL> c2s_kexinit_packet = '<STR_LIT>' <EOL> transport = None <EOL> def __init__ ( self , transport ) : <EOL> self . supported_server_keys = [ ] <EOL> self . transport = transport <EOL> def get_initial_client_kex_packet ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def get_initial_server_kex_packet ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def register_client_callbacks ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def register_server_callbacks ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def get_hash_object ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> hash_object = self . _get_hash_object ( ) <EOL> for arg in args : <EOL> hash_object . update ( arg ) <EOL> return hash_object <EOL> def _get_hash_object ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def get_encryption_key ( self , letter , required_size ) : <EOL> """<STR_LIT>""" <EOL> shared_secret = ssh_packet . pack_payload ( ( ssh_packet . MPINT , ) , ( self . shared_secret , ) ) <EOL> key = self . get_hash_object ( <EOL> shared_secret , <EOL> self . exchange_hash , <EOL> letter , <EOL> self . session_id ) . digest ( ) <EOL> if len ( key ) > required_size : <EOL> key = key [ : required_size ] <EOL> elif len ( key ) < required_size : <EOL> self . transport . debug . write ( <EOL> ssh_debug . DEBUG_2 , '<STR_LIT>' , <EOL> ( len ( key ) , required_size ) ) <EOL> key_data = [ key ] <EOL> key_data_len = len ( key ) <EOL> while key_data_len < required_size : <EOL> additional_key_data = self . get_hash_object ( <EOL> shared_secret , self . exchange_hash , '<STR_LIT>' . join ( key_data ) ) . digest ( ) <EOL> key_data . append ( additional_key_data ) <EOL> key_data_len += len ( additional_key_data ) <EOL> key = '<STR_LIT>' . join ( key_data ) [ : required_size ] <EOL> else : <EOL> pass <EOL> return key <EOL> def set_info ( self , c2s_version_string , s2c_version_string , <EOL> c2s_kexinit_packet , s2c_kexinit_packet , supported_server_keys ) : <EOL> self . c2s_version_string = c2s_version_string <EOL> self . s2c_version_string = s2c_version_string <EOL> self . c2s_kexinit_packet = c2s_kexinit_packet <EOL> self . s2c_kexinit_packet = s2c_kexinit_packet <EOL> self . supported_server_keys = supported_server_keys <EOL> def get_key_algorithm ( self , key ) : <EOL> name = ssh_packet . unpack_payload ( ( ssh_packet . STRING , ) , key ) [ <NUM_LIT:0> ] <EOL> for key_alg in self . supported_server_keys : <EOL> if key_alg . name == name : <EOL> return key_alg <EOL> raise ValueError ( name ) </s>
