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

Inherits:
Object
  • Object
show all
Includes:
Constants, Loggable
Defined in:
lib/tpkg/thirdparty/net-ssh-2.1.0/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, 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.



21
22
23
24
25
26
# File 'lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/abstract.rb', line 21

def initialize(session, options={})
  @session = session
  @key_manager = options[:key_manager]
  @options = options
  self.logger = session.logger
end

Instance Attribute Details

#key_managerObject (readonly)

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



18
19
20
# File 'lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/abstract.rb', line 18

def key_manager
  @key_manager
end

#sessionObject (readonly)

The authentication session object



14
15
16
# File 'lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/abstract.rb', line 14

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.



36
37
38
# File 'lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/abstract.rb', line 36

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.



30
31
32
# File 'lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/abstract.rb', line 30

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.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/abstract.rb', line 43

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