hrr_rb_ssh 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +12 -2
- data/README.md +11 -9
- data/demo/echo_server.rb +50 -42
- data/demo/server.rb +81 -62
- data/demo/subsystem_echo_server.rb +54 -47
- data/lib/hrr_rb_ssh/{transport/server_host_key_algorithm/ecdsa_sha2_nistp521 → algorithm/publickey/ecdsa_sha2}/ecdsa_signature_blob.rb +3 -3
- data/lib/hrr_rb_ssh/{transport/server_host_key_algorithm/ecdsa_sha2_nistp256 → algorithm/publickey/ecdsa_sha2}/public_key_blob.rb +5 -6
- data/lib/hrr_rb_ssh/{transport/server_host_key_algorithm/ecdsa_sha2_nistp256 → algorithm/publickey/ecdsa_sha2}/signature.rb +5 -5
- data/lib/hrr_rb_ssh/algorithm/publickey/ecdsa_sha2.rb +85 -0
- data/lib/hrr_rb_ssh/algorithm/publickey/ecdsa_sha2_nistp256.rb +19 -0
- data/lib/hrr_rb_ssh/algorithm/publickey/ecdsa_sha2_nistp384.rb +19 -0
- data/lib/hrr_rb_ssh/algorithm/publickey/ecdsa_sha2_nistp521.rb +19 -0
- data/lib/hrr_rb_ssh/{transport/server_host_key_algorithm → algorithm/publickey}/ssh_dss/public_key_blob.rb +3 -3
- data/lib/hrr_rb_ssh/{transport/server_host_key_algorithm → algorithm/publickey}/ssh_dss/signature.rb +4 -4
- data/lib/hrr_rb_ssh/algorithm/publickey/ssh_dss.rb +90 -0
- data/lib/hrr_rb_ssh/{transport/server_host_key_algorithm → algorithm/publickey}/ssh_rsa/public_key_blob.rb +3 -4
- data/lib/hrr_rb_ssh/{transport/server_host_key_algorithm → algorithm/publickey}/ssh_rsa/signature.rb +4 -4
- data/lib/hrr_rb_ssh/algorithm/publickey/ssh_rsa.rb +67 -0
- data/lib/hrr_rb_ssh/algorithm/publickey.rb +32 -0
- data/lib/hrr_rb_ssh/algorithm.rb +9 -0
- data/lib/hrr_rb_ssh/authentication/method/none/context.rb +1 -1
- data/lib/hrr_rb_ssh/authentication/method/none.rb +1 -1
- data/lib/hrr_rb_ssh/authentication/method/password/context.rb +1 -1
- data/lib/hrr_rb_ssh/authentication/method/password.rb +1 -1
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp256.rb +2 -65
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp384.rb +2 -65
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp521.rb +2 -65
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/functionable.rb +54 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/signature_blob.rb +31 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_dss.rb +2 -73
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_rsa.rb +2 -55
- data/lib/hrr_rb_ssh/authentication/method/publickey.rb +3 -3
- data/lib/hrr_rb_ssh/authentication.rb +15 -15
- data/lib/hrr_rb_ssh/codable.rb +1 -1
- data/lib/hrr_rb_ssh/compat/openssh/public_key.rb +3 -40
- data/lib/hrr_rb_ssh/compat/ruby/array.rb +14 -0
- data/lib/hrr_rb_ssh/compat/ruby/openssl/bn.rb +20 -0
- data/lib/hrr_rb_ssh/compat/ruby/openssl.rb +4 -0
- data/lib/hrr_rb_ssh/compat/ruby/queue.rb +38 -0
- data/lib/hrr_rb_ssh/compat/ruby.rb +6 -0
- data/lib/hrr_rb_ssh/compat.rb +1 -63
- data/lib/hrr_rb_ssh/connection/channel/channel_type/direct_tcpip.rb +1 -1
- data/lib/hrr_rb_ssh/connection/channel/channel_type/forwarded_tcpip.rb +1 -1
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/proc_chain/chain_context.rb +1 -1
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/proc_chain.rb +1 -1
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/env/context.rb +1 -1
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/env.rb +1 -1
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/exec/context.rb +1 -1
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/exec.rb +1 -1
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/pty_req/context.rb +1 -1
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/pty_req.rb +1 -1
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/shell/context.rb +1 -1
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/shell.rb +1 -1
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/subsystem/context.rb +1 -1
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/subsystem.rb +1 -1
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/window_change/context.rb +1 -1
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/window_change.rb +1 -1
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session.rb +1 -1
- data/lib/hrr_rb_ssh/connection/channel.rb +22 -22
- data/lib/hrr_rb_ssh/connection/global_request_handler.rb +1 -1
- data/lib/hrr_rb_ssh/connection/request_handler/reference_env_request_handler.rb +1 -1
- data/lib/hrr_rb_ssh/connection/request_handler/reference_exec_request_handler.rb +3 -56
- data/lib/hrr_rb_ssh/connection/request_handler/reference_pty_req_request_handler.rb +50 -13
- data/lib/hrr_rb_ssh/connection/request_handler/reference_shell_request_handler.rb +3 -56
- data/lib/hrr_rb_ssh/connection/request_handler/reference_window_change_request_handler.rb +1 -1
- data/lib/hrr_rb_ssh/connection/request_handler.rb +1 -1
- data/lib/hrr_rb_ssh/connection.rb +40 -40
- data/lib/hrr_rb_ssh/data_type.rb +0 -3
- data/lib/hrr_rb_ssh/error/closed_authentication.rb +9 -0
- data/lib/hrr_rb_ssh/{closed_transport_error.rb → error/closed_connection.rb} +3 -1
- data/lib/hrr_rb_ssh/{closed_authentication_error.rb → error/closed_transport.rb} +3 -1
- data/lib/hrr_rb_ssh/error.rb +11 -0
- data/lib/hrr_rb_ssh/{closed_connection_error.rb → mode.rb} +3 -1
- data/lib/hrr_rb_ssh/server.rb +23 -0
- data/lib/hrr_rb_ssh/transport/compression_algorithm/functionable.rb +1 -1
- data/lib/hrr_rb_ssh/transport/compression_algorithm/unfunctionable.rb +1 -1
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb +3 -3
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/unfunctionable.rb +1 -1
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman.rb +8 -48
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group_exchange.rb +11 -51
- data/lib/hrr_rb_ssh/transport/kex_algorithm/elliptic_curve_diffie_hellman.rb +8 -48
- data/lib/hrr_rb_ssh/transport/kex_algorithm/iv_computable.rb +57 -0
- data/lib/hrr_rb_ssh/transport/mac_algorithm/functionable.rb +2 -2
- data/lib/hrr_rb_ssh/transport/mac_algorithm/unfunctionable.rb +1 -1
- data/lib/hrr_rb_ssh/transport/receiver.rb +1 -1
- data/lib/hrr_rb_ssh/transport/sender.rb +1 -1
- data/lib/hrr_rb_ssh/transport/sequence_number.rb +1 -1
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb +2 -56
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp384.rb +2 -56
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp521.rb +2 -56
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/functionable.rb +29 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_dss.rb +2 -50
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_rsa.rb +2 -31
- data/lib/hrr_rb_ssh/transport.rb +83 -81
- data/lib/hrr_rb_ssh/version.rb +1 -1
- data/lib/hrr_rb_ssh.rb +4 -0
- metadata +32 -37
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp256/ecdsa_signature_blob.rb +0 -27
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp256/public_key_blob.rb +0 -28
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp256/signature.rb +0 -27
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp256/signature_blob.rb +0 -33
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp384/ecdsa_signature_blob.rb +0 -27
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp384/public_key_blob.rb +0 -28
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp384/signature.rb +0 -27
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp384/signature_blob.rb +0 -33
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp521/ecdsa_signature_blob.rb +0 -27
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp521/public_key_blob.rb +0 -28
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp521/signature.rb +0 -27
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp521/signature_blob.rb +0 -33
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_dss/public_key_blob.rb +0 -30
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_dss/signature.rb +0 -27
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_dss/signature_blob.rb +0 -33
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_rsa/public_key_blob.rb +0 -28
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_rsa/signature.rb +0 -27
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_rsa/signature_blob.rb +0 -33
- data/lib/hrr_rb_ssh/transport/mode.rb +0 -11
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256/ecdsa_signature_blob.rb +0 -23
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp384/ecdsa_signature_blob.rb +0 -23
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp384/public_key_blob.rb +0 -25
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp384/signature.rb +0 -23
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp521/public_key_blob.rb +0 -25
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp521/signature.rb +0 -23
@@ -14,7 +14,7 @@ module HrrRbSsh
|
|
14
14
|
NAME = 'pty-req'
|
15
15
|
|
16
16
|
def self.run proc_chain, username, io, variables, message, options
|
17
|
-
logger =
|
17
|
+
logger = Logger.new self.class.name
|
18
18
|
|
19
19
|
context = Context.new proc_chain, username, io, variables, message
|
20
20
|
handler = options.fetch('connection_channel_request_pty_req', RequestHandler.new {})
|
@@ -14,7 +14,7 @@ module HrrRbSsh
|
|
14
14
|
NAME = 'shell'
|
15
15
|
|
16
16
|
def self.run proc_chain, username, io, variables, message, options
|
17
|
-
logger =
|
17
|
+
logger = Logger.new self.class.name
|
18
18
|
|
19
19
|
context = Context.new proc_chain, username, io, variables, message
|
20
20
|
handler = options.fetch('connection_channel_request_shell', RequestHandler.new {})
|
@@ -14,7 +14,7 @@ module HrrRbSsh
|
|
14
14
|
NAME = 'subsystem'
|
15
15
|
|
16
16
|
def self.run proc_chain, username, io, variables, message, options
|
17
|
-
logger =
|
17
|
+
logger = Logger.new self.class.name
|
18
18
|
|
19
19
|
context = Context.new proc_chain, username, io, variables, message
|
20
20
|
handler = options.fetch('connection_channel_request_subsystem', RequestHandler.new {})
|
@@ -14,7 +14,7 @@ module HrrRbSsh
|
|
14
14
|
NAME = 'window-change'
|
15
15
|
|
16
16
|
def self.run proc_chain, username, io, variables, message, options
|
17
|
-
logger =
|
17
|
+
logger = Logger.new self.class.name
|
18
18
|
|
19
19
|
context = Context.new proc_chain, username, io, variables, message
|
20
20
|
handler = options.fetch('connection_channel_request_window_change', RequestHandler.new {})
|
@@ -22,7 +22,7 @@ module HrrRbSsh
|
|
22
22
|
:receive_message_queue
|
23
23
|
|
24
24
|
def initialize connection, message, socket=nil
|
25
|
-
@logger =
|
25
|
+
@logger = Logger.new self.class.name
|
26
26
|
|
27
27
|
@connection = connection
|
28
28
|
|
@@ -103,7 +103,7 @@ module HrrRbSsh
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
send_channel_close
|
106
|
-
rescue
|
106
|
+
rescue Error::ClosedConnection => e
|
107
107
|
Thread.pass
|
108
108
|
rescue => e
|
109
109
|
@logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
@@ -127,7 +127,7 @@ module HrrRbSsh
|
|
127
127
|
break
|
128
128
|
end
|
129
129
|
case message[:'message number']
|
130
|
-
when
|
130
|
+
when Message::SSH_MSG_CHANNEL_REQUEST::VALUE
|
131
131
|
@logger.info { "received channel request: #{message[:'request type']}" }
|
132
132
|
begin
|
133
133
|
@channel_type_instance.request message
|
@@ -141,11 +141,11 @@ module HrrRbSsh
|
|
141
141
|
send_channel_success
|
142
142
|
end
|
143
143
|
end
|
144
|
-
when
|
144
|
+
when Message::SSH_MSG_CHANNEL_DATA::VALUE
|
145
145
|
@logger.info { "received channel data" }
|
146
146
|
local_channel = message[:'recipient channel']
|
147
147
|
@receive_data_queue.enq message[:'data']
|
148
|
-
when
|
148
|
+
when Message::SSH_MSG_CHANNEL_WINDOW_ADJUST::VALUE
|
149
149
|
@logger.debug { "received channel window adjust" }
|
150
150
|
@remote_window_size = [@remote_window_size + message[:'bytes to add'], 0xffff_ffff].min
|
151
151
|
else
|
@@ -261,80 +261,80 @@ module HrrRbSsh
|
|
261
261
|
|
262
262
|
def send_channel_success
|
263
263
|
message = {
|
264
|
-
:'message number' =>
|
264
|
+
:'message number' => Message::SSH_MSG_CHANNEL_SUCCESS::VALUE,
|
265
265
|
:'recipient channel' => @remote_channel,
|
266
266
|
}
|
267
|
-
payload =
|
267
|
+
payload = Message::SSH_MSG_CHANNEL_SUCCESS.encode message
|
268
268
|
@connection.send payload
|
269
269
|
end
|
270
270
|
|
271
271
|
def send_channel_failure
|
272
272
|
message = {
|
273
|
-
:'message number' =>
|
273
|
+
:'message number' => Message::SSH_MSG_CHANNEL_FAILURE::VALUE,
|
274
274
|
:'recipient channel' => @remote_channel,
|
275
275
|
}
|
276
|
-
payload =
|
276
|
+
payload = Message::SSH_MSG_CHANNEL_FAILURE.encode message
|
277
277
|
@connection.send payload
|
278
278
|
end
|
279
279
|
|
280
280
|
def send_channel_window_adjust
|
281
281
|
message = {
|
282
|
-
:'message number' =>
|
282
|
+
:'message number' => Message::SSH_MSG_CHANNEL_WINDOW_ADJUST::VALUE,
|
283
283
|
:'recipient channel' => @remote_channel,
|
284
284
|
:'bytes to add' => INITIAL_WINDOW_SIZE,
|
285
285
|
}
|
286
|
-
payload =
|
286
|
+
payload = Message::SSH_MSG_CHANNEL_WINDOW_ADJUST.encode message
|
287
287
|
@connection.send payload
|
288
288
|
end
|
289
289
|
|
290
290
|
def send_channel_data data
|
291
291
|
message = {
|
292
|
-
:'message number' =>
|
292
|
+
:'message number' => Message::SSH_MSG_CHANNEL_DATA::VALUE,
|
293
293
|
:'recipient channel' => @remote_channel,
|
294
294
|
:'data' => data,
|
295
295
|
}
|
296
|
-
payload =
|
296
|
+
payload = Message::SSH_MSG_CHANNEL_DATA.encode message
|
297
297
|
@connection.send payload
|
298
298
|
end
|
299
299
|
|
300
|
-
def send_channel_extended_data data, code=
|
300
|
+
def send_channel_extended_data data, code=Message::SSH_MSG_CHANNEL_EXTENDED_DATA::DataTypeCode::SSH_EXTENDED_DATA_STDERR
|
301
301
|
message = {
|
302
|
-
:'message number' =>
|
302
|
+
:'message number' => Message::SSH_MSG_CHANNEL_EXTENDED_DATA::VALUE,
|
303
303
|
:'recipient channel' => @remote_channel,
|
304
304
|
:'data type code' => code,
|
305
305
|
:'data' => data,
|
306
306
|
}
|
307
|
-
payload =
|
307
|
+
payload = Message::SSH_MSG_CHANNEL_EXTENDED_DATA.encode message
|
308
308
|
@connection.send payload
|
309
309
|
end
|
310
310
|
|
311
311
|
def send_channel_request_exit_status exitstatus
|
312
312
|
message = {
|
313
|
-
:'message number' =>
|
313
|
+
:'message number' => Message::SSH_MSG_CHANNEL_REQUEST::VALUE,
|
314
314
|
:'recipient channel' => @remote_channel,
|
315
315
|
:'request type' => "exit-status",
|
316
316
|
:'want reply' => false,
|
317
317
|
:'exit status' => exitstatus,
|
318
318
|
}
|
319
|
-
payload =
|
319
|
+
payload = Message::SSH_MSG_CHANNEL_REQUEST.encode message
|
320
320
|
@connection.send payload
|
321
321
|
end
|
322
322
|
|
323
323
|
def send_channel_eof
|
324
324
|
message = {
|
325
|
-
:'message number' =>
|
325
|
+
:'message number' => Message::SSH_MSG_CHANNEL_EOF::VALUE,
|
326
326
|
:'recipient channel' => @remote_channel,
|
327
327
|
}
|
328
|
-
payload =
|
328
|
+
payload = Message::SSH_MSG_CHANNEL_EOF.encode message
|
329
329
|
@connection.send payload
|
330
330
|
end
|
331
331
|
|
332
332
|
def send_channel_close
|
333
333
|
message = {
|
334
|
-
:'message number' =>
|
334
|
+
:'message number' => Message::SSH_MSG_CHANNEL_CLOSE::VALUE,
|
335
335
|
:'recipient channel' => @remote_channel,
|
336
336
|
}
|
337
|
-
payload =
|
337
|
+
payload = Message::SSH_MSG_CHANNEL_CLOSE.encode message
|
338
338
|
@connection.send payload
|
339
339
|
end
|
340
340
|
end
|
@@ -9,7 +9,7 @@ module HrrRbSsh
|
|
9
9
|
class RequestHandler
|
10
10
|
class ReferenceEnvRequestHandler < RequestHandler
|
11
11
|
def initialize
|
12
|
-
@logger =
|
12
|
+
@logger = Logger.new self.class.name
|
13
13
|
@proc = Proc.new { |context|
|
14
14
|
context.vars[:env] ||= Hash.new
|
15
15
|
context.vars[:env][context.variable_name] = context.variable_value
|
@@ -10,7 +10,7 @@ module HrrRbSsh
|
|
10
10
|
class RequestHandler
|
11
11
|
class ReferenceExecRequestHandler < RequestHandler
|
12
12
|
def initialize
|
13
|
-
@logger =
|
13
|
+
@logger = Logger.new self.class.name
|
14
14
|
@proc = Proc.new { |context|
|
15
15
|
ptm = context.vars[:ptm]
|
16
16
|
pts = context.vars[:pts]
|
@@ -39,10 +39,8 @@ module HrrRbSsh
|
|
39
39
|
pid = fork do
|
40
40
|
Process.setsid
|
41
41
|
Dir.chdir passwd.dir
|
42
|
-
Process.
|
43
|
-
Process.
|
44
|
-
Process.uid = passwd.uid
|
45
|
-
Process.euid = passwd.uid
|
42
|
+
Process::GID.change_privilege passwd.gid
|
43
|
+
Process::UID.change_privilege passwd.uid
|
46
44
|
if ptm
|
47
45
|
STDIN.reopen pts, 'r'
|
48
46
|
STDOUT.reopen pts, 'w'
|
@@ -58,45 +56,6 @@ module HrrRbSsh
|
|
58
56
|
else
|
59
57
|
pts.close
|
60
58
|
|
61
|
-
ptm_read_thread = Thread.start {
|
62
|
-
loop do
|
63
|
-
begin
|
64
|
-
context.io[1].write ptm.readpartial(10240)
|
65
|
-
rescue EOFError => e
|
66
|
-
context.logger.info { "ptm is EOF in ptm_read_thread" }
|
67
|
-
break
|
68
|
-
rescue IOError => e
|
69
|
-
context.logger.warn { "IO Error in ptm_read_thread" }
|
70
|
-
break
|
71
|
-
rescue Errno::EIO => e
|
72
|
-
context.logger.info { "EIO Error in ptm_read_thread" }
|
73
|
-
break
|
74
|
-
rescue => e
|
75
|
-
context.logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
76
|
-
break
|
77
|
-
end
|
78
|
-
end
|
79
|
-
}
|
80
|
-
ptm_write_thread = Thread.start {
|
81
|
-
loop do
|
82
|
-
begin
|
83
|
-
ptm.write context.io[0].readpartial(10240)
|
84
|
-
rescue EOFError => e
|
85
|
-
context.logger.info { "IO is EOF in ptm_write_thread" }
|
86
|
-
break
|
87
|
-
rescue IOError => e
|
88
|
-
context.logger.warn { "IO Error in ptm_write_thread" }
|
89
|
-
break
|
90
|
-
rescue Errno::EIO => e
|
91
|
-
context.logger.info { "EIO Error in ptm_read_thread" }
|
92
|
-
break
|
93
|
-
rescue => e
|
94
|
-
context.logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
95
|
-
break
|
96
|
-
end
|
97
|
-
end
|
98
|
-
}
|
99
|
-
|
100
59
|
begin
|
101
60
|
pid, status = Process.waitpid2 pid
|
102
61
|
context.logger.info { "program exited with status #{status.inspect}" }
|
@@ -116,18 +75,6 @@ module HrrRbSsh
|
|
116
75
|
end
|
117
76
|
context.logger.info { "program exited with status #{status.inspect}" }
|
118
77
|
end
|
119
|
-
begin
|
120
|
-
ptm_read_thread.join
|
121
|
-
rescue => e
|
122
|
-
context.logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
123
|
-
end
|
124
|
-
begin
|
125
|
-
ptm_write_thread.exit
|
126
|
-
ptm_write_thread.join
|
127
|
-
rescue => e
|
128
|
-
context.logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
129
|
-
end
|
130
|
-
context.logger.info { "proc chain finished" }
|
131
78
|
end
|
132
79
|
end
|
133
80
|
}
|
@@ -13,7 +13,7 @@ module HrrRbSsh
|
|
13
13
|
class RequestHandler
|
14
14
|
class ReferencePtyReqRequestHandler < RequestHandler
|
15
15
|
def initialize
|
16
|
-
@logger =
|
16
|
+
@logger = Logger.new self.class.name
|
17
17
|
@proc = Proc.new { |context|
|
18
18
|
begin
|
19
19
|
ptm, pts = PTY.open
|
@@ -27,27 +27,64 @@ module HrrRbSsh
|
|
27
27
|
context.vars[:env]['TERM'] = context.term_environment_variable_value
|
28
28
|
context.chain_proc { |chain|
|
29
29
|
begin
|
30
|
+
ptm_read_thread = Thread.start {
|
31
|
+
loop do
|
32
|
+
begin
|
33
|
+
context.io[1].write ptm.readpartial(10240)
|
34
|
+
rescue EOFError => e
|
35
|
+
context.logger.info { "ptm is EOF in ptm_read_thread" }
|
36
|
+
break
|
37
|
+
rescue IOError => e
|
38
|
+
context.logger.warn { "IO Error in ptm_read_thread" }
|
39
|
+
break
|
40
|
+
rescue Errno::EIO => e
|
41
|
+
context.logger.info { "EIO Error in ptm_read_thread" }
|
42
|
+
break
|
43
|
+
rescue => e
|
44
|
+
context.logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
45
|
+
break
|
46
|
+
end
|
47
|
+
end
|
48
|
+
}
|
49
|
+
ptm_write_thread = Thread.start {
|
50
|
+
loop do
|
51
|
+
begin
|
52
|
+
ptm.write context.io[0].readpartial(10240)
|
53
|
+
rescue EOFError => e
|
54
|
+
context.logger.info { "IO is EOF in ptm_write_thread" }
|
55
|
+
break
|
56
|
+
rescue IOError => e
|
57
|
+
context.logger.warn { "IO Error in ptm_write_thread" }
|
58
|
+
break
|
59
|
+
rescue Errno::EIO => e
|
60
|
+
context.logger.info { "EIO Error in ptm_read_thread" }
|
61
|
+
break
|
62
|
+
rescue => e
|
63
|
+
context.logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
64
|
+
break
|
65
|
+
end
|
66
|
+
end
|
67
|
+
}
|
30
68
|
chain.call_next
|
31
69
|
ensure
|
70
|
+
context.vars[:ptm].close rescue nil
|
71
|
+
context.vars[:pts].close rescue nil
|
32
72
|
begin
|
33
|
-
|
34
|
-
rescue
|
73
|
+
ptm_read_thread.join
|
74
|
+
rescue => e
|
75
|
+
context.logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
35
76
|
end
|
36
77
|
begin
|
37
|
-
|
38
|
-
|
78
|
+
ptm_write_thread.exit
|
79
|
+
ptm_write_thread.join
|
80
|
+
rescue => e
|
81
|
+
context.logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
39
82
|
end
|
40
83
|
end
|
41
84
|
}
|
42
85
|
rescue => e
|
43
|
-
|
44
|
-
|
45
|
-
rescue
|
46
|
-
end
|
47
|
-
begin
|
48
|
-
pts.close
|
49
|
-
rescue
|
50
|
-
end
|
86
|
+
ptm.close rescue nil
|
87
|
+
pts.close rescue nil
|
51
88
|
context.chain_proc{ |chain|
|
52
89
|
exitstatus = 1
|
53
90
|
}
|
@@ -11,7 +11,7 @@ module HrrRbSsh
|
|
11
11
|
class RequestHandler
|
12
12
|
class ReferenceShellRequestHandler < RequestHandler
|
13
13
|
def initialize
|
14
|
-
@logger =
|
14
|
+
@logger = Logger.new self.class.name
|
15
15
|
@proc = Proc.new { |context|
|
16
16
|
ptm = context.vars[:ptm]
|
17
17
|
pts = context.vars[:pts]
|
@@ -36,10 +36,8 @@ module HrrRbSsh
|
|
36
36
|
ptm.close
|
37
37
|
Process.setsid
|
38
38
|
Dir.chdir passwd.dir
|
39
|
-
Process.
|
40
|
-
Process.
|
41
|
-
Process.uid = passwd.uid
|
42
|
-
Process.euid = passwd.uid
|
39
|
+
Process::GID.change_privilege passwd.gid
|
40
|
+
Process::UID.change_privilege passwd.uid
|
43
41
|
STDIN.reopen pts, 'r'
|
44
42
|
STDOUT.reopen pts, 'w'
|
45
43
|
STDERR.reopen pts, 'w'
|
@@ -49,45 +47,6 @@ module HrrRbSsh
|
|
49
47
|
|
50
48
|
pts.close
|
51
49
|
|
52
|
-
ptm_read_thread = Thread.start {
|
53
|
-
loop do
|
54
|
-
begin
|
55
|
-
context.io[1].write ptm.readpartial(10240)
|
56
|
-
rescue EOFError => e
|
57
|
-
context.logger.info { "ptm is EOF in ptm_read_thread" }
|
58
|
-
break
|
59
|
-
rescue IOError => e
|
60
|
-
context.logger.warn { "IO Error in ptm_read_thread" }
|
61
|
-
break
|
62
|
-
rescue Errno::EIO => e
|
63
|
-
context.logger.info { "EIO Error in ptm_read_thread" }
|
64
|
-
break
|
65
|
-
rescue => e
|
66
|
-
context.logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
67
|
-
break
|
68
|
-
end
|
69
|
-
end
|
70
|
-
}
|
71
|
-
ptm_write_thread = Thread.start {
|
72
|
-
loop do
|
73
|
-
begin
|
74
|
-
ptm.write context.io[0].readpartial(10240)
|
75
|
-
rescue EOFError => e
|
76
|
-
context.logger.info { "IO is EOF in ptm_write_thread" }
|
77
|
-
break
|
78
|
-
rescue IOError => e
|
79
|
-
context.logger.warn { "IO Error in ptm_write_thread" }
|
80
|
-
break
|
81
|
-
rescue Errno::EIO => e
|
82
|
-
context.logger.info { "EIO Error in ptm_read_thread" }
|
83
|
-
break
|
84
|
-
rescue => e
|
85
|
-
context.logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
86
|
-
break
|
87
|
-
end
|
88
|
-
end
|
89
|
-
}
|
90
|
-
|
91
50
|
begin
|
92
51
|
pid, status = Process.waitpid2 pid
|
93
52
|
context.logger.info { "shell exited with status #{status.inspect}" }
|
@@ -107,18 +66,6 @@ module HrrRbSsh
|
|
107
66
|
end
|
108
67
|
context.logger.info { "shell exited with status #{status.inspect}" }
|
109
68
|
end
|
110
|
-
begin
|
111
|
-
ptm_read_thread.join
|
112
|
-
rescue => e
|
113
|
-
context.logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
114
|
-
end
|
115
|
-
begin
|
116
|
-
ptm_write_thread.exit
|
117
|
-
ptm_write_thread.join
|
118
|
-
rescue => e
|
119
|
-
context.logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
120
|
-
end
|
121
|
-
context.logger.info { "proc chain finished" }
|
122
69
|
end
|
123
70
|
}
|
124
71
|
}
|
@@ -10,7 +10,7 @@ module HrrRbSsh
|
|
10
10
|
class RequestHandler
|
11
11
|
class ReferenceWindowChangeRequestHandler < RequestHandler
|
12
12
|
def initialize
|
13
|
-
@logger =
|
13
|
+
@logger = Logger.new self.class.name
|
14
14
|
@proc = Proc.new { |context|
|
15
15
|
context.vars[:ptm].winsize = [context.terminal_height_rows, context.terminal_width_columns, context.terminal_width_pixels, context.terminal_height_pixels]
|
16
16
|
}
|