hrr_rb_ssh 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/demo/server.rb +5 -97
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_dss/public_key_blob.rb +30 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_dss/signature.rb +27 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_dss/signature_blob.rb +33 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_dss.rb +8 -31
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_rsa/public_key_blob.rb +28 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_rsa/signature.rb +27 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_rsa/signature_blob.rb +33 -0
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_rsa.rb +8 -29
- data/lib/hrr_rb_ssh/codable.rb +64 -0
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/window_change/context.rb +50 -0
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/window_change.rb +33 -0
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type.rb +1 -0
- data/lib/hrr_rb_ssh/connection/request_handler/reference_env_request_handler.rb +21 -0
- data/lib/hrr_rb_ssh/connection/request_handler/reference_exec_request_handler.rb +28 -0
- data/lib/hrr_rb_ssh/connection/request_handler/reference_pty_req_request_handler.rb +32 -0
- data/lib/hrr_rb_ssh/connection/request_handler/reference_shell_request_handler.rb +81 -0
- data/lib/hrr_rb_ssh/connection/request_handler/reference_window_change_request_handler.rb +21 -0
- data/lib/hrr_rb_ssh/connection/request_handler.rb +6 -0
- data/lib/hrr_rb_ssh/message/001_ssh_msg_disconnect.rb +1 -1
- data/lib/hrr_rb_ssh/message/002_ssh_msg_ignore.rb +1 -1
- data/lib/hrr_rb_ssh/message/003_ssh_msg_unimplemented.rb +1 -1
- data/lib/hrr_rb_ssh/message/004_ssh_msg_debug.rb +1 -1
- data/lib/hrr_rb_ssh/message/005_ssh_msg_service_request.rb +1 -1
- data/lib/hrr_rb_ssh/message/006_ssh_msg_service_accept.rb +1 -1
- data/lib/hrr_rb_ssh/message/020_ssh_msg_kexinit.rb +1 -1
- 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 +24 -0
- data/lib/hrr_rb_ssh/message/030_ssh_msg_kexdh_init.rb +1 -1
- data/lib/hrr_rb_ssh/message/031_ssh_msg_kex_dh_gex_group.rb +25 -0
- data/lib/hrr_rb_ssh/message/031_ssh_msg_kexdh_reply.rb +1 -1
- data/lib/hrr_rb_ssh/message/032_ssh_msg_kex_dh_gex_init.rb +24 -0
- data/lib/hrr_rb_ssh/message/033_ssh_msg_kex_dh_gex_reply.rb +26 -0
- data/lib/hrr_rb_ssh/message/034_ssh_msg_kex_dh_gex_request.rb +26 -0
- data/lib/hrr_rb_ssh/message/050_ssh_msg_userauth_request.rb +1 -1
- data/lib/hrr_rb_ssh/message/051_ssh_msg_userauth_failure.rb +1 -1
- 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 +1 -1
- data/lib/hrr_rb_ssh/message/080_ssh_msg_global_request.rb +1 -1
- data/lib/hrr_rb_ssh/message/081_ssh_msg_request_success.rb +1 -1
- 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 +1 -1
- data/lib/hrr_rb_ssh/message/091_ssh_msg_channel_open_confirmation.rb +1 -1
- data/lib/hrr_rb_ssh/message/092_ssh_msg_channel_open_failure.rb +1 -1
- data/lib/hrr_rb_ssh/message/093_ssh_msg_channel_window_adjust.rb +1 -1
- data/lib/hrr_rb_ssh/message/094_ssh_msg_channel_data.rb +1 -1
- data/lib/hrr_rb_ssh/message/095_ssh_msg_channel_extended_data.rb +1 -1
- data/lib/hrr_rb_ssh/message/096_ssh_msg_channel_eof.rb +1 -1
- data/lib/hrr_rb_ssh/message/097_ssh_msg_channel_close.rb +1 -1
- data/lib/hrr_rb_ssh/message/098_ssh_msg_channel_request.rb +1 -1
- data/lib/hrr_rb_ssh/message/099_ssh_msg_channel_success.rb +1 -1
- data/lib/hrr_rb_ssh/message/100_ssh_msg_channel_failure.rb +1 -1
- data/lib/hrr_rb_ssh/message.rb +5 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman/h0.rb +29 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman.rb +28 -18
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group14_sha256.rb +35 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group15_sha512.rb +35 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group16_sha512.rb +41 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group17_sha512.rb +47 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group18_sha512.rb +62 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group_exchange/h0.rb +34 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group_exchange.rb +170 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group_exchange_sha1.rb +17 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group_exchange_sha256.rb +17 -0
- data/lib/hrr_rb_ssh/transport/kex_algorithm.rb +7 -0
- data/lib/hrr_rb_ssh/transport/receiver.rb +16 -14
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_dss/public_key_blob.rb +26 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_dss/signature.rb +23 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_dss.rb +11 -39
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_rsa/public_key_blob.rb +25 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_rsa/signature.rb +23 -0
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_rsa.rb +11 -38
- data/lib/hrr_rb_ssh/transport.rb +9 -29
- data/lib/hrr_rb_ssh/version.rb +1 -1
- metadata +35 -4
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/codable.rb +0 -33
- data/lib/hrr_rb_ssh/message/codable.rb +0 -66
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'io/console'
|
5
|
+
require 'hrr_rb_ssh/logger'
|
6
|
+
require 'hrr_rb_ssh/connection/request_handler'
|
7
|
+
|
8
|
+
module HrrRbSsh
|
9
|
+
class Connection
|
10
|
+
class RequestHandler
|
11
|
+
class ReferencePtyReqRequestHandler < RequestHandler
|
12
|
+
def initialize
|
13
|
+
@logger = HrrRbSsh::Logger.new self.class.name
|
14
|
+
@proc = Proc.new { |context|
|
15
|
+
ptm, pts = PTY.open
|
16
|
+
ptm.winsize = [context.terminal_height_rows, context.terminal_width_characters]
|
17
|
+
context.vars[:ptm] = ptm
|
18
|
+
context.vars[:pts] = pts
|
19
|
+
context.chain_proc { |chain|
|
20
|
+
begin
|
21
|
+
chain.call_next
|
22
|
+
ensure
|
23
|
+
context.vars[:ptm].close
|
24
|
+
context.vars[:pts].close
|
25
|
+
end
|
26
|
+
}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,81 @@
|
|
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
|
+
|
7
|
+
module HrrRbSsh
|
8
|
+
class Connection
|
9
|
+
class RequestHandler
|
10
|
+
class ReferenceShellRequestHandler < RequestHandler
|
11
|
+
def initialize
|
12
|
+
@logger = HrrRbSsh::Logger.new self.class.name
|
13
|
+
@proc = Proc.new { |context|
|
14
|
+
ptm = context.vars[:ptm]
|
15
|
+
pts = context.vars[:pts]
|
16
|
+
|
17
|
+
context.chain_proc { |chain|
|
18
|
+
pid = fork do
|
19
|
+
ptm.close
|
20
|
+
Process.setsid
|
21
|
+
STDIN.reopen pts, 'r'
|
22
|
+
STDOUT.reopen pts, 'w'
|
23
|
+
STDERR.reopen pts, 'w'
|
24
|
+
pts.close
|
25
|
+
context.vars[:env] ||= Hash.new
|
26
|
+
exec context.vars[:env], 'login', '-f', context.username
|
27
|
+
end
|
28
|
+
|
29
|
+
pts.close
|
30
|
+
|
31
|
+
threads = []
|
32
|
+
threads.push Thread.start {
|
33
|
+
loop do
|
34
|
+
begin
|
35
|
+
context.io.write ptm.readpartial(1024)
|
36
|
+
rescue EOFError => e
|
37
|
+
context.logger.info("ptm is EOF")
|
38
|
+
break
|
39
|
+
rescue IOError => e
|
40
|
+
context.logger.warn("IO is closed")
|
41
|
+
break
|
42
|
+
rescue => e
|
43
|
+
context.logger.error(e.full_message)
|
44
|
+
break
|
45
|
+
end
|
46
|
+
end
|
47
|
+
}
|
48
|
+
threads.push Thread.start {
|
49
|
+
loop do
|
50
|
+
begin
|
51
|
+
ptm.write context.io.readpartial(1024)
|
52
|
+
rescue EOFError => e
|
53
|
+
context.logger.info("IO is EOF")
|
54
|
+
break
|
55
|
+
rescue IOError => e
|
56
|
+
context.logger.warn("IO is closed")
|
57
|
+
break
|
58
|
+
rescue => e
|
59
|
+
context.logger.error(e.full_message)
|
60
|
+
break
|
61
|
+
end
|
62
|
+
end
|
63
|
+
}
|
64
|
+
|
65
|
+
pid, status = Process.waitpid2 pid
|
66
|
+
threads.each do |t|
|
67
|
+
begin
|
68
|
+
t.exit
|
69
|
+
t.join
|
70
|
+
rescue => e
|
71
|
+
context.logger.error(e.full_message)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
status.exitstatus
|
75
|
+
}
|
76
|
+
}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'io/console'
|
5
|
+
require 'hrr_rb_ssh/logger'
|
6
|
+
require 'hrr_rb_ssh/connection/request_handler'
|
7
|
+
|
8
|
+
module HrrRbSsh
|
9
|
+
class Connection
|
10
|
+
class RequestHandler
|
11
|
+
class ReferenceWindowChangeRequestHandler < RequestHandler
|
12
|
+
def initialize
|
13
|
+
@logger = HrrRbSsh::Logger.new self.class.name
|
14
|
+
@proc = Proc.new { |context|
|
15
|
+
context.vars[:ptm].winsize = [context.terminal_height_rows, context.terminal_width_columns]
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -16,3 +16,9 @@ module HrrRbSsh
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
require 'hrr_rb_ssh/connection/request_handler/reference_pty_req_request_handler'
|
21
|
+
require 'hrr_rb_ssh/connection/request_handler/reference_env_request_handler'
|
22
|
+
require 'hrr_rb_ssh/connection/request_handler/reference_shell_request_handler'
|
23
|
+
require 'hrr_rb_ssh/connection/request_handler/reference_exec_request_handler'
|
24
|
+
require 'hrr_rb_ssh/connection/request_handler/reference_window_change_request_handler'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/data_type'
|
5
|
+
require 'hrr_rb_ssh/codable'
|
6
|
+
|
7
|
+
module HrrRbSsh
|
8
|
+
module Message
|
9
|
+
module SSH_MSG_KEX_DH_GEX_REQUEST_OLD
|
10
|
+
class << self
|
11
|
+
include Codable
|
12
|
+
end
|
13
|
+
|
14
|
+
ID = self.name.split('::').last
|
15
|
+
VALUE = 30
|
16
|
+
|
17
|
+
DEFINITION = [
|
18
|
+
#[DataType, Field Name]
|
19
|
+
[DataType::Byte, 'message number'],
|
20
|
+
[DataType::Uint32, 'n'],
|
21
|
+
]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/data_type'
|
5
|
+
require 'hrr_rb_ssh/codable'
|
6
|
+
|
7
|
+
module HrrRbSsh
|
8
|
+
module Message
|
9
|
+
module SSH_MSG_KEX_DH_GEX_GROUP
|
10
|
+
class << self
|
11
|
+
include Codable
|
12
|
+
end
|
13
|
+
|
14
|
+
ID = self.name.split('::').last
|
15
|
+
VALUE = 31
|
16
|
+
|
17
|
+
DEFINITION = [
|
18
|
+
#[DataType, Field Name]
|
19
|
+
[DataType::Byte, 'message number'],
|
20
|
+
[DataType::Mpint, 'p'],
|
21
|
+
[DataType::Mpint, 'g'],
|
22
|
+
]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/data_type'
|
5
|
+
require 'hrr_rb_ssh/codable'
|
6
|
+
|
7
|
+
module HrrRbSsh
|
8
|
+
module Message
|
9
|
+
module SSH_MSG_KEX_DH_GEX_INIT
|
10
|
+
class << self
|
11
|
+
include Codable
|
12
|
+
end
|
13
|
+
|
14
|
+
ID = self.name.split('::').last
|
15
|
+
VALUE = 32
|
16
|
+
|
17
|
+
DEFINITION = [
|
18
|
+
#[DataType, Field Name]
|
19
|
+
[DataType::Byte, 'message number'],
|
20
|
+
[DataType::Mpint, 'e'],
|
21
|
+
]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/data_type'
|
5
|
+
require 'hrr_rb_ssh/codable'
|
6
|
+
|
7
|
+
module HrrRbSsh
|
8
|
+
module Message
|
9
|
+
module SSH_MSG_KEX_DH_GEX_REPLY
|
10
|
+
class << self
|
11
|
+
include Codable
|
12
|
+
end
|
13
|
+
|
14
|
+
ID = self.name.split('::').last
|
15
|
+
VALUE = 33
|
16
|
+
|
17
|
+
DEFINITION = [
|
18
|
+
#[DataType, Field Name]
|
19
|
+
[DataType::Byte, 'message number'],
|
20
|
+
[DataType::String, 'server public host key and certificates (K_S)'],
|
21
|
+
[DataType::Mpint, 'f'],
|
22
|
+
[DataType::String, 'signature of H'],
|
23
|
+
]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/data_type'
|
5
|
+
require 'hrr_rb_ssh/codable'
|
6
|
+
|
7
|
+
module HrrRbSsh
|
8
|
+
module Message
|
9
|
+
module SSH_MSG_KEX_DH_GEX_REQUEST
|
10
|
+
class << self
|
11
|
+
include Codable
|
12
|
+
end
|
13
|
+
|
14
|
+
ID = self.name.split('::').last
|
15
|
+
VALUE = 34
|
16
|
+
|
17
|
+
DEFINITION = [
|
18
|
+
#[DataType, Field Name]
|
19
|
+
[DataType::Byte, 'message number'],
|
20
|
+
[DataType::Uint32, 'min'],
|
21
|
+
[DataType::Uint32, 'n'],
|
22
|
+
[DataType::Uint32, 'max'],
|
23
|
+
]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/hrr_rb_ssh/message.rb
CHANGED
@@ -11,6 +11,11 @@ require 'hrr_rb_ssh/message/020_ssh_msg_kexinit'
|
|
11
11
|
require 'hrr_rb_ssh/message/021_ssh_msg_newkeys'
|
12
12
|
require 'hrr_rb_ssh/message/030_ssh_msg_kexdh_init'
|
13
13
|
require 'hrr_rb_ssh/message/031_ssh_msg_kexdh_reply'
|
14
|
+
require 'hrr_rb_ssh/message/030_ssh_msg_kex_dh_gex_request_old'
|
15
|
+
require 'hrr_rb_ssh/message/031_ssh_msg_kex_dh_gex_group'
|
16
|
+
require 'hrr_rb_ssh/message/032_ssh_msg_kex_dh_gex_init'
|
17
|
+
require 'hrr_rb_ssh/message/033_ssh_msg_kex_dh_gex_reply'
|
18
|
+
require 'hrr_rb_ssh/message/034_ssh_msg_kex_dh_gex_request'
|
14
19
|
require 'hrr_rb_ssh/message/050_ssh_msg_userauth_request'
|
15
20
|
require 'hrr_rb_ssh/message/051_ssh_msg_userauth_failure'
|
16
21
|
require 'hrr_rb_ssh/message/052_ssh_msg_userauth_success'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
require 'hrr_rb_ssh/data_type'
|
5
|
+
require 'hrr_rb_ssh/codable'
|
6
|
+
|
7
|
+
module HrrRbSsh
|
8
|
+
class Transport
|
9
|
+
class KexAlgorithm
|
10
|
+
module DiffieHellman
|
11
|
+
module H0
|
12
|
+
class << self
|
13
|
+
include Codable
|
14
|
+
end
|
15
|
+
DEFINITION = [
|
16
|
+
[DataType::String, 'V_C'],
|
17
|
+
[DataType::String, 'V_S'],
|
18
|
+
[DataType::String, 'I_C'],
|
19
|
+
[DataType::String, 'I_S'],
|
20
|
+
[DataType::String, 'K_S'],
|
21
|
+
[DataType::Mpint, 'e'],
|
22
|
+
[DataType::Mpint, 'f'],
|
23
|
+
[DataType::Mpint, 'k'],
|
24
|
+
]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|