jayniz-net-ssh 2.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +161 -0
- data/Manifest +107 -0
- data/README.rdoc +140 -0
- data/Rakefile +79 -0
- data/Rudyfile +110 -0
- data/THANKS.rdoc +16 -0
- data/lib/net/ssh/authentication/agent.rb +176 -0
- data/lib/net/ssh/authentication/constants.rb +18 -0
- data/lib/net/ssh/authentication/key_manager.rb +193 -0
- data/lib/net/ssh/authentication/methods/abstract.rb +60 -0
- data/lib/net/ssh/authentication/methods/hostbased.rb +71 -0
- data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +66 -0
- data/lib/net/ssh/authentication/methods/password.rb +39 -0
- data/lib/net/ssh/authentication/methods/publickey.rb +92 -0
- data/lib/net/ssh/authentication/pageant.rb +183 -0
- data/lib/net/ssh/authentication/session.rb +134 -0
- data/lib/net/ssh/buffer.rb +340 -0
- data/lib/net/ssh/buffered_io.rb +150 -0
- data/lib/net/ssh/config.rb +185 -0
- data/lib/net/ssh/connection/channel.rb +625 -0
- data/lib/net/ssh/connection/constants.rb +33 -0
- data/lib/net/ssh/connection/session.rb +597 -0
- data/lib/net/ssh/connection/term.rb +178 -0
- data/lib/net/ssh/errors.rb +85 -0
- data/lib/net/ssh/key_factory.rb +102 -0
- data/lib/net/ssh/known_hosts.rb +129 -0
- data/lib/net/ssh/loggable.rb +61 -0
- data/lib/net/ssh/packet.rb +102 -0
- data/lib/net/ssh/prompt.rb +93 -0
- data/lib/net/ssh/proxy/errors.rb +14 -0
- data/lib/net/ssh/proxy/http.rb +94 -0
- data/lib/net/ssh/proxy/socks4.rb +70 -0
- data/lib/net/ssh/proxy/socks5.rb +142 -0
- data/lib/net/ssh/ruby_compat.rb +43 -0
- data/lib/net/ssh/service/forward.rb +267 -0
- data/lib/net/ssh/test/channel.rb +129 -0
- data/lib/net/ssh/test/extensions.rb +152 -0
- data/lib/net/ssh/test/kex.rb +44 -0
- data/lib/net/ssh/test/local_packet.rb +51 -0
- data/lib/net/ssh/test/packet.rb +81 -0
- data/lib/net/ssh/test/remote_packet.rb +38 -0
- data/lib/net/ssh/test/script.rb +157 -0
- data/lib/net/ssh/test/socket.rb +59 -0
- data/lib/net/ssh/test.rb +89 -0
- data/lib/net/ssh/transport/algorithms.rb +384 -0
- data/lib/net/ssh/transport/cipher_factory.rb +97 -0
- data/lib/net/ssh/transport/constants.rb +30 -0
- data/lib/net/ssh/transport/hmac/abstract.rb +79 -0
- data/lib/net/ssh/transport/hmac/md5.rb +12 -0
- data/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
- data/lib/net/ssh/transport/hmac/none.rb +15 -0
- data/lib/net/ssh/transport/hmac/sha1.rb +13 -0
- data/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
- data/lib/net/ssh/transport/hmac.rb +31 -0
- data/lib/net/ssh/transport/identity_cipher.rb +55 -0
- data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
- data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
- data/lib/net/ssh/transport/kex.rb +13 -0
- data/lib/net/ssh/transport/openssl.rb +128 -0
- data/lib/net/ssh/transport/packet_stream.rb +232 -0
- data/lib/net/ssh/transport/server_version.rb +70 -0
- data/lib/net/ssh/transport/session.rb +276 -0
- data/lib/net/ssh/transport/state.rb +206 -0
- data/lib/net/ssh/verifiers/lenient.rb +30 -0
- data/lib/net/ssh/verifiers/null.rb +12 -0
- data/lib/net/ssh/verifiers/strict.rb +53 -0
- data/lib/net/ssh/version.rb +62 -0
- data/lib/net/ssh.rb +215 -0
- data/net-ssh.gemspec +131 -0
- data/setup.rb +1585 -0
- data/support/arcfour_check.rb +20 -0
- data/test/authentication/methods/common.rb +28 -0
- data/test/authentication/methods/test_abstract.rb +51 -0
- data/test/authentication/methods/test_hostbased.rb +114 -0
- data/test/authentication/methods/test_keyboard_interactive.rb +98 -0
- data/test/authentication/methods/test_password.rb +50 -0
- data/test/authentication/methods/test_publickey.rb +127 -0
- data/test/authentication/test_agent.rb +205 -0
- data/test/authentication/test_key_manager.rb +105 -0
- data/test/authentication/test_session.rb +93 -0
- data/test/common.rb +107 -0
- data/test/configs/eqsign +3 -0
- data/test/configs/exact_match +8 -0
- data/test/configs/multihost +4 -0
- data/test/configs/wild_cards +14 -0
- data/test/connection/test_channel.rb +452 -0
- data/test/connection/test_session.rb +488 -0
- data/test/test_all.rb +8 -0
- data/test/test_buffer.rb +336 -0
- data/test/test_buffered_io.rb +63 -0
- data/test/test_config.rb +99 -0
- data/test/test_key_factory.rb +67 -0
- data/test/transport/hmac/test_md5.rb +39 -0
- data/test/transport/hmac/test_md5_96.rb +25 -0
- data/test/transport/hmac/test_none.rb +34 -0
- data/test/transport/hmac/test_sha1.rb +34 -0
- data/test/transport/hmac/test_sha1_96.rb +25 -0
- data/test/transport/kex/test_diffie_hellman_group1_sha1.rb +146 -0
- data/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +92 -0
- data/test/transport/test_algorithms.rb +302 -0
- data/test/transport/test_cipher_factory.rb +213 -0
- data/test/transport/test_hmac.rb +34 -0
- data/test/transport/test_identity_cipher.rb +40 -0
- data/test/transport/test_packet_stream.rb +441 -0
- data/test/transport/test_server_version.rb +68 -0
- data/test/transport/test_session.rb +315 -0
- data/test/transport/test_state.rb +173 -0
- metadata +168 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'net/ssh/verifiers/strict'
|
2
|
+
|
3
|
+
module Net; module SSH; module Verifiers
|
4
|
+
|
5
|
+
# Basically the same as the Strict verifier, but does not try to actually
|
6
|
+
# verify a connection if the server is the localhost and the port is a
|
7
|
+
# nonstandard port number. Those two conditions will typically mean the
|
8
|
+
# connection is being tunnelled through a forwarded port, so the known-hosts
|
9
|
+
# file will not be helpful (in general).
|
10
|
+
class Lenient < Strict
|
11
|
+
# Tries to determine if the connection is being tunnelled, and if so,
|
12
|
+
# returns true. Otherwise, performs the standard strict verification.
|
13
|
+
def verify(arguments)
|
14
|
+
return true if tunnelled?(arguments)
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
# A connection is potentially being tunnelled if the port is not 22,
|
21
|
+
# and the ip refers to the localhost.
|
22
|
+
def tunnelled?(args)
|
23
|
+
return false if args[:session].port == Net::SSH::Transport::Session::DEFAULT_PORT
|
24
|
+
|
25
|
+
ip = args[:session].peer[:ip]
|
26
|
+
return ip == "127.0.0.1" || ip == "::1"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end; end; end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Net; module SSH; module Verifiers
|
2
|
+
|
3
|
+
# The Null host key verifier simply allows every key it sees, without
|
4
|
+
# bothering to verify. This is simple, but is not particularly secure.
|
5
|
+
class Null
|
6
|
+
# Returns true.
|
7
|
+
def verify(arguments)
|
8
|
+
true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end; end; end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'net/ssh/errors'
|
2
|
+
require 'net/ssh/known_hosts'
|
3
|
+
|
4
|
+
module Net; module SSH; module Verifiers
|
5
|
+
|
6
|
+
# Does a strict host verification, looking the server up in the known
|
7
|
+
# host files to see if a key has already been seen for this server. If this
|
8
|
+
# server does not appear in any host file, this will silently add the
|
9
|
+
# server. If the server does appear at least once, but the key given does
|
10
|
+
# not match any known for the server, an exception will be raised (HostKeyMismatch).
|
11
|
+
# Otherwise, this returns true.
|
12
|
+
class Strict
|
13
|
+
def verify(arguments)
|
14
|
+
options = arguments[:session].options
|
15
|
+
host = options[:host_key_alias] || arguments[:session].host_as_string
|
16
|
+
matches = Net::SSH::KnownHosts.search_for(host, arguments[:session].options)
|
17
|
+
|
18
|
+
# we've never seen this host before, so just automatically add the key.
|
19
|
+
# not the most secure option (since the first hit might be the one that
|
20
|
+
# is hacked), but since almost nobody actually compares the key
|
21
|
+
# fingerprint, this is a reasonable compromise between usability and
|
22
|
+
# security.
|
23
|
+
if matches.empty?
|
24
|
+
ip = arguments[:session].peer[:ip]
|
25
|
+
Net::SSH::KnownHosts.add(host, arguments[:key], arguments[:session].options)
|
26
|
+
return true
|
27
|
+
end
|
28
|
+
|
29
|
+
# If we found any matches, check to see that the key type and
|
30
|
+
# blob also match.
|
31
|
+
found = matches.any? do |key|
|
32
|
+
key.ssh_type == arguments[:key].ssh_type &&
|
33
|
+
key.to_blob == arguments[:key].to_blob
|
34
|
+
end
|
35
|
+
|
36
|
+
# If a match was found, return true. Otherwise, raise an exception
|
37
|
+
# indicating that the key was not recognized.
|
38
|
+
found || process_cache_miss(host, arguments)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def process_cache_miss(host, args)
|
44
|
+
exception = HostKeyMismatch.new("fingerprint #{args[:fingerprint]} does not match for #{host.inspect}")
|
45
|
+
exception.data = args
|
46
|
+
exception.callback = Proc.new do
|
47
|
+
Net::SSH::KnownHosts.add(host, args[:key], args[:session].options)
|
48
|
+
end
|
49
|
+
raise exception
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end; end; end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Net; module SSH
|
2
|
+
# A class for describing the current version of a library. The version
|
3
|
+
# consists of three parts: the +major+ number, the +minor+ number, and the
|
4
|
+
# +tiny+ (or +patch+) number.
|
5
|
+
#
|
6
|
+
# Two Version instances may be compared, so that you can test that a version
|
7
|
+
# of a library is what you require:
|
8
|
+
#
|
9
|
+
# require 'net/ssh/version'
|
10
|
+
#
|
11
|
+
# if Net::SSH::Version::CURRENT < Net::SSH::Version[2,1,0]
|
12
|
+
# abort "your software is too old!"
|
13
|
+
# end
|
14
|
+
class Version
|
15
|
+
include Comparable
|
16
|
+
|
17
|
+
# A convenience method for instantiating a new Version instance with the
|
18
|
+
# given +major+, +minor+, and +tiny+ components.
|
19
|
+
def self.[](major, minor, tiny)
|
20
|
+
new(major, minor, tiny)
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :major, :minor, :tiny
|
24
|
+
|
25
|
+
# Create a new Version object with the given components.
|
26
|
+
def initialize(major, minor, tiny)
|
27
|
+
@major, @minor, @tiny = major, minor, tiny
|
28
|
+
end
|
29
|
+
|
30
|
+
# Compare this version to the given +version+ object.
|
31
|
+
def <=>(version)
|
32
|
+
to_i <=> version.to_i
|
33
|
+
end
|
34
|
+
|
35
|
+
# Converts this version object to a string, where each of the three
|
36
|
+
# version components are joined by the '.' character. E.g., 2.0.0.
|
37
|
+
def to_s
|
38
|
+
@to_s ||= [@major, @minor, @tiny].join(".")
|
39
|
+
end
|
40
|
+
|
41
|
+
# Converts this version to a canonical integer that may be compared
|
42
|
+
# against other version objects.
|
43
|
+
def to_i
|
44
|
+
@to_i ||= @major * 1_000_000 + @minor * 1_000 + @tiny
|
45
|
+
end
|
46
|
+
|
47
|
+
# The major component of this version of the Net::SSH library
|
48
|
+
MAJOR = 2
|
49
|
+
|
50
|
+
# The minor component of this version of the Net::SSH library
|
51
|
+
MINOR = 0
|
52
|
+
|
53
|
+
# The tiny component of this version of the Net::SSH library
|
54
|
+
TINY = 15
|
55
|
+
|
56
|
+
# The current version of the Net::SSH library as a Version instance
|
57
|
+
CURRENT = new(MAJOR, MINOR, TINY)
|
58
|
+
|
59
|
+
# The current version of the Net::SSH library as a String
|
60
|
+
STRING = CURRENT.to_s
|
61
|
+
end
|
62
|
+
end; end
|
data/lib/net/ssh.rb
ADDED
@@ -0,0 +1,215 @@
|
|
1
|
+
# Make sure HOME is set, regardless of OS, so that File.expand_path works
|
2
|
+
# as expected with tilde characters.
|
3
|
+
ENV['HOME'] ||= ENV['HOMEPATH'] ? "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}" : "."
|
4
|
+
|
5
|
+
require 'logger'
|
6
|
+
|
7
|
+
require 'net/ssh/config'
|
8
|
+
require 'net/ssh/errors'
|
9
|
+
require 'net/ssh/loggable'
|
10
|
+
require 'net/ssh/transport/session'
|
11
|
+
require 'net/ssh/authentication/session'
|
12
|
+
require 'net/ssh/connection/session'
|
13
|
+
|
14
|
+
module Net
|
15
|
+
|
16
|
+
# Net::SSH is a library for interacting, programmatically, with remote
|
17
|
+
# processes via the SSH2 protocol. Sessions are always initiated via
|
18
|
+
# Net::SSH.start. From there, a program interacts with the new SSH session
|
19
|
+
# via the convenience methods on Net::SSH::Connection::Session, by opening
|
20
|
+
# and interacting with new channels (Net::SSH::Connection:Session#open_channel
|
21
|
+
# and Net::SSH::Connection::Channel), or by forwarding local and/or
|
22
|
+
# remote ports through the connection (Net::SSH::Service::Forward).
|
23
|
+
#
|
24
|
+
# The SSH protocol is very event-oriented. Requests are sent from the client
|
25
|
+
# to the server, and are answered asynchronously. This gives great flexibility
|
26
|
+
# (since clients can have multiple requests pending at a time), but it also
|
27
|
+
# adds complexity. Net::SSH tries to manage this complexity by providing
|
28
|
+
# some simpler methods of synchronous communication (see Net::SSH::Connection::Session#exec!).
|
29
|
+
#
|
30
|
+
# In general, though, and if you want to do anything more complicated than
|
31
|
+
# simply executing commands and capturing their output, you'll need to use
|
32
|
+
# channels (Net::SSH::Connection::Channel) to build state machines that are
|
33
|
+
# executed while the event loop runs (Net::SSH::Connection::Session#loop).
|
34
|
+
#
|
35
|
+
# Net::SSH::Connection::Session and Net::SSH::Connection::Channel have more
|
36
|
+
# information about this technique.
|
37
|
+
#
|
38
|
+
# = "Um, all I want to do is X, just show me how!"
|
39
|
+
#
|
40
|
+
# == X == "execute a command and capture the output"
|
41
|
+
#
|
42
|
+
# Net::SSH.start("host", "user", :password => "password") do |ssh|
|
43
|
+
# result = ssh.exec!("ls -l")
|
44
|
+
# puts result
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# == X == "forward connections on a local port to a remote host"
|
48
|
+
#
|
49
|
+
# Net::SSH.start("host", "user", :password => "password") do |ssh|
|
50
|
+
# ssh.forward.local(1234, "www.google.com", 80)
|
51
|
+
# ssh.loop { true }
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# == X == "forward connections on a remote port to the local host"
|
55
|
+
#
|
56
|
+
# Net::SSH.start("host", "user", :password => "password") do |ssh|
|
57
|
+
# ssh.forward.remote(80, "www.google.com", 1234)
|
58
|
+
# ssh.loop { true }
|
59
|
+
# end
|
60
|
+
module SSH
|
61
|
+
# This is the set of options that Net::SSH.start recognizes. See
|
62
|
+
# Net::SSH.start for a description of each option.
|
63
|
+
VALID_OPTIONS = [
|
64
|
+
:auth_methods, :compression, :compression_level, :config, :encryption,
|
65
|
+
:forward_agent, :hmac, :host_key, :kex, :keys, :key_data, :languages,
|
66
|
+
:logger, :paranoid, :password, :port, :proxy, :rekey_blocks_limit,
|
67
|
+
:rekey_limit, :rekey_packet_limit, :timeout, :verbose,
|
68
|
+
:global_known_hosts_file, :user_known_hosts_file, :host_key_alias,
|
69
|
+
:host_name, :user, :properties, :passphrase
|
70
|
+
]
|
71
|
+
|
72
|
+
# The standard means of starting a new SSH connection. When used with a
|
73
|
+
# block, the connection will be closed when the block terminates, otherwise
|
74
|
+
# the connection will just be returned. The yielded (or returned) value
|
75
|
+
# will be an instance of Net::SSH::Connection::Session (q.v.). (See also
|
76
|
+
# Net::SSH::Connection::Channel and Net::SSH::Service::Forward.)
|
77
|
+
#
|
78
|
+
# Net::SSH.start("host", "user") do |ssh|
|
79
|
+
# ssh.exec! "cp /some/file /another/location"
|
80
|
+
# hostname = ssh.exec!("hostname")
|
81
|
+
#
|
82
|
+
# ssh.open_channel do |ch|
|
83
|
+
# ch.exec "sudo -p 'sudo password: ' ls" do |ch, success|
|
84
|
+
# abort "could not execute sudo ls" unless success
|
85
|
+
#
|
86
|
+
# ch.on_data do |ch, data|
|
87
|
+
# print data
|
88
|
+
# if data =~ /sudo password: /
|
89
|
+
# ch.send_data("password\n")
|
90
|
+
# end
|
91
|
+
# end
|
92
|
+
# end
|
93
|
+
# end
|
94
|
+
#
|
95
|
+
# ssh.loop
|
96
|
+
# end
|
97
|
+
#
|
98
|
+
# This method accepts the following options (all are optional):
|
99
|
+
#
|
100
|
+
# * :auth_methods => an array of authentication methods to try
|
101
|
+
# * :compression => the compression algorithm to use, or +true+ to use
|
102
|
+
# whatever is supported.
|
103
|
+
# * :compression_level => the compression level to use when sending data
|
104
|
+
# * :config => set to +true+ to load the default OpenSSH config files
|
105
|
+
# (~/.ssh/config, /etc/ssh_config), or to +false+ to not load them, or to
|
106
|
+
# a file-name (or array of file-names) to load those specific configuration
|
107
|
+
# files. Defaults to +true+.
|
108
|
+
# * :encryption => the encryption cipher (or ciphers) to use
|
109
|
+
# * :forward_agent => set to true if you want the SSH agent connection to
|
110
|
+
# be forwarded
|
111
|
+
# * :global_known_hosts_file => the location of the global known hosts
|
112
|
+
# file. Set to an array if you want to specify multiple global known
|
113
|
+
# hosts files. Defaults to %w(/etc/ssh/known_hosts /etc/ssh/known_hosts2).
|
114
|
+
# * :hmac => the hmac algorithm (or algorithms) to use
|
115
|
+
# * :host_key => the host key algorithm (or algorithms) to use
|
116
|
+
# * :host_key_alias => the host name to use when looking up or adding a
|
117
|
+
# host to a known_hosts dictionary file
|
118
|
+
# * :host_name => the real host name or IP to log into. This is used
|
119
|
+
# instead of the +host+ parameter, and is primarily only useful when
|
120
|
+
# specified in an SSH configuration file. It lets you specify an
|
121
|
+
# "alias", similarly to adding an entry in /etc/hosts but without needing
|
122
|
+
# to modify /etc/hosts.
|
123
|
+
# * :kex => the key exchange algorithm (or algorithms) to use
|
124
|
+
# * :keys => an array of file names of private keys to use for publickey
|
125
|
+
# and hostbased authentication
|
126
|
+
# * :key_data => an array of strings, with each element of the array being
|
127
|
+
# a raw private key in PEM format.
|
128
|
+
# * :logger => the logger instance to use when logging
|
129
|
+
# * :paranoid => either true, false, or :very, specifying how strict
|
130
|
+
# host-key verification should be
|
131
|
+
# * :passphrase => the passphrase to use when loading a private key (default
|
132
|
+
# is +nil+, for no passphrase)
|
133
|
+
# * :password => the password to use to login
|
134
|
+
# * :port => the port to use when connecting to the remote host
|
135
|
+
# * :properties => a hash of key/value pairs to add to the new connection's
|
136
|
+
# properties (see Net::SSH::Connection::Session#properties)
|
137
|
+
# * :proxy => a proxy instance (see Proxy) to use when connecting
|
138
|
+
# * :rekey_blocks_limit => the max number of blocks to process before rekeying
|
139
|
+
# * :rekey_limit => the max number of bytes to process before rekeying
|
140
|
+
# * :rekey_packet_limit => the max number of packets to process before rekeying
|
141
|
+
# * :timeout => how long to wait for the initial connection to be made
|
142
|
+
# * :user => the user name to log in as; this overrides the +user+
|
143
|
+
# parameter, and is primarily only useful when provided via an SSH
|
144
|
+
# configuration file.
|
145
|
+
# * :user_known_hosts_file => the location of the user known hosts file.
|
146
|
+
# Set to an array to specify multiple user known hosts files.
|
147
|
+
# Defaults to %w(~/.ssh/known_hosts ~/.ssh/known_hosts2).
|
148
|
+
# * :verbose => how verbose to be (Logger verbosity constants, Logger::DEBUG
|
149
|
+
# is very verbose, Logger::FATAL is all but silent). Logger::FATAL is the
|
150
|
+
# default. The symbols :debug, :info, :warn, :error, and :fatal are also
|
151
|
+
# supported and are translated to the corresponding Logger constant.
|
152
|
+
def self.start(host, user, options={}, &block)
|
153
|
+
invalid_options = options.keys - VALID_OPTIONS
|
154
|
+
if invalid_options.any?
|
155
|
+
raise ArgumentError, "invalid option(s): #{invalid_options.join(', ')}"
|
156
|
+
end
|
157
|
+
|
158
|
+
options[:user] = user if user
|
159
|
+
options = configuration_for(host, options.fetch(:config, true)).merge(options)
|
160
|
+
host = options.fetch(:host_name, host)
|
161
|
+
|
162
|
+
if !options.key?(:logger)
|
163
|
+
options[:logger] = Logger.new(STDERR)
|
164
|
+
options[:logger].level = Logger::FATAL
|
165
|
+
end
|
166
|
+
|
167
|
+
if options[:verbose]
|
168
|
+
options[:logger].level = case options[:verbose]
|
169
|
+
when Fixnum then options[:verbose]
|
170
|
+
when :debug then Logger::DEBUG
|
171
|
+
when :info then Logger::INFO
|
172
|
+
when :warn then Logger::WARN
|
173
|
+
when :error then Logger::ERROR
|
174
|
+
when :fatal then Logger::FATAL
|
175
|
+
else raise ArgumentError, "can't convert #{options[:verbose].inspect} to any of the Logger level constants"
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
transport = Transport::Session.new(host, options)
|
180
|
+
auth = Authentication::Session.new(transport, options)
|
181
|
+
|
182
|
+
user = options.fetch(:user, user)
|
183
|
+
if auth.authenticate("ssh-connection", user, options[:password])
|
184
|
+
connection = Connection::Session.new(transport, options)
|
185
|
+
if block_given?
|
186
|
+
yield connection
|
187
|
+
connection.close
|
188
|
+
else
|
189
|
+
return connection
|
190
|
+
end
|
191
|
+
else
|
192
|
+
raise AuthenticationFailed, user
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# Returns a hash of the configuration options for the given host, as read
|
197
|
+
# from the SSH configuration file(s). If +use_ssh_config+ is true (the
|
198
|
+
# default), this will load configuration from both ~/.ssh/config and
|
199
|
+
# /etc/ssh_config. If +use_ssh_config+ is nil or false, nothing will be
|
200
|
+
# loaded (and an empty hash returned). Otherwise, +use_ssh_config+ may
|
201
|
+
# be a file name (or array of file names) of SSH configuration file(s)
|
202
|
+
# to read.
|
203
|
+
#
|
204
|
+
# See Net::SSH::Config for the full description of all supported options.
|
205
|
+
def self.configuration_for(host, use_ssh_config=true)
|
206
|
+
files = case use_ssh_config
|
207
|
+
when true then Net::SSH::Config.default_files
|
208
|
+
when false, nil then return {}
|
209
|
+
else Array(use_ssh_config)
|
210
|
+
end
|
211
|
+
|
212
|
+
Net::SSH::Config.for(host, files)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
data/net-ssh.gemspec
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
@spec = Gem::Specification.new do |s|
|
2
|
+
s.name = "net-ssh"
|
3
|
+
s.rubyforge_project = 'net-ssh'
|
4
|
+
s.version = "2.0.15"
|
5
|
+
s.summary = "Net::SSH: a pure-Ruby implementation of the SSH2 client protocol."
|
6
|
+
s.description = s.summary
|
7
|
+
s.authors = ["Jamis Buck", "Delano Mandelbaum"]
|
8
|
+
s.email = ["net-ssh@solutious.com", "net-ssh@solutious.com"]
|
9
|
+
s.homepage = "http://rubyforge.org/projects/net-ssh/"
|
10
|
+
|
11
|
+
s.extra_rdoc_files = %w[README.rdoc THANKS.rdoc CHANGELOG.rdoc]
|
12
|
+
s.has_rdoc = true
|
13
|
+
s.rdoc_options = ["--line-numbers", "--title", s.summary, "--main", "README.rdoc"]
|
14
|
+
s.require_paths = %w[lib]
|
15
|
+
s.rubygems_version = '1.3.2'
|
16
|
+
|
17
|
+
s.executables = %w[]
|
18
|
+
|
19
|
+
# = MANIFEST =
|
20
|
+
s.files = %w(
|
21
|
+
CHANGELOG.rdoc
|
22
|
+
Manifest
|
23
|
+
README.rdoc
|
24
|
+
Rakefile
|
25
|
+
Rudyfile
|
26
|
+
THANKS.rdoc
|
27
|
+
lib/net/ssh.rb
|
28
|
+
lib/net/ssh/authentication/agent.rb
|
29
|
+
lib/net/ssh/authentication/constants.rb
|
30
|
+
lib/net/ssh/authentication/key_manager.rb
|
31
|
+
lib/net/ssh/authentication/methods/abstract.rb
|
32
|
+
lib/net/ssh/authentication/methods/hostbased.rb
|
33
|
+
lib/net/ssh/authentication/methods/keyboard_interactive.rb
|
34
|
+
lib/net/ssh/authentication/methods/password.rb
|
35
|
+
lib/net/ssh/authentication/methods/publickey.rb
|
36
|
+
lib/net/ssh/authentication/pageant.rb
|
37
|
+
lib/net/ssh/authentication/session.rb
|
38
|
+
lib/net/ssh/buffer.rb
|
39
|
+
lib/net/ssh/buffered_io.rb
|
40
|
+
lib/net/ssh/config.rb
|
41
|
+
lib/net/ssh/connection/channel.rb
|
42
|
+
lib/net/ssh/connection/constants.rb
|
43
|
+
lib/net/ssh/connection/session.rb
|
44
|
+
lib/net/ssh/connection/term.rb
|
45
|
+
lib/net/ssh/errors.rb
|
46
|
+
lib/net/ssh/key_factory.rb
|
47
|
+
lib/net/ssh/known_hosts.rb
|
48
|
+
lib/net/ssh/loggable.rb
|
49
|
+
lib/net/ssh/packet.rb
|
50
|
+
lib/net/ssh/prompt.rb
|
51
|
+
lib/net/ssh/proxy/errors.rb
|
52
|
+
lib/net/ssh/proxy/http.rb
|
53
|
+
lib/net/ssh/proxy/socks4.rb
|
54
|
+
lib/net/ssh/proxy/socks5.rb
|
55
|
+
lib/net/ssh/ruby_compat.rb
|
56
|
+
lib/net/ssh/service/forward.rb
|
57
|
+
lib/net/ssh/test.rb
|
58
|
+
lib/net/ssh/test/channel.rb
|
59
|
+
lib/net/ssh/test/extensions.rb
|
60
|
+
lib/net/ssh/test/kex.rb
|
61
|
+
lib/net/ssh/test/local_packet.rb
|
62
|
+
lib/net/ssh/test/packet.rb
|
63
|
+
lib/net/ssh/test/remote_packet.rb
|
64
|
+
lib/net/ssh/test/script.rb
|
65
|
+
lib/net/ssh/test/socket.rb
|
66
|
+
lib/net/ssh/transport/algorithms.rb
|
67
|
+
lib/net/ssh/transport/cipher_factory.rb
|
68
|
+
lib/net/ssh/transport/constants.rb
|
69
|
+
lib/net/ssh/transport/hmac.rb
|
70
|
+
lib/net/ssh/transport/hmac/abstract.rb
|
71
|
+
lib/net/ssh/transport/hmac/md5.rb
|
72
|
+
lib/net/ssh/transport/hmac/md5_96.rb
|
73
|
+
lib/net/ssh/transport/hmac/none.rb
|
74
|
+
lib/net/ssh/transport/hmac/sha1.rb
|
75
|
+
lib/net/ssh/transport/hmac/sha1_96.rb
|
76
|
+
lib/net/ssh/transport/identity_cipher.rb
|
77
|
+
lib/net/ssh/transport/kex.rb
|
78
|
+
lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb
|
79
|
+
lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb
|
80
|
+
lib/net/ssh/transport/openssl.rb
|
81
|
+
lib/net/ssh/transport/packet_stream.rb
|
82
|
+
lib/net/ssh/transport/server_version.rb
|
83
|
+
lib/net/ssh/transport/session.rb
|
84
|
+
lib/net/ssh/transport/state.rb
|
85
|
+
lib/net/ssh/verifiers/lenient.rb
|
86
|
+
lib/net/ssh/verifiers/null.rb
|
87
|
+
lib/net/ssh/verifiers/strict.rb
|
88
|
+
lib/net/ssh/version.rb
|
89
|
+
net-ssh.gemspec
|
90
|
+
setup.rb
|
91
|
+
support/arcfour_check.rb
|
92
|
+
test/authentication/methods/common.rb
|
93
|
+
test/authentication/methods/test_abstract.rb
|
94
|
+
test/authentication/methods/test_hostbased.rb
|
95
|
+
test/authentication/methods/test_keyboard_interactive.rb
|
96
|
+
test/authentication/methods/test_password.rb
|
97
|
+
test/authentication/methods/test_publickey.rb
|
98
|
+
test/authentication/test_agent.rb
|
99
|
+
test/authentication/test_key_manager.rb
|
100
|
+
test/authentication/test_session.rb
|
101
|
+
test/common.rb
|
102
|
+
test/configs/eqsign
|
103
|
+
test/configs/exact_match
|
104
|
+
test/configs/multihost
|
105
|
+
test/configs/wild_cards
|
106
|
+
test/connection/test_channel.rb
|
107
|
+
test/connection/test_session.rb
|
108
|
+
test/test_all.rb
|
109
|
+
test/test_buffer.rb
|
110
|
+
test/test_buffered_io.rb
|
111
|
+
test/test_config.rb
|
112
|
+
test/test_key_factory.rb
|
113
|
+
test/transport/hmac/test_md5.rb
|
114
|
+
test/transport/hmac/test_md5_96.rb
|
115
|
+
test/transport/hmac/test_none.rb
|
116
|
+
test/transport/hmac/test_sha1.rb
|
117
|
+
test/transport/hmac/test_sha1_96.rb
|
118
|
+
test/transport/kex/test_diffie_hellman_group1_sha1.rb
|
119
|
+
test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb
|
120
|
+
test/transport/test_algorithms.rb
|
121
|
+
test/transport/test_cipher_factory.rb
|
122
|
+
test/transport/test_hmac.rb
|
123
|
+
test/transport/test_identity_cipher.rb
|
124
|
+
test/transport/test_packet_stream.rb
|
125
|
+
test/transport/test_server_version.rb
|
126
|
+
test/transport/test_session.rb
|
127
|
+
test/transport/test_state.rb
|
128
|
+
)
|
129
|
+
|
130
|
+
|
131
|
+
end
|