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)


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

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)


39
40
41
# File 'lib/packetgen/plugin/crypto.rb', line 39

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:



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

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



69
70
71
72
# File 'lib/packetgen/plugin/crypto.rb', line 69

def decipher(data)
  @intg.update(data) if @intg
  @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



60
61
62
63
64
# File 'lib/packetgen/plugin/crypto.rb', line 60

def encipher(data)
  enciphered_data = @conf.update(data)
  @intg.update(enciphered_data) if @intg
  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
# 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