Class: Net::SSH::Authentication::Methods::Abstract

Inherits:
Object
  • Object
show all
Includes:
Constants, Loggable
Defined in:
lib/net/ssh/authentication/methods/abstract.rb

Overview

The base class of all user authentication methods. It provides a few bits of common functionality.

Direct Known Subclasses

Hostbased, KeyboardInteractive, None, Password, Publickey

Constant Summary

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 collapse

Attributes included from Loggable

#logger

Instance Method Summary collapse

Methods included from Loggable

#debug, #error, #fatal, #info, #lwarn

Constructor Details

#initialize(session, options = {}) ⇒ Abstract

Instantiates a new authentication method.


29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/net/ssh/authentication/methods/abstract.rb', line 29

def initialize(session, options = {})
  @session = session
  @key_manager = options[:key_manager]
  @options = options
  @prompt = options[:password_prompt]
  @pubkey_algorithms = options[:pubkey_algorithms] \
    || %w[[email protected]
          [email protected]
          rsa-sha2-256
          ssh-rsa]
  self.logger = session.logger
end

Instance Attribute Details

#key_managerObject (readonly)

The key manager object. Not all authentication methods will require this.


21
22
23
# File 'lib/net/ssh/authentication/methods/abstract.rb', line 21

def key_manager
  @key_manager
end

#pubkey_algorithmsObject (readonly)

So far only affects algorithms used for rsa keys, but can be extended to other keys, e.g after reading of PubkeyAcceptedAlgorithms option from ssh_config file is implemented.


26
27
28
# File 'lib/net/ssh/authentication/methods/abstract.rb', line 26

def pubkey_algorithms
  @pubkey_algorithms
end

#sessionObject (readonly)

The authentication session object


17
18
19
# File 'lib/net/ssh/authentication/methods/abstract.rb', line 17

def session
  @session
end

Instance Method Details

#send_message(msg) ⇒ Object

Sends a message via the underlying transport layer abstraction. This will block until the message is completely sent.


50
51
52
# File 'lib/net/ssh/authentication/methods/abstract.rb', line 50

def send_message(msg)
  session.transport.send_message(msg)
end

#session_idObject

Returns the session-id, as generated during the first key exchange of an SSH connection.


44
45
46
# File 'lib/net/ssh/authentication/methods/abstract.rb', line 44

def session_id
  session.transport.algorithms.session_id
end

#userauth_request(username, next_service, auth_method, *others) ⇒ Object

Creates a new USERAUTH_REQUEST packet. The extra arguments on the end must be either boolean values or strings, and are tacked onto the end of the packet. The new packet is returned, ready for sending.


57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/net/ssh/authentication/methods/abstract.rb', line 57

def userauth_request(username, next_service, auth_method, *others)
  buffer = Net::SSH::Buffer.from(:byte, USERAUTH_REQUEST,
                                 :string, username, :string, next_service, :string, auth_method)

  others.each do |value|
    case value
    when true, false then buffer.write_bool(value)
    when String      then buffer.write_string(value)
    else raise ArgumentError, "don't know how to write #{value.inspect}"
    end
  end

  buffer
end