コード例 #1
0
ファイル: protonReactor.py プロジェクト: fzkbass/vdsm
    def _authenticateConnector(self, connector):
        self.log.debug("Authenticating...")
        sasl = proton.pn_connector_sasl(connector)
        state = proton.pn_sasl_state(sasl)
        while state == proton.PN_SASL_CONF or state == proton.PN_SASL_STEP:
            if state == proton.PN_SASL_CONF:
                self.log.debug("Authenticating-CONF...")
                proton.pn_sasl_mechanisms(sasl, "ANONYMOUS")
                proton.pn_sasl_server(sasl)
            elif state == proton.PN_SASL_STEP:
                self.log.debug("Authenticating-STEP...")
                mech = proton.pn_sasl_remote_mechanisms(sasl)
                if isinstance(mech, (list, tuple)):
                    mech = mech[0]

                if mech == "ANONYMOUS":
                    proton.pn_sasl_done(sasl, proton.PN_SASL_OK)
                else:
                    proton.pn_sasl_done(sasl, proton.PN_SASL_AUTH)
            state = proton.pn_sasl_state(sasl)

        if state == proton.PN_SASL_PASS:
            proton.pn_connector_set_connection(connector,
                                               proton.pn_connection())
            proton.pn_connector_set_context(connector, CONNECTED)
            self.log.debug("Authentication-PASSED")
        elif state == proton.PN_SASL_FAIL:
            proton.pn_connector_set_context(connector, FAILED)
            self.log.debug("Authentication-FAILED")
        else:
            self.log.debug("Authentication-PENDING")
コード例 #2
0
ファイル: protonReactor.py プロジェクト: fzkbass/vdsm
    def _authenticateConnector(self, connector):
        self.log.debug("Authenticating...")
        sasl = proton.pn_connector_sasl(connector)
        state = proton.pn_sasl_state(sasl)
        while state == proton.PN_SASL_CONF or state == proton.PN_SASL_STEP:
            if state == proton.PN_SASL_CONF:
                self.log.debug("Authenticating-CONF...")
                proton.pn_sasl_mechanisms(sasl, "ANONYMOUS")
                proton.pn_sasl_server(sasl)
            elif state == proton.PN_SASL_STEP:
                self.log.debug("Authenticating-STEP...")
                mech = proton.pn_sasl_remote_mechanisms(sasl)
                if isinstance(mech, (list, tuple)):
                    mech = mech[0]

                if mech == "ANONYMOUS":
                    proton.pn_sasl_done(sasl, proton.PN_SASL_OK)
                else:
                    proton.pn_sasl_done(sasl, proton.PN_SASL_AUTH)
            state = proton.pn_sasl_state(sasl)

        if state == proton.PN_SASL_PASS:
            proton.pn_connector_set_connection(connector,
                                               proton.pn_connection())
            proton.pn_connector_set_context(connector, CONNECTED)
            self.log.debug("Authentication-PASSED")
        elif state == proton.PN_SASL_FAIL:
            proton.pn_connector_set_context(connector, FAILED)
            self.log.debug("Authentication-FAILED")
        else:
            self.log.debug("Authentication-PENDING")
コード例 #3
0
ファイル: protonReactor.py プロジェクト: fzkbass/vdsm
    def _openClientSession(self):
        host, port = self._address
        amqpAddress = "ampq://%s:%d/vdsm" % (host, port)
        senderName = "jsonrpc.ProtonClient %s (%s)" % (
            str(uuid.uuid4()),
            amqpAddress,
        )
        self.log = logging.getLogger(senderName)

        self.connector = proton.pn_connector(self._reactor._driver, host,
                                             str(port), None)
        if self.connector is None:
            raise ProtonError("Could not create connector")

        self.connection = proton.pn_connection()
        proton.pn_connector_set_connection(self.connector, self.connection)

        sasl = proton.pn_connector_sasl(self.connector)
        proton.pn_sasl_mechanisms(sasl, "ANONYMOUS")
        proton.pn_sasl_client(sasl)

        proton.pn_connector_set_context(self.connector, CLIENT_AUTH)
        self.log.debug("Opening active connection")
        proton.pn_connection_open(self.connection)

        while True:
            # TODO: Handle connection being closed mid authentication
            if proton.pn_sasl_state(sasl) in (proton.PN_SASL_PASS, ):
                proton.pn_connector_set_context(self.connector, CONNECTED)
                break

            if proton.pn_sasl_state(sasl) == proton.PN_SASL_FAIL:
                yield Return(-1)

            yield

        self.session = proton.pn_session(self.connection)
        proton.pn_session_open(self.session)
        proton.pn_session_set_context(self.session, self)

        link = proton.pn_sender(self.session, senderName)
        dst = proton.pn_link_target(link)
        proton.pn_terminus_set_address(dst, amqpAddress)
        self.sender = link
        yield Return(1)
コード例 #4
0
ファイル: protonReactor.py プロジェクト: fzkbass/vdsm
    def _openClientSession(self):
        host, port = self._address
        amqpAddress = "ampq://%s:%d/vdsm" % (host, port)
        senderName = "jsonrpc.ProtonClient %s (%s)" % (str(uuid.uuid4()),
                                                       amqpAddress,)
        self.log = logging.getLogger(senderName)

        self.connector = proton.pn_connector(self._reactor._driver,
                                             host, str(port), None)
        if self.connector is None:
            raise ProtonError("Could not create connector")

        self.connection = proton.pn_connection()
        proton.pn_connector_set_connection(self.connector, self.connection)

        sasl = proton.pn_connector_sasl(self.connector)
        proton.pn_sasl_mechanisms(sasl, "ANONYMOUS")
        proton.pn_sasl_client(sasl)

        proton.pn_connector_set_context(self.connector, CLIENT_AUTH)
        self.log.debug("Opening active connection")
        proton.pn_connection_open(self.connection)

        while True:
            # TODO: Handle connection being closed mid authentication
            if proton.pn_sasl_state(sasl) in (proton.PN_SASL_PASS,):
                proton.pn_connector_set_context(self.connector, CONNECTED)
                break

            if proton.pn_sasl_state(sasl) == proton.PN_SASL_FAIL:
                yield Return(-1)

            yield

        self.session = proton.pn_session(self.connection)
        proton.pn_session_open(self.session)
        proton.pn_session_set_context(self.session, self)

        link = proton.pn_sender(self.session, senderName)
        dst = proton.pn_link_target(link)
        proton.pn_terminus_set_address(dst, amqpAddress)
        self.sender = link
        yield Return(1)