Class: PacketGen::Header::IKE::KE

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

Overview

This class handles Key Exchange payloads, as defined in RFC 7296 §3.4

A KE 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        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   Diffie-Hellman Group Num    |           RESERVED            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                       Key Exchange Data                       ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

These specific fields are:

Create a KE payload

# Create a IKE packet with a KE payload
pkt = PacketGen.gen('IP').add('UDP').add('IKE')
# group name is taken from Transform::DH_* constants
pkt.add('IKE::KE', group: 'MODP4096')
# group number may also be used
pkt.ike_ke.group = 1
pkt.calc_length

Author:

  • Sylvain Daubert

Since:

  • 2.0.0

Constant Summary collapse

PAYLOAD_TYPE =

Payload type number

Since:

  • 2.0.0

34

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

#initialize(options = {}) ⇒ KE

Returns a new instance of KE.

Since:

  • 2.0.0



54
55
56
57
# File 'lib/packetgen/header/ike/ke.rb', line 54

def initialize(options={})
  super
  self.group = options[:group] if options[:group]
end

Instance Attribute Details

#group_numInteger

16-bit DH group number

Returns:

  • (Integer)


48
# File 'lib/packetgen/header/ike/ke.rb', line 48

define_field_before :content, :group_num, Types::Int16

#reservedInteger

16-bit reserved field

Returns:

  • (Integer)


52
# File 'lib/packetgen/header/ike/ke.rb', line 52

define_field_before :content, :reserved, Types::Int16, default: 0

Instance Method Details

#group=(value) ⇒ Integer

Set group

Parameters:

  • value (Integer, String)

    may be a String taken from Transform::DH_* constant names.

Returns:

  • (Integer)

Raises:

  • (ArgumentError)

Since:

  • 2.0.0



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/packetgen/header/ike/ke.rb', line 63

def group=(value)
  group = case value
          when Integer
            value
          else
            cname = "DH_#{value}"
            Transform.const_defined?(cname) ? Transform.const_get(cname) : nil
          end
  raise ArgumentError, "unknown group #{value.inspect}" unless group
  self[:group_num].value = group
end