Package paramiko :: Module auth_transport :: Class Transport
[show private | hide private]
[frames | no frames]

Type Transport

object --+            
         |            
  _Verbose --+        
             |        
        Thread --+    
                 |    
     BaseTransport --+
                     |
                    Transport


An SSH Transport attaches to a stream (usually a socket), negotiates an encrypted session, authenticates, and then creates stream tunnels, called Channels, across the session. Multiple channels can be multiplexed across a single session (and often are, in the case of port forwardings).
Method Summary
  __init__(self, sock)
Create a new SSH session over an existing socket, or socket-like object.
str __repr__(self)
Returns a string representation of this object, for debugging.
list auth_password(self, username, password, event)
Authenticate to the server using a password.
list auth_publickey(self, username, key, event)
Authenticate to the server using a private key.
string get_username(self)
Return the username this connection is authenticated for.
bool is_authenticated(self)
Return true if this session is active and authenticated.
  _disconnect_no_more_auth(self)
  _disconnect_service_not_available(self)
  _get_session_blob(self, key, service, username)
  _parse_service_accept(self, m)
  _parse_service_request(self, m)
  _parse_userauth_banner(self, m)
  _parse_userauth_failure(self, m)
  _parse_userauth_request(self, m)
  _parse_userauth_success(self, m)
  _request_auth(self)
  _wait_for_response(self, event)
    Inherited from BaseTransport
  __del__(self)
Channel accept(self, timeout)
Return the next channel opened by the client over this transport, in server mode.
  add_server_key(self, key)
Add a host key to the list of keys used for server mode.
  close(self)
Close this session, and any open channels that are tied to it.
  connect(self, hostkey, username, password, pkey)
Negotiate an SSH2 session, and optionally verify the server's host key and authenticate using a password or private key.
Exception get_exception(self)
Return any exception that happened during the last server request.
bool get_hexdump(self)
Return True if the transport is currently logging hex dumps of protocol traffic.
str get_log_channel(self)
Return the channel name used for this transport's logging.
PKey get_remote_server_key(self)
Return the host key of the server (in client mode).
SecurityOptions get_security_options(self)
Return a SecurityOptions object which can be used to tweak the encryption algorithms this transport will permit, and the order of preference for them.
PKey get_server_key(self)
Return the active host key, in server mode.
Message global_request(self, kind, data, wait)
Make a global request to the remote host.
bool is_active(self)
Return true if this session is active (open).
bool load_server_moduli(filename)
(optional) Load a file of prime moduli for use in doing group-exchange key negotiation in server mode. (Static method)
Channel open_channel(self, kind, dest_addr, src_addr)
Request a new channel to the server.
Channel open_session(self)
Request a new channel to the server, of type "session".
SFTPClient open_sftp_client(self)
Create an SFTP client channel from an open transport.
bool renegotiate_keys(self)
Force this session to switch to new keys.
  run(self)
  send_ignore(self, bytes)
Send a junk packet across the encrypted link.
  set_hexdump(self, hexdump)
Turn on/off logging a hex dump of protocol traffic at DEBUG level in the logs.
  set_keepalive(self, interval)
Turn on/off keepalive packets (default is off).
  set_log_channel(self, name)
Set the channel for this transport's logging.
  set_subsystem_handler(self, name, handler, *larg, **kwarg)
Set the handler class for a subsystem in server mode.
  start_client(self, event)
Negotiate a new SSH2 session as a client.
  start_server(self, event, server)
Negotiate a new SSH2 session as a server.
  stop_thread(self)
  _activate_inbound(self)
switch on newly negotiated encryption parameters for inbound traffic
  _activate_outbound(self)
switch on newly negotiated encryption parameters for outbound traffic
  _check_banner(self)
  _compute_key(self, id, nbytes)
id is 'A' - 'F' for the various keys used by ssh
  _expect_packet(self, type)
used by a kex object to register the next packet type it expects to see
  _get_cipher(self, name, key, iv)
  _get_modulus_pack(self)
used by KexGex to find primes for group exchange
  _get_subsystem_handler(self, name)
  _log(self, level, msg)
  _negotiate_keys(self, m)
  _parse_channel_open(self, m)
  _parse_channel_open_failure(self, m)
  _parse_channel_open_success(self, m)
  _parse_debug(self, m)
  _parse_disconnect(self, m)
  _parse_global_request(self, m)
  _parse_kex_init(self, m)
  _parse_newkeys(self, m)
  _parse_request_failure(self, m)
  _parse_request_success(self, m)
  _send_kex_init(self)
announce to the other side that we'd like to negotiate keys, and what kind of key negotiation we support.
  _send_message(self, data)
  _send_user_message(self, data)
send a message, but block if we're in key negotiation.
  _set_K_H(self, k, h)
used by a kex object to set the K (root key) and H (exchange hash)
  _unlink_channel(self, chanid)
