class PacketGen::Header::EAP
Extensible Authentication Protocol (EAP
), {tools.ietf.org/html/rfc3748 RFC 3748}
A EAP
header has:
-
a {#code} field ({Types::Int8Enum}),
-
a {#id} field ({Types::Int8}),
-
a {#length} field ({Types::Int16}).
Request (code 1) and Response (code 2) packets also have:
-
a {#type} field (
Types::Int8Enum
).
And Expanded Types
(type 254) packets also have:
-
a {#vendor_id} field ({Types::Int24}),
-
a {#vendor_type} field ({Types::Int32}).
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:
-
EAP-MD5,
-
EAP-TLS,
-
EAP-TTLS,
-
EAP-FAST.
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
Public Class Methods
@return [EAP]
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
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
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
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
Is packet a failure? @return [Boolean]
# File lib/packetgen/header/eap.rb, line 187 def failure? code == CODES['Failure'] end
Get human readable code @return [String]
# File lib/packetgen/header/eap.rb, line 154 def human_code self[:code].to_human end
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
Populate object from a binary string @param [String] str @return [Dot11] may return a subclass object if a more specific class
may be determined
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
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
Is packet a request? @return [Boolean]
# File lib/packetgen/header/eap.rb, line 169 def request? code == CODES['Request'] end
Is packet a response? @return [Boolean]
# File lib/packetgen/header/eap.rb, line 175 def response? code == CODES['Response'] end
Is packet a success? @return [Boolean]
# File lib/packetgen/header/eap.rb, line 181 def success? code == CODES['Success'] end
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