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
TYPE_UNSUPPORTED_CRITICAL_PAYLOAD =

Unsupported critical payload

Since:

  • 2.0.0

1
TYPE_INVALID_IKE_SPI =

Invalid IKE SPI

Since:

  • 2.0.0

4
TYPE_INVALID_MAJOR_VERSION =

Invalid major version

Since:

  • 2.0.0

5
TYPE_INVALID_SYNTAX =

Invalid syntax

Since:

  • 2.0.0

7
TYPE_INVALID_MESSAGE_ID =

Invalid message ID

Since:

  • 2.0.0

9
TYPE_INVALID_SPI =

Invalid SPI

Since:

  • 2.0.0

11
TYPE_NO_PROPOSAL_CHOSEN =

No proposal chosen (none of the proposed crypto suites was acceptable)

Since:

  • 2.0.0

14
TYPE_INVALID_KE_PAYLOAD =

Invalid KE payload

Since:

  • 2.0.0

17
TYPE_AUTHENTICATION_FAILED =

Authentication failed

Since:

  • 2.0.0

24
TYPE_SINGLE_PAIR_REQUIRED =

Single pair required

Since:

  • 2.0.0

34
TYPE_NO_ADDITIONAL_SAS =

No additional SAs

Since:

  • 2.0.0

35
TYPE_INTERNAL_ADDRESS_FAILURE =

Internal address failture

Since:

  • 2.0.0

36
TYPE_FAILED_CP_REQUIRED =

Failed CP required

Since:

  • 2.0.0

37
TYPE_TS_UNACCEPTABLE =

traffic selectors unacceptable

Since:

  • 2.0.0

38
TYPE_INVALID_SELECTORS =

invalid selectors

Since:

  • 2.0.0

39
TYPE_TEMPORARY_FAILURE =

Temporary failure

Since:

  • 2.0.0

43
TYPE_CHILD_SA_NOT_FOUND =

Child SA not found

Since:

  • 2.0.0

44
TYPE_INITIAL_CONTACT =

Initial contact

Since:

  • 2.0.0

16384
TYPE_SET_WINDOW_SIZE =

Set window size

Since:

  • 2.0.0

16385
TYPE_ADDITIONAL_TS_POSSIBLE =

Additional traffic selector possible

Since:

  • 2.0.0

16386
TYPE_IPCOMP_SUPPORTED =

IPcomp supported

Since:

  • 2.0.0

16387
TYPE_NAT_DETECTION_SOURCE_IP =

NAT detection source IP

Since:

  • 2.0.0

16388
TYPE_NAT_DETECTION_DESTINATION_IP =

NAT detection destination IP

Since:

  • 2.0.0

16389
16390
TYPE_USE_TRANSPORT_MODE =

Use transport mode (tunnel mode is default)

Since:

  • 2.0.0

16391
TYPE_HTTP_CERT_LOOKUP_SUPPORTED =

HTTP certificate look up supported

Since:

  • 2.0.0

16392
TYPE_REKEY_SA =

Rekey SA

Since:

  • 2.0.0

16393
TYPE_ESP_TFC_PADDING_NOT_SUPPORTED =

ESP TFC paddin not supported

Since:

  • 2.0.0

16394
TYPE_NON_FIRST_FRAGMENTS_ALSO =

Non-first fragment also

Since:

  • 2.0.0

16395

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

bind_header, #header_id, inherited, #ip_header, known_headers, #method_name, #parse?, protocol_name, #protocol_name

Methods inherited from Types::Fields

#[], #[]=, #body=, define_bit_fields_on, define_field, define_field_after, define_field_before, delete_field, #fields, #force_binary, inherited, #is_optional?, #is_present?, #optional_fields, #read, #sz, #to_h, #to_s

Constructor Details

#initialize(options = {}) ⇒ Notify

Returns a new instance of Notify.

Since:

  • 2.0.0



140
141
142
143
144
145
146
147
148
# File 'lib/packetgen/header/ike/notify.rb', line 140

def initialize(options={})
  if options[:spi] and 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)


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

define_field_before :content, :message_type, Types::Int16

#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)


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

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)


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

define_field_before :content, :spi, Types::String,
builder: ->(t) { Types::String.new('', length_from: t[: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)


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

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



192
193
194
195
196
197
# File 'lib/packetgen/header/ike/notify.rb', line 192

def human_message_type
  name = self.class.constants.grep(/TYPE_/).
         select { |c| self.class.const_get(c) == type }.
         first || "type #{type}"
  name.to_s.sub(/TYPE_/, '')
end

#human_protocolString

Get protocol name

Returns:

  • (String)

Since:

  • 2.0.0



183
184
185
186
187
188
# File 'lib/packetgen/header/ike/notify.rb', line 183

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

#inspectString

Returns:

  • (String)

Since:

  • 2.0.0



201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/packetgen/header/ike/notify.rb', line 201

def inspect
  str = Inspect.dashed_line(self.class, 2)
  fields.each do |attr|
    next if attr == :body
    if i(protocol message_type).include? attr
      str << Inspect.shift_level(2)
      str << Inspect::FMT_ATTR % [self[attr].class.to_s.sub(/.*::/, ''), attr,
                                  send("human_#{attr}")]
    else
      str << Inspect.inspect_attribute(attr, self[attr], 2)
    end
  end
  str
end