Skip to content

Instantly share code, notes, and snippets.

@dstufft

dstufft/fails.py Secret

Created October 2, 2013 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dstufft/9dc9978dc0af77e82f0c to your computer and use it in GitHub Desktop.
Save dstufft/9dc9978dc0af77e82f0c to your computer and use it in GitHub Desktop.
from __future__ import print_function
import sys
from twisted.internet import defer
from twisted.internet.endpoints import TCP4ClientEndpoint, connectProtocol
from twisted.internet.task import react
from twisted.conch.ssh.transport import SSHClientTransport
from twisted.python import log
log.startLogging(sys.stdout, setStdout=False)
class ForgeSSHClientTransport(SSHClientTransport):
# def verifyHostKey(self, hostKey, fingerprint):
# print("WAT")
# return defer.succeed(True)
def connectionSecure(self):
print("Testing")
def main(reactor, hostname, port):
port = int(port)
sshClient = TCP4ClientEndpoint(reactor, hostname, port)
d = connectProtocol(sshClient, ForgeSSHClientTransport())
return d
if __name__ == "__main__":
react(main, sys.argv[1:])
from __future__ import print_function
import sys
from twisted.internet import defer
from twisted.internet.endpoints import TCP4ClientEndpoint, connectProtocol
from twisted.internet.task import react
from twisted.conch.ssh.transport import SSHClientTransport
from twisted.python import log
log.startLogging(sys.stdout, setStdout=False)
class ForgeSSHClientTransport(SSHClientTransport):
def __init__(self):
self.connectionReady = defer.Deferred(
lambda d: self.transport.abortConnection()
)
# Clear the reference to that deferred to help the garbage collector
# and to signal to other parts of this implementation (in particular
# connectionLost) that it has already been fired and does not need to
# be fired again.
def readyFired(result):
self.connectionReady = None
return result
self.connectionReady.addBoth(readyFired)
# def verifyHostKey(self, hostKey, fingerprint):
# print("WAT")
# return defer.succeed(True)
def connectionSecure(self):
print("Testing")
def main(reactor, hostname, port):
port = int(port)
sshClient = TCP4ClientEndpoint(reactor, hostname, port)
d = connectProtocol(sshClient, ForgeSSHClientTransport())
d.addCallback(lambda protocol: protocol.connectionReady)
return d
if __name__ == "__main__":
react(main, sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment