class documentation

class SSHUserAuthClient(service.SSHService): (source)

Known subclasses: twisted.conch.client.default.SSHUserAuthClient, twisted.conch.scripts.tkconch.SSHUserAuthClient, twisted.conch.endpoints._UserAuth

View In Hierarchy

A service implementing the client side of 'ssh-userauth'.

This service will try all authentication methods provided by the server, making callbacks for more information when necessary.

Method __init__ Undocumented
Method ask​For​Auth Send a MSG_USERAUTH_REQUEST.
Method auth​_keyboard​_interactive Try to authenticate with keyboard-interactive authentication. Send the request to the server and return True.
Method auth​_password Try to authenticate with a password. Ask the user for a password. If the user will return a password, return True. Otherwise, return False.
Method auth​_publickey Try to authenticate with a public key. Ask the user for a public key; if the user has one, send the request to the server and return True. Otherwise, return False.
Method get​Generic​Answers Returns a Deferred with the responses to the promopts.
Method get​Password Return a Deferred that will be called back with a password. prompt is a string to display for the password, or None for a generic 'user@hostname's password: '.
Method get​Private​Key Return a Deferred that will be called back with the private key object corresponding to the last public key from getPublicKey(). If the private key is not available, errback on the Deferred.
Method get​Public​Key Return a public key for the user. If no more public keys are available, return None.
Method service​Started called when the service is active on the transport.
Method sign​Data Sign the given data with the given public key.
Method ssh_​USERAUTH_​FAILURE We received a MSG_USERAUTH_FAILURE. Payload:: string methods byte partial success
Method ssh_​USERAUTH_​PK_​OK This message (number 60) can mean several different messages depending on the current authentication type. We dispatch to individual methods in order to handle this request.
Method ssh_​USERAUTH_​PK_​OK_keyboard_interactive This is MSG_USERAUTH_INFO_RESPONSE. The server has sent us the questions it wants us to answer, so we ask the user and sent the responses.
Method ssh_​USERAUTH_​PK_​OK_password This is MSG_USERAUTH_PASSWD_CHANGEREQ. The password given has expired. We ask for an old password and a new password, then send both back to the server.
Method ssh_​USERAUTH_​PK_​OK_publickey This is MSG_USERAUTH_PK. Our public key is valid, so we create a signature and try to authenticate with it.
Method ssh_​USERAUTH_​SUCCESS We received a MSG_USERAUTH_SUCCESS. The server has accepted our authentication, so start the next service.
Method try​Auth Dispatch to an authentication method.
Instance Variable authenticated​With a list of strings of authentication methods we've tried
Instance Variable instance the service to start after authentication has finished
Instance Variable last​Auth Undocumented
Instance Variable last​Public​Key the last public key object we've tried to authenticate with
Instance Variable name the name of this service: 'ssh-userauth'
Instance Variable preferred​Order a list of authentication methods that should be used first, in order of preference, if supported by the server
Instance Variable tried​Public​Keys a list of public key objects that we've tried to authenticate with
Instance Variable user the name of the user to authenticate as
Method _cb​Generic​Answers Called back when we are finished answering keyboard-interactive questions. Send the info back to the server in a MSG_USERAUTH_INFO_RESPONSE.
Method _cb​Get​Public​Key Undocumented
Method _cb​Password Called back when the user gives a password. Send the request to the server.
Method _cb​Sign​Data Called back when the private key is returned. Sign the data and return the signature.
Method _cb​Signed​Data Called back out of self.signData with the signed data. Send the authentication request with the signature.
Method _cb​Userauth​Failure Undocumented
Method _eb​Auth Generic callback for a failed authentication attempt. Respond by asking for the list of accepted methods (the 'none' method)
Method _set​New​Pass Called back when we are choosing a new password. Get the old password and send the authentication message with both.
Method _set​Old​Pass Called back when we are choosing a new password. Simply store the old password for now.
Instance Variable _new​Pass Undocumented
Instance Variable _old​Pass Undocumented

Inherited from SSHService:

Method log​Prefix Undocumented
Method packet​Received called when we receive a packet on the transport
Method service​Stopped called when the service is stopped, either by the connection ending or by another service being started
Class Variable protocol​Messages Undocumented
Class Variable transport Undocumented
Class Variable _log Undocumented
def __init__(self, user, instance): (source)
def askForAuth(self, kind, extraData): (source)
Send a MSG_USERAUTH_REQUEST.
Parameters
kind:bytesthe authentication method to try.
extra​Data:bytesmethod-specific data to go in the packet
def auth_keyboard_interactive(self): (source)
Try to authenticate with keyboard-interactive authentication. Send the request to the server and return True.
Returns
boolUndocumented
def auth_password(self): (source)
Try to authenticate with a password. Ask the user for a password. If the user will return a password, return True. Otherwise, return False.
Returns
boolUndocumented
def auth_publickey(self): (source)
Try to authenticate with a public key. Ask the user for a public key; if the user has one, send the request to the server and return True. Otherwise, return False.
Returns
boolUndocumented
def getGenericAnswers(self, name, instruction, prompts): (source)
Returns a Deferred with the responses to the promopts.
Parameters
nameThe name of the authentication currently in progress.
instructionDescribes what the authentication wants.
promptsA list of (prompt, echo) pairs, where prompt is a string to display and echo is a boolean indicating whether the user's response should be echoed as they type it.
def getPassword(self, prompt=None): (source)
Return a Deferred that will be called back with a password. prompt is a string to display for the password, or None for a generic 'user@hostname's password: '.
Parameters
prompt:bytes/NoneUndocumented
Returns
defer.DeferredUndocumented
def getPrivateKey(self): (source)
Return a Deferred that will be called back with the private key object corresponding to the last public key from getPublicKey(). If the private key is not available, errback on the Deferred.
Returns
Deferred called back with KeyUndocumented
def getPublicKey(self): (source)

