/usr/lib/python3/dist-packages/asyncssh/client.py is in python3-asyncssh 1.11.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | # Copyright (c) 2013-2017 by Ron Frederick <ronf@timeheart.net>.
# All rights reserved.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v1.0 which accompanies this
# distribution and is available at:
#
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Ron Frederick - initial implementation, API, and documentation
"""SSH client protocol handler"""
class SSHClient:
"""SSH client protocol handler
Applications should subclass this when implementing an SSH client.
The functions listed below should be overridden to define
application-specific behavior. In particular, the method
:meth:`auth_completed` should be defined to open the desired
SSH channels on this connection once authentication has been
completed.
For simple password or public key based authentication, nothing
needs to be defined here if the password or client keys are passed
in when the connection is created. However, to prompt interactively
or otherwise dynamically select these values, the methods
:meth:`password_auth_requested` and/or :meth:`public_key_auth_requested`
can be defined. Keyboard-interactive authentication is also supported
via :meth:`kbdint_auth_requested` and :meth:`kbdint_challenge_received`.
If the server sends an authentication banner, the method
:meth:`auth_banner_received` will be called.
If the server requires a password change, the method
:meth:`password_change_requested` will be called, followed by either
:meth:`password_changed` or :meth:`password_change_failed` depending
on whether the password change is successful.
.. note:: The authentication callbacks described here can be
defined as coroutines. However, they may be cancelled if
they are running when the SSH connection is closed by
the server. If they attempt to catch the CancelledError
exception to perform cleanup, they should make sure to
re-raise it to allow AsyncSSH to finish its own cleanup.
"""
# pylint: disable=no-self-use,unused-argument
def connection_made(self, connection):
"""Called when a connection is made
This method is called as soon as the TCP connection completes. The
connection parameter should be stored if needed for later use.
:param connection:
The connection which was successfully opened
:type connection: :class:`SSHClientConnection`
"""
pass # pragma: no cover
def connection_lost(self, exc):
"""Called when a connection is lost or closed
This method is called when a connection is closed. If the
connection is shut down cleanly, *exc* will be ``None``.
Otherwise, it will be an exception explaining the reason for
the disconnect.
:param exc:
The exception which caused the connection to close, or
``None`` if the connection closed cleanly
:type exc: :class:`Exception`
"""
pass # pragma: no cover
def debug_msg_received(self, msg, lang, always_display):
"""A debug message was received on this connection
This method is called when the other end of the connection sends
a debug message. Applications should implement this method if
they wish to process these debug messages.
:param str msg:
The debug message sent
:param str lang:
The language the message is in
:param bool always_display:
Whether or not to display the message
"""
pass # pragma: no cover
def auth_banner_received(self, msg, lang):
"""An incoming authentication banner was received
This method is called when the server sends a banner to display
during authentication. Applications should implement this method
if they wish to do something with the banner.
:param str msg:
The message the server wanted to display
:param str lang:
The language the message is in
"""
pass # pragma: no cover
def auth_completed(self):
"""Authentication was completed successfully
This method is called when authentication has completed
succesfully. Applications may use this method to create
whatever client sessions and direct TCP/IP or UNIX domain
connections are needed and/or set up listeners for incoming
TCP/IP or UNIX domain connections coming from the server.
"""
pass # pragma: no cover
def public_key_auth_requested(self):
"""Public key authentication has been requested
This method should return a private key corresponding to
the user that authentication is being attempted for.
This method may be called multiple times and can return a
different key to try each time it is called. When there are
no keys left to try, it should return ``None`` to indicate
that some other authentication method should be tried.
If client keys were provided when the connection was opened,
they will be tried before this method is called.
If blocking operations need to be performed to determine the
key to authenticate with, this method may be defined as a
coroutine.
:returns: A key as described in :ref:`SpecifyingPrivateKeys`
or ``None`` to move on to another authentication
method
"""
return None # pragma: no cover
def password_auth_requested(self):
"""Password authentication has been requested
This method should return a string containing the password
corresponding to the user that authentication is being
attempted for. It may be called multiple times and can
return a different password to try each time, but most
servers have a limit on the number of attempts allowed.
When there's no password left to try, this method should
return ``None`` to indicate that some other authentication
method should be tried.
If a password was provided when the connection was opened,
it will be tried before this method is called.
If blocking operations need to be performed to determine the
password to authenticate with, this method may be defined as
a coroutine.
:returns: A string containing the password to authenticate
with or ``None`` to move on to another authentication
method
"""
return None # pragma: no cover
def password_change_requested(self, prompt, lang):
"""A password change has been requested
This method is called when password authentication was
attempted and the user's password was expired on the
server. To request a password change, this method should
return a tuple or two strings containing the old and new
passwords. Otherwise, it should return ``NotImplemented``.
If blocking operations need to be performed to determine the
passwords to authenticate with, this method may be defined
as a coroutine.
By default, this method returns ``NotImplemented``.
:param str prompt:
The prompt requesting that the user enter a new password
:param str lang:
The language that the prompt is in
:returns: A tuple of two strings containing the old and new
passwords or ``NotImplemented`` if password changes
aren't supported
"""
return NotImplemented # pragma: no cover
def password_changed(self):
"""The requested password change was successful
This method is called to indicate that a requested password
change was successful. It is generally followed by a call to
:meth:`auth_completed` since this means authentication was
also successful.
"""
pass # pragma: no cover
def password_change_failed(self):
"""The requested password change has failed
This method is called to indicate that a requested password
change failed, generally because the requested new password
doesn't meet the password criteria on the remote system.
After this method is called, other forms of authentication
will automatically be attempted.
"""
pass # pragma: no cover
def kbdint_auth_requested(self):
"""Keyboard-interactive authentication has been requested
This method should return a string containing a comma-separated
list of submethods that the server should use for
keyboard-interactive authentication. An empty string can be
returned to let the server pick the type of keyboard-interactive
authentication to perform. If keyboard-interactive authentication
is not supported, ``None`` should be returned.
By default, keyboard-interactive authentication is supported
if a password was provided when the :class:`SSHClient` was
created and it hasn't been sent yet. If the challenge is not
a password challenge, this authentication will fail. This
method and the :meth:`kbdint_challenge_received` method can be
overridden if other forms of challenge should be supported.
If blocking operations need to be performed to determine the
submethods to request, this method may be defined as a
coroutine.
:returns: A string containing the submethods the server should
use for authentication or ``None`` to move on to
another authentication method
"""
return NotImplemented # pragma: no cover
def kbdint_challenge_received(self, name, instruction, lang, prompts):
"""A keyboard-interactive auth challenge has been received
This method is called when the server sends a keyboard-interactive
authentication challenge.
The return value should be a list of strings of the same length
as the number of prompts provided if the challenge can be
answered, or ``None`` to indicate that some other form of
authentication should be attempted.
If blocking operations need to be performed to determine the
responses to authenticate with, this method may be defined
as a coroutine.
By default, this method will look for a challenge consisting
of a single 'Password:' prompt, and call the method
:meth:`password_auth_requested` to provide the response.
It will also ignore challenges with no prompts (generally used
to provide instructions). Any other form of challenge will
cause this method to return ``None`` to move on to another
authentication method.
:param str name:
The name of the challenge
:param str instruction:
Instructions to the user about how to respond to the challenge
:param str lang:
The language the challenge is in
:param prompts:
The challenges the user should respond to and whether or
not the responses should be echoed when they are entered
:type prompts: list of tuples of str and bool
:returns: List of string responses to the challenge or ``None``
to move on to another authentication method
"""
return None # pragma: no cover
|