Example #1
0
        public RadiusPacket SendAndReceivePacket(RadiusPacket packet, int retries)
        {
            IPEndPoint RemoteIpEndPoint = null;

            for (int x = 0; x < retries; x++)
            {
                var dt = DateTime.UtcNow;
                using (RadiusUdpClient udpClient = new RadiusUdpClient())
                {
                    udpClient.Connect(this.hostName, this.authPort);
                    udpClient.SetTimeout(this.socketTimeout);
                    Byte[] packetBinary = packet.GetBytes();
                    udpClient.Send(packetBinary, packetBinary.Length);
                    Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
                    if (receiveBytes != null)
                    {
                        RadiusPacket receivedPacket = new RadiusPacket(receiveBytes, this.sharedSecret, packet.Authenticator);
                        if (VerifyPacket(packet, receivedPacket))
                        {
                            return(receivedPacket);
                        }
                    }
                }
            }
            return(null);
        }
Example #2
0
        static void Main(string[] args)
        {
            if (args.Length != 4)
            {
                ShowUsage();
                return;
            }
            try {
                RadiusClient rc             = new RadiusClient(args[0], args[1]);
                RadiusPacket authPacket     = rc.Authenticate(args[2], args[3]);
                RadiusPacket receivedPacket = rc.SendAndReceivePacket(authPacket);
                if (receivedPacket == null)
                {
                    throw new Exception("Can't contact remote radius server !");
                }
                switch (receivedPacket.Type)
                {
                case RadiusPacketType.ACCESS_ACCEPT:
                    Console.WriteLine("accepted");
                    foreach (RadiusAttribute attr in receivedPacket.Attributes)
                    {
                        Console.WriteLine(attr.Type.ToString() + " = " + attr.Value);
                    }
                    break;

                default:
                    Console.WriteLine("rejected");
                    break;
                }
            } catch (Exception e) {
                Console.WriteLine("Error : " + e.Message);
            }
        }
Example #3
0
 public RadiusPacket Authenticate(string username, string password)
 {
     RadiusPacket packet = new RadiusPacket(RadiusPacketType.ACCESS_REQUEST,this.sharedSecret);
     byte[] encryptedPass = Utils.encodePapPassword(Encoding.ASCII.GetBytes(password),packet.Authenticator,this.sharedSecret);
     packet.SetAttributes(RadiusAttributeType.USER_NAME , Encoding.ASCII.GetBytes(username));
     packet.SetAttributes(RadiusAttributeType.USER_PASSWORD , encryptedPass);
     return packet;
 }
Example #4
0
        public RadiusPacket Authenticate(string username, string password)
        {
            RadiusPacket packet = new RadiusPacket(RadiusPacketType.ACCESS_REQUEST, this.sharedSecret);

            byte[] encryptedPass = Utils.encodePapPassword(Encoding.ASCII.GetBytes(password), packet.Authenticator, this.sharedSecret);
            packet.SetAttributes(RadiusAttributeType.USER_NAME, Encoding.ASCII.GetBytes(username));
            packet.SetAttributes(RadiusAttributeType.USER_PASSWORD, encryptedPass);
            return(packet);
        }
Example #5
0
 private bool VerifyPacket(RadiusPacket requestedPacket, RadiusPacket receivedPacket)
 {
     if (requestedPacket.Identifier != receivedPacket.Identifier)
     {
         return(false);
     }
     if (requestedPacket.Authenticator.ToString() != Utils.makeRFC2865ResponseAuthenticator(receivedPacket.RawData, requestedPacket.Authenticator, sharedSecret).ToString())
     {
         return(false);
     }
     return(true);
 }
Example #6
0
 public RadiusPacket SendAndReceivePacket(RadiusPacket packet)
 {
     return(SendAndReceivePacket(packet, AUTH_RETRIES));
 }
Example #7
0
 public RadiusPacket SendAndReceivePacket(RadiusPacket packet,int retries)
 {
     IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
     RadiusUdpClient udpClient = new RadiusUdpClient();
     udpClient.SetTimeout(this.socketTimeout);
     for(int x=0; x< retries;x++) {
         try{
                 try {
                     udpClient.Connect(this.hostName,this.authPort);
                 } catch (Exception e) {
       udpClient = new RadiusUdpClient();
       udpClient.Connect(this.hostName, this.authPort);
                 }
             udpClient.Send(packet.GetBytes(),packet.GetBytes().Length);
             Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
             RadiusPacket receivedPacket = new RadiusPacket(receiveBytes,this.sharedSecret,packet.Authenticator);
             if(VerifyPacket(packet,receivedPacket))
                  return receivedPacket;
             udpClient.Close();
         }catch (Exception e){
             if(udpClient!=null)udpClient.Close();
             Console.WriteLine(e.Message);
         }
     }
     return null;
 }
Example #8
0
 public RadiusPacket SendAndReceivePacket(RadiusPacket packet)
 {
     return SendAndReceivePacket(packet,AUTH_RETRIES);
 }
Example #9
0
 private bool VerifyPacket(RadiusPacket requestedPacket,RadiusPacket receivedPacket)
 {
     if(requestedPacket.Identifier != receivedPacket.Identifier ) return false;
     if(requestedPacket.Authenticator.ToString() != Utils.makeRFC2865ResponseAuthenticator(receivedPacket.RawData,requestedPacket.Authenticator,sharedSecret).ToString()) return false;
     return true;
 }