Python twisted.application.internet.SSLServer() Examples
The following are 15
code examples of twisted.application.internet.SSLServer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
twisted.application.internet
, or try the search function
.
Example #1
Source File: epoptesd.py From epoptes with GNU General Public License v3.0 | 5 votes |
def makeService(self, options): """Override IServiceMaker.makeService.""" factory = bashplex.DelimitedBashReceiverFactory() factory.ping_interval = int(options['ping-interval']) factory.ping_timeout = int(options['ping-timeout']) factory.startup_commands = filter_bash( '/usr/share/epoptes/client-functions') if config.system['ENCRYPTION']: client_service = internet.SSLServer( int(config.system['PORT']), factory, ServerContextFactory()) else: client_service = internet.TCPServer( int(config.system['PORT']), factory) gid = grp.getgrnam(config.system['SOCKET_GROUP'])[2] if not os.path.isdir(config.system['DIR']): # TODO: for some reason this does 0750 instead os.makedirs(config.system['DIR'], 0o2770) os.chmod(config.system['DIR'], 0o2770) os.chown(config.system['DIR'], -1, gid) gui_service = internet.UNIXServer( "%s/epoptes.socket" % config.system['DIR'], guiplex.GUIFactory()) top_service = service.MultiService() top_service.addService(client_service) top_service.addService(gui_service) return top_service
Example #2
Source File: tap.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def makeService(config): s = service.MultiService() if config['root']: root = config['root'] if config['indexes']: config['root'].indexNames = config['indexes'] else: # This really ought to be web.Admin or something root = demo.Test() if isinstance(root, static.File): root.registry.setComponent(interfaces.IServiceCollection, s) if config['logfile']: site = server.Site(root, logPath=config['logfile']) else: site = server.Site(root) site.displayTracebacks = not config["notracebacks"] if not _PY3 and config['personal']: personal = strports.service( config['port'], makePersonalServerFactory(site)) personal.setServiceParent(s) else: if config['https']: from twisted.internet.ssl import DefaultOpenSSLContextFactory i = internet.SSLServer(int(config['https']), site, DefaultOpenSSLContextFactory(config['privkey'], config['certificate'])) i.setServiceParent(s) strports.service(config['port'], site).setServiceParent(s) return s
Example #3
Source File: tcp.py From ccs-twistedextensions with Apache License 2.0 | 5 votes |
def __init__(self, *args, **kwargs): internet.SSLServer.__init__(self, *args, **kwargs) self.protocolFactory = self.args[1] self.protocolFactory.myServer = self self.inherit = self.kwargs.get("inherit", False) self.backlog = self.kwargs.get("backlog", None) self.interface = self.kwargs.get("interface", None)
Example #4
Source File: tcp.py From ccs-twistedextensions with Apache License 2.0 | 5 votes |
def stopService(self): """ Wait for outstanding requests to finish @return: a Deferred which fires when all outstanding requests are complete. """ internet.SSLServer.stopService(self) # TODO: check for an ICompletionWaiter interface return _allConnectionsClosed(self.protocolFactory)
Example #5
Source File: test_caldav.py From ccs-calendarserver with Apache License 2.0 | 5 votes |
def test_SSLKeyConfiguration(self): """ Test that the configuration of the SSLServer reflect the config file's SSL Private Key and SSL Certificate """ # Note: the listeners are bundled within a MultiService named "ConnectionService" service = CalDAVServiceMaker().makeService(self.options) service = service.getServiceNamed(CalDAVService.connectionServiceName) sslService = None for s in service.services: if isinstance(s, internet.SSLServer): sslService = s break self.failIf(sslService is None, "No SSL Service found") context = sslService.args[2] self.assertEquals( config.SSLPrivateKey, context.privateKeyFileName ) self.assertEquals( config.SSLCertificate, context.certificateFileName, )
Example #6
Source File: test_caldav.py From ccs-calendarserver with Apache License 2.0 | 5 votes |
def test_noSSL(self): """ Test the single service to make sure there is no SSL Service when SSL is disabled """ # Note: the listeners are bundled within a MultiService named "ConnectionService" service = CalDAVServiceMaker().makeService(self.options) service = service.getServiceNamed(CalDAVService.connectionServiceName) self.assertNotIn( internet.SSLServer, [s.__class__ for s in service.services] )
Example #7
Source File: test_caldav.py From ccs-calendarserver with Apache License 2.0 | 5 votes |
def test_singleBindAddresses(self): """ Test that the TCPServer and SSLServers are bound to the proper address """ # Note: the listeners are bundled within a MultiService named "ConnectionService" service = CalDAVServiceMaker().makeService(self.options) service = service.getServiceNamed(CalDAVService.connectionServiceName) for s in service.services: if isinstance(s, (internet.TCPServer, internet.SSLServer)): self.assertEquals(s.kwargs["interface"], "127.0.0.1")
Example #8
Source File: test_caldav.py From ccs-calendarserver with Apache License 2.0 | 5 votes |
def test_multipleBindAddresses(self): """ Test that the TCPServer and SSLServers are bound to the proper addresses. """ # Note: the listeners are bundled within a MultiService named "ConnectionService" service = CalDAVServiceMaker().makeService(self.options) service = service.getServiceNamed(CalDAVService.connectionServiceName) tcpServers = [] sslServers = [] for s in service.services: if isinstance(s, internet.TCPServer): tcpServers.append(s) elif isinstance(s, internet.SSLServer): sslServers.append(s) self.assertEquals(len(tcpServers), len(config.BindAddresses)) self.assertEquals(len(sslServers), len(config.BindAddresses)) for addr in config.BindAddresses: for s in tcpServers: if s.kwargs["interface"] == addr: tcpServers.remove(s) for s in sslServers: if s.kwargs["interface"] == addr: sslServers.remove(s) self.assertEquals(len(tcpServers), 0) self.assertEquals(len(sslServers), 0)
Example #9
Source File: test_caldav.py From ccs-calendarserver with Apache License 2.0 | 5 votes |
def test_listenBacklog(self): """ Test that the backlog arguments is set in TCPServer and SSLServers """ # Note: the listeners are bundled within a MultiService named "ConnectionService" service = CalDAVServiceMaker().makeService(self.options) service = service.getServiceNamed(CalDAVService.connectionServiceName) for s in service.services: if isinstance(s, (internet.TCPServer, internet.SSLServer)): self.assertEquals(s.kwargs["backlog"], 1024)
Example #10
Source File: app.py From scrapy-do with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _configure_web_server(self, config, controller): interfaces, https, key_file, cert_file, chain_file, _, _ = \ self._validate_web_config(config) site = server.Site(get_web_app(config, controller)) web_servers = [] for interface, port in interfaces: if https: cf = SSLCertOptions(key_file, cert_file, chain_file) web_server = SSLServer(port, site, cf, interface=interface) method = 'https' else: web_server = TCPServer(port, site, interface=interface) method = 'http' web_servers.append(web_server) if ':' in interface: interface = '[{}]'.format(interface) log.msg(format="Scrapy-Do web interface is available at " "%(method)s://%(interface)s:%(port)s/", method=method, interface=interface, port=port) return web_servers #---------------------------------------------------------------------------
Example #11
Source File: tap.py From python-for-android with Apache License 2.0 | 5 votes |
def makeService(config): s = service.MultiService() if config['root']: root = config['root'] if config['indexes']: config['root'].indexNames = config['indexes'] else: # This really ought to be web.Admin or something root = demo.Test() if isinstance(root, static.File): root.registry.setComponent(interfaces.IServiceCollection, s) if config['logfile']: site = server.Site(root, logPath=config['logfile']) else: site = server.Site(root) site.displayTracebacks = not config["notracebacks"] if config['personal']: personal = strports.service( config['port'], makePersonalServerFactory(site)) personal.setServiceParent(s) else: if config['https']: from twisted.internet.ssl import DefaultOpenSSLContextFactory i = internet.SSLServer(int(config['https']), site, DefaultOpenSSLContextFactory(config['privkey'], config['certificate'])) i.setServiceParent(s) strports.service(config['port'], site).setServiceParent(s) return s
Example #12
Source File: compat.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def listenSSL(self, port, factory, ctxFactory, backlog=50, interface=''): s = internet.SSLServer(port, factory, ctxFactory, backlog, interface) s.privileged = 1 s.setServiceParent(self.app)
Example #13
Source File: tap.py From python-for-android with Apache License 2.0 | 4 votes |
def makeService(config): if config['esmtp']: rmType = relaymanager.SmartHostESMTPRelayingManager smtpFactory = config.service.getESMTPFactory else: rmType = relaymanager.SmartHostSMTPRelayingManager smtpFactory = config.service.getSMTPFactory if config['relay']: dir = config['relay'] if not os.path.isdir(dir): os.mkdir(dir) config.service.setQueue(relaymanager.Queue(dir)) default = relay.DomainQueuer(config.service) manager = rmType(config.service.queue) if config['esmtp']: manager.fArgs += (None, None) manager.fArgs += (config['hostname'],) helper = relaymanager.RelayStateHelper(manager, 1) helper.setServiceParent(config.service) config.service.domains.setDefaultDomain(default) ctx = None if config['certificate']: from twisted.mail.protocols import SSLContextFactory ctx = SSLContextFactory(config['certificate']) if config['pop3']: s = internet.TCPServer(config['pop3'], config.service.getPOP3Factory()) s.setServiceParent(config.service) if config['pop3s']: s = internet.SSLServer(config['pop3s'], config.service.getPOP3Factory(), ctx) s.setServiceParent(config.service) if config['smtp']: f = smtpFactory() f.context = ctx if config['hostname']: f.domain = config['hostname'] f.fArgs = (f.domain,) if config['esmtp']: f.fArgs = (None, None) + f.fArgs s = internet.TCPServer(config['smtp'], f) s.setServiceParent(config.service) return config.service
Example #14
Source File: tap.py From BitTorrent with GNU General Public License v3.0 | 4 votes |
def makeService(config): s = service.MultiService() if config['root']: root = config['root'] if config['indexes']: config['root'].indexNames = config['indexes'] else: # This really ought to be web.Admin or something root = demo.Test() if isinstance(root, static.File): root.registry.setComponent(interfaces.IServiceCollection, s) if config['logfile']: site = server.Site(root, logPath=config['logfile']) else: site = server.Site(root) site.displayTracebacks = not config["notracebacks"] if config['personal']: import pwd,os pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell \ = pwd.getpwuid(os.getuid()) i = internet.UNIXServer(os.path.join(pw_dir, distrib.UserDirectory.userSocketName), pb.BrokerFactory(distrib.ResourcePublisher(site))) i.setServiceParent(s) else: if config['https']: from twisted.internet.ssl import DefaultOpenSSLContextFactory i = internet.SSLServer(int(config['https']), site, DefaultOpenSSLContextFactory(config['privkey'], config['certificate'])) i.setServiceParent(s) strports.service(config['port'], site).setServiceParent(s) flashport = config.get('flashconduit', None) if flashport: from twisted.web.woven.flashconduit import FlashConduitFactory i = internet.TCPServer(int(flashport), FlashConduitFactory(site)) i.setServiceParent(s) return s
Example #15
Source File: tap.py From BitTorrent with GNU General Public License v3.0 | 4 votes |
def makeService(config): if config['esmtp']: rmType = relaymanager.SmartHostESMTPRelayingManager smtpFactory = config.service.getESMTPFactory else: rmType = relaymanager.SmartHostSMTPRelayingManager smtpFactory = config.service.getSMTPFactory if config['relay']: dir = config['relay'] if not os.path.isdir(dir): os.mkdir(dir) config.service.setQueue(relaymanager.Queue(dir)) default = relay.DomainQueuer(config.service) manager = rmType(config.service.queue) if config['esmtp']: manager.fArgs += (None, None) manager.fArgs += (config['hostname'],) helper = relaymanager.RelayStateHelper(manager, 1) helper.setServiceParent(config.service) config.service.domains.setDefaultDomain(default) ctx = None if config['certificate']: from twisted.mail.protocols import SSLContextFactory ctx = SSLContextFactory(config['certificate']) if config['pop3']: s = internet.TCPServer(config['pop3'], config.service.getPOP3Factory()) s.setServiceParent(config.service) if config['pop3s']: s = internet.SSLServer(config['pop3s'], config.service.getPOP3Factory(), ctx) s.setServiceParent(config.service) if config['smtp']: f = smtpFactory() f.context = ctx if config['hostname']: f.domain = config['hostname'] f.fArgs = (f.domain,) if config['esmtp']: f.fArgs = (None, None) + f.fArgs s = internet.TCPServer(config['smtp'], f) s.setServiceParent(config.service) return config.service