Class RADIUS

  • All Implemented Interfaces:
    IPacket

    public class RADIUS
    extends BasePacket
    RADIUS packet.
    • Field Detail

      • code

        protected byte code
      • identifier

        protected byte identifier
      • length

        protected short length
      • authenticator

        protected byte[] authenticator
      • RADIUS_CODE_ACCESS_REQUEST

        public static final byte RADIUS_CODE_ACCESS_REQUEST
        See Also:
        Constant Field Values
      • RADIUS_CODE_ACCESS_ACCEPT

        public static final byte RADIUS_CODE_ACCESS_ACCEPT
        See Also:
        Constant Field Values
      • RADIUS_CODE_ACCESS_REJECT

        public static final byte RADIUS_CODE_ACCESS_REJECT
        See Also:
        Constant Field Values
      • RADIUS_CODE_ACCOUNTING_REQUEST

        public static final byte RADIUS_CODE_ACCOUNTING_REQUEST
        See Also:
        Constant Field Values
      • RADIUS_CODE_ACCOUNTING_RESPONSE

        public static final byte RADIUS_CODE_ACCOUNTING_RESPONSE
        See Also:
        Constant Field Values
      • RADIUS_CODE_ACCESS_CHALLENGE

        public static final byte RADIUS_CODE_ACCESS_CHALLENGE
        See Also:
        Constant Field Values
    • Constructor Detail

      • RADIUS

        public RADIUS()
        Default constructor.
      • RADIUS

        public RADIUS​(byte code,
                      byte identifier)
        Constructs a RADIUS packet with the given code and identifier.
        Parameters:
        code - code
        identifier - identifier
    • Method Detail

      • getCode

        public byte getCode()
        Gets the code.
        Returns:
        code
      • setCode

        public void setCode​(byte code)
        Sets the code.
        Parameters:
        code - code
      • getIdentifier

        public byte getIdentifier()
        Gets the identifier.
        Returns:
        identifier
      • getReadableIdentifier

        public int getReadableIdentifier()
        Get the identifier in a readable format.
        Returns:
        identifier
      • setIdentifier

        public void setIdentifier​(byte identifier)
        Sets the identifier.
        Parameters:
        identifier - identifier
      • getAuthenticator

        public byte[] getAuthenticator()
        Gets the authenticator.
        Returns:
        authenticator
      • setAuthenticator

        public void setAuthenticator​(byte[] authenticator)
        Sets the authenticator.
        Parameters:
        authenticator - authenticator
      • generateAuthCode

        public byte[] generateAuthCode()
        Generates an authenticator code.
        Returns:
        the authenticator
      • isValidCode

        public boolean isValidCode()
        Checks if the packet's code field is valid.
        Returns:
        whether the code is valid
      • addMessageAuthenticator

        public RADIUSAttribute addMessageAuthenticator​(java.lang.String key)
        Adds a message authenticator to the packet based on the given key.
        Parameters:
        key - key to generate message authenticator
        Returns:
        the messgae authenticator RADIUS attribute
      • checkMessageAuthenticator

        public boolean checkMessageAuthenticator​(java.lang.String key)
        Checks the message authenticator in the packet with one generated from the given key.
        Parameters:
        key - key to generate message authenticator
        Returns:
        whether the message authenticators match or not
      • encapsulateMessage

        public void encapsulateMessage​(EAP message)
        Encapsulates an EAP packet in this RADIUS packet.
        Parameters:
        message - EAP message object to be embedded in the RADIUS EAP-Message attributed
      • decapsulateMessage

        public EAP decapsulateMessage()
                               throws DeserializationException
        Decapsulates an EAP packet from the RADIUS packet.
        Returns:
        An EAP object containing the reassembled EAP message
        Throws:
        DeserializationException - if packet deserialization fails
      • getAttributeList

        public java.util.ArrayList<RADIUSAttribute> getAttributeList​(byte attrType)
        Gets a list of attributes from the RADIUS packet.
        Parameters:
        attrType - the type field of the required attributes
        Returns:
        List of the attributes that matches the type or an empty list if there is none
      • getAttribute

        public RADIUSAttribute getAttribute​(byte attrType)
        Gets an attribute from the RADIUS packet.
        Parameters:
        attrType - the type field of the required attribute
        Returns:
        the first attribute that matches the type or null if does not exist
      • setAttribute

        public RADIUSAttribute setAttribute​(byte attrType,
                                            byte[] value)
        Sets an attribute in the RADIUS packet.
        Parameters:
        attrType - the type field of the attribute to set
        value - value to be set
        Returns:
        reference to the attribute object
      • updateAttribute

        public RADIUSAttribute updateAttribute​(byte attrType,
                                               byte[] value)
        Updates an attribute in the RADIUS packet.
        Parameters:
        attrType - the type field of the attribute to update
        value - the value to update to
        Returns:
        reference to the attribute object
      • deserializer

        public static Deserializer<RADIUS> deserializer()
        Deserializer for RADIUS packets.
        Returns:
        deserializer
      • serialize

        public byte[] serialize()
        Description copied from interface: IPacket
        Sets all payloads parent packet if applicable, then serializes this packet and all payloads.
        Returns:
        a byte[] containing this packet and payloads
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object