示例#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);
        }
示例#2
0
        /**
         * Returns the socket used for the server communication. It is
         * bound to an arbitrary free local port number.
         * @return local socket
         * @throws SocketException
         */

        /**
         * Creates a datagram packet from a RadiusPacket to be send. 
         * @param packet RadiusPacket
         * @param port destination port number
         * @return new datagram packet
         * @throws IOException
         */

        protected byte[] MakeDatagramPacket(RadiusPacket packet)
        {
            using (var bos = new MemoryStream())
            {
                packet.EncodeRequestPacket(bos, SharedSecret);
                byte[] data = bos.ToArray();
                bos.Close();
                bos.Dispose();
                return data;
            }
        }