public void TestMessageAuthenticatorValidationSuccess() { var request = "0cda00268a54f4686fb394c52866e302185d062350125a665e2e1e8411f3e243822097c84fa3"; var secret = "xyzzy5461"; var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary()); var requestPacket = radiusPacketParser.Parse(Utils.StringToByteArray(request), Encoding.UTF8.GetBytes(secret)); }
public void TestMessageAuthenticatorValidationFail() { var request = "0cda00268a54f4686fb394c52866e302185d062350125a665e2e1e8411f3e243822097c84fa3"; var secret = "xyzzy5461durr"; var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary()); Assert.That(() => radiusPacketParser.Parse(Utils.StringToByteArray(request), Encoding.UTF8.GetBytes(secret)), Throws.TypeOf <InvalidOperationException>()); }
public void TestPacketParserMissingData() { var request = "0cda00268a54f4686fb394c52866e302185d062350125a665e2e1e8411f3e243822097c84f"; var expected = request; var secret = "xyzzy5461"; var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary()); Assert.Throws <ArgumentOutOfRangeException>(() => radiusPacketParser.Parse(Utils.StringToByteArray(request), Encoding.UTF8.GetBytes(secret))); }
public void Test3GPPLocationInfoParsing() { var request = "01d901becff27ef45a6bc4525aa5d65f483876951f103433363838383735303636393736011b32333230313038353030373639373640666c6578696e65747304060af7e0611a1600001fe40120001031352e3020283537393333290606000000020706000000073d06000000121a0e00001fe4003e0008000000011a17000028af01113233323031303835303037363937361a0d000028af080732333230311a09000028af0a03351a09000028af0c03301a0c000028af020605b28a3e1a27000028af052130352d314239333146373339364645464537344142464646463030384530301a0c000028af0d06303830301e0b666c6578696e6574731a0c000028af0606c230840c1a0d000028af120732333230311a0c000028af0706c23084da1a0d000028af090732333230311a09000028af1a03001a09000028af1503011a10000028af160a0132f210426d1bc01a0a000028af170480011a18000028af1412383632383238303231323838323230301a0c000028af0306000000001a0e00001fe4001800080000000405060001272602120ca8378c51ef621ac229c647a85646071a1100000009170b464c4558494e45545321053136382105313736"; var secret = "xyzzy5461"; var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary()); var requestPacket = radiusPacketParser.Parse(Utils.StringToByteArray(request), Encoding.UTF8.GetBytes(secret)); var locationInfo = requestPacket.GetAttribute <Byte[]>("3GPP-User-Location-Info"); Assert.AreEqual("23201", Utils.GetMccMncFrom3GPPLocationInfo(locationInfo).mccmnc); }
public void TestMessageAuthenticatorNoSideEffect() { var request = Utils.StringToByteArray("0cda00268a54f4686fb394c52866e302185d062350125a665e2e1e8411f3e243822097c84fa3"); var expected = Utils.StringToByteArray("0cda00268a54f4686fb394c52866e302185d062350125a665e2e1e8411f3e243822097c84fa3"); var secret = "xyzzy5461"; var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary()); var requestPacket = radiusPacketParser.Parse(request, Encoding.UTF8.GetBytes(secret)); Assert.AreEqual(Utils.ToHexString(expected), Utils.ToHexString(request)); }
public void TestAccountingPacketRequestAuthenticatorFail() { var packetBytes = "0404002711019c27d4e00cbc523b3e2fc834baf401066e656d6f2806000000012c073230303234"; var secret = "foo"; var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary()); var requestAuthenticator = radiusPacketParser.CalculateRequestAuthenticator(Encoding.UTF8.GetBytes(secret), Utils.StringToByteArray(packetBytes)); Assert.That(() => radiusPacketParser.Parse(Utils.StringToByteArray(packetBytes), Encoding.UTF8.GetBytes(secret)), Throws.TypeOf <InvalidOperationException>()); }
public void TestAccountingPacketRequestAuthenticatorSuccess() { var packetBytes = "0404002711019c27d4e00cbc523b3e2fc834baf401066e656d6f2806000000012c073230303234"; var secret = "xyzzy5461"; var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary()); var requestAuthenticator = radiusPacketParser.CalculateRequestAuthenticator(Encoding.UTF8.GetBytes(secret), Utils.StringToByteArray(packetBytes)); var packet = radiusPacketParser.Parse(Utils.StringToByteArray(packetBytes), Encoding.UTF8.GetBytes(secret)); Assert.AreEqual(packet.Authenticator.ToHexString(), requestAuthenticator.ToHexString()); }
public void TestLTE3GPPLocationInfoParsing() { var request = "017301cea4571e304078c73bbb4367ca5fcede3e1f103433363838383735303636393736011b32333230313038353030373639373640666c6578696e65747304060af7e0611a1600001fe40120001031352e3020283537393333291e0b666c6578696e6574730606000000020706000000073d06000000121a0e00001fe4003e0008000000021a17000028af01113233323031303835303037363937361a0d000028af080732333230311a09000028af0a03351a0c000028af020605654e411a0c000028af0d06303830301a0c000028af0606c23084e01a0c000028af0706c23084da1a09000028af1503061a18000028af1412383632383238303231323838323230301a15000028af160f8232f210426d32f21000013e021a0d000028af120732333230311a0d000028af090732333230311a09000028af0c03301a0a000028af170480011a1f000028af051930382d34433038303030343933453030303034393345301a0c000028af0306000000001a09000028af1a03001a0e00001fe4001800080000000f050600012d2202121e205a653bc6cad430e70a585ab0271f1a0c0000159f5806000000031a1100000009170b464c4558494e4554532104393521043935210439352105323136"; var secret = "xyzzy5461"; var ltelocationid = Utils.StringToByteArray("8232f210426d32f21000013e02"); var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary()); var requestPacket = radiusPacketParser.Parse(Utils.StringToByteArray(request), Encoding.UTF8.GetBytes(secret)); var locationInfo = requestPacket.GetAttribute <Byte[]>("3GPP-User-Location-Info"); Assert.AreEqual("23201", Utils.GetMccMncFrom3GPPLocationInfo(locationInfo).mccmnc); }
public void TestPacketParserAndAssemblerExtraDataIgnored() { var request = "0cda00268a54f4686fb394c52866e302185d062350125a665e2e1e8411f3e243822097c84fa300ff00ff00ff"; var expected = "0cda00268a54f4686fb394c52866e302185d062350125a665e2e1e8411f3e243822097c84fa3"; var secret = "xyzzy5461"; var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary()); var requestPacket = radiusPacketParser.Parse(Utils.StringToByteArray(request), Encoding.UTF8.GetBytes(secret)); var bytes = radiusPacketParser.GetBytes(requestPacket); Assert.AreEqual(expected, bytes.ToHexString()); }
public void TestCreatingMissingAttributes() { var secret = "xyzzy5461"; var packet = new RadiusPacket(PacketCode.AccessRequest, 1, secret); packet.AddAttribute("User-Name", "*****@*****.**"); packet.AddAttribute("User-Password", "test"); var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary()); var testPacket = radiusPacketParser.Parse(radiusPacketParser.GetBytes(packet), Encoding.UTF8.GetBytes(secret)); Assert.IsNull(testPacket.GetAttribute <uint?>("NAS-Port")); Assert.AreEqual(0, testPacket.GetAttributes <uint>("NAS-Port").Count); }
public void TestCreateAndParseAccountingRequestPacket() { var secret = "xyzzy5461"; var dictionary = GetDictionary(); var packet = new RadiusPacket(PacketCode.AccountingRequest, 0, secret); packet.AddAttribute("User-Name", "nemo"); packet.AddAttribute("Acct-Status-Type", 2); packet.AddAttribute("NAS-IP-Address", IPAddress.Parse("192.168.1.16")); packet.AddAttribute("NAS-Port", 3); var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary()); var bytes = radiusPacketParser.GetBytes(packet); var derp = radiusPacketParser.Parse(bytes, Encoding.UTF8.GetBytes(secret)); }
public void TestCreatingAndParsingPacket() { var secret = "xyzzy5461"; var packet = new RadiusPacket(PacketCode.AccessRequest, 1, secret); packet.AddAttribute("User-Name", "*****@*****.**"); packet.AddAttribute("User-Password", "test"); packet.AddAttribute("NAS-IP-Address", IPAddress.Parse("127.0.0.1")); packet.AddAttribute("NAS-Port", 100); packet.AddAttribute("3GPP-IMSI-MCC-MNC", "24001"); packet.AddAttribute("3GPP-CG-Address", IPAddress.Parse("127.0.0.1")); var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, GetDictionary()); var testPacket = radiusPacketParser.Parse(radiusPacketParser.GetBytes(packet), Encoding.UTF8.GetBytes(secret)); Assert.AreEqual("*****@*****.**", testPacket.GetAttribute <string>("User-Name")); Assert.AreEqual("test", testPacket.GetAttribute <string>("User-Password")); Assert.AreEqual(IPAddress.Parse("127.0.0.1"), testPacket.GetAttribute <IPAddress>("NAS-IP-Address")); Assert.AreEqual(IPAddress.Parse("127.0.0.1"), testPacket.GetAttributes <IPAddress>("NAS-IP-Address").First()); // this should actually be tested with EAP-Message attributes Assert.AreEqual(100, testPacket.GetAttribute <uint>("NAS-Port")); Assert.AreEqual("24001", testPacket.GetAttribute <string>("3GPP-IMSI-MCC-MNC")); Assert.AreEqual(IPAddress.Parse("127.0.0.1"), testPacket.GetAttribute <IPAddress>("3GPP-CG-Address")); }