Class: PacketGen::Plugin::IKE::KE

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

Overview

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

A KE 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        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   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

Constant Summary collapse

PAYLOAD_TYPE =

Payload type number

34

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 = {}) ⇒ KE

Returns a new instance of KE.



53
54
55
56
# File 'lib/packetgen/plugin/ike/ke.rb', line 53

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

Instance Attribute Details

#group_numInteger

16-bit DH group number

Returns:

  • (Integer)


47
# File 'lib/packetgen/plugin/ike/ke.rb', line 47

define_field_before :content, :group_num, PacketGen::Types::Int16

#reservedInteger

16-bit reserved field

Returns:

  • (Integer)


51
# File 'lib/packetgen/plugin/ike/ke.rb', line 51

define_field_before :content, :reserved, PacketGen::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)


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

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