public void TestStatusServerAccountingResponsePacket()
        {
            var request  = "0cb30026925f6b66dd5fed571fcb1db7ad3882605012e8d6eabda910875cd91fdade26367858";
            var expected = "05b300140f6f92145f107e2f504e860a4860669c";  // Note the error in the RFC. First byte should be 05 not 02
            var secret   = "xyzzy5461";

            var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary());
            var rs       = new RadiusServer(new UdpClientFactory(), new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1812), radiusPacketParser, RadiusServerType.Accounting, NullLogger <RadiusServer> .Instance);
            var response = rs.GetResponsePacket(new MockPacketHandler(), secret, Utils.StringToByteArray(request), new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1813));

            Assert.AreEqual(expected, radiusPacketParser.GetBytes(response).ToHexString());
        }
        public void TestResponsePacket()
        {
            var request  = "010000380f403f9473978057bd83d5cb98f4227a01066e656d6f02120dbe708d93d413ce3196e43f782a0aee0406c0a80110050600000003";
            var expected = "0200002686fe220e7624ba2a1005f6bf9b55e0b20606000000010f06000000000e06c0a80103";
            var secret   = "xyzzy5461";

            var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary());
            var rs       = new RadiusServer(new UdpClientFactory(), new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1812), radiusPacketParser, RadiusServerType.Authentication, NullLogger <RadiusServer> .Instance);
            var response = rs.GetResponsePacket(new MockPacketHandler(), secret, Utils.StringToByteArray(request), new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1813));

            Assert.AreEqual(expected, radiusPacketParser.GetBytes(response).ToHexString());
        }
        public void TestStatusServerAuthenticationResponsePacket()
        {
            var request  = "0cda00268a54f4686fb394c52866e302185d062350125a665e2e1e8411f3e243822097c84fa3";
            var expected = "02da0014ef0d552a4bf2d693ec2b6fe8b5411d66";
            var secret   = "xyzzy5461";

            var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary());
            var rs       = new RadiusServer(new UdpClientFactory(), new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1812), radiusPacketParser, RadiusServerType.Authentication, NullLogger <RadiusServer> .Instance);
            var response = rs.GetResponsePacket(new MockPacketHandler(), secret, Utils.StringToByteArray(request), new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1813));

            Assert.AreEqual(expected, radiusPacketParser.GetBytes(response).ToHexString());
        }
        public void TestResponsePacketWithProxyStateMiddle()
        {
            var request  = "010000420f403f9473978057bd83d5cb98f4227a01066e656d6f02120dbe708d93d413ce3196e43f782a0aee0406c0a8011021053135342105323330050600000003";
            var expected = "02000030acf049cee1a3ed134316e5b3348cdf3c0606000000010f06000000000e06c0a8010321053135342105323330";
            var secret   = "xyzzy5461";

            var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary());
            var rs       = new RadiusServer(new UdpClientFactory(), new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1812), radiusPacketParser, RadiusServerType.Authentication, NullLogger <RadiusServer> .Instance);
            var response = rs.GetResponsePacket(new MockPacketHandler(), secret, Utils.StringToByteArray(request), new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1813));

            Assert.AreEqual(expected, radiusPacketParser.GetBytes(response).ToHexString());
        }
Ejemplo n.º 5
0
        public void TestCreateDisconnectRequestPacket()
        {
            var expected = "2801001e2ec8a0da729620319be0140bc28e92682c0a3039303432414638";
            var secret   = "xyzzy5461";

            var packet = new RadiusPacket(PacketCode.DisconnectRequest, 1, secret);

            packet.AddAttribute("Acct-Session-Id", "09042AF8");

            var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary());

            Assert.AreEqual(expected, radiusPacketParser.GetBytes(packet).ToHexString());
        }
Ejemplo n.º 6
0
        public void TestPacketParserAndAssemblerExtraDataIgnored()
        {
            var request  = "0cda00268a54f4686fb394c52866e302185d062350125a665e2e1e8411f3e243822097c84fa300ff00ff00ff";
            var expected = "0cda00268a54f4686fb394c52866e302185d062350125a665e2e1e8411f3e243822097c84fa3";
            var secret   = "xyzzy5461";


            var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary());
            var requestPacket      = radiusPacketParser.Parse(Utils.StringToByteArray(request), Encoding.UTF8.GetBytes(secret));
            var bytes = radiusPacketParser.GetBytes(requestPacket);

            Assert.AreEqual(expected, bytes.ToHexString());
        }
