Class: PacketGen::Plugin::IKE
- Inherits:
-
Header::Base
- Object
- Header::Base
- PacketGen::Plugin::IKE
- Defined in:
- lib/packetgen/plugin/ike.rb,
lib/packetgen/plugin/ike/vendor_id.rb,
lib/packetgen/plugin/ike/payload.rb,
lib/packetgen/plugin/ike/certreq.rb,
lib/packetgen/plugin/ike/notify.rb,
lib/packetgen/plugin/ike/nonce.rb,
lib/packetgen/plugin/ike/cert.rb,
lib/packetgen/plugin/ike/auth.rb,
lib/packetgen/plugin/ike/ts.rb,
lib/packetgen/plugin/ike/sk.rb,
lib/packetgen/plugin/ike/sa.rb,
lib/packetgen/plugin/ike/ke.rb,
lib/packetgen/plugin/ike/id.rb
Overview
IKE is the Internet Key Exchange protocol (RFC 7296). Ony IKEv2 is supported.
A IKE Plugin consists of a Plugin, and a set of payloads. This class handles IKE Plugin. For payloads, see Payload.
IKE Plugin
The format of a IKE Plugin is shown below:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| IKE SA Initiator's SPI |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| IKE SA Responder's SPI |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload | MjVer | MnVer | Exchange Type | Flags |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Message ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
A IKE Plugin consists of:
-
a IKE SA initiator SPI (#init_spi, BinStruct::Int64 type),
-
a IKE SA responder SPI (#resp_spi, BinStruct::Int64 type),
-
a Next Payload field (#next, BinStruct::Int8 type),
-
a Version field (#version, BinStruct::Int8 type, with first 4-bit field as major number, and last 4-bit field as minor number),
-
a Exchange type (#exchange_type, BinStruct::Int8 type),
-
a #flags field (BinStruct::Int8 type),
-
a Message ID (#message_id, BinStruct::Int32 type),
-
and a #length (BinStruct::Int32 type).
Create a IKE Plugin
Standalone
ike = PacketGen::Plugin::IKE.new
Classical IKE packet
pkt = PacketGen.gen('IP').add('UDP').add('IKE')
# access to IKE Plugin
pkt.ike # => PacketGen::Plugin::IKE
NAT-T IKE packet
# NonESPMarker is used to insert a 32-bit null field between UDP Plugin
# and IKE one to differentiate it from ESP-in-UDP (see RFC 3948)
pkt = PacketGen.gen('IP').add('UDP').add('NonESPMarker').add('IKE)
Defined Under Namespace
Classes: Attribute, Attributes, Auth, Cert, CertReq, IDi, IDr, KE, Nonce, Notify, Payload, SA, SAProposal, SAProposals, SK, TSi, TSr, TrafficSelector, TrafficSelectors, Transform, Transforms, VendorID
Constant Summary collapse
- UDP_PORT1 =
Classical well-known UDP port for IKE
500
- UDP_PORT2 =
Well-known UDP port for IKE when NAT is detected
4500
- PROTOCOLS =
Protocols supported by IKE
{ 'IKE' => 1, 'AH' => 2, 'ESP' => 3 }.freeze
- EXCHANGE_TYPES =
Known echange types
{ 'IKE_SA_INIT' => 34, 'IKE_AUTH' => 35, 'CREATE_CHILD_SA' => 36, 'INFORMATIONAL' => 37 }.freeze
Instance Attribute Summary collapse
-
#exchange_type ⇒ Integer
(also: #type)
readonly
8-bit exchange type.
-
#flag_i ⇒ Boolean
bit set in message sent by the original initiator.
-
#flag_r ⇒ Boolean
indicate this message is a response to a message containing the same Message ID.
-
#flag_v ⇒ Boolean
version flag.
-
#flags. See {#flag_r}, {#flag_v} and {#flag_i}.({#flag_r}, {#flag_v} and {#flag_i}.) ⇒ Integer
8-bit flags.
-
#init_spi ⇒ Integer
64-bit initiator SPI.
-
#length ⇒ Integer
32-bit length of total message (Plugin + payloads).
-
#message_id ⇒ Integer
32-bit message ID.
-
#mjver ⇒ Integer
4-bit major version value (#version‘s 4 most significant bits).
-
#mnver ⇒ Integer
4-bit minor version value (#version‘s 4 least significant bits).
-
#next ⇒ Integer
8-bit next payload type.
-
#resp_spi ⇒ Integer
64-bit responder SPI.
- #rsv1 ⇒ Integer
- #rsv2 ⇒ Integer
-
#version ⇒ Integer
8-bit IKE version.
Instance Method Summary collapse
- #added_to_packet(packet) ⇒ void private
-
#calc_length ⇒ Integer
Calculate length field.
-
#human_exchange_type ⇒ String
(also: #human_type)
Get exchange type name.
-
#initialize(options = {}) ⇒ IKE
constructor
A new instance of IKE.
- #inspect ⇒ String
-
#payloads ⇒ Array<Payload>
IKE payloads.
-
#reply! ⇒ self
Toggle
I
andR
flags.
Constructor Details
#initialize(options = {}) ⇒ IKE
Returns a new instance of IKE.
152 153 154 155 156 157 |
# File 'lib/packetgen/plugin/ike.rb', line 152 def initialize(={}) super calc_length unless [:length] self.type = [:type] if [:type] self.type = [:exchange_type] if [:exchange_type] end |
Instance Attribute Details
#exchange_type ⇒ Integer (readonly) Also known as: type
8-bit exchange type
119 |
# File 'lib/packetgen/plugin/ike.rb', line 119 define_attr :exchange_type, BinStruct::Int8Enum, enum: EXCHANGE_TYPES |
#flag_i ⇒ Boolean
bit set in message sent by the original initiator
136 |
# File 'lib/packetgen/plugin/ike.rb', line 136 define_bit_attr :flags, rsv1: 2, flag_r: 1, flag_v: 1, flag_i: 1, rsv2: 3 |
#flag_r ⇒ Boolean
indicate this message is a response to a message containing the same Message ID
136 |
# File 'lib/packetgen/plugin/ike.rb', line 136 define_bit_attr :flags, rsv1: 2, flag_r: 1, flag_v: 1, flag_i: 1, rsv2: 3 |
#flag_v ⇒ Boolean
version flag. Ignored by IKEv2 peers, and should be set to 0
136 |
# File 'lib/packetgen/plugin/ike.rb', line 136 define_bit_attr :flags, rsv1: 2, flag_r: 1, flag_v: 1, flag_i: 1, rsv2: 3 |
#flags. See {#flag_r}, {#flag_v} and {#flag_i}.({#flag_r}, {#flag_v} and {#flag_i}.) ⇒ Integer
8-bit flags
136 |
# File 'lib/packetgen/plugin/ike.rb', line 136 define_bit_attr :flags, rsv1: 2, flag_r: 1, flag_v: 1, flag_i: 1, rsv2: 3 |
#init_spi ⇒ Integer
64-bit initiator SPI
97 |
# File 'lib/packetgen/plugin/ike.rb', line 97 define_attr :init_spi, BinStruct::Int64 |
#length ⇒ Integer
32-bit length of total message (Plugin + payloads)
144 |
# File 'lib/packetgen/plugin/ike.rb', line 144 define_attr :length, BinStruct::Int32 |
#message_id ⇒ Integer
32-bit message ID
140 |
# File 'lib/packetgen/plugin/ike.rb', line 140 define_attr :message_id, BinStruct::Int32 |
#mjver ⇒ Integer
4-bit major version value (#version‘s 4 most significant bits)
115 |
# File 'lib/packetgen/plugin/ike.rb', line 115 define_bit_attr :version, default: 0x20, mjver: 4, mver: 4 |
#mnver ⇒ Integer
4-bit minor version value (#version‘s 4 least significant bits)
115 |
# File 'lib/packetgen/plugin/ike.rb', line 115 define_bit_attr :version, default: 0x20, mjver: 4, mver: 4 |
#next ⇒ Integer
8-bit next payload type
105 |
# File 'lib/packetgen/plugin/ike.rb', line 105 define_attr :next, BinStruct::Int8 |
#resp_spi ⇒ Integer
64-bit responder SPI
101 |
# File 'lib/packetgen/plugin/ike.rb', line 101 define_attr :resp_spi, BinStruct::Int64 |
#rsv1 ⇒ Integer
136 |
# File 'lib/packetgen/plugin/ike.rb', line 136 define_bit_attr :flags, rsv1: 2, flag_r: 1, flag_v: 1, flag_i: 1, rsv2: 3 |
#rsv2 ⇒ Integer
136 |
# File 'lib/packetgen/plugin/ike.rb', line 136 define_bit_attr :flags, rsv1: 2, flag_r: 1, flag_v: 1, flag_i: 1, rsv2: 3 |
#version ⇒ Integer
8-bit IKE version
115 |
# File 'lib/packetgen/plugin/ike.rb', line 115 define_bit_attr :version, default: 0x20, mjver: 4, mver: 4 |
Instance Method Details
#added_to_packet(packet) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method is used internally by PacketGen and should not be directly called
This method returns an undefined value.
215 216 217 218 219 220 221 222 223 224 |
# File 'lib/packetgen/plugin/ike.rb', line 215 def added_to_packet(packet) return unless packet.is? 'UDP' return unless packet.udp.sport.zero? packet.udp.sport = if packet.is?('NonESPMarker') UDP_PORT2 else UDP_PORT1 end end |
#calc_length ⇒ Integer
Calculate length field
171 172 173 |
# File 'lib/packetgen/plugin/ike.rb', line 171 def calc_length PacketGen::Header::Base.calculate_and_set_length self end |
#human_exchange_type ⇒ String Also known as: human_type
Get exchange type name
164 165 166 |
# File 'lib/packetgen/plugin/ike.rb', line 164 def human_exchange_type self[:exchange_type].to_human end |
#inspect ⇒ String
188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/packetgen/plugin/ike.rb', line 188 def inspect super do |attr| case attr when :flags str_flags = +'' %w[r v i].each do |flag| str_flags << (send("flag_#{flag}?") ? flag.upcase : '.') end str = PacketGen::Inspect.shift_level str << (PacketGen::Inspect::FMT_ATTR % [self[attr].class.to_s.sub(/.*::/, ''), attr, str_flags]) end end end |
#payloads ⇒ Array<Payload>
IKE payloads
177 178 179 180 181 182 183 184 185 |
# File 'lib/packetgen/plugin/ike.rb', line 177 def payloads payloads = [] body = self.body while body.is_a?(Payload) payloads << body body = body.body end payloads end |
#reply! ⇒ self
Toggle I
and R
flags.
204 205 206 207 208 |
# File 'lib/packetgen/plugin/ike.rb', line 204 def reply! self.flag_r = !self.flag_r? self.flag_i = !self.flag_i? self end |