Class: PacketGen::Header::IKE::Transform

Inherits:
Types::Fields show all
Defined in:
lib/packetgen/header/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::Header::IKE::Transform.new(type: 'ENCR', id: 'AES_CBC')
# using integer values
trans = PacketGen::Header::IKE::Transform.new(type: 1, id: 12)

Add attributes to a transform

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

Author:

  • Sylvain Daubert

Since:

  • 2.0.0

Constant Summary collapse

TYPES =

Since:

  • 2.0.0

{
  'ENCR' => 1,
  'PRF'  => 2,
  'INTG' => 3,
  'DH'   => 4,
  'ESN'  => 5
}.freeze
ENCR_DES_IV64 =

Since:

  • 2.0.0

1
ENCR_DES =

Since:

  • 2.0.0

2
ENCR_3DES =

Since:

  • 2.0.0

3
ENCR_RC5 =

Since:

  • 2.0.0

4
ENCR_IDEA =

Since:

  • 2.0.0

5
ENCR_CAST =

Since:

  • 2.0.0

6
ENCR_BLOWFISH =

Since:

  • 2.0.0

7
ENCR_3IDEA =

Since:

  • 2.0.0

8
ENCR_DES_IV32 =

Since:

  • 2.0.0

9
ENCR_AES_CBC =

Since:

  • 2.0.0

12
ENCR_AES_CTR =

Since:

  • 2.0.0

13
ENCR_AES_CCM8 =

Since:

  • 2.0.0

14
ENCR_AES_CCM12 =

Since:

  • 2.0.0

15
ENCR_AES_CCM16 =

Since:

  • 2.0.0

16
ENCR_AES_GCM8 =

Since:

  • 2.0.0

18
ENCR_AES_GCM12 =

Since:

  • 2.0.0

19
ENCR_AES_GCM16 =

Since:

  • 2.0.0

20
ENCR_CAMELLIA_CBC =

Since:

  • 2.0.0

23
ENCR_CAMELLIA_CTR =

Since:

  • 2.0.0

24
ENCR_CAMELLIA_CCM8 =

Since:

  • 2.0.0

25
ENCR_CAMELLIA_CCM12 =

Since:

  • 2.0.0

26
ENCR_CAMELLIA_CCM16 =

Since:

  • 2.0.0

27
ENCR_CHACHA20_POLY1305 =

Since:

  • 2.0.0

28
PRF_HMAC_MD5 =

Since:

  • 2.0.0

1
PRF_HMAC_SHA1 =

Since:

  • 2.0.0

2
PRF_AES128_XCBC =

Since:

  • 2.0.0

4
PRF_HMAC_SHA2_256 =

Since:

  • 2.0.0

5
PRF_HMAC_SHA2_384 =

Since:

  • 2.0.0

6
PRF_HMAC_SHA2_512 =

Since:

  • 2.0.0

7
PRF_AES128_CMAC =

Since:

  • 2.0.0

8
INTG_NONE =

Since:

  • 2.0.0

0
INTG_HMAC_MD5_96 =

Since:

  • 2.0.0

1
INTG_HMAC_SHA1_96 =

Since:

  • 2.0.0

2
INTG_AES_XCBC_96 =

Since:

  • 2.0.0

5
INTG_HMAC_MD5_128 =

Since:

  • 2.0.0

6
INTG_HMAC_SHA1_160 =

Since:

  • 2.0.0

7
INTG_AES_CMAC_96 =

Since:

  • 2.0.0

8
INTG_AES128_GMAC =

Since:

  • 2.0.0

9
INTG_AES192_GMAC =

Since:

  • 2.0.0

10
INTG_AES256_GMAC =

Since:

  • 2.0.0

11
INTG_HMAC_SHA2_256_128 =

Since:

  • 2.0.0

12
INTG_HMAC_SHA2_384_192 =

Since:

  • 2.0.0

13
INTG_HMAC_SHA2_512_256 =

