Class: PacketGen::Plugin::IKE::SA

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

Overview

This class handles Security Assocation payloads, as defined in RFC 7296 §3.3.

A SA payload contains a generic payload Plugin (see Payload) and a set of SAProposal (#proposals field, which is a SAProposals object):

                     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        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                          <Proposals>                          ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Create a SA payload

# Create a IKE packet with a SA payload
pkt = PacketGen.gen('IP').add('UDP').add('IKE').add('IKE::SA')
# add a proposal. Protocol name is taken from SAProposal::PROTO_* constants
pkt.ike_sa.proposals << { num: 1, protocol: 'ESP' }
# add a transform to this proposal.
# type name is taken from Transform::TYPE_* constants.
# ID is taken from Transform::<TYPE>_* constants.
pkt.ike_sa.proposals.first.transforms << { type: 'ENCR', id: 'AES_CTR' }
# and finally, add an attribute to this transform (here, KEY_SIZE = 128 bits)
pkt.ike_sa.proposals[0].transforms[0].attributes << { type: 0x800e, value: 128 }
pkt.calc_length

Author:

  • Sylvain Daubert

Constant Summary collapse

PAYLOAD_TYPE =

Payload type number

33

Instance Attribute Summary collapse

Attributes inherited from Payload

#content, #critical, #flags, #hreserved, #length, #next

Instance Method Summary collapse

Methods inherited from Payload

#initialize, protocol_name

Constructor Details

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

Instance Attribute Details

#proposalsSAProposals

Set of SA proposals

Returns:



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

define_field_before :body, :proposals, SAProposals, builder: ->(h, t) { t.new(length_from: -> { h.length - h.offset_of(:proposals) }) }

Instance Method Details

#calc_lengthInteger

Compute length and set Payload#length field

Returns:

  • (Integer)

    new length



549
550
551
552
# File 'lib/packetgen/plugin/ike/sa.rb', line 549

def calc_length
  proposals.each(&:calc_length)
  super
end