Class: PacketGen::Header::IKE::IDi

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

Overview

This class handles Identification - Initiator payloads, denoted IDi (see RFC 7296, §3.5).

A ID payload consists of the IKE 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        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   ID Type     |                 RESERVED                      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                   Identification Data                         ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

These specific fields are:

Create a IDi payload

# Create a IKE packet with a IDi payload
pkt = PacketGen.gen('IP').add('UDP').add('IKE').add('IKE::IDi', type: 'FQDN')
pkt.ike_idi.content.read 'fqdn.example.org'
pkt.calc_length

Author:

  • Sylvain Daubert

Since:

  • 2.0.0

Direct Known Subclasses

IDr

Constant Summary collapse

PAYLOAD_TYPE =

Payload type number

Since:

  • 2.0.0

35
TYPES =

Since:

  • 2.0.0

{
  'IPV4_ADDR'   => 1,
  'FQDN'        => 2,
  'RFC822_ADDR' => 3,
  'IPV6_ADDR'   => 5,
  'DER_ASN1_DN' => 9,
  'DER_ASN1_GN' => 10,
  'KEY_ID'      => 11
}.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, #initialize, #read

Methods inherited from Base

#added_to_packet, bind, bind_header, calculate_and_set_length, #header_id, inherited, #initialize, #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, #initialize, #inspect, #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

This class inherits a constructor from PacketGen::Header::IKE::Payload

Instance Attribute Details

#reservedInteger

24-bit reserved field

Returns:

  • (Integer)


60
# File 'lib/packetgen/header/ike/id.rb', line 60

define_field_before :content, :reserved, Types::Int24

#typeInteger (readonly)

8-bit ID type

Returns:

  • (Integer)


56
# File 'lib/packetgen/header/ike/id.rb', line 56

define_field_before :content, :type, Types::Int8Enum, enum: TYPES

Instance Method Details

#human_contentString

Get human readable content, from #type

Returns:

  • (String)

Since:

  • 2.0.0



70
71
72
73
74
75
76
77
78
79
# File 'lib/packetgen/header/ike/id.rb', line 70

def human_content
  case type
  when TYPES['IPV4_ADDR'], TYPES['IPV4_ADDR']
    IPAddr.ntop(content)
  when TYPES['DER_ASN1_DN'], TYPES['DER_ASN1_GN']
    OpenSSL::X509::Name.new(content).to_s
  else
    content.inspect
  end
end

#human_typeString

Get ID type name

Returns:

  • (String)

Since:

  • 2.0.0



64
65
66
# File 'lib/packetgen/header/ike/id.rb', line 64

def human_type
  self[:type].to_human
end