net-ssh 5.0.0.beta1 → 5.0.0.beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - checksums.yaml.gz.sig +0 -0
 - data.tar.gz.sig +0 -0
 - data/.rubocop_todo.yml +98 -258
 - data/CHANGES.txt +8 -0
 - data/Gemfile +1 -3
 - data/Rakefile +37 -39
 - data/lib/net/ssh.rb +26 -25
 - data/lib/net/ssh/authentication/agent.rb +228 -225
 - data/lib/net/ssh/authentication/certificate.rb +166 -164
 - data/lib/net/ssh/authentication/constants.rb +17 -14
 - data/lib/net/ssh/authentication/ed25519.rb +107 -104
 - data/lib/net/ssh/authentication/ed25519_loader.rb +32 -28
 - data/lib/net/ssh/authentication/key_manager.rb +5 -3
 - data/lib/net/ssh/authentication/methods/abstract.rb +53 -47
 - data/lib/net/ssh/authentication/methods/hostbased.rb +32 -33
 - data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +2 -4
 - data/lib/net/ssh/authentication/methods/none.rb +10 -10
 - data/lib/net/ssh/authentication/methods/password.rb +13 -13
 - data/lib/net/ssh/authentication/methods/publickey.rb +54 -55
 - data/lib/net/ssh/authentication/pageant.rb +468 -465
 - data/lib/net/ssh/authentication/pub_key_fingerprint.rb +44 -0
 - data/lib/net/ssh/authentication/session.rb +127 -123
 - data/lib/net/ssh/buffer.rb +305 -303
 - data/lib/net/ssh/buffered_io.rb +163 -162
 - data/lib/net/ssh/config.rb +230 -227
 - data/lib/net/ssh/connection/channel.rb +659 -654
 - data/lib/net/ssh/connection/constants.rb +30 -26
 - data/lib/net/ssh/connection/event_loop.rb +108 -104
 - data/lib/net/ssh/connection/keepalive.rb +54 -50
 - data/lib/net/ssh/connection/session.rb +677 -678
 - data/lib/net/ssh/connection/term.rb +180 -176
 - data/lib/net/ssh/errors.rb +101 -99
 - data/lib/net/ssh/key_factory.rb +108 -108
 - data/lib/net/ssh/known_hosts.rb +148 -154
 - data/lib/net/ssh/loggable.rb +56 -54
 - data/lib/net/ssh/packet.rb +82 -78
 - data/lib/net/ssh/prompt.rb +55 -53
 - data/lib/net/ssh/proxy/command.rb +103 -102
 - data/lib/net/ssh/proxy/errors.rb +12 -8
 - data/lib/net/ssh/proxy/http.rb +92 -91
 - data/lib/net/ssh/proxy/https.rb +42 -39
 - data/lib/net/ssh/proxy/jump.rb +50 -47
 - data/lib/net/ssh/proxy/socks4.rb +0 -2
 - data/lib/net/ssh/proxy/socks5.rb +11 -11
 - data/lib/net/ssh/ruby_compat.rb +1 -0
 - data/lib/net/ssh/service/forward.rb +364 -362
 - data/lib/net/ssh/test.rb +85 -83
 - data/lib/net/ssh/test/channel.rb +146 -142
 - data/lib/net/ssh/test/extensions.rb +148 -146
 - data/lib/net/ssh/test/kex.rb +35 -31
 - data/lib/net/ssh/test/local_packet.rb +48 -44
 - data/lib/net/ssh/test/packet.rb +87 -84
 - data/lib/net/ssh/test/remote_packet.rb +35 -31
 - data/lib/net/ssh/test/script.rb +173 -171
 - data/lib/net/ssh/test/socket.rb +59 -55
 - data/lib/net/ssh/transport/algorithms.rb +413 -412
 - data/lib/net/ssh/transport/cipher_factory.rb +108 -105
 - data/lib/net/ssh/transport/constants.rb +35 -31
 - data/lib/net/ssh/transport/ctr.rb +1 -1
 - data/lib/net/ssh/transport/hmac.rb +1 -1
 - data/lib/net/ssh/transport/hmac/abstract.rb +67 -64
 - data/lib/net/ssh/transport/hmac/sha2_256_96.rb +1 -1
 - data/lib/net/ssh/transport/hmac/sha2_512_96.rb +1 -1
 - data/lib/net/ssh/transport/identity_cipher.rb +55 -51
 - data/lib/net/ssh/transport/kex.rb +2 -4
 - data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha1.rb +47 -40
 - data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +201 -197
 - data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +53 -56
 - data/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb +94 -87
 - data/lib/net/ssh/transport/kex/ecdh_sha2_nistp384.rb +17 -10
 - data/lib/net/ssh/transport/kex/ecdh_sha2_nistp521.rb +17 -10
 - data/lib/net/ssh/transport/key_expander.rb +29 -25
 - data/lib/net/ssh/transport/openssl.rb +17 -30
 - data/lib/net/ssh/transport/packet_stream.rb +193 -192
 - data/lib/net/ssh/transport/server_version.rb +64 -66
 - data/lib/net/ssh/transport/session.rb +286 -284
 - data/lib/net/ssh/transport/state.rb +198 -196
 - data/lib/net/ssh/verifiers/lenient.rb +29 -25
 - data/lib/net/ssh/verifiers/null.rb +13 -9
 - data/lib/net/ssh/verifiers/secure.rb +45 -45
 - data/lib/net/ssh/verifiers/strict.rb +20 -16
 - data/lib/net/ssh/version.rb +55 -53
 - data/net-ssh.gemspec +4 -4
 - data/support/ssh_tunnel_bug.rb +2 -2
 - metadata +25 -24
 - metadata.gz.sig +0 -0
 
