Class: PacketGen::Header::EAP
- Inherits:
-
Base
- Object
- Types::Fields
- Base
- PacketGen::Header::EAP
- Defined in:
- lib/packetgen/header/eap.rb,
lib/packetgen/header/eap/md5.rb,
lib/packetgen/header/eap/tls.rb,
lib/packetgen/header/eap/fast.rb,
lib/packetgen/header/eap/ttls.rb
Overview
Extensible Authentication Protocol (EAP), 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 (MD5, TLS, TTLS and 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, MD5, TLS, TTLS or FAST instance. But this instance is still accessible through Packet#eap.
Defined Under Namespace
Constant Summary collapse
- CODES =
EAP known codes
{ 'Request' => 1, 'Response' => 2, 'Success' => 3, 'Failure' => 4 }.freeze
- TYPES =
EAP known request/response types
{ 'Identity' => 1, 'Notification' => 2, 'Nak' => 3, 'MD5-Challenge' => 4, 'One Time Password' => 5, 'Generic Token Card' => 6, 'EAP-TLS' => 13, 'EAP-TTLS' => 21, 'EAP-FAST' => 43, 'Expanded Types' => 254, 'Experimental Use' => 255 }.freeze
Instance Attribute Summary collapse
- #body ⇒ Types::String, Header::Base
-
#code ⇒ Integer
8-bit EAP code.
-
#id ⇒ Integer
8-bit identifier.
-
#length ⇒ Integer
16-bit length of EAP packet.
-
#type ⇒ Integer
This field is present only for Request or Response packets, with type different from Expanded Types (254).
-
#vendor_id ⇒ Integer
This field is present only for Request or Response packets, with type equal to Expanded Types (254).
-
#vendor_type ⇒ Integer
This field is present only for Request or Response packets, with type equal to Expanded Types (254).
Instance Method Summary collapse
-
#added_to_packet(packet) ⇒ void
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). -
#calc_length ⇒ Integer
Calculate length field from content.
-
#desired_auth_type ⇒ Array<Integer>
Return an array of desired authentication types from a Nak packet.
-
#failure? ⇒ Boolean
Is packet a failure?.
-
#human_code ⇒ String
Get human readable code.
-
#human_type ⇒ String
Get human readable type.
- #initialize(options = {}) ⇒ EAP constructor
- #old_read ⇒ Object
-
#read(str) ⇒ Dot11
Populate object from a binary string.
-
#reply! ⇒ self
Invert between a request and a response packet.
-
#request? ⇒ Boolean
Is packet a request?.
-
#response? ⇒ Boolean
Is packet a response?.
-
#success? ⇒ Boolean
Is packet a success?.
-
#type? ⇒ Boolean
Say is this EAP header has #type field.
Methods inherited from Base
bind, calculate_and_set_length, #header_id, inherited, #ip_header, #ll_header
Methods included from PacketGen::Headerable
included, #method_name, #packet, #packet=, #parse?, #protocol_name
Methods inherited from Types::Fields
#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, fields, inherited, #inspect, #offset_of, #optional?, #optional_fields, #present?, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field
Constructor Details
#initialize(options = {}) ⇒ EAP
122 123 124 125 |
# File 'lib/packetgen/header/eap.rb', line 122 def initialize(={}) super calc_length if [:length].nil? end |
Instance Attribute Details
#body ⇒ Types::String, Header::Base
119 |
# File 'lib/packetgen/header/eap.rb', line 119 define_field :body, Types::String |
#code ⇒ Integer
Returns 8-bit EAP code.
85 |
# File 'lib/packetgen/header/eap.rb', line 85 define_field :code, Types::Int8Enum, enum: CODES |
#id ⇒ Integer
Returns 8-bit identifier.
89 |
# File 'lib/packetgen/header/eap.rb', line 89 define_field :id, Types::Int8 |
#length ⇒ Integer
Returns 16-bit length of EAP packet.
93 |
# File 'lib/packetgen/header/eap.rb', line 93 define_field :length, Types::Int16, default: 4 |
#type ⇒ Integer
This field is present only for Request or Response packets, with type different from Expanded Types (254).
99 100 101 |
# File 'lib/packetgen/header/eap.rb', line 99 define_field :type, Types::Int8Enum, enum: TYPES, optional: ->(eap) { eap.type? } |
Instance Method Details
#added_to_packet(packet) ⇒ void
This method returns an undefined value.
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).
219 220 221 222 223 |
# File 'lib/packetgen/header/eap.rb', line 219 def added_to_packet(packet) return if packet.respond_to? :eap packet.instance_eval("def eap(arg=nil); header(#{self.class}, arg); end") # def eap(arg=nil); header(EAP, arg); end end |
#calc_length ⇒ Integer
Calculate length field from content
203 204 205 |
# File 'lib/packetgen/header/eap.rb', line 203 def calc_length Base.calculate_and_set_length self end |
#desired_auth_type ⇒ Array<Integer>
Return an array of desired authentication types from a Nak packet
195 196 197 198 199 |
# File 'lib/packetgen/header/eap.rb', line 195 def desired_auth_type raise ParseError, 'not a Nak response' if (code != 2) && (type != 3) body.to_s.unpack('C*') end |
#failure? ⇒ Boolean
Is packet a failure?
188 189 190 |
# File 'lib/packetgen/header/eap.rb', line 188 def failure? code == CODES['Failure'] end |
#human_code ⇒ String
Get human readable code
155 156 157 |
# File 'lib/packetgen/header/eap.rb', line 155 def human_code self[:code].to_human end |
#human_type ⇒ String
Get human readable type
162 163 164 165 166 |
# File 'lib/packetgen/header/eap.rb', line 162 def human_type raise ParseError, 'not a Request nor a Response' unless type? self[:type].to_human end |
#old_read ⇒ Object
128 |
# File 'lib/packetgen/header/eap.rb', line 128 alias old_read read |
#read(str) ⇒ Dot11
Populate object from a binary string
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/packetgen/header/eap.rb', line 134 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 |
#reply! ⇒ self
Invert between a request and a response packet. Not action for others codes.
228 229 230 231 232 233 234 |
# File 'lib/packetgen/header/eap.rb', line 228 def reply! case self.code when 1 then self.code = 2 when 2 then self.code = 1 end self end |
#request? ⇒ Boolean
Is packet a request?
170 171 172 |
# File 'lib/packetgen/header/eap.rb', line 170 def request? code == CODES['Request'] end |
#response? ⇒ Boolean
Is packet a response?
176 177 178 |
# File 'lib/packetgen/header/eap.rb', line 176 def response? code == CODES['Response'] end |
#success? ⇒ Boolean
Is packet a success?
182 183 184 |
# File 'lib/packetgen/header/eap.rb', line 182 def success? code == CODES['Success'] end |
#type? ⇒ Boolean
Say is this EAP header has #type field
210 211 212 |
# File 'lib/packetgen/header/eap.rb', line 210 def type? [1, 2].include?(self.code) end |