hrr_rb_ssh 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/demo/server.rb +23 -3
  4. data/hrr_rb_ssh.gemspec +2 -2
  5. data/lib/hrr_rb_ssh/authentication/method/method.rb +34 -0
  6. data/lib/hrr_rb_ssh/authentication/method/none.rb +5 -14
  7. data/lib/hrr_rb_ssh/authentication/method/password.rb +6 -12
  8. data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/algorithm.rb +41 -0
  9. data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/codable.rb +33 -0
  10. data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_dss.rb +105 -0
  11. data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_rsa.rb +85 -0
  12. data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm.rb +28 -0
  13. data/lib/hrr_rb_ssh/authentication/method/publickey.rb +9 -25
  14. data/lib/hrr_rb_ssh/authentication/method.rb +12 -9
  15. data/lib/hrr_rb_ssh/connection/channel/channel_type/channel_type.rb +30 -0
  16. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/env/context.rb +46 -0
  17. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/env.rb +34 -0
  18. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/exec/context.rb +44 -0
  19. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/exec.rb +34 -0
  20. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/pty_req/context.rb +54 -0
  21. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/pty_req.rb +34 -0
  22. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/request_type.rb +34 -0
  23. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/shell/context.rb +41 -0
  24. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/shell.rb +34 -0
  25. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/subsystem/context.rb +44 -0
  26. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/subsystem.rb +34 -0
  27. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type.rb +33 -0
  28. data/lib/hrr_rb_ssh/connection/channel/channel_type/session.rb +30 -0
  29. data/lib/hrr_rb_ssh/connection/channel/channel_type.rb +25 -0
  30. data/lib/hrr_rb_ssh/connection/channel.rb +2 -12
  31. data/lib/hrr_rb_ssh/transport/compression_algorithm/compression_algorithm.rb +34 -0
  32. data/lib/hrr_rb_ssh/transport/compression_algorithm/functionable.rb +31 -0
  33. data/lib/hrr_rb_ssh/transport/compression_algorithm/none.rb +7 -19
  34. data/lib/hrr_rb_ssh/transport/compression_algorithm/unfunctionable.rb +20 -0
  35. data/lib/hrr_rb_ssh/transport/compression_algorithm/zlib.rb +7 -24
  36. data/lib/hrr_rb_ssh/transport/compression_algorithm.rb +11 -9
  37. data/lib/hrr_rb_ssh/transport/direction.rb +11 -0
  38. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes128_cbc.rb +19 -0
  39. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes128_ctr.rb +19 -0
  40. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes192_cbc.rb +19 -0
  41. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes192_ctr.rb +19 -0
  42. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes256_cbc.rb +19 -0
  43. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes256_ctr.rb +19 -0
  44. data/lib/hrr_rb_ssh/transport/encryption_algorithm/arcfour.rb +19 -0
  45. data/lib/hrr_rb_ssh/transport/encryption_algorithm/blowfish_cbc.rb +19 -0
  46. data/lib/hrr_rb_ssh/transport/encryption_algorithm/cast128_cbc.rb +19 -0
  47. data/lib/hrr_rb_ssh/transport/encryption_algorithm/encryption_algorithm.rb +34 -0
  48. data/lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb +61 -0
  49. data/lib/hrr_rb_ssh/transport/encryption_algorithm/none.rb +6 -33
  50. data/lib/hrr_rb_ssh/transport/encryption_algorithm/three_des_cbc.rb +19 -0
  51. data/lib/hrr_rb_ssh/transport/encryption_algorithm/unfunctionable.rb +35 -0
  52. data/lib/hrr_rb_ssh/transport/encryption_algorithm.rb +20 -9
  53. data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman.rb +3 -4
  54. data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group14_sha1.rb +4 -8
  55. data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group1_sha1.rb +4 -8
  56. data/lib/hrr_rb_ssh/transport/kex_algorithm/kex_algorithm.rb +34 -0
  57. data/lib/hrr_rb_ssh/transport/kex_algorithm.rb +10 -9
  58. data/lib/hrr_rb_ssh/transport/mac_algorithm/functionable.rb +32 -0
  59. data/lib/hrr_rb_ssh/transport/mac_algorithm/hmac_md5.rb +21 -0
  60. data/lib/hrr_rb_ssh/transport/mac_algorithm/hmac_md5_96.rb +21 -0
  61. data/lib/hrr_rb_ssh/transport/mac_algorithm/hmac_sha1.rb +5 -29
  62. data/lib/hrr_rb_ssh/transport/mac_algorithm/hmac_sha1_96.rb +21 -0
  63. data/lib/hrr_rb_ssh/transport/mac_algorithm/mac_algorithm.rb +34 -0
  64. data/lib/hrr_rb_ssh/transport/mac_algorithm/none.rb +6 -22
  65. data/lib/hrr_rb_ssh/transport/mac_algorithm/unfunctionable.rb +24 -0
  66. data/lib/hrr_rb_ssh/transport/mac_algorithm.rb +14 -9
  67. data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/server_host_key_algorithm.rb +34 -0
  68. data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_dss.rb +106 -0
  69. data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_rsa.rb +4 -11
  70. data/lib/hrr_rb_ssh/transport/server_host_key_algorithm.rb +10 -8
  71. data/lib/hrr_rb_ssh/transport.rb +23 -15
  72. data/lib/hrr_rb_ssh/version.rb +1 -1
  73. metadata +51 -17
  74. data/lib/hrr_rb_ssh/authentication/method/publickey/ssh_rsa.rb +0 -116
  75. data/lib/hrr_rb_ssh/connection/channel/session/env/context.rb +0 -43
  76. data/lib/hrr_rb_ssh/connection/channel/session/env.rb +0 -31
  77. data/lib/hrr_rb_ssh/connection/channel/session/exec/context.rb +0 -41
  78. data/lib/hrr_rb_ssh/connection/channel/session/exec.rb +0 -31
  79. data/lib/hrr_rb_ssh/connection/channel/session/pty_req/context.rb +0 -50
  80. data/lib/hrr_rb_ssh/connection/channel/session/pty_req.rb +0 -31
  81. data/lib/hrr_rb_ssh/connection/channel/session/shell/context.rb +0 -37
  82. data/lib/hrr_rb_ssh/connection/channel/session/shell.rb +0 -31
  83. data/lib/hrr_rb_ssh/connection/channel/session/subsystem/context.rb +0 -40
  84. data/lib/hrr_rb_ssh/connection/channel/session/subsystem.rb +0 -31
  85. data/lib/hrr_rb_ssh/connection/channel/session.rb +0 -31
  86. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes_128_cbc.rb +0 -73
