class Net::SSH::Authentication::Methods::Abstract

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

Attributes

key_manager[R]

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

prompt[R]
pubkey_algorithms[R]

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.

session[R]

The authentication session object

Public Class Methods

new(session, options = {}) click to toggle source

Instantiates a new authentication method.

# 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[rsa-sha2-256-cert-v01@openssh.com
          ssh-rsa-cert-v01@openssh.com
          rsa-sha2-256
          ssh-rsa]
  self.logger = session.logger
end

Public Instance Methods

send_message(msg) click to toggle source

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

# File lib/net/ssh/authentication/methods/abstract.rb, line 50
def send_message(msg)
  session.transport.send_message(msg)
end
session_id() click to toggle source

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

# 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) click to toggle source

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.

# 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