Open JoshClose opened 5 years ago
I ended up writing a new RadiusDictionary
that parses the freeradius files. I didn't want to copy and paste a bunch of stuff. It seems to parse fine, but I haven't ran it against anything yet.
Is there any reason those files wouldn't work in your system?
Here is my source if you want to see.
using Flexinets.Radius.Core;
using log4net;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace InfinitWifi.RadiusServer
{
public class RadiusDictionary : IRadiusDictionary
{
private readonly List<DictionaryVendorAttribute> vendorSpecificAttributes = new List<DictionaryVendorAttribute>();
private readonly Dictionary<byte, DictionaryAttribute> attributes = new Dictionary<byte, DictionaryAttribute>();
private readonly Dictionary<string, DictionaryAttribute> attributeNames = new Dictionary<string, DictionaryAttribute>();
private readonly ILog log = LogManager.GetLogger(typeof(RadiusDictionary));
public RadiusDictionary(string dictionaryFilePath)
{
ParseFile(dictionaryFilePath);
log.Info($"Parsed {attributes.Count} attributes and {vendorSpecificAttributes.Count} vendor attributes from file");
}
public DictionaryAttribute GetAttribute(byte code) => attributes[code];
public DictionaryAttribute GetAttribute(string name)
{
attributeNames.TryGetValue(name, out var attributeType);
return attributeType;
}
public DictionaryVendorAttribute GetVendorAttribute(uint vendorId, byte vendorCode) =>
vendorSpecificAttributes.FirstOrDefault(a => a.VendorId == vendorId && a.VendorCode == vendorCode);
private void ParseFile(string dictionaryFilePath)
{
using (var reader = new StreamReader(dictionaryFilePath))
{
var vendorName = string.Empty;
uint vendorId = 0;
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
if (line.StartsWith("$INCLUDE"))
{
var lineParts = SplitLine(line);
var fileName = lineParts[1];
var filePath = Path.Combine(Path.GetDirectoryName(dictionaryFilePath), fileName);
ParseFile(filePath);
}
else if (line.StartsWith("VENDOR"))
{
var lineParts = SplitLine(line);
vendorName = lineParts[1];
vendorId = Convert.ToUInt32(lineParts[2]);
}
else if (line.StartsWith("END-VENDOR"))
{
vendorName = string.Empty;
vendorId = 0;
}
else if (line.StartsWith("ATTRIBUTE"))
{
var lineParts = SplitLine(line);
if (vendorId == 0)
{
var name = lineParts[1];
if (!byte.TryParse(lineParts[2], out var code))
{
continue;
}
var type = lineParts[3];
var attribute = new DictionaryAttribute(name, code, type);
attributes[code] = attribute;
attributeNames[name] = attribute;
}
else
{
var name = lineParts[1];
if (!uint.TryParse(lineParts[2], out var code))
{
continue;
}
var type = lineParts[3];
var attribute = new DictionaryVendorAttribute(vendorId, name, code, type);
vendorSpecificAttributes.Add(attribute);
}
}
}
}
}
private string[] SplitLine(string line)
{
return line.Split(new char[] { '\t', '\x20' }, StringSplitOptions.RemoveEmptyEntries);
}
}
}
Hi,
The current dictionary is actually based on the format Radiator uses. So it looks a bit like FreeRADIUS, but not quite.
I actually started creating a parser for FreeRADIUS dictionaries, but havent had the time to finish it.
Anyway, as you noticed the dictionary is very deliberately wrapped in the IRadiusDictionary interface, so of course any dictionary conforming to it should work.
If you want to do a PR for a FreeRADIUS dictionary parser thats also fine :p
I'll probably do a PR. This will parse the 202 FreeRADIUS files that come with Wireshark seemingly fine. I'll write up some tests.
Do you want me to add all the files for FreeRADIUS so they can be tested and used if someone wants to grab them?
I guess it would be nice to have the dictionaries, however I havent checked license compatibility. Im not sure if a radius dictionary actually is something that can be copyrighted in the first place though.
Btw, dictionary stuff should go in the Flexinets.Radius.Core repo and not this one. The radius client project also shares the core code and would benefit from the dictionary as well.
cheers, verner
Yes, sorry. I forked the core project and am doing the work there.
I'm seeing some types that the RadiusPacket.ParseContentBytes
doesn't handle. One instance is the Message-Authenticator
has a type of octets
, not octet
.
Here is a list of them. Do you see any others that need to be handled/added?
"abinary"
"byte"
"bytes"
"combo-ip"
"date"
"extended"
"ifid"
"integer"
"integer64"
"ipaddr"
"ipv4prefix"
"ipv6addr"
"ipv6prefix"
"long-extended"
"octets"
"short"
"signed"
"string"
"String"
"tlv"
Could you explain your vendor format? I'm looking to add some vendors to my file, but I'm seeing differences from the files I have. I'm using ones from WireShark, but they look like they came from FreeRadius. I'm looking at Cisco vendor 9 as an example. Not everything is included in your file. Some of the names match up and some have cisco- in front when it doesn't in the freeradius file. Casing is different. Are values not put in your file?
To me, this looks to be the format:
This is the file I want to use.