Class: PacketGen::Plugin::IKE::Notify

Inherits:
Payload
  • Object
show all
Defined in:
lib/packetgen/plugin/ike/notify.rb

Overview

This class handles Notify payloads, as defined in RFC 7296 §3.10.

A Notify payload contains a generic payload Plugin (see Payload) and some specific fields:

                     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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload  |C|  RESERVED   |         Payload Length        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Protocol ID  |   SPI Size    |      Notify Message Type      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                Security Parameter Index (SPI)                 ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                       Notification Data                       ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

These specific fields are:

Create a Notify payload

# Create a IKE packet with a Notify payload
pkt = PacketGen.gen('IP').add('UDP').add('IKE').add('IKE::Notify', protocol: 'IKE', type: 'INVALID_SYNTAX')
pkt.ike_notify.spi      # => ""
pkt.ike_notify.content  # => ""
pkt.calc_length

Create a Notify payload with a SPI

# Create a IKE packet with a Notify payload
pkt = PacketGen.gen('IP').add('UDP').add('IKE').add('IKE::Notify', protocol: 'ESP', spi_size: 4, type: 'INVALID_SYNTAX')
pkt.ike_notify.spi.read BinStruct::Int32.new(0x12345678).to_s
pkt.calc_length
@author Sylvain Daubert

Constant Summary collapse

PAYLOAD_TYPE =

Payload type number

41
TYPES =

Message types

{
  'UNSUPPORTED_CRITICAL_PAYLOAD' => 1,
  'INVALID_IKE_SPI' => 4,
  'INVALID_MAJOR_VERSION' => 5,
  'INVALID_SYNTAX' => 7,
  'INVALID_MESSAGE_ID' => 9,
  'INVALID_SPI' => 11,
  'NO_PROPOSAL_CHOSEN' => 14,
  'INVALID_KE_PAYLOAD' => 17,
  'AUTHENTICATION_FAILED' => 24,
  'SINGLE_PAIR_REQUIRED' => 34,
  'NO_ADDITIONAL_SAS' => 35,
  'INTERNAL_ADDRESS_FAILURE' => 36,
  'FAILED_CP_REQUIRED' => 37,
  'TS_UNACCEPTABLE' => 38,
  'INVALID_SELECTORS' => 39,
  'TEMPORARY_FAILURE' => 43,
  'CHILD_SA_NOT_FOUND' => 44,
  'INITIAL_CONTACT' => 16_384,
  'SET_WINDOW_SIZE' => 16_385,
  'ADDITIONAL_TS_POSSIBLE' => 16_386,
  'IPCOMP_SUPPORTED' => 16_387,
  'NAT_DETECTION_SOURCE_IP' => 16_388,
  'NAT_DETECTION_DESTINATION_IP' => 16_389,
  'COOKIE' => 16_390,
  'USE_TRANSPORT_MODE' => 16_391,
  'HTTP_CERT_LOOKUP_SUPPORTED' => 16_392,
  'REKEY_SA' => 16_393,
  'ESP_TFC_PADDING_NOT_SUPPORTED' => 16_394,
  'NON_FIRST_FRAGMENTS_ALSO' => 16_395,
}.freeze

Instance Attribute Summary collapse

Attributes inherited from Payload

#content, #critical, #flags, #hreserved, #length, #next

Instance Method Summary collapse

Methods inherited from Payload

#calc_length, protocol_name

Constructor Details

#initialize(options = {}) ⇒ Notify

Returns a new instance of Notify.



118
119
120
121
122
123
124
# File 'lib/packetgen/plugin/ike/notify.rb', line 118

def initialize(options={})
  options[:spi_size] = options[:spi].size if options[:spi] && options[:spi_size].nil?
  super
  self.protocol = options[:protocol] if options[:protocol]
  self.message_type = options[:message_type] if options[:message_type]
  self.message_type = options[:type] if options[:type]
end

Instance Attribute Details

#message_typeInteger Also known as: type

16-bit notify message type. Specifies the type of notification message.

Returns:

  • (Integer)


108
# File 'lib/packetgen/plugin/ike/notify.rb', line 108

define_attr_before :content, :message_type, BinStruct::Int16Enum, enum: TYPES, default: 0

#protocolInteger (readonly)

8-bit protocol ID. If this notification concerns an existing SA whose SPI is given in the SPI field, this field indicates the type of that SA. For notifications concerning Child SAs, this field MUST contain either (2) to indicate AH or (3) to indicate ESP. Of the notifications defined in this document, the SPI is included only with INVALID_SELECTORS, REKEY_SA, and CHILD_SA_NOT_FOUND. If the SPI field is empty, this field MUST be sent as zero and MUST be ignored on receipt.

Returns:

  • (Integer)


96
# File 'lib/packetgen/plugin/ike/notify.rb', line 96

define_attr_before :content, :protocol, BinStruct::Int8Enum, enum: PROTOCOLS

#spiString

the sending entity’s SPI. When the #spi_size field is zero, this field is not present in the proposal.

Returns:

  • (String)


113
114
# File 'lib/packetgen/plugin/ike/notify.rb', line 113

define_attr_before :content, :spi, BinStruct::String,
builder: ->(h, t) { t.new(length_from: h[:spi_size]) }

#spi_sizeInteger

8-bit SPI size. Give size of SPI field. Length in octets of the SPI as defined by the IPsec protocol ID or zero if no SPI is applicable. For a notification concerning the IKE SA, the SPI Size MUST be zero and the field must be empty.Set to 0 for an initial IKE SA negotiation, as SPI is obtained from outer Plugin.

Returns:

  • (Integer)


104
# File 'lib/packetgen/plugin/ike/notify.rb', line 104

define_attr_before :content, :spi_size, BinStruct::Int8, default: 0

Instance Method Details

#human_message_typeString Also known as: human_type

Get message type name

Returns:

  • (String)


136
137
138
# File 'lib/packetgen/plugin/ike/notify.rb', line 136

def human_message_type
  self[:message_type].to_human
end

#human_protocolString

Get protocol name

Returns:

  • (String)


130
131
132
# File 'lib/packetgen/plugin/ike/notify.rb', line 130

def human_protocol
  self[:protocol].to_human
end

#inspectString

Returns:

  • (String)


142
143
144
145
146
147
148
149
# File 'lib/packetgen/plugin/ike/notify.rb', line 142

def inspect
  super do |attr|
    next unless attr == :protocol

    str = PacketGen::Inspect.shift_level
    str << (PacketGen::Inspect::FMT_ATTR % [self[attr].class.to_s.sub(/.*::/, ''), attr, human_protocol])
  end
end