Module: PacketGen::Plugin::Crypto Private

Included in:
ESP, IKE::SK
Defined in:
lib/packetgen/plugin/crypto.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Mixin for cryptographic classes

Author:

  • Sylvain Daubert

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Instance Method Details

#authenticate!Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check authentication

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/packetgen/plugin/crypto.rb', line 47

def authenticate!
  @conf.final
  if @intg
    @intg.update @esn.to_s if defined? @esn
    @intg.digest[0, @icv_length] == @icv
  else
    true
  end
rescue OpenSSL::Cipher::CipherError
  false
end

#authenticated?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Say if crypto modes permit authentication

Returns:

  • (Boolean)


41
42
43
# File 'lib/packetgen/plugin/crypto.rb', line 41

def authenticated?
  @conf.authenticated? || !@intg.nil?
end

#confidentiality_modeString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get confidentiality mode name

Returns:

  • (String)

Raises:



32
33
34
35
36
37
# File 'lib/packetgen/plugin/crypto.rb', line 32

def confidentiality_mode
  mode = @conf.name.match(/-([^-]*)$/)[1]
  raise Error, 'unknown cipher mode' if mode.nil?

  mode.downcase
end

#decipher(data) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Decipher data

Parameters:

  • data (String)

Returns:

  • (String)

    deciphered data



71
72
73
74
# File 'lib/packetgen/plugin/crypto.rb', line 71

def decipher(data)
  @intg&.update(data)
  @conf.update(data)
end

#encipher(data) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Encipher data

Parameters:

  • data (String)

Returns:

  • (String)

    enciphered data



62
63
64
65
66
# File 'lib/packetgen/plugin/crypto.rb', line 62

def encipher(data)
  enciphered_data = @conf.update(data)
  @intg&.update(enciphered_data)
  enciphered_data
end

#set_crypto(conf, intg) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Register cryptographic modes

Parameters:

  • conf (OpenSSL::Cipher)
  • intg (OpenSSL::HMAC)


21
22
23
24
25
26
27
28
# File 'lib/packetgen/plugin/crypto.rb', line 21

def set_crypto(conf, intg)
  @conf = conf
  @intg = intg
  return unless conf.authenticated?

  # #auth_tag_len only supported from ruby 2.4.0
  @conf.auth_tag_len = @trunc if @conf.respond_to? :auth_tag_len
end