hrr_rb_ssh 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +27 -0
- data/.rspec +3 -0
- data/.travis.yml +22 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE +201 -0
- data/README.md +47 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/demo/server.rb +134 -0
- data/hrr_rb_ssh.gemspec +27 -0
- data/lib/hrr_rb_ssh/authentication/authenticator.rb +16 -0
- data/lib/hrr_rb_ssh/authentication/method/none/context.rb +28 -0
- data/lib/hrr_rb_ssh/authentication/method/none.rb +38 -0
- data/lib/hrr_rb_ssh/authentication/method/password/context.rb +29 -0
- data/lib/hrr_rb_ssh/authentication/method/password.rb +37 -0
- data/lib/hrr_rb_ssh/authentication/method.rb +21 -0
- data/lib/hrr_rb_ssh/authentication.rb +107 -0
- data/lib/hrr_rb_ssh/closed_authentication_error.rb +7 -0
- data/lib/hrr_rb_ssh/closed_connection_error.rb +7 -0
- data/lib/hrr_rb_ssh/closed_transport_error.rb +7 -0
- data/lib/hrr_rb_ssh/compat.rb +65 -0
- data/lib/hrr_rb_ssh/connection/channel/proc_chain/chain_context.rb +22 -0
- data/lib/hrr_rb_ssh/connection/channel/proc_chain.rb +25 -0
- data/lib/hrr_rb_ssh/connection/channel/session/env/context.rb +43 -0
- data/lib/hrr_rb_ssh/connection/channel/session/env.rb +31 -0
- data/lib/hrr_rb_ssh/connection/channel/session/exec/context.rb +41 -0
- data/lib/hrr_rb_ssh/connection/channel/session/exec.rb +31 -0
- data/lib/hrr_rb_ssh/connection/channel/session/pty_req/context.rb +50 -0
- data/lib/hrr_rb_ssh/connection/channel/session/pty_req.rb +31 -0
- data/lib/hrr_rb_ssh/connection/channel/session/shell/context.rb +37 -0
- data/lib/hrr_rb_ssh/connection/channel/session/shell.rb +31 -0
- data/lib/hrr_rb_ssh/connection/channel/session/subsystem/context.rb +40 -0
- data/lib/hrr_rb_ssh/connection/channel/session/subsystem.rb +31 -0
- data/lib/hrr_rb_ssh/connection/channel/session.rb +31 -0
- data/lib/hrr_rb_ssh/connection/channel.rb +278 -0
- data/lib/hrr_rb_ssh/connection/request_handler.rb +18 -0
- data/lib/hrr_rb_ssh/connection.rb +170 -0
- data/lib/hrr_rb_ssh/logger.rb +52 -0
- data/lib/hrr_rb_ssh/message/001_ssh_msg_disconnect.rb +44 -0
- data/lib/hrr_rb_ssh/message/002_ssh_msg_ignore.rb +24 -0
- data/lib/hrr_rb_ssh/message/003_ssh_msg_unimplemented.rb +24 -0
- data/lib/hrr_rb_ssh/message/004_ssh_msg_debug.rb +26 -0
- data/lib/hrr_rb_ssh/message/005_ssh_msg_service_request.rb +24 -0
- data/lib/hrr_rb_ssh/message/006_ssh_msg_service_accept.rb +24 -0
- data/lib/hrr_rb_ssh/message/020_ssh_msg_kexinit.rb +51 -0
- data/lib/hrr_rb_ssh/message/021_ssh_msg_newkeys.rb +23 -0
- data/lib/hrr_rb_ssh/message/030_ssh_msg_kexdh_init.rb +24 -0
- data/lib/hrr_rb_ssh/message/031_ssh_msg_kexdh_reply.rb +26 -0
- data/lib/hrr_rb_ssh/message/050_ssh_msg_userauth_request.rb +58 -0
- data/lib/hrr_rb_ssh/message/051_ssh_msg_userauth_failure.rb +25 -0
- data/lib/hrr_rb_ssh/message/052_ssh_msg_userauth_success.rb +23 -0
- data/lib/hrr_rb_ssh/message/060_ssh_msg_userauth_pk_ok.rb +25 -0
- data/lib/hrr_rb_ssh/message/080_ssh_msg_global_request.rb +47 -0
- data/lib/hrr_rb_ssh/message/081_ssh_msg_request_success.rb +36 -0
- data/lib/hrr_rb_ssh/message/082_ssh_msg_request_failure.rb +23 -0
- data/lib/hrr_rb_ssh/message/090_ssh_msg_channel_open.rb +67 -0
- data/lib/hrr_rb_ssh/message/091_ssh_msg_channel_open_confirmation.rb +67 -0
- data/lib/hrr_rb_ssh/message/092_ssh_msg_channel_open_failure.rb +34 -0
- data/lib/hrr_rb_ssh/message/093_ssh_msg_channel_window_adjust.rb +25 -0
- data/lib/hrr_rb_ssh/message/094_ssh_msg_channel_data.rb +25 -0
- data/lib/hrr_rb_ssh/message/095_ssh_msg_channel_extended_data.rb +30 -0
- data/lib/hrr_rb_ssh/message/096_ssh_msg_channel_eof.rb +24 -0
- data/lib/hrr_rb_ssh/message/097_ssh_msg_channel_close.rb +24 -0
- data/lib/hrr_rb_ssh/message/098_ssh_msg_channel_request.rb +139 -0
- data/lib/hrr_rb_ssh/message/099_ssh_msg_channel_success.rb +24 -0
- data/lib/hrr_rb_ssh/message/100_ssh_msg_channel_failure.rb +24 -0
- data/lib/hrr_rb_ssh/message/codable.rb +67 -0
- data/lib/hrr_rb_ssh/message.rb +36 -0
- data/lib/hrr_rb_ssh/transport/compression_algorithm/none.rb +33 -0
- data/lib/hrr_rb_ssh/transport/compression_algorithm/zlib.rb +38 -0
- data/lib/hrr_rb_ssh/transport/compression_algorithm.rb +22 -0
- data/lib/hrr_rb_ssh/transport/constant.rb +11 -0
- data/lib/hrr_rb_ssh/transport/data_type.rb +163 -0
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes_128_cbc.rb +73 -0
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/none.rb +49 -0
- data/lib/hrr_rb_ssh/transport/encryption_algorithm.rb +22 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman.rb +129 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group14_sha1.rb +42 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group1_sha1.rb +34 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm.rb +22 -0
- data/lib/hrr_rb_ssh/transport/mac_algorithm/hmac_sha1.rb +45 -0
- data/lib/hrr_rb_ssh/transport/mac_algorithm/none.rb +40 -0
- data/lib/hrr_rb_ssh/transport/mac_algorithm.rb +22 -0
- data/lib/hrr_rb_ssh/transport/mode.rb +11 -0
- data/lib/hrr_rb_ssh/transport/receiver.rb +75 -0
- data/lib/hrr_rb_ssh/transport/sender.rb +57 -0
- data/lib/hrr_rb_ssh/transport/sequence_number.rb +22 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_rsa.rb +108 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm.rb +21 -0
- data/lib/hrr_rb_ssh/transport.rb +459 -0
- data/lib/hrr_rb_ssh/version.rb +6 -0
- data/lib/hrr_rb_ssh.rb +13 -0
- metadata +193 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/logger'
|
5
|
+
|
6
|
+
module HrrRbSsh
|
7
|
+
class Authentication
|
8
|
+
module Method
|
9
|
+
class Password
|
10
|
+
class Context
|
11
|
+
attr_reader :username, :password
|
12
|
+
|
13
|
+
def initialize username, password
|
14
|
+
@username = username
|
15
|
+
@password = password
|
16
|
+
|
17
|
+
@logger = HrrRbSsh::Logger.new self.class.name
|
18
|
+
end
|
19
|
+
|
20
|
+
def verify username, password
|
21
|
+
@logger.info("verify username and password")
|
22
|
+
@logger.debug("username is #{username}, @username is #{@username}, and password is #{password}, @password is #{@password}")
|
23
|
+
username == @username and password == @password
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/logger'
|
5
|
+
require 'hrr_rb_ssh/authentication/method/password/context'
|
6
|
+
|
7
|
+
module HrrRbSsh
|
8
|
+
class Authentication
|
9
|
+
module Method
|
10
|
+
name_list = [
|
11
|
+
'password'
|
12
|
+
]
|
13
|
+
|
14
|
+
class Password
|
15
|
+
def initialize options
|
16
|
+
@logger = HrrRbSsh::Logger.new self.class.name
|
17
|
+
|
18
|
+
@authenticator = options.fetch( 'authentication_password_authenticator', Authenticator.new { false } )
|
19
|
+
end
|
20
|
+
|
21
|
+
def authenticate userauth_request_message
|
22
|
+
@logger.info("authenticate")
|
23
|
+
@logger.debug("userauth request: " + userauth_request_message.inspect)
|
24
|
+
username = userauth_request_message['user name']
|
25
|
+
password = userauth_request_message['plaintext password']
|
26
|
+
context = Context.new(username, password)
|
27
|
+
@authenticator.authenticate context
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
@@list ||= Hash.new
|
32
|
+
name_list.each do |name|
|
33
|
+
@@list[name] = Password
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/authentication/method/none'
|
5
|
+
require 'hrr_rb_ssh/authentication/method/password'
|
6
|
+
|
7
|
+
module HrrRbSsh
|
8
|
+
class Authentication
|
9
|
+
module Method
|
10
|
+
@@list ||= Hash.new
|
11
|
+
|
12
|
+
def self.[] key
|
13
|
+
@@list[key]
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.name_list
|
17
|
+
@@list.keys
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/logger'
|
5
|
+
require 'hrr_rb_ssh/message'
|
6
|
+
require 'hrr_rb_ssh/closed_authentication_error'
|
7
|
+
require 'hrr_rb_ssh/authentication/authenticator'
|
8
|
+
require 'hrr_rb_ssh/authentication/method'
|
9
|
+
|
10
|
+
module HrrRbSsh
|
11
|
+
class Authentication
|
12
|
+
SERVICE_NAME = 'ssh-userauth'
|
13
|
+
|
14
|
+
def initialize transport, options={}
|
15
|
+
@transport = transport
|
16
|
+
@options = options
|
17
|
+
|
18
|
+
@logger = HrrRbSsh::Logger.new self.class.name
|
19
|
+
|
20
|
+
@transport.register_acceptable_service SERVICE_NAME
|
21
|
+
|
22
|
+
@closed = nil
|
23
|
+
|
24
|
+
@username = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def send payload
|
28
|
+
raise HrrRbSsh::ClosedAuthenticationError if @closed
|
29
|
+
begin
|
30
|
+
@transport.send payload
|
31
|
+
rescue HrrRbSsh::ClosedTransportError
|
32
|
+
raise HrrRbSsh::ClosedAuthenticationError
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def receive
|
37
|
+
raise HrrRbSsh::ClosedAuthenticationError if @closed
|
38
|
+
begin
|
39
|
+
@transport.receive
|
40
|
+
rescue HrrRbSsh::ClosedTransportError
|
41
|
+
raise HrrRbSsh::ClosedAuthenticationError
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def start
|
46
|
+
@transport.start
|
47
|
+
authenticate
|
48
|
+
end
|
49
|
+
|
50
|
+
def close
|
51
|
+
return if @closed
|
52
|
+
@closed = true
|
53
|
+
@transport.close
|
54
|
+
end
|
55
|
+
|
56
|
+
def closed?
|
57
|
+
@closed
|
58
|
+
end
|
59
|
+
|
60
|
+
def username
|
61
|
+
raise HrrRbSsh::ClosedAuthenticationError if @closed
|
62
|
+
@username
|
63
|
+
end
|
64
|
+
|
65
|
+
def authenticate
|
66
|
+
loop do
|
67
|
+
payload = @transport.receive
|
68
|
+
case payload[0,1].unpack("C")[0]
|
69
|
+
when HrrRbSsh::Message::SSH_MSG_USERAUTH_REQUEST::VALUE
|
70
|
+
userauth_request_message = HrrRbSsh::Message::SSH_MSG_USERAUTH_REQUEST.decode payload
|
71
|
+
method_name = userauth_request_message['method name']
|
72
|
+
method = Method[method_name].new(@options)
|
73
|
+
if method.authenticate(userauth_request_message)
|
74
|
+
send_userauth_success
|
75
|
+
@username = userauth_request_message['user name']
|
76
|
+
@closed = false
|
77
|
+
break
|
78
|
+
else
|
79
|
+
send_userauth_failure
|
80
|
+
@closed = true
|
81
|
+
end
|
82
|
+
else
|
83
|
+
@closed = true
|
84
|
+
raise
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def send_userauth_failure
|
90
|
+
message = {
|
91
|
+
'SSH_MSG_USERAUTH_FAILURE' => HrrRbSsh::Message::SSH_MSG_USERAUTH_FAILURE::VALUE,
|
92
|
+
'authentications that can continue' => Method.name_list,
|
93
|
+
'partial success' => false,
|
94
|
+
}
|
95
|
+
payload = HrrRbSsh::Message::SSH_MSG_USERAUTH_FAILURE.encode message
|
96
|
+
@transport.send payload
|
97
|
+
end
|
98
|
+
|
99
|
+
def send_userauth_success
|
100
|
+
message = {
|
101
|
+
'SSH_MSG_USERAUTH_SUCCESS' => HrrRbSsh::Message::SSH_MSG_USERAUTH_SUCCESS::VALUE,
|
102
|
+
}
|
103
|
+
payload = HrrRbSsh::Message::SSH_MSG_USERAUTH_SUCCESS.encode message
|
104
|
+
@transport.send payload
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
if RUBY_VERSION < "2.1"
|
5
|
+
class Array
|
6
|
+
def to_h
|
7
|
+
h = Hash.new
|
8
|
+
self.each do |k, v|
|
9
|
+
h[k] = v
|
10
|
+
end
|
11
|
+
h
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'openssl'
|
16
|
+
class OpenSSL::BN
|
17
|
+
alias_method :__initialize__, :initialize
|
18
|
+
|
19
|
+
def initialize *args
|
20
|
+
args[0] = case args[0]
|
21
|
+
when OpenSSL::BN, Fixnum, Bignum
|
22
|
+
args[0].to_s
|
23
|
+
else
|
24
|
+
args[0]
|
25
|
+
end
|
26
|
+
__initialize__ *args
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if RUBY_VERSION < "2.3"
|
32
|
+
class ClosedQueueError < StandardError
|
33
|
+
end
|
34
|
+
|
35
|
+
class Queue
|
36
|
+
require 'timeout'
|
37
|
+
|
38
|
+
alias_method :__enq__, :enq
|
39
|
+
alias_method :__deq__, :deq
|
40
|
+
|
41
|
+
def close
|
42
|
+
@closed = true
|
43
|
+
end
|
44
|
+
|
45
|
+
def closed?
|
46
|
+
@closed == true
|
47
|
+
end
|
48
|
+
|
49
|
+
def enq arg
|
50
|
+
raise ClosedQueueError if @closed == true
|
51
|
+
__enq__ arg
|
52
|
+
end
|
53
|
+
|
54
|
+
def deq
|
55
|
+
begin
|
56
|
+
Timeout.timeout(0.1) do
|
57
|
+
__deq__
|
58
|
+
end
|
59
|
+
rescue Timeout::Error
|
60
|
+
return nil if @closed == true
|
61
|
+
retry
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/logger'
|
5
|
+
|
6
|
+
module HrrRbSsh
|
7
|
+
class Connection
|
8
|
+
class Channel
|
9
|
+
class ProcChain
|
10
|
+
class ChainContext
|
11
|
+
def initialize proc_chain
|
12
|
+
@logger = HrrRbSsh::Logger.new self.class.name
|
13
|
+
@proc_chain = proc_chain
|
14
|
+
end
|
15
|
+
def call_next *args
|
16
|
+
@proc_chain.call_next *args
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/logger'
|
5
|
+
require 'hrr_rb_ssh/connection/channel/proc_chain/chain_context'
|
6
|
+
|
7
|
+
module HrrRbSsh
|
8
|
+
class Connection
|
9
|
+
class Channel
|
10
|
+
class ProcChain
|
11
|
+
def initialize
|
12
|
+
@logger = HrrRbSsh::Logger.new self.class.name
|
13
|
+
@q = Queue.new
|
14
|
+
end
|
15
|
+
def connect next_proc
|
16
|
+
@q.enq next_proc if next_proc
|
17
|
+
end
|
18
|
+
def call_next *args
|
19
|
+
next_proc = @q.deq
|
20
|
+
next_proc.call ChainContext.new(self), *args
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/logger'
|
5
|
+
|
6
|
+
module HrrRbSsh
|
7
|
+
class Connection
|
8
|
+
class Channel
|
9
|
+
module Session
|
10
|
+
class Env
|
11
|
+
class Context
|
12
|
+
attr_reader \
|
13
|
+
:logger,
|
14
|
+
:username,
|
15
|
+
:io,
|
16
|
+
:variables,
|
17
|
+
:vars,
|
18
|
+
:variable_name,
|
19
|
+
:variable_value
|
20
|
+
|
21
|
+
def initialize proc_chain, username, io, variables, message
|
22
|
+
@logger = HrrRbSsh::Logger.new self.class.name
|
23
|
+
|
24
|
+
@proc_chain = proc_chain
|
25
|
+
@username = username
|
26
|
+
@io = io
|
27
|
+
@variables = variables
|
28
|
+
@vars = variables
|
29
|
+
|
30
|
+
@variable_name = message['variable name']
|
31
|
+
@variable_value = message['variable value']
|
32
|
+
end
|
33
|
+
|
34
|
+
def chain_proc &block
|
35
|
+
@proc = block || @proc
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/logger'
|
5
|
+
require 'hrr_rb_ssh/connection/request_handler'
|
6
|
+
require 'hrr_rb_ssh/connection/channel/session/env/context'
|
7
|
+
|
8
|
+
module HrrRbSsh
|
9
|
+
class Connection
|
10
|
+
class Channel
|
11
|
+
module Session
|
12
|
+
request_type = 'env'
|
13
|
+
|
14
|
+
class Env
|
15
|
+
def self.run proc_chain, username, io, variables, message, options
|
16
|
+
logger = HrrRbSsh::Logger.new self.class.name
|
17
|
+
|
18
|
+
context = Context.new proc_chain, username, io, variables, message
|
19
|
+
handler = options.fetch('connection_channel_request_env', RequestHandler.new {})
|
20
|
+
handler.run context
|
21
|
+
|
22
|
+
proc_chain.connect context.chain_proc
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
@@request_type_list ||= Hash.new
|
27
|
+
@@request_type_list[request_type] = Env
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/logger'
|
5
|
+
|
6
|
+
module HrrRbSsh
|
7
|
+
class Connection
|
8
|
+
class Channel
|
9
|
+
module Session
|
10
|
+
class Exec
|
11
|
+
class Context
|
12
|
+
attr_reader \
|
13
|
+
:logger,
|
14
|
+
:username,
|
15
|
+
:io,
|
16
|
+
:variables,
|
17
|
+
:vars,
|
18
|
+
:command
|
19
|
+
|
20
|
+
def initialize proc_chain, username, io, variables, message
|
21
|
+
@logger = HrrRbSsh::Logger.new self.class.name
|
22
|
+
|
23
|
+
@proc_chain = proc_chain
|
24
|
+
@username = username
|
25
|
+
@io = io
|
26
|
+
@variables = variables
|
27
|
+
@vars = variables
|
28
|
+
|
29
|
+
@command = message['command']
|
30
|
+
end
|
31
|
+
|
32
|
+
def chain_proc &block
|
33
|
+
@proc = block || @proc
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/logger'
|
5
|
+
require 'hrr_rb_ssh/connection/request_handler'
|
6
|
+
require 'hrr_rb_ssh/connection/channel/session/exec/context'
|
7
|
+
|
8
|
+
module HrrRbSsh
|
9
|
+
class Connection
|
10
|
+
class Channel
|
11
|
+
module Session
|
12
|
+
request_type = 'exec'
|
13
|
+
|
14
|
+
class Exec
|
15
|
+
def self.run proc_chain, username, io, variables, message, options
|
16
|
+
logger = HrrRbSsh::Logger.new self.class.name
|
17
|
+
|
18
|
+
context = Context.new proc_chain, username, io, variables, message
|
19
|
+
handler = options.fetch('connection_channel_request_exec', RequestHandler.new {})
|
20
|
+
handler.run context
|
21
|
+
|
22
|
+
proc_chain.connect context.chain_proc
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
@@request_type_list ||= Hash.new
|
27
|
+
@@request_type_list[request_type] = Exec
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/logger'
|
5
|
+
|
6
|
+
module HrrRbSsh
|
7
|
+
class Connection
|
8
|
+
class Channel
|
9
|
+
module Session
|
10
|
+
class PtyReq
|
11
|
+
class Context
|
12
|
+
attr_reader \
|
13
|
+
:logger,
|
14
|
+
:username,
|
15
|
+
:io,
|
16
|
+
:variables,
|
17
|
+
:vars,
|
18
|
+
:term_environment_variable_value,
|
19
|
+
:terminal_width_characters,
|
20
|
+
:terminal_height_rows,
|
21
|
+
:terminal_width_pixels,
|
22
|
+
:terminal_height_pixels,
|
23
|
+
:encoded_terminal_modes
|
24
|
+
|
25
|
+
def initialize proc_chain, username, io, variables, message
|
26
|
+
@logger = HrrRbSsh::Logger.new self.class.name
|
27
|
+
|
28
|
+
@proc_chain = proc_chain
|
29
|
+
@username = username
|
30
|
+
@io = io
|
31
|
+
@variables = variables
|
32
|
+
@vars = variables
|
33
|
+
|
34
|
+
@term_environment_variable_value = message['TERM environment variable value']
|
35
|
+
@terminal_width_characters = message['terminal width, characters']
|
36
|
+
@terminal_height_rows = message['terminal height, rows']
|
37
|
+
@terminal_width_pixels = message['terminal width, pixels']
|
38
|
+
@terminal_height_pixels = message['terminal height, pixels']
|
39
|
+
@encoded_terminal_modes = message['encoded terminal modes']
|
40
|
+
end
|
41
|
+
|
42
|
+
def chain_proc &block
|
43
|
+
@proc = block || @proc
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/logger'
|
5
|
+
require 'hrr_rb_ssh/connection/request_handler'
|
6
|
+
require 'hrr_rb_ssh/connection/channel/session/pty_req/context'
|
7
|
+
|
8
|
+
module HrrRbSsh
|
9
|
+
class Connection
|
10
|
+
class Channel
|
11
|
+
module Session
|
12
|
+
request_type = 'pty-req'
|
13
|
+
|
14
|
+
class PtyReq
|
15
|
+
def self.run proc_chain, username, io, variables, message, options
|
16
|
+
logger = HrrRbSsh::Logger.new self.class.name
|
17
|
+
|
18
|
+
context = Context.new proc_chain, username, io, variables, message
|
19
|
+
handler = options.fetch('connection_channel_request_pty_req', RequestHandler.new {})
|
20
|
+
handler.run context
|
21
|
+
|
22
|
+
proc_chain.connect context.chain_proc
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
@@request_type_list ||= Hash.new
|
27
|
+
@@request_type_list[request_type] = PtyReq
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/logger'
|
5
|
+
|
6
|
+
module HrrRbSsh
|
7
|
+
class Connection
|
8
|
+
class Channel
|
9
|
+
module Session
|
10
|
+
class Shell
|
11
|
+
class Context
|
12
|
+
attr_reader \
|
13
|
+
:logger,
|
14
|
+
:username,
|
15
|
+
:io,
|
16
|
+
:variables,
|
17
|
+
:vars
|
18
|
+
|
19
|
+
def initialize proc_chain, username, io, variables, message
|
20
|
+
@logger = HrrRbSsh::Logger.new self.class.name
|
21
|
+
|
22
|
+
@proc_chain = proc_chain
|
23
|
+
@username = username
|
24
|
+
@io = io
|
25
|
+
@variables = variables
|
26
|
+
@vars = variables
|
27
|
+
end
|
28
|
+
|
29
|
+
def chain_proc &block
|
30
|
+
@proc = block || @proc
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/logger'
|
5
|
+
require 'hrr_rb_ssh/connection/request_handler'
|
6
|
+
require 'hrr_rb_ssh/connection/channel/session/shell/context'
|
7
|
+
|
8
|
+
module HrrRbSsh
|
9
|
+
class Connection
|
10
|
+
class Channel
|
11
|
+
module Session
|
12
|
+
request_type = 'shell'
|
13
|
+
|
14
|
+
class Shell
|
15
|
+
def self.run proc_chain, username, io, variables, message, options
|
16
|
+
logger = HrrRbSsh::Logger.new self.class.name
|
17
|
+
|
18
|
+
context = Context.new proc_chain, username, io, variables, message
|
19
|
+
handler = options.fetch('connection_channel_request_shell', RequestHandler.new {})
|
20
|
+
handler.run context
|
21
|
+
|
22
|
+
proc_chain.connect context.chain_proc
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
@@request_type_list ||= Hash.new
|
27
|
+
@@request_type_list[request_type] = Shell
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/logger'
|
5
|
+
|
6
|
+
module HrrRbSsh
|
7
|
+
class Connection
|
8
|
+
class Channel
|
9
|
+
module Session
|
10
|
+
class Subsystem
|
11
|
+
class Context
|
12
|
+
attr_reader \
|
13
|
+
:logger,
|
14
|
+
:username,
|
15
|
+
:io,
|
16
|
+
:variables,
|
17
|
+
:vars,
|
18
|
+
:subsystem_name
|
19
|
+
|
20
|
+
def initialize proc_chain, username, io, variables, message
|
21
|
+
@logger = HrrRbSsh::Logger.new self.class.name
|
22
|
+
|
23
|
+
@proc_chain = proc_chain
|
24
|
+
@username = username
|
25
|
+
@io = io
|
26
|
+
@variables = variables
|
27
|
+
@vars = variables
|
28
|
+
|
29
|
+
@subsystem_name = message['subsystem name']
|
30
|
+
end
|
31
|
+
|
32
|
+
def chain_proc &block
|
33
|
+
@proc = block || @proc
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|