| 
         @@ -1,30 +1,34 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module Net 
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            # rbnacl, bcrypt_pbkdf
         
     | 
| 
       5 
     | 
    
         
            -
            module ED25519Loader
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
            begin
         
     | 
| 
       8 
     | 
    
         
            -
              require 'net/ssh/authentication/ed25519'
         
     | 
| 
       9 
     | 
    
         
            -
              LOADED = true
         
     | 
| 
       10 
     | 
    
         
            -
              ERROR = nil
         
     | 
| 
       11 
     | 
    
         
            -
            rescue LoadError => e
         
     | 
| 
       12 
     | 
    
         
            -
              ERROR = e
         
     | 
| 
       13 
     | 
    
         
            -
              LOADED = false
         
     | 
| 
       14 
     | 
    
         
            -
            end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
            def self.raiseUnlessLoaded(message)
         
     | 
| 
       17 
     | 
    
         
            -
              description = ERROR.is_a?(LoadError) ? dependenciesRequiredForED25519 : ''
         
     | 
| 
       18 
     | 
    
         
            -
              description << "#{ERROR.class} : \"#{ERROR.message}\"\n" if ERROR
         
     | 
| 
       19 
     | 
    
         
            -
              raise NotImplementedError, "#{message}\n#{description}" unless LOADED
         
     | 
| 
       20 
     | 
    
         
            -
            end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
            def self.dependenciesRequiredForED25519
         
     | 
| 
       23 
     | 
    
         
            -
              result = "net-ssh requires the following gems for ed25519 support:\n"
         
     | 
| 
       24 
     | 
    
         
            -
              result << " * ed25519 (>= 1.2, < 2.0)\n"
         
     | 
| 
       25 
     | 
    
         
            -
              result << " * bcrypt_pbkdf (>= 1.0, < 2.0)\n" unless RUBY_PLATFORM == "java"
         
     | 
| 
       26 
     | 
    
         
            -
              result << "See https://github.com/net-ssh/net-ssh/issues/565 for more information\n"
         
     | 
| 
       27 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            module Net 
         
     | 
| 
      
 2 
     | 
    
         
            +
              module SSH 
         
     | 
| 
      
 3 
     | 
    
         
            +
                module Authentication
         
     | 
| 
       28 
4 
     | 
    
         | 
| 
      
 5 
     | 
    
         
            +
                  # Loads ED25519 support which requires optinal dependecies like
         
     | 
| 
      
 6 
     | 
    
         
            +
                  # rbnacl, bcrypt_pbkdf
         
     | 
| 
      
 7 
     | 
    
         
            +
                  module ED25519Loader
         
     | 
| 
      
 8 
     | 
    
         
            +
                  
         
     | 
| 
      
 9 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 10 
     | 
    
         
            +
                      require 'net/ssh/authentication/ed25519'
         
     | 
| 
      
 11 
     | 
    
         
            +
                      LOADED = true
         
     | 
| 
      
 12 
     | 
    
         
            +
                      ERROR = nil
         
     | 
| 
      
 13 
     | 
    
         
            +
                    rescue LoadError => e
         
     | 
| 
      
 14 
     | 
    
         
            +
                      ERROR = e
         
     | 
| 
      
 15 
     | 
    
         
            +
                      LOADED = false
         
     | 
| 
      
 16 
     | 
    
         
            +
                    end
         
     | 
| 
      
 17 
     | 
    
         
            +
                  
         
     | 
| 
      
 18 
     | 
    
         
            +
                    def self.raiseUnlessLoaded(message)
         
     | 
| 
      
 19 
     | 
    
         
            +
                      description = ERROR.is_a?(LoadError) ? dependenciesRequiredForED25519 : ''
         
     | 
| 
      
 20 
     | 
    
         
            +
                      description << "#{ERROR.class} : \"#{ERROR.message}\"\n" if ERROR
         
     | 
| 
      
 21 
     | 
    
         
            +
                      raise NotImplementedError, "#{message}\n#{description}" unless LOADED
         
     | 
| 
      
 22 
     | 
    
         
            +
                    end
         
     | 
| 
      
 23 
     | 
    
         
            +
                  
         
     | 
| 
      
 24 
     | 
    
         
            +
                    def self.dependenciesRequiredForED25519
         
     | 
| 
      
 25 
     | 
    
         
            +
                      result = "net-ssh requires the following gems for ed25519 support:\n"
         
     | 
| 
      
 26 
     | 
    
         
            +
                      result << " * ed25519 (>= 1.2, < 2.0)\n"
         
     | 
| 
      
 27 
     | 
    
         
            +
                      result << " * bcrypt_pbkdf (>= 1.0, < 2.0)\n" unless RUBY_PLATFORM == "java"
         
     | 
| 
      
 28 
     | 
    
         
            +
                      result << "See https://github.com/net-ssh/net-ssh/issues/565 for more information\n"
         
     | 
| 
      
 29 
     | 
    
         
            +
                    end
         
     | 
| 
      
 30 
     | 
    
         
            +
                  
         
     | 
| 
      
 31 
     | 
    
         
            +
                  end
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
              end
         
     | 
| 
       29 
34 
     | 
    
         
             
            end
         
     | 
| 
       30 
     | 
    
         
            -
            end; end; end
         
     | 
| 
         @@ -43,7 +43,7 @@ module Net 
     | 
|
| 
       43 
43 
     | 
    
         
             
                      self.logger = logger
         
     | 
| 
       44 
44 
     | 
    
         
             
                      @key_files = []
         
     | 
| 
       45 
45 
     | 
    
         
             
                      @key_data = []
         
     | 
| 
       46 
     | 
    
         
            -
                      @use_agent =  
     | 
| 
      
 46 
     | 
    
         
            +
                      @use_agent = options[:use_agent] != false
         
     | 
| 
       47 
47 
     | 
    
         
             
                      @known_identities = {}
         
     | 
| 
       48 
48 
     | 
    
         
             
                      @agent = nil
         
     | 
| 
       49 
49 
     | 
    
         
             
                      @options = options
         
     | 
| 
         @@ -182,6 +182,10 @@ module Net 
     | 
|
| 
       182 
182 
     | 
    
         
             
                      nil
         
     | 
| 
       183 
183 
     | 
    
         
             
                    end
         
     | 
| 
       184 
184 
     | 
    
         | 
| 
      
 185 
     | 
    
         
            +
                    def no_keys?
         
     | 
| 
      
 186 
     | 
    
         
            +
                      key_files.empty? && key_data.empty?
         
     | 
| 
      
 187 
     | 
    
         
            +
                    end
         
     | 
| 
      
 188 
     | 
    
         
            +
             
     | 
| 
       185 
189 
     | 
    
         
             
                    private
         
     | 
| 
       186 
190 
     | 
    
         | 
| 
       187 
191 
     | 
    
         
             
                    # Prepares identities from user key_files for loading, preserving their order and sources.
         
     | 
| 
         @@ -235,7 +239,6 @@ module Net 
     | 
|
| 
       235 
239 
     | 
    
         
             
                          else
         
     | 
| 
       236 
240 
     | 
    
         
             
                            identity
         
     | 
| 
       237 
241 
     | 
    
         
             
                          end
         
     | 
| 
       238 
     | 
    
         
            -
             
     | 
| 
       239 
242 
     | 
    
         
             
                        rescue OpenSSL::PKey::RSAError, OpenSSL::PKey::DSAError, OpenSSL::PKey::ECError, OpenSSL::PKey::PKeyError, ArgumentError => e
         
     | 
| 
       240 
243 
     | 
    
         
             
                          if ignore_decryption_errors
         
     | 
| 
       241 
244 
     | 
    
         
             
                            identity
         
     | 
| 
         @@ -260,7 +263,6 @@ module Net 
     | 
|
| 
       260 
263 
     | 
    
         
             
                        raise e
         
     | 
| 
       261 
264 
     | 
    
         
             
                      end
         
     | 
| 
       262 
265 
     | 
    
         
             
                    end
         
     | 
| 
       263 
     | 
    
         
            -
             
     | 
| 
       264 
266 
     | 
    
         
             
                  end
         
     | 
| 
       265 
267 
     | 
    
         
             
                end
         
     | 
| 
       266 
268 
     | 
    
         
             
              end
         
     | 
| 
         @@ -3,62 +3,68 @@ require 'net/ssh/errors' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            require 'net/ssh/loggable'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'net/ssh/authentication/constants'
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
            module Net 
     | 
| 
      
 6 
     | 
    
         
            +
            module Net
         
     | 
| 
      
 7 
     | 
    
         
            +
              module SSH
         
     | 
| 
      
 8 
     | 
    
         
            +
                module Authentication
         
     | 
| 
      
 9 
     | 
    
         
            +
                  module Methods
         
     | 
| 
       7 
10 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
      
 11 
     | 
    
         
            +
                    # The base class of all user authentication methods. It provides a few
         
     | 
| 
      
 12 
     | 
    
         
            +
                    # bits of common functionality.
         
     | 
| 
      
 13 
     | 
    
         
            +
                    class Abstract
         
     | 
| 
      
 14 
     | 
    
         
            +
                      include Loggable
         
     | 
| 
      
 15 
     | 
    
         
            +
                      include Constants
         
     | 
| 
       12 
16 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
      
 17 
     | 
    
         
            +
                      # The authentication session object
         
     | 
| 
      
 18 
     | 
    
         
            +
                      attr_reader :session
         
     | 
| 
       15 
19 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
                      # The key manager object. Not all authentication methods will require
         
     | 
| 
      
 21 
     | 
    
         
            +
                      # this.
         
     | 
| 
      
 22 
     | 
    
         
            +
                      attr_reader :key_manager
         
     | 
| 
       19 
23 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
      
 24 
     | 
    
         
            +
                      # Instantiates a new authentication method.
         
     | 
| 
      
 25 
     | 
    
         
            +
                      def initialize(session, options={})
         
     | 
| 
      
 26 
     | 
    
         
            +
                        @session = session
         
     | 
| 
      
 27 
     | 
    
         
            +
                        @key_manager = options[:key_manager]
         
     | 
| 
      
 28 
     | 
    
         
            +
                        @options = options
         
     | 
| 
      
 29 
     | 
    
         
            +
                        @prompt = options[:password_prompt]
         
     | 
| 
      
 30 
     | 
    
         
            +
                        self.logger = session.logger
         
     | 
| 
      
 31 
     | 
    
         
            +
                      end
         
     | 
| 
       28 
32 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
      
 33 
     | 
    
         
            +
                      # Returns the session-id, as generated during the first key exchange of
         
     | 
| 
      
 34 
     | 
    
         
            +
                      # an SSH connection.
         
     | 
| 
      
 35 
     | 
    
         
            +
                      def session_id
         
     | 
| 
      
 36 
     | 
    
         
            +
                        session.transport.algorithms.session_id
         
     | 
| 
      
 37 
     | 
    
         
            +
                      end
         
     | 
| 
       34 
38 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
      
 39 
     | 
    
         
            +
                      # Sends a message via the underlying transport layer abstraction. This
         
     | 
| 
      
 40 
     | 
    
         
            +
                      # will block until the message is completely sent.
         
     | 
| 
      
 41 
     | 
    
         
            +
                      def send_message(msg)
         
     | 
| 
      
 42 
     | 
    
         
            +
                        session.transport.send_message(msg)
         
     | 
| 
      
 43 
     | 
    
         
            +
                      end
         
     | 
| 
       40 
44 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
      
 45 
     | 
    
         
            +
                      # Creates a new USERAUTH_REQUEST packet. The extra arguments on the end
         
     | 
| 
      
 46 
     | 
    
         
            +
                      # must be either boolean values or strings, and are tacked onto the end
         
     | 
| 
      
 47 
     | 
    
         
            +
                      # of the packet. The new packet is returned, ready for sending.
         
     | 
| 
      
 48 
     | 
    
         
            +
                      def userauth_request(username, next_service, auth_method, *others)
         
     | 
| 
      
 49 
     | 
    
         
            +
                        buffer = Net::SSH::Buffer.from(:byte, USERAUTH_REQUEST,
         
     | 
| 
      
 50 
     | 
    
         
            +
                          :string, username, :string, next_service, :string, auth_method)
         
     | 
| 
       47 
51 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
      
 52 
     | 
    
         
            +
                        others.each do |value|
         
     | 
| 
      
 53 
     | 
    
         
            +
                          case value
         
     | 
| 
      
 54 
     | 
    
         
            +
                          when true, false then buffer.write_bool(value)
         
     | 
| 
      
 55 
     | 
    
         
            +
                          when String      then buffer.write_string(value)
         
     | 
| 
      
 56 
     | 
    
         
            +
                          else raise ArgumentError, "don't know how to write #{value.inspect}"
         
     | 
| 
      
 57 
     | 
    
         
            +
                          end
         
     | 
| 
      
 58 
     | 
    
         
            +
                        end
         
     | 
| 
       55 
59 
     | 
    
         | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
      
 60 
     | 
    
         
            +
                        buffer
         
     | 
| 
      
 61 
     | 
    
         
            +
                      end
         
     | 
| 
       58 
62 
     | 
    
         | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
      
 63 
     | 
    
         
            +
                      private
         
     | 
| 
       60 
64 
     | 
    
         | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
      
 65 
     | 
    
         
            +
                      attr_reader :prompt
         
     | 
| 
      
 66 
     | 
    
         
            +
                    end
         
     | 
| 
      
 67 
     | 
    
         
            +
                  end
         
     | 
| 
      
 68 
     | 
    
         
            +
                end
         
     | 
| 
       62 
69 
     | 
    
         
             
              end
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
            end; end; end; end
         
     | 
| 
      
 70 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -24,49 +24,48 @@ module Net 
     | 
|
| 
       24 
24 
     | 
    
         | 
| 
       25 
25 
     | 
    
         
             
                      private
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
                        # Attempts to perform host-based authentication of the user, using
         
     | 
| 
       33 
     | 
    
         
            -
                        # the given host identity (key).
         
     | 
| 
       34 
     | 
    
         
            -
                        def authenticate_with(identity, next_service, username, key_manager)
         
     | 
| 
       35 
     | 
    
         
            -
                          debug { "trying hostbased (#{identity.fingerprint})" }
         
     | 
| 
       36 
     | 
    
         
            -
                          client_username = ENV['USER'] || username
         
     | 
| 
      
 27 
     | 
    
         
            +
                      # Returns the hostname as reported by the underlying socket.
         
     | 
| 
      
 28 
     | 
    
         
            +
                      def hostname
         
     | 
| 
      
 29 
     | 
    
         
            +
                        session.transport.socket.client_name
         
     | 
| 
      
 30 
     | 
    
         
            +
                      end
         
     | 
| 
       37 
31 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
      
 32 
     | 
    
         
            +
                      # Attempts to perform host-based authentication of the user, using
         
     | 
| 
      
 33 
     | 
    
         
            +
                      # the given host identity (key).
         
     | 
| 
      
 34 
     | 
    
         
            +
                      def authenticate_with(identity, next_service, username, key_manager)
         
     | 
| 
      
 35 
     | 
    
         
            +
                        debug { "trying hostbased (#{identity.fingerprint})" }
         
     | 
| 
      
 36 
     | 
    
         
            +
                        client_username = ENV['USER'] || username
         
     | 
| 
       40 
37 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
      
 38 
     | 
    
         
            +
                        req = build_request(identity, next_service, username, "#{hostname}.", client_username)
         
     | 
| 
      
 39 
     | 
    
         
            +
                        sig_data = Buffer.from(:string, session_id, :raw, req)
         
     | 
| 
       42 
40 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
      
 41 
     | 
    
         
            +
                        sig = key_manager.sign(identity, sig_data.to_s)
         
     | 
| 
       44 
42 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
                          message = session.next_message
         
     | 
| 
      
 43 
     | 
    
         
            +
                        message = Buffer.from(:raw, req, :string, sig)
         
     | 
| 
       47 
44 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                              info { "hostbased succeeded (#{identity.fingerprint})" }
         
     | 
| 
       51 
     | 
    
         
            -
                              return true
         
     | 
| 
       52 
     | 
    
         
            -
                            when USERAUTH_FAILURE
         
     | 
| 
       53 
     | 
    
         
            -
                              info { "hostbased failed (#{identity.fingerprint})" }
         
     | 
| 
      
 45 
     | 
    
         
            +
                        send_message(message)
         
     | 
| 
      
 46 
     | 
    
         
            +
                        message = session.next_message
         
     | 
| 
       54 
47 
     | 
    
         | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
      
 48 
     | 
    
         
            +
                        case message.type
         
     | 
| 
      
 49 
     | 
    
         
            +
                        when USERAUTH_SUCCESS
         
     | 
| 
      
 50 
     | 
    
         
            +
                          info { "hostbased succeeded (#{identity.fingerprint})" }
         
     | 
| 
      
 51 
     | 
    
         
            +
                          return true
         
     | 
| 
      
 52 
     | 
    
         
            +
                        when USERAUTH_FAILURE
         
     | 
| 
      
 53 
     | 
    
         
            +
                          info { "hostbased failed (#{identity.fingerprint})" }
         
     | 
| 
       57 
54 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
                             
     | 
| 
       60 
     | 
    
         
            -
                              raise Net::SSH::Exception, "unexpected server response to USERAUTH_REQUEST: #{message.type} (#{message.inspect})"
         
     | 
| 
       61 
     | 
    
         
            -
                          end
         
     | 
| 
       62 
     | 
    
         
            -
                        end
         
     | 
| 
      
 55 
     | 
    
         
            +
                          raise Net::SSH::Authentication::DisallowedMethod unless
         
     | 
| 
      
 56 
     | 
    
         
            +
                            message[:authentications].split(/,/).include? 'hostbased'
         
     | 
| 
       63 
57 
     | 
    
         | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
                         
     | 
| 
       66 
     | 
    
         
            -
                           
     | 
| 
       67 
     | 
    
         
            -
                            Buffer.from(:key, identity).to_s, hostname, client_username).to_s
         
     | 
| 
      
 58 
     | 
    
         
            +
                          return false
         
     | 