used by a Channel to remove itself from the active channel list
  _verify_key(self, host_key, sig)
    Inherited from Thread
  getName(self)
  isAlive(self)
  isDaemon(self)
  join(self, timeout)
  setDaemon(self, daemonic)
  setName(self, name)
  start(self)
  _set_daemon(self)
    Inherited from _Verbose
  _note(self, format, *args)
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Class Variable Summary
dict _handler_table = {5: <function _parse_service_request at...
    Inherited from BaseTransport
dict _channel_handler_table = {96: <unbound method Channel._h...
dict _cipher_info = {'blowfish-cbc': {'block-size': 8, 'key-s...
str _CLIENT_ID = 'paramiko_1.4'
dict _kex_info = {'diffie-hellman-group1-sha1': <class 'param...
dict _key_info = {'ssh-dss': <class 'paramiko.dsskey.DSSKey'>...
dict _mac_info = {'hmac-sha1': {'class': <module 'Crypto.Hash...
NoneType _modulus_pack = None                                                                  
tuple _preferred_ciphers = ('aes128-cbc', 'blowfish-cbc', 'aes...
tuple _preferred_kex = ('diffie-hellman-group1-sha1', 'diffie-...
tuple _preferred_keys = ('ssh-rsa', 'ssh-dss')
tuple _preferred_macs = ('hmac-sha1', 'hmac-md5', 'hmac-sha1-9...
str _PROTO_ID = '2.0'
    Inherited from Thread
bool _Thread__initialized = False

Instance Method Details

__init__(self, sock)
(Constructor)

Create a new SSH session over an existing socket, or socket-like object. This only creates the Transport object; it doesn't begin the SSH session yet. Use connect or start_client to begin a client session, or start_server to begin a server session.

If the object is not actually a socket, it must have the following methods:
  • send(str): Writes from 1 to len(str) bytes, and returns an int representing the number of bytes written. Returns 0 or raises EOFError if the stream has been closed.
  • recv(int): Reads from 1 to int bytes and returns them as a string. Returns 0 or raises EOFError if the stream has been closed.
  • close(): Closes the socket.
  • settimeout(n): Sets a (float) timeout on I/O operations.
For ease of use, you may also pass in an address (as a tuple) or a host string as the sock argument. (A host string is a hostname with an optional port (separated by ":") which will be converted into a tuple of (hostname, port).) A socket will be connected to this address and used for communication. Exceptions from the socket call may be thrown in this case.
Parameters:
sock - a socket or socket-like object to create the session over.
           (type=socket)
Overrides:
paramiko.transport.BaseTransport.__init__ (inherited documentation)

__repr__(self)
(Representation operator)

Returns a string representation of this object, for debugging.
Returns:
str
Overrides:
paramiko.transport.BaseTransport.__repr__ (inherited documentation)

auth_password(self, username, password, event=None)

Authenticate to the server using a password. The username and password are sent over an encrypted link.

If an event is passed in, this method will return immediately, and the event will be triggered once authentication succeeds or fails. On success, is_authenticated will return True. On failure, you may use get_exception to get more detailed error information.

Since 1.1, if no event is passed, this method will block until the authentication succeeds or fails. On failure, an exception is raised. Otherwise, the method simply returns.

If the server requires multi-step authentication (which is very rare), this method will return a list of auth types permissible for the next step. Otherwise, in the normal case, an empty list is returned.
Parameters:
username - the username to authenticate as
           (type=string)
password - the password to authenticate with
           (type=string)
event - an event to trigger when the authentication attempt is complete (whether it was successful or not)
           (type=threading.Event)
Returns:
list of auth types permissible for the next stage of authentication (normally empty)
           (type=list)
Raises:
BadAuthenticationType - if password authentication isn't allowed by the server for this user (and no event was passed in)
SSHException - if the authentication failed (and no event was passed in)

auth_publickey(self, username, key, event=None)

Authenticate to the server using a private key. The key is used to sign data from the server, so it must include the private part.

If an event is passed in, this method will return immediately, and the event will be triggered once authentication succeeds or fails. On success, is_authenticated will return True. On failure, you may use get_exception to get more detailed error information.

Since 1.1, if no event is passed, this method will block until the authentication succeeds or fails. On failure, an exception is raised. Otherwise, the method simply returns.

If the server requires multi-step authentication (which is very rare), this method will return a list of auth types permissible for the next step. Otherwise, in the normal case, an empty list is returned.
Parameters:
username - the username to authenticate as.
           (type=string)
key - the private key to authenticate with.
           (type=PKey)
event - an event to trigger when the authentication attempt is complete (whether it was successful or not)
           (type=threading.Event)
Returns:
list of auth types permissible for the next stage of authentication (normally empty).
           (type=list)
Raises:
BadAuthenticationType - if public-key authentication isn't allowed by the server for this user (and no event was passed in).
SSHException - if the authentication failed (and no event was passed in).

get_username(self)

Return the username this connection is authenticated for. If the session is not authenticated (or authentication failed), this method returns None.
Returns:
username that was authenticated, or None.
           (type=string)

Since: fearow

is_authenticated(self)

Return true if this session is active and authenticated.
Returns:
True if the session is still open and has been authenticated successfully; False if authentication failed and/or the session is closed.
           (type=bool)

Class Variable Details

_handler_table

Type:
dict
Value:
{5: <function _parse_service_request at 0x250bb0>,
 6: <function _parse_service_accept at 0x250bf0>,
 20: <function _negotiate_keys at 0x249770>,
 21: <function _parse_newkeys at 0x2498f0>,
 50: <function _parse_userauth_request at 0x250c30>,
 51: <function _parse_userauth_failure at 0x250cb0>,
 52: <function _parse_userauth_success at 0x250c70>,
 53: <function _parse_userauth_banner at 0x250cf0>,
...                                                                    

Generated by Epydoc 2.1 on Sun Jul 17 23:44:29 2005 http://epydoc.sf.net