當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。