当前位置: 首页>>代码示例>>Python>>正文


Python zmq.auth方法代码示例

本文整理汇总了Python中zmq.auth方法的典型用法代码示例。如果您正苦于以下问题:Python zmq.auth方法的具体用法?Python zmq.auth怎么用?Python zmq.auth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在zmq的用法示例。


在下文中一共展示了zmq.auth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_null

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import auth [as 别名]
def test_null(self):
        """threaded auth - NULL"""
        # A default NULL connection should always succeed, and not
        # go through our authentication infrastructure at all.
        self.auth.stop()
        self.auth = None
        # use a new context, so ZAP isn't inherited
        self.context = self.Context()
        
        server = self.socket(zmq.PUSH)
        client = self.socket(zmq.PULL)
        self.assertTrue(self.can_connect(server, client))

        # By setting a domain we switch on authentication for NULL sockets,
        # though no policies are configured yet. The client connection
        # should still be allowed.
        server = self.socket(zmq.PUSH)
        server.zap_domain = b'global'
        client = self.socket(zmq.PULL)
        self.assertTrue(self.can_connect(server, client)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:22,代码来源:test_auth.py

示例2: start

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import auth [as 别名]
def start(self):
        """Start the authentication thread"""
        # create a socket to communicate with auth thread.
        self.pipe = self.context.socket(zmq.PAIR)
        self.pipe.linger = 1
        self.pipe.bind(self.pipe_endpoint)
        authenticator = MultiZapAuthenticator(self.context, encoding=self.encoding,
                                              log=self.log)
        self.thread = AuthenticationThread(self.context, self.pipe_endpoint,
                                           encoding=self.encoding, log=self.log,
                                           authenticator=authenticator)
        self.thread.start()
        # Event.wait:Changed in version 2.7: Previously, the method always returned None.
        if sys.version_info < (2, 7):
            self.thread.started.wait(timeout=10)
        else:
            if not self.thread.started.wait(timeout=10):
                raise RuntimeError("Authenticator thread failed to start") 
开发者ID:hyperledger,项目名称:indy-plenum,代码行数:20,代码来源:authenticator.py

示例3: validate_auth_keys

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import auth [as 别名]
def validate_auth_keys(path, extension):
    """
    ### validate_auth_keys

    Validates, and also maintains generated ZMQ CURVE Key-pairs.

    Parameters:
        path (string): path of generated CURVE key-pairs
        extension (string): type of key-pair to be validated

    **Returns:** A  boolean value, confirming whether tests passed, or not?.
    """
    # check for valid path
    if not (os.path.exists(path)):
        return False

    # check if directory empty
    if not (os.listdir(path)):
        return False

    keys_buffer = []  # stores auth-keys

    # loop over auth-keys
    for key_file in os.listdir(path):
        key = os.path.splitext(key_file)
        # check if valid key is generated
        if key and (key[0] in ["server", "client"]) and (key[1] == extension):
            keys_buffer.append(key_file)  # store it

    # remove invalid keys if found
    if len(keys_buffer) == 1:
        os.remove(os.path.join(path, keys_buffer[0]))

    # return results
    return True if (len(keys_buffer) == 2) else False 
开发者ID:abhiTronix,项目名称:vidgear,代码行数:37,代码来源:helper.py

示例4: setUp

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import auth [as 别名]
def setUp(self):
        if zmq.zmq_version_info() < (4,0):
            raise SkipTest("security is new in libzmq 4.0")
        try:
            zmq.curve_keypair()
        except zmq.ZMQError:
            raise SkipTest("security requires libzmq to have curve support")
        super(BaseAuthTestCase, self).setUp()
        # enable debug logging while we run tests
        logging.getLogger('zmq.auth').setLevel(logging.DEBUG)
        self.auth = self.make_auth()
        self.auth.start()
        self.base_dir, self.public_keys_dir, self.secret_keys_dir = self.create_certs() 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:15,代码来源:test_auth.py

示例5: tearDown

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import auth [as 别名]
def tearDown(self):
        if self.auth:
            self.auth.stop()
            self.auth = None
        self.remove_certs(self.base_dir)
        super(BaseAuthTestCase, self).tearDown() 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:8,代码来源:test_auth.py

示例6: create_certs

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import auth [as 别名]
def create_certs(self):
        """Create CURVE certificates for a test"""

        # Create temporary CURVE keypairs for this test run. We create all keys in a
        # temp directory and then move them into the appropriate private or public
        # directory.

        base_dir = tempfile.mkdtemp()
        keys_dir = os.path.join(base_dir, 'certificates')
        public_keys_dir = os.path.join(base_dir, 'public_keys')
        secret_keys_dir = os.path.join(base_dir, 'private_keys')

        os.mkdir(keys_dir)
        os.mkdir(public_keys_dir)
        os.mkdir(secret_keys_dir)

        server_public_file, server_secret_file = zmq.auth.create_certificates(keys_dir, "server")
        client_public_file, client_secret_file = zmq.auth.create_certificates(keys_dir, "client")

        for key_file in os.listdir(keys_dir):
            if key_file.endswith(".key"):
                shutil.move(os.path.join(keys_dir, key_file),
                            os.path.join(public_keys_dir, '.'))

        for key_file in os.listdir(keys_dir):
            if key_file.endswith(".key_secret"):
                shutil.move(os.path.join(keys_dir, key_file),
                            os.path.join(secret_keys_dir, '.'))

        return (base_dir, public_keys_dir, secret_keys_dir) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:32,代码来源:test_auth.py

示例7: load_certs

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import auth [as 别名]
def load_certs(self, secret_keys_dir):
        """Return server and client certificate keys"""
        server_secret_file = os.path.join(secret_keys_dir, "server.key_secret")
        client_secret_file = os.path.join(secret_keys_dir, "client.key_secret")

        server_public, server_secret = zmq.auth.load_certificate(server_secret_file)
        client_public, client_secret = zmq.auth.load_certificate(client_secret_file)

        return server_public, server_secret, client_public, client_secret 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:11,代码来源:test_auth.py

示例8: test_whitelist

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import auth [as 别名]
def test_whitelist(self):
        """threaded auth - Whitelist"""
        # Whitelist 127.0.0.1, connection should pass"
        self.auth.allow('127.0.0.1')
        server = self.socket(zmq.PUSH)
        # By setting a domain we switch on authentication for NULL sockets,
        # though no policies are configured yet.
        server.zap_domain = b'global'
        client = self.socket(zmq.PULL)
        self.assertTrue(self.can_connect(server, client)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:12,代码来源:test_auth.py

示例9: test_plain

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import auth [as 别名]
def test_plain(self):
        """threaded auth - PLAIN"""

        # Try PLAIN authentication - without configuring server, connection should fail
        server = self.socket(zmq.PUSH)
        server.plain_server = True
        client = self.socket(zmq.PULL)
        client.plain_username = b'admin'
        client.plain_password = b'Password'
        self.assertFalse(self.can_connect(server, client))

        # Try PLAIN authentication - with server configured, connection should pass
        server = self.socket(zmq.PUSH)
        server.plain_server = True
        client = self.socket(zmq.PULL)
        client.plain_username = b'admin'
        client.plain_password = b'Password'
        self.auth.configure_plain(domain='*', passwords={'admin': 'Password'})
        self.assertTrue(self.can_connect(server, client))

        # Try PLAIN authentication - with bogus credentials, connection should fail
        server = self.socket(zmq.PUSH)
        server.plain_server = True
        client = self.socket(zmq.PULL)
        client.plain_username = b'admin'
        client.plain_password = b'Bogus'
        self.assertFalse(self.can_connect(server, client))

        # Remove authenticator and check that a normal connection works
        self.auth.stop()
        self.auth = None

        server = self.socket(zmq.PUSH)
        client = self.socket(zmq.PULL)
        self.assertTrue(self.can_connect(server, client))
        client.close()
        server.close() 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:39,代码来源:test_auth.py

示例10: make_auth

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import auth [as 别名]
def make_auth(self):
        from zmq.auth.ioloop import IOLoopAuthenticator
        return IOLoopAuthenticator(self.context, io_loop=self.io_loop) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:5,代码来源:test_auth.py

示例11: test_none

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import auth [as 别名]
def test_none(self):
        """ioloop auth - NONE"""
        # A default NULL connection should always succeed, and not
        # go through our authentication infrastructure at all.
        # no auth should be running
        self.auth.stop()
        self.auth = None 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:9,代码来源:test_auth.py

示例12: test_blacklist

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import auth [as 别名]
def test_blacklist(self):
        """ioloop auth - Blacklist"""
        # Blacklist 127.0.0.1, connection should fail
        self.auth.deny('127.0.0.1')
        self.server.zap_domain = b'global' 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:7,代码来源:test_auth.py

示例13: test_plain_unconfigured_server

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import auth [as 别名]
def test_plain_unconfigured_server(self):
        """ioloop auth - PLAIN, unconfigured server"""
        self.client.plain_username = b'admin'
        self.client.plain_password = b'Password'
        # Try PLAIN authentication - without configuring server, connection should fail
        self.server.plain_server = True 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:8,代码来源:test_auth.py

示例14: test_plain_bogus_credentials

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import auth [as 别名]
def test_plain_bogus_credentials(self):
        """ioloop auth - PLAIN, bogus credentials"""
        self.client.plain_username = b'admin'
        self.client.plain_password = b'Bogus'
        self.server.plain_server = True

        self.auth.configure_plain(domain='*', passwords={'admin': 'Password'}) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:9,代码来源:test_auth.py

示例15: test_curve_unconfigured_server

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import auth [as 别名]
def test_curve_unconfigured_server(self):
        """ioloop auth - CURVE, unconfigured server"""
        certs = self.load_certs(self.secret_keys_dir)
        server_public, server_secret, client_public, client_secret = certs

        self.auth.allow('127.0.0.1')

        self.server.curve_publickey = server_public
        self.server.curve_secretkey = server_secret
        self.server.curve_server = True

        self.client.curve_publickey = client_public
        self.client.curve_secretkey = client_secret
        self.client.curve_serverkey = server_public 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:16,代码来源:test_auth.py


注:本文中的zmq.auth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。