Exemple #1
0
    def _callback():
        try:
            auth = storage.auth = zmq.auth.IOLoopAuthenticator(
                zctx,
                io_loop=storage.ioloop_thread.io_loop
            )
            auth.start()
            auth.configure_plain(domain="*",
                                 passwords=config.get("users", {}))

            socket = zctx.socket(zmq.ROUTER)
            socket.identity = config["identity"].encode("utf-8")
            socket.plain_server = True
            socket.bind(config["bind_address"])

            storage.stream = zmqstream.ZMQStream(
                socket,
                io_loop=storage.ioloop_thread.io_loop
            )
            storage.stream.on_recv(functools.partial(on_router_recv, bot))

            for name, federation in config.get("federations", {}).items():
                if federation.get("autoconnect", False):
                    storage.federations[name] = RequesterConnection(bot, name, federation)
        finally:
            event.set()
Exemple #2
0
def run():
    '''Run woodhouse example'''

    valid_client_test_pass = False
    invalid_client_test_pass = False

    ctx = zmq.Context().instance()

    # Start an authenticator for this context.
    auth = ThreadAuthenticator(ctx)
    auth.start()
    auth.allow('127.0.0.1')
    # Instruct authenticator to handle PLAIN requests
    auth.configure_plain(domain='*', passwords={'admin': 'secret'})

    server = ctx.socket(zmq.PUSH)
    server.plain_server = True  # must come before bind
    server.bind('tcp://*:9000')

    client = ctx.socket(zmq.PULL)
    client.plain_username = b'admin'
    client.plain_password = b'secret'
    client.connect('tcp://127.0.0.1:9000')

    server.send(b"Hello")

    if client.poll():
        msg = client.recv()
        if msg == b"Hello":
            valid_client_test_pass = True

    client.close()


    # now use invalid credentials - expect no msg received
    client2 = ctx.socket(zmq.PULL)
    client2.plain_username = b'admin'
    client2.plain_password = b'bogus'
    client2.connect('tcp://127.0.0.1:9000')

    server.send(b"World")

    if client2.poll(50):
        msg = client.recv()
        if msg == "World":
            invalid_client_test_pass = False
    else:
        # no message is expected
        invalid_client_test_pass = True

    # stop auth thread
    auth.stop()

    if valid_client_test_pass and invalid_client_test_pass:
        logging.info("Woodhouse test OK")
    else:
        logging.error("Woodhouse test FAIL")
Exemple #3
0
def run():
    '''Run woodhouse example'''

    valid_client_test_pass = False
    invalid_client_test_pass = False

    ctx = zmq.Context.instance()

    # Start an authenticator for this context.
    auth = ThreadAuthenticator(ctx)
    auth.start()
    auth.allow('127.0.0.1')
    # Instruct authenticator to handle PLAIN requests
    auth.configure_plain(domain='*', passwords={'admin': 'secret'})

    server = ctx.socket(zmq.PUSH)
    server.plain_server = True  # must come before bind
    server.bind('tcp://*:9000')

    client = ctx.socket(zmq.PULL)
    client.plain_username = b'admin'
    client.plain_password = b'secret'
    client.connect('tcp://127.0.0.1:9000')

    server.send(b"Hello")

    if client.poll():
        msg = client.recv()
        if msg == b"Hello":
            valid_client_test_pass = True

    client.close()

    # now use invalid credentials - expect no msg received
    client2 = ctx.socket(zmq.PULL)
    client2.plain_username = b'admin'
    client2.plain_password = b'bogus'
    client2.connect('tcp://127.0.0.1:9000')

    server.send(b"World")

    if client2.poll(50):
        msg = client.recv()
        if msg == "World":
            invalid_client_test_pass = False
    else:
        # no message is expected
        invalid_client_test_pass = True

    # stop auth thread
    auth.stop()

    if valid_client_test_pass and invalid_client_test_pass:
        logging.info("Woodhouse test OK")
    else:
        logging.error("Woodhouse test FAIL")
