Class: Net::SSH::Transport::Kex::Abstract

Inherits:
Object
  • Object
show all
Includes:
Loggable, Constants
Defined in:
lib/net/ssh/transport/kex/abstract.rb

Overview

Abstract class that implement Diffie-Hellman Key Exchange See tools.ietf.org/html/rfc4253#page-21

Direct Known Subclasses

Abstract5656, DiffieHellmanGroup1SHA1

Constant Summary

Constants included from Constants

Constants::DEBUG, Constants::DISCONNECT, Constants::IGNORE, Constants::KEXDH_GEX_GROUP, Constants::KEXDH_GEX_INIT, Constants::KEXDH_GEX_REPLY, Constants::KEXDH_GEX_REQUEST, Constants::KEXDH_INIT, Constants::KEXDH_REPLY, Constants::KEXECDH_INIT, Constants::KEXECDH_REPLY, Constants::KEXINIT, Constants::NEWKEYS, Constants::SERVICE_ACCEPT, Constants::SERVICE_REQUEST, Constants::UNIMPLEMENTED

Instance Attribute Summary collapse

Attributes included from Loggable

#logger

Instance Method Summary collapse

Methods included from Loggable

#debug, #error, #fatal, #info, #lwarn

Constructor Details

#initialize(algorithms, connection, data) ⇒ Abstract

Create a new instance of the Diffie-Hellman Key Exchange algorithm. The Diffie-Hellman (DH) key exchange provides a shared secret that cannot be determined by either party alone. The key exchange is combined with a signature with the host key to provide host authentication.



27
28
29
30
31
32
33
34
# File 'lib/net/ssh/transport/kex/abstract.rb', line 27

def initialize(algorithms, connection, data)
  @algorithms = algorithms
  @connection = connection

  @data = data.dup
  @dh = generate_key
  @logger = @data.delete(:logger)
end

Instance Attribute Details

#algorithmsObject (readonly)

Returns the value of attribute algorithms.



17
18
19
# File 'lib/net/ssh/transport/kex/abstract.rb', line 17

def algorithms
  @algorithms
end

#connectionObject (readonly)

Returns the value of attribute connection.



18
19
20
# File 'lib/net/ssh/transport/kex/abstract.rb', line 18

def connection
  @connection
end

#dataObject (readonly)

Returns the value of attribute data.



19
20
21
# File 'lib/net/ssh/transport/kex/abstract.rb', line 19

def data
  @data
end

#dhObject (readonly)

Returns the value of attribute dh.



20
21
22
# File 'lib/net/ssh/transport/kex/abstract.rb', line 20

def dh
  @dh
end

Instance Method Details

#digesterObject

Raises:

  • (NotImplementedError)


61
62
63
# File 'lib/net/ssh/transport/kex/abstract.rb', line 61

def digester
  raise NotImplementedError, 'abstract class: digester not implemented'
end

#exchange_keysObject

Perform the key-exchange for the given session, with the given data. This method will return a hash consisting of the following keys:

  • :session_id

  • :server_key

  • :shared_secret

  • :hashing_algorithm

The caller is expected to be able to understand how to use these deliverables.



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/net/ssh/transport/kex/abstract.rb', line 47

def exchange_keys
  result = send_kexinit
  verify_server_key(result[:server_key])
  session_id = verify_signature(result)
  confirm_newkeys

  {
    session_id: session_id,
    server_key: result[:server_key],
    shared_secret: result[:shared_secret],
    hashing_algorithm: digester
  }
end