x2go.checkhosts module

Providing mechanisms to X2GoControlSession* backends for checking host validity.

class x2go.checkhosts.X2GoAutoAddPolicy(caller=None, session_instance=None, fake_hostname=None)[source]

Bases: X2GoMissingHostKeyPolicy

missing_host_key(client, hostname, key)[source]

Called when an .SSHClient receives a server key for a server that isn’t in either the system or local .HostKeys object. To accept the key, simply return. To reject, raised an exception (which will be passed to the calling application).

class x2go.checkhosts.X2GoInteractiveAddPolicy(caller=None, session_instance=None, fake_hostname=None)[source]

Bases: X2GoMissingHostKeyPolicy

Policy for making host key information available to Python X2Go after a Paramiko/SSH connect has been attempted. This class needs information about the associated x2go.session.X2GoSession instance.

Once called, the missing_host_key() method of this class will try to call X2GoSession.HOOK_check_host_dialog(). This hook method—if not re-defined in your application—will then try to call the X2GoClient.HOOK_check_host_dialog(), which then will return True by default if not customized in your application.

To accept host key checks, make sure to either customize the X2GoClient.HOOK_check_host_dialog() method or the X2GoSession.HOOK_check_host_dialog() method and hook some interactive user dialog to either of them.

missing_host_key(client, hostname, key)[source]

Handle a missing host key situation. This method calls

Once called, the missing_host_key() method will try to call X2GoSession.HOOK_check_host_dialog(). This hook method—if not re-defined in your application—will then try to call the X2GoClient.HOOK_check_host_dialog(), which then will return True by default if not customized in your application.

To accept host key checks, make sure to either customize the X2GoClient.HOOK_check_host_dialog() method or the X2GoSession.HOOK_check_host_dialog() method and hook some interactive user dialog to either of them.

Parameters:
  • client (X2GoControlSession* instance) – SSH client (X2GoControlSession*) instance

  • hostname (str) – remote hostname

  • key (Paramiko/SSH key instance) – host key to validate

Raises:
class x2go.checkhosts.X2GoMissingHostKeyPolicy(caller=None, session_instance=None, fake_hostname=None)[source]

Bases: MissingHostKeyPolicy

Skeleton class for Python X2Go’s missing host key policies.

get_client()[source]

Retrieve the Paramiko SSH/Client.

Returns:

the associated X2Go control session instance.

Return type:

X2GoControlSession* instance

get_hostname()[source]

Retrieve the server hostname:port expression of the server to be validated.

Returns:

hostname:port

Return type:

str

get_hostname_name()[source]

Retrieve the server hostname string of the server to be validated.

Returns:

hostname

Return type:

str

get_hostname_port()[source]

Retrieve the server port of the server to be validated.

Returns:

port

Return type:

str

get_key()[source]

Retrieve the host key of the server to be validated.

Returns:

host key

Return type:

Paramiko/SSH key instance

get_key_fingerprint()[source]

Retrieve the host key fingerprint of the server to be validated.

Returns:

host key fingerprint

Return type:

str

get_key_fingerprint_with_colons()[source]

Retrieve the (colonized) host key fingerprint of the server to be validated.

Returns:

host key fingerprint (with colons)

Return type:

str

get_key_name()[source]

Retrieve the host key name of the server to be validated.

Returns:

host key name (RSA, DSA, ECDSA…)

Return type:

str

x2go.checkhosts.check_ssh_host_key(x2go_sshclient_instance, hostname, port=22)[source]

Perform a Paramiko/SSH host key check by connecting to the host and validating the results (i.e. by validating raised exceptions during the connect process).

Parameters:
  • x2go_sshclient_instance (X2GoControlSession* instance) – a Paramiko/SSH client instance to be used for testing host key validity.

  • hostname (str) – hostname of server to validate

  • port (int) – port of server to validate (Default value = 22)

Returns:

returns a tuple with the following components (<host_ok>, <hostname>, <port>, <fingerprint>, <fingerprint_type>)

Return type:

tuple

Raises:

SSHException – if an SSH exception occurred, that we did not provocate in X2GoInteractiveAddPolicy.missing_host_key() <x2go.checkhosts.X2GoInteractiveAddPolicy.missing_host_key()