Class: Net::SSH::Authentication::Methods::KeyboardInteractive
- Includes:
- begin require 'highline' HighLinebegin require 'highline' HighLine.track_eof = false PromptMethods::Highline rescue LoadError begin require 'termios' PromptMethods::Termios rescue LoadError PromptMethods::Clear end end
- Defined in:
- lib/net/ssh/authentication/methods/keyboard_interactive.rb
Overview
Implements the “keyboard-interactive” SSH authentication method.
Constant Summary collapse
- USERAUTH_INFO_REQUEST =
60
- USERAUTH_INFO_RESPONSE =
61
Constants included from Constants
Constants::USERAUTH_BANNER, Constants::USERAUTH_FAILURE, Constants::USERAUTH_METHOD_RANGE, Constants::USERAUTH_PASSWD_CHANGEREQ, Constants::USERAUTH_PK_OK, Constants::USERAUTH_REQUEST, Constants::USERAUTH_SUCCESS
Instance Attribute Summary
Attributes inherited from Abstract
Attributes included from Loggable
Instance Method Summary collapse
-
#authenticate(next_service, username, password = nil) ⇒ Object
Attempt to authenticate the given user for the given service.
Methods inherited from Abstract
#initialize, #send_message, #session_id, #userauth_request
Methods included from Loggable
#debug, #error, #fatal, #info, #lwarn
Constructor Details
This class inherits a constructor from Net::SSH::Authentication::Methods::Abstract
Instance Method Details
#authenticate(next_service, username, password = nil) ⇒ Object
Attempt to authenticate the given user for the given service.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/net/ssh/authentication/methods/keyboard_interactive.rb', line 17 def authenticate(next_service, username, password=nil) debug { "trying keyboard-interactive" } (userauth_request(username, next_service, "keyboard-interactive", "", "")) loop do = session. case .type when USERAUTH_SUCCESS debug { "keyboard-interactive succeeded" } return true when USERAUTH_FAILURE debug { "keyboard-interactive failed" } return false when USERAUTH_INFO_REQUEST name = .read_string instruction = .read_string debug { "keyboard-interactive info request" } unless password puts(name) unless name.empty? puts(instruction) unless instruction.empty? end lang_tag = .read_string responses =[] .read_long.times do text = .read_string echo = .read_bool responses << (password || prompt(text, echo)) end # if the password failed the first time around, don't try # and use it on subsequent requests. password = nil msg = Buffer.from(:byte, USERAUTH_INFO_RESPONSE, :long, responses.length, :string, responses) (msg) else raise Net::SSH::Exception, "unexpected reply in keyboard interactive: #{.type} (#{.inspect})" end end end |