@@ -1,37 +1,20 @@
1
1
  # coding: utf-8
2
2
  # vim: et ts=2 sw=2
3
3
 
4
- require 'zlib'
5
-
6
- require 'hrr_rb_ssh/logger'
4
+ require 'hrr_rb_ssh/transport/compression_algorithm/compression_algorithm'
5
+ require 'hrr_rb_ssh/transport/compression_algorithm/functionable'
7
6
 
8
7
  module HrrRbSsh
9
8
  class Transport
10
9
  class CompressionAlgorithm
11
- name_list = [
12
- 'zlib'
13
- ]
14
-
15
- class Zlib
16
- def initialize
17
- @logger = HrrRbSsh::Logger.new self.class.name
18
-
19
- @deflator = ::Zlib::Deflate.new
20
- @inflator = ::Zlib::Inflate.new
21
- end
10
+ class Zlib < CompressionAlgorithm
11
+ NAME = 'zlib'
22
12
 
23
- def deflate data
24
- @deflator.deflate(data, ::Zlib::SYNC_FLUSH)
13
+ def initialize direction
14
+ super
25
15
  end
26
16
 
27
- def inflate data
28
- @inflator.inflate(data)
29
- end
30
- end
31
-
32
- @@list ||= Hash.new
33
- name_list.each do |name|
34
- @@list[name] = Zlib
17
+ include Functionable
35
18
  end
36
19
  end
37
20
  end
@@ -1,22 +1,24 @@
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/transport/compression_algorithm/none'
6
- require 'hrr_rb_ssh/transport/compression_algorithm/zlib'
7
-
8
4
  module HrrRbSsh
9
5
  class Transport
10
6
  class CompressionAlgorithm
11
- @@list ||= Hash.new
12
-
13
- def self.[] key
14
- @@list[key]
7
+ def self.list
8
+ CompressionAlgorithm.list
15
9
  end
