hrr_rb_ssh 0.1.4 → 0.1.5
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/demo/server.rb +10 -2
- data/lib/hrr_rb_ssh/authentication/method/none.rb +1 -1
- data/lib/hrr_rb_ssh/authentication/method/password.rb +2 -2
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp256/ecdsa_signature_blob.rb +27 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp256/public_key_blob.rb +28 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp256/signature.rb +27 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp256/signature_blob.rb +33 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp256.rb +84 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp384/ecdsa_signature_blob.rb +27 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp384/public_key_blob.rb +28 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp384/signature.rb +27 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp384/signature_blob.rb +33 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp384.rb +84 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp521/ecdsa_signature_blob.rb +27 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp521/public_key_blob.rb +28 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp521/signature.rb +27 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp521/signature_blob.rb +33 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ecdsa_sha2_nistp521.rb +84 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_dss/public_key_blob.rb +5 -5
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_dss/signature.rb +2 -2
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_dss/signature_blob.rb +8 -8
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_dss.rb +24 -24
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_rsa/public_key_blob.rb +3 -3
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_rsa/signature.rb +2 -2
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_rsa/signature_blob.rb +8 -8
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_rsa.rb +19 -19
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm.rb +3 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/context.rb +7 -7
- data/lib/hrr_rb_ssh/authentication/method/publickey.rb +7 -7
- data/lib/hrr_rb_ssh/authentication.rb +6 -6
- data/lib/hrr_rb_ssh/codable.rb +7 -2
- data/lib/hrr_rb_ssh/connection/channel/channel_type/direct_tcpip.rb +102 -0
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/proc_chain/chain_context.rb +26 -0
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/proc_chain.rb +29 -0
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/env/context.rb +2 -2
- 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/pty_req/context.rb +6 -6
- 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/window_change/context.rb +4 -4
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session.rb +42 -0
- data/lib/hrr_rb_ssh/connection/channel/channel_type.rb +1 -0
- data/lib/hrr_rb_ssh/connection/channel.rb +50 -63
- data/lib/hrr_rb_ssh/connection/request_handler/reference_shell_request_handler.rb +29 -9
- data/lib/hrr_rb_ssh/connection.rb +22 -27
- data/lib/hrr_rb_ssh/message/001_ssh_msg_disconnect.rb +4 -4
- data/lib/hrr_rb_ssh/message/002_ssh_msg_ignore.rb +2 -2
- data/lib/hrr_rb_ssh/message/003_ssh_msg_unimplemented.rb +2 -2
- data/lib/hrr_rb_ssh/message/004_ssh_msg_debug.rb +4 -4
- data/lib/hrr_rb_ssh/message/005_ssh_msg_service_request.rb +2 -2
- data/lib/hrr_rb_ssh/message/006_ssh_msg_service_accept.rb +2 -2
- data/lib/hrr_rb_ssh/message/020_ssh_msg_kexinit.rb +29 -29
- data/lib/hrr_rb_ssh/message/021_ssh_msg_newkeys.rb +1 -1
- data/lib/hrr_rb_ssh/message/030_ssh_msg_kex_dh_gex_request_old.rb +2 -2
- data/lib/hrr_rb_ssh/message/030_ssh_msg_kexdh_init.rb +2 -2
- data/lib/hrr_rb_ssh/message/030_ssh_msg_kexecdh_init.rb +24 -0
- data/lib/hrr_rb_ssh/message/031_ssh_msg_kex_dh_gex_group.rb +3 -3
- data/lib/hrr_rb_ssh/message/031_ssh_msg_kexdh_reply.rb +4 -4
- data/lib/hrr_rb_ssh/message/031_ssh_msg_kexecdh_reply.rb +26 -0
- data/lib/hrr_rb_ssh/message/032_ssh_msg_kex_dh_gex_init.rb +2 -2
- data/lib/hrr_rb_ssh/message/033_ssh_msg_kex_dh_gex_reply.rb +4 -4
- data/lib/hrr_rb_ssh/message/034_ssh_msg_kex_dh_gex_request.rb +4 -4
- data/lib/hrr_rb_ssh/message/050_ssh_msg_userauth_request.rb +17 -17
- data/lib/hrr_rb_ssh/message/051_ssh_msg_userauth_failure.rb +3 -3
- data/lib/hrr_rb_ssh/message/052_ssh_msg_userauth_success.rb +1 -1
- data/lib/hrr_rb_ssh/message/060_ssh_msg_userauth_pk_ok.rb +3 -3
- data/lib/hrr_rb_ssh/message/080_ssh_msg_global_request.rb +12 -12
- data/lib/hrr_rb_ssh/message/081_ssh_msg_request_success.rb +5 -5
- data/lib/hrr_rb_ssh/message/082_ssh_msg_request_failure.rb +1 -1
- data/lib/hrr_rb_ssh/message/090_ssh_msg_channel_open.rb +24 -24
- data/lib/hrr_rb_ssh/message/091_ssh_msg_channel_open_confirmation.rb +14 -24
- data/lib/hrr_rb_ssh/message/092_ssh_msg_channel_open_failure.rb +5 -5
- data/lib/hrr_rb_ssh/message/093_ssh_msg_channel_window_adjust.rb +3 -3
- data/lib/hrr_rb_ssh/message/094_ssh_msg_channel_data.rb +3 -3
- data/lib/hrr_rb_ssh/message/095_ssh_msg_channel_extended_data.rb +4 -4
- data/lib/hrr_rb_ssh/message/096_ssh_msg_channel_eof.rb +2 -2
- data/lib/hrr_rb_ssh/message/097_ssh_msg_channel_close.rb +2 -2
- data/lib/hrr_rb_ssh/message/098_ssh_msg_channel_request.rb +51 -51
- data/lib/hrr_rb_ssh/message/099_ssh_msg_channel_success.rb +2 -2
- data/lib/hrr_rb_ssh/message/100_ssh_msg_channel_failure.rb +2 -2
- data/lib/hrr_rb_ssh/message.rb +2 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman/h0.rb +8 -8
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman.rb +13 -13
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group_exchange/h0.rb +13 -13
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group_exchange.rb +24 -24
- data/lib/hrr_rb_ssh/transport/kex_algorithm/elliptic_curve_diffie_hellman/h0.rb +29 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm/elliptic_curve_diffie_hellman.rb +132 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm/elliptic_curve_diffie_hellman_sha2_nistp256.rb +18 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm/elliptic_curve_diffie_hellman_sha2_nistp384.rb +18 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm/elliptic_curve_diffie_hellman_sha2_nistp521.rb +18 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm.rb +3 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256/ecdsa_signature_blob.rb +23 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256/public_key_blob.rb +25 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256/signature.rb +23 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb +79 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp384/ecdsa_signature_blob.rb +23 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp384/public_key_blob.rb +25 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp384/signature.rb +23 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp384.rb +80 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp521/ecdsa_signature_blob.rb +23 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp521/public_key_blob.rb +25 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp521/signature.rb +23 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp521.rb +81 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_dss/public_key_blob.rb +5 -5
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_dss/signature.rb +2 -2
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_dss.rb +9 -9
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_rsa/public_key_blob.rb +3 -3
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_rsa/signature.rb +2 -2
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_rsa.rb +6 -6
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm.rb +3 -0
- data/lib/hrr_rb_ssh/transport.rb +30 -30
- data/lib/hrr_rb_ssh/version.rb +1 -1
- metadata +39 -4
- data/lib/hrr_rb_ssh/connection/channel/proc_chain/chain_context.rb +0 -22
- data/lib/hrr_rb_ssh/connection/channel/proc_chain.rb +0 -25
@@ -33,12 +33,12 @@ module HrrRbSsh
|
|
33
33
|
@variables = variables
|
34
34
|
@vars = variables
|
35
35
|
|
36
|
-
@term_environment_variable_value = message['TERM environment variable value']
|
37
|
-
@terminal_width_characters = message['terminal width, characters']
|
38
|
-
@terminal_height_rows = message['terminal height, rows']
|
39
|
-
@terminal_width_pixels = message['terminal width, pixels']
|
40
|
-
@terminal_height_pixels = message['terminal height, pixels']
|
41
|
-
@encoded_terminal_modes = message['encoded terminal modes']
|
36
|
+
@term_environment_variable_value = message[:'TERM environment variable value']
|
37
|
+
@terminal_width_characters = message[:'terminal width, characters']
|
38
|
+
@terminal_height_rows = message[:'terminal height, rows']
|
39
|
+
@terminal_width_pixels = message[:'terminal width, pixels']
|
40
|
+
@terminal_height_pixels = message[:'terminal height, pixels']
|
41
|
+
@encoded_terminal_modes = message[:'encoded terminal modes']
|
42
42
|
end
|
43
43
|
|
44
44
|
def chain_proc &block
|
data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/window_change/context.rb
CHANGED
@@ -31,10 +31,10 @@ module HrrRbSsh
|
|
31
31
|
@variables = variables
|
32
32
|
@vars = variables
|
33
33
|
|
34
|
-
@terminal_width_columns = message['terminal width, columns']
|
35
|
-
@terminal_height_rows = message['terminal height, rows']
|
36
|
-
@terminal_width_pixels = message['terminal width, pixels']
|
37
|
-
@terminal_height_pixels = message['terminal height, pixels']
|
34
|
+
@terminal_width_columns = message[:'terminal width, columns']
|
35
|
+
@terminal_height_rows = message[:'terminal height, rows']
|
36
|
+
@terminal_width_pixels = message[:'terminal width, pixels']
|
37
|
+
@terminal_height_pixels = message[:'terminal height, pixels']
|
38
38
|
end
|
39
39
|
|
40
40
|
def chain_proc &block
|
@@ -1,16 +1,58 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
# vim: et ts=2 sw=2
|
3
3
|
|
4
|
+
require 'hrr_rb_ssh/logger'
|
5
|
+
|
4
6
|
module HrrRbSsh
|
5
7
|
class Connection
|
6
8
|
class Channel
|
7
9
|
class ChannelType
|
8
10
|
class Session < ChannelType
|
9
11
|
NAME = 'session'
|
12
|
+
|
13
|
+
def initialize connection, channel, message
|
14
|
+
@logger = HrrRbSsh::Logger.new self.class.name
|
15
|
+
@connection = connection
|
16
|
+
@channel = channel
|
17
|
+
@variables = {}
|
18
|
+
@proc_chain = ProcChain.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def start
|
22
|
+
@proc_chain_thread = proc_chain_thread
|
23
|
+
end
|
24
|
+
|
25
|
+
def close
|
26
|
+
if @proc_chain_thread
|
27
|
+
@proc_chain_thread.exit
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def request message
|
32
|
+
request_type = message[:'request type']
|
33
|
+
RequestType[request_type].run @proc_chain, @connection.username, @channel.request_handler_io, @variables, message, @connection.options
|
34
|
+
end
|
35
|
+
|
36
|
+
def proc_chain_thread
|
37
|
+
Thread.start {
|
38
|
+
@logger.info("start proc chain thread")
|
39
|
+
begin
|
40
|
+
exitstatus = @proc_chain.call_next
|
41
|
+
rescue => e
|
42
|
+
@logger.error([e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join)
|
43
|
+
exitstatus = 1
|
44
|
+
ensure
|
45
|
+
@logger.info("closing proc chain thread")
|
46
|
+
@channel.close from=:channel_type_instance, exitstatus=exitstatus
|
47
|
+
@logger.info("proc chain thread closed")
|
48
|
+
end
|
49
|
+
}
|
50
|
+
end
|
10
51
|
end
|
11
52
|
end
|
12
53
|
end
|
13
54
|
end
|
14
55
|
end
|
15
56
|
|
57
|
+
require 'hrr_rb_ssh/connection/channel/channel_type/session/proc_chain'
|
16
58
|
require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type'
|
@@ -3,7 +3,6 @@
|
|
3
3
|
|
4
4
|
require 'socket'
|
5
5
|
require 'hrr_rb_ssh/logger'
|
6
|
-
require 'hrr_rb_ssh/connection/channel/proc_chain'
|
7
6
|
require 'hrr_rb_ssh/connection/channel/channel_type'
|
8
7
|
|
9
8
|
module HrrRbSsh
|
@@ -13,24 +12,34 @@ module HrrRbSsh
|
|
13
12
|
MAXIMUM_PACKET_SIZE = 100000
|
14
13
|
|
15
14
|
attr_reader \
|
16
|
-
:
|
15
|
+
:channel_type,
|
16
|
+
:local_channel,
|
17
|
+
:remote_channel,
|
18
|
+
:local_window_size,
|
19
|
+
:local_maximum_packet_size,
|
20
|
+
:remote_window_size,
|
21
|
+
:remote_maximum_packet_size,
|
22
|
+
:receive_message_queue,
|
23
|
+
:request_handler_io
|
17
24
|
|
18
|
-
def initialize connection,
|
25
|
+
def initialize connection, message
|
19
26
|
@logger = HrrRbSsh::Logger.new self.class.name
|
20
27
|
|
21
28
|
@connection = connection
|
22
|
-
|
23
|
-
@
|
24
|
-
@
|
29
|
+
|
30
|
+
@channel_type = message[:'channel type']
|
31
|
+
@local_channel = message[:'sender channel']
|
32
|
+
@remote_channel = message[:'sender channel']
|
25
33
|
@local_window_size = INITIAL_WINDOW_SIZE
|
26
34
|
@local_maximum_packet_size = MAXIMUM_PACKET_SIZE
|
27
|
-
@remote_window_size =
|
28
|
-
@remote_maximum_packet_size =
|
35
|
+
@remote_window_size = message[:'initial window size']
|
36
|
+
@remote_maximum_packet_size = message[:'maximum packet size']
|
37
|
+
|
38
|
+
@channel_type_instance = ChannelType[@channel_type].new connection, self, message
|
29
39
|
|
30
|
-
@
|
40
|
+
@receive_message_queue = Queue.new
|
31
41
|
@receive_data_queue = Queue.new
|
32
42
|
|
33
|
-
@proc_chain = ProcChain.new
|
34
43
|
@channel_io, @request_handler_io = UNIXSocket.pair
|
35
44
|
|
36
45
|
@closed = nil
|
@@ -40,7 +49,7 @@ module HrrRbSsh
|
|
40
49
|
@channel_loop_thread = channel_loop_thread
|
41
50
|
@sender_thread = sender_thread
|
42
51
|
@receiver_thread = receiver_thread
|
43
|
-
@
|
52
|
+
@channel_type_instance.start
|
44
53
|
@closed = false
|
45
54
|
end
|
46
55
|
|
@@ -48,10 +57,10 @@ module HrrRbSsh
|
|
48
57
|
return if @closed
|
49
58
|
@logger.info("close channel")
|
50
59
|
@closed = true
|
51
|
-
unless from == :
|
52
|
-
@
|
60
|
+
unless from == :channel_type_instance
|
61
|
+
@channel_type_instance.close
|
53
62
|
end
|
54
|
-
@
|
63
|
+
@receive_message_queue.close
|
55
64
|
@receive_data_queue.close
|
56
65
|
begin
|
57
66
|
@request_handler_io.close
|
@@ -64,7 +73,7 @@ module HrrRbSsh
|
|
64
73
|
Thread.pass
|
65
74
|
end
|
66
75
|
begin
|
67
|
-
if from == :
|
76
|
+
if from == :channel_type_instance
|
68
77
|
send_channel_eof
|
69
78
|
case exitstatus
|
70
79
|
when Integer
|
@@ -89,29 +98,28 @@ module HrrRbSsh
|
|
89
98
|
def channel_loop_thread
|
90
99
|
Thread.start do
|
91
100
|
@logger.info("start channel loop thread")
|
92
|
-
variables = {}
|
93
101
|
loop do
|
94
102
|
begin
|
95
|
-
message = @
|
96
|
-
if message.nil? && @
|
103
|
+
message = @receive_message_queue.deq
|
104
|
+
if message.nil? && @receive_message_queue.closed?
|
97
105
|
@receive_data_queue.close
|
98
106
|
@logger.info("closing channel loop thread")
|
99
107
|
break
|
100
108
|
end
|
101
|
-
case message['message number']
|
109
|
+
case message[:'message number']
|
102
110
|
when HrrRbSsh::Message::SSH_MSG_CHANNEL_REQUEST::VALUE
|
103
|
-
@logger.info("received channel request: #{message['request type']}")
|
104
|
-
request message
|
105
|
-
if message['want reply']
|
111
|
+
@logger.info("received channel request: #{message[:'request type']}")
|
112
|
+
@channel_type_instance.request message
|
113
|
+
if message[:'want reply']
|
106
114
|
send_channel_success
|
107
115
|
end
|
108
116
|
when HrrRbSsh::Message::SSH_MSG_CHANNEL_DATA::VALUE
|
109
117
|
@logger.info("received channel data")
|
110
|
-
local_channel = message['recipient channel']
|
111
|
-
@receive_data_queue.enq message['data']
|
118
|
+
local_channel = message[:'recipient channel']
|
119
|
+
@receive_data_queue.enq message[:'data']
|
112
120
|
when HrrRbSsh::Message::SSH_MSG_CHANNEL_WINDOW_ADJUST::VALUE
|
113
121
|
@logger.debug("received channel window adjust")
|
114
|
-
@remote_window_size = [@remote_window_size + message['bytes to add'], 0xffff_ffff].min
|
122
|
+
@remote_window_size = [@remote_window_size + message[:'bytes to add'], 0xffff_ffff].min
|
115
123
|
else
|
116
124
|
@logger.warn("received unsupported message: #{message.inspect}")
|
117
125
|
end
|
@@ -191,31 +199,10 @@ module HrrRbSsh
|
|
191
199
|
}
|
192
200
|
end
|
193
201
|
|
194
|
-
def proc_chain_thread
|
195
|
-
Thread.start {
|
196
|
-
@logger.info("start proc chain thread")
|
197
|
-
begin
|
198
|
-
exitstatus = @proc_chain.call_next
|
199
|
-
rescue => e
|
200
|
-
@logger.error([e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join)
|
201
|
-
exitstatus = 1
|
202
|
-
ensure
|
203
|
-
@logger.info("closing proc chain thread")
|
204
|
-
close from=:proc_chain_thread, exitstatus=exitstatus
|
205
|
-
@logger.info("proc chain thread closed")
|
206
|
-
end
|
207
|
-
}
|
208
|
-
end
|
209
|
-
|
210
|
-
def request message, variables
|
211
|
-
request_type = message['request type']
|
212
|
-
ChannelType[@channel_type]::RequestType[request_type].run @proc_chain, @connection.username, @request_handler_io, variables, message, @connection.options
|
213
|
-
end
|
214
|
-
|
215
202
|
def send_channel_success
|
216
203
|
message = {
|
217
|
-
'message number' => HrrRbSsh::Message::SSH_MSG_CHANNEL_SUCCESS::VALUE,
|
218
|
-
'recipient channel' => @remote_channel,
|
204
|
+
:'message number' => HrrRbSsh::Message::SSH_MSG_CHANNEL_SUCCESS::VALUE,
|
205
|
+
:'recipient channel' => @remote_channel,
|
219
206
|
}
|
220
207
|
payload = HrrRbSsh::Message::SSH_MSG_CHANNEL_SUCCESS.encode message
|
221
208
|
@connection.send payload
|
@@ -223,9 +210,9 @@ module HrrRbSsh
|
|
223
210
|
|
224
211
|
def send_channel_window_adjust
|
225
212
|
message = {
|
226
|
-
'message number' => HrrRbSsh::Message::SSH_MSG_CHANNEL_WINDOW_ADJUST::VALUE,
|
227
|
-
'recipient channel' => @remote_channel,
|
228
|
-
'bytes to add' => INITIAL_WINDOW_SIZE,
|
213
|
+
:'message number' => HrrRbSsh::Message::SSH_MSG_CHANNEL_WINDOW_ADJUST::VALUE,
|
214
|
+
:'recipient channel' => @remote_channel,
|
215
|
+
:'bytes to add' => INITIAL_WINDOW_SIZE,
|
229
216
|
}
|
230
217
|
payload = HrrRbSsh::Message::SSH_MSG_CHANNEL_WINDOW_ADJUST.encode message
|
231
218
|
@connection.send payload
|
@@ -233,9 +220,9 @@ module HrrRbSsh
|
|
233
220
|
|
234
221
|
def send_channel_data data
|
235
222
|
message = {
|
236
|
-
'message number' => HrrRbSsh::Message::SSH_MSG_CHANNEL_DATA::VALUE,
|
237
|
-
'recipient channel' => @remote_channel,
|
238
|
-
'data' => data,
|
223
|
+
:'message number' => HrrRbSsh::Message::SSH_MSG_CHANNEL_DATA::VALUE,
|
224
|
+
:'recipient channel' => @remote_channel,
|
225
|
+
:'data' => data,
|
239
226
|
}
|
240
227
|
payload = HrrRbSsh::Message::SSH_MSG_CHANNEL_DATA.encode message
|
241
228
|
@connection.send payload
|
@@ -243,11 +230,11 @@ module HrrRbSsh
|
|
243
230
|
|
244
231
|
def send_channel_request_exit_status exitstatus
|
245
232
|
message = {
|
246
|
-
'message number' => HrrRbSsh::Message::SSH_MSG_CHANNEL_REQUEST::VALUE,
|
247
|
-
'recipient channel' => @remote_channel,
|
248
|
-
'request type' =>
|
249
|
-
'want reply' => false,
|
250
|
-
'exit status' => exitstatus,
|
233
|
+
:'message number' => HrrRbSsh::Message::SSH_MSG_CHANNEL_REQUEST::VALUE,
|
234
|
+
:'recipient channel' => @remote_channel,
|
235
|
+
:'request type' => "exit-status",
|
236
|
+
:'want reply' => false,
|
237
|
+
:'exit status' => exitstatus,
|
251
238
|
}
|
252
239
|
payload = HrrRbSsh::Message::SSH_MSG_CHANNEL_REQUEST.encode message
|
253
240
|
@connection.send payload
|
@@ -255,8 +242,8 @@ module HrrRbSsh
|
|
255
242
|
|
256
243
|
def send_channel_eof
|
257
244
|
message = {
|
258
|
-
'message number' => HrrRbSsh::Message::SSH_MSG_CHANNEL_EOF::VALUE,
|
259
|
-
'recipient channel' => @remote_channel,
|
245
|
+
:'message number' => HrrRbSsh::Message::SSH_MSG_CHANNEL_EOF::VALUE,
|
246
|
+
:'recipient channel' => @remote_channel,
|
260
247
|
}
|
261
248
|
payload = HrrRbSsh::Message::SSH_MSG_CHANNEL_EOF.encode message
|
262
249
|
@connection.send payload
|
@@ -264,8 +251,8 @@ module HrrRbSsh
|
|
264
251
|
|
265
252
|
def send_channel_close
|
266
253
|
message = {
|
267
|
-
'message number' => HrrRbSsh::Message::SSH_MSG_CHANNEL_CLOSE::VALUE,
|
268
|
-
'recipient channel' => @remote_channel,
|
254
|
+
:'message number' => HrrRbSsh::Message::SSH_MSG_CHANNEL_CLOSE::VALUE,
|
255
|
+
:'recipient channel' => @remote_channel,
|
269
256
|
}
|
270
257
|
payload = HrrRbSsh::Message::SSH_MSG_CHANNEL_CLOSE.encode message
|
271
258
|
@connection.send payload
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
# vim: et ts=2 sw=2
|
3
3
|
|
4
|
+
require 'timeout'
|
4
5
|
require 'hrr_rb_ssh/logger'
|
5
6
|
require 'hrr_rb_ssh/connection/request_handler'
|
6
7
|
|
@@ -23,7 +24,7 @@ module HrrRbSsh
|
|
23
24
|
STDERR.reopen pts, 'w'
|
24
25
|
pts.close
|
25
26
|
context.vars[:env] ||= Hash.new
|
26
|
-
exec context.vars[:env], 'login', '-
|
27
|
+
exec context.vars[:env], 'login', '-pf', context.username
|
27
28
|
end
|
28
29
|
|
29
30
|
pts.close
|
@@ -62,16 +63,35 @@ module HrrRbSsh
|
|
62
63
|
end
|
63
64
|
}
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
context.logger.
|
66
|
+
begin
|
67
|
+
pid, status = Process.waitpid2 pid
|
68
|
+
context.logger.info "shell exited with status #{status.inspect}"
|
69
|
+
status.exitstatus
|
70
|
+
ensure
|
71
|
+
unless status
|
72
|
+
context.logger.info "exiting shell"
|
73
|
+
Process.kill :TERM, pid
|
74
|
+
begin
|
75
|
+
Timeout.timeout(1) do
|
76
|
+
pid, status = Process.waitpid2 pid
|
77
|
+
end
|
78
|
+
rescue Timeout::Error
|
79
|
+
context.logger.warn "force exiting shell"
|
80
|
+
Process.kill :KILL, pid
|
81
|
+
pid, status = Process.waitpid2 pid
|
82
|
+
end
|
83
|
+
context.logger.info "shell exited with status #{status.inspect}"
|
84
|
+
end
|
85
|
+
threads.each do |t|
|
86
|
+
begin
|
87
|
+
t.exit
|
88
|
+
t.join
|
89
|
+
rescue => e
|
90
|
+
context.logger.error(e.full_message)
|
91
|
+
end
|
72
92
|
end
|
93
|
+
context.logger.info "proc chain finished"
|
73
94
|
end
|
74
|
-
status.exitstatus
|
75
95
|
}
|
76
96
|
}
|
77
97
|
end
|
@@ -90,7 +90,7 @@ module HrrRbSsh
|
|
90
90
|
def global_request payload
|
91
91
|
@logger.info('received ' + HrrRbSsh::Message::SSH_MSG_GLOBAL_REQUEST::ID)
|
92
92
|
message = HrrRbSsh::Message::SSH_MSG_GLOBAL_REQUEST.decode payload
|
93
|
-
if message['want reply']
|
93
|
+
if message[:'want reply']
|
94
94
|
# returns always failure because global request is not supported so far
|
95
95
|
send_request_failure
|
96
96
|
end
|
@@ -99,50 +99,45 @@ module HrrRbSsh
|
|
99
99
|
def channel_open payload
|
100
100
|
@logger.info('received ' + HrrRbSsh::Message::SSH_MSG_CHANNEL_OPEN::ID)
|
101
101
|
message = HrrRbSsh::Message::SSH_MSG_CHANNEL_OPEN.decode payload
|
102
|
-
|
103
|
-
local_channel
|
104
|
-
remote_channel = message['sender channel']
|
105
|
-
initial_window_size = message['initial window size']
|
106
|
-
maximum_packet_size = message['maximum packet size']
|
107
|
-
channel = Channel.new self, channel_type, local_channel, remote_channel, initial_window_size, maximum_packet_size
|
108
|
-
@channels[local_channel] = channel
|
102
|
+
channel = Channel.new self, message
|
103
|
+
@channels[channel.local_channel] = channel
|
109
104
|
channel.start
|
110
|
-
send_channel_open_confirmation
|
105
|
+
send_channel_open_confirmation channel
|
111
106
|
end
|
112
107
|
|
113
108
|
def channel_request payload
|
114
109
|
@logger.info('received ' + HrrRbSsh::Message::SSH_MSG_CHANNEL_REQUEST::ID)
|
115
110
|
message = HrrRbSsh::Message::SSH_MSG_CHANNEL_REQUEST.decode payload
|
116
|
-
local_channel = message['recipient channel']
|
117
|
-
@channels[local_channel].
|
111
|
+
local_channel = message[:'recipient channel']
|
112
|
+
@channels[local_channel].receive_message_queue.enq message
|
118
113
|
end
|
119
114
|
|
120
115
|
def channel_window_adjust payload
|
121
116
|
@logger.info('received ' + HrrRbSsh::Message::SSH_MSG_CHANNEL_WINDOW_ADJUST::ID)
|
122
117
|
message = HrrRbSsh::Message::SSH_MSG_CHANNEL_WINDOW_ADJUST.decode payload
|
123
|
-
local_channel = message['recipient channel']
|
124
|
-
@channels[local_channel].
|
118
|
+
local_channel = message[:'recipient channel']
|
119
|
+
@channels[local_channel].receive_message_queue.enq message
|
125
120
|
end
|
126
121
|
|
127
122
|
def channel_data payload
|
128
123
|
@logger.info('received ' + HrrRbSsh::Message::SSH_MSG_CHANNEL_DATA::ID)
|
129
124
|
message = HrrRbSsh::Message::SSH_MSG_CHANNEL_DATA.decode payload
|
130
|
-
local_channel = message['recipient channel']
|
131
|
-
@channels[local_channel].
|
125
|
+
local_channel = message[:'recipient channel']
|
126
|
+
@channels[local_channel].receive_message_queue.enq message
|
132
127
|
end
|
133
128
|
|
134
129
|
def channel_eof payload
|
135
130
|
@logger.info('received ' + HrrRbSsh::Message::SSH_MSG_CHANNEL_EOF::ID)
|
136
131
|
message = HrrRbSsh::Message::SSH_MSG_CHANNEL_EOF.decode payload
|
137
|
-
local_channel = message['recipient channel']
|
132
|
+
local_channel = message[:'recipient channel']
|
138
133
|
channel = @channels[local_channel]
|
139
|
-
channel.
|
134
|
+
channel.receive_message_queue.close
|
140
135
|
end
|
141
136
|
|
142
137
|
def channel_close payload
|
143
138
|
@logger.info('received ' + HrrRbSsh::Message::SSH_MSG_CHANNEL_CLOSE::ID)
|
144
139
|
message = HrrRbSsh::Message::SSH_MSG_CHANNEL_CLOSE.decode payload
|
145
|
-
local_channel = message['recipient channel']
|
140
|
+
local_channel = message[:'recipient channel']
|
146
141
|
channel = @channels[local_channel]
|
147
142
|
channel.close
|
148
143
|
@logger.info("deleting channel")
|
@@ -152,7 +147,7 @@ module HrrRbSsh
|
|
152
147
|
|
153
148
|
def send_request_success
|
154
149
|
message = {
|
155
|
-
'message number' => HrrRbSsh::Message::SSH_MSG_REQUEST_SUCCESS::VALUE,
|
150
|
+
:'message number' => HrrRbSsh::Message::SSH_MSG_REQUEST_SUCCESS::VALUE,
|
156
151
|
}
|
157
152
|
payload = HrrRbSsh::Message::SSH_MSG_REQUEST_SUCCESS.encode message
|
158
153
|
@authentication.send payload
|
@@ -160,20 +155,20 @@ module HrrRbSsh
|
|
160
155
|
|
161
156
|
def send_request_failure
|
162
157
|
message = {
|
163
|
-
'message number' => HrrRbSsh::Message::SSH_MSG_REQUEST_FAILURE::VALUE,
|
158
|
+
:'message number' => HrrRbSsh::Message::SSH_MSG_REQUEST_FAILURE::VALUE,
|
164
159
|
}
|
165
160
|
payload = HrrRbSsh::Message::SSH_MSG_REQUEST_FAILURE.encode message
|
166
161
|
@authentication.send payload
|
167
162
|
end
|
168
163
|
|
169
|
-
def send_channel_open_confirmation
|
164
|
+
def send_channel_open_confirmation channel
|
170
165
|
message = {
|
171
|
-
'message number' => HrrRbSsh::Message::SSH_MSG_CHANNEL_OPEN_CONFIRMATION::VALUE,
|
172
|
-
'channel type' => channel_type,
|
173
|
-
'recipient channel' => remote_channel,
|
174
|
-
'sender channel' => local_channel,
|
175
|
-
'initial window size' =>
|
176
|
-
'maximum packet size' =>
|
166
|
+
:'message number' => HrrRbSsh::Message::SSH_MSG_CHANNEL_OPEN_CONFIRMATION::VALUE,
|
167
|
+
:'channel type' => channel.channel_type,
|
168
|
+
:'recipient channel' => channel.remote_channel,
|
169
|
+
:'sender channel' => channel.local_channel,
|
170
|
+
:'initial window size' => channel.local_window_size,
|
171
|
+
:'maximum packet size' => channel.local_maximum_packet_size,
|
177
172
|
}
|
178
173
|
payload = HrrRbSsh::Message::SSH_MSG_CHANNEL_OPEN_CONFIRMATION.encode message
|
179
174
|
@authentication.send payload
|
@@ -34,10 +34,10 @@ module HrrRbSsh
|
|
34
34
|
|
35
35
|
DEFINITION = [
|
36
36
|
#[DataType, Field Name]
|
37
|
-
[DataType::Byte, 'message number'],
|
38
|
-
[DataType::Uint32, 'reason code'],
|
39
|
-
[DataType::String, 'description'],
|
40
|
-
[DataType::String, 'language tag'],
|
37
|
+
[DataType::Byte, :'message number'],
|
38
|
+
[DataType::Uint32, :'reason code'],
|
39
|
+
[DataType::String, :'description'],
|
40
|
+
[DataType::String, :'language tag'],
|
41
41
|
]
|
42
42
|
end
|
43
43
|
end
|
@@ -16,8 +16,8 @@ module HrrRbSsh
|
|
16
16
|
|
17
17
|
DEFINITION = [
|
18
18
|
#[DataType, Field Name]
|
19
|
-
[DataType::Byte, 'message number'],
|
20
|
-
[DataType::Uint32, 'packet sequence number of rejected message'],
|
19
|
+
[DataType::Byte, :'message number'],
|
20
|
+
[DataType::Uint32, :'packet sequence number of rejected message'],
|
21
21
|
]
|
22
22
|
end
|
23
23
|
end
|
@@ -16,10 +16,10 @@ module HrrRbSsh
|
|
16
16
|
|
17
17
|
DEFINITION = [
|
18
18
|
#[DataType, Field Name]
|
19
|
-
[DataType::Byte, 'message number'],
|
20
|
-
[DataType::Boolean, 'always_display'],
|
21
|
-
[DataType::String, 'message'],
|
22
|
-
[DataType::String, 'language tag'],
|
19
|
+
[DataType::Byte, :'message number'],
|
20
|
+
[DataType::Boolean, :'always_display'],
|
21
|
+
[DataType::String, :'message'],
|
22
|
+
[DataType::String, :'language tag'],
|
23
23
|
]
|
24
24
|
end
|
25
25
|
end
|
@@ -16,35 +16,35 @@ module HrrRbSsh
|
|
16
16
|
|
17
17
|
DEFINITION = [
|
18
18
|
#[DataType, Field Name]
|
19
|
-
[DataType::Byte, 'message number'],
|
20
|
-
[DataType::Byte, 'cookie (random byte)'],
|
21
|
-
[DataType::Byte, 'cookie (random byte)'],
|
22
|
-
[DataType::Byte, 'cookie (random byte)'],
|
23
|
-
[DataType::Byte, 'cookie (random byte)'],
|
24
|
-
[DataType::Byte, 'cookie (random byte)'],
|
25
|
-
[DataType::Byte, 'cookie (random byte)'],
|
26
|
-
[DataType::Byte, 'cookie (random byte)'],
|
27
|
-
[DataType::Byte, 'cookie (random byte)'],
|
28
|
-
[DataType::Byte, 'cookie (random byte)'],
|
29
|
-
[DataType::Byte, 'cookie (random byte)'],
|
30
|
-
[DataType::Byte, 'cookie (random byte)'],
|
31
|
-
[DataType::Byte, 'cookie (random byte)'],
|
32
|
-
[DataType::Byte, 'cookie (random byte)'],
|
33
|
-
[DataType::Byte, 'cookie (random byte)'],
|
34
|
-
[DataType::Byte, 'cookie (random byte)'],
|
35
|
-
[DataType::Byte, 'cookie (random byte)'],
|
36
|
-
[DataType::NameList,
|
37
|
-
[DataType::NameList,
|
38
|
-
[DataType::NameList,
|
39
|
-
[DataType::NameList,
|
40
|
-
[DataType::NameList,
|
41
|
-
[DataType::NameList,
|
42
|
-
[DataType::NameList,
|
43
|
-
[DataType::NameList,
|
44
|
-
[DataType::NameList,
|
45
|
-
[DataType::NameList,
|
46
|
-
[DataType::Boolean, 'first_kex_packet_follows'],
|
47
|
-
[DataType::Uint32, '0 (reserved for future extension)'],
|
19
|
+
[DataType::Byte, :'message number'],
|
20
|
+
[DataType::Byte, :'cookie (random byte)'],
|
21
|
+
[DataType::Byte, :'cookie (random byte)'],
|
22
|
+
[DataType::Byte, :'cookie (random byte)'],
|
23
|
+
[DataType::Byte, :'cookie (random byte)'],
|
24
|
+
[DataType::Byte, :'cookie (random byte)'],
|
25
|
+
[DataType::Byte, :'cookie (random byte)'],
|
26
|
+
[DataType::Byte, :'cookie (random byte)'],
|
27
|
+
[DataType::Byte, :'cookie (random byte)'],
|
28
|
+
[DataType::Byte, :'cookie (random byte)'],
|
29
|
+
[DataType::Byte, :'cookie (random byte)'],
|
30
|
+
[DataType::Byte, :'cookie (random byte)'],
|
31
|
+
[DataType::Byte, :'cookie (random byte)'],
|
32
|
+
[DataType::Byte, :'cookie (random byte)'],
|
33
|
+
[DataType::Byte, :'cookie (random byte)'],
|
34
|
+
[DataType::Byte, :'cookie (random byte)'],
|
35
|
+
[DataType::Byte, :'cookie (random byte)'],
|
36
|
+
[DataType::NameList, :'kex_algorithms'],
|
37
|
+
[DataType::NameList, :'server_host_key_algorithms'],
|
38
|
+
[DataType::NameList, :'encryption_algorithms_client_to_server'],
|
39
|
+
[DataType::NameList, :'encryption_algorithms_server_to_client'],
|
40
|
+
[DataType::NameList, :'mac_algorithms_client_to_server'],
|
41
|
+
[DataType::NameList, :'mac_algorithms_server_to_client'],
|
42
|
+
[DataType::NameList, :'compression_algorithms_client_to_server'],
|
43
|
+
[DataType::NameList, :'compression_algorithms_server_to_client'],
|
44
|
+
[DataType::NameList, :'languages_client_to_server'],
|
45
|
+
[DataType::NameList, :'languages_server_to_client'],
|
46
|
+
[DataType::Boolean, :'first_kex_packet_follows'],
|
47
|
+
[DataType::Uint32, :'0 (reserved for future extension)'],
|
48
48
|
]
|
49
49
|
end
|
50
50
|
end
|