コード例 #1
0
ファイル: connection.py プロジェクト: xBlackSwan/msldap
    async def connect(self):
        """
		Connects to the remote server. Establishes the session, but doesn't perform binding.
		This function MUST be called first before the `bind` operation.

		:return: A tuple of (True, None) on success or (False, Exception) on error. 
		:rtype: (:class:`bool`, :class:`Exception`)
		"""
        try:
            logger.debug('Connecting!')
            self.network = await MSLDAPNetworkSelector.select(self.target)
            res, err = await self.network.run()
            if res is False:
                return False, err

            # now processing channel binding options
            if self.target.proto == LDAPProtocol.SSL:
                certdata = self.network.get_peer_certificate()
                #cert = Certificate.load(certdata).native
                #print(cert)
                cb_struct = ChannelBindingsStruct()
                cb_struct.application_data = b'tls-server-end-point:' + sha256(
                    certdata).digest()

                self.cb_data = cb_struct.to_bytes()

            self.handle_incoming_task = asyncio.create_task(
                self.__handle_incoming())
            logger.debug('Connection succsessful!')
            return True, None
        except Exception as e:
            return False, e
コード例 #2
0
    async def connect(self):
        try:
            logger.debug('Connecting!')
            self.network = await MSLDAPNetworkSelector.select(self.target)
            res, err = await self.network.run()
            if res is False:
                return False, err

            # now processing channel binding options
            if self.target.proto == LDAPProtocol.SSL:
                certdata = self.network.get_peer_certificate()
                #cert = Certificate.load(certdata).native
                #print(cert)
                cb_struct = ChannelBindingsStruct()
                cb_struct.application_data = b'tls-server-end-point:' + sha256(
                    certdata).digest()

                self.cb_data = cb_struct.to_bytes()

            self.handle_incoming_task = asyncio.create_task(
                self.__handle_incoming())
            logger.debug('Connection succsessful!')
            return True, None
        except Exception as e:
            return False, e