當前位置: 首頁>>代碼示例>>Python>>正文


Python zmq.curve_keypair方法代碼示例

本文整理匯總了Python中zmq.curve_keypair方法的典型用法代碼示例。如果您正苦於以下問題:Python zmq.curve_keypair方法的具體用法?Python zmq.curve_keypair怎麽用?Python zmq.curve_keypair使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在zmq的用法示例。


在下文中一共展示了zmq.curve_keypair方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_certificates

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import curve_keypair [as 別名]
def create_certificates(key_dir, name, metadata=None):
    """Create zmq certificates.
    
    Returns the file paths to the public and secret certificate files.
    """
    public_key, secret_key = zmq.curve_keypair()
    base_filename = os.path.join(key_dir, name)
    secret_key_file = "{0}.key_secret".format(base_filename)
    public_key_file = "{0}.key".format(base_filename)
    now = datetime.datetime.now()

    _write_key_file(public_key_file,
                    _cert_public_banner.format(now),
                    public_key)

    _write_key_file(secret_key_file,
                    _cert_secret_banner.format(now),
                    public_key,
                    secret_key=secret_key,
                    metadata=metadata)

    return public_key_file, secret_key_file 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:24,代碼來源:certs.py

示例2: test_keypair

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import curve_keypair [as 別名]
def test_keypair(self):
        """test curve_keypair"""
        try:
            public, secret = zmq.curve_keypair()
        except zmq.ZMQError:
            raise SkipTest("CURVE unsupported")
        
        self.assertEqual(type(secret), bytes)
        self.assertEqual(type(public), bytes)
        self.assertEqual(len(secret), 40)
        self.assertEqual(len(public), 40)
        
        # verify that it is indeed Z85
        bsecret, bpublic = [ z85.decode(key) for key in (public, secret) ]
        self.assertEqual(type(bsecret), bytes)
        self.assertEqual(type(bpublic), bytes)
        self.assertEqual(len(bsecret), 32)
        self.assertEqual(len(bpublic), 32) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:20,代碼來源:test_security.py

示例3: test_curve_public

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import curve_keypair [as 別名]
def test_curve_public(self):
        """test curve_public"""
        try:
            public, secret = zmq.curve_keypair()
        except zmq.ZMQError:
            raise SkipTest("CURVE unsupported")
        if zmq.zmq_version_info() < (4,2):
            raise SkipTest("curve_public is new in libzmq 4.2")

        derived_public = zmq.curve_public(secret)

        self.assertEqual(type(derived_public), bytes)
        self.assertEqual(len(derived_public), 40)

        # verify that it is indeed Z85
        bpublic = z85.decode(derived_public)
        self.assertEqual(type(bpublic), bytes)
        self.assertEqual(len(bpublic), 32)

        # verify that it is equal to the known public key
        self.assertEqual(derived_public, public) 
開發者ID:luckystarufo,項目名稱:pySINDy,代碼行數:23,代碼來源:test_security.py

示例4: setUp

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import curve_keypair [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 be built with CURVE support")
        super(TestSecurity, self).setUp() 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:10,代碼來源:test_security.py

示例5: test_curve

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import curve_keypair [as 別名]
def test_curve(self):
        """test CURVE encryption"""
        server = self.socket(zmq.DEALER)
        server.identity = b'IDENT'
        client = self.socket(zmq.DEALER)
        self.sockets.extend([server, client])
        try:
            server.curve_server = True
        except zmq.ZMQError as e:
            # will raise EINVAL if no CURVE support
            if e.errno == zmq.EINVAL:
                raise SkipTest("CURVE unsupported")
        
        server_public, server_secret = zmq.curve_keypair()
        client_public, client_secret = zmq.curve_keypair()
        
        server.curve_secretkey = server_secret
        server.curve_publickey = server_public
        client.curve_serverkey = server_public
        client.curve_publickey = client_public
        client.curve_secretkey = client_secret
        
        self.assertEqual(server.mechanism, zmq.CURVE)
        self.assertEqual(client.mechanism, zmq.CURVE)
        
        self.assertEqual(server.get(zmq.CURVE_SERVER), True)
        self.assertEqual(client.get(zmq.CURVE_SERVER), False)

        with self.zap():
            iface = 'tcp://127.0.0.1'
            port = server.bind_to_random_port(iface)
            client.connect("%s:%i" % (iface, port))
            self.bounce(server, client) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:35,代碼來源:test_security.py

示例6: create_zmq_connection

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import curve_keypair [as 別名]
def create_zmq_connection(node, sock_type):
    clientstack = node.clientstack
    sock = zmq.Context().socket(sock_type)
    l_pub_key, l_sec_key = zmq.curve_keypair()
    sock.setsockopt(zmq.IDENTITY, base64.encodebytes(l_pub_key))
    sock.setsockopt(zmq.CURVE_PUBLICKEY, l_pub_key)
    sock.setsockopt(zmq.CURVE_SECRETKEY, l_sec_key)
    sock.setsockopt(zmq.TCP_KEEPALIVE, 1)

    sock.setsockopt(zmq.CURVE_SERVERKEY, clientstack.publicKey)
    sock.connect("tcp://{}:{}".format(clientstack.ha.host, clientstack.ha.port))

    return sock 
開發者ID:hyperledger,項目名稱:indy-plenum,代碼行數:15,代碼來源:helper.py

示例7: check_zmq_connection

# 需要導入模塊: import zmq [as 別名]
# 或者: from zmq import curve_keypair [as 別名]
def check_zmq_connection(addr_port):
    ctx = zmq.Context()
    sock = ctx.socket(zmq.DEALER)
    l_pub_key, l_sec_key = zmq.curve_keypair()
    sock.setsockopt(zmq.IDENTITY, base64.encodebytes(l_pub_key))
    sock.setsockopt(zmq.CURVE_PUBLICKEY, l_pub_key)
    sock.setsockopt(zmq.CURVE_SECRETKEY, l_sec_key)
    dest = get_dest(SERVER_SEED)
    sock.setsockopt(zmq.CURVE_SERVERKEY, z85.encode(ed_25519_pk_to_curve_25519(base58.b58decode(dest))))

    try:
        sock.connect("{}://{}".format(ZMQ_NETWORK_PROTOCOL, addr_port))
        sock.send_string(TEST_MSG)
    except OSError as e:
        print("ZMQ CHECK PHASE::: Cannot connect to {} because\n {}".format(addr_port, e))
        return False

    print("ZMQ CHECK PHASE:::Waiting {} seconds for response from server".format(WAIT_TIMEOUT))

    ready = zmq.select([sock], [], [], WAIT_TIMEOUT)
    if ready[0]:
        reply = sock.recv(flags=zmq.NOBLOCK)
        reply = reply.decode()
        print("ZMQ CHECK PHASE::: Got reply {}".format(reply))

        if reply != EXPECTED_ZMQ_REPLY:
            print("ZMQ CHECK PHASE:::ZMQ connection test failed. \nGot {} \nbut expected reply {}\n".format(reply, EXPECTED_ZMQ_REPLY))
        print("ZMQ CHECK PHASE:::Got expected response")
        return True
    return False 
開發者ID:hyperledger,項目名稱:indy-plenum,代碼行數:32,代碼來源:client.py


注:本文中的zmq.curve_keypair方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。