def Start(self, wxapp=None):
     host = self.location[0]
     port = self.location[1]
     #reactor.connectSSL(host, port, self.factory, ssl.ClientContextFactory())
     wrapper.connectSSL(host,
                        port,
                        self.factory,
                        ClientContextFactory(),
                        postConnectionCheck=None)
Example #2
0
    def test_twisted_wrapper(self):
        # Test only when twisted and ZopeInterfaces are present
        try:
            from twisted.internet.protocol import ClientFactory
            from twisted.protocols.basic import LineReceiver
            from twisted.internet import reactor
            import M2Crypto.SSL.TwistedProtocolWrapper as wrapper
        except ImportError:
            import warnings
            warnings.warn(
                'Skipping twisted wrapper test because twisted not found')
            return

        # TODO Class must implement all abstract methods
        class EchoClient(LineReceiver):
            def connectionMade(self):
                self.sendLine(b'GET / HTTP/1.0\n\n')

            def lineReceived(self, line):
                global twisted_data
                twisted_data += line

        class EchoClientFactory(ClientFactory):
            protocol = EchoClient

            def clientConnectionFailed(self, connector, reason):
                reactor.stop()
                self.fail(reason)

            def clientConnectionLost(self, connector, reason):
                reactor.stop()

        pid = self.start_server(self.args)

        class ContextFactory:
            def getContext(self):
                return SSL.Context()

        try:
            global twisted_data
            twisted_data = b''

            context_factory = ContextFactory()
            factory = EchoClientFactory()
            wrapper.connectSSL(srv_host, self.srv_port, factory,
                               context_factory)
            # This will block until reactor.stop() is called
            reactor.run()
        finally:
            self.stop_server(pid)
        self.assertIn('s_server -quiet -www', twisted_data)
Example #3
0
    def test_twisted_wrapper(self):
        # Test only when twisted and ZopeInterfaces are present
        try:
            from twisted.internet.protocol import ClientFactory
            from twisted.protocols.basic import LineReceiver
            from twisted.internet import reactor
            import M2Crypto.SSL.TwistedProtocolWrapper as wrapper
        except ImportError:
            warnings.warn(
                'Skipping twisted wrapper test because twisted not found')
            return

        # TODO Class must implement all abstract methods
        class EchoClient(LineReceiver):
            def connectionMade(self):
                self.sendLine(b'GET / HTTP/1.0\n\n')

            def lineReceived(self, line):
                global twisted_data
                twisted_data += line

        class EchoClientFactory(ClientFactory):
            protocol = EchoClient

            def clientConnectionFailed(self, connector, reason):
                reactor.stop()
                self.fail(reason)

            def clientConnectionLost(self, connector, reason):
                reactor.stop()

        pid = self.start_server(self.args)

        class ContextFactory(object):
            def getContext(self):
                return SSL.Context()

        try:
            global twisted_data
            twisted_data = b''

            context_factory = ContextFactory()
            factory = EchoClientFactory()
            wrapper.connectSSL(srv_host, self.srv_port, factory,
                               context_factory)
            # This will block until reactor.stop() is called
            reactor.run()
        finally:
            self.stop_server(pid)
        self.assertIn(b's_server -quiet -www', twisted_data)
Example #4
0
    def test_twisted_wrapper(self):
        # Test only when twisted and ZopeInterfaces are present
        try:
            from twisted.internet.protocol import ClientFactory
            from twisted.protocols.basic import LineReceiver
            from twisted.internet import reactor
            import M2Crypto.SSL.TwistedProtocolWrapper as wrapper
        except ImportError:
            import warnings

            warnings.warn("Skipping twisted wrapper test because twisted not found")
            return

        class EchoClient(LineReceiver):
            def connectionMade(self):
                self.sendLine("GET / HTTP/1.0\n\n")

            def lineReceived(self, line):
                global twisted_data
                twisted_data += line

        class EchoClientFactory(ClientFactory):
            protocol = EchoClient

            def clientConnectionFailed(self, connector, reason):
                reactor.stop()
                assert 0, reason

            def clientConnectionLost(self, connector, reason):
                reactor.stop()

        pid = self.start_server(self.args)

        class ContextFactory:
            def getContext(self):
                return SSL.Context()

        try:
            global twisted_data
            twisted_data = ""

            contextFactory = ContextFactory()
            factory = EchoClientFactory()
            wrapper.connectSSL(srv_host, srv_port, factory, contextFactory)
            reactor.run()  # This will block until reactor.stop() is called
        finally:
            self.stop_server(pid)
        self.failIf(string.find(twisted_data, "s_server -quiet -www") == -1)
Example #5
0
class EchoClient(basic.LineReceiver):
    def connectionMade(self):
        self.sendLine('Hello World!')

    def lineReceived(self, line):
        print 'received: "%s"' % line
        self.transport.loseConnection()


class EchoClientFactory(protocol.ClientFactory):
    protocol = EchoClient

    def clientConnectionFailed(self, connector, reason):
        print 'connection failed'
        reactor.stop()

    def clientConnectionLost(self, connector, reason):
        print 'connection lost'
        reactor.stop()


class ContextFactory:
    def getContext(self):
        return SSL.Context()


if __name__ == '__main__':
    factory = EchoClientFactory()
    wrapper.connectSSL('localhost', 8000, factory, ContextFactory())
    reactor.run()  # This will block until reactor.stop() is called
Example #6
0
class EchoClient(basic.LineReceiver):
    def connectionMade(self):
        self.sendLine("Hello World!")

    def lineReceived(self, line):
        print 'received: "%s"' % line
        self.transport.loseConnection()


class EchoClientFactory(protocol.ClientFactory):
    protocol = EchoClient

    def clientConnectionFailed(self, connector, reason):
        print "connection failed"
        reactor.stop()

    def clientConnectionLost(self, connector, reason):
        print "connection lost"
        reactor.stop()


class ContextFactory:
    def getContext(self):
        return SSL.Context()


if __name__ == "__main__":
    factory = EchoClientFactory()
    wrapper.connectSSL("localhost", 8000, factory, ContextFactory())
    reactor.run()  # This will block until reactor.stop() is called
Example #7
0
 def Start(self):
     port = self.location[1]
     self.contextFactory = SecureContextFactory()
     wrapper.listenSSL(port, self.factory, self.contextFactory)
 def Start(self, wxapp=None):
     host = self.location[0]
     port = self.location[1]
     #reactor.connectSSL(host, port, self.factory, ssl.ClientContextFactory())
     wrapper.connectSSL(host, port, self.factory, ClientContextFactory(), postConnectionCheck=None)
Example #9
0
import sys
import M2Crypto.SSL as SSL
import M2Crypto.SSL.TwistedProtocolWrapper as wrapper
import twisted.internet.protocol as protocol
import twisted.internet.reactor as reactor
import twisted.python.log as log


class Echo(protocol.Protocol):
    def dataReceived(self, data):
        print 'received: "%s"' % data
        self.transport.write(data)

    def connectionMade(self):
        print 'connection made'


class ContextFactory:
    def getContext(self):
        ctx = SSL.Context()
        ctx.load_cert('server.pem')
        return ctx


if __name__ == '__main__':
    log.startLogging(sys.stdout)
    factory = protocol.Factory()
    factory.protocol = Echo
    wrapper.listenSSL(8000, factory, ContextFactory())
    reactor.run()
 def Start(self):
     port = self.location[1]
     self.contextFactory = SecureContextFactory()
     wrapper.listenSSL(port, self.factory, self.contextFactory)