Exemple #4
0
    def test_plain(self):
        """test threaded auth - PLAIN"""
        self.auth = auth = zmq.auth.ThreadedAuthenticator(self.context)
        auth.start()

        # 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))
        client.close()
        server.close()

        # 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"
        auth.configure_plain(domain="*", passwords={"admin": "Password"})
        self.assertTrue(self.can_connect(server, client))
        client.close()
        server.close()

        # 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))
        client.close()
        server.close()

        # Remove authenticator and check that a normal connection works
        auth.stop()
        del auth

        server = self.socket(zmq.PUSH)
        client = self.socket(zmq.PULL)
        self.assertTrue(self.can_connect(server, client))
        client.close()
        server.close()
Exemple #5
0
    def test_plain_bogus_credentials(self):
        """test ioloop auth - PLAIN, bogus credentials"""
        self.auth = auth = zmq.auth.IOLoopAuthenticator(self.context, io_loop=self.io_loop)
        auth.start()
        auth.configure_plain(domain="*", passwords={"admin": "Password"})

        self.client.plain_username = b"admin"
        self.client.plain_password = b"Bogus"
        self.pullstream.on_recv(self.on_message_fail)
        # Try PLAIN authentication - with server configured, connection should pass
        self.server.plain_server = True

        t = self.io_loop.time()
        self.io_loop.add_timeout(t + 0.1, self.attempt_connection)
        self.io_loop.add_timeout(t + 0.2, self.send_msg)
        # Timeout the test so the test case can complete even if no message
        # is received.
        self.io_loop.add_timeout(t + 0.5, self.on_test_timeout_succeed)

        self.io_loop.start()

        if not (self.test_result == True):
            self.fail(self.test_result)
Exemple #6
0
    def test_plain_configured_server(self):
        """test ioloop auth - PLAIN, configured server"""
        self.auth = auth = zmq.auth.IOLoopAuthenticator(self.context, io_loop=self.io_loop)
        auth.start()
        auth.configure_plain(domain='*', passwords={'admin': 'Password'})

        self.client.plain_username = b'admin'
        self.client.plain_password = b'Password'
        self.pullstream.on_recv(self.on_message_succeed)
        # Try PLAIN authentication - with server configured, connection should pass
        self.server.plain_server = True

        t = self.io_loop.time()
        self.io_loop.add_timeout(t + .1, self.attempt_connection)
        self.io_loop.add_timeout(t + .2, self.send_msg)
        # Timeout the test so the test case can complete even if no message
        # is received.
        self.io_loop.add_timeout(t + .5, self.on_test_timeout_fail)

        self.io_loop.start()

        if not (self.test_result == True):
            self.fail(self.test_result)
Exemple #7
0
import zmq
import zmq.auth
from zmq.auth.thread import ThreadAuthenticator
context = zmq.Context()
server = context.socket(zmq.REP)

auth = ThreadAuthenticator(context)
auth.start()
auth.allow('127.0.0.1')
auth.configure_plain(domain='*', passwords={'admin': 'password'})
server.plain_server = True
server.setsockopt(zmq.PLAIN_SERVER, 1)
server.connect('tcp://127.0.0.1:5556')

msg = server.recv_string()
server.send(b'Authenticated')

auth.stop()

# Jose Manuel Vidal

import zmq
import zmq.auth
from zmq.auth.thread import ThreadAuthenticator
import os
import sha
import sys

context = zmq.Context()

auth = ThreadAuthenticator(context)
auth.start()
auth.configure_plain(domain='*', passwords=
{
	'admin': 'admin',
	'user': '******'
})

socket = context.socket(zmq.REP)
socket.plain_server = True
socket.bind("tcp://*:5059")

while True:
	try:
		#Leer comando del cliente
		comando = socket.recv()
		
		if comando == 'LS':
			#Listar.
			resultado = ''