Ejemplo n.º 7
0
        public void TestPacketParserAndAssemblerStreamExtraDataIgnored()
        {
            var request  = "0cda00268a54f4686fb394c52866e302185d062350125a665e2e1e8411f3e243822097c84fa3ff00ff00ff00ff";
            var expected = "0cda00268a54f4686fb394c52866e302185d062350125a665e2e1e8411f3e243822097c84fa3";
            var secret   = Encoding.UTF8.GetBytes("xyzzy5461");

            var stream             = new MemoryStream(Utils.StringToByteArray(request));
            var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary());
            var result             = radiusPacketParser.TryParsePacketFromStream(stream, out var packet, secret);
            var bytes = radiusPacketParser.GetBytes(packet);

            Assert.AreEqual(expected, bytes.ToHexString());
        }
Ejemplo n.º 8
0
        public void TestCreateStatusServerRequestPacketAccounting()
        {
            var expected = "0cb30026925f6b66dd5fed571fcb1db7ad3882605012e8d6eabda910875cd91fdade26367858";
            var secret   = "xyzzy5461";

            var packet = new RadiusPacket(PacketCode.StatusServer, 179, secret);

            packet.Authenticator = Utils.StringToByteArray("925f6b66dd5fed571fcb1db7ad388260");

            var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary());

            Assert.AreEqual(expected, radiusPacketParser.GetBytes(packet).ToHexString());
        }
Ejemplo n.º 9
0
        public void TestCreateStatusServerRequestPacket()
        {
            var expected = "0cda00268a54f4686fb394c52866e302185d062350125a665e2e1e8411f3e243822097c84fa3";
            var secret   = "xyzzy5461";

            var packet = new RadiusPacket(PacketCode.StatusServer, 218, secret);

            packet.Authenticator = Utils.StringToByteArray("8a54f4686fb394c52866e302185d0623");

            var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary());

            Assert.AreEqual(expected, radiusPacketParser.GetBytes(packet).ToHexString());
        }
Ejemplo n.º 10
0
        public void TestCreatingMissingAttributes()
        {
            var secret = "xyzzy5461";

            var packet = new RadiusPacket(PacketCode.AccessRequest, 1, secret);

            packet.AddAttribute("User-Name", "*****@*****.**");
            packet.AddAttribute("User-Password", "test");

            var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary());
            var testPacket         = radiusPacketParser.Parse(radiusPacketParser.GetBytes(packet), Encoding.UTF8.GetBytes(secret));

            Assert.IsNull(testPacket.GetAttribute <uint?>("NAS-Port"));
            Assert.AreEqual(0, testPacket.GetAttributes <uint>("NAS-Port").Count);
        }
Ejemplo n.º 11
0
        public void TestCreateAndParseAccountingRequestPacket()
        {
            var secret     = "xyzzy5461";
            var dictionary = GetDictionary();
            var packet     = new RadiusPacket(PacketCode.AccountingRequest, 0, secret);

            packet.AddAttribute("User-Name", "nemo");
            packet.AddAttribute("Acct-Status-Type", 2);
            packet.AddAttribute("NAS-IP-Address", IPAddress.Parse("192.168.1.16"));
            packet.AddAttribute("NAS-Port", 3);

            var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary());
            var bytes = radiusPacketParser.GetBytes(packet);
            var derp  = radiusPacketParser.Parse(bytes, Encoding.UTF8.GetBytes(secret));
        }
Ejemplo n.º 12
0
        public void TestCreateCoARequestPacket()
        {
            var expected = "2b0000266613591d86e32fa6dbae94f13772573601066e656d6f0406c0a80110050600000003";
            var secret   = "xyzzy5461";

            var packet = new RadiusPacket(PacketCode.CoaRequest, 0, secret);

            packet.Authenticator = Utils.StringToByteArray("0f403f9473978057bd83d5cb98f4227a");
            packet.AddAttribute("User-Name", "nemo");
            packet.AddAttribute("NAS-IP-Address", IPAddress.Parse("192.168.1.16"));
            packet.AddAttribute("NAS-Port", 3);

            var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary());

            Assert.AreEqual(expected, radiusPacketParser.GetBytes(packet).ToHexString());
        }
