Coder Social home page Coder Social logo

Comments (7)

JoshClose avatar JoshClose commented on May 24, 2024

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);
		}
	}
}

from flexinets.radius.radiusserver.

vforteli avatar vforteli commented on May 24, 2024

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

from flexinets.radius.radiusserver.

JoshClose avatar JoshClose commented on May 24, 2024

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.

from flexinets.radius.radiusserver.

JoshClose avatar JoshClose commented on May 24, 2024

Do you want me to add all the files for FreeRADIUS so they can be tested and used if someone wants to grab them?

from flexinets.radius.radiusserver.

vforteli avatar vforteli commented on May 24, 2024

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

from flexinets.radius.radiusserver.

JoshClose avatar JoshClose commented on May 24, 2024

Yes, sorry. I forked the core project and am doing the work there.

from flexinets.radius.radiusserver.

JoshClose avatar JoshClose commented on May 24, 2024

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"

from flexinets.radius.radiusserver.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.