예제 #1
0
async def test_logout_event():
    s = settings.default()

    server = AuthenticationServer()
    async with rmc.serve(s, [server], HOST, 12345):
        async with rmc.connect(s, HOST, 12345) as client:
            assert not server.flag
        await anyio.sleep(.1)  # Wait a bit
        assert server.flag
예제 #2
0
async def test_simple():
    s = settings.default()

    servers = [AuthenticationServer()]
    async with rmc.serve(s, servers, HOST, 12345):
        async with rmc.connect(s, HOST, 12345) as client:
            assert client.remote_address() == (HOST, 12345)

            auth = authentication.AuthenticationClient(client)
            result = await auth.get_name(12345)
            assert result == "12345"
예제 #3
0
async def test_unimplemented_protocol(anyio_backend):
    s = settings.default()

    servers = []
    async with rmc.serve(s, servers, HOST, 12345):
        async with rmc.connect(s, HOST, 12345) as client:
            assert client.remote_address() == (HOST, 12345)

            auth = authentication.AuthenticationClient(client)
            try:
                result = await auth.get_name(12345)
            except common.RMCError as e:
                assert e.result().name() == "Core::NotImplemented"
예제 #4
0
    async def login(self, username, password=None, auth_info=None, servers=[]):
        if self.settings["nex.version"] < 40000:
            result = await self.login_old(username, auth_info)
        elif self.settings["nex.version"] < 40400:
            result = await self.login_switch(username, auth_info)
        else:
            result = await self.login_with_param(username, auth_info)

        secure_station = result.secure_station

        kerberos_key = result.source_key
        if not kerberos_key:
            if password is None:
                raise ValueError("A password is required for this account")

            # Derive kerberos key from password
            kerberos_key = self.key_derivation.derive_key(
                password.encode(), result.pid)

        # Decrypt ticket from login response
        ticket = kerberos.ClientTicket.decrypt(result.ticket, kerberos_key,
                                               self.settings)
        if ticket.target != secure_station["PID"]:
            # Request ticket for secure server
            response = await self.auth_proto.request_ticket(
                result.pid, secure_station["PID"])

            # Check for errors and decrypt ticket
            response.result.raise_if_error()
            ticket = kerberos.ClientTicket.decrypt(response.ticket,
                                                   kerberos_key, self.settings)

        creds = kerberos.Credentials(ticket, result.pid, secure_station["CID"])

        # The secure server may reside at the same
        # address as the authentication server
        host = secure_station["address"]
        port = secure_station["port"]
        if host == "0.0.0.1":
            host, port = self.auth_host, self.auth_port

        # Connect to secure server
        stream_id = secure_station["sid"]

        context = tls.TLSContext()
        context.load_default_authorities()
        async with rmc.connect(self.settings, host, port, stream_id, context,
                               creds, servers) as client:
            yield client
예제 #5
0
async def connect(settings, host, port):
    context = tls.TLSContext()
    context.load_default_authorities()
    async with rmc.connect(settings, host, port, context=context) as client:
        yield BackEndClient(settings, client, host, port)
예제 #6
0
async def connect(settings, host, port):
    context = tls.TLSContext()
    async with rmc.connect(settings, host, port, context=context) as client:
        yield BackEndClient(settings, client, host, port)