def test_parse_client_basic(self): from twisted.plugins import autobahn_endpoints self.assertTrue(hasattr(autobahn_endpoints, 'AutobahnClientParser')) from twisted.internet.endpoints import clientFromString, quoteStringArgument from twisted.internet import reactor ep_string = "autobahn:{0}:url={1}".format( quoteStringArgument('tcp:localhost:9000'), quoteStringArgument('ws://localhost:9000'), ) # we're just testing that this doesn't fail entirely clientFromString(reactor, ep_string)
def test_parse_client_basic(self): from twisted.plugins import autobahn_endpoints self.assertTrue(hasattr(autobahn_endpoints, "AutobahnClientParser")) from twisted.internet.endpoints import clientFromString, quoteStringArgument from twisted.internet import reactor ep_string = "autobahn:{0}:url={1}".format( quoteStringArgument("tcp:localhost:9000"), quoteStringArgument("ws://localhost:9000") ) # we're just testing that this doesn't fail entirely clientFromString(reactor, ep_string)
def test_quoteStringArgument(self): """ L{endpoints.quoteStringArgument} should quote backslashes and colons for interpolation into L{endpoints.serverFromString} and L{endpoints.clientFactory} arguments. """ self.assertEqual(endpoints.quoteStringArgument("some : stuff \\"), "some \\: stuff \\\\")
def test_quoteStringArgument(self): """ L{endpoints.quoteStringArgument} should quote backslashes and colons for interpolation into L{endpoints.serverFromString} and L{endpoints.clientFactory} arguments. """ self.assertEquals(endpoints.quoteStringArgument("some : stuff \\"), "some \\: stuff \\\\")
def unparseEndpoint(args: Tuple[object, ...], kwargs: Mapping[str, object]) -> str: """ Un-parse the already-parsed args and kwargs back into endpoint syntax. @param args: C{:}-separated arguments @param kwargs: C{:} and then C{=}-separated keyword arguments @return: a string equivalent to the original format which this was parsed as. """ description = ":".join([quoteStringArgument(str(arg)) for arg in args] + sorted( "{}={}".format(quoteStringArgument(str(key)), quoteStringArgument(str(value))) for key, value in kwargs.items())) return description
def unparseEndpoint(args, kwargs): """ Un-parse the already-parsed args and kwargs back into endpoint syntax. @param args: C{:}-separated arguments @type args: L{tuple} of native L{str} @param kwargs: C{:} and then C{=}-separated keyword arguments @type arguments: L{tuple} of native L{str} @return: a string equivalent to the original format which this was parsed as. @rtype: native L{str} """ description = ":".join( [quoteStringArgument(str(arg)) for arg in args] + sorted("%s=%s" % (quoteStringArgument(str(key)), quoteStringArgument(str(value))) for key, value in kwargs.items())) return description
def unparseEndpoint(args, kwargs): """ Un-parse the already-parsed args and kwargs back into endpoint syntax. @param args: C{:}-separated arguments @type args: L{tuple} of native L{str} @param kwargs: C{:} and then C{=}-separated keyword arguments @type arguments: L{tuple} of native L{str} @return: a string equivalent to the original format which this was parsed as. @rtype: native L{str} """ description = ':'.join( [quoteStringArgument(str(arg)) for arg in args] + sorted(['%s=%s' % (quoteStringArgument(str(key)), quoteStringArgument(str(value))) for key, value in iteritems(kwargs) ])) return description
def main(pm): from sputnik.webserver.router.twisted.wamp import RouterFactory router_factory = RouterFactory() router_factory.router = SputnikRouter router_factory.authz_plugins = \ pm.services.get("sputnik.webserver.plugins.authz", []) router_factory.schema_plugins = \ pm.services.get("sputnik.webserver.plugins.schema", []) from sputnik.webserver.router.twisted.wamp import RouterSessionFactory session_factory = RouterSessionFactory(router_factory) session_factory.session = SputnikRouterSession authn_stack = [("ip.IPFilter", "requisite"), ("anonymous.AnonymousLogin", "sufficient"), ("cookie.CookieLogin", "sufficient"), ("wampcra.WAMPCRALogin", "requisite"), ("totp.TOTPVerification", "requisite")] session_factory.plugins = [] for plugin_name, flag in authn_stack: path = "sputnik.webserver.plugins.authn." + plugin_name session_factory.plugins.append((pm.plugins[path], flag)) rpc_plugins = pm.services.get("sputnik.webserver.plugins.rpc", []) feeds_plugins = pm.services.get("sputnik.webserver.plugins.feeds", []) svc_plugins = rpc_plugins + feeds_plugins for plugin in svc_plugins: component_session = plugin component_session.config.realm = u"sputnik" session_factory.add(component_session, plugin.plugin_path.decode("ascii"), u"trusted") uri = "ws://" if config.getboolean("webserver", "ssl"): uri = "wss://" address = config.get("webserver", "ws_address") port = config.getint("webserver", "ws_port") uri += "%s:%s/" % (address, port) from autobahn.twisted.websocket import WampWebSocketServerFactory transport_factory = WampWebSocketServerFactory(session_factory, uri, debug = False, debug_wamp = False) transport_factory.setProtocolOptions(failByDrop = False) watchdog(config.get("watchdog", "webserver")) from twisted.web.server import Site from autobahn.twisted.resource import WebSocketResource root = Root() ws_resource = WebSocketResource(transport_factory) rest_resource = pm.plugins['sputnik.webserver.rest.RESTProxy'] root.putChild("ws", ws_resource) root.putChild("api", rest_resource) site = Site(root) site.noisy = False site.log = lambda _: None from twisted.internet.endpoints import serverFromString, quoteStringArgument if config.getboolean("webserver", "ssl"): key = config.get("webserver", "ssl_key") cert = config.get("webserver", "ssl_cert") cert_chain = config.get("webserver", "ssl_cert_chain") # TODO: Add dhparameters # See https://twistedmatrix.com/documents/14.0.0/core/howto/endpoints.html server = serverFromString(reactor, b"ssl:%d:privateKey=%s:certKey=%s:extraCertChain=%s:sslmethod=TLSv1_METHOD" % (port, quoteStringArgument(key), quoteStringArgument(cert), quoteStringArgument(cert_chain))) else: server = serverFromString(reactor, b"tcp:%d" % port) server.listen(site)
def run(pm, reactor): from sputnik.webserver.router.twisted.wamp import RouterFactory router_factory = RouterFactory() router_factory.router = SputnikRouter router_factory.authz_plugins = \ pm.services.get("sputnik.webserver.plugins.authz", []) router_factory.schema_plugins = \ pm.services.get("sputnik.webserver.plugins.schema", []) from sputnik.webserver.router.twisted.wamp import RouterSessionFactory session_factory = RouterSessionFactory(router_factory) session_factory.session = SputnikRouterSession authn_stack = [("ip.IPFilter", "requisite"), ("anonymous.AnonymousLogin", "sufficient"), ("cookie.CookieLogin", "sufficient"), ("wampcra.WAMPCRALogin", "requisite"), ("totp.TOTPVerification", "requisite")] session_factory.plugins = [] for plugin_name, flag in authn_stack: path = "sputnik.webserver.plugins.authn." + plugin_name session_factory.plugins.append((pm.plugins[path], flag)) rpc_plugins = pm.services.get("sputnik.webserver.plugins.rpc", []) feeds_plugins = pm.services.get("sputnik.webserver.plugins.feeds", []) svc_plugins = rpc_plugins + feeds_plugins for plugin in svc_plugins: component_session = plugin component_session.config.realm = u"sputnik" session_factory.add(component_session, plugin.plugin_path.decode("ascii"), u"trusted") uri = "ws://" if config.getboolean("webserver", "ssl"): uri = "wss://" address = config.get("webserver", "ws_address") port = config.getint("webserver", "ws_port") uri += "%s:%s/" % (address, port) from autobahn.twisted.websocket import WampWebSocketServerFactory transport_factory = WampWebSocketServerFactory(session_factory, uri, debug=False, debug_wamp=False) transport_factory.setProtocolOptions(failByDrop=False) watchdog(config.get("watchdog", "webserver")) from twisted.web.server import Site from autobahn.twisted.resource import WebSocketResource root = Root() ws_resource = WebSocketResource(transport_factory) rest_resource = pm.plugins['sputnik.webserver.rest.RESTProxy'] root.putChild("ws", ws_resource) root.putChild("api", rest_resource) site = Site(root) site.noisy = False site.log = lambda _: None from twisted.internet.endpoints import serverFromString, quoteStringArgument if config.getboolean("webserver", "ssl"): key = config.get("webserver", "ssl_key") cert = config.get("webserver", "ssl_cert") cert_chain = config.get("webserver", "ssl_cert_chain") # TODO: Add dhparameters # See https://twistedmatrix.com/documents/14.0.0/core/howto/endpoints.html server = serverFromString( reactor, b"ssl:%d:privateKey=%s:certKey=%s:extraCertChain=%s:sslmethod=TLSv1_METHOD" % (port, quoteStringArgument(key), quoteStringArgument(cert), quoteStringArgument(cert_chain))) else: server = serverFromString(reactor, b"tcp:%d" % port) server.listen(site)
from twisted.trial import unittest from twisted.internet import error, interfaces from twisted.internet import endpoints from twisted.internet.address import IPv4Address, UNIXAddress from twisted.internet.protocol import ClientFactory, Protocol from twisted.test.proto_helpers import MemoryReactor, RaisingMemoryReactor from twisted.python.failure import Failure from twisted import plugins from twisted.python.modules import getModule from twisted.python.filepath import FilePath pemPath = getModule("twisted.test").filePath.sibling("server.pem") casPath = getModule(__name__).filePath.sibling("fake_CAs") escapedPEMPathName = endpoints.quoteStringArgument(pemPath.path) escapedCAsPathName = endpoints.quoteStringArgument(casPath.path) try: from twisted.test.test_sslverify import makeCertificate from twisted.internet.ssl import CertificateOptions, Certificate, \ KeyPair, PrivateCertificate from OpenSSL.SSL import ContextType testCertificate = Certificate.loadPEM(pemPath.getContent()) testPrivateCertificate = PrivateCertificate.loadPEM(pemPath.getContent()) skipSSL = False except ImportError: skipSSL = "OpenSSL is required to construct SSL Endpoints"
from twisted.trial import unittest from twisted.internet import error, interfaces from twisted.internet import endpoints from twisted.internet.address import IPv4Address, UNIXAddress from twisted.internet.protocol import ClientFactory, Protocol from twisted.test.proto_helpers import MemoryReactor, RaisingMemoryReactor from twisted.python.failure import Failure from twisted import plugins from twisted.python.modules import getModule from twisted.python.filepath import FilePath pemPath = getModule("twisted.test").filePath.sibling("server.pem") casPath = getModule(__name__).filePath.sibling("fake_CAs") escapedPEMPathName = endpoints.quoteStringArgument(pemPath.path) escapedCAsPathName = endpoints.quoteStringArgument(casPath.path) try: from twisted.test.test_sslverify import makeCertificate from twisted.internet.ssl import CertificateOptions, Certificate, \ KeyPair, PrivateCertificate from OpenSSL.SSL import ContextType testCertificate = Certificate.loadPEM(pemPath.getContent()) testPrivateCertificate = PrivateCertificate.loadPEM(pemPath.getContent()) skipSSL = False except ImportError: skipSSL = "OpenSSL is required to construct SSL Endpoints"
def _create_tx_endpoints_string(args, kwargs): _kwargs = ([ '='.join((k, quoteStringArgument(v))) for k, v in kwargs.items() ]) return ':'.join(args + _kwargs)
def __init__(self, api="SAM", apiEndpoint="tcp:127.0.0.1:7656", socksPort=9050): self.api = api self.apiEndpoint = quoteStringArgument(apiEndpoint) self.socksPort = socksPort
def _create_tx_endpoints_string(args, kwargs): _kwargs = ( ['='.join((k, quoteStringArgument(v))) for k, v in kwargs.items()]) return ':'.join(args + _kwargs)