Ejemplo n.º 1
0
        /**
         * Proxies the given packet to the server given in the Proxy connection.
         * Stores the Proxy connection object in the cache with a key that
         * is added to the packet in the "Proxy-State" attribute.
         * @param packet the packet to Proxy
         * @param proxyCon the RadiusProxyConnection for this packet
         * @throws IOException
         */

        protected void proxyPacket(RadiusPacket packet, RadiusProxyConnection proxyConnection)
        {
            lock (typeof(RadiusProxy))
            {
                // add Proxy-State attribute
                proxyIndex++;
                String proxyIndexStr = proxyIndex.ToString();
                packet.AddAttribute(new RadiusAttribute(33, Encoding.UTF8.GetBytes(proxyIndexStr)));

                // store RadiusProxyConnection object
                proxyConnections.Add(proxyIndexStr, proxyConnection);
            }

            // get server address
            //IPAddress serverAddress = proxyConnection.getRadiusServer().EndpointAddress.Address;
            //int serverPort = proxyConnection.getRadiusServer().EndpointAddress.Port;
            String serverSecret = proxyConnection.RadiusServer.SharedSecret;

            // save request authenticator (will be calculated new)
            byte[] auth = packet.Authenticator;

            // encode new packet (with new authenticator)
            var bos = new MemoryStream();

            packet.EncodeRequestPacket(bos, serverSecret);
            byte[] data = bos.ToArray();
            bos.Dispose();


            //var datagram = new DatagramPacket(data, data.Length, serverAddress, serverPort);

            // restore original authenticator
            packet.Authenticator = auth;

            // send packet
            //Socket proxySocket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.IP);
            proxySocket.Send(data, data.Length);
            //proxySocket.send(datagram);
        }
        public void TestCreatingAndParsingPacket()
        {
            var secret = "xyzzy5461";

            var dictionary = GetDictionary();

            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 testPacket = RadiusPacket.Parse(packet.GetBytes(dictionary), dictionary, 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(100, testPacket.GetAttribute <UInt32>("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"));
        }
Ejemplo n.º 3
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"));
        }