Question

I am using SSHCommandClientEndpoint to execute some commands. I need to disable verifyHostKey. I mean, to override this method:

def verifyHostKey(self, hostKey, fingerprint):
    return defer.succesed(True)

I have found this method in _CommandTransport class but i dont know the right way to disbale it. How to do it right?

Was it helpful?

Solution

I think you may have asked the wrong question here - but fortunately I think I can guess what question you meant to ask.

First: why is this question wrong? You've asked how to change a private implementation detail of an API you're trying to use. You haven't stated a goal beyond making this change. For all anyone knows, the correct answer to this question might be that you should open up the source file and start editing it.

Considering the replacement code you've proposed:

def verifyHostKey(self, hostKey, fingerprint):
    return defer.succesed(True)

my guess is that the question you meant to ask was about how you can disable host key verification (and make the client behave as though it always succeeds, no matter what).

You can accomplish this by supplying an alternate value for the knownHosts argument to SSHCommandClientEndpoint.newConnection. As the API documentation says:

@param knownHosts: The currently known host keys, used to check the
    host key presented by the server we actually connect to.
@type knownHosts: L{KnownHostsFile}

Ideally this parameter would be documented as accepting an object that provides a certain abstract interface so you could be more confident that an alternate implementation will work (and will continue to work over time). Fortunately in this case the only requirement of the knownHosts object is that it implement its own verifyHostKey method.

You can implement something like this:

class PermissiveKnownHosts(object):
    def verifyHostKey(self, ui, hostname, ip, key):
        return succeed(True)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top