Class: PacketGen::Header::IKE::Notify

Inherits:
Payload show all
Defined in:
lib/packetgen/header/ike/notify.rb

Overview

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

A Notify payload contains a generic payload header (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 PacketGen::Types::Int32.new(0x12345678).to_s
pkt.calc_length
@author Sylvain Daubert

Since:

  • 2.0.0

Constant Summary collapse

PAYLOAD_TYPE =

Payload type number

Since:

  • 2.0.0

41
TYPES =

Message types

Since:

  • 2.0.0

{
  '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

Attributes inherited from Base

#packet

Instance Method Summary collapse

Methods inherited from Payload

#base_read, #calc_length, #read

Methods inherited from Base

#added_to_packet, bind, bind_header, calculate_and_set_length, #header_id, inherited, #ip_header, known_headers, #ll_header, #method_name, #parse?, #protocol_name, protocol_name

Methods inherited from Types::Fields

#[], #[]=, #bits_on, #body=, define_bit_fields_on, define_field, define_field_after, define_field_before, delete_field, fields, #fields, #force_binary, inherited, #is_optional?, #is_present?, #offset_of, #optional?, #optional_fields, #present?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field

Constructor Details

#initialize(options = {}) ⇒ Notify

Returns a new instance of Notify.

Since:

  • 2.0.0



119
120
121
122
123
124
125
126
127
# File 'lib/packetgen/header/ike/notify.rb', line 119

def initialize(options={})
  if options[:spi] && options[:spi_size].nil?
    options[:spi_size] = options[:spi].size
  end
  super
  self.protocol = options[:protocol] if options[:protocol]
  self.message_type = options[:message_type] if options[:message_type]
  self.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)


109
# File 'lib/packetgen/header/ike/notify.rb', line 109

define_field_before :content, :message_type, Types::Int16Enum, enum: TYPES, default: 0

#protocolInteger

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)


97
# File 'lib/packetgen/header/ike/notify.rb', line 97

define_field_before :content, :protocol, Types::Int8

#spiString

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

Returns:

  • (String)


114
115
# File 'lib/packetgen/header/ike/notify.rb', line 114

define_field_before :content, :spi, Types::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 header.

Returns:

  • (Integer)


105
# File 'lib/packetgen/header/ike/notify.rb', line 105

define_field_before :content, :spi_size, Types::Int8, default: 0

Instance Method Details

#human_message_typeString Also known as: human_type

Get message type name

Returns:

  • (String)

Since:

  • 2.0.0



156
157
158
# File 'lib/packetgen/header/ike/notify.rb', line 156

def human_message_type
  self[:message_type].to_human
end

#human_protocolString

Get protocol name

Returns:

  • (String)

Since:

  • 2.0.0



148
149
150
151
152
# File 'lib/packetgen/header/ike/notify.rb', line 148

def human_protocol
  name = IKE.constants.grep(/PROTO/)
            .detect { |c| IKE.const_get(c) == protocol } || "proto #{protocol}"
  name.to_s.sub(/PROTO_/, '')
end

#inspectString

Returns:

  • (String)

Since:

  • 2.0.0



162
163
164
165
166
167
168
169
170
# File 'lib/packetgen/header/ike/notify.rb', line 162

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

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