16
10
 
17
11
  def self.name_list
18
- @@list.keys
12
+ CompressionAlgorithm.name_list
13
+ end
14
+
15
+ def self.[] key
16
+ CompressionAlgorithm[key]
19
17
  end
20
18
  end
21
19
  end
22
20
  end
21
+
22
+ require 'hrr_rb_ssh/transport/compression_algorithm/compression_algorithm'
23
+ require 'hrr_rb_ssh/transport/compression_algorithm/none'
24
+ require 'hrr_rb_ssh/transport/compression_algorithm/zlib'
@@ -0,0 +1,11 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ module HrrRbSsh
5
+ class Transport
6
+ module Direction
7
+ OUTGOING = :outgoing
8
+ INCOMING = :incoming
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/transport/encryption_algorithm/encryption_algorithm'
5
+ require 'hrr_rb_ssh/transport/encryption_algorithm/functionable'
6
+
7
+ module HrrRbSsh
8
+ class Transport
9
+ class EncryptionAlgorithm
10
+ class Aes128Cbc < EncryptionAlgorithm
11
+ NAME = 'aes128-cbc'
12
+ CIPHER_NAME = "AES-128-CBC"
13
+ BLOCK_SIZE = 16
14
+
15
+ include Functionable
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/transport/encryption_algorithm/encryption_algorithm'
5
+ require 'hrr_rb_ssh/transport/encryption_algorithm/functionable'
6
+
7
+ module HrrRbSsh
8
+ class Transport
9
+ class EncryptionAlgorithm
10
+ class Aes128Ctr < EncryptionAlgorithm
11
+ NAME = 'aes128-ctr'
12
+ CIPHER_NAME = "AES-128-CTR"
13
+ BLOCK_SIZE = 16
14
+
15
+ include Functionable
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/transport/encryption_algorithm/encryption_algorithm'
5
+ require 'hrr_rb_ssh/transport/encryption_algorithm/functionable'
6
+
7
+ module HrrRbSsh
8
+ class Transport
9
+ class EncryptionAlgorithm
10
+ class Aes192Cbc < EncryptionAlgorithm
11
+ NAME = 'aes192-cbc'
12
+ CIPHER_NAME = "AES-192-CBC"
13
+ BLOCK_SIZE = 16
14
+
15
+ include Functionable
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/transport/encryption_algorithm/encryption_algorithm'
5
+ require 'hrr_rb_ssh/transport/encryption_algorithm/functionable'
6
+
7
+ module HrrRbSsh
8
+ class Transport
9
+ class EncryptionAlgorithm
10
+ class Aes192Ctr < EncryptionAlgorithm
11
+ NAME = 'aes192-ctr'
12
+ CIPHER_NAME = "AES-192-CTR"
13
+ BLOCK_SIZE = 16
14
+
15
+ include Functionable
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/transport/encryption_algorithm/encryption_algorithm'
5
+ require 'hrr_rb_ssh/transport/encryption_algorithm/functionable'
6
+
7
+ module HrrRbSsh
8
+ class Transport
9
+ class EncryptionAlgorithm
10
+ class Aes256Cbc < EncryptionAlgorithm
11
+ NAME = 'aes256-cbc'
12
+ CIPHER_NAME = "AES-256-CBC"
13
+ BLOCK_SIZE = 16
14
+
15
+ include Functionable
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/transport/encryption_algorithm/encryption_algorithm'
5
+ require 'hrr_rb_ssh/transport/encryption_algorithm/functionable'
6
+
7
+ module HrrRbSsh
8
+ class Transport
9
+ class EncryptionAlgorithm
10
+ class Aes256Ctr < EncryptionAlgorithm
11
+ NAME = 'aes256-ctr'
12
+ CIPHER_NAME = "AES-256-CTR"
13
+ BLOCK_SIZE = 16
14
+
15
+ include Functionable
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/transport/encryption_algorithm/encryption_algorithm'
5
+ require 'hrr_rb_ssh/transport/encryption_algorithm/functionable'
6
+
7
+ module HrrRbSsh
8
+ class Transport
9
+ class EncryptionAlgorithm
10
+ class Arcfour < EncryptionAlgorithm
11
+ NAME = 'arcfour'
12
+ CIPHER_NAME = "RC4"
13
+ BLOCK_SIZE = 8
14
+
15
+ include Functionable
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/transport/encryption_algorithm/encryption_algorithm'
5
+ require 'hrr_rb_ssh/transport/encryption_algorithm/functionable'
6
+
7
+ module HrrRbSsh
8
+ class Transport
9
+ class EncryptionAlgorithm
10
+ class BlowfishCbc < EncryptionAlgorithm
11
+ NAME = 'blowfish-cbc'
12
+ CIPHER_NAME = "BF-CBC"
13
+ BLOCK_SIZE = 8
14
+
15
+ include Functionable
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/transport/encryption_algorithm/encryption_algorithm'
5
+ require 'hrr_rb_ssh/transport/encryption_algorithm/functionable'
6
+
7
+ module HrrRbSsh
8
+ class Transport
9
+ class EncryptionAlgorithm
10
+ class Cast128Cbc < EncryptionAlgorithm
11
+ NAME = 'cast128-cbc'
12
+ CIPHER_NAME = "CAST5-CBC"
13
+ BLOCK_SIZE = 8
14
+
15
+ include Functionable
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/logger'
5
+
6
+ module HrrRbSsh
7
+ class Transport
8
+ class EncryptionAlgorithm
9
+ class EncryptionAlgorithm
10
+ @@list = Array.new
11
+
12
+ def self.inherited klass
13
+ @@list.push klass
14
+ end
15
+
16
+ def self.list
17
+ @@list
18
+ end
19
+
20
+ def self.name_list
21
+ @@list.map{ |klass| klass::NAME }
22
+ end
23
+
24
+ def self.[] key
25
+ @@list.find{ |klass| key == klass::NAME }
26
+ end
27
+
28
+ def initialize direction, iv, key
29
+ @logger = HrrRbSsh::Logger.new self.class.name
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,61 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/logger'
5
+
6
+ module HrrRbSsh
7
+ class Transport
8
+ class EncryptionAlgorithm
9
+ module Functionable
10
+ def self.included klass
11
+ cipher = OpenSSL::Cipher.new(klass::CIPHER_NAME)
12
+ klass.const_set(:IV_LENGTH, cipher.iv_len)
13
+ klass.const_set(:KEY_LENGTH, cipher.key_len)
14
+ end
15
+
16
+ def initialize direction, iv, key
17
+ super
18
+
19
+ @cipher = OpenSSL::Cipher.new(self.class::CIPHER_NAME)
20
+ case direction
21
+ when HrrRbSsh::Transport::Direction::OUTGOING
22
+ @cipher.encrypt
23
+ when HrrRbSsh::Transport::Direction::INCOMING
24
+ @cipher.decrypt
25
+ end
26
+ @cipher.padding = 0
27
+ @cipher.iv = iv
28
+ @cipher.key = key
29
+ end
30
+
31
+ def block_size
32
+ self.class::BLOCK_SIZE
33
+ end
34
+
35
+ def iv_length
36
+ self.class::IV_LENGTH
37
+ end
38
+
39
+ def key_length
40
+ self.class::KEY_LENGTH
41
+ end
42
+
43
+ def encrypt data
44
+ if data.empty?
45
+ data
46
+ else
47
+ @cipher.update(data) + @cipher.final
48
+ end
49
+ end
50
+
51
+ def decrypt data
52
+ if data.empty?
53
+ data
54
+ else
55
+ @cipher.update(data) + @cipher.final
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -2,47 +2,20 @@
2
2
  # vim: et ts=2 sw=2
