示例#1
0
        public void RadiusPacket_RFC_Examples()
        {
            const string secret = "xyzzy5461";
            RadiusPacket request;
            RadiusPacket response;

            byte[] raw;
            string sValue;

            byte[]    bValue;
            IPAddress aValue;
            int       iValue;

            // Verifies packet serialization against some examples in RFC 2865.
            //
            // 7.1.  User Telnet to Specified Host

            raw     = Helper.FromHex(@"

01 00 00 38 0f 40 3f 94 73 97 80 57 bd 83 d5 cb
98 f4 22 7a 01 06 6e 65 6d 6f 02 12 0d be 70 8d
93 d4 13 ce 31 96 e4 3f 78 2a 0a ee 04 06 c0 a8
01 10 05 06 00 00 00 03
");
            request = new RadiusPacket(new IPEndPoint(IPAddress.Parse("192.168.1.16"), 4001), raw, raw.Length);
            Assert.AreEqual(RadiusCode.AccessRequest, request.Code);
            Assert.AreEqual(0, request.Identifier);
            Assert.AreEqual(4, request.Attributes.Count);

            Assert.IsTrue(request.GetAttributeAsText(RadiusAttributeType.UserName, out sValue));
            Assert.AreEqual("nemo", sValue);

            Assert.IsTrue(request.GetAttributeAsBinary(RadiusAttributeType.UserPassword, out bValue));
            Assert.AreEqual("arctangent", request.DecryptUserPassword(bValue, secret));

            Assert.IsTrue(request.GetAttributeAsAddress(RadiusAttributeType.NasIpAddress, out aValue));
            Assert.AreEqual(IPAddress.Parse("192.168.1.16"), aValue);

            Assert.IsTrue(request.GetAttributeAsInteger(RadiusAttributeType.NasPort, out iValue));
            Assert.AreEqual(3, iValue);

            // Verify the response

            response = new RadiusPacket(RadiusCode.AccessAccept, 0, null);
            response.Attributes.Add(new RadiusAttribute(RadiusAttributeType.ServiceType, 1));
            response.Attributes.Add(new RadiusAttribute(RadiusAttributeType.LoginService, 0));
            response.Attributes.Add(new RadiusAttribute(RadiusAttributeType.LoginIpHost, IPAddress.Parse("192.168.1.3")));

            response.ComputeResponseAuthenticator(request, secret);

            CollectionAssert.AreEqual(Helper.FromHex(@"

      02 00 00 26 86 fe 22 0e 76 24 ba 2a 10 05 f6 bf
      9b 55 e0 b2 06 06 00 00 00 01 0f 06 00 00 00 00
      0e 06 c0 a8 01 03
"),
                                      response.ToArray());
        }
示例#2
0
        public void RadiusPacket_PasswordEncryption()
        {
            // Test passwords from 1 to 128 characters in length.

            for (int i = 1; i < 128; i++)
            {
                string       password = GetPassword(i);
                RadiusPacket packet;

                packet = new RadiusPacket(RadiusCode.AccessRequest, 55, Crypto.Rand(16));
                packet.Attributes.Add(new RadiusAttribute(RadiusAttributeType.UserPassword, packet.EncryptUserPassword(password, "secret")));
                Assert.AreNotEqual(password, Helper.FromAnsi(packet.Attributes[0].Value, 0, password.Length));
                Assert.AreEqual(password, packet.DecryptUserPassword(packet.Attributes[0].Value, "secret"));
            }
        }