WIP
parent
a6decbd443
commit
0141fb51b9
|
@ -63,8 +63,8 @@ namespace ln.radius
|
|||
return String.Format("[RadiusAttribute Type={0} {1}]", Name, Encoding.ASCII.GetString(Bytes));
|
||||
}
|
||||
|
||||
static Dictionary<byte, string> attributeNames = new Dictionary<byte, string>();
|
||||
static Dictionary<byte, RadiusAttributeFactory> attributeFactories = new Dictionary<byte, RadiusAttributeFactory>();
|
||||
static internal Dictionary<byte, string> attributeNames = new Dictionary<byte, string>();
|
||||
static internal Dictionary<byte, RadiusAttributeFactory> attributeFactories = new Dictionary<byte, RadiusAttributeFactory>();
|
||||
public static RadiusAttribute Create(byte attributeType)
|
||||
{
|
||||
if (attributeFactories.ContainsKey(attributeType))
|
||||
|
|
|
@ -13,6 +13,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using ln.types;
|
||||
using System.Security.Cryptography;
|
||||
using ln.logging;
|
||||
namespace ln.radius
|
||||
{
|
||||
public enum RadiusCode : byte {
|
||||
|
@ -54,6 +55,15 @@ namespace ln.radius
|
|||
Code = radiusCode;
|
||||
}
|
||||
|
||||
public RAT GetAttribute<RAT>(string attrName) where RAT : RadiusAttribute => (RAT)GetAttribute(attrName);
|
||||
public RadiusAttribute GetAttribute(string attrName)
|
||||
{
|
||||
foreach (RadiusAttribute radiusAttribute in radiusAttributes)
|
||||
if (radiusAttribute.Name.Equals(attrName))
|
||||
return radiusAttribute;
|
||||
throw new KeyNotFoundException();
|
||||
}
|
||||
|
||||
public byte[] Authenticate(byte[] secret)
|
||||
{
|
||||
byte[] packet = ToBytes();
|
||||
|
@ -65,6 +75,29 @@ namespace ln.radius
|
|||
return packet;
|
||||
}
|
||||
|
||||
public bool IsAuthentic(byte[] secret)
|
||||
{
|
||||
byte[] authenticator = Authenticator;
|
||||
bool authentic = false;
|
||||
|
||||
try
|
||||
{
|
||||
Authenticator = new byte[16];
|
||||
byte[] packet = ToBytes();
|
||||
|
||||
MD5 md5 = MD5.Create();
|
||||
md5.TransformBlock(packet, 0, packet.Length, null, 0);
|
||||
md5.TransformFinalBlock(secret, 0, secret.Length);
|
||||
authentic = authenticator.AreEqual(md5.Hash);
|
||||
} catch (Exception e)
|
||||
{
|
||||
Logging.Log(LogLevel.ERROR, "RadiusMessage.IsAuthentic(): {0}", e);
|
||||
Logging.Log(e);
|
||||
}
|
||||
Authenticator = authenticator;
|
||||
return authentic;
|
||||
}
|
||||
|
||||
public byte[] ToBytes()
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
|
|
|
@ -61,7 +61,6 @@ namespace ln.radius
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void ListenerThread(UdpClient udp)
|
||||
{
|
||||
try
|
||||
|
@ -73,7 +72,6 @@ namespace ln.radius
|
|||
try
|
||||
{
|
||||
RadiusMessage radiusMessage = RadiusMessage.FromBytes(rx, remoteEndPoint);
|
||||
Logging.Log("RX: {0}",radiusMessage.ToString());
|
||||
RequestPool.Enqueue(() => MessageReceived(this, radiusMessage));
|
||||
} catch (Exception e)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue