Sha256: 1ed2bdd5712310ca82c61905b643e399c06249426ee3616b189c5ae073efc4f2

Contents?: true

Size: 1.52 KB

Versions: 28

Compression:

Stored size: 1.52 KB

Contents

require 'openssl'

require 'net/ssh/errors'
require 'net/ssh/transport/algorithms'
require 'net/ssh/transport/constants'
require 'net/ssh/transport/kex'

module Net
  module SSH
    module Test
      # 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.
      class Kex
        include Net::SSH::Transport::Constants

        # Creates a new instance of the testing key-exchange algorithm with the
        # given arguments.
        def initialize(algorithms, connection, data)
          @connection = connection
        end

        # Exchange keys with the server. This returns a hash of constant values,
        # and does not actually exchange keys.
        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
      end
    end
  end
end

Net::SSH::Transport::Algorithms::ALGORITHMS[:kex] << "test"
Net::SSH::Transport::Kex::MAP["test"] = Net::SSH::Test::Kex

Version data entries

28 entries across 28 versions & 6 rubygems

Version Path
net-ssh-7.3.0 lib/net/ssh/test/kex.rb
net-ssh-7.3.0.rc1 lib/net/ssh/test/kex.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/net-ssh-7.2.1/lib/net/ssh/test/kex.rb
net-ssh-7.2.3 lib/net/ssh/test/kex.rb
net-ssh-backports-6.3.6.backports lib/net/ssh/test/kex.rb
net-ssh-backports-6.3.5.backports lib/net/ssh/test/kex.rb
net-ssh-backports-6.3.4.backports lib/net/ssh/test/kex.rb
net-ssh-backports-6.3.3.backports lib/net/ssh/test/kex.rb
net-ssh-backports-6.3.2.backports lib/net/ssh/test/kex.rb
net-ssh-backports-6.3.1.backports lib/net/ssh/test/kex.rb
net-ssh-backports-6.3.0.backports lib/net/ssh/test/kex.rb
net-ssh-7.2.2.rc1 lib/net/ssh/test/kex.rb
net-ssh-7.2.1 lib/net/ssh/test/kex.rb
net-ssh-7.2.1.rc1 lib/net/ssh/test/kex.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/net-ssh-7.2.0/lib/net/ssh/test/kex.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/net-ssh-7.2.0/lib/net/ssh/test/kex.rb
net-ssh-7.2.0 lib/net/ssh/test/kex.rb
net-ssh-7.2.0.rc1 lib/net/ssh/test/kex.rb
net-ssh-7.2.0.beta1 lib/net/ssh/test/kex.rb
net-ssh-7.1.0 lib/net/ssh/test/kex.rb