Class: PacketGen::Header::IKE::SAProposal
- Inherits:
-
Types::Fields
- Object
- Types::Fields
- PacketGen::Header::IKE::SAProposal
- Defined in:
- lib/packetgen/header/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::Header::IKE::Proposal.new(num: 1, protocol: 'IKE')
# using integer values
proposal = PacketGen::Header::IKE::Proposal.new(num: 1, protocol: 1)
Add transforms to a proposal
# using a Transform object
trans = PacketGen::Header::IKE::Transform.new(type: 'ENCR', id: '3DES')
proposal.transforms << trans
# using a hash
proposal.transforms << { type: 'ENCR', id: '3DES' }
Instance Attribute Summary collapse
-
#last ⇒ Integer
8-bit last substructure.
-
#length ⇒ Integer
16-bit proposal length.
-
#num ⇒ Integer
8-bit proposal number.
-
#num_trans ⇒ Integer
8-bit number of transformations.
-
#protocol ⇒ Integer
8-bit protocol ID.
-
#reserved ⇒ Integer
8-bit reserved field.
-
#spi ⇒ String
the sending entity’s SPI.
-
#spi_size ⇒ Integer
8-bit SPI size.
-
#transforms ⇒ Transforms
8-bit set of tranforms for this proposal.
Instance Method Summary collapse
-
#calc_length ⇒ Integer
Compute length and set #length field.
-
#human_protocol ⇒ String
Get protocol name.
-
#initialize(options = {}) ⇒ SAProposal
constructor
A new instance of SAProposal.
-
#last? ⇒ Boolean?
Say if this proposal is the last one (from #last field).
-
#read(str) ⇒ self
Populate object from a string.
-
#to_human ⇒ String
Get a human readable string.
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?, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field
Constructor Details
#initialize(options = {}) ⇒ SAProposal
Returns a new instance of SAProposal.
406 407 408 409 410 411 412 413 |
# File 'lib/packetgen/header/ike/sa.rb', line 406 def initialize(={}) if [:spi] && [:spi_size].nil? [:spi_size] = [:spi].size end super self[:length].value = sz unless [:length] self.protocol = [:protocol] if [:protocol] end |
Instance Attribute Details
#last ⇒ Integer
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.
364 |
# File 'lib/packetgen/header/ike/sa.rb', line 364 define_field :last, Types::Int8 |
#length ⇒ Integer
16-bit proposal length
372 |
# File 'lib/packetgen/header/ike/sa.rb', line 372 define_field :length, Types::Int16 |
#num ⇒ Integer
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.
381 |
# File 'lib/packetgen/header/ike/sa.rb', line 381 define_field :num, Types::Int8, default: 1 |
#num_trans ⇒ Integer
8-bit number of transformations
395 |
# File 'lib/packetgen/header/ike/sa.rb', line 395 define_field :num_trans, Types::Int8, default: 0 |
#protocol ⇒ Integer
8-bit protocol ID. Specify IPsec protocol currently negociated. May 1 (IKE), 2 (AH) or 3 (ESP).
386 |
# File 'lib/packetgen/header/ike/sa.rb', line 386 define_field :protocol, Types::Int8 |
#reserved ⇒ Integer
8-bit reserved field
368 |
# File 'lib/packetgen/header/ike/sa.rb', line 368 define_field :reserved, Types::Int8 |
#spi ⇒ String
the sending entity’s SPI. When the #spi_size field is zero, this field is not present in the proposal.
400 |
# File 'lib/packetgen/header/ike/sa.rb', line 400 define_field :spi, Types::String, builder: ->(h, t) { t.new(length_from: h[:spi_size]) } |
#spi_size ⇒ Integer
8-bit SPI size. Give size of SPI field. Set to 0 for an initial IKE SA negotiation, as SPI is obtained from outer header.
391 |
# File 'lib/packetgen/header/ike/sa.rb', line 391 define_field :spi_size, Types::Int8, default: 0 |
#transforms ⇒ Transforms
8-bit set of tranforms for this proposal
404 |
# File 'lib/packetgen/header/ike/sa.rb', line 404 define_field :transforms, Transforms, builder: ->(h, t) { t.new(counter: h[:num_trans]) } |
Instance Method Details
#calc_length ⇒ Integer
Compute length and set #length field
443 444 445 446 |
# File 'lib/packetgen/header/ike/sa.rb', line 443 def calc_length transforms.each(&:calc_length) Base.calculate_and_set_length self end |
#human_protocol ⇒ String
Get protocol name
463 464 465 466 467 |
# File 'lib/packetgen/header/ike/sa.rb', line 463 def human_protocol name = IKE.constants.grep(/PROTO/) .detect { |c| IKE.const_get(c) == protocol } || "proto #{protocol}" name.to_s.sub(/PROTO_/, '') end |
#last? ⇒ Boolean?
Say if this proposal is the last one (from #last field)
472 473 474 475 476 477 478 479 |
# File 'lib/packetgen/header/ike/sa.rb', line 472 def last? case last when 0 true when 2 false end end |
#read(str) ⇒ self
Populate object from a string
433 434 435 436 437 438 439 |
# File 'lib/packetgen/header/ike/sa.rb', line 433 def read(str) super hlen = self.class.new.sz + spi_size tlen = length - hlen transforms.read(str[hlen, tlen]) self end |
#to_human ⇒ String
Get a human readable string
450 451 452 453 454 455 456 457 458 459 |
# File 'lib/packetgen/header/ike/sa.rb', line 450 def to_human str = "##{num} #{human_protocol}".dup case spi_size when 4 str << '(spi:0x%08x)' % Types::Int32.new.read(spi).to_i when 8 str << '(spi:0x%016x)' % Types::Int64.new.read(spi).to_i end str << ":#{transforms.to_human}" end |