hrr_rb_ssh 0.1.2 → 0.1.3
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 +13 -1
- data/lib/hrr_rb_ssh/authentication/method/none/context.rb +1 -1
- data/lib/hrr_rb_ssh/authentication/method/none.rb +4 -4
- data/lib/hrr_rb_ssh/authentication/method/password/context.rb +1 -1
- data/lib/hrr_rb_ssh/authentication/method/password.rb +4 -4
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/codable.rb +5 -5
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_dss.rb +29 -18
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_rsa.rb +27 -16
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm.rb +7 -13
- data/lib/hrr_rb_ssh/authentication/method/publickey/context.rb +1 -1
- data/lib/hrr_rb_ssh/authentication/method/publickey.rb +5 -5
- data/lib/hrr_rb_ssh/authentication/method.rb +6 -12
- data/lib/hrr_rb_ssh/authentication.rb +1 -1
- 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/env.rb +2 -3
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/exec/context.rb +2 -2
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/exec.rb +2 -3
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/pty_req/context.rb +2 -2
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/pty_req.rb +2 -3
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/shell/context.rb +2 -2
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/shell.rb +2 -3
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/subsystem/context.rb +2 -2
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/subsystem.rb +2 -3
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type.rb +16 -11
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session.rb +1 -15
- data/lib/hrr_rb_ssh/connection/channel/channel_type.rb +15 -10
- data/lib/hrr_rb_ssh/connection/channel.rb +1 -1
- data/lib/hrr_rb_ssh/data_type.rb +153 -0
- data/lib/hrr_rb_ssh/message/001_ssh_msg_disconnect.rb +6 -6
- data/lib/hrr_rb_ssh/message/002_ssh_msg_ignore.rb +4 -4
- data/lib/hrr_rb_ssh/message/003_ssh_msg_unimplemented.rb +4 -4
- data/lib/hrr_rb_ssh/message/004_ssh_msg_debug.rb +6 -6
- data/lib/hrr_rb_ssh/message/005_ssh_msg_service_request.rb +4 -4
- data/lib/hrr_rb_ssh/message/006_ssh_msg_service_accept.rb +4 -4
- data/lib/hrr_rb_ssh/message/020_ssh_msg_kexinit.rb +31 -31
- data/lib/hrr_rb_ssh/message/021_ssh_msg_newkeys.rb +3 -3
- data/lib/hrr_rb_ssh/message/030_ssh_msg_kexdh_init.rb +4 -4
- data/lib/hrr_rb_ssh/message/031_ssh_msg_kexdh_reply.rb +6 -6
- data/lib/hrr_rb_ssh/message/050_ssh_msg_userauth_request.rb +18 -18
- data/lib/hrr_rb_ssh/message/051_ssh_msg_userauth_failure.rb +5 -5
- data/lib/hrr_rb_ssh/message/052_ssh_msg_userauth_success.rb +3 -3
- data/lib/hrr_rb_ssh/message/060_ssh_msg_userauth_pk_ok.rb +5 -5
- data/lib/hrr_rb_ssh/message/080_ssh_msg_global_request.rb +13 -13
- data/lib/hrr_rb_ssh/message/081_ssh_msg_request_success.rb +6 -6
- data/lib/hrr_rb_ssh/message/082_ssh_msg_request_failure.rb +3 -3
- data/lib/hrr_rb_ssh/message/090_ssh_msg_channel_open.rb +25 -25
- data/lib/hrr_rb_ssh/message/091_ssh_msg_channel_open_confirmation.rb +25 -25
- data/lib/hrr_rb_ssh/message/092_ssh_msg_channel_open_failure.rb +7 -7
- data/lib/hrr_rb_ssh/message/093_ssh_msg_channel_window_adjust.rb +5 -5
- data/lib/hrr_rb_ssh/message/094_ssh_msg_channel_data.rb +5 -5
- data/lib/hrr_rb_ssh/message/095_ssh_msg_channel_extended_data.rb +6 -6
- data/lib/hrr_rb_ssh/message/096_ssh_msg_channel_eof.rb +4 -4
- data/lib/hrr_rb_ssh/message/097_ssh_msg_channel_close.rb +4 -4
- data/lib/hrr_rb_ssh/message/098_ssh_msg_channel_request.rb +53 -53
- data/lib/hrr_rb_ssh/message/099_ssh_msg_channel_success.rb +4 -4
- data/lib/hrr_rb_ssh/message/100_ssh_msg_channel_failure.rb +4 -4
- data/lib/hrr_rb_ssh/message/codable.rb +2 -3
- data/lib/hrr_rb_ssh/subclass_with_preference_listable.rb +29 -0
- data/lib/hrr_rb_ssh/transport/compression_algorithm/functionable.rb +4 -4
- data/lib/hrr_rb_ssh/transport/compression_algorithm/none.rb +1 -6
- data/lib/hrr_rb_ssh/transport/compression_algorithm/unfunctionable.rb +4 -0
- data/lib/hrr_rb_ssh/transport/compression_algorithm/zlib.rb +1 -6
- data/lib/hrr_rb_ssh/transport/compression_algorithm.rb +5 -11
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes128_cbc.rb +1 -2
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes128_ctr.rb +1 -2
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes192_cbc.rb +1 -2
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes192_ctr.rb +1 -2
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes256_cbc.rb +1 -2
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes256_ctr.rb +1 -2
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/arcfour.rb +1 -2
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/blowfish_cbc.rb +1 -2
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/cast128_cbc.rb +1 -2
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb +1 -2
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/none.rb +1 -6
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/three_des_cbc.rb +1 -2
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/unfunctionable.rb +6 -0
- data/lib/hrr_rb_ssh/transport/encryption_algorithm.rb +5 -11
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman.rb +14 -14
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group14_sha1.rb +2 -5
- data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group1_sha1.rb +2 -5
- data/lib/hrr_rb_ssh/transport/kex_algorithm.rb +5 -10
- data/lib/hrr_rb_ssh/transport/mac_algorithm/functionable.rb +2 -3
- data/lib/hrr_rb_ssh/transport/mac_algorithm/hmac_md5.rb +3 -5
- data/lib/hrr_rb_ssh/transport/mac_algorithm/hmac_md5_96.rb +3 -5
- data/lib/hrr_rb_ssh/transport/mac_algorithm/hmac_sha1.rb +3 -5
- data/lib/hrr_rb_ssh/transport/mac_algorithm/hmac_sha1_96.rb +3 -5
- data/lib/hrr_rb_ssh/transport/mac_algorithm/none.rb +2 -8
- data/lib/hrr_rb_ssh/transport/mac_algorithm/unfunctionable.rb +4 -0
- data/lib/hrr_rb_ssh/transport/mac_algorithm.rb +5 -11
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_dss.rb +14 -13
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_rsa.rb +12 -11
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm.rb +5 -10
- data/lib/hrr_rb_ssh/transport.rb +147 -108
- data/lib/hrr_rb_ssh/version.rb +1 -1
- metadata +4 -12
- data/lib/hrr_rb_ssh/authentication/method/method.rb +0 -34
- data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/algorithm.rb +0 -41
- data/lib/hrr_rb_ssh/connection/channel/channel_type/channel_type.rb +0 -30
- data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/request_type.rb +0 -34
- data/lib/hrr_rb_ssh/transport/compression_algorithm/compression_algorithm.rb +0 -34
- data/lib/hrr_rb_ssh/transport/data_type.rb +0 -163
- data/lib/hrr_rb_ssh/transport/encryption_algorithm/encryption_algorithm.rb +0 -34
- data/lib/hrr_rb_ssh/transport/kex_algorithm/kex_algorithm.rb +0 -34
- data/lib/hrr_rb_ssh/transport/mac_algorithm/mac_algorithm.rb +0 -34
- data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/server_host_key_algorithm.rb +0 -34
@@ -1,8 +1,8 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
# vim: et ts=2 sw=2
|
3
3
|
|
4
|
-
require 'hrr_rb_ssh/
|
5
|
-
require 'hrr_rb_ssh/
|
4
|
+
require 'hrr_rb_ssh/logger'
|
5
|
+
require 'hrr_rb_ssh/data_type'
|
6
6
|
|
7
7
|
module HrrRbSsh
|
8
8
|
class Transport
|
@@ -10,6 +10,8 @@ module HrrRbSsh
|
|
10
10
|
class SshDss < ServerHostKeyAlgorithm
|
11
11
|
NAME = 'ssh-dss'
|
12
12
|
|
13
|
+
PREFERENCE = 10
|
14
|
+
|
13
15
|
SECRET_KEY = <<-EOB
|
14
16
|
-----BEGIN DSA PRIVATE KEY-----
|
15
17
|
MIIBuwIBAAKBgQD3fQ6cwTtOJpVI0iASOQZxkhwPRNy7UwovQkEK6bXW33HaCebO
|
@@ -26,28 +28,27 @@ MRl/p42OrQzL/chRPvRf
|
|
26
28
|
EOB
|
27
29
|
|
28
30
|
KEY_FORMAT_DEFINITION = [
|
29
|
-
[
|
30
|
-
[
|
31
|
-
[
|
32
|
-
[
|
33
|
-
[
|
31
|
+
[DataType::String, 'ssh-dss'],
|
32
|
+
[DataType::Mpint, 'p'],
|
33
|
+
[DataType::Mpint, 'q'],
|
34
|
+
[DataType::Mpint, 'g'],
|
35
|
+
[DataType::Mpint, 'y'],
|
34
36
|
]
|
35
37
|
|
36
38
|
SIGN_DEFINITION = [
|
37
|
-
[
|
38
|
-
[
|
39
|
+
[DataType::String, 'ssh-dss'],
|
40
|
+
[DataType::String, 'dss_signature_blob'],
|
39
41
|
]
|
40
42
|
|
41
43
|
def initialize
|
42
|
-
|
43
|
-
|
44
|
+
@logger = HrrRbSsh::Logger.new(self.class.name)
|
44
45
|
@dss = OpenSSL::PKey::DSA.new SECRET_KEY
|
45
46
|
end
|
46
47
|
|
47
48
|
def encode definition, payload
|
48
49
|
definition.map{ |data_type, field_name|
|
49
50
|
field_value = if payload[field_name].instance_of? ::Proc then payload[field_name].call else payload[field_name] end
|
50
|
-
|
51
|
+
data_type.encode( field_value )
|
51
52
|
}.join
|
52
53
|
end
|
53
54
|
|
@@ -56,7 +57,7 @@ MRl/p42OrQzL/chRPvRf
|
|
56
57
|
definition.map{ |data_type, field_name|
|
57
58
|
[
|
58
59
|
field_name,
|
59
|
-
|
60
|
+
data_type.decode( payload_io )
|
60
61
|
]
|
61
62
|
}.to_h
|
62
63
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
# vim: et ts=2 sw=2
|
3
3
|
|
4
|
-
require 'hrr_rb_ssh/
|
5
|
-
require 'hrr_rb_ssh/
|
4
|
+
require 'hrr_rb_ssh/logger'
|
5
|
+
require 'hrr_rb_ssh/data_type'
|
6
6
|
|
7
7
|
module HrrRbSsh
|
8
8
|
class Transport
|
@@ -10,6 +10,8 @@ module HrrRbSsh
|
|
10
10
|
class SshRsa < ServerHostKeyAlgorithm
|
11
11
|
NAME = 'ssh-rsa'
|
12
12
|
|
13
|
+
PREFERENCE = 20
|
14
|
+
|
13
15
|
SECRET_KEY = <<-EOB
|
14
16
|
-----BEGIN RSA PRIVATE KEY-----
|
15
17
|
MIIEpAIBAAKCAQEA71zHt9RvbXmxuOCWPKR65iBHO+a8M7Mfo4vRCs/dorZN7XL1
|
@@ -41,26 +43,25 @@ vzTNM3SFzgt3bHkdEtDLc64aoBX+dHOot6u71XLZrshnHPtiZ0C/ZA==
|
|
41
43
|
EOB
|
42
44
|
|
43
45
|
KEY_FORMAT_DEFINITION = [
|
44
|
-
[
|
45
|
-
[
|
46
|
-
[
|
46
|
+
[DataType::String, 'ssh-rsa'],
|
47
|
+
[DataType::Mpint, 'e'],
|
48
|
+
[DataType::Mpint, 'n'],
|
47
49
|
]
|
48
50
|
|
49
51
|
SIGN_DEFINITION = [
|
50
|
-
[
|
51
|
-
[
|
52
|
+
[DataType::String, 'ssh-rsa'],
|
53
|
+
[DataType::String, 'rsa_signature_blob'],
|
52
54
|
]
|
53
55
|
|
54
56
|
def initialize
|
55
|
-
|
56
|
-
|
57
|
+
@logger = HrrRbSsh::Logger.new(self.class.name)
|
57
58
|
@rsa = OpenSSL::PKey::RSA.new SECRET_KEY
|
58
59
|
end
|
59
60
|
|
60
61
|
def encode definition, payload
|
61
62
|
definition.map{ |data_type, field_name|
|
62
63
|
field_value = if payload[field_name].instance_of? ::Proc then payload[field_name].call else payload[field_name] end
|
63
|
-
|
64
|
+
data_type.encode( field_value )
|
64
65
|
}.join
|
65
66
|
end
|
66
67
|
|
@@ -69,7 +70,7 @@ vzTNM3SFzgt3bHkdEtDLc64aoBX+dHOot6u71XLZrshnHPtiZ0C/ZA==
|
|
69
70
|
definition.map{ |data_type, field_name|
|
70
71
|
[
|
71
72
|
field_name,
|
72
|
-
|
73
|
+
data_type.decode( payload_io )
|
73
74
|
]
|
74
75
|
}.to_h
|
75
76
|
end
|
@@ -1,19 +1,14 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
# vim: et ts=2 sw=2
|
3
3
|
|
4
|
+
require 'hrr_rb_ssh/subclass_with_preference_listable'
|
5
|
+
|
4
6
|
module HrrRbSsh
|
5
7
|
class Transport
|
6
8
|
class ServerHostKeyAlgorithm
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def self.name_list
|
12
|
-
ServerHostKeyAlgorithm.name_list
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.[] key
|
16
|
-
ServerHostKeyAlgorithm[key]
|
9
|
+
@subclass_list = Array.new
|
10
|
+
class << self
|
11
|
+
include SubclassWithPreferenceListable
|
17
12
|
end
|
18
13
|
end
|
19
14
|
end
|
data/lib/hrr_rb_ssh/transport.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
# vim: et ts=2 sw=2
|
3
3
|
|
4
|
+
require 'monitor'
|
4
5
|
require 'hrr_rb_ssh/version'
|
5
6
|
require 'hrr_rb_ssh/logger'
|
7
|
+
require 'hrr_rb_ssh/data_type'
|
6
8
|
require 'hrr_rb_ssh/message'
|
7
9
|
require 'hrr_rb_ssh/closed_transport_error'
|
8
10
|
require 'hrr_rb_ssh/transport/constant'
|
9
11
|
require 'hrr_rb_ssh/transport/mode'
|
10
12
|
require 'hrr_rb_ssh/transport/direction'
|
11
|
-
require 'hrr_rb_ssh/transport/data_type'
|
12
13
|
require 'hrr_rb_ssh/transport/sequence_number'
|
13
14
|
require 'hrr_rb_ssh/transport/sender'
|
14
15
|
require 'hrr_rb_ssh/transport/receiver'
|
@@ -24,6 +25,16 @@ module HrrRbSsh
|
|
24
25
|
|
25
26
|
attr_reader \
|
26
27
|
:io,
|
28
|
+
:supported_encryption_algorithms,
|
29
|
+
:supported_server_host_key_algorithms,
|
30
|
+
:supported_kex_algorithms,
|
31
|
+
:supported_mac_algorithms,
|
32
|
+
:supported_compression_algorithms,
|
33
|
+
:preferred_encryption_algorithms,
|
34
|
+
:preferred_server_host_key_algorithms,
|
35
|
+
:preferred_kex_algorithms,
|
36
|
+
:preferred_mac_algorithms,
|
37
|
+
:preferred_compression_algorithms,
|
27
38
|
:incoming_sequence_number,
|
28
39
|
:outgoing_sequence_number,
|
29
40
|
:server_host_key_algorithm,
|
@@ -39,7 +50,7 @@ module HrrRbSsh
|
|
39
50
|
:i_s,
|
40
51
|
:session_id
|
41
52
|
|
42
|
-
def initialize io, mode
|
53
|
+
def initialize io, mode, options={}
|
43
54
|
@io = io
|
44
55
|
@mode = mode
|
45
56
|
|
@@ -48,14 +59,13 @@ module HrrRbSsh
|
|
48
59
|
@closed = nil
|
49
60
|
@disconnected = nil
|
50
61
|
|
62
|
+
@in_kex = false
|
63
|
+
|
51
64
|
@sender = HrrRbSsh::Transport::Sender.new
|
52
65
|
@receiver = HrrRbSsh::Transport::Receiver.new
|
53
66
|
|
54
|
-
@
|
55
|
-
@
|
56
|
-
|
57
|
-
@sender_thread = nil
|
58
|
-
@receiver_thread = nil
|
67
|
+
@sender_monitor = Monitor.new
|
68
|
+
@receiver_monitor = Monitor.new
|
59
69
|
|
60
70
|
@local_version = "SSH-2.0-HrrRbSsh-#{HrrRbSsh::VERSION}".force_encoding(Encoding::ASCII_8BIT)
|
61
71
|
@remote_version = "".force_encoding(Encoding::ASCII_8BIT)
|
@@ -65,6 +75,8 @@ module HrrRbSsh
|
|
65
75
|
|
66
76
|
@acceptable_services = Array.new
|
67
77
|
|
78
|
+
update_supported_algorithms
|
79
|
+
update_preferred_algorithms options
|
68
80
|
initialize_local_algorithms
|
69
81
|
initialize_algorithms
|
70
82
|
end
|
@@ -74,19 +86,75 @@ module HrrRbSsh
|
|
74
86
|
end
|
75
87
|
|
76
88
|
def send payload
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
89
|
+
@sender_monitor.synchronize do
|
90
|
+
begin
|
91
|
+
@sender.send self, payload
|
92
|
+
rescue Errno::EPIPE => e
|
93
|
+
@logger.warn("IO is Broken PIPE")
|
94
|
+
close
|
95
|
+
raise HrrRbSsh::ClosedTransportError
|
96
|
+
rescue => e
|
97
|
+
@logger.error([e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join)
|
98
|
+
close
|
99
|
+
raise HrrRbSsh::ClosedTransportError
|
100
|
+
end
|
81
101
|
end
|
82
102
|
end
|
83
103
|
|
84
104
|
def receive
|
85
|
-
|
86
|
-
|
87
|
-
|
105
|
+
raise ClosedTransportError if @closed
|
106
|
+
@receiver_monitor.synchronize do
|
107
|
+
begin
|
108
|
+
payload = @receiver.receive self
|
109
|
+
case payload[0,1].unpack("C")[0]
|
110
|
+
when HrrRbSsh::Message::SSH_MSG_DISCONNECT::VALUE
|
111
|
+
message = HrrRbSsh::Message::SSH_MSG_DISCONNECT.decode payload
|
112
|
+
@logger.debug("received disconnect message: #{message.inspect}")
|
113
|
+
@disconnected = true
|
114
|
+
close
|
115
|
+
raise ClosedTransportError
|
116
|
+
when HrrRbSsh::Message::SSH_MSG_IGNORE::VALUE
|
117
|
+
message = HrrRbSsh::Message::SSH_MSG_IGNORE.decode payload
|
118
|
+
@logger.debug("received ignore message: #{message.inspect}")
|
119
|
+
receive
|
120
|
+
when HrrRbSsh::Message::SSH_MSG_UNIMPLEMENTED::VALUE
|
121
|
+
message = HrrRbSsh::Message::SSH_MSG_UNIMPLEMENTED.decode payload
|
122
|
+
@logger.debug("received unimplemented message: #{message.inspect}")
|
123
|
+
receive
|
124
|
+
when HrrRbSsh::Message::SSH_MSG_DEBUG::VALUE
|
125
|
+
message = HrrRbSsh::Message::SSH_MSG_DEBUG.decode payload
|
126
|
+
@logger.debug("received debug message: #{message.inspect}")
|
127
|
+
receive
|
128
|
+
when HrrRbSsh::Message::SSH_MSG_KEXINIT::VALUE
|
129
|
+
@logger.debug("received kexinit message")
|
130
|
+
if @in_kex
|
131
|
+
payload
|
132
|
+
else
|
133
|
+
exchange_key payload
|
134
|
+
receive
|
135
|
+
end
|
136
|
+
else
|
137
|
+
payload
|
138
|
+
end
|
139
|
+
rescue ClosedTransportError
|
140
|
+
raise ClosedTransportError
|
141
|
+
rescue EOFError => e
|
142
|
+
close
|
143
|
+
raise ClosedTransportError
|
144
|
+
rescue IOError => e
|
145
|
+
@logger.warn("IO is closed")
|
146
|
+
close
|
147
|
+
raise ClosedTransportError
|
148
|
+
rescue Errno::ECONNRESET => e
|
149
|
+
@logger.warn("IO is RESET")
|
150
|
+
close
|
151
|
+
raise ClosedTransportError
|
152
|
+
rescue => e
|
153
|
+
@logger.error([e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join)
|
154
|
+
close
|
155
|
+
raise ClosedTransportError
|
156
|
+
end
|
88
157
|
end
|
89
|
-
payload
|
90
158
|
end
|
91
159
|
|
92
160
|
def start
|
@@ -108,9 +176,6 @@ module HrrRbSsh
|
|
108
176
|
@logger.error([e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join)
|
109
177
|
close
|
110
178
|
else
|
111
|
-
@sender_thread = sender_thread
|
112
|
-
@receiver_thread = receiver_thread
|
113
|
-
|
114
179
|
@logger.info("transport started")
|
115
180
|
end
|
116
181
|
end
|
@@ -119,8 +184,6 @@ module HrrRbSsh
|
|
119
184
|
return if @closed
|
120
185
|
@logger.info("close transport")
|
121
186
|
@closed = true
|
122
|
-
@send_queue.close
|
123
|
-
@receive_queue.close
|
124
187
|
disconnect
|
125
188
|
@logger.info("transport closed")
|
126
189
|
end
|
@@ -150,20 +213,29 @@ module HrrRbSsh
|
|
150
213
|
update_version_strings
|
151
214
|
end
|
152
215
|
|
153
|
-
def exchange_key
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
216
|
+
def exchange_key payload=nil
|
217
|
+
@in_kex = true
|
218
|
+
@sender_monitor.synchronize do
|
219
|
+
@receiver_monitor.synchronize do
|
220
|
+
send_kexinit
|
221
|
+
if payload
|
222
|
+
receive_kexinit payload
|
223
|
+
else
|
224
|
+
receive_kexinit receive
|
225
|
+
end
|
226
|
+
update_kex_and_server_host_key_algorithms
|
158
227
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
228
|
+
case @mode
|
229
|
+
when HrrRbSsh::Transport::Mode::SERVER
|
230
|
+
receive_kexdh_init receive
|
231
|
+
send_kexdh_reply
|
163
232
|
|
164
|
-
|
165
|
-
|
233
|
+
send_newkeys
|
234
|
+
receive_newkeys receive
|
235
|
+
end
|
236
|
+
end
|
166
237
|
end
|
238
|
+
@in_kex = false
|
167
239
|
end
|
168
240
|
|
169
241
|
def verify_service_request
|
@@ -176,74 +248,49 @@ module HrrRbSsh
|
|
176
248
|
end
|
177
249
|
end
|
178
250
|
|
179
|
-
def
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
if @send_queue.closed?
|
186
|
-
@logger.info("closing sender thread")
|
187
|
-
break
|
188
|
-
end
|
189
|
-
@sender.send self, payload
|
190
|
-
rescue => e
|
191
|
-
@logger.error([e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join)
|
192
|
-
close
|
193
|
-
end
|
194
|
-
end
|
195
|
-
@logger.info("sender thread closed")
|
196
|
-
}
|
251
|
+
def update_supported_algorithms
|
252
|
+
@supported_kex_algorithms = HrrRbSsh::Transport::KexAlgorithm.list_supported
|
253
|
+
@supported_server_host_key_algorithms = HrrRbSsh::Transport::ServerHostKeyAlgorithm.list_supported
|
254
|
+
@supported_encryption_algorithms = HrrRbSsh::Transport::EncryptionAlgorithm.list_supported
|
255
|
+
@supported_mac_algorithms = HrrRbSsh::Transport::MacAlgorithm.list_supported
|
256
|
+
@supported_compression_algorithms = HrrRbSsh::Transport::CompressionAlgorithm.list_supported
|
197
257
|
end
|
198
258
|
|
199
|
-
def
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
@logger.debug("received unimplemented message: #{message.inspect}")
|
221
|
-
when HrrRbSsh::Message::SSH_MSG_DEBUG::VALUE
|
222
|
-
message = HrrRbSsh::Message::SSH_MSG_DEBUG.decode payload
|
223
|
-
@logger.debug("received debug message: #{message.inspect}")
|
224
|
-
else
|
225
|
-
@receive_queue.enq payload
|
226
|
-
end
|
227
|
-
rescue EOFError => e
|
228
|
-
close
|
229
|
-
rescue => e
|
230
|
-
@logger.error([e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join)
|
231
|
-
close
|
259
|
+
def update_preferred_algorithms options
|
260
|
+
@preferred_kex_algorithms = options['transport_preferred_kex_algorithms'] || HrrRbSsh::Transport::KexAlgorithm.list_preferred
|
261
|
+
@preferred_server_host_key_algorithms = options['transport_preferred_server_host_key_algorithms'] || HrrRbSsh::Transport::ServerHostKeyAlgorithm.list_preferred
|
262
|
+
@preferred_encryption_algorithms = options['transport_preferred_encryption_algorithms'] || HrrRbSsh::Transport::EncryptionAlgorithm.list_preferred
|
263
|
+
@preferred_mac_algorithms = options['transport_preferred_mac_algorithms'] || HrrRbSsh::Transport::MacAlgorithm.list_preferred
|
264
|
+
@preferred_compression_algorithms = options['transport_preferred_compression_algorithms'] || HrrRbSsh::Transport::CompressionAlgorithm.list_preferred
|
265
|
+
|
266
|
+
check_if_preferred_algorithms_are_supported
|
267
|
+
end
|
268
|
+
|
269
|
+
def check_if_preferred_algorithms_are_supported
|
270
|
+
[
|
271
|
+
['kex', @preferred_kex_algorithms, @supported_kex_algorithms ],
|
272
|
+
['server host key', @preferred_server_host_key_algorithms, @supported_server_host_key_algorithms],
|
273
|
+
['encryption', @preferred_encryption_algorithms, @supported_encryption_algorithms ],
|
274
|
+
['mac', @preferred_mac_algorithms, @supported_mac_algorithms ],
|
275
|
+
['compression', @preferred_compression_algorithms, @supported_compression_algorithms ],
|
276
|
+
].each{ |algorithm_name, list_preferred, list_supported|
|
277
|
+
list_preferred.each{ |a|
|
278
|
+
unless list_supported.include? a
|
279
|
+
raise ArgumentError, "#{algorithm_name} algorithm #{a} is not supported"
|
232
280
|
end
|
233
|
-
|
234
|
-
@logger.info("receiver thread closed")
|
281
|
+
}
|
235
282
|
}
|
236
283
|
end
|
237
284
|
|
238
285
|
def initialize_local_algorithms
|
239
|
-
@local_kex_algorithms =
|
240
|
-
@local_server_host_key_algorithms =
|
241
|
-
@local_encryption_algorithms_client_to_server =
|
242
|
-
@local_encryption_algorithms_server_to_client =
|
243
|
-
@local_mac_algorithms_client_to_server =
|
244
|
-
@local_mac_algorithms_server_to_client =
|
245
|
-
@local_compression_algorithms_client_to_server =
|
246
|
-
@local_compression_algorithms_server_to_client =
|
286
|
+
@local_kex_algorithms = @preferred_kex_algorithms
|
287
|
+
@local_server_host_key_algorithms = @preferred_server_host_key_algorithms
|
288
|
+
@local_encryption_algorithms_client_to_server = @preferred_encryption_algorithms
|
289
|
+
@local_encryption_algorithms_server_to_client = @preferred_encryption_algorithms
|
290
|
+
@local_mac_algorithms_client_to_server = @preferred_mac_algorithms
|
291
|
+
@local_mac_algorithms_server_to_client = @preferred_mac_algorithms
|
292
|
+
@local_compression_algorithms_client_to_server = @preferred_compression_algorithms
|
293
|
+
@local_compression_algorithms_server_to_client = @preferred_compression_algorithms
|
247
294
|
end
|
248
295
|
|
249
296
|
def initialize_algorithms
|
@@ -294,7 +341,7 @@ module HrrRbSsh
|
|
294
341
|
"language tag" => ""
|
295
342
|
}
|
296
343
|
payload = HrrRbSsh::Message::SSH_MSG_DISCONNECT.encode message
|
297
|
-
|
344
|
+
send payload
|
298
345
|
end
|
299
346
|
|
300
347
|
def send_kexinit
|
@@ -315,7 +362,7 @@ module HrrRbSsh
|
|
315
362
|
'0 (reserved for future extension)' => 0,
|
316
363
|
}
|
317
364
|
payload = HrrRbSsh::Message::SSH_MSG_KEXINIT.encode message
|
318
|
-
|
365
|
+
send payload
|
319
366
|
|
320
367
|
case @mode
|
321
368
|
when HrrRbSsh::Transport::Mode::SERVER
|
@@ -325,27 +372,20 @@ module HrrRbSsh
|
|
325
372
|
end
|
326
373
|
end
|
327
374
|
|
328
|
-
def receive_kexinit
|
329
|
-
payload = @receiver.receive self
|
330
|
-
|
375
|
+
def receive_kexinit payload
|
331
376
|
case @mode
|
332
377
|
when HrrRbSsh::Transport::Mode::SERVER
|
333
378
|
@i_c = payload
|
334
379
|
when HrrRbSsh::Transport::Mode::CLIENT
|
335
380
|
@i_s = payload
|
336
381
|
end
|
337
|
-
|
338
382
|
message = HrrRbSsh::Message::SSH_MSG_KEXINIT.decode payload
|
339
|
-
|
340
383
|
update_remote_algorithms message
|
341
384
|
end
|
342
385
|
|
343
|
-
def receive_kexdh_init
|
344
|
-
payload = @receiver.receive self
|
386
|
+
def receive_kexdh_init payload
|
345
387
|
message = HrrRbSsh::Message::SSH_MSG_KEXDH_INIT.decode payload
|
346
|
-
|
347
388
|
@kex_algorithm.set_e message['e']
|
348
|
-
|
349
389
|
@session_id ||= @kex_algorithm.hash self
|
350
390
|
end
|
351
391
|
|
@@ -357,7 +397,7 @@ module HrrRbSsh
|
|
357
397
|
'signature of H' => @kex_algorithm.sign(self),
|
358
398
|
}
|
359
399
|
payload = HrrRbSsh::Message::SSH_MSG_KEXDH_REPLY.encode message
|
360
|
-
|
400
|
+
send payload
|
361
401
|
end
|
362
402
|
|
363
403
|
def send_newkeys
|
@@ -365,11 +405,10 @@ module HrrRbSsh
|
|
365
405
|
'message number' => HrrRbSsh::Message::SSH_MSG_NEWKEYS::VALUE,
|
366
406
|
}
|
367
407
|
payload = HrrRbSsh::Message::SSH_MSG_NEWKEYS.encode message
|
368
|
-
|
408
|
+
send payload
|
369
409
|
end
|
370
410
|
|
371
|
-
def receive_newkeys
|
372
|
-
payload = @receiver.receive self
|
411
|
+
def receive_newkeys payload
|
373
412
|
message = HrrRbSsh::Message::SSH_MSG_NEWKEYS.decode payload
|
374
413
|
|
375
414
|
update_encryption_mac_compression_algorithms
|
@@ -388,7 +427,7 @@ module HrrRbSsh
|
|
388
427
|
'service name' => service_name,
|
389
428
|
}
|
390
429
|
payload = HrrRbSsh::Message::SSH_MSG_SERVICE_ACCEPT.encode message
|
391
|
-
|
430
|
+
send payload
|
392
431
|
end
|
393
432
|
|
394
433
|
def update_remote_algorithms message
|
data/lib/hrr_rb_ssh/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hrr_rb_ssh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hirura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -88,14 +88,12 @@ files:
|
|
88
88
|
- lib/hrr_rb_ssh/authentication.rb
|
89
89
|
- lib/hrr_rb_ssh/authentication/authenticator.rb
|
90
90
|
- lib/hrr_rb_ssh/authentication/method.rb
|
91
|
-
- lib/hrr_rb_ssh/authentication/method/method.rb
|
92
91
|
- lib/hrr_rb_ssh/authentication/method/none.rb
|
93
92
|
- lib/hrr_rb_ssh/authentication/method/none/context.rb
|
94
93
|
- lib/hrr_rb_ssh/authentication/method/password.rb
|
95
94
|
- lib/hrr_rb_ssh/authentication/method/password/context.rb
|
96
95
|
- lib/hrr_rb_ssh/authentication/method/publickey.rb
|
97
96
|
- lib/hrr_rb_ssh/authentication/method/publickey/algorithm.rb
|
98
|
-
- lib/hrr_rb_ssh/authentication/method/publickey/algorithm/algorithm.rb
|
99
97
|
- lib/hrr_rb_ssh/authentication/method/publickey/algorithm/codable.rb
|
100
98
|
- lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_dss.rb
|
101
99
|
- lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_rsa.rb
|
@@ -107,7 +105,6 @@ files:
|
|
107
105
|
- lib/hrr_rb_ssh/connection.rb
|
108
106
|
- lib/hrr_rb_ssh/connection/channel.rb
|
109
107
|
- lib/hrr_rb_ssh/connection/channel/channel_type.rb
|
110
|
-
- lib/hrr_rb_ssh/connection/channel/channel_type/channel_type.rb
|
111
108
|
- lib/hrr_rb_ssh/connection/channel/channel_type/session.rb
|
112
109
|
- lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type.rb
|
113
110
|
- lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/env.rb
|
@@ -116,7 +113,6 @@ files:
|
|
116
113
|
- lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/exec/context.rb
|
117
114
|
- lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/pty_req.rb
|
118
115
|
- lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/pty_req/context.rb
|
119
|
-
- lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/request_type.rb
|
120
116
|
- lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/shell.rb
|
121
117
|
- lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/shell/context.rb
|
122
118
|
- lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/subsystem.rb
|
@@ -124,6 +120,7 @@ files:
|
|
124
120
|
- lib/hrr_rb_ssh/connection/channel/proc_chain.rb
|
125
121
|
- lib/hrr_rb_ssh/connection/channel/proc_chain/chain_context.rb
|
126
122
|
- lib/hrr_rb_ssh/connection/request_handler.rb
|
123
|
+
- lib/hrr_rb_ssh/data_type.rb
|
127
124
|
- lib/hrr_rb_ssh/logger.rb
|
128
125
|
- lib/hrr_rb_ssh/message.rb
|
129
126
|
- lib/hrr_rb_ssh/message/001_ssh_msg_disconnect.rb
|
@@ -155,15 +152,14 @@ files:
|
|
155
152
|
- lib/hrr_rb_ssh/message/099_ssh_msg_channel_success.rb
|
156
153
|
- lib/hrr_rb_ssh/message/100_ssh_msg_channel_failure.rb
|
157
154
|
- lib/hrr_rb_ssh/message/codable.rb
|
155
|
+
- lib/hrr_rb_ssh/subclass_with_preference_listable.rb
|
158
156
|
- lib/hrr_rb_ssh/transport.rb
|
159
157
|
- lib/hrr_rb_ssh/transport/compression_algorithm.rb
|
160
|
-
- lib/hrr_rb_ssh/transport/compression_algorithm/compression_algorithm.rb
|
161
158
|
- lib/hrr_rb_ssh/transport/compression_algorithm/functionable.rb
|
162
159
|
- lib/hrr_rb_ssh/transport/compression_algorithm/none.rb
|
163
160
|
- lib/hrr_rb_ssh/transport/compression_algorithm/unfunctionable.rb
|
164
161
|
- lib/hrr_rb_ssh/transport/compression_algorithm/zlib.rb
|
165
162
|
- lib/hrr_rb_ssh/transport/constant.rb
|
166
|
-
- lib/hrr_rb_ssh/transport/data_type.rb
|
167
163
|
- lib/hrr_rb_ssh/transport/direction.rb
|
168
164
|
- lib/hrr_rb_ssh/transport/encryption_algorithm.rb
|
169
165
|
- lib/hrr_rb_ssh/transport/encryption_algorithm/aes128_cbc.rb
|
@@ -175,7 +171,6 @@ files:
|
|
175
171
|
- lib/hrr_rb_ssh/transport/encryption_algorithm/arcfour.rb
|
176
172
|
- lib/hrr_rb_ssh/transport/encryption_algorithm/blowfish_cbc.rb
|
177
173
|
- lib/hrr_rb_ssh/transport/encryption_algorithm/cast128_cbc.rb
|
178
|
-
- lib/hrr_rb_ssh/transport/encryption_algorithm/encryption_algorithm.rb
|
179
174
|
- lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb
|
180
175
|
- lib/hrr_rb_ssh/transport/encryption_algorithm/none.rb
|
181
176
|
- lib/hrr_rb_ssh/transport/encryption_algorithm/three_des_cbc.rb
|
@@ -184,14 +179,12 @@ files:
|
|
184
179
|
- lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman.rb
|
185
180
|
- lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group14_sha1.rb
|
186
181
|
- lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group1_sha1.rb
|
187
|
-
- lib/hrr_rb_ssh/transport/kex_algorithm/kex_algorithm.rb
|
188
182
|
- lib/hrr_rb_ssh/transport/mac_algorithm.rb
|
189
183
|
- lib/hrr_rb_ssh/transport/mac_algorithm/functionable.rb
|
190
184
|
- lib/hrr_rb_ssh/transport/mac_algorithm/hmac_md5.rb
|
191
185
|
- lib/hrr_rb_ssh/transport/mac_algorithm/hmac_md5_96.rb
|
192
186
|
- lib/hrr_rb_ssh/transport/mac_algorithm/hmac_sha1.rb
|
193
187
|
- lib/hrr_rb_ssh/transport/mac_algorithm/hmac_sha1_96.rb
|
194
|
-
- lib/hrr_rb_ssh/transport/mac_algorithm/mac_algorithm.rb
|
195
188
|
- lib/hrr_rb_ssh/transport/mac_algorithm/none.rb
|
196
189
|
- lib/hrr_rb_ssh/transport/mac_algorithm/unfunctionable.rb
|
197
190
|
- lib/hrr_rb_ssh/transport/mode.rb
|
@@ -199,7 +192,6 @@ files:
|
|
199
192
|
- lib/hrr_rb_ssh/transport/sender.rb
|
200
193
|
- lib/hrr_rb_ssh/transport/sequence_number.rb
|
201
194
|
- lib/hrr_rb_ssh/transport/server_host_key_algorithm.rb
|
202
|
-
- lib/hrr_rb_ssh/transport/server_host_key_algorithm/server_host_key_algorithm.rb
|
203
195
|
- lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_dss.rb
|
204
196
|
- lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_rsa.rb
|
205
197
|
- lib/hrr_rb_ssh/version.rb
|