hrr_rb_ssh 0.1.2 → 0.1.3

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.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/demo/server.rb +13 -1
  3. data/lib/hrr_rb_ssh/authentication/method/none/context.rb +1 -1
  4. data/lib/hrr_rb_ssh/authentication/method/none.rb +4 -4
  5. data/lib/hrr_rb_ssh/authentication/method/password/context.rb +1 -1
  6. data/lib/hrr_rb_ssh/authentication/method/password.rb +4 -4
  7. data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/codable.rb +5 -5
  8. data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_dss.rb +29 -18
  9. data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_rsa.rb +27 -16
  10. data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm.rb +7 -13
  11. data/lib/hrr_rb_ssh/authentication/method/publickey/context.rb +1 -1
  12. data/lib/hrr_rb_ssh/authentication/method/publickey.rb +5 -5
  13. data/lib/hrr_rb_ssh/authentication/method.rb +6 -12
  14. data/lib/hrr_rb_ssh/authentication.rb +1 -1
  15. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/env/context.rb +2 -2
  16. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/env.rb +2 -3
  17. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/exec/context.rb +2 -2
  18. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/exec.rb +2 -3
  19. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/pty_req/context.rb +2 -2
  20. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/pty_req.rb +2 -3
  21. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/shell/context.rb +2 -2
  22. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/shell.rb +2 -3
  23. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/subsystem/context.rb +2 -2
  24. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/subsystem.rb +2 -3
  25. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type.rb +16 -11
  26. data/lib/hrr_rb_ssh/connection/channel/channel_type/session.rb +1 -15
  27. data/lib/hrr_rb_ssh/connection/channel/channel_type.rb +15 -10
  28. data/lib/hrr_rb_ssh/connection/channel.rb +1 -1
  29. data/lib/hrr_rb_ssh/data_type.rb +153 -0
  30. data/lib/hrr_rb_ssh/message/001_ssh_msg_disconnect.rb +6 -6
  31. data/lib/hrr_rb_ssh/message/002_ssh_msg_ignore.rb +4 -4
  32. data/lib/hrr_rb_ssh/message/003_ssh_msg_unimplemented.rb +4 -4
  33. data/lib/hrr_rb_ssh/message/004_ssh_msg_debug.rb +6 -6
  34. data/lib/hrr_rb_ssh/message/005_ssh_msg_service_request.rb +4 -4
  35. data/lib/hrr_rb_ssh/message/006_ssh_msg_service_accept.rb +4 -4
  36. data/lib/hrr_rb_ssh/message/020_ssh_msg_kexinit.rb +31 -31
  37. data/lib/hrr_rb_ssh/message/021_ssh_msg_newkeys.rb +3 -3
  38. data/lib/hrr_rb_ssh/message/030_ssh_msg_kexdh_init.rb +4 -4
  39. data/lib/hrr_rb_ssh/message/031_ssh_msg_kexdh_reply.rb +6 -6
  40. data/lib/hrr_rb_ssh/message/050_ssh_msg_userauth_request.rb +18 -18
  41. data/lib/hrr_rb_ssh/message/051_ssh_msg_userauth_failure.rb +5 -5
  42. data/lib/hrr_rb_ssh/message/052_ssh_msg_userauth_success.rb +3 -3
  43. data/lib/hrr_rb_ssh/message/060_ssh_msg_userauth_pk_ok.rb +5 -5
  44. data/lib/hrr_rb_ssh/message/080_ssh_msg_global_request.rb +13 -13
  45. data/lib/hrr_rb_ssh/message/081_ssh_msg_request_success.rb +6 -6
  46. data/lib/hrr_rb_ssh/message/082_ssh_msg_request_failure.rb +3 -3
  47. data/lib/hrr_rb_ssh/message/090_ssh_msg_channel_open.rb +25 -25
  48. data/lib/hrr_rb_ssh/message/091_ssh_msg_channel_open_confirmation.rb +25 -25
  49. data/lib/hrr_rb_ssh/message/092_ssh_msg_channel_open_failure.rb +7 -7
  50. data/lib/hrr_rb_ssh/message/093_ssh_msg_channel_window_adjust.rb +5 -5
  51. data/lib/hrr_rb_ssh/message/094_ssh_msg_channel_data.rb +5 -5
  52. data/lib/hrr_rb_ssh/message/095_ssh_msg_channel_extended_data.rb +6 -6
  53. data/lib/hrr_rb_ssh/message/096_ssh_msg_channel_eof.rb +4 -4
  54. data/lib/hrr_rb_ssh/message/097_ssh_msg_channel_close.rb +4 -4
  55. data/lib/hrr_rb_ssh/message/098_ssh_msg_channel_request.rb +53 -53
  56. data/lib/hrr_rb_ssh/message/099_ssh_msg_channel_success.rb +4 -4
  57. data/lib/hrr_rb_ssh/message/100_ssh_msg_channel_failure.rb +4 -4
  58. data/lib/hrr_rb_ssh/message/codable.rb +2 -3
  59. data/lib/hrr_rb_ssh/subclass_with_preference_listable.rb +29 -0
  60. data/lib/hrr_rb_ssh/transport/compression_algorithm/functionable.rb +4 -4
  61. data/lib/hrr_rb_ssh/transport/compression_algorithm/none.rb +1 -6
  62. data/lib/hrr_rb_ssh/transport/compression_algorithm/unfunctionable.rb +4 -0
  63. data/lib/hrr_rb_ssh/transport/compression_algorithm/zlib.rb +1 -6
  64. data/lib/hrr_rb_ssh/transport/compression_algorithm.rb +5 -11
  65. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes128_cbc.rb +1 -2
  66. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes128_ctr.rb +1 -2
  67. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes192_cbc.rb +1 -2
  68. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes192_ctr.rb +1 -2
  69. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes256_cbc.rb +1 -2
  70. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes256_ctr.rb +1 -2
  71. data/lib/hrr_rb_ssh/transport/encryption_algorithm/arcfour.rb +1 -2
  72. data/lib/hrr_rb_ssh/transport/encryption_algorithm/blowfish_cbc.rb +1 -2
  73. data/lib/hrr_rb_ssh/transport/encryption_algorithm/cast128_cbc.rb +1 -2
  74. data/lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb +1 -2
  75. data/lib/hrr_rb_ssh/transport/encryption_algorithm/none.rb +1 -6
  76. data/lib/hrr_rb_ssh/transport/encryption_algorithm/three_des_cbc.rb +1 -2
  77. data/lib/hrr_rb_ssh/transport/encryption_algorithm/unfunctionable.rb +6 -0
  78. data/lib/hrr_rb_ssh/transport/encryption_algorithm.rb +5 -11
  79. data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman.rb +14 -14
  80. data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group14_sha1.rb +2 -5
  81. data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group1_sha1.rb +2 -5
  82. data/lib/hrr_rb_ssh/transport/kex_algorithm.rb +5 -10
  83. data/lib/hrr_rb_ssh/transport/mac_algorithm/functionable.rb +2 -3
  84. data/lib/hrr_rb_ssh/transport/mac_algorithm/hmac_md5.rb +3 -5
  85. data/lib/hrr_rb_ssh/transport/mac_algorithm/hmac_md5_96.rb +3 -5
  86. data/lib/hrr_rb_ssh/transport/mac_algorithm/hmac_sha1.rb +3 -5
  87. data/lib/hrr_rb_ssh/transport/mac_algorithm/hmac_sha1_96.rb +3 -5
  88. data/lib/hrr_rb_ssh/transport/mac_algorithm/none.rb +2 -8
  89. data/lib/hrr_rb_ssh/transport/mac_algorithm/unfunctionable.rb +4 -0
  90. data/lib/hrr_rb_ssh/transport/mac_algorithm.rb +5 -11
  91. data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_dss.rb +14 -13
  92. data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_rsa.rb +12 -11
  93. data/lib/hrr_rb_ssh/transport/server_host_key_algorithm.rb +5 -10
  94. data/lib/hrr_rb_ssh/transport.rb +147 -108
  95. data/lib/hrr_rb_ssh/version.rb +1 -1
  96. metadata +4 -12
  97. data/lib/hrr_rb_ssh/authentication/method/method.rb +0 -34
  98. data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/algorithm.rb +0 -41
  99. data/lib/hrr_rb_ssh/connection/channel/channel_type/channel_type.rb +0 -30
  100. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/request_type.rb +0 -34
  101. data/lib/hrr_rb_ssh/transport/compression_algorithm/compression_algorithm.rb +0 -34
  102. data/lib/hrr_rb_ssh/transport/data_type.rb +0 -163
  103. data/lib/hrr_rb_ssh/transport/encryption_algorithm/encryption_algorithm.rb +0 -34
  104. data/lib/hrr_rb_ssh/transport/kex_algorithm/kex_algorithm.rb +0 -34
  105. data/lib/hrr_rb_ssh/transport/mac_algorithm/mac_algorithm.rb +0 -34
  106. data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/server_host_key_algorithm.rb +0 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a15e10f1895dfd1a8e0159fc18355de0128cc033bbe5f5ee49e483e2de7bc1e3
4
- data.tar.gz: 6e1cb80d55521f431dff77735cb843c37fdc440640ffd9ae958119fdd9eb96d3
3
+ metadata.gz: 5ca801bcbdd5c4d01bbdfdd2827f114771d5e8e2f5b709a66313c1d36a5154fb
4
+ data.tar.gz: 630ce9b5a4983a2f7aa72239504821c43f26c6527857bb0709c1daa60b431c4f
5
5
  SHA512:
6
- metadata.gz: b63d6c8658d97b862f81e9beed336d04768894fffe1339c86cd2f8f9c22310f5f1d1be1f7abc381a0a0a5bbb18fd9a343959355aa77d849c321041de954d3749
7
- data.tar.gz: db9de741c096e3024231760c25e3d0ed04fee0a7d3083f1ad71b1deecbe389c401576f37c31714052408bca4c6431861e40f7ccafc04be8b4277c096147ef32f
6
+ metadata.gz: d6db961156a157f29a616dfa75320c394baf86ad78e85fa7b9ec7676ea76d23f10ce1b71b6ecfbb3d181f913b6af86dd713e660f4fb9fa69e98b5b5465ec902f
7
+ data.tar.gz: 1efb26c747d9360359aa04c8d12a88ff83b95ab53d4d8d04262f368459c1b016f0e8f653f88042e5aeebdb0f436d430da5f5a3431b4f47c1c79b6be6033dc32a
data/demo/server.rb CHANGED
@@ -18,6 +18,12 @@ logger.level = Logger::INFO
18
18
  HrrRbSsh::Logger.initialize logger
