Esempio n. 1
0
        public void RadiusClient_MultiPort()
        {
            // Verify that a multiport enable client actually works by running a bunch
            // of authentications throught the client and then counting the number of
            // source UDP ports we received packets from and verifying that this equals
            // the number of client ports requested.

            RadiusServer         server         = new RadiusServer();
            RadiusServerSettings serverSettings = new RadiusServerSettings();
            RadiusClient         client         = new RadiusClient();
            RadiusClientSettings clientSettings = new RadiusClientSettings(Local_RADIUS, "hello");
            RadiusServerDeelie   deelie;

            serverSettings.RealmFormat = RealmFormat.Email;
            serverSettings.Devices.Add(new RadiusNasInfo(IPAddress.Loopback, "hello"));
            serverSettings.Devices.Add(new RadiusNasInfo(NetHelper.GetActiveAdapter(), "hello"));

            clientSettings.RealmFormat      = RealmFormat.Email;
            clientSettings.PortCount        = 5;
            clientSettings.MaxTransmissions = 1;

            try
            {
                server.Start(serverSettings);
                server.LoadAccountsFromString(@"

    // This is a comment line

    r1;jeff;password123
    r2;jeff;passwordXXX
    r1;jane;bigfish
    ");

                client.Open(clientSettings);
                deelie = new RadiusServerDeelie(server, RadiusServerDeelie.Mode.Normal);

                for (int i = 0; i < 555; i++)
                {
                    Assert.IsTrue(client.Authenticate("r1", "jeff", "password123"));
                }

                Dictionary <int, RadiusPacket> packetsByPort = new Dictionary <int, RadiusPacket>();

                foreach (RadiusPacket packet in deelie.Packets)
                {
                    if (!packetsByPort.ContainsKey(packet.SourceEP.Port))
                    {
                        packetsByPort.Add(packet.SourceEP.Port, packet);
                    }
                }

                Assert.AreEqual(5, packetsByPort.Count);
            }
            finally
            {
                server.Stop();
                client.Close();
            }
        }
Esempio n. 2
0
        public void RadiusServer_Bad_NasDevice()
        {
            // Verify that the server detects an unknown NAS device.

            RadiusServer         server         = new RadiusServer();
            RadiusServerSettings serverSettings = new RadiusServerSettings();
            RadiusClient         client         = new RadiusClient();
            RadiusClientSettings clientSettings = new RadiusClientSettings(Local_RADIUS, "hello");
            RadiusServerDeelie   deelie;

            serverSettings.RealmFormat = RealmFormat.Slash;

            clientSettings.RealmFormat      = RealmFormat.Slash;
            clientSettings.PortCount        = 1;
            clientSettings.MaxTransmissions = 1;

            try
            {
                server.Start(serverSettings);
                server.LoadAccountsFromString(@"

    // This is a comment line

    r1;jeff;password123
    r2;jeff;passwordXXX
    r1;jane;bigfish
    ");

                client.Open(clientSettings);
                deelie = new RadiusServerDeelie(server, RadiusServerDeelie.Mode.Normal);

                try
                {
                    client.Authenticate("r1", "jeff", "password123");
                    Assert.Fail("TimeoutException expected");
                }
                catch (TimeoutException)
                {
                    // Expecting a timeout since the server should ignore this packet
                }
                catch (Exception e)
                {
                    Assert.IsInstanceOfType(e, typeof(TimeoutException));
                }

                Assert.IsTrue(deelie.Log.Count > 0);
                Assert.AreEqual(RadiusLogEntryType.UnknownNas, deelie.Log[0].EntryType);
                Assert.IsFalse(deelie.Log[0].Success);
            }
            finally
            {
                server.Stop();
                client.Close();
            }
        }
Esempio n. 3
0
        public void RadiusServer_Auth_Log()
        {
            // Verify that authentication events are logged

            RadiusServer         server         = new RadiusServer();
            RadiusServerSettings serverSettings = new RadiusServerSettings();
            RadiusClient         client         = new RadiusClient();
            RadiusClientSettings clientSettings = new RadiusClientSettings(Local_RADIUS, "hello");
            RadiusServerDeelie   deelie;

            serverSettings.RealmFormat = RealmFormat.Slash;
            serverSettings.Devices.Add(new RadiusNasInfo(IPAddress.Loopback, "hello"));
            serverSettings.Devices.Add(new RadiusNasInfo(NetHelper.GetActiveAdapter(), "hello"));

            clientSettings.RealmFormat      = RealmFormat.Slash;
            clientSettings.PortCount        = 1;
            clientSettings.MaxTransmissions = 1;

            try
            {
                server.Start(serverSettings);
                server.LoadAccountsFromString(@"

    // This is a comment line

    r1;jeff;password123
    r2;jeff;passwordXXX
    r1;jane;bigfish
    ");

                client.Open(clientSettings);
                deelie = new RadiusServerDeelie(server, RadiusServerDeelie.Mode.Normal);

                Assert.IsTrue(client.Authenticate("r1", "jeff", "password123"));
                Assert.IsFalse(client.Authenticate("r1", "jeff", "PASSWORD123"));

                Assert.AreEqual(2, deelie.Log.Count);

                Assert.IsTrue(deelie.Log[0].Success);
                Assert.AreEqual(RadiusLogEntryType.Authentication, deelie.Log[0].EntryType);
                Assert.AreEqual("r1", deelie.Log[0].Realm);
                Assert.AreEqual("jeff", deelie.Log[0].Account);

                Assert.IsFalse(deelie.Log[1].Success);
                Assert.AreEqual(RadiusLogEntryType.Authentication, deelie.Log[1].EntryType);
                Assert.AreEqual("r1", deelie.Log[1].Realm);
                Assert.AreEqual("jeff", deelie.Log[1].Account);
            }
            finally
            {
                server.Stop();
                client.Close();
            }
        }
Esempio n. 4
0
        public void RadiusClient_ID_WrapAround()
        {
            // Verify that a single port client instance will wrap request IDs
            // properly after ID=255

            RadiusServer         server         = new RadiusServer();
            RadiusServerSettings serverSettings = new RadiusServerSettings();
            RadiusClient         client         = new RadiusClient();
            RadiusClientSettings clientSettings = new RadiusClientSettings(Local_RADIUS, "hello");
            RadiusServerDeelie   deelie;

            serverSettings.RealmFormat = RealmFormat.Email;
            serverSettings.Devices.Add(new RadiusNasInfo(IPAddress.Loopback, "hello"));
            serverSettings.Devices.Add(new RadiusNasInfo(NetHelper.GetActiveAdapter(), "hello"));

            clientSettings.RealmFormat      = RealmFormat.Email;
            clientSettings.PortCount        = 1;
            clientSettings.MaxTransmissions = 1;

            try
            {
                server.Start(serverSettings);
                server.LoadAccountsFromString(@"

    // This is a comment line

    r1;jeff;password123
    r2;jeff;passwordXXX
    r1;jane;bigfish
    ");

                client.Open(clientSettings);
                deelie = new RadiusServerDeelie(server, RadiusServerDeelie.Mode.Normal);

                for (int i = 0; i < 555; i++)
                {
                    Assert.IsTrue(client.Authenticate("r1", "jeff", "password123"));
                }

                // We should have 555 packets in the deelie with ordered IDs.

                Assert.AreEqual(555, deelie.Packets.Count);
                for (int i = 0; i < 555; i++)
                {
                    Assert.AreEqual((byte)i, deelie.Packets[i].Identifier);
                }
            }
            finally
            {
                server.Stop();
                client.Close();
            }
        }
Esempio n. 5
0
        public void RadiusServer_Auth_Parallel_Delay()
        {
            // Verify that we can perform multiple parallel authentications with
            // a brief delay.

            RadiusServer         server         = new RadiusServer();
            RadiusServerSettings serverSettings = new RadiusServerSettings();
            RadiusClient         client         = new RadiusClient();
            RadiusClientSettings clientSettings = new RadiusClientSettings(Local_RADIUS, "hello");

            IAsyncResult[]     ar = new IAsyncResult[255];
            RadiusServerDeelie deelie;

            serverSettings.RealmFormat = RealmFormat.Slash;
            serverSettings.Devices.Add(new RadiusNasInfo(IPAddress.Loopback, "hello"));
            serverSettings.Devices.Add(new RadiusNasInfo(NetHelper.GetActiveAdapter(), "hello"));

            clientSettings.RealmFormat      = RealmFormat.Slash;
            clientSettings.PortCount        = 1;
            clientSettings.MaxTransmissions = 1;

            try
            {
                server.Start(serverSettings);
                server.LoadAccountsFromString(@"

    // This is a comment line

    r1;jeff;password123
    r2;jeff;passwordXXX
    r1;jane;bigfish
    ");

                client.Open(clientSettings);
                deelie = new RadiusServerDeelie(server, RadiusServerDeelie.Mode.AuthShortDelay);

                for (int i = 0; i < ar.Length; i++)
                {
                    ar[i] = client.BeginAuthenticate("r1", "jeff", "password123", null, null);
                }

                for (int i = 0; i < ar.Length; i++)
                {
                    Assert.IsTrue(client.EndAuthenticate(ar[i]));
                }
            }
            finally
            {
                server.Stop();
                client.Close();
            }
        }
Esempio n. 6
0
        public void RadiusClient_Timeout()
        {
            // Verify that the client detects timeouts.

            RadiusServer         server         = new RadiusServer();
            RadiusServerSettings serverSettings = new RadiusServerSettings();
            RadiusClient         client         = new RadiusClient();
            RadiusClientSettings clientSettings = new RadiusClientSettings(Local_RADIUS, "hello");
            RadiusServerDeelie   deelie;

            serverSettings.RealmFormat = RealmFormat.Email;
            serverSettings.Devices.Add(new RadiusNasInfo(IPAddress.Loopback, "hello"));
            serverSettings.Devices.Add(new RadiusNasInfo(NetHelper.GetActiveAdapter(), "hello"));

            clientSettings.RealmFormat      = RealmFormat.Email;
            clientSettings.PortCount        = 1;
            clientSettings.MaxTransmissions = 1;

            try
            {
                server.Start(serverSettings);
                server.LoadAccountsFromString(@"

    // This is a comment line

    r1;jeff;password123
    r2;jeff;passwordXXX
    r1;jane;bigfish
    ");

                client.Open(clientSettings);
                deelie = new RadiusServerDeelie(server, RadiusServerDeelie.Mode.IgnoreAllPackets);

                try
                {
                    client.Authenticate("r1", "jeff", "password123");
                    Assert.Fail("Expected a timeout");
                }
                catch (Exception e)
                {
                    Assert.IsInstanceOfType(e, typeof(TimeoutException));
                }
            }
            finally
            {
                server.Stop();
                client.Close();
            }
        }
Esempio n. 7
0
        public void RadiusClient_Retry()
        {
            // Verify that the client actually retries sending request packets and
            // that it used the same ID for both.

            RadiusServer         server         = new RadiusServer();
            RadiusServerSettings serverSettings = new RadiusServerSettings();
            RadiusClient         client         = new RadiusClient();
            RadiusClientSettings clientSettings = new RadiusClientSettings(Local_RADIUS, "hello");
            RadiusServerDeelie   deelie;

            serverSettings.RealmFormat = RealmFormat.Email;
            serverSettings.Devices.Add(new RadiusNasInfo(IPAddress.Loopback, "hello"));
            serverSettings.Devices.Add(new RadiusNasInfo(NetHelper.GetActiveAdapter(), "hello"));

            clientSettings.RealmFormat      = RealmFormat.Email;
            clientSettings.PortCount        = 1;
            clientSettings.MaxTransmissions = 2;

            try
            {
                server.Start(serverSettings);
                server.LoadAccountsFromString(@"

    // This is a comment line

    r1;jeff;password123
    r2;jeff;passwordXXX
    r1;jane;bigfish
    ");

                client.Open(clientSettings);
                deelie = new RadiusServerDeelie(server, RadiusServerDeelie.Mode.IgnoreFirstPacket);

                Assert.IsTrue(client.Authenticate("r1", "jeff", "password123"));
                Assert.AreEqual(2, deelie.Packets.Count);
                Assert.AreEqual(deelie.Packets[0].Identifier, deelie.Packets[1].Identifier);
            }
            finally
            {
                server.Stop();
                client.Close();
            }
        }
Esempio n. 8
0
        public void RadiusClient_Blast()
        {
            // Send a bunch of queries to multiple servers from multiple client ports.

            RadiusServer         server1         = new RadiusServer();
            RadiusServer         server2         = new RadiusServer();
            RadiusServerSettings server1Settings = new RadiusServerSettings();
            RadiusServerSettings server2Settings = new RadiusServerSettings();
            RadiusClient         client          = new RadiusClient();
            RadiusClientSettings clientSettings  = new RadiusClientSettings(new NetworkBinding[] { Local_RADIUS, Local_AAA }, "hello");
            RadiusServerDeelie   deelie1;
            RadiusServerDeelie   deelie2;

            IAsyncResult[] ar;

            server1Settings.RealmFormat = RealmFormat.Email;
            server1Settings.Devices.Add(new RadiusNasInfo(IPAddress.Loopback, "hello"));
            server1Settings.Devices.Add(new RadiusNasInfo(NetHelper.GetActiveAdapter(), "hello"));
            server1Settings.NetworkBinding = new IPEndPoint(IPAddress.Any, NetworkPort.RADIUS);

            server2Settings.RealmFormat = RealmFormat.Email;
            server2Settings.Devices.Add(new RadiusNasInfo(IPAddress.Loopback, "hello"));
            server2Settings.Devices.Add(new RadiusNasInfo(NetHelper.GetActiveAdapter(), "hello"));
            server2Settings.NetworkBinding = new IPEndPoint(IPAddress.Any, NetworkPort.AAA);

            clientSettings.RealmFormat      = RealmFormat.Email;
            clientSettings.PortCount        = 4;
            clientSettings.MaxTransmissions = 3;

            try
            {
                string accountInfo = @"

    // This is a comment line

    r1;jeff;password123
    r2;jeff;passwordXXX
    r1;jane;bigfish
    ";
                server1.Start(server1Settings);
                server1.LoadAccountsFromString(accountInfo);
                deelie1 = new RadiusServerDeelie(server1, RadiusServerDeelie.Mode.Normal);

                server2.Start(server2Settings);
                server2.LoadAccountsFromString(accountInfo);
                deelie2 = new RadiusServerDeelie(server2, RadiusServerDeelie.Mode.Normal);

                client.Open(clientSettings);

                ar = new IAsyncResult[clientSettings.PortCount * 256];
                for (int i = 0; i < ar.Length; i++)
                {
                    ar[i] = client.BeginAuthenticate("r1", "jeff", "password123", null, null);
                }

                for (int i = 0; i < ar.Length; i++)
                {
                    Assert.IsTrue(client.EndAuthenticate(ar[i]));
                }

                Assert.IsTrue(deelie1.Packets.Count > 0);
                Assert.IsTrue(deelie2.Packets.Count > 0);
            }
            finally
            {
                server1.Stop();
                server2.Stop();
                client.Close();
            }
        }
Esempio n. 9
0
        public void RadiusClient_FailOver_MultiPort()
        {
            // Verify that the client actually fails over to alternate
            // RADIUS servers with a multi port client.

            RadiusServer         server1         = new RadiusServer();
            RadiusServer         server2         = new RadiusServer();
            RadiusServerSettings server1Settings = new RadiusServerSettings();
            RadiusServerSettings server2Settings = new RadiusServerSettings();
            RadiusClient         client          = new RadiusClient();
            RadiusClientSettings clientSettings  = new RadiusClientSettings(new NetworkBinding[] { Local_AAA, NetworkBinding.Parse("192.168.255.1:1645") }, "hello");
            RadiusServerDeelie   deelie1;
            RadiusServerDeelie   deelie2;

            server1Settings.RealmFormat = RealmFormat.Email;
            server1Settings.Devices.Add(new RadiusNasInfo(IPAddress.Loopback, "hello"));
            server1Settings.Devices.Add(new RadiusNasInfo(NetHelper.GetActiveAdapter(), "hello"));
            server1Settings.NetworkBinding = new IPEndPoint(IPAddress.Any, NetworkPort.RADIUS);

            server2Settings.RealmFormat = RealmFormat.Email;
            server2Settings.Devices.Add(new RadiusNasInfo(IPAddress.Loopback, "hello"));
            server2Settings.Devices.Add(new RadiusNasInfo(NetHelper.GetActiveAdapter(), "hello"));
            server2Settings.NetworkBinding = new IPEndPoint(IPAddress.Any, NetworkPort.AAA);

            clientSettings.RealmFormat      = RealmFormat.Email;
            clientSettings.PortCount        = 4;
            clientSettings.MaxTransmissions = 10;
            clientSettings.RetryInterval    = TimeSpan.FromSeconds(0.5);

            try
            {
                string accountInfo = @"

    // This is a comment line

    r1;jeff;password123
    r2;jeff;passwordXXX
    r1;jane;bigfish
    ";
                server1.Start(server1Settings);
                server1.LoadAccountsFromString(accountInfo);
                deelie1 = new RadiusServerDeelie(server1, RadiusServerDeelie.Mode.IgnoreAlternatePackets);

                server2.Start(server2Settings);
                server2.LoadAccountsFromString(accountInfo);
                deelie2 = new RadiusServerDeelie(server2, RadiusServerDeelie.Mode.IgnoreAlternatePackets);

                client.Open(clientSettings);

                for (int i = 0; i < 10; i++)
                {
                    Assert.IsTrue(client.Authenticate("r1", "jeff", "password123"));
                }
            }
            finally
            {
                server1.Stop();
                server2.Stop();
                client.Close();
            }
        }
Esempio n. 10
0
        public void RadiusClient_LoadBalance_MultiPort()
        {
            // Verify that the client actually distributes packets across multiple
            // RADIUS servers with a multi port client.

            RadiusServer         server1         = new RadiusServer();
            RadiusServer         server2         = new RadiusServer();
            RadiusServerSettings server1Settings = new RadiusServerSettings();
            RadiusServerSettings server2Settings = new RadiusServerSettings();
            RadiusClient         client          = new RadiusClient();
            RadiusClientSettings clientSettings  = new RadiusClientSettings(new NetworkBinding[] { Local_RADIUS, Local_AAA }, "hello");
            RadiusServerDeelie   deelie1;
            RadiusServerDeelie   deelie2;

            server1Settings.RealmFormat = RealmFormat.Email;
            server1Settings.Devices.Add(new RadiusNasInfo(IPAddress.Loopback, "hello"));
            server1Settings.Devices.Add(new RadiusNasInfo(NetHelper.GetActiveAdapter(), "hello"));
            server1Settings.NetworkBinding = new IPEndPoint(IPAddress.Any, NetworkPort.RADIUS);

            server2Settings.RealmFormat = RealmFormat.Email;
            server2Settings.Devices.Add(new RadiusNasInfo(IPAddress.Loopback, "hello"));
            server2Settings.Devices.Add(new RadiusNasInfo(NetHelper.GetActiveAdapter(), "hello"));
            server2Settings.NetworkBinding = new IPEndPoint(IPAddress.Any, NetworkPort.AAA);

            clientSettings.RealmFormat      = RealmFormat.Email;
            clientSettings.PortCount        = 4;
            clientSettings.MaxTransmissions = 1;

            try
            {
                string accountInfo = @"

    // This is a comment line

    r1;jeff;password123
    r2;jeff;passwordXXX
    r1;jane;bigfish
    ";
                server1.Start(server1Settings);
                server1.LoadAccountsFromString(accountInfo);
                deelie1 = new RadiusServerDeelie(server1, RadiusServerDeelie.Mode.Normal);

                server2.Start(server2Settings);
                server2.LoadAccountsFromString(accountInfo);
                deelie2 = new RadiusServerDeelie(server2, RadiusServerDeelie.Mode.Normal);

                client.Open(clientSettings);

                for (int i = 0; i < 20; i++)
                {
                    Assert.IsTrue(client.Authenticate("r1", "jeff", "password123"));
                }

                Assert.IsTrue(deelie1.Packets.Count > 0);
                Assert.IsTrue(deelie2.Packets.Count > 0);
            }
            finally
            {
                server1.Stop();
                server2.Stop();
                client.Close();
            }
        }
Esempio n. 11
0
        public void RadiusClient_ID_Exhaustion_MultiPort()
        {
            // Verify that the client throws an exception when it is asked to
            // manage more than 256 parallel authentication requests.

            RadiusServer         server         = new RadiusServer();
            RadiusServerSettings serverSettings = new RadiusServerSettings();
            RadiusClient         client         = new RadiusClient();
            RadiusClientSettings clientSettings = new RadiusClientSettings(Local_RADIUS, "hello");
            RadiusServerDeelie   deelie;

            IAsyncResult[] ar;

            serverSettings.RealmFormat = RealmFormat.Email;
            serverSettings.Devices.Add(new RadiusNasInfo(IPAddress.Loopback, "hello"));
            serverSettings.Devices.Add(new RadiusNasInfo(NetHelper.GetActiveAdapter(), "hello"));

            clientSettings.RealmFormat      = RealmFormat.Email;
            clientSettings.PortCount        = 2;
            clientSettings.MaxTransmissions = 1;

            try
            {
                server.Start(serverSettings);
                server.LoadAccountsFromString(@"

    // This is a comment line

    r1;jeff;password123
    r2;jeff;passwordXXX
    r1;jane;bigfish
    ");

                client.Open(clientSettings);
                deelie = new RadiusServerDeelie(server, RadiusServerDeelie.Mode.AuthLongDelay);

                ar = new IAsyncResult[clientSettings.PortCount * 256 + 1];

                try
                {
                    for (int i = 0; i < ar.Length; i++)
                    {
                        ar[i] = client.BeginAuthenticate("r1", "jeff", "password123", null, null);
                    }

                    for (int i = 0; i < ar.Length; i++)
                    {
                        if (ar[i] != null)
                        {
                            client.EndAuthenticate(ar[i]);
                        }
                    }

                    Assert.Fail("Expected a RadiusException");
                }
                catch (Exception e)
                {
                    Assert.IsInstanceOfType(e, typeof(RadiusException));
                }
            }
            finally
            {
                server.Stop();
                client.Close();
            }
        }