| 
      
 59 
     | 
    
         
            +
                        else
         
     | 
| 
      
 60 
     | 
    
         
            +
                          raise Net::SSH::Exception, "unexpected server response to USERAUTH_REQUEST: #{message.type} (#{message.inspect})"
         
     | 
| 
       68 
61 
     | 
    
         
             
                        end
         
     | 
| 
      
 62 
     | 
    
         
            +
                      end
         
     | 
| 
       69 
63 
     | 
    
         | 
| 
      
 64 
     | 
    
         
            +
                      # Build the "core" hostbased request string.
         
     | 
| 
      
 65 
     | 
    
         
            +
                      def build_request(identity, next_service, username, hostname, client_username)
         
     | 
| 
      
 66 
     | 
    
         
            +
                        userauth_request(username, next_service, "hostbased", identity.ssh_type,
         
     | 
| 
      
 67 
     | 
    
         
            +
                          Buffer.from(:key, identity).to_s, hostname, client_username).to_s
         
     | 
| 
      
 68 
     | 
    
         
            +
                      end
         
     | 
| 
       70 
69 
     | 
    
         
             
                    end
         
     | 
| 
       71 
70 
     | 
    
         | 
| 
       72 
71 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -40,12 +40,10 @@ module Net 
     | 
|
| 
       40 
40 
     | 
    
         
             
                            instruction = message.read_string
         
     | 
| 
       41 
41 
     | 
    
         
             
                            debug { "keyboard-interactive info request" }
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
                            if password.nil? && interactive? && prompter.nil?
         
     | 
| 
       44 
     | 
    
         
            -
                              prompter = prompt.start(type: 'keyboard-interactive', name: name, instruction: instruction)
         
     | 
| 
       45 
     | 
    
         
            -
                            end
         
     | 
| 
      
 43 
     | 
    
         
            +
                            prompter = prompt.start(type: 'keyboard-interactive', name: name, instruction: instruction) if password.nil? && interactive? && prompter.nil?
         
     | 
| 
       46 
44 
     | 
    
         | 
| 
       47 
45 
     | 
    
         
             
                            _ = message.read_string # lang_tag
         
     | 
| 
       48 
     | 
    
         
            -
                            responses =[]
         
     | 
| 
      
 46 
     | 
    
         
            +
                            responses = []
         
     | 
| 
       49 
47 
     | 
    
         | 
| 
       50 
48 
     | 
    
         
             
                            message.read_long.times do
         
     | 
| 
       51 
49 
     | 
    
         
             
                              text = message.read_string
         
     | 
| 
         @@ -14,18 +14,18 @@ module Net 
     | 
|
| 
       14 
14 
     | 
    
         
             
                        message = session.next_message
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
                        case message.type
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
      
 17 
     | 
    
         
            +
                        when USERAUTH_SUCCESS
         
     | 
| 
      
 18 
     | 
    
         
            +
                          debug { "none succeeded" }
         
     | 
| 
      
 19 
     | 
    
         
            +
                          return true
         
     | 
| 
      
 20 
     | 
    
         
            +
                        when USERAUTH_FAILURE
         
     | 
| 
      
 21 
     | 
    
         
            +
                          debug { "none failed" }
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
      
 23 
     | 
    
         
            +
                          raise Net::SSH::Authentication::DisallowedMethod unless
         
     | 
| 
      
 24 
     | 
    
         
            +
                            message[:authentications].split(/,/).include? 'none'
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
      
 26 
     | 
    
         
            +
                          return false
         
     | 
| 
      
 27 
     | 
    
         
            +
                        else
         
     | 
| 
      
 28 
     | 
    
         
            +
                          raise Net::SSH::Exception, "unexpected reply to USERAUTH_REQUEST: #{message.type} (#{message.inspect})"
         
     | 
| 
       29 
29 
     | 
    
         
             
                        end   
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
31 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -14,7 +14,7 @@ module Net 
     | 
|
| 
       14 
14 
     | 
    
         
             
                      def authenticate(next_service, username, password=nil)
         
     | 
| 
       15 
15 
     | 
    
         
             
                        clear_prompter!
         
     | 
| 
       16 
16 
     | 
    
         
             
                        retries = 0
         
     | 
| 
       17 
     | 
    
         
            -
                        max_retries = 
     | 
| 
      
 17 
     | 
    
         
            +
                        max_retries = get_max_retries
         
     | 
| 
       18 
18 
     | 
    
         
             
                        return false if !password && max_retries == 0
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
                        begin
         
     | 
| 
         @@ -34,17 +34,17 @@ module Net 
     | 
|
| 
       34 
34 
     | 
    
         
             
                        end until (message.type != USERAUTH_FAILURE || retries >= max_retries)
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
36 
     | 
    
         
             
                        case message.type
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
      
 37 
     | 
    
         
            +
                        when USERAUTH_SUCCESS
         
     | 
| 
      
 38 
     | 
    
         
            +
                          debug { "password succeeded" }
         
     | 
| 
      
 39 
     | 
    
         
            +
                          @prompter.success if @prompter
         
     | 
| 
      
 40 
     | 
    
         
            +
                          return true
         
     | 
| 
      
 41 
     | 
    
         
            +
                        when USERAUTH_FAILURE
         
     | 
| 
      
 42 
     | 
    
         
            +
                          return false
         
     | 
| 
      
 43 
     | 
    
         
            +
                        when USERAUTH_PASSWD_CHANGEREQ
         
     | 
| 
      
 44 
     | 
    
         
            +
                          debug { "password change request received, failing" }
         
     | 
| 
      
 45 
     | 
    
         
            +
                          return false
         
     | 
| 
      
 46 
     | 
    
         
            +
                        else
         
     | 
| 
      
 47 
     | 
    
         
            +
                          raise Net::SSH::Exception, "unexpected reply to USERAUTH_REQUEST: #{message.type} (#{message.inspect})"
         
     | 
| 
       48 
48 
     | 
    
         
             
                        end
         
     | 
| 
       49 
49 
     | 
    
         
             
                      end
         
     | 
| 
       50 
50 
     | 
    
         | 
| 
         @@ -59,7 +59,7 @@ module Net 
     | 
|
| 
       59 
59 
     | 
    
         | 
| 
       60 
60 
     | 
    
         
             
                      def ask_password(username)
         
     | 
| 
       61 
61 
     | 
    
         
             
                        host = session.transport.host
         
     | 
| 
       62 
     | 
    
         
            -
                        prompt_info = {type: 'password', user: username, host: host}
         
     | 
| 
      
 62 
     | 
    
         
            +
                        prompt_info = { type: 'password', user: username, host: host }
         
     | 
| 
       63 
63 
     | 
    
         
             
                        if @prompt_info != prompt_info
         
     | 
| 
       64 
64 
     | 
    
         
             
                          @prompt_info = prompt_info
         
     | 
| 
       65 
65 
     | 
    
         
             
                          @prompter = prompt.start(prompt_info)
         
     | 
| 
         @@ -25,69 +25,68 @@ module Net 
     | 
|
| 
       25 
25 
     | 
    
         | 
| 
       26 
26 
     | 
    
         
             
                      private
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
      
 28 
     | 
    
         
            +
                      # Builds a packet that contains the request formatted for sending
         
     | 
| 
      
 29 
     | 
    
         
            +
                      # a public-key request to the server.
         
     | 
| 
      
 30 
     | 
    
         
            +
                      def build_request(pub_key, username, next_service, has_sig)
         
     | 
| 
      
 31 
     | 
    
         
            +
                        blob = Net::SSH::Buffer.new
         
     | 
| 
      
 32 
     | 
    
         
            +
                        blob.write_key pub_key
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                        userauth_request(username, next_service, "publickey", has_sig,
         
     | 
| 
      
 35 
     | 
    
         
            +
                          pub_key.ssh_type, blob.to_s)
         
     | 
| 
      
 36 
     | 
    
         
            +
                      end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
      
 38 
     | 
    
         
            +
                      # Builds and sends a request formatted for a public-key
         
     | 
| 
      
 39 
     | 
    
         
            +
                      # authentication request.
         
     | 
| 
      
 40 
     | 
    
         
            +
                      def send_request(pub_key, username, next_service, signature=nil)
         
     | 
| 
      
 41 
     | 
    
         
            +
                        msg = build_request(pub_key, username, next_service, !signature.nil?)
         
     | 
| 
      
 42 
     | 
    
         
            +
                        msg.write_string(signature) if signature
         
     | 
| 
      
 43 
     | 
    
         
            +
                        send_message(msg)
         
     | 
| 
      
 44 
     | 
    
         
            +
                      end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                      # Attempts to perform public-key authentication for the given
         
     | 
| 
      
 47 
     | 
    
         
            +
                      # username, with the given identity (public key). Returns +true+ if
         
     | 
| 
      
 48 
     | 
    
         
            +
                      # successful, or +false+ otherwise.
         
     | 
| 
      
 49 
     | 
    
         
            +
                      def authenticate_with(identity, next_service, username)
         
     | 
| 
      
 50 
     | 
    
         
            +
                        debug { "trying publickey (#{identity.fingerprint})" }
         
     | 
| 
      
 51 
     | 
    
         
            +
                        send_request(identity, username, next_service)
         
     | 
| 
       45 
52 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
                         
     | 
| 
       47 
     | 
    
         
            -
                        # username, with the given identity (public key). Returns +true+ if
         
     | 
| 
       48 
     | 
    
         
            -
                        # successful, or +false+ otherwise.
         
     | 