19
19
 
20
20
 
21
+ tran_preferred_encryption_algorithms = %w(aes128-ctr aes192-ctr aes256-ctr aes128-cbc 3des-cbc blowfish-cbc cast128-cbc aes192-cbc aes256-cbc arcfour)
22
+ tran_preferred_server_host_key_algorithms = %w(ssh-rsa ssh-dss)
23
+ tran_preferred_kex_algorithms = %w(diffie-hellman-group14-sha1 diffie-hellman-group1-sha1)
24
+ tran_preferred_mac_algorithms = %w(hmac-sha1 hmac-md5 hmac-sha1-96 hmac-md5-96)
25
+ tran_preferred_compression_algorithms = %w(none zlib)
26
+
21
27
  auth_none = HrrRbSsh::Authentication::Authenticator.new { |context|
22
28
  false
23
29
  }
@@ -163,6 +169,12 @@ conn_exec = HrrRbSsh::Connection::RequestHandler.new { |context|
163
169
 
164
170
  options = {}
165
171
 
172
+ options['transport_preferred_encryption_algorithms'] = tran_preferred_encryption_algorithms
173
+ options['transport_preferred_server_host_key_algorithms'] = tran_preferred_server_host_key_algorithms
174
+ options['transport_preferred_kex_algorithms'] = tran_preferred_kex_algorithms
175
+ options['transport_preferred_mac_algorithms'] = tran_preferred_mac_algorithms
176
+ options['transport_preferred_compression_algorithms'] = tran_preferred_compression_algorithms
177
+
166
178
  options['authentication_none_authenticator'] = auth_none
167
179
  options['authentication_publickey_authenticator'] = auth_publickey
168
180
  options['authentication_password_authenticator'] = auth_password
@@ -176,7 +188,7 @@ options['connection_channel_request_exec'] = conn_exec
176
188
  server = TCPServer.new 10022
177
189
  while true
178
190
  t = Thread.new(server.accept) do |io|
179
- tran = HrrRbSsh::Transport.new io, HrrRbSsh::Transport::Mode::SERVER
191
+ tran = HrrRbSsh::Transport.new io, HrrRbSsh::Transport::Mode::SERVER, options
180
192
  auth = HrrRbSsh::Authentication.new tran, options
181
193
  conn = HrrRbSsh::Connection.new auth, options
182
194
  conn.start
@@ -5,7 +5,7 @@ require 'hrr_rb_ssh/logger'
5
5
 
6
6
  module HrrRbSsh
7
7
  class Authentication
8
- module Method
8
+ class Method
9
9
  class None
10
10
  class Context
11
11
  attr_reader :username
@@ -1,17 +1,17 @@
1
1
  # coding: utf-8
2
2
  # vim: et ts=2 sw=2
3
3
 
4
- require 'hrr_rb_ssh/authentication/method/method'
4
+ require 'hrr_rb_ssh/logger'
5
5
 
6
6
  module HrrRbSsh
7
7
  class Authentication
8
- module Method
8
+ class Method
9
9
  class None < Method
10
10
  NAME = 'none'
11
+ PREFERENCE = 0
11
12
 
12
13
  def initialize options
13
- super
14
-
14
+ @logger = HrrRbSsh::Logger.new(self.class.name)
15
15
  @authenticator = options.fetch( 'authentication_none_authenticator', Authenticator.new { false } )
16
16
  end
17
17
 
@@ -5,7 +5,7 @@ require 'hrr_rb_ssh/logger'
5
5
 
6
6
  module HrrRbSsh
7
7
  class Authentication
8
- module Method
8
+ class Method
9
9
  class Password
10
10
  class Context
11
11
  attr_reader :username, :password
@@ -1,17 +1,17 @@
1
1
  # coding: utf-8
2
2
  # vim: et ts=2 sw=2
3
3
 
4
- require 'hrr_rb_ssh/authentication/method/method'
4
+ require 'hrr_rb_ssh/logger'
5
5
 
6
6
  module HrrRbSsh
7
7
  class Authentication
8
- module Method
8
+ class Method
9
9
  class Password < Method
10
10
  NAME = 'password'
11
+ PREFERENCE = 10
11
12
 
12
13
  def initialize options
13
- super
14
-
14
+ @logger = HrrRbSsh::Logger.new(self.class.name)
15
15
  @authenticator = options.fetch( 'authentication_password_authenticator', Authenticator.new { false } )
16
16
  end
17
17
 
@@ -1,18 +1,18 @@
1
1
  # coding: utf-8
2
2
  # vim: et ts=2 sw=2
3
3
 
4
- require 'hrr_rb_ssh/transport/data_type'
4
+ require 'hrr_rb_ssh/data_type'
5
5
 
6
6
  module HrrRbSsh
7
7
  class Authentication
8
- module Method
8
+ class Method
9
9
  class Publickey
10
- module Algorithm
10
+ class Algorithm
11
11
  module Codable
12
12
  def encode definition, payload
13
13
  definition.map{ |data_type, field_name|
14
14
  field_value = if payload[field_name].instance_of? ::Proc then payload[field_name].call else payload[field_name] end
15
- HrrRbSsh::Transport::DataType[data_type].encode(field_value)
15
+ data_type.encode(field_value)
16
16
  }.join
17
17
  end
18
18
 
@@ -21,7 +21,7 @@ module HrrRbSsh
21
21
  definition.map{ |data_type, field_name|
22
22
  [
23
23
  field_name,
24
- HrrRbSsh::Transport::DataType[data_type].decode(payload_io)
24
+ data_type.decode(payload_io)
25
25
  ]
26
26
  }.to_h
27
27
  end
@@ -1,39 +1,50 @@
1
1
  # coding: utf-8
2
2
  # vim: et ts=2 sw=2
3
3
 
4
+ require 'hrr_rb_ssh/logger'
5
+ require 'hrr_rb_ssh/data_type'
6
+ require 'hrr_rb_ssh/authentication/method/publickey/algorithm/codable'
7
+
4
8
  module HrrRbSsh
5
9
  class Authentication
6
- module Method
10
+ class Method
7
11
  class Publickey
8
- module Algorithm
12
+ class Algorithm
9
13
  class SshDss < Algorithm
10
- NAME = 'ssh-dss'
14
+ NAME = 'ssh-dss'
15
+ PREFERENCE = 10
11
16
  DIGEST = 'sha1'
12
17
 
13
18
  PUBLIC_KEY_BLOB_DEFINITION = [
14
- ['string', 'public key algorithm name'],
15
- ['mpint', 'p'],
16
- ['mpint', 'q'],
17
- ['mpint', 'g'],
18
- ['mpint', 'y'],
19
+ [DataType::String, 'public key algorithm name'],
20
+ [DataType::Mpint, 'p'],
21
+ [DataType::Mpint, 'q'],
22
+ [DataType::Mpint, 'g'],
23
+ [DataType::Mpint, 'y'],
19
24
  ]
20
25
 
21
26
  SIGNATURE_DEFINITION = [
22
- ['string', 'public key algorithm name'],
23
- ['string', 'signature blob'],
27
+ [DataType::String, 'public key algorithm name'],
28
+ [DataType::String, 'signature blob'],
24
29
  ]
25
30
 
26
31
  SIGNATURE_BLOB_DEFINITION = [
27
- ['string', 'session identifier'],
28
- ['byte', 'message number'],
29
- ['string', 'user name'],
30
- ['string', 'service name'],
31
- ['string', 'method name'],
32
- ['boolean', 'with signature'],
33
- ['string', 'public key algorithm name'],
34
- ['string', 'public key blob'],
32
+ [DataType::String, 'session identifier'],
33
+ [DataType::Byte, 'message number'],
34
+ [DataType::String, 'user name'],
35
+ [DataType::String, 'service name'],
36
+ [DataType::String, 'method name'],
37
+ [DataType::Boolean, 'with signature'],
38
+ [DataType::String, 'public key algorithm name'],
39
+ [DataType::String, 'public key blob'],
35
40
  ]
36
41
 
42
+ include Codable
43
+
44
+ def initialize
45
+ @logger = HrrRbSsh::Logger.new(self.class.name)
46
+ end
47
+
37
48
  def verify_public_key public_key_algorithm_name, public_key, public_key_blob
38
49
  public_key = case public_key
39
50
  when String
@@ -1,37 +1,48 @@
1
1
  # coding: utf-8
2
2
  # vim: et ts=2 sw=2
3
3
 
4
+ require 'hrr_rb_ssh/logger'
5
+ require 'hrr_rb_ssh/data_type'
6
+ require 'hrr_rb_ssh/authentication/method/publickey/algorithm/codable'
7
+
4
8
  module HrrRbSsh
5
9
  class Authentication
6
- module Method
10
+ class Method
7
11
  class Publickey
8
- module Algorithm
12
+ class Algorithm
9
13
  class SshRsa < Algorithm
10
- NAME = 'ssh-rsa'
14
+ NAME = 'ssh-rsa'
15
+ PREFERENCE = 20
11
16
  DIGEST = 'sha1'
12
17
 
13
18
  PUBLIC_KEY_BLOB_DEFINITION = [
14
- ['string', 'public key algorithm name'],
15
- ['mpint', 'e'],
16
- ['mpint', 'n'],
19
+ [DataType::String, 'public key algorithm name'],
20
+ [DataType::Mpint, 'e'],
21
+ [DataType::Mpint, 'n'],
17
22
  ]
18
23
 
19
24
  SIGNATURE_DEFINITION = [
20
- ['string', 'public key algorithm name'],
21
- ['string', 'signature blob'],
25
+ [DataType::String, 'public key algorithm name'],
26
+ [DataType::String, 'signature blob'],
22
27
  ]
23
28
 
24
29
  SIGNATURE_BLOB_DEFINITION = [
25
- ['string', 'session identifier'],
26
- ['byte', 'message number'],
27
- ['string', 'user name'],
28
- ['string', 'service name'],
29
- ['string', 'method name'],
30
- ['boolean', 'with signature'],
31
- ['string', 'public key algorithm name'],
32
- ['string', 'public key blob'],
30
+ [DataType::String, 'session identifier'],
31
+ [DataType::Byte, 'message number'],
32
+ [DataType::String, 'user name'],
33
+ [DataType::String, 'service name'],
34
+ [DataType::String, 'method name'],
35
+ [DataType::Boolean, 'with signature'],
36
+ [DataType::String, 'public key algorithm name'],
37
+ [DataType::String, 'public key blob'],
33
38
  ]
34
39
 
40
+ include Codable
41
+
42
+ def initialize
43
+ @logger = HrrRbSsh::Logger.new(self.class.name)
44
+ end
45
+
35
46
  def verify_public_key public_key_algorithm_name, public_key, public_key_blob
36
47
  public_key = case public_key
37
48
  when String
@@ -1,21 +1,16 @@
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 Authentication
6
- module Method
8
+ class Method
7
9
  class Publickey
8
- module Algorithm
9
- def self.list
10
- Algorithm.list
11
- end
12
-
13
- def self.name_list
14
- Algorithm.name_list
15
- end
16
-
17
- def self.[] key
18
- Algorithm[key]
10
+ class Algorithm
11
+ @subclass_list = Array.new
12
+ class << self
13
+ include SubclassWithPreferenceListable
19
14
  end
20
15
  end
21
16
  end
@@ -23,6 +18,5 @@ module HrrRbSsh
23
18
  end
24
19
  end
25
20
 
26
- require 'hrr_rb_ssh/authentication/method/publickey/algorithm/algorithm'
27
21
  require 'hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_dss'
28
22
  require 'hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_rsa'
@@ -5,7 +5,7 @@ require 'hrr_rb_ssh/logger'
5
5
 
6
6
  module HrrRbSsh
7
7
  class Authentication
8
- module Method
8
+ class Method
9
9
  class Publickey
10
10
  class Context
11
11
  attr_reader \
@@ -1,24 +1,24 @@
1
1
  # coding: utf-8
2
2
  # vim: et ts=2 sw=2
3
3
 
4
- require 'hrr_rb_ssh/authentication/method/method'
4
+ require 'hrr_rb_ssh/logger'
5
5
 
6
6
  module HrrRbSsh
7
7
  class Authentication
8
- module Method
8
+ class Method
9
9
  class Publickey < Method
10
10
  NAME = 'publickey'
11
+ PREFERENCE = 20
11
12
 
12
13
  def initialize options
13
- super
14
-
14
+ @logger = HrrRbSsh::Logger.new(self.class.name)
15
15
  @session_id = options['session id']
16
16
  @authenticator = options.fetch( 'authentication_publickey_authenticator', Authenticator.new { false } )
17
17
  end
18
18
 
19
19
  def authenticate userauth_request_message
20
20
  public_key_algorithm_name = userauth_request_message['public key algorithm name']
21
- unless Algorithm.name_list.include?(public_key_algorithm_name)
21
+ unless Algorithm.list_preferred.include?(public_key_algorithm_name)
22
22
  @logger.info("unsupported public key algorithm: #{public_key_algorithm_name}")
23
23
  return false
24
24
  end
@@ -1,25 +1,19 @@
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 Authentication
6
- module Method
7
- def self.list
8
- Method.list
9
- end
10
-
11
- def self.name_list
12
- Method.name_list
13
- end
14
-
15
- def self.[] key
16
- Method[key]
8
+ class Method
9
+ @subclass_list = Array.new
10
+ class << self
11
+ include SubclassWithPreferenceListable
17
12
  end
18
13
  end
19
14
  end
20
15
  end
21
16
 
22
- require 'hrr_rb_ssh/authentication/method/method'
23
17
  require 'hrr_rb_ssh/authentication/method/none'
24
18
  require 'hrr_rb_ssh/authentication/method/password'
25
19
  require 'hrr_rb_ssh/authentication/method/publickey'
@@ -95,7 +95,7 @@ module HrrRbSsh
95
95
  def send_userauth_failure
96
96
  message = {
97
97
  'message number' => HrrRbSsh::Message::SSH_MSG_USERAUTH_FAILURE::VALUE,
98
- 'authentications that can continue' => Method.name_list,
98
+ 'authentications that can continue' => Method.list_preferred,
99
99
  'partial success' => false,
100
100
  }
101
101
  payload = HrrRbSsh::Message::SSH_MSG_USERAUTH_FAILURE.encode message
@@ -6,9 +6,9 @@ require 'hrr_rb_ssh/logger'
6
6
  module HrrRbSsh
7
7
  class Connection
8
8
  class Channel
9
- module ChannelType
9
+ class ChannelType
10
10
  class Session
11
- module RequestType
11
+ class RequestType
12
12
  class Env
13
13
  class Context
14
14
  attr_reader \
@@ -3,14 +3,13 @@
3
3
 
4
4
  require 'hrr_rb_ssh/logger'
5
5
  require 'hrr_rb_ssh/connection/request_handler'
6
- require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/request_type'
7
6
 
8
7
  module HrrRbSsh
9
8
  class Connection
10
9
  class Channel
11
- module ChannelType
10
+ class ChannelType
12
11
  class Session
13
- module RequestType
12
+ class RequestType
14
13
  class Env < RequestType
15
14
  NAME = 'env'
16
15
 
@@ -6,9 +6,9 @@ require 'hrr_rb_ssh/logger'
6
6
  module HrrRbSsh
7
7
  class Connection
8
8
  class Channel
9
- module ChannelType
9
+ class ChannelType
10
10
  class Session
11
- module RequestType
11
+ class RequestType
12
12
  class Exec
13
13
  class Context
14
14
  attr_reader \
@@ -3,14 +3,13 @@
3
3
 
4
4
  require 'hrr_rb_ssh/logger'
5
5
  require 'hrr_rb_ssh/connection/request_handler'
6
- require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/request_type'
7
6
 
8
7
  module HrrRbSsh
9
8
  class Connection
10
9
  class Channel
11
- module ChannelType
10
+ class ChannelType
12
11
  class Session
13
- module RequestType
12
+ class RequestType
14
13
  class Exec < RequestType
15
14
  NAME = 'exec'
16
15
 
@@ -6,9 +6,9 @@ require 'hrr_rb_ssh/logger'
6
6
  module HrrRbSsh
7
7
  class Connection
8
8
  class Channel
9
- module ChannelType
9
+ class ChannelType
10
10
  class Session
11
- module RequestType
11
+ class RequestType
12
12
  class PtyReq
13
13
  class Context
14
14
  attr_reader \
@@ -3,14 +3,13 @@
3
3
 
4
4
  require 'hrr_rb_ssh/logger'
5
5
  require 'hrr_rb_ssh/connection/request_handler'
6
- require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/request_type'
7
6
 
8
7
  module HrrRbSsh
9
8
  class Connection
10
9
  class Channel
11
- module ChannelType
10
+ class ChannelType
12
11
  class Session
13
- module RequestType
12
+ class RequestType
14
13
  class PtyReq < RequestType
15
14
  NAME = 'pty-req'
16
15
 
@@ -6,9 +6,9 @@ require 'hrr_rb_ssh/logger'
6
6
  module HrrRbSsh
7
7
  class Connection
8
8
  class Channel
9
- module ChannelType
9
+ class ChannelType
10
10
  class Session
11
- module RequestType
11
+ class RequestType
12
12
  class Shell
13
13
  class Context
14
14
  attr_reader \
@@ -3,14 +3,13 @@
3
3
 
4
4
  require 'hrr_rb_ssh/logger'
5
5
  require 'hrr_rb_ssh/connection/request_handler'
6
- require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/request_type'
7
6
 
8
7
  module HrrRbSsh
9
8
  class Connection
10
9
  class Channel
11
- module ChannelType
10
+ class ChannelType
12
11
  class Session
13
- module RequestType
12
+ class RequestType
14
13
  class Shell < RequestType
15
14
  NAME = 'shell'
16
15
 
@@ -6,9 +6,9 @@ require 'hrr_rb_ssh/logger'
6
6
  module HrrRbSsh
7
7
  class Connection
8
8
  class Channel
9
- module ChannelType
9
+ class ChannelType
10
10
  class Session
11
- module RequestType
11
+ class RequestType
12
12
  class Subsystem
13
13
  class Context
14
14
  attr_reader \
@@ -3,14 +3,13 @@
3
3
 
4
4
  require 'hrr_rb_ssh/logger'
5
5
  require 'hrr_rb_ssh/connection/request_handler'
6
- require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/request_type'
7
6
 
8
7
  module HrrRbSsh
9
8
  class Connection
10
9
  class Channel
11
- module ChannelType
10
+ class ChannelType
12
11
  class Session
13
- module RequestType
12
+ class RequestType
14
13
  class Subsystem < RequestType
15
14
  NAME = 'subsystem'
16
15
 
@@ -4,19 +4,25 @@
4
4
  module HrrRbSsh
5
5
  class Connection
6
6
  class Channel
7
- module ChannelType
7
+ class ChannelType
8
8
  class Session
9
- module RequestType
10
- def self.list
11
- RequestType.list
12
- end
9
+ class RequestType
10
+ @subclass_list = Array.new
11
+ class << self
12
+ def inherited klass
13
+ @subclass_list.push klass if @subclass_list
14
+ end
13
15
 
14
- def self.name_list
15
- RequestType.name_list
16
- end
16
+ def [] key
17
+ __subclass_list__(__method__).find{ |klass| klass::NAME == key }
18
+ end
19
+
20
+ def __subclass_list__ method_name
21
+ send(:method_missing, method_name) unless @subclass_list
22
+ @subclass_list
23
+ end
17
24
 
18
- def self.[] key
19
- RequestType[key]
25
+ private :__subclass_list__
20
26
  end
21
27
  end
22
28
  end
@@ -25,7 +31,6 @@ module HrrRbSsh
25
31
  end
26
32
  end
27
33
 
28
- require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/request_type'
29
34
  require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/pty_req'
30
35
  require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/env'
31
36
  require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/shell'
@@ -1,26 +1,12 @@
1
1
  # coding: utf-8
2
2
  # vim: et ts=2 sw=2
3
3
 
4
- require 'hrr_rb_ssh/connection/channel/channel_type/channel_type'
5
-
6
4
  module HrrRbSsh
7
5
  class Connection
8
6
  class Channel
9
- module ChannelType
7
+ class ChannelType
10
8
  class Session < ChannelType
11
9
  NAME = 'session'
12
-
13
- def self.list
14
- RequestType.list
15
- end
16
-
17
- def self.name_list
18
- RequestType.name_list
19
- end
20
-
21
- def self.[] key
22
- RequestType[key]
23
- end
24
10
  end
25
11
  end
26
12
  end