Implements the host-based SSH authentication method.
Attempts to perform host-based authorization of the user by trying all known keys.
# File lib/net/ssh/authentication/methods/hostbased.rb, line 14 14: def authenticate(next_service, username, password=nil) 15: return false unless key_manager 16: 17: key_manager.each_identity do |identity| 18: return true if authenticate_with(identity, next_service, 19: username, key_manager) 20: end 21: 22: return false 23: end
Attempts to perform host-based authentication of the user, using the given host identity (key).
# File lib/net/ssh/authentication/methods/hostbased.rb, line 34 34: def authenticate_with(identity, next_service, username, key_manager) 35: debug { "trying hostbased (#{identity.fingerprint})" } 36: client_username = ENV['USER'] || username 37: 38: req = build_request(identity, next_service, username, "#{hostname}.", client_username) 39: sig_data = Buffer.from(:string, session_id, :raw, req) 40: 41: sig = key_manager.sign(identity, sig_data.to_s) 42: 43: message = Buffer.from(:raw, req, :string, sig) 44: 45: send_message(message) 46: message = session.next_message 47: 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})" } 54: 55: raise Net::SSH::Authentication::DisallowedMethod unless 56: message[:authentications].split(/,/).include? 'hostbased' 57: 58: return false 59: else 60: raise Net::SSH::Exception, "unexpected server response to USERAUTH_REQUEST: #{message.type} (#{message.inspect})" 61: end 62: end
Build the “core” hostbased request string.
# File lib/net/ssh/authentication/methods/hostbased.rb, line 65 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
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.