| 
       49 
     | 
    
         
            -
                        def authenticate_with(identity, next_service, username)
         
     | 
| 
       50 
     | 
    
         
            -
                          debug { "trying publickey (#{identity.fingerprint})" }
         
     | 
| 
       51 
     | 
    
         
            -
                          send_request(identity, username, next_service)
         
     | 
| 
      
 53 
     | 
    
         
            +
                        message = session.next_message
         
     | 
| 
       52 
54 
     | 
    
         | 
| 
      
 55 
     | 
    
         
            +
                        case message.type
         
     | 
| 
      
 56 
     | 
    
         
            +
                        when USERAUTH_PK_OK
         
     | 
| 
      
 57 
     | 
    
         
            +
                          buffer = build_request(identity, username, next_service, true)
         
     | 
| 
      
 58 
     | 
    
         
            +
                          sig_data = Net::SSH::Buffer.new
         
     | 
| 
      
 59 
     | 
    
         
            +
                          sig_data.write_string(session_id)
         
     | 
| 
      
 60 
     | 
    
         
            +
                          sig_data.append(buffer.to_s)
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                          sig_blob = key_manager.sign(identity, sig_data)
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
                          send_request(identity, username, next_service, sig_blob.to_s)
         
     | 
| 
       53 
65 
     | 
    
         
             
                          message = session.next_message
         
     | 
| 
       54 
66 
     | 
    
         | 
| 
       55 
67 
     | 
    
         
             
                          case message.type
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
                                  debug { "publickey succeeded (#{identity.fingerprint})" }
         
     | 
| 
       70 
     | 
    
         
            -
                                  return true
         
     | 
| 
       71 
     | 
    
         
            -
                                when USERAUTH_FAILURE
         
     | 
| 
       72 
     | 
    
         
            -
                                  debug { "publickey failed (#{identity.fingerprint})" }
         
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
                                  raise Net::SSH::Authentication::DisallowedMethod unless
         
     | 
| 
       75 
     | 
    
         
            -
                                    message[:authentications].split(/,/).include? 'publickey'
         
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
                                  return false
         
     | 
| 
       78 
     | 
    
         
            -
                                else
         
     | 
| 
       79 
     | 
    
         
            -
                                  raise Net::SSH::Exception,
         
     | 
| 
       80 
     | 
    
         
            -
                                    "unexpected server response to USERAUTH_REQUEST: #{message.type} (#{message.inspect})"
         
     | 
| 
       81 
     | 
    
         
            -
                              end
         
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
                            when USERAUTH_FAILURE
         
     | 
| 
       84 
     | 
    
         
            -
                              return false
         
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
                            else
         
     | 
| 
       87 
     | 
    
         
            -
                              raise Net::SSH::Exception, "unexpected reply to USERAUTH_REQUEST: #{message.type} (#{message.inspect})"
         
     | 
| 
      
 68 
     | 
    
         
            +
                          when USERAUTH_SUCCESS
         
     | 
| 
      
 69 
     | 
    
         
            +
                            debug { "publickey succeeded (#{identity.fingerprint})" }
         
     | 
| 
      
 70 
     | 
    
         
            +
                            return true
         
     | 
| 
      
 71 
     | 
    
         
            +
                          when USERAUTH_FAILURE
         
     | 
| 
      
 72 
     | 
    
         
            +
                            debug { "publickey failed (#{identity.fingerprint})" }
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                            raise Net::SSH::Authentication::DisallowedMethod unless
         
     | 
| 
      
 75 
     | 
    
         
            +
                              message[:authentications].split(/,/).include? 'publickey'
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                            return false
         
     | 
| 
      
 78 
     | 
    
         
            +
                          else
         
     | 
| 
      
 79 
     | 
    
         
            +
                            raise Net::SSH::Exception,
         
     | 
| 
      
 80 
     | 
    
         
            +
                              "unexpected server response to USERAUTH_REQUEST: #{message.type} (#{message.inspect})"
         
     | 
| 
       88 
81 
     | 
    
         
             
                          end
         
     | 
| 
       89 
     | 
    
         
            -
                        end
         
     | 
| 
       90 
82 
     | 
    
         | 
| 
      
 83 
     | 
    
         
            +
                        when USERAUTH_FAILURE
         
     | 
| 
      
 84 
     | 
    
         
            +
                          return false
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
                        else
         
     | 
| 
      
 87 
     | 
    
         
            +
                          raise Net::SSH::Exception, "unexpected reply to USERAUTH_REQUEST: #{message.type} (#{message.inspect})"
         
     | 
| 
      
 88 
     | 
    
         
            +
                        end
         
     | 
| 
      
 89 
     | 
    
         
            +
                      end
         
     | 
| 
       91 
90 
     | 
    
         
             
                    end
         
     | 
| 
       92 
91 
     | 
    
         | 
| 
       93 
92 
     | 
    
         
             
                  end
         
     |