コード例 #1
0
    def setup(self):
        # initialize storage
        # doing it here because it's needed by the server factory
        storage.init(self.config['database'])
        self.presencedb = storage.MySQLPresenceStorage()

        # TODO from configuration
        stor_class = self.config['storage']['class']
        klass = getattr(storage, stor_class)
        self.storage = klass(*self.config['storage']['params'])

        self.keyring = keyring.Keyring(storage.MySQLNetworkStorage(), self.config['fingerprint'], self.network, self.servername, disable_cache=True)
        token_auth = auth.AuthKontalkChecker(self.config['fingerprint'], self.keyring)

        # upload endpoint
        portal = Portal(FileUploadRealm(self), [token_auth])
        resource = HTTPSAuthSessionWrapper(portal, auth.KontalkCertificate)
        self.putChild('upload', resource)

        # download endpoint
        portal = Portal(FileDownloadRealm(self), [token_auth])
        resource = HTTPSAuthSessionWrapper(portal, auth.KontalkCertificate)
        self.putChild('download', resource)

        # http service
        self.factory = server.Site(self)
        sslFactory = xmlstream2.MyOpenSSLCertificateOptions(self.config['ssl_key'], self.config['ssl_cert'], self._sslVerify)
        endpoint = SSL4ServerEndpoint(reactor, self.config['bind'][1], sslFactory, interface=str(self.config['bind'][0]))
        svc = StreamServerEndpointService(endpoint, self.factory)
        svc._raiseSynchronously = True
        return svc
コード例 #2
0
ファイル: resolver.py プロジェクト: odetoyama/xmppserver
    def __init__(self, config):
        router_cfg = config['router']
        for key in ('socket', 'host', 'port'):
            if key not in router_cfg:
                router_cfg[key] = None

        router_jid = '%s.%s' % (router_cfg['jid'], config['host'])
        xmlstream2.SocketComponent.__init__(self, router_cfg['socket'],
                                            router_cfg['host'],
                                            router_cfg['port'], router_jid,
                                            router_cfg['secret'])
        self.config = config

        # this is for queueing keyring thread requests
        reactor.suggestThreadPoolSize(1)

        self.logTraffic = config['debug']
        self.network = config['network']
        self.servername = config['host']
        self.start_time = time.time()

        storage.init(config['database'])
        self.keyring = keyring.Keyring(storage.MySQLNetworkStorage(),
                                       config['fingerprint'], self.network,
                                       self.servername, True)
        self.presencedb = storage.MySQLPresenceStorage()

        self.subscriptions = {}
        self.whitelists = {}
        self.blacklists = {}

        # protocol handlers here!!
        for handler in self.protocolHandlers:
            inst = handler()
            if handler == JIDCache:
                self.cache = inst
            inst.setHandlerParent(self)
コード例 #3
0
    def setup(self):
        # initialize storage
        # doing it here because it's needed by the c2s server factory
        storage.init(self.config['database'])
        self.presencedb = storage.MySQLPresenceStorage()

        try:
            stanza_expire = self.config['stanza_expire']
        except KeyError:
            stanza_expire = 0
        self.stanzadb = storage.MySQLStanzaStorage(stanza_expire)

        try:
            validation_expire = self.config['registration']['expire']
        except KeyError:
            validation_expire = 0
        self.validationdb = storage.MySQLUserValidationStorage(
            validation_expire)

        self.keyring = keyring.Keyring(storage.MySQLNetworkStorage(),
                                       self.config['fingerprint'],
                                       self.network, self.servername)
        authrealm = auth.SASLRealm("Kontalk")
        authportal = portal.Portal(authrealm, [
            auth.AuthKontalkChecker(self.config['fingerprint'], self.keyring,
                                    self._verify_fingerprint)
        ])

        self.sfactory = XMPPServerFactory(authportal, self, self.network,
                                          self.servername)
        self.sfactory.logTraffic = self.config['debug']
        if 'ssl_key' in self.config and 'ssl_cert' in self.config:
            self.sfactory.loadPEM(self.config['ssl_cert'],
                                  self.config['ssl_key'])

        services = []

        if 'plain' in self.config['bind']:
            plain_svc = strports.service(
                'tcp:' + str(self.config['bind']['plain'][1]) + ':interface=' +
                str(self.config['bind']['plain'][0]), self.sfactory)
            services.append(plain_svc)

        if 'ssl' in self.config['bind']:
            ssl_svc = internet.SSLServer(
                port=int(self.config['bind']['ssl'][1]),
                interface=str(self.config['bind']['ssl'][0]),
                factory=self.sfactory,
                contextFactory=self.sfactory.getSSLContext())

            services.append(ssl_svc)

        if 'tls' in self.config['bind']:
            cert = OpenPGPCertificate(open(self.config['pgp_cert']).read())
            key = OpenPGPPrivateKey(open(self.config['pgp_key']).read())

            cred = auth.OpenPGPKontalkCredentials(
                cert, key, str(self.config['pgp_keyring']))
            cred.verify_peer = True
            tls_svc = StreamServerEndpointService(
                tls.TLSServerEndpoint(reactor=reactor,
                                      port=int(self.config['bind']['tls'][1]),
                                      interface=str(
                                          self.config['bind']['tls'][0]),
                                      credentials=cred), self.sfactory)
            tls_svc._raiseSynchronously = True

            services.append(tls_svc)

        return services