Class: 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 more...
Overview
Extensible Authentication Protocol (EAP), RFC 3748
A EAP header has:
-
a #code field (
BinStruct::Int8Enum
), -
a #id field (
BinStruct::Int8
), -
a #length field (
BinStruct::Int16
).
Request (code 1) and Response (code 2) packets also have:
-
a #type field (
BinStruct::Int8Enum
).
And Expanded Types (type 254) packets also have:
-
a #vendor_id field (
BinStruct::Int24
), -
a #vendor_type field (
BinStruct::Int32
).
Finally, all packets have a #body (BinStruct::String
).
Specialized headers
Some EAP has a specialized class:
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 ⇒ BinStruct::String, Headerable
EAP packet body.
-
#code ⇒ Integer
8-bit EAP code.
-
#id ⇒ Integer
8-bit identifier.
-
#length ⇒ Integer
16-bit length of EAP packet.
-
#type ⇒ Integer
8-bit request or response type.
-
#vendor_id ⇒ Integer
24-bit vendor ID.
-
#vendor_type ⇒ Integer
32-bit vendor type.
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
-
#nak? ⇒ Boolean
Is packet a NAK?.
- #old_read ⇒ Object
-
#read(str) ⇒ EAP
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, #to_s
Constructor Details
permalink #initialize(options = {}) ⇒ EAP
139 140 141 142 |
# File 'lib/packetgen/header/eap.rb', line 139 def initialize(={}) super calc_length if [:length].nil? end |
Instance Attribute Details
permalink #body ⇒ BinStruct::String, Headerable
EAP packet body
136 |
# File 'lib/packetgen/header/eap.rb', line 136 define_attr :body, BinStruct::String |
permalink #code ⇒ Integer
8-bit EAP code. See known EAP codes
96 |
# File 'lib/packetgen/header/eap.rb', line 96 define_attr :code, BinStruct::Int8Enum, enum: CODES |
permalink #id ⇒ Integer
8-bit identifier
101 |
# File 'lib/packetgen/header/eap.rb', line 101 define_attr :id, BinStruct::Int8 |
permalink #length ⇒ Integer
16-bit length of EAP packet
106 |
# File 'lib/packetgen/header/eap.rb', line 106 define_attr :length, BinStruct::Int16, default: 4 |
permalink #type ⇒ Integer
8-bit request or response type. This field is present only for Request or Response packets. See known EAP types.
113 114 115 |
# File 'lib/packetgen/header/eap.rb', line 113 define_attr :type, BinStruct::Int8Enum, enum: TYPES, optional: lambda(&:type?) |
permalink #vendor_id ⇒ Integer
24-bit vendor ID. This field is present only for Request or Response packets, with type equal to Expanded Types (254).
122 123 |
# File 'lib/packetgen/header/eap.rb', line 122 define_attr :vendor_id, BinStruct::Int24, optional: ->(eap) { eap.type? && (eap.type == 254) } |
permalink #vendor_type ⇒ Integer
32-bit vendor type. This field is present only for Request or Response packets, with type equal to Expanded Types (254).
130 131 |
# File 'lib/packetgen/header/eap.rb', line 130 define_attr :vendor_type, BinStruct::Int32, optional: ->(eap) { eap.type? && (eap.type == 254) } |
Instance Method Details
permalink #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).
244 245 246 247 248 |
# File 'lib/packetgen/header/eap.rb', line 244 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 |
permalink #calc_length ⇒ Integer
Calculate length field from content
228 229 230 |
# File 'lib/packetgen/header/eap.rb', line 228 def calc_length Base.calculate_and_set_length(self) end |
permalink #desired_auth_type ⇒ Array<Integer>
Return an array of desired authentication types from a Nak packet
220 221 222 223 224 |
# File 'lib/packetgen/header/eap.rb', line 220 def desired_auth_type raise ParseError, 'not a Nak response' unless nak? body.to_s.unpack('C*') end |
permalink #failure? ⇒ Boolean
Is packet a failure?
205 206 207 |
# File 'lib/packetgen/header/eap.rb', line 205 def failure? code == CODES['Failure'] end |
permalink #human_code ⇒ String
Get human readable code
172 173 174 |
# File 'lib/packetgen/header/eap.rb', line 172 def human_code self[:code].to_human end |
permalink #human_type ⇒ String
Get human readable type
179 180 181 182 183 |
# File 'lib/packetgen/header/eap.rb', line 179 def human_type raise ParseError, 'not a Request nor a Response' unless type? self[:type].to_human end |
permalink #nak? ⇒ Boolean
Is packet a NAK?
213 214 215 |
# File 'lib/packetgen/header/eap.rb', line 213 def nak? (code == 2) && (type == 3) end |
permalink #old_read ⇒ Object
145 |
# File 'lib/packetgen/header/eap.rb', line 145 alias old_read read |
permalink #read(str) ⇒ EAP
Populate object from a binary string
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/packetgen/header/eap.rb', line 151 def read(str) super 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 |
permalink #reply! ⇒ self
Invert between a request and a response packet. Not action for others codes.
253 254 255 256 257 258 259 |
# File 'lib/packetgen/header/eap.rb', line 253 def reply! case self.code when 1 then self.code = 2 when 2 then self.code = 1 end self end |
permalink #request? ⇒ Boolean
Is packet a request?
187 188 189 |
# File 'lib/packetgen/header/eap.rb', line 187 def request? code == CODES['Request'] end |
permalink #response? ⇒ Boolean
Is packet a response?
193 194 195 |
# File 'lib/packetgen/header/eap.rb', line 193 def response? code == CODES['Response'] end |
permalink #success? ⇒ Boolean
Is packet a success?
199 200 201 |
# File 'lib/packetgen/header/eap.rb', line 199 def success? code == CODES['Success'] end |
permalink #type? ⇒ Boolean
Say is this EAP header has #type field
235 236 237 |
# File 'lib/packetgen/header/eap.rb', line 235 def type? [1, 2].include?(self.code) end |