net-ssh 6.3.0.beta1 → 7.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.dockerignore +6 -0
- data/.github/config/rubocop_linter_action.yml +4 -0
- data/.github/workflows/ci-with-docker.yml +44 -0
- data/.github/workflows/ci.yml +4 -10
- data/.github/workflows/rubocop.yml +13 -0
- data/.rubocop.yml +2 -1
- data/.rubocop_todo.yml +244 -237
- data/Dockerfile +27 -0
- data/Dockerfile.openssl3 +17 -0
- data/README.md +7 -1
- data/Rakefile +4 -0
- data/docker-compose.yml +23 -0
- data/lib/net/ssh/authentication/agent.rb +13 -13
- data/lib/net/ssh/authentication/certificate.rb +4 -4
- data/lib/net/ssh/authentication/ed25519.rb +5 -5
- data/lib/net/ssh/authentication/key_manager.rb +18 -5
- data/lib/net/ssh/authentication/methods/abstract.rb +12 -2
- data/lib/net/ssh/authentication/methods/hostbased.rb +3 -3
- data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +1 -1
- data/lib/net/ssh/authentication/methods/none.rb +1 -1
- data/lib/net/ssh/authentication/methods/password.rb +1 -1
- data/lib/net/ssh/authentication/methods/publickey.rb +56 -14
- data/lib/net/ssh/authentication/pageant.rb +8 -8
- data/lib/net/ssh/authentication/pub_key_fingerprint.rb +2 -2
- data/lib/net/ssh/authentication/session.rb +5 -3
- data/lib/net/ssh/buffer.rb +41 -26
- data/lib/net/ssh/buffered_io.rb +6 -6
- data/lib/net/ssh/config.rb +4 -4
- data/lib/net/ssh/connection/channel.rb +13 -14
- data/lib/net/ssh/connection/event_loop.rb +8 -8
- data/lib/net/ssh/connection/session.rb +13 -13
- data/lib/net/ssh/errors.rb +2 -2
- data/lib/net/ssh/key_factory.rb +7 -7
- data/lib/net/ssh/known_hosts.rb +5 -4
- data/lib/net/ssh/prompt.rb +1 -1
- data/lib/net/ssh/proxy/http.rb +1 -1
- data/lib/net/ssh/proxy/https.rb +2 -2
- data/lib/net/ssh/proxy/socks4.rb +1 -1
- data/lib/net/ssh/proxy/socks5.rb +1 -1
- data/lib/net/ssh/service/forward.rb +4 -4
- data/lib/net/ssh/test/channel.rb +3 -3
- data/lib/net/ssh/test/extensions.rb +6 -6
- data/lib/net/ssh/test/packet.rb +1 -1
- data/lib/net/ssh/test/script.rb +3 -3
- data/lib/net/ssh/test/socket.rb +1 -1
- data/lib/net/ssh/test.rb +3 -3
- data/lib/net/ssh/transport/algorithms.rb +12 -12
- data/lib/net/ssh/transport/cipher_factory.rb +15 -15
- data/lib/net/ssh/transport/ctr.rb +3 -3
- data/lib/net/ssh/transport/hmac/abstract.rb +4 -4
- data/lib/net/ssh/transport/hmac.rb +12 -12
- data/lib/net/ssh/transport/identity_cipher.rb +1 -1
- data/lib/net/ssh/transport/kex/abstract.rb +3 -3
- data/lib/net/ssh/transport/kex/abstract5656.rb +1 -1
- data/lib/net/ssh/transport/kex/curve25519_sha256.rb +1 -1
- data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +21 -21
- data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +1 -1
- data/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb +2 -2
- data/lib/net/ssh/transport/kex.rb +7 -7
- data/lib/net/ssh/transport/key_expander.rb +1 -1
- data/lib/net/ssh/transport/openssl.rb +32 -11
- data/lib/net/ssh/transport/packet_stream.rb +1 -1
- data/lib/net/ssh/transport/session.rb +6 -6
- data/lib/net/ssh/transport/state.rb +1 -1
- data/lib/net/ssh/version.rb +4 -4
- data/lib/net/ssh.rb +3 -3
- data/net-ssh.gemspec +2 -2
- data.tar.gz.sig +0 -0
- metadata +15 -9
- metadata.gz.sig +0 -0
- data/.travis.yml +0 -51
data/lib/net/ssh/buffer.rb
CHANGED
@@ -70,7 +70,7 @@ module Net
|
|
70
70
|
|
71
71
|
# Creates a new buffer, initialized to the given content. The position
|
72
72
|
# is initialized to the beginning of the buffer.
|
73
|
-
def initialize(content=String.new)
|
73
|
+
def initialize(content = String.new)
|
74
74
|
@content = content.to_s
|
75
75
|
@position = 0
|
76
76
|
end
|
@@ -128,7 +128,7 @@ module Net
|
|
128
128
|
# would otherwise tend to grow without bound.
|
129
129
|
#
|
130
130
|
# Returns the buffer object itself.
|
131
|
-
def consume!(n=position)
|
131
|
+
def consume!(n = position)
|
132
132
|
if n >= length
|
133
133
|
# optimize for a fairly common case
|
134
134
|
clear!
|
@@ -171,7 +171,7 @@ module Net
|
|
171
171
|
# Reads and returns the next +count+ bytes from the buffer, starting from
|
172
172
|
# the read position. If +count+ is +nil+, this will return all remaining
|
173
173
|
# text in the buffer. This method will increment the pointer.
|
174
|
-
def read(count=nil)
|
174
|
+
def read(count = nil)
|
175
175
|
count ||= length
|
176
176
|
count = length - @position if @position + count > length
|
177
177
|
@position += count
|
@@ -180,7 +180,7 @@ module Net
|
|
180
180
|
|
181
181
|
# Reads (as #read) and returns the given number of bytes from the buffer,
|
182
182
|
# and then consumes (as #consume!) all data up to the new read position.
|
183
|
-
def read!(count=nil)
|
183
|
+
def read!(count = nil)
|
184
184
|
data = read(count)
|
185
185
|
consume!
|
186
186
|
data
|
@@ -283,6 +283,8 @@ module Net
|
|
283
283
|
key.iqmp = iqmp
|
284
284
|
end
|
285
285
|
key
|
286
|
+
when /^ecdsa\-sha2\-(\w*)$/
|
287
|
+
OpenSSL::PKey::EC.read_keyblob($1, self)
|
286
288
|
else
|
287
289
|
raise Exception, "Cannot decode private key of type #{type}"
|
288
290
|
end
|
@@ -295,29 +297,42 @@ module Net
|
|
295
297
|
when /^(.*)-cert-v01@openssh\.com$/
|
296
298
|
key = Net::SSH::Authentication::Certificate.read_certblob(self, $1)
|
297
299
|
when /^ssh-dss$/
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
300
|
+
p = read_bignum
|
301
|
+
q = read_bignum
|
302
|
+
g = read_bignum
|
303
|
+
pub_key = read_bignum
|
304
|
+
|
305
|
+
asn1 = OpenSSL::ASN1::Sequence.new(
|
306
|
+
[
|
307
|
+
OpenSSL::ASN1::Sequence.new(
|
308
|
+
[
|
309
|
+
OpenSSL::ASN1::ObjectId.new('DSA'),
|
310
|
+
OpenSSL::ASN1::Sequence.new(
|
311
|
+
[
|
312
|
+
OpenSSL::ASN1::Integer.new(p),
|
313
|
+
OpenSSL::ASN1::Integer.new(q),
|
314
|
+
OpenSSL::ASN1::Integer.new(g)
|
315
|
+
]
|
316
|
+
)
|
317
|
+
]
|
318
|
+
),
|
319
|
+
OpenSSL::ASN1::BitString.new(OpenSSL::ASN1::Integer.new(pub_key).to_der)
|
320
|
+
]
|
321
|
+
)
|
322
|
+
|
323
|
+
key = OpenSSL::PKey::DSA.new(asn1.to_der)
|
311
324
|
when /^ssh-rsa$/
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
325
|
+
e = read_bignum
|
326
|
+
n = read_bignum
|
327
|
+
|
328
|
+
asn1 = OpenSSL::ASN1::Sequence(
|
329
|
+
[
|
330
|
+
OpenSSL::ASN1::Integer(n),
|
331
|
+
OpenSSL::ASN1::Integer(e)
|
332
|
+
]
|
333
|
+
)
|
334
|
+
|
335
|
+
key = OpenSSL::PKey::RSA.new(asn1.to_der)
|
321
336
|
when /^ssh-ed25519$/
|
322
337
|
Net::SSH::Authentication::ED25519Loader.raiseUnlessLoaded("unsupported key type `#{type}'")
|
323
338
|
key = Net::SSH::Authentication::ED25519::PubKey.read_keyblob(self)
|
data/lib/net/ssh/buffered_io.rb
CHANGED
@@ -51,7 +51,7 @@ module Net
|
|
51
51
|
# Called when the #extend is called on an object, with this module as the
|
52
52
|
# argument. It ensures that the modules instance variables are all properly
|
53
53
|
# initialized.
|
54
|
-
def self.extended(object)
|
54
|
+
def self.extended(object) # :nodoc:
|
55
55
|
# need to use __send__ because #send is overridden in Socket
|
56
56
|
object.__send__(:initialize_buffered_io)
|
57
57
|
end
|
@@ -59,7 +59,7 @@ module Net
|
|
59
59
|
# Tries to read up to +n+ bytes of data from the remote end, and appends
|
60
60
|
# the data to the input buffer. It returns the number of bytes read, or 0
|
61
61
|
# if no data was available to be read.
|
62
|
-
def fill(n=8192)
|
62
|
+
def fill(n = 8192)
|
63
63
|
input.consume!
|
64
64
|
data = recv(n)
|
65
65
|
debug { "read #{data.length} bytes" }
|
@@ -72,7 +72,7 @@ module Net
|
|
72
72
|
|
73
73
|
# Read up to +length+ bytes from the input buffer. If +length+ is nil,
|
74
74
|
# all available data is read from the buffer. (See #available.)
|
75
|
-
def read_available(length=nil)
|
75
|
+
def read_available(length = nil)
|
76
76
|
input.read(length || available)
|
77
77
|
end
|
78
78
|
|
@@ -121,11 +121,11 @@ module Net
|
|
121
121
|
|
122
122
|
public # these methods are primarily for use in tests
|
123
123
|
|
124
|
-
def write_buffer
|
124
|
+
def write_buffer # :nodoc:
|
125
125
|
output.to_s
|
126
126
|
end
|
127
127
|
|
128
|
-
def read_buffer
|
128
|
+
def read_buffer # :nodoc:
|
129
129
|
input.to_s
|
130
130
|
end
|
131
131
|
|
@@ -166,7 +166,7 @@ module Net
|
|
166
166
|
# http://github.com/net-ssh/net-ssh/tree/portfwfix
|
167
167
|
#
|
168
168
|
module ForwardedBufferedIo
|
169
|
-
def fill(n=8192)
|
169
|
+
def fill(n = 8192)
|
170
170
|
begin
|
171
171
|
super(n)
|
172
172
|
rescue Errno::ECONNRESET => e
|
data/lib/net/ssh/config.rb
CHANGED
@@ -65,7 +65,7 @@ module Net
|
|
65
65
|
# given +files+ (defaulting to the list of files returned by
|
66
66
|
# #default_files), translates the resulting hash into the options
|
67
67
|
# recognized by Net::SSH, and returns them.
|
68
|
-
def for(host, files=expandable_default_files)
|
68
|
+
def for(host, files = expandable_default_files)
|
69
69
|
translate(files.inject({}) { |settings, file|
|
70
70
|
load(file, host, settings)
|
71
71
|
})
|
@@ -77,7 +77,7 @@ module Net
|
|
77
77
|
# ones. Returns a hash containing the OpenSSH options. (See
|
78
78
|
# #translate for how to convert the OpenSSH options into Net::SSH
|
79
79
|
# options.)
|
80
|
-
def load(path, host, settings={}, base_dir = nil)
|
80
|
+
def load(path, host, settings = {}, base_dir = nil)
|
81
81
|
file = File.expand_path(path)
|
82
82
|
base_dir ||= File.dirname(file)
|
83
83
|
return settings unless File.readable?(file)
|
@@ -317,7 +317,7 @@ module Net
|
|
317
317
|
tail = pattern
|
318
318
|
prefix = String.new
|
319
319
|
while !tail.empty? do
|
320
|
-
head,sep,tail = tail.partition(/[\*\?]/)
|
320
|
+
head, sep, tail = tail.partition(/[\*\?]/)
|
321
321
|
prefix = prefix + Regexp.quote(head)
|
322
322
|
case sep
|
323
323
|
when '*'
|
@@ -371,7 +371,7 @@ module Net
|
|
371
371
|
|
372
372
|
conditions = conditions.each_slice(2)
|
373
373
|
condition_matches = []
|
374
|
-
conditions.each do |(kind,exprs)|
|
374
|
+
conditions.each do |(kind, exprs)|
|
375
375
|
exprs = unquote(exprs)
|
376
376
|
|
377
377
|
case kind.downcase
|
@@ -96,12 +96,12 @@ module Net
|
|
96
96
|
# The output buffer for this channel. Data written to the channel is
|
97
97
|
# enqueued here, to be written as CHANNEL_DATA packets during each pass of
|
98
98
|
# the event loop. See Connection::Session#process and #enqueue_pending_output.
|
99
|
-
attr_reader :output
|
99
|
+
attr_reader :output # :nodoc:
|
100
100
|
|
101
101
|
# The list of pending requests. Each time a request is sent which requires
|
102
102
|
# a reply, the corresponding callback is pushed onto this queue. As responses
|
103
103
|
# arrive, they are shifted off the front and handled.
|
104
|
-
attr_reader :pending_requests
|
104
|
+
attr_reader :pending_requests # :nodoc:
|
105
105
|
|
106
106
|
# Instantiates a new channel on the given connection, of the given type,
|
107
107
|
# and with the given id. If a block is given, it will be remembered until
|
@@ -217,7 +217,7 @@ module Net
|
|
217
217
|
# puts "could not obtain pty"
|
218
218
|
# end
|
219
219
|
# end
|
220
|
-
def request_pty(opts={}, &block)
|
220
|
+
def request_pty(opts = {}, &block)
|
221
221
|
extra = opts.keys - VALID_PTY_OPTIONS.keys
|
222
222
|
raise ArgumentError, "invalid option(s) to request_pty: #{extra.inspect}" if extra.any?
|
223
223
|
|
@@ -230,9 +230,9 @@ module Net
|
|
230
230
|
modes.write_byte(0)
|
231
231
|
|
232
232
|
send_channel_request("pty-req", :string, opts[:term],
|
233
|
-
|
234
|
-
|
235
|
-
|
233
|
+
:long, opts[:chars_wide], :long, opts[:chars_high],
|
234
|
+
:long, opts[:pixels_wide], :long, opts[:pixels_high],
|
235
|
+
:string, modes.to_s, &block)
|
236
236
|
end
|
237
237
|
|
238
238
|
# Sends data to the channel's remote endpoint. This usually has the
|
@@ -490,8 +490,8 @@ module Net
|
|
490
490
|
fail "Channel open not yet confirmed, please call send_channel_request(or exec) from block of open_channel" unless remote_id
|
491
491
|
|
492
492
|
msg = Buffer.from(:byte, CHANNEL_REQUEST,
|
493
|
-
|
494
|
-
|
493
|
+
:long, remote_id, :string, request_name,
|
494
|
+
:bool, !callback.nil?, *data)
|
495
495
|
connection.send_message(msg)
|
496
496
|
pending_requests << callback if callback
|
497
497
|
end
|
@@ -503,7 +503,7 @@ module Net
|
|
503
503
|
# #do_open_confirmation). This is called automatically by #process, which
|
504
504
|
# is called from the event loop (Connection::Session#process). You will
|
505
505
|
# generally not need to invoke it directly.
|
506
|
-
def enqueue_pending_output
|
506
|
+
def enqueue_pending_output # :nodoc:
|
507
507
|
return unless remote_id
|
508
508
|
|
509
509
|
while output.length > 0
|
@@ -527,7 +527,7 @@ module Net
|
|
527
527
|
# packet sizes, respectively. If an open-confirmation callback was
|
528
528
|
# given when the channel was created, it is invoked at this time with
|
529
529
|
# the channel itself as the sole argument.
|
530
|
-
def do_open_confirmation(remote_id, max_window, max_packet)
|
530
|
+
def do_open_confirmation(remote_id, max_window, max_packet) # :nodoc:
|
531
531
|
@remote_id = remote_id
|
532
532
|
@remote_window_size = @remote_maximum_window_size = max_window
|
533
533
|
@remote_maximum_packet_size = max_packet
|
@@ -553,7 +553,7 @@ module Net
|
|
553
553
|
# causes the remote window size to be adjusted upwards by the given
|
554
554
|
# number of bytes. This has the effect of allowing more data to be sent
|
555
555
|
# from the local end to the remote end of the channel.
|
556
|
-
def do_window_adjust(bytes)
|
556
|
+
def do_window_adjust(bytes) # :nodoc:
|
557
557
|
@remote_maximum_window_size += bytes
|
558
558
|
@remote_window_size += bytes
|
559
559
|
end
|
@@ -566,7 +566,7 @@ module Net
|
|
566
566
|
# CHANNEL_SUCCESS, unless the callback raised ChannelRequestFailed. The
|
567
567
|
# callback should accept the channel as the first argument, and the
|
568
568
|
# request-specific data as the second.
|
569
|
-
def do_request(request, want_reply, data)
|
569
|
+
def do_request(request, want_reply, data) # :nodoc:
|
570
570
|
result = true
|
571
571
|
|
572
572
|
begin
|
@@ -587,7 +587,7 @@ module Net
|
|
587
587
|
# but does not actually throttle requests that come in illegally when
|
588
588
|
# the window size is too small. The callback is invoked with the channel
|
589
589
|
# as the first argument, and the data as the second.
|
590
|
-
def do_data(data)
|
590
|
+
def do_data(data) # :nodoc:
|
591
591
|
update_local_window_size(data.length)
|
592
592
|
@on_data.call(self, data) if @on_data
|
593
593
|
end
|
@@ -686,7 +686,6 @@ module Net
|
|
686
686
|
#
|
687
687
|
# channel.set_remote_env foo: 'bar', baz: 'whale'
|
688
688
|
def set_remote_env(env)
|
689
|
-
env.each { |key, value| puts "E:#{key} V:#{value}" }
|
690
689
|
env.each { |key, value| self.env(key, value) }
|
691
690
|
end
|
692
691
|
end
|
@@ -12,7 +12,7 @@ module Net
|
|
12
12
|
class EventLoop
|
13
13
|
include Loggable
|
14
14
|
|
15
|
-
def initialize(logger=nil)
|
15
|
+
def initialize(logger = nil)
|
16
16
|
self.logger = logger
|
17
17
|
@sessions = []
|
18
18
|
end
|
@@ -60,7 +60,7 @@ module Net
|
|
60
60
|
w = []
|
61
61
|
minwait = nil
|
62
62
|
@sessions.each do |session|
|
63
|
-
sr,sw,actwait = session.ev_do_calculate_rw_wait(wait)
|
63
|
+
sr, sw, actwait = session.ev_do_calculate_rw_wait(wait)
|
64
64
|
minwait = actwait if actwait && (minwait.nil? || actwait < minwait)
|
65
65
|
r.push(*sr)
|
66
66
|
w.push(*sw)
|
@@ -75,18 +75,18 @@ module Net
|
|
75
75
|
if readers
|
76
76
|
readers.each do |reader|
|
77
77
|
session = owners[reader]
|
78
|
-
(fired_sessions[session] ||= { r: [],w: [] })[:r] << reader
|
78
|
+
(fired_sessions[session] ||= { r: [], w: [] })[:r] << reader
|
79
79
|
end
|
80
80
|
end
|
81
81
|
if writers
|
82
82
|
writers.each do |writer|
|
83
83
|
session = owners[writer]
|
84
|
-
(fired_sessions[session] ||= { r: [],w: [] })[:w] << writer
|
84
|
+
(fired_sessions[session] ||= { r: [], w: [] })[:w] << writer
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
fired_sessions.each do |s,rw|
|
89
|
-
s.ev_do_handle_events(rw[:r],rw[:w])
|
88
|
+
fired_sessions.each do |s, rw|
|
89
|
+
s.ev_do_handle_events(rw[:r], rw[:w])
|
90
90
|
end
|
91
91
|
|
92
92
|
@sessions.each { |s| s.ev_do_postprocess(fired_sessions.key?(s)) }
|
@@ -111,10 +111,10 @@ module Net
|
|
111
111
|
raise "Only one session expected" unless @sessions.count == 1
|
112
112
|
|
113
113
|
session = @sessions.first
|
114
|
-
sr,sw,actwait = session.ev_do_calculate_rw_wait(wait)
|
114
|
+
sr, sw, actwait = session.ev_do_calculate_rw_wait(wait)
|
115
115
|
readers, writers, = IO.select(sr, sw, nil, actwait)
|
116
116
|
|
117
|
-
session.ev_do_handle_events(readers,writers)
|
117
|
+
session.ev_do_handle_events(readers, writers)
|
118
118
|
session.ev_do_postprocess(!((readers.nil? || readers.empty?) && (writers.nil? || writers.empty?)))
|
119
119
|
end
|
120
120
|
end
|
@@ -41,17 +41,17 @@ module Net
|
|
41
41
|
attr_reader :properties
|
42
42
|
|
43
43
|
# The map of channels, each key being the local-id for the channel.
|
44
|
-
attr_reader :channels
|
44
|
+
attr_reader :channels # :nodoc:
|
45
45
|
|
46
46
|
# The map of listeners that the event loop knows about. See #listen_to.
|
47
|
-
attr_reader :listeners
|
47
|
+
attr_reader :listeners # :nodoc:
|
48
48
|
|
49
49
|
# The map of specialized handlers for opening specific channel types. See
|
50
50
|
# #on_open_channel.
|
51
|
-
attr_reader :channel_open_handlers
|
51
|
+
attr_reader :channel_open_handlers # :nodoc:
|
52
52
|
|
53
53
|
# The list of callbacks for pending requests. See #send_global_request.
|
54
|
-
attr_reader :pending_requests
|
54
|
+
attr_reader :pending_requests # :nodoc:
|
55
55
|
|
56
56
|
class NilChannel
|
57
57
|
def initialize(session)
|
@@ -65,7 +65,7 @@ module Net
|
|
65
65
|
|
66
66
|
# Create a new connection service instance atop the given transport
|
67
67
|
# layer. Initializes the listeners to be only the underlying socket object.
|
68
|
-
def initialize(transport, options={})
|
68
|
+
def initialize(transport, options = {})
|
69
69
|
self.logger = transport.logger
|
70
70
|
|
71
71
|
@transport = transport
|
@@ -149,7 +149,7 @@ module Net
|
|
149
149
|
# to be run.
|
150
150
|
#
|
151
151
|
# ssh.loop { ssh.busy? }
|
152
|
-
def busy?(include_invisible=false)
|
152
|
+
def busy?(include_invisible = false)
|
153
153
|
if include_invisible
|
154
154
|
channels.any?
|
155
155
|
else
|
@@ -174,7 +174,7 @@ module Net
|
|
174
174
|
# int_pressed = false
|
175
175
|
# trap("INT") { int_pressed = true }
|
176
176
|
# ssh.loop(0.1) { not int_pressed }
|
177
|
-
def loop(wait=nil, &block)
|
177
|
+
def loop(wait = nil, &block)
|
178
178
|
running = block || Proc.new { busy? }
|
179
179
|
loop_forever { break unless process(wait, &running) }
|
180
180
|
begin
|
@@ -222,7 +222,7 @@ module Net
|
|
222
222
|
# connections.delete_if { |ssh| !ssh.process(0.1, &condition) }
|
223
223
|
# break if connections.empty?
|
224
224
|
# end
|
225
|
-
def process(wait=nil, &block)
|
225
|
+
def process(wait = nil, &block)
|
226
226
|
@event_loop.process(wait, &block)
|
227
227
|
rescue StandardError
|
228
228
|
force_channel_cleanup_on_close if closed?
|
@@ -255,7 +255,7 @@ module Net
|
|
255
255
|
def ev_do_calculate_rw_wait(wait)
|
256
256
|
r = listeners.keys
|
257
257
|
w = r.select { |w2| w2.respond_to?(:pending_write?) && w2.pending_write? }
|
258
|
-
[r,w,io_select_wait(wait)]
|
258
|
+
[r, w, io_select_wait(wait)]
|
259
259
|
end
|
260
260
|
|
261
261
|
# This is called internally as part of #process.
|
@@ -335,13 +335,13 @@ module Net
|
|
335
335
|
# end
|
336
336
|
#
|
337
337
|
# channel.wait
|
338
|
-
def open_channel(type="session", *extra, &on_confirm)
|
338
|
+
def open_channel(type = "session", *extra, &on_confirm)
|
339
339
|
local_id = get_next_channel_id
|
340
340
|
|
341
341
|
channel = Channel.new(self, type, local_id, @max_pkt_size, @max_win_size, &on_confirm)
|
342
342
|
msg = Buffer.from(:byte, CHANNEL_OPEN, :string, type, :long, local_id,
|
343
|
-
|
344
|
-
|
343
|
+
:long, channel.local_maximum_window_size,
|
344
|
+
:long, channel.local_maximum_packet_size, *extra)
|
345
345
|
send_message(msg)
|
346
346
|
|
347
347
|
channels[local_id] = channel
|
@@ -382,7 +382,7 @@ module Net
|
|
382
382
|
raise "could not execute command: #{command.inspect}" unless success
|
383
383
|
|
384
384
|
if status
|
385
|
-
channel.on_request("exit-status") do |ch2,data|
|
385
|
+
channel.on_request("exit-status") do |ch2, data|
|
386
386
|
status[:exit_code] = data.read_long
|
387
387
|
end
|
388
388
|
|
data/lib/net/ssh/errors.rb
CHANGED
@@ -45,10 +45,10 @@ module Net
|
|
45
45
|
# the remember_host! method on the exception, and then retry.
|
46
46
|
class HostKeyError < Net::SSH::Exception
|
47
47
|
# the callback to use when #remember_host! is called
|
48
|
-
attr_writer :callback
|
48
|
+
attr_writer :callback # :nodoc:
|
49
49
|
|
50
50
|
# situation-specific data describing the host (see #host, #port, etc.)
|
51
|
-
attr_writer :data
|
51
|
+
attr_writer :data # :nodoc:
|
52
52
|
|
53
53
|
# An accessor for getting at the data that was used to look up the host
|
54
54
|
# (see also #fingerprint, #host, #port, #ip, and #key).
|
data/lib/net/ssh/key_factory.rb
CHANGED
@@ -17,14 +17,14 @@ module Net
|
|
17
17
|
class KeyFactory
|
18
18
|
# Specifies the mapping of SSH names to OpenSSL key classes.
|
19
19
|
MAP = {
|
20
|
-
'dh'
|
21
|
-
'rsa'
|
22
|
-
'dsa'
|
20
|
+
'dh' => OpenSSL::PKey::DH,
|
21
|
+
'rsa' => OpenSSL::PKey::RSA,
|
22
|
+
'dsa' => OpenSSL::PKey::DSA,
|
23
23
|
'ecdsa' => OpenSSL::PKey::EC
|
24
24
|
}
|
25
25
|
MAP["ed25519"] = Net::SSH::Authentication::ED25519::PrivKey if defined? Net::SSH::Authentication::ED25519
|
26
26
|
|
27
|
-
class <<self
|
27
|
+
class << self
|
28
28
|
# Fetch an OpenSSL key instance by its SSH name. It will be a new,
|
29
29
|
# empty key of the given type.
|
30
30
|
def get(name)
|
@@ -36,7 +36,7 @@ module Net
|
|
36
36
|
# appropriately. The new key is returned. If the key itself is
|
37
37
|
# encrypted (requiring a passphrase to use), the user will be
|
38
38
|
# prompted to enter their password unless passphrase works.
|
39
|
-
def load_private_key(filename, passphrase=nil, ask_passphrase=true, prompt=Prompt.default)
|
39
|
+
def load_private_key(filename, passphrase = nil, ask_passphrase = true, prompt = Prompt.default)
|
40
40
|
data = File.read(File.expand_path(filename))
|
41
41
|
load_data_private_key(data, passphrase, ask_passphrase, filename, prompt)
|
42
42
|
end
|
@@ -46,7 +46,7 @@ module Net
|
|
46
46
|
# appropriately. The new key is returned. If the key itself is
|
47
47
|
# encrypted (requiring a passphrase to use), the user will be
|
48
48
|
# prompted to enter their password unless passphrase works.
|
49
|
-
def load_data_private_key(data, passphrase=nil, ask_passphrase=true, filename="", prompt=Prompt.default)
|
49
|
+
def load_data_private_key(data, passphrase = nil, ask_passphrase = true, filename = "", prompt = Prompt.default)
|
50
50
|
key_type = classify_key(data, filename)
|
51
51
|
|
52
52
|
encrypted_key = nil
|
@@ -86,7 +86,7 @@ module Net
|
|
86
86
|
# Loads a public key. It will correctly determine whether
|
87
87
|
# the file describes an RSA or DSA key, and will load it
|
88
88
|
# appropriately. The new public key is returned.
|
89
|
-
def load_data_public_key(data, filename="")
|
89
|
+
def load_data_public_key(data, filename = "")
|
90
90
|
fields = data.split(/ /)
|
91
91
|
|
92
92
|
blob = nil
|
data/lib/net/ssh/known_hosts.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'strscan'
|
2
2
|
require 'openssl'
|
3
3
|
require 'base64'
|
4
|
+
require 'delegate'
|
4
5
|
require 'net/ssh/buffer'
|
5
6
|
require 'net/ssh/authentication/ed25519_loader'
|
6
7
|
|
@@ -105,10 +106,10 @@ module Net
|
|
105
106
|
|
106
107
|
SUPPORTED_TYPE.push('ssh-ed25519') if Net::SSH::Authentication::ED25519Loader::LOADED
|
107
108
|
|
108
|
-
class <<self
|
109
|
+
class << self
|
109
110
|
# Searches all known host files (see KnownHosts.hostfiles) for all keys
|
110
111
|
# of the given host. Returns an enumerable of keys found.
|
111
|
-
def search_for(host, options={})
|
112
|
+
def search_for(host, options = {})
|
112
113
|
HostKeys.new(search_in(hostfiles(options), host, options), host, self, options)
|
113
114
|
end
|
114
115
|
|
@@ -127,7 +128,7 @@ module Net
|
|
127
128
|
#
|
128
129
|
# If you only want the user known host files, you can pass :user as
|
129
130
|
# the second option.
|
130
|
-
def hostfiles(options, which
|
131
|
+
def hostfiles(options, which = :all)
|
131
132
|
files = []
|
132
133
|
|
133
134
|
files += Array(options[:user_known_hosts_file] || %w[~/.ssh/known_hosts ~/.ssh/known_hosts2]) if which == :all || which == :user
|
@@ -142,7 +143,7 @@ module Net
|
|
142
143
|
# Looks in all user known host files (see KnownHosts.hostfiles) and tries to
|
143
144
|
# add an entry for the given host and key to the first file it is able
|
144
145
|
# to.
|
145
|
-
def add(host, key, options={})
|
146
|
+
def add(host, key, options = {})
|
146
147
|
hostfiles(options, :user).each do |file|
|
147
148
|
KnownHosts.new(file).add(host, key)
|
148
149
|
return
|
data/lib/net/ssh/prompt.rb
CHANGED
@@ -38,7 +38,7 @@ module Net
|
|
38
38
|
|
39
39
|
# ask input from user, a prompter might ask for multiple inputs
|
40
40
|
# (like user and password) in a single session.
|
41
|
-
def ask(prompt, echo=true)
|
41
|
+
def ask(prompt, echo = true)
|
42
42
|
$stdout.print(prompt)
|
43
43
|
$stdout.flush
|
44
44
|
ret = $stdin.noecho(&:gets).chomp
|
data/lib/net/ssh/proxy/http.rb
CHANGED
@@ -40,7 +40,7 @@ module Net
|
|
40
40
|
#
|
41
41
|
# * :user => the user name to use when authenticating to the proxy
|
42
42
|
# * :password => the password to use when authenticating
|
43
|
-
def initialize(proxy_host, proxy_port=80, options={})
|
43
|
+
def initialize(proxy_host, proxy_port = 80, options = {})
|
44
44
|
@proxy_host = proxy_host
|
45
45
|
@proxy_port = proxy_port
|
46
46
|
@options = options
|
data/lib/net/ssh/proxy/https.rb
CHANGED
@@ -16,7 +16,7 @@ module Net
|
|
16
16
|
# taken by Net::SSH::Proxy::HTTP it supports:
|
17
17
|
#
|
18
18
|
# * :ssl_context => the SSL configuration to use for the connection
|
19
|
-
def initialize(proxy_host, proxy_port=80, options={})
|
19
|
+
def initialize(proxy_host, proxy_port = 80, options = {})
|
20
20
|
@ssl_context = options.delete(:ssl_context) ||
|
21
21
|
OpenSSL::SSL::SSLContext.new
|
22
22
|
super(proxy_host, proxy_port, options)
|
@@ -27,7 +27,7 @@ module Net
|
|
27
27
|
# Shim to make OpenSSL::SSL::SSLSocket behave like a regular TCPSocket
|
28
28
|
# for all intents and purposes of Net::SSH::BufferedIo
|
29
29
|
module SSLSocketCompatibility
|
30
|
-
def self.extended(object)
|
30
|
+
def self.extended(object) # :nodoc:
|
31
31
|
object.define_singleton_method(:recv, object.method(:sysread))
|
32
32
|
object.sync_close = true
|
33
33
|
end
|
data/lib/net/ssh/proxy/socks4.rb
CHANGED
@@ -37,7 +37,7 @@ module Net
|
|
37
37
|
# Create a new proxy connection to the given proxy host and port.
|
38
38
|
# Optionally, a :user key may be given to identify the username
|
39
39
|
# with which to authenticate.
|
40
|
-
def initialize(proxy_host, proxy_port=1080, options={})
|
40
|
+
def initialize(proxy_host, proxy_port = 1080, options = {})
|
41
41
|
@proxy_host = proxy_host
|
42
42
|
@proxy_port = proxy_port
|
43
43
|
@options = options
|
data/lib/net/ssh/proxy/socks5.rb
CHANGED
@@ -52,7 +52,7 @@ module Net
|
|
52
52
|
# Create a new proxy connection to the given proxy host and port.
|
53
53
|
# Optionally, :user and :password options may be given to
|
54
54
|
# identify the username and password with which to authenticate.
|
55
|
-
def initialize(proxy_host, proxy_port=1080, options={})
|
55
|
+
def initialize(proxy_host, proxy_port = 1080, options = {})
|
56
56
|
@proxy_host = proxy_host
|
57
57
|
@proxy_port = proxy_port
|
58
58
|
@options = options
|
@@ -17,7 +17,7 @@ module Net
|
|
17
17
|
attr_reader :session
|
18
18
|
|
19
19
|
# A simple class for representing a requested remote forwarded port.
|
20
|
-
Remote = Struct.new(:host, :port)
|
20
|
+
Remote = Struct.new(:host, :port) # :nodoc:
|
21
21
|
|
22
22
|
# Instantiates a new Forward service instance atop the given connection
|
23
23
|
# service session. This will register new channel open handlers to handle
|
@@ -105,7 +105,7 @@ module Net
|
|
105
105
|
#
|
106
106
|
# ssh.forward.cancel_local(1234)
|
107
107
|
# ssh.forward.cancel_local(1234, "0.0.0.0")
|
108
|
-
def cancel_local(port, bind_address="127.0.0.1")
|
108
|
+
def cancel_local(port, bind_address = "127.0.0.1")
|
109
109
|
socket = @local_forwarded_ports.delete([port, bind_address])
|
110
110
|
socket.shutdown rescue nil
|
111
111
|
socket.close rescue nil
|
@@ -214,7 +214,7 @@ module Net
|
|
214
214
|
# raise Net::SSH::Exception, "remote forwarding request failed"
|
215
215
|
# end
|
216
216
|
#
|
217
|
-
def remote(port, host, remote_port, remote_host="127.0.0.1")
|
217
|
+
def remote(port, host, remote_port, remote_host = "127.0.0.1")
|
218
218
|
session.send_global_request("tcpip-forward", :string, remote_host, :long, remote_port) do |success, response|
|
219
219
|
if success
|
220
220
|
remote_port = response.read_long if remote_port == 0
|
@@ -248,7 +248,7 @@ module Net
|
|
248
248
|
#
|
249
249
|
# ssh.forward.cancel_remote(1234, "0.0.0.0")
|
250
250
|
# ssh.loop { ssh.forward.active_remotes.include?([1234, "0.0.0.0"]) }
|
251
|
-
def cancel_remote(port, host="127.0.0.1")
|
251
|
+
def cancel_remote(port, host = "127.0.0.1")
|
252
252
|
session.send_global_request("cancel-tcpip-forward", :string, host, :long, port) do |success, response|
|
253
253
|
if success
|
254
254
|
@remote_forwarded_ports.delete([port, host])
|
data/lib/net/ssh/test/channel.rb
CHANGED
@@ -65,7 +65,7 @@ module Net
|
|
65
65
|
# be scripted.
|
66
66
|
#
|
67
67
|
# channel.sends_exec "ls -l"
|
68
|
-
def sends_exec(command, reply=true, success=true)
|
68
|
+
def sends_exec(command, reply = true, success = true)
|
69
69
|
script.sends_channel_request(self, "exec", reply, command, success)
|
70
70
|
end
|
71
71
|
|
@@ -74,7 +74,7 @@ module Net
|
|
74
74
|
# and +success+ arguments.
|
75
75
|
#
|
76
76
|
# channel.sends_subsystem "sftp"
|
77
|
-
def sends_subsystem(subsystem, reply=true, success=true)
|
77
|
+
def sends_subsystem(subsystem, reply = true, success = true)
|
78
78
|
script.sends_channel_request(self, "subsystem", reply, subsystem, success)
|
79
79
|
end
|
80
80
|
|
@@ -124,7 +124,7 @@ module Net
|
|
124
124
|
# Scripts the reception of an "exit-status" channel request packet.
|
125
125
|
#
|
126
126
|
# channel.gets_exit_status(127)
|
127
|
-
def gets_exit_status(status=0)
|
127
|
+
def gets_exit_status(status = 0)
|
128
128
|
script.gets_channel_request(self, "exit-status", false, status)
|
129
129
|
end
|
130
130
|
|