WIP
parent
ce680a9546
commit
d90ab38bec
|
@ -44,6 +44,18 @@ namespace ln.radius
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RadiusAttribute SetBytes(byte[] bytes)
|
||||||
|
{
|
||||||
|
this.Bytes = bytes;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RadiusAttribute SetText(string text)
|
||||||
|
{
|
||||||
|
this.AsText = text;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static RadiusAttribute Read(Stream stream)
|
public static RadiusAttribute Read(Stream stream)
|
||||||
|
@ -169,6 +181,12 @@ namespace ln.radius
|
||||||
return string.Format("[RadiusAttribute Type={0} {1}]", Name, IP.ToString());
|
return string.Format("[RadiusAttribute Type={0} {1}]", Name, IP.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IPv4Attribute SetIP(IPv4 ip)
|
||||||
|
{
|
||||||
|
this.IP = ip;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class IntAttribute : RadiusAttribute
|
public class IntAttribute : RadiusAttribute
|
||||||
|
@ -188,6 +206,12 @@ namespace ln.radius
|
||||||
{
|
{
|
||||||
return string.Format("[RadiusAttribute Type={0} {1}]", Name, UInt32);
|
return string.Format("[RadiusAttribute Type={0} {1}]", Name, UInt32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IntAttribute SetUInt(uint value)
|
||||||
|
{
|
||||||
|
this.UInt32 = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TimeAttribute : RadiusAttribute
|
public class TimeAttribute : RadiusAttribute
|
||||||
|
|
|
@ -55,6 +55,14 @@ namespace ln.radius
|
||||||
Code = radiusCode;
|
Code = radiusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RadiusMessage ConstructReply(RadiusCode radiusCode)
|
||||||
|
{
|
||||||
|
RadiusMessage reply = new RadiusMessage(EndPoint, radiusCode);
|
||||||
|
reply.Identifier = Identifier;
|
||||||
|
reply.Authenticator = Authenticator;
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
|
||||||
public RAT GetAttribute<RAT>() where RAT : RadiusAttribute
|
public RAT GetAttribute<RAT>() where RAT : RadiusAttribute
|
||||||
{
|
{
|
||||||
foreach (RadiusAttribute radiusAttribute in radiusAttributes)
|
foreach (RadiusAttribute radiusAttribute in radiusAttributes)
|
||||||
|
@ -71,6 +79,24 @@ namespace ln.radius
|
||||||
throw new KeyNotFoundException();
|
throw new KeyNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetAttribute(RadiusAttribute attribute)
|
||||||
|
{
|
||||||
|
foreach (RadiusAttribute radiusAttribute in radiusAttributes.ToArray())
|
||||||
|
{
|
||||||
|
if (radiusAttribute.Type == attribute.Type)
|
||||||
|
radiusAttributes.Remove(radiusAttribute);
|
||||||
|
}
|
||||||
|
radiusAttributes.Add(attribute);
|
||||||
|
}
|
||||||
|
public void AddAttribute(RadiusAttribute attribute)
|
||||||
|
{
|
||||||
|
radiusAttributes.Add(attribute);
|
||||||
|
}
|
||||||
|
public void RemoveAttribute(RadiusAttribute attribute)
|
||||||
|
{
|
||||||
|
radiusAttributes.Remove(attribute);
|
||||||
|
}
|
||||||
|
|
||||||
public byte[] Authenticate(byte[] secret)
|
public byte[] Authenticate(byte[] secret)
|
||||||
{
|
{
|
||||||
byte[] packet = ToBytes();
|
byte[] packet = ToBytes();
|
||||||
|
@ -109,7 +135,6 @@ namespace ln.radius
|
||||||
{
|
{
|
||||||
using (MemoryStream memoryStream = new MemoryStream())
|
using (MemoryStream memoryStream = new MemoryStream())
|
||||||
{
|
{
|
||||||
|
|
||||||
memoryStream.WriteByte((byte)Code);
|
memoryStream.WriteByte((byte)Code);
|
||||||
memoryStream.WriteByte((byte)Identifier);
|
memoryStream.WriteByte((byte)Identifier);
|
||||||
memoryStream.WriteShort((short)0);
|
memoryStream.WriteShort((short)0);
|
||||||
|
@ -121,7 +146,7 @@ namespace ln.radius
|
||||||
byte[] bytes = memoryStream.ToArray();
|
byte[] bytes = memoryStream.ToArray();
|
||||||
|
|
||||||
Array.Copy(
|
Array.Copy(
|
||||||
BitConverter.GetBytes((short)bytes.Length), 0,
|
BitConverter.GetBytes((short)bytes.Length).BigEndian(), 0,
|
||||||
bytes, 2,
|
bytes, 2,
|
||||||
2
|
2
|
||||||
);
|
);
|
||||||
|
|
|
@ -57,7 +57,8 @@ namespace ln.radius
|
||||||
|
|
||||||
lock (udp)
|
lock (udp)
|
||||||
{
|
{
|
||||||
udp.Send(packet, packet.Length, message.EndPoint);
|
int sent = udp.Send(packet, packet.Length, message.EndPoint);
|
||||||
|
Logging.Log(LogLevel.DEBUG, "Radius sent {0} bytes to {1}", sent, message.EndPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue