hrr_rb_ssh 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +0 -3
- data/README.md +1 -1
- data/lib/hrr_rb_ssh/authentication.rb +2 -2
- data/lib/hrr_rb_ssh/authentication/method/keyboard_interactive.rb +0 -1
- data/lib/hrr_rb_ssh/authentication/method/none.rb +0 -1
- data/lib/hrr_rb_ssh/authentication/method/password.rb +0 -1
- data/lib/hrr_rb_ssh/client.rb +6 -6
- data/lib/hrr_rb_ssh/connection.rb +5 -5
- data/lib/hrr_rb_ssh/connection/channel.rb +3 -3
- data/lib/hrr_rb_ssh/transport.rb +39 -48
- data/lib/hrr_rb_ssh/transport/receiver.rb +3 -3
- data/lib/hrr_rb_ssh/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 781a7427bc3d26dcddba2be4a74f685d26ecc867fe6a1d937cd19e3b56cd9477
|
4
|
+
data.tar.gz: c1ea1ee12f012d1cf66a23518049a9ce127a1ded1536c735330b6f7e3ad22d7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0c79b9c3d00f49b4e8090ec6cf9aa5e58619d62f4bd46a0d2864c3c29d908a92470f4eda4e9ba1b057f765b98214ddcaa5b44e9cd4de1ecd44639afd89d29bd
|
7
|
+
data.tar.gz: e9c84a3ad17d39972c6950f4da1b92bca351511d5bc220b342ac7d61f7d70631f60c68ecd5ac5d964d76825b5a67027227bb45ac3f2703788c7d7a548359c730
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -584,7 +584,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/hirura
|
|
584
584
|
|
585
585
|
## Code of Conduct
|
586
586
|
|
587
|
-
Everyone interacting in the HrrRbSsh project
|
587
|
+
Everyone interacting in the HrrRbSsh project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hirura/hrr_rb_ssh/blob/master/CODE_OF_CONDUCT.md).
|
588
588
|
|
589
589
|
## License
|
590
590
|
|
@@ -112,7 +112,7 @@ module HrrRbSsh
|
|
112
112
|
when PARTIAL_SUCCESS
|
113
113
|
log_info { "partially verified" }
|
114
114
|
authentication_methods.delete method_name
|
115
|
-
|
115
|
+
log_info { "authentication methods that can continue: #{authentication_methods}" }
|
116
116
|
if authentication_methods.empty?
|
117
117
|
log_info { "verified" }
|
118
118
|
send_userauth_success
|
@@ -159,7 +159,7 @@ module HrrRbSsh
|
|
159
159
|
log_info { "partially verified" }
|
160
160
|
end
|
161
161
|
authentication_methods_that_can_continue = message[:'authentications that can continue']
|
162
|
-
|
162
|
+
log_info { "authentication methods that can continue: #{authentication_methods_that_can_continue}" }
|
163
163
|
next_method_name = authentication_methods.find{ |local_m| authentication_methods_that_can_continue.find{ |remote_m| local_m == remote_m } }
|
164
164
|
if next_method_name
|
165
165
|
authentication_methods.delete next_method_name
|
@@ -23,7 +23,6 @@ module HrrRbSsh
|
|
23
23
|
|
24
24
|
def authenticate userauth_request_message
|
25
25
|
log_info { "authenticate" }
|
26
|
-
log_debug { "userauth request: " + userauth_request_message.inspect }
|
27
26
|
username = userauth_request_message[:'user name']
|
28
27
|
submethods = userauth_request_message[:'submethods']
|
29
28
|
context = Context.new(@transport, username, submethods, @variables, @authentication_methods, logger: logger)
|
@@ -22,7 +22,6 @@ module HrrRbSsh
|
|
22
22
|
|
23
23
|
def authenticate userauth_request_message
|
24
24
|
log_info { "authenticate" }
|
25
|
-
log_debug { "userauth request: " + userauth_request_message.inspect }
|
26
25
|
context = Context.new(userauth_request_message[:'user name'], @variables, @authentication_methods, logger: logger)
|
27
26
|
@authenticator.authenticate context
|
28
27
|
end
|
@@ -23,7 +23,6 @@ module HrrRbSsh
|
|
23
23
|
|
24
24
|
def authenticate userauth_request_message
|
25
25
|
log_info { "authenticate" }
|
26
|
-
log_debug { "userauth request: " + userauth_request_message.inspect }
|
27
26
|
username = userauth_request_message[:'user name']
|
28
27
|
password = userauth_request_message[:'plaintext password']
|
29
28
|
context = Context.new(username, password, @variables, @authentication_methods, logger: logger)
|
data/lib/hrr_rb_ssh/client.rb
CHANGED
@@ -75,14 +75,14 @@ module HrrRbSsh
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def close
|
78
|
-
|
78
|
+
log_info { "closing client" }
|
79
79
|
@closed = true
|
80
80
|
@connection.close
|
81
|
-
|
81
|
+
log_info { "client closed" }
|
82
82
|
end
|
83
83
|
|
84
84
|
def exec! command, pty: false, env: {}
|
85
|
-
|
85
|
+
log_info { "start exec!: #{command}" }
|
86
86
|
out_buf = StringIO.new
|
87
87
|
err_buf = StringIO.new
|
88
88
|
begin
|
@@ -141,7 +141,7 @@ module HrrRbSsh
|
|
141
141
|
end
|
142
142
|
|
143
143
|
def exec command, pty: false, env: {}
|
144
|
-
|
144
|
+
log_info { "start exec: #{command}" }
|
145
145
|
begin
|
146
146
|
log_info { "Opning channel" }
|
147
147
|
channel = @connection.request_channel_open "session"
|
@@ -174,7 +174,7 @@ module HrrRbSsh
|
|
174
174
|
end
|
175
175
|
|
176
176
|
def shell env: {}
|
177
|
-
|
177
|
+
log_info { "start shell" }
|
178
178
|
begin
|
179
179
|
log_info { "Opning channel" }
|
180
180
|
channel = @connection.request_channel_open "session"
|
@@ -205,7 +205,7 @@ module HrrRbSsh
|
|
205
205
|
end
|
206
206
|
|
207
207
|
def subsystem name
|
208
|
-
|
208
|
+
log_info { "start subsystem" }
|
209
209
|
begin
|
210
210
|
log_info { "Opning channel" }
|
211
211
|
channel = @connection.request_channel_open "session"
|
@@ -224,35 +224,35 @@ module HrrRbSsh
|
|
224
224
|
log_info { 'received ' + Message::SSH_MSG_CHANNEL_REQUEST::ID }
|
225
225
|
message = Message::SSH_MSG_CHANNEL_REQUEST.new(logger: logger).decode payload
|
226
226
|
local_channel = message[:'recipient channel']
|
227
|
-
@channels[local_channel].receive_message_queue.enq message
|
227
|
+
@channels[local_channel].receive_message_queue.enq message if @channels.has_key? local_channel
|
228
228
|
end
|
229
229
|
|
230
230
|
def channel_window_adjust payload
|
231
231
|
log_info { 'received ' + Message::SSH_MSG_CHANNEL_WINDOW_ADJUST::ID }
|
232
232
|
message = Message::SSH_MSG_CHANNEL_WINDOW_ADJUST.new(logger: logger).decode payload
|
233
233
|
local_channel = message[:'recipient channel']
|
234
|
-
@channels[local_channel].receive_message_queue.enq message
|
234
|
+
@channels[local_channel].receive_message_queue.enq message if @channels.has_key? local_channel
|
235
235
|
end
|
236
236
|
|
237
237
|
def channel_data payload
|
238
238
|
log_info { 'received ' + Message::SSH_MSG_CHANNEL_DATA::ID }
|
239
239
|
message = Message::SSH_MSG_CHANNEL_DATA.new(logger: logger).decode payload
|
240
240
|
local_channel = message[:'recipient channel']
|
241
|
-
@channels[local_channel].receive_message_queue.enq message
|
241
|
+
@channels[local_channel].receive_message_queue.enq message if @channels.has_key? local_channel
|
242
242
|
end
|
243
243
|
|
244
244
|
def channel_extended_data payload
|
245
245
|
log_info { 'received ' + Message::SSH_MSG_CHANNEL_EXTENDED_DATA::ID }
|
246
246
|
message = Message::SSH_MSG_CHANNEL_EXTENDED_DATA.new(logger: logger).decode payload
|
247
247
|
local_channel = message[:'recipient channel']
|
248
|
-
@channels[local_channel].receive_message_queue.enq message
|
248
|
+
@channels[local_channel].receive_message_queue.enq message if @channels.has_key? local_channel
|
249
249
|
end
|
250
250
|
|
251
251
|
def channel_eof payload
|
252
252
|
log_info { 'received ' + Message::SSH_MSG_CHANNEL_EOF::ID }
|
253
253
|
message = Message::SSH_MSG_CHANNEL_EOF.new(logger: logger).decode payload
|
254
254
|
local_channel = message[:'recipient channel']
|
255
|
-
@channels[local_channel].receive_message_queue.enq message
|
255
|
+
@channels[local_channel].receive_message_queue.enq message if @channels.has_key? local_channel
|
256
256
|
end
|
257
257
|
|
258
258
|
def channel_close payload
|
@@ -85,13 +85,13 @@ module HrrRbSsh
|
|
85
85
|
@channel_type_instance.start
|
86
86
|
end
|
87
87
|
@closed = false
|
88
|
-
log_debug { "in start: #{@waiting_thread}" }
|
88
|
+
log_debug { "in start: #{@waiting_thread.inspect}" }
|
89
89
|
@waiting_thread.wakeup if @waiting_thread
|
90
90
|
end
|
91
91
|
|
92
92
|
def wait_until_started
|
93
93
|
@waiting_thread = Thread.current
|
94
|
-
log_debug { "in wait_until_started: #{@waiting_thread}" }
|
94
|
+
log_debug { "in wait_until_started: #{@waiting_thread.inspect}" }
|
95
95
|
Thread.stop
|
96
96
|
end
|
97
97
|
|
@@ -203,7 +203,7 @@ module HrrRbSsh
|
|
203
203
|
local_channel = message[:'recipient channel']
|
204
204
|
@receive_extended_data_queue.enq message[:'data']
|
205
205
|
when Message::SSH_MSG_CHANNEL_WINDOW_ADJUST::VALUE
|
206
|
-
|
206
|
+
log_info { "received channel window adjust" }
|
207
207
|
@remote_window_size = [@remote_window_size + message[:'bytes to add'], 0xffff_ffff].min
|
208
208
|
else
|
209
209
|
log_warn { "received unsupported message: #{message.inspect}" }
|
data/lib/hrr_rb_ssh/transport.rb
CHANGED
@@ -59,7 +59,6 @@ module HrrRbSsh
|
|
59
59
|
@options = options
|
60
60
|
|
61
61
|
@closed = nil
|
62
|
-
@disconnected = nil
|
63
62
|
|
64
63
|
@in_kex = false
|
65
64
|
|
@@ -88,11 +87,12 @@ module HrrRbSsh
|
|
88
87
|
end
|
89
88
|
|
90
89
|
def send payload
|
90
|
+
raise Error::ClosedTransport if @closed
|
91
91
|
@sender_monitor.synchronize do
|
92
92
|
begin
|
93
93
|
@sender.send self, payload
|
94
|
-
rescue
|
95
|
-
|
94
|
+
rescue IOError, SystemCallError => e
|
95
|
+
log_info { "#{e.message} (#{e.class})" }
|
96
96
|
close
|
97
97
|
raise Error::ClosedTransport
|
98
98
|
rescue => e
|
@@ -110,25 +110,24 @@ module HrrRbSsh
|
|
110
110
|
payload = @receiver.receive self
|
111
111
|
case payload[0,1].unpack("C")[0]
|
112
112
|
when Message::SSH_MSG_DISCONNECT::VALUE
|
113
|
+
log_info { "received disconnect message" }
|
113
114
|
message = Message::SSH_MSG_DISCONNECT.new(logger: logger).decode payload
|
114
|
-
log_debug { "received disconnect message: #{message.inspect}" }
|
115
|
-
@disconnected = true
|
116
115
|
close
|
117
116
|
raise Error::ClosedTransport
|
118
117
|
when Message::SSH_MSG_IGNORE::VALUE
|
118
|
+
log_info { "received ignore message" }
|
119
119
|
message = Message::SSH_MSG_IGNORE.new(logger: logger).decode payload
|
120
|
-
log_debug { "received ignore message: #{message.inspect}" }
|
121
120
|
receive
|
122
121
|
when Message::SSH_MSG_UNIMPLEMENTED::VALUE
|
122
|
+
log_info { "received unimplemented message" }
|
123
123
|
message = Message::SSH_MSG_UNIMPLEMENTED.new(logger: logger).decode payload
|
124
|
-
log_debug { "received unimplemented message: #{message.inspect}" }
|
125
124
|
receive
|
126
125
|
when Message::SSH_MSG_DEBUG::VALUE
|
126
|
+
log_info { "received debug message" }
|
127
127
|
message = Message::SSH_MSG_DEBUG.new(logger: logger).decode payload
|
128
|
-
log_debug { "received debug message: #{message.inspect}" }
|
129
128
|
receive
|
130
129
|
when Message::SSH_MSG_KEXINIT::VALUE
|
131
|
-
|
130
|
+
log_info { "received kexinit message" }
|
132
131
|
if @in_kex
|
133
132
|
payload
|
134
133
|
else
|
@@ -139,16 +138,9 @@ module HrrRbSsh
|
|
139
138
|
payload
|
140
139
|
end
|
141
140
|
rescue Error::ClosedTransport
|
142
|
-
raise
|
143
|
-
rescue EOFError => e
|
144
|
-
|
145
|
-
raise Error::ClosedTransport
|
146
|
-
rescue IOError => e
|
147
|
-
log_warn { "IO is closed" }
|
148
|
-
close
|
149
|
-
raise Error::ClosedTransport
|
150
|
-
rescue Errno::ECONNRESET => e
|
151
|
-
log_warn { "IO is RESET" }
|
141
|
+
raise
|
142
|
+
rescue EOFError, IOError, SystemCallError => e
|
143
|
+
log_info { "#{e.message} (#{e.class})" }
|
152
144
|
close
|
153
145
|
raise Error::ClosedTransport
|
154
146
|
rescue => e
|
@@ -161,23 +153,20 @@ module HrrRbSsh
|
|
161
153
|
|
162
154
|
def start
|
163
155
|
log_info { "start transport" }
|
164
|
-
|
165
156
|
begin
|
166
157
|
exchange_version
|
167
158
|
exchange_key
|
168
|
-
|
169
159
|
case @mode
|
170
160
|
when Mode::SERVER
|
171
161
|
verify_service_request
|
172
162
|
when Mode::CLIENT
|
173
163
|
send_service_request
|
174
164
|
end
|
175
|
-
|
176
165
|
@closed = false
|
177
166
|
rescue Error::ClosedTransport
|
178
|
-
|
179
|
-
|
180
|
-
|
167
|
+
raise
|
168
|
+
rescue EOFError, IOError, SystemCallError => e
|
169
|
+
log_info { "#{e.message} (#{e.class})" }
|
181
170
|
close
|
182
171
|
raise Error::ClosedTransport
|
183
172
|
rescue => e
|
@@ -190,13 +179,20 @@ module HrrRbSsh
|
|
190
179
|
end
|
191
180
|
|
192
181
|
def close
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
182
|
+
@sender_monitor.synchronize do
|
183
|
+
return if @closed
|
184
|
+
log_info { "close transport" }
|
185
|
+
begin
|
186
|
+
disconnect
|
187
|
+
@incoming_compression_algorithm.close
|
188
|
+
@outgoing_compression_algorithm.close
|
189
|
+
rescue => e
|
190
|
+
log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
191
|
+
ensure
|
192
|
+
@closed = true
|
193
|
+
log_info { "transport closed" }
|
194
|
+
end
|
195
|
+
end
|
200
196
|
end
|
201
197
|
|
202
198
|
def closed?
|
@@ -204,20 +200,9 @@ module HrrRbSsh
|
|
204
200
|
end
|
205
201
|
|
206
202
|
def disconnect
|
207
|
-
return if @disconnected
|
208
203
|
log_info { "disconnect transport" }
|
209
|
-
|
210
|
-
|
211
|
-
send_disconnect
|
212
|
-
rescue Error::ClosedTransport
|
213
|
-
log_warn { "Transport is closed" }
|
214
|
-
rescue IOError
|
215
|
-
log_warn { "IO is closed" }
|
216
|
-
rescue => e
|
217
|
-
log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
218
|
-
ensure
|
219
|
-
log_info { "transport disconnected" }
|
220
|
-
end
|
204
|
+
send_disconnect
|
205
|
+
log_info { "transport disconnected" }
|
221
206
|
end
|
222
207
|
|
223
208
|
def exchange_version
|
@@ -356,7 +341,15 @@ module HrrRbSsh
|
|
356
341
|
:'language tag' => ""
|
357
342
|
}
|
358
343
|
payload = Message::SSH_MSG_DISCONNECT.new(logger: logger).encode message
|
359
|
-
|
344
|
+
@sender_monitor.synchronize do
|
345
|
+
begin
|
346
|
+
@sender.send self, payload
|
347
|
+
rescue IOError, SystemCallError => e
|
348
|
+
log_info { "#{e.message} (#{e.class})" }
|
349
|
+
rescue => e
|
350
|
+
log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
351
|
+
end
|
352
|
+
end
|
360
353
|
end
|
361
354
|
|
362
355
|
def send_kexinit
|
@@ -425,8 +418,6 @@ module HrrRbSsh
|
|
425
418
|
def receive_service_request
|
426
419
|
payload = @receiver.receive self
|
427
420
|
message = Message::SSH_MSG_SERVICE_REQUEST.new(logger: logger).decode payload
|
428
|
-
|
429
|
-
message
|
430
421
|
end
|
431
422
|
|
432
423
|
def send_service_accept service_name
|
@@ -35,7 +35,7 @@ module HrrRbSsh
|
|
35
35
|
block_size = [transport.incoming_encryption_algorithm.block_size, minimum_block_size].max
|
36
36
|
encrypted_packet.push transport.io.read(block_size)
|
37
37
|
if (encrypted_packet.last == nil) || (encrypted_packet.last.length != block_size)
|
38
|
-
|
38
|
+
log_info { "IO is EOF" }
|
39
39
|
raise EOFError
|
40
40
|
end
|
41
41
|
unencrypted_packet.push transport.incoming_encryption_algorithm.decrypt(encrypted_packet.last)
|
@@ -44,7 +44,7 @@ module HrrRbSsh
|
|
44
44
|
following_packet_length = packet_length_field_length + packet_length - block_size
|
45
45
|
encrypted_packet.push transport.io.read(following_packet_length)
|
46
46
|
if (encrypted_packet.last == nil) || (encrypted_packet.last.length != following_packet_length)
|
47
|
-
|
47
|
+
log_info { "IO is EOF" }
|
48
48
|
raise EOFError
|
49
49
|
end
|
50
50
|
unencrypted_packet.push transport.incoming_encryption_algorithm.decrypt(encrypted_packet.last)
|
@@ -56,7 +56,7 @@ module HrrRbSsh
|
|
56
56
|
mac_length = transport.incoming_mac_algorithm.digest_length
|
57
57
|
mac = transport.io.read mac_length
|
58
58
|
if (mac == nil) || (mac.length != mac_length)
|
59
|
-
|
59
|
+
log_info { "IO is EOF" }
|
60
60
|
raise EOFError
|
61
61
|
end
|
62
62
|
mac
|
data/lib/hrr_rb_ssh/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hrr_rb_ssh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hirura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|