コード例 #1
0
ファイル: RadiusClient.cs プロジェクト: QANTau/Radius.NET
		public RadiusPacket Authenticate(string username, string password)
		{
			RadiusPacket packet = new RadiusPacket(RadiusCode.ACCESS_REQUEST);
			packet.SetAuthenticator(_SharedSecret);
			byte[] encryptedPass = Utils.EncodePapPassword(Encoding.ASCII.GetBytes(password), packet.Authenticator, _SharedSecret);
			packet.SetAttribute(new RadiusAttribute(RadiusAttributeType.USER_NAME, Encoding.ASCII.GetBytes(username)));
			packet.SetAttribute(new RadiusAttribute(RadiusAttributeType.USER_PASSWORD, encryptedPass));
			return packet;
		}
コード例 #2
0
        public RadiusPacket Authenticate(string username, string password)
        {
            RadiusPacket packet = new RadiusPacket(RadiusCode.ACCESS_REQUEST);

            packet.SetAuthenticator(_SharedSecret);
            byte[] encryptedPass = Utils.EncodePapPassword(Encoding.ASCII.GetBytes(password), packet.Authenticator, _SharedSecret);
            packet.SetAttribute(new RadiusAttribute(RadiusAttributeType.USER_NAME, Encoding.ASCII.GetBytes(username)));
            packet.SetAttribute(new RadiusAttribute(RadiusAttributeType.USER_PASSWORD, encryptedPass));
            return(packet);
        }
コード例 #3
0
ファイル: RadiusClient.cs プロジェクト: pedroccrl/Radius.NET
        public RadiusPacket DisconnectRequest(string sessionId, string username, string framedIpAddress)
        {
            var packet = new RadiusPacket(RadiusCode.DISCONNECT_REQUEST);

            packet.SetAttribute(RadiusAttribute.CreateString(RadiusAttributeType.ACCT_SESSION_ID, sessionId));
            packet.SetAttribute(RadiusAttribute.CreateString(RadiusAttributeType.USER_NAME, username));
            packet.SetAttribute(RadiusAttribute.CreateAddress(RadiusAttributeType.FRAMED_IP_ADDRESS, framedIpAddress));
            packet.SetAuthenticator(_SharedSecret);

            return(packet);
        }
コード例 #4
0
        public async static Task Authentication(string[] args)
        {
            try
            {
                RadiusClient rc         = new RadiusClient(args[0], args[1]);
                RadiusPacket authPacket = rc.Authenticate(args[2], args[3]);
                authPacket.SetAttribute(new VendorSpecificAttribute(10135, 1, UTF8Encoding.UTF8.GetBytes("Testing")));
                authPacket.SetAttribute(new VendorSpecificAttribute(10135, 2, new[] { (byte)7 }));

                RadiusPacket receivedPacket = await rc.SendAndReceivePacket(authPacket);

                if (receivedPacket == null)
                {
                    throw new Exception("Can't contact remote radius server !");
                }

                switch (receivedPacket.PacketType)
                {
                case RadiusCode.ACCESS_ACCEPT:
                    Console.WriteLine("Access-Accept");
                    foreach (var attr in receivedPacket.Attributes)
                    {
                        Console.WriteLine(attr.Type.ToString() + " = " + attr.Value);
                    }
                    break;

                case RadiusCode.ACCESS_CHALLENGE:
                    Console.WriteLine("Access-Challenge");
                    break;

                case RadiusCode.ACCESS_REJECT:
                    Console.WriteLine("Access-Reject");
                    if (!rc.VerifyAuthenticator(authPacket, receivedPacket))
                    {
                        Console.WriteLine("Authenticator check failed: Check your secret");
                    }
                    break;

                default:
                    Console.WriteLine("Rejected");
                    break;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }