class PacketGen::Header::EAP

Extensible Authentication Protocol (EAP), {tools.ietf.org/html/rfc3748 RFC 3748}

A EAP header has:

Request (code 1) and Response (code 2) packets also have:

And Expanded Types (type 254) packets also have:

Finally, all packets have a {#body} ({Types::String}).

Create EAP headers

An EAP header may be created this way:

# create a request header with default type (1)
eap = EAP.new(code: 1)   # => PacketGen::Header::EAP
# the same
eap = EAP.new(code: 'Request')   # => PacketGen::Header::EAP
# create a Response header of type Nak
nak = EAP.new(code: 'Response', type: 'Nak')

Specialized headers

Some EAP has a specialized class:

Creating such a header is fairly simple:

# Generate a EAP-TLS Response (type is forced to 13)
eap = EAP::TLS.new(code: 2)     # => PacketGen::Header::EAP::TLS

Header accessors

EAP headers may be accessed through +Packet#eap+ accessor. As EAP has specialized subclasses ({EAP::MD5}, {EAP::TLS}, {EAP::TTLS} and {EAP::FAST}), these headers may be accessed through #eap_md5, #eap_tls, #eap_ttls and #eap_fast, respectively. But #eap is still here as a shortcut.

Parse EAP packets

When parsing an EAP packet, EAP subclass may be created from type value.

So result of parsing a EAP header may be a {EAP}, {EAP::MD5}, {EAP::TLS}, {EAP::TTLS} or {EAP::FAST} instance. But this instance is still accessible through +Packet#eap+. @author Sylvain Daubert @since 2.1.4

Constants

CODES

EAP known codes

TYPES

EAP known request/response types

Public Class Methods

new(options={}) click to toggle source

@return [EAP]

Calls superclass method PacketGen::Header::Base::new
# File lib/packetgen/header/eap.rb, line 121
def initialize(options={})
  super
  calc_length if options[:length].nil?
end

Public Instance Methods

added_to_packet(packet) click to toggle source

Callback called when a EAP header is added to a packet Here, add #eap method as a shortcut to existing +#eap_(md5|tls|ttls|fast)+. @param [Packet] packet @return [void]

# File lib/packetgen/header/eap.rb, line 218
def added_to_packet(packet)
  return if packet.respond_to? :eap

  packet.instance_eval("def eap(arg=nil); header(#{self.class}, arg); end")
end
calc_length() click to toggle source

Calculate length field from content @return [Integer]

# File lib/packetgen/header/eap.rb, line 202
def calc_length
  Base.calculate_and_set_length self
end
desired_auth_type() click to toggle source

Return an array of desired authentication types from a Nak packet @return [Array<Integer>] @raise [ParseError] not a Nak packet

# File lib/packetgen/header/eap.rb, line 194
def desired_auth_type
  raise ParseError, 'not a Nak response' if (code != 2) && (type != 3)

  body.to_s.unpack('C*')
end
failure?() click to toggle source

Is packet a failure? @return [Boolean]

# File lib/packetgen/header/eap.rb, line 187
def failure?
  code == CODES['Failure']
end
human_code() click to toggle source

Get human readable code @return [String]

# File lib/packetgen/header/eap.rb, line 154
def human_code
  self[:code].to_human
end
human_type() click to toggle source

Get human readable type @return [String] @raise [ParseError] not a Request nor a Response packet

# File lib/packetgen/header/eap.rb, line 161
def human_type
  raise ParseError, 'not a Request nor a Response' unless type?

  self[:type].to_human
end
old_read(str)

@private

Alias for: read
read(str) click to toggle source

Populate object from a binary string @param [String] str @return [Dot11] may return a subclass object if a more specific class

may be determined
Calls superclass method PacketGen::Headerable#read
# File lib/packetgen/header/eap.rb, line 133
def read(str)
  super str
  return self unless self.instance_of?(EAP)
  return self unless type?

  case self.type
  when 4
    EAP::MD5.new.read(str)
  when 13
    EAP::TLS.new.read(str)
  when 21
    EAP::TTLS.new.read(str)
  when 43
    EAP::FAST.new.read(str)
  else
    self
  end
end
Also aliased as: old_read
reply!() click to toggle source

Invert between a request and a response packet. Not action for others codes. @return [self]

# File lib/packetgen/header/eap.rb, line 227
def reply!
  case self.code
  when 1 then self.code = 2
  when 2 then self.code = 1
  end
  self
end
request?() click to toggle source

Is packet a request? @return [Boolean]

# File lib/packetgen/header/eap.rb, line 169
def request?
  code == CODES['Request']
end
response?() click to toggle source

Is packet a response? @return [Boolean]

# File lib/packetgen/header/eap.rb, line 175
def response?
  code == CODES['Response']
end
success?() click to toggle source

Is packet a success? @return [Boolean]

# File lib/packetgen/header/eap.rb, line 181
def success?
  code == CODES['Success']
end
type?() click to toggle source

Say is this EAP header has {#type} field @return [Boolean] @since 2.7.0

# File lib/packetgen/header/eap.rb, line 209
def type?
  [1, 2].include?(self.code)
end