Class: Net::SSH::Test::Kex

Inherits:
Object
  • Object
show all
Includes:
Net::SSH::Transport::Constants
Defined in:
lib/net/ssh/test/kex.rb

Overview

An implementation of a key-exchange strategy specifically for unit tests. (This strategy would never really work against a real SSH server–it makes too many assumptions about the server’s response.)

This registers itself with the transport key-exchange system as the “test” algorithm.

Constant Summary

Constants included from Net::SSH::Transport::Constants

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

Instance Method Summary collapse

Constructor Details

#initialize(algorithms, connection, data) ⇒ Kex

Creates a new instance of the testing key-exchange algorithm with the given arguments.



22
23
24
# File 'lib/net/ssh/test/kex.rb', line 22

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

Instance Method Details

#exchange_keysObject

Exchange keys with the server. This returns a hash of constant values, and does not actually exchange keys.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/net/ssh/test/kex.rb', line 28

def exchange_keys
  result = Net::SSH::Buffer.from(:byte, NEWKEYS)
  @connection.send_message(result)

  buffer = @connection.next_message
  raise Net::SSH::Exception, "expected NEWKEYS" unless buffer.type == NEWKEYS

  { session_id: "abc-xyz",
    server_key: OpenSSL::PKey::RSA.new(512),
    shared_secret: OpenSSL::BN.new("1234567890", 10),
    hashing_algorithm: OpenSSL::Digest::SHA1 }
end