Class Net::SSH::Authentication::Methods::KeyboardInteractive

  1. lib/net/ssh/authentication/methods/keyboard_interactive.rb

Implements the “keyboard-interactive” SSH authentication method.

Methods

public instance

  1. authenticate

Included modules

  1. Prompt

Constants

USERAUTH_INFO_REQUEST = 60
USERAUTH_INFO_RESPONSE = 61

Public instance methods

authenticate (next_service, username, password=nil)

Attempt to authenticate the given user for the given service.

[show source]
    # File lib/net/ssh/authentication/methods/keyboard_interactive.rb, line 17
17:           def authenticate(next_service, username, password=nil)
18:             debug { "trying keyboard-interactive" }
19:             send_message(userauth_request(username, next_service, "keyboard-interactive", "", ""))
20: 
21:             loop do
22:               message = session.next_message
23: 
24:               case message.type
25:               when USERAUTH_SUCCESS
26:                 debug { "keyboard-interactive succeeded" }
27:                 return true
28:               when USERAUTH_FAILURE
29:                 debug { "keyboard-interactive failed" }
30:                 return false
31:               when USERAUTH_INFO_REQUEST
32:                 name = message.read_string
33:                 instruction = message.read_string
34:                 debug { "keyboard-interactive info request" }
35: 
36:                 unless password
37:                   puts(name) unless name.empty?
38:                   puts(instruction) unless instruction.empty?
39:                 end
40: 
41:                 lang_tag = message.read_string
42:                 responses =[]
43:   
44:                 message.read_long.times do
45:                   text = message.read_string
46:                   echo = message.read_bool
47:                   responses << (password || prompt(text, echo))
48:                 end
49: 
50:                 # if the password failed the first time around, don't try
51:                 # and use it on subsequent requests.
52:                 password = nil
53: 
54:                 msg = Buffer.from(:byte, USERAUTH_INFO_RESPONSE, :long, responses.length, :string, responses)
55:                 send_message(msg)
56:               else
57:                 raise Net::SSH::Exception, "unexpected reply in keyboard interactive: #{message.type} (#{message.inspect})"
58:               end
59:             end
60:           end