Ejemplo n.º 13
0
        public void TestMessageAuthenticatorResponsePacket()
        {
            var expected = "0368002c71624da25c0b5897f70539e019a81eae4f06046700045012ce70fe87a997b44de583cd19bea29321";
            var secret   = "testing123";

            var response = new RadiusPacket(PacketCode.AccessReject, 104, secret)
            {
                RequestAuthenticator = Utils.StringToByteArray("b3e22ff855a690280e6c3444c46e663b")
            };

            response.AddAttribute("EAP-Message", Utils.StringToByteArray("04670004"));
            response.AddAttribute("Message-Authenticator", new byte[16]);

            var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary());

            Assert.AreEqual(expected, radiusPacketParser.GetBytes(response).ToHexString());
        }
Ejemplo n.º 14
0
        public void TestCreateAccessRequestPacket()
        {
            var expected = "010000380f403f9473978057bd83d5cb98f4227a01066e656d6f02120dbe708d93d413ce3196e43f782a0aee0406c0a80110050600000003";
            var secret   = "xyzzy5461";

            var packet = new RadiusPacket(PacketCode.AccessRequest, 0, secret);

            packet.Authenticator = Utils.StringToByteArray("0f403f9473978057bd83d5cb98f4227a");
            packet.AddAttribute("User-Name", "nemo");
            packet.AddAttribute("User-Password", "arctangent");
            packet.AddAttribute("NAS-IP-Address", IPAddress.Parse("192.168.1.16"));
            packet.AddAttribute("NAS-Port", 3);

            var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary());

            Assert.AreEqual(expected, radiusPacketParser.GetBytes(packet).ToHexString());
        }
Ejemplo n.º 15
0
        public void TestCreateAccessRequestPacketUnknownAttribute()
        {
            var secret = "xyzzy5461";

            var packet = new RadiusPacket(PacketCode.AccessRequest, 0, secret);

            packet.Authenticator = Utils.StringToByteArray("0f403f9473978057bd83d5cb98f4227a");
            packet.AddAttribute("User-Name", "nemo");
            packet.AddAttribute("hurr", "durr");
            packet.AddAttribute("User-Password", "arctangent");
            packet.AddAttribute("NAS-IP-Address", IPAddress.Parse("192.168.1.16"));
            packet.AddAttribute("NAS-Port", 3);

            var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary());

            Assert.That(() => radiusPacketParser.GetBytes(packet),
                        Throws.TypeOf <InvalidOperationException>());
        }
Ejemplo n.º 16
0
        public void TestCreatingAndParsingPacket()
        {
            var secret = "xyzzy5461";

            var packet = new RadiusPacket(PacketCode.AccessRequest, 1, secret);

            packet.AddAttribute("User-Name", "*****@*****.**");
            packet.AddAttribute("User-Password", "test");
            packet.AddAttribute("NAS-IP-Address", IPAddress.Parse("127.0.0.1"));
            packet.AddAttribute("NAS-Port", 100);
            packet.AddAttribute("3GPP-IMSI-MCC-MNC", "24001");
            packet.AddAttribute("3GPP-CG-Address", IPAddress.Parse("127.0.0.1"));

            var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary());
            var testPacket         = radiusPacketParser.Parse(radiusPacketParser.GetBytes(packet), Encoding.UTF8.GetBytes(secret));

            Assert.AreEqual("*****@*****.**", testPacket.GetAttribute <string>("User-Name"));
            Assert.AreEqual("test", testPacket.GetAttribute <string>("User-Password"));
            Assert.AreEqual(IPAddress.Parse("127.0.0.1"), testPacket.GetAttribute <IPAddress>("NAS-IP-Address"));
            Assert.AreEqual(IPAddress.Parse("127.0.0.1"), testPacket.GetAttributes <IPAddress>("NAS-IP-Address").First());   // this should actually be tested with EAP-Message attributes
            Assert.AreEqual(100, testPacket.GetAttribute <uint>("NAS-Port"));
            Assert.AreEqual("24001", testPacket.GetAttribute <string>("3GPP-IMSI-MCC-MNC"));
            Assert.AreEqual(IPAddress.Parse("127.0.0.1"), testPacket.GetAttribute <IPAddress>("3GPP-CG-Address"));
        }