/// <summary> /// Constructs a RADIUS packet from the parameters passed. /// </summary> /// <param name="code">The RADIUS message code.</param> /// <param name="identifier">Used to aid matching requests and replies value (0..255).</param> /// <param name="authenticator">16 byte autheticator used for hiding passwords.</param> /// <param name="attributes">The packet attributes.</param> /// <remarks> /// <note> /// <b>authenticator</b> may be passed as null in situations where /// a response authenticator will be computed after the packet is fully /// initialized via the <see cref="ComputeResponseAuthenticator" /> method. /// </note> /// </remarks> public RadiusPacket(RadiusCode code, int identifier, byte[] authenticator, params RadiusAttribute[] attributes) { if (identifier < 0 || identifier > 255) { throw new ArgumentException("[identifier] must be in the range of 0..255"); } if (authenticator == null) { authenticator = new byte[16]; } if (authenticator.Length != 16) { throw new ArgumentException("[authenticator] must be 16 bytes."); } this.Code = code; this.Identifier = identifier; this.Authenticator = authenticator; this.SourceEP = null; this.Attributes = new List <RadiusAttribute>(); for (int i = 0; i < attributes.Length; i++) { this.Attributes.Add(attributes[i]); } }
/// <summary> /// Constructs a RADIUS packet by parsing the raw UDP packet bytes passed. /// </summary> /// <param name="sourceEP">The source endpoint for received packets.</param> /// <param name="raw">The raw UDP packet.</param> /// <param name="length">Size of the raw packet in bytes.</param> public RadiusPacket(IPEndPoint sourceEP, byte[] raw, int length) { int pos; int len; this.SourceEP = sourceEP; // Parse the packet header fields if (length < HeaderSize) { throw new RadiusException(raw, "Bad RADIUS packet: length < 20"); } this.Code = (RadiusCode)raw[0]; this.Identifier = raw[1]; len = (raw[2] << 8) | raw[3]; if (len > length) { throw new RadiusException(raw, "Bad RADIUS packet: truncated"); } length = len; this.Authenticator = Helper.Extract(raw, 4, 16); // Parse the packet attributes this.Attributes = new List <RadiusAttribute>(); pos = HeaderSize; while (pos < length - 2) { RadiusAttributeType aType; int aLen; byte[] aValue; aType = (RadiusAttributeType)raw[pos++]; aLen = raw[pos++] - 2; if (aLen < 0) { throw new RadiusException(raw, "Bad RADIUS packet: attribute length < 2"); } if (pos + aLen > length) { throw new RadiusException(raw, "Bad RADIUS packet: attribute extends past packet"); } aValue = Helper.Extract(raw, pos, aLen); pos += aLen; this.Attributes.Add(new RadiusAttribute(aType, aValue)); } }
public RadiusPacket(RadiusCode packetType, byte identifier) { PacketType = packetType; Identifier = identifier; _Length = RADIUS_HEADER_LENGTH; RawData = new byte[RADIUS_HEADER_LENGTH]; RawData[RADIUS_CODE_INDEX] = (byte)PacketType; RawData[RADIUS_IDENTIFIER_INDEX] = Identifier; Array.Copy(BitConverter.GetBytes(_Length), 0, RawData, RADIUS_LENGTH_INDEX, sizeof(ushort)); Array.Reverse(RawData, RADIUS_LENGTH_INDEX, sizeof(ushort)); }
public RadiusPacket(RadiusCode packetType, byte identifier) { PacketType = packetType; Identifier = identifier; _Length = RADIUS_HEADER_LENGTH; RawData = new byte[RADIUS_HEADER_LENGTH]; RawData[RADIUS_CODE_INDEX] = (byte)PacketType; RawData[RADIUS_IDENTIFIER_INDEX] = Identifier; Array.Copy(BitConverter.GetBytes(_Length), 0, RawData, RADIUS_LENGTH_INDEX, sizeof(ushort)); Array.Reverse(RawData, RADIUS_LENGTH_INDEX, sizeof(ushort)); }
public IList <RadiusAttribute> this[RadiusCode responseType] { get { if (!this.responseLists.ContainsKey(responseType)) { this.responseLists[responseType] = new RadiusAttributeList(this.outer.ecb.GetResponse(this.outer.ecbPtr, responseType)); } return(this.responseLists[responseType]); } }
public IList<RadiusAttribute> this[RadiusCode responseType] { get { if (!this.responseLists.ContainsKey(responseType)) { this.responseLists[responseType] = new RadiusAttributeList(this.outer.ecb.GetResponse(this.outer.ecbPtr, responseType)); } return this.responseLists[responseType]; } }