Class: PacketGen::Plugin::IKE::SAProposal

Inherits:
Types::Fields
  • Object
show all
Defined in:
lib/packetgen/plugin/ike/sa.rb

Overview

SA Proposal, as defined in RFC 7296 §3.3.1

                     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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Last Substruc |   RESERVED    |         Proposal Length       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Proposal Num  |  Protocol ID  |    SPI Size   |Num  Transforms|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
~                        SPI (variable)                         ~
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                        <Transforms>                           ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Create a proposal

# using protocol name
proposal = PacketGen::Plugin::IKE::Proposal.new(num: 1, protocol: 'IKE')
# using integer values
proposal = PacketGen::Plugin::IKE::Proposal.new(num: 1, protocol: 1)

Add transforms to a proposal

# using a Transform object
trans = PacketGen::Plugin::IKE::Transform.new(type: 'ENCR', id: '3DES')
proposal.transforms << trans
# using a hash
proposal.transforms << { type: 'ENCR', id: '3DES' }

Author:

  • Sylvain Daubert

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SAProposal

Returns a new instance of SAProposal.



379
380
381
382
383
384
385
386
# File 'lib/packetgen/plugin/ike/sa.rb', line 379

def initialize(options={})
  if options[:spi] && options[:spi_size].nil?
    options[:spi_size] = options[:spi].size
  end
  super
  self.length = sz unless options[:length]
  self.protocol = options[:protocol] if options[:protocol]
end

Instance Attribute Details

#lastInteger

8-bit last substructure. Specifies whether or not this is the last Proposal Substructure in the SA. This field has a value of 0 if this was the last Proposal Substructure, and a value of 2 if there are more Proposal Substructures.

Returns:

  • (Integer)


337
# File 'lib/packetgen/plugin/ike/sa.rb', line 337

define_field :last, PacketGen::Types::Int8

#lengthInteger

16-bit proposal length

Returns:

  • (Integer)


345
# File 'lib/packetgen/plugin/ike/sa.rb', line 345

define_field :length, PacketGen::Types::Int16

#numInteger

8-bit proposal number. When a proposal is made, the first proposal in an SA payload MUST be 1, and subsequent proposals MUST be one more than the previous proposal (indicating an OR of the two proposals). When a proposal is accepted, the proposal number in the SA payload MUST match the number on the proposal sent that was accepted.

Returns:

  • (Integer)


354
# File 'lib/packetgen/plugin/ike/sa.rb', line 354

define_field :num, PacketGen::Types::Int8, default: 1

#num_transInteger

8-bit number of transformations

Returns:

  • (Integer)


368
# File 'lib/packetgen/plugin/ike/sa.rb', line 368

define_field :num_trans, PacketGen::Types::Int8, default: 0

#protocolInteger (readonly)

8-bit protocol ID. Specify IPsec protocol currently negociated. May 1 (IKE), 2 (AH) or 3 (ESP).

Returns:

  • (Integer)


359
# File 'lib/packetgen/plugin/ike/sa.rb', line 359

define_field :protocol, PacketGen::Types::Int8Enum, enum: PROTOCOLS

#reservedInteger

8-bit reserved field

Returns:

  • (Integer)


341
# File 'lib/packetgen/plugin/ike/sa.rb', line 341

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


373
# File 'lib/packetgen/plugin/ike/sa.rb', line 373

define_field :spi, PacketGen::Types::String, builder: ->(h, t) { t.new(length_from: h[:spi_size]) }

#spi_sizeInteger

8-bit SPI size. Give size of SPI field. Set to 0 for an initial IKE SA negotiation, as SPI is obtained from outer Plugin.

Returns:

  • (Integer)


364
# File 'lib/packetgen/plugin/ike/sa.rb', line 364

define_field :spi_size, PacketGen::Types::Int8, default: 0

#transformsTransforms

8-bit set of tranforms for this proposal

Returns:



377
# File 'lib/packetgen/plugin/ike/sa.rb', line 377

define_field :transforms, Transforms, builder: ->(h, t) { t.new(counter: h[:num_trans]) }

Instance Method Details

#calc_lengthInteger

Compute length and set #length field

Returns:

  • (Integer)

    new length



390
391
392
393
# File 'lib/packetgen/plugin/ike/sa.rb', line 390

def calc_length
  transforms.each(&:calc_length)
  PacketGen::Header::Base.calculate_and_set_length self
end

#human_protocolString

Get protocol name

Returns:

  • (String)


410
411
412
# File 'lib/packetgen/plugin/ike/sa.rb', line 410

def human_protocol
  self[:protocol].to_human
end

#last?Boolean?

Say if this proposal is the last one (from #last field)

Returns:

  • (Boolean, nil)

    returns a Boolean when #last has defined value (0 => true, 2 => false), else nil is returned.



417
418
419
420
421
422
423
424
# File 'lib/packetgen/plugin/ike/sa.rb', line 417

def last?
  case last
  when 0
    true
  when 2
    false
  end
end

#to_humanString

Get a human readable string

Returns:

  • (String)


397
398
399
400
401
402
403
404
405
406
# File 'lib/packetgen/plugin/ike/sa.rb', line 397

def to_human
  str = "##{num} #{human_protocol}".dup
  case spi_size
  when 4
    str << '(spi:0x%08x)' % PacketGen::Types::Int32.new.read(spi).to_i
  when 8
    str << '(spi:0x%016x)' % PacketGen::Types::Int64.new.read(spi).to_i
  end
  str << ":#{transforms.to_human}"
end