Twisted Sink Override Authentication

I am trying to override the default authentication scheme in a twisted motor. Something that I thought I understood how to do. The script itself is the answer to the question. I will subclass SSHUserAuthClientas follows:

class ClientUserAuth(SSHUserAuthClient):
    def getPassword(self, prompt = None):
        return defer.succeed("*****")

and I obviously replace the call with the SSHUserAuthClientcall of my class in the script. For reasons that I cannot understand, the script does not execute the method getPasswordin my class, but the superclass method getPassword. Does anyone know what I'm doing wrong? The only other change to the script I made is to add the following import module

from twisted.internet import defer

Thank!

EDIT: It is strange that the subclass method getPublicKeyis called correctly. This is just a method getPasswordthat acts weird.

+3
2

, -. , . , Linux OS X, , Linux OS X SSH -.

getGenericAnswers .

+3

, .

, , . = [('Password: ', False)].
= []

, (Redhat, Ubuntu, OpenSUSE)

from twisted.conch.ssh import keys, userauth

class ClientUserAuth(userauth.SSHUserAuthClient):
    def getPassword(self, prompt = None):
        #normal password authentication
        print "PASSWORD AUTH"
        return defer.succeed('*****') # <-- YOUR PASSWORD

    def getGenericAnswers(self, name, instruction, prompts):
        #interactive password authentication
        print "INTERACTIVE AUTH"
        response = ['']*len(prompts)
        for i, p in enumerate(prompts):
            try:
                if('password' in p[0].lower()):
                    response[i] = '*****' # <-- YOUR PASSWORD
            except:
                pass
        #The response is always a sequence, and the length of it is always
        #identical to the length of prompts
        return defer.succeed(response)

>

Twisted , Conch .

from twisted.python import log
log.msg('Started Logging for A Conch Program')
log.startLogging(sys.stdout)
+3

Source: https://habr.com/ru/post/1796650/


All Articles