Since:

  • 2.0.0

14
DH_NONE =

Since:

  • 2.0.0

0
DH_MODP768 =

Since:

  • 2.0.0

1
DH_MODP1024 =

Since:

  • 2.0.0

2
DH_MODP1536 =

Since:

  • 2.0.0

5
DH_MODP2048 =

Since:

  • 2.0.0

14
DH_MODP3072 =

Since:

  • 2.0.0

15
DH_MODP4096 =

Since:

  • 2.0.0

16
DH_MODP6144 =

Since:

  • 2.0.0

17
DH_MODP8192 =

Since:

  • 2.0.0

18
DH_ECP256 =

Since:

  • 2.0.0

19
DH_ECP384 =

Since:

  • 2.0.0

20
DH_ECP521 =

Since:

  • 2.0.0

21
DH_BRAINPOOLP224 =

Since:

  • 2.0.0

27
DH_BRAINPOOLP256 =

Since:

  • 2.0.0

28
DH_BRAINPOOLP384 =

Since:

  • 2.0.0

29
DH_BRAINPOOLP512 =

Since:

  • 2.0.0

30
DH_CURVE25519 =

Since:

  • 2.0.0

31
DH_CURVE448 =

Since:

  • 2.0.0

32
ESN_NO_ESN =

Since:

  • 2.0.0

0
ESN_ESN =

Since:

  • 2.0.0

1

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Returns a new instance of Transform.

Since:

  • 2.0.0



238
239
240
241
242
243
# File 'lib/packetgen/header/ike/sa.rb', line 238

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

Instance Attribute Details

#attributesAttributes

Set of attributes for this transform

Returns:



236
# File 'lib/packetgen/header/ike/sa.rb', line 236

define_field :attributes, Attributes

#idInteger

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

Returns:

  • (Integer)


232
# File 'lib/packetgen/header/ike/sa.rb', line 232

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


210
# File 'lib/packetgen/header/ike/sa.rb', line 210

define_field :last, Types::Int8

#lengthInteger

16-bit proposal length

Returns:

  • (Integer)


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

define_field :length, Types::Int16

#rsv1Integer

8-bit reserved field

Returns:

  • (Integer)


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

define_field :rsv1, Types::Int8

#rsv2Integer

8-bit reserved field

Returns:

  • (Integer)


227
# File 'lib/packetgen/header/ike/sa.rb', line 227

define_field :rsv2, Types::Int8

#typeInteger (readonly)

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

Returns:

  • (Integer)


223
# File 'lib/packetgen/header/ike/sa.rb', line 223

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

Instance Method Details

#calc_lengthInteger

Compute length and set #length field

Returns:

  • (Integer)

    new length

Since:

  • 2.0.0



273
274
275
# File 'lib/packetgen/header/ike/sa.rb', line 273

def calc_length
  Base.calculate_and_set_length self
end

#human_idString

Get human-readable ID

Returns:

  • (String)

Since:

  • 2.0.0



297
298
299
300
301
# File 'lib/packetgen/header/ike/sa.rb', line 297

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)

Since:

  • 2.0.0



287
288
289
290
291
292
293
# File 'lib/packetgen/header/ike/sa.rb', line 287

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.

Since:

  • 2.0.0



305
306
307
308
309
310
311
312
# File 'lib/packetgen/header/ike/sa.rb', line 305

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

#read(str) ⇒ self

Populate object from a string

Parameters:

  • str (String)

Returns:

  • (self)

Since:

  • 2.0.0



263
264
265
266
267
268
269
# File 'lib/packetgen/header/ike/sa.rb', line 263

def read(str)
  super
  hlen = self.class.new.sz
  attr_len = length - hlen
  attributes.read(str[hlen, attr_len])
  self
end

#to_humanString

Get a human readable string

Returns:

  • (String)

Since:

  • 2.0.0



279
280
281
282
283
# File 'lib/packetgen/header/ike/sa.rb', line 279

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