3
3
 
4
4
  require 'hrr_rb_ssh/logger'
5
+ require 'hrr_rb_ssh/transport/encryption_algorithm/unfunctionable'
5
6
 
6
7
  module HrrRbSsh
7
8
  class Transport
8
9
  class EncryptionAlgorithm
9
- name_list = [
10
- 'none'
11
- ]
12
-
13
- class None
10
+ class None < EncryptionAlgorithm
11
+ NAME = 'none'
14
12
  BLOCK_SIZE = 0
15
- IV_LENGTH = 0
16
- KEY_LENGTH = 0
17
-
18
- def initialize iv=nil, key=nil
19
- @logger = HrrRbSsh::Logger.new self.class.name
20
- end
21
-
22
- def block_size
23
- BLOCK_SIZE
24
- end
25
-
26
- def iv_length
27
- IV_LENGTH
28
- end
29
-
30
- def key_length
31
- KEY_LENGTH
32
- end
33
13
 
34
- def encrypt data
35
- data
14
+ def initialize direction=nil, iv=nil, key=nil
15
+ super
36
16
  end
37
17
 
38
- def decrypt data
39
- data
40
- end
41
- end
42
-
43
- @@list ||= Hash.new
44
- name_list.each do |name|
45
- @@list[name] = None
18
+ include Unfunctionable
46
19
  end
