Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from OpenSSL import SSL
- from twisted.internet import reactor, ssl
- from twisted.internet.protocol import ClientFactory
- from twisted.protocols.basic import LineReceiver
- import socket
- class ClientTLSContext(ssl.ClientContextFactory):
- isClient = 1
- def get_context(self):
- return SSL.Context(SSL.TLSv1_METHOD)
- class TLSClient(LineReceiver):
- def connectionMade(self):
- print "Connected\nattempting login"
- self.send("STARTTLS")
- def lineReceived(self, line):
- print "Received line:", line
- if line == "READY":
- ctx = ClientTLSContext()
- self.transport.startTLS(ctx, self.factory)
- print "KEBAB"
- self.transport.loseConnection()
- def send(self, line):
- self.sendLine(line)
- class TLSClientFactory(ClientFactory):
- protocol = TLSClient
- def clientConnectionFailed(self, connector, reason):
- print "connection failed: ", reason.getErrorMessage()
- reactor.stop()
- def clientConnectionLost(self, connector, reason):
- print "connection lost: ", reason.getErrorMessage()
- reactor.stop()
- def connectionLost(self):
- print "Lost connection"
- #if __name__ == "__main__":
- class XClient:
- def _connect(self):
- factory = TLSClientFactory()
- reactor.connectTCP(self.ip, self.port, factory)
- reactor.run()
- def login (self, addr="localhost", port=1337, user="x", password="x", **keywords):
- try:
- self.ip = socket.gethostbyname(addr)
- except:
- print "Failed to resolve", addr
- self.port = port
- self._connect()
Add Comment
Please, Sign In to add comment