Return a public key for the user. If no more public keys are available, return None.

This implementation always returns None. Override it in a subclass to actually find and return a public key object.

Returns
Key or NoneUndocumented
def serviceStarted(self): (source)
called when the service is active on the transport.
def signData(self, publicKey, signData): (source)

Sign the given data with the given public key.

By default, this will call getPrivateKey to get the private key, then sign the data using Key.sign().

This method is factored out so that it can be overridden to use alternate methods, such as a key agent.

Parameters
public​Key:keys.KeyThe public key object returned from getPublicKey
sign​Data:bytesthe data to be signed by the private key.
Returns
defer.Deferreda Deferred that's called back with the signature
def ssh_USERAUTH_FAILURE(self, packet): (source)

We received a MSG_USERAUTH_FAILURE. Payload:

    string methods
    byte partial success

If partial success is True, then the previous method succeeded but is not sufficient for authentication. methods is a comma-separated list of accepted authentication methods.

We sort the list of methods by their position in self.preferredOrder, removing methods that have already succeeded. We then call self.tryAuth with the most preferred method.

Parameters
packet:bytesthe MSG_USERAUTH_FAILURE payload.
Returns
defer.Deferred or Nonea defer.Deferred that will be callbacked with None as soon as all authentication methods have been tried, or None if no more authentication methods are available.
def ssh_USERAUTH_PK_OK(self, packet): (source)
This message (number 60) can mean several different messages depending on the current authentication type. We dispatch to individual methods in order to handle this request.
def ssh_USERAUTH_PK_OK_keyboard_interactive(self, packet): (source)
This is MSG_USERAUTH_INFO_RESPONSE. The server has sent us the questions it wants us to answer, so we ask the user and sent the responses.
def ssh_USERAUTH_PK_OK_password(self, packet): (source)
This is MSG_USERAUTH_PASSWD_CHANGEREQ. The password given has expired. We ask for an old password and a new password, then send both back to the server.
def ssh_USERAUTH_PK_OK_publickey(self, packet): (source)
This is MSG_USERAUTH_PK. Our public key is valid, so we create a signature and try to authenticate with it.
def ssh_USERAUTH_SUCCESS(self, packet): (source)
We received a MSG_USERAUTH_SUCCESS. The server has accepted our authentication, so start the next service.
def tryAuth(self, kind): (source)
Dispatch to an authentication method.
Parameters
kind:bytesthe authentication method
authenticatedWith: list of bytes = (source)
a list of strings of authentication methods we've tried
the service to start after authentication has finished
lastAuth = (source)

Undocumented

lastPublicKey: Key = (source)
the last public key object we've tried to authenticate with
name: str = (source)
the name of this service: 'ssh-userauth'
preferredOrder: list = (source)
a list of authentication methods that should be used first, in order of preference, if supported by the server
triedPublicKeys: list of Key = (source)
a list of public key objects that we've tried to authenticate with
the name of the user to authenticate as
def _cbGenericAnswers(self, responses): (source)
Called back when we are finished answering keyboard-interactive questions. Send the info back to the server in a MSG_USERAUTH_INFO_RESPONSE.
Parameters
responses:lista list of bytes responses
def _cbGetPublicKey(self, publicKey): (source)

Undocumented

def _cbPassword(self, password): (source)
Called back when the user gives a password. Send the request to the server.
Parameters
password:bytesthe password the user entered
def _cbSignData(self, privateKey, signData): (source)
Called back when the private key is returned. Sign the data and return the signature.
Parameters
private​Key:keys.Keythe private key object
sign​Data:bytesthe data to be signed by the private key.
Returns
bytesthe signature
def _cbSignedData(self, signedData): (source)
Called back out of self.signData with the signed data. Send the authentication request with the signature.
Parameters
signed​Data:bytesthe data signed by the user's private key.
def _cbUserauthFailure(self, result, iterator): (source)

Undocumented

def _ebAuth(self, ignored, *args): (source)
Generic callback for a failed authentication attempt. Respond by asking for the list of accepted methods (the 'none' method)
def _setNewPass(self, np): (source)
Called back when we are choosing a new password. Get the old password and send the authentication message with both.
Parameters
np:bytesthe new password as entered by the user
def _setOldPass(self, op): (source)
Called back when we are choosing a new password. Simply store the old password for now.
Parameters
op:bytesthe old password as entered by the user
_newPass = (source)

Undocumented

_oldPass = (source)

Undocumented