47
20
  end
48
21
  end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/transport/encryption_algorithm/encryption_algorithm'
5
+ require 'hrr_rb_ssh/transport/encryption_algorithm/functionable'
6
+
7
+ module HrrRbSsh
8
+ class Transport
9
+ class EncryptionAlgorithm
10
+ class ThreeDesCbc < EncryptionAlgorithm
11
+ NAME = '3des-cbc'
12
+ CIPHER_NAME = "DES-EDE3-CBC"
13
+ BLOCK_SIZE = 8
14
+
15
+ include Functionable
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ module HrrRbSsh
5
+ class Transport
6
+ class EncryptionAlgorithm
7
+ module Unfunctionable
8
+ def self.included klass
9
+ klass.const_set(:IV_LENGTH, 0)
10
+ klass.const_set(:KEY_LENGTH, 0)
11
+ end
12
+
13
+ def block_size
14
+ self.class::BLOCK_SIZE
15
+ end
16
+
17
+ def iv_length
18
+ self.class::IV_LENGTH
19
+ end
20
+
21
+ def key_length
22
+ self.class::KEY_LENGTH
23
+ end
24
+
25
+ def encrypt data
26
+ data
27
+ end
28
+
29
+ def decrypt data
30
+ data
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,22 +1,33 @@
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/transport/encryption_algorithm/none'
6
- require 'hrr_rb_ssh/transport/encryption_algorithm/aes_128_cbc'
7
-
8
4
  module HrrRbSsh
9
5
  class Transport
10
6
  class EncryptionAlgorithm
11
- @@list ||= Hash.new
12
-
13
- def self.[] key
14
- @@list[key]
7
+ def self.list
8
+ EncryptionAlgorithm.list
15
9
  end
16
10
 
17
11
  def self.name_list
18
- @@list.keys
12
+ EncryptionAlgorithm.name_list
13
+ end
14
+
15
+ def self.[] key
16
+ EncryptionAlgorithm[key]
19
17
  end
20
18
  end
21
19
  end
22
20
  end
21
+
22
+ require 'hrr_rb_ssh/transport/encryption_algorithm/encryption_algorithm'
23
+ require 'hrr_rb_ssh/transport/encryption_algorithm/none'
24
+ require 'hrr_rb_ssh/transport/encryption_algorithm/three_des_cbc'
25
+ require 'hrr_rb_ssh/transport/encryption_algorithm/blowfish_cbc'
26
+ require 'hrr_rb_ssh/transport/encryption_algorithm/aes128_cbc'
27
+ require 'hrr_rb_ssh/transport/encryption_algorithm/aes192_cbc'
28
+ require 'hrr_rb_ssh/transport/encryption_algorithm/aes256_cbc'
29
+ require 'hrr_rb_ssh/transport/encryption_algorithm/arcfour'
30
+ require 'hrr_rb_ssh/transport/encryption_algorithm/cast128_cbc'
31
+ require 'hrr_rb_ssh/transport/encryption_algorithm/aes128_ctr'
32
+ require 'hrr_rb_ssh/transport/encryption_algorithm/aes192_ctr'
33
+ require 'hrr_rb_ssh/transport/encryption_algorithm/aes256_ctr'
@@ -1,13 +1,13 @@
1
1
  # coding: utf-8
2
2
  # vim: et ts=2 sw=2
3
3
 
4
- require 'hrr_rb_ssh/logger'
4
+ require 'openssl'
5
5
  require 'hrr_rb_ssh/transport/data_type'
6
6
 
7
7
  module HrrRbSsh
8
8
  class Transport
9
9
  class KexAlgorithm
10
- class DiffieHellman
10
+ module DiffieHellman
11
11
  H0_DEFINITION = [
12
12
  ['string', 'V_C'],
13
13
  ['string', 'V_S'],
@@ -20,7 +20,7 @@ module HrrRbSsh
20
20
  ]
21
21
 
22
22
  def initialize
23
- @logger = HrrRbSsh::Logger.new self.class.name
23
+ super
24
24
 
25
25
  @dh = OpenSSL::PKey::DH.new
26
26
  if @dh.respond_to?(:set_pqg)
@@ -122,7 +122,6 @@ module HrrRbSsh
122
122
  key_length = HrrRbSsh::Transport::MacAlgorithm[mac_algorithm_s_to_c_name]::KEY_LENGTH
123
123
  build_key(shared_secret, hash(transport), 'F'.ord, transport.session_id, key_length)
124
124
  end
125
-
126
125
  end
127
126
  end
128
127
  end
@@ -1,16 +1,15 @@
1
1
  # coding: utf-8
2
2
  # vim: et ts=2 sw=2
3
3
 
4
+ require 'hrr_rb_ssh/transport/kex_algorithm/kex_algorithm'
4
5
  require 'hrr_rb_ssh/transport/kex_algorithm/diffie_hellman'
5
6
 
6
7
  module HrrRbSsh
7
8
  class Transport
8
9
  class KexAlgorithm
9
- name_list = [
10
- 'diffie-hellman-group14-sha1'
11
- ]
10
+ class DiffieHellmanGroup14Sha1 < KexAlgorithm
11
+ NAME = 'diffie-hellman-group14-sha1'
12
12
 
13
- class DiffieHellmanGroup14Sha1 < DiffieHellman
14
13
  P = \
15
14
  "FFFFFFFF" "FFFFFFFF" "C90FDAA2" "2168C234" \
16
15
  "C4C6628B" "80DC1CD1" "29024E08" "8A67CC74" \
@@ -31,11 +30,8 @@ module HrrRbSsh
31
30
  G = 2
32
31
 
33
32
  DIGEST = 'sha1'
34
- end
35
33
 
36
- @@list ||= Hash.new
37
- name_list.each do |name|
38
- @@list[name] = DiffieHellmanGroup14Sha1
34
+ include DiffieHellman
39
35
  end
40
36
  end
41
37
  end
@@ -1,16 +1,15 @@
1
1
  # coding: utf-8
2
2
  # vim: et ts=2 sw=2
3
3
 
4
+ require 'hrr_rb_ssh/transport/kex_algorithm/kex_algorithm'
4
5
  require 'hrr_rb_ssh/transport/kex_algorithm/diffie_hellman'
5
6
 
6
7
  module HrrRbSsh
7
8
  class Transport
8
9
  class KexAlgorithm
9
- name_list = [
10
- 'diffie-hellman-group1-sha1'
11
- ]
10
+ class DiffieHellmanGroup1Sha1 < KexAlgorithm
11
+ NAME = 'diffie-hellman-group1-sha1'
12
12
 
13
- class DiffieHellmanGroup1Sha1 < DiffieHellman
14
13
  P = \
15
14
  "FFFFFFFF" "FFFFFFFF" "C90FDAA2" "2168C234" \
16
15
  "C4C6628B" "80DC1CD1" "29024E08" "8A67CC74" \
@@ -23,11 +22,8 @@ module HrrRbSsh
23
22
  G = 2
24
23
 
25
24
  DIGEST = 'sha1'
26
- end
27
25
 
28
- @@list ||= Hash.new
29
- name_list.each do |name|
30
- @@list[name] = DiffieHellmanGroup1Sha1
26
+ include DiffieHellman
31
27
  end
32
28
  end
33
29
  end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/logger'
5
+
6
+ module HrrRbSsh
7
+ class Transport
8
+ class KexAlgorithm
9
+ class KexAlgorithm
10
+ @@list = Array.new
11
+
12
+ def self.inherited klass
13
+ @@list.push klass
14
+ end
15
+
16
+ def self.list
17
+ @@list
18
+ end
19
+
20
+ def self.name_list
21
+ @@list.map{ |klass| klass::NAME }
22
+ end
23
+
24
+ def self.[] key
25
+ @@list.find{ |klass| key == klass::NAME }
26
+ end
27
+
28
+ def initialize
29
+ @logger = HrrRbSsh::Logger.new self.class.name
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end