Class: PacketGen::Plugin::IKE::Transform

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

Overview

SA Tranform substructure, as defined in RFC 7296 §3.3.2

                     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    |        Transform Length       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Transform Type |   RESERVED    |          Transform ID         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                      Transform Attributes                     ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Create a Transform

# using type and id names
trans = PacketGen::Plugin::IKE::Transform.new(type: 'ENCR', id: 'AES_CBC')
# using integer values
trans = PacketGen::Plugin::IKE::Transform.new(type: 1, id: 12)

Add attributes to a transform

# using an Attribute object
attr = PacketGen::Plugin::IKE::Attribute.new(type: 14, value: 128)
trans.attributes << attr
# using a hash
trans.attributes << { type: 14, value: 128 }

Author:

  • Sylvain Daubert

Constant Summary collapse

TYPES =
{
  'ENCR' => 1,
  'PRF'  => 2,
  'INTG' => 3,
  'DH'   => 4,
  'ESN'  => 5
}.freeze
ENCR_DES_IV64 =
1
ENCR_DES =
2
ENCR_3DES =
3
ENCR_RC5 =
4
ENCR_IDEA =
5
ENCR_CAST =
6
ENCR_BLOWFISH =
7
ENCR_3IDEA =
8
ENCR_DES_IV32 =
9
ENCR_AES_CBC =
12
ENCR_AES_CTR =
13
ENCR_AES_CCM8 =
14
ENCR_AES_CCM12 =
15
ENCR_AES_CCM16 =
16
ENCR_AES_GCM8 =
18
ENCR_AES_GCM12 =
19
ENCR_AES_GCM16 =
20
ENCR_CAMELLIA_CBC =
23
ENCR_CAMELLIA_CTR =
24
ENCR_CAMELLIA_CCM8 =
25
ENCR_CAMELLIA_CCM12 =
26
ENCR_CAMELLIA_CCM16 =
27
ENCR_CHACHA20_POLY1305 =
28
PRF_HMAC_MD5 =
1
PRF_HMAC_SHA1 =
2
PRF_AES128_XCBC =
4
PRF_HMAC_SHA2_256 =
5
PRF_HMAC_SHA2_384 =
6
PRF_HMAC_SHA2_512 =
7
PRF_AES128_CMAC =
8
INTG_NONE =
0
INTG_HMAC_MD5_96 =
1
INTG_HMAC_SHA1_96 =
2
INTG_AES_XCBC_96 =
5
INTG_HMAC_MD5_128 =
6
INTG_HMAC_SHA1_160 =
7
INTG_AES_CMAC_96 =
8
INTG_AES128_GMAC =
9
INTG_AES192_GMAC =
10
INTG_AES256_GMAC =
11
INTG_HMAC_SHA2_256_128 =
12
INTG_HMAC_SHA2_384_192 =
13
INTG_HMAC_SHA2_512_256 =
14
DH_NONE =
0
DH_MODP768 =
1
DH_MODP1024 =
2
DH_MODP1536 =
5
DH_MODP2048 =
14
DH_MODP3072 =
15
DH_MODP4096 =
16
DH_MODP6144 =
17
DH_MODP8192 =
18
DH_ECP256 =
19
DH_ECP384 =
20
DH_ECP521 =
21
DH_BRAINPOOLP224 =
27
DH_BRAINPOOLP256 =
28
DH_BRAINPOOLP384 =
29
DH_BRAINPOOLP512 =
30
DH_CURVE25519 =
31
DH_CURVE448 =
32
ESN_NO_ESN =
0
ESN_ESN =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Transform

Returns a new instance of Transform.



220
221
222
223
224
225
# File 'lib/packetgen/plugin/ike/sa.rb', line 220

def initialize(options={})
  super
  self.type = options[:type] if options[:type]
  self.id = options[:id] if options[:id]
  self[:length].value = sz unless options[:length]
end

Instance Attribute Details

#attributesAttributes

Set of attributes for this transform

Returns:



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

define_field :attributes, Attributes, builder: ->(h, t) { t.new(length_from: -> { h.length - h.offset_of(:attributes) }) }

#idInteger

16-bit transform ID. The Transform ID is the specific instance of the proposed transform type.

Returns:

  • (Integer)


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

define_field :id, PacketGen::Types::Int16

#lastInteger

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

Returns:

  • (Integer)


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

define_field :last, PacketGen::Types::Int8

#lengthInteger

16-bit transform length

Returns:

  • (Integer)


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

define_field :length, PacketGen::Types::Int16

#rsv1Integer

8-bit reserved field

Returns:

  • (Integer)


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

define_field :rsv1, PacketGen::Types::Int8

#rsv2Integer

8-bit reserved field

Returns:

  • (Integer)


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

define_field :rsv2, PacketGen::Types::Int8

#typeInteger (readonly)

8-bit transform type. The Transform Type is the cryptographic algorithm type (i.e. encryption, PRF, integrity, etc.)

Returns:

  • (Integer)


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

define_field :type, PacketGen::Types::Int8Enum, enum: TYPES

Instance Method Details

#calc_lengthInteger

Compute length and set #length field

Returns:

  • (Integer)

    new length



246
247
248
# File 'lib/packetgen/plugin/ike/sa.rb', line 246

def calc_length
  PacketGen::Header::Base.calculate_and_set_length self
end

#human_idString

Get human-readable ID

Returns:

  • (String)


270
271
272
273
274
# File 'lib/packetgen/plugin/ike/sa.rb', line 270

def human_id
  name = self.class.constants.grep(/#{human_type}_/)
             .detect { |c| self.class.const_get(c) == id } || "ID=#{id}"
  name.to_s.sub(/#{human_type}_/, '')
end

#human_typeString

Get human-readable type

Returns:

  • (String)


260
261
262
263
264
265
266
# File 'lib/packetgen/plugin/ike/sa.rb', line 260

def human_type
  if self[:type].enum.value? self.type
    self[:type].to_human
  else
    "type[#{self.type}]"
  end
end

#last?Boolean?

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

Returns:

  • (Boolean, nil)

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



278
279
280
281
282
283
284
285
# File 'lib/packetgen/plugin/ike/sa.rb', line 278

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

#to_humanString

Get a human readable string

Returns:

  • (String)


252
253
254
255
256
# File 'lib/packetgen/plugin/ike/sa.rb', line 252

def to_human
  h = "#{human_type}(#{human_id}".dup
  h << ",#{attributes.to_human}" unless attributes.empty?
  h << ')'
end