net-ssh 4.2.0 → 7.0.1

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 (126) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/.dockerignore +6 -0
  4. data/.github/config/rubocop_linter_action.yml +4 -0
  5. data/.github/workflows/ci-with-docker.yml +44 -0
  6. data/.github/workflows/ci.yml +87 -0
  7. data/.github/workflows/rubocop.yml +13 -0
  8. data/.gitignore +7 -0
  9. data/.rubocop.yml +19 -2
  10. data/.rubocop_todo.yml +619 -667
  11. data/CHANGES.txt +110 -1
  12. data/Dockerfile +27 -0
  13. data/Dockerfile.openssl3 +17 -0
  14. data/Gemfile +3 -7
  15. data/{Gemfile.norbnacl → Gemfile.noed25519} +3 -1
  16. data/Manifest +4 -5
  17. data/README.md +293 -0
  18. data/Rakefile +45 -29
  19. data/appveyor.yml +8 -6
  20. data/docker-compose.yml +23 -0
  21. data/lib/net/ssh/authentication/agent.rb +248 -223
  22. data/lib/net/ssh/authentication/certificate.rb +178 -164
  23. data/lib/net/ssh/authentication/constants.rb +17 -15
  24. data/lib/net/ssh/authentication/ed25519.rb +141 -116
  25. data/lib/net/ssh/authentication/ed25519_loader.rb +28 -28
  26. data/lib/net/ssh/authentication/key_manager.rb +79 -36
  27. data/lib/net/ssh/authentication/methods/abstract.rb +62 -47
  28. data/lib/net/ssh/authentication/methods/hostbased.rb +34 -37
  29. data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +3 -3
  30. data/lib/net/ssh/authentication/methods/none.rb +16 -19
  31. data/lib/net/ssh/authentication/methods/password.rb +15 -16
  32. data/lib/net/ssh/authentication/methods/publickey.rb +96 -55
  33. data/lib/net/ssh/authentication/pageant.rb +468 -465
  34. data/lib/net/ssh/authentication/pub_key_fingerprint.rb +43 -0
  35. data/lib/net/ssh/authentication/session.rb +131 -122
  36. data/lib/net/ssh/buffer.rb +385 -332
  37. data/lib/net/ssh/buffered_io.rb +150 -151
  38. data/lib/net/ssh/config.rb +316 -239
  39. data/lib/net/ssh/connection/channel.rb +635 -613
  40. data/lib/net/ssh/connection/constants.rb +29 -29
  41. data/lib/net/ssh/connection/event_loop.rb +104 -95
  42. data/lib/net/ssh/connection/keepalive.rb +55 -51
  43. data/lib/net/ssh/connection/session.rb +614 -611
  44. data/lib/net/ssh/connection/term.rb +125 -123
  45. data/lib/net/ssh/errors.rb +101 -99
  46. data/lib/net/ssh/key_factory.rb +194 -108
  47. data/lib/net/ssh/known_hosts.rb +212 -134
  48. data/lib/net/ssh/loggable.rb +50 -49
  49. data/lib/net/ssh/packet.rb +83 -79
  50. data/lib/net/ssh/prompt.rb +51 -51
  51. data/lib/net/ssh/proxy/command.rb +105 -91
  52. data/lib/net/ssh/proxy/errors.rb +12 -10
  53. data/lib/net/ssh/proxy/http.rb +81 -81
  54. data/lib/net/ssh/proxy/https.rb +37 -36
  55. data/lib/net/ssh/proxy/jump.rb +49 -48
  56. data/lib/net/ssh/proxy/socks4.rb +2 -6
  57. data/lib/net/ssh/proxy/socks5.rb +14 -17
  58. data/lib/net/ssh/service/forward.rb +365 -362
  59. data/lib/net/ssh/test/channel.rb +145 -143
  60. data/lib/net/ssh/test/extensions.rb +131 -127
  61. data/lib/net/ssh/test/kex.rb +34 -32
  62. data/lib/net/ssh/test/local_packet.rb +46 -44
  63. data/lib/net/ssh/test/packet.rb +87 -84
  64. data/lib/net/ssh/test/remote_packet.rb +32 -30
  65. data/lib/net/ssh/test/script.rb +155 -155
  66. data/lib/net/ssh/test/socket.rb +49 -48
  67. data/lib/net/ssh/test.rb +82 -80
  68. data/lib/net/ssh/transport/algorithms.rb +433 -364
  69. data/lib/net/ssh/transport/cipher_factory.rb +95 -91
  70. data/lib/net/ssh/transport/constants.rb +32 -24
  71. data/lib/net/ssh/transport/ctr.rb +37 -15
  72. data/lib/net/ssh/transport/hmac/abstract.rb +81 -63
  73. data/lib/net/ssh/transport/hmac/md5.rb +0 -2
  74. data/lib/net/ssh/transport/hmac/md5_96.rb +0 -2
  75. data/lib/net/ssh/transport/hmac/none.rb +0 -2
  76. data/lib/net/ssh/transport/hmac/ripemd160.rb +0 -2
  77. data/lib/net/ssh/transport/hmac/sha1.rb +0 -2
  78. data/lib/net/ssh/transport/hmac/sha1_96.rb +0 -2
  79. data/lib/net/ssh/transport/hmac/sha2_256.rb +7 -11
  80. data/lib/net/ssh/transport/hmac/sha2_256_96.rb +4 -8
  81. data/lib/net/ssh/transport/hmac/sha2_256_etm.rb +12 -0
  82. data/lib/net/ssh/transport/hmac/sha2_512.rb +6 -9
  83. data/lib/net/ssh/transport/hmac/sha2_512_96.rb +4 -8
  84. data/lib/net/ssh/transport/hmac/sha2_512_etm.rb +12 -0
  85. data/lib/net/ssh/transport/hmac.rb +14 -12
  86. data/lib/net/ssh/transport/identity_cipher.rb +54 -52
  87. data/lib/net/ssh/transport/kex/abstract.rb +130 -0
  88. data/lib/net/ssh/transport/kex/abstract5656.rb +72 -0
  89. data/lib/net/ssh/transport/kex/curve25519_sha256.rb +39 -0
  90. data/lib/net/ssh/transport/kex/curve25519_sha256_loader.rb +30 -0
  91. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha1.rb +33 -40
  92. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha256.rb +11 -0
  93. data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +112 -217
  94. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +53 -63
  95. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha256.rb +5 -9
  96. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb +36 -90
  97. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp384.rb +18 -10
  98. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp521.rb +18 -10
  99. data/lib/net/ssh/transport/kex.rb +15 -12
  100. data/lib/net/ssh/transport/key_expander.rb +24 -21
  101. data/lib/net/ssh/transport/openssl.rb +158 -133
  102. data/lib/net/ssh/transport/packet_stream.rb +223 -191
  103. data/lib/net/ssh/transport/server_version.rb +55 -56
  104. data/lib/net/ssh/transport/session.rb +306 -259
  105. data/lib/net/ssh/transport/state.rb +178 -176
  106. data/lib/net/ssh/verifiers/accept_new.rb +33 -0
  107. data/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb +33 -0
  108. data/lib/net/ssh/verifiers/always.rb +58 -0
  109. data/lib/net/ssh/verifiers/never.rb +19 -0
  110. data/lib/net/ssh/version.rb +55 -53
  111. data/lib/net/ssh.rb +47 -34
  112. data/net-ssh-public_cert.pem +18 -19
  113. data/net-ssh.gemspec +12 -11
  114. data/support/ssh_tunnel_bug.rb +5 -5
  115. data.tar.gz.sig +0 -0
  116. metadata +78 -73
  117. metadata.gz.sig +0 -0
  118. data/.travis.yml +0 -51
  119. data/Gemfile.norbnacl.lock +0 -41
  120. data/README.rdoc +0 -169
  121. data/lib/net/ssh/ruby_compat.rb +0 -24
  122. data/lib/net/ssh/verifiers/lenient.rb +0 -30
  123. data/lib/net/ssh/verifiers/null.rb +0 -12
  124. data/lib/net/ssh/verifiers/secure.rb +0 -52
  125. data/lib/net/ssh/verifiers/strict.rb +0 -24
  126. data/support/arcfour_check.rb +0 -20
@@ -1,169 +1,183 @@
1
1
  require 'securerandom'
2
2
 
3
- module Net; module SSH; module Authentication
4
- # Class for representing an SSH certificate.
5
- #
6
- # http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/usr.bin/ssh/PROTOCOL.certkeys?rev=1.10&content-type=text/plain
7
- class Certificate
8
- attr_accessor :nonce
9
- attr_accessor :key
10
- attr_accessor :serial
11
- attr_accessor :type
12
- attr_accessor :key_id
13
- attr_accessor :valid_principals
14
- attr_accessor :valid_after
15
- attr_accessor :valid_before
16
- attr_accessor :critical_options
17
- attr_accessor :extensions
18
- attr_accessor :reserved
19
- attr_accessor :signature_key
20
- attr_accessor :signature
21
-
22
- # Read a certificate blob associated with a key of the given type.
23
- def self.read_certblob(buffer, type)
24
- cert = Certificate.new
25
- cert.nonce = buffer.read_string
26
- cert.key = buffer.read_keyblob(type)
27
- cert.serial = buffer.read_int64
28
- cert.type = type_symbol(buffer.read_long)
29
- cert.key_id = buffer.read_string
30
- cert.valid_principals = buffer.read_buffer.read_all(&:read_string)
31
- cert.valid_after = Time.at(buffer.read_int64)
32
- cert.valid_before = Time.at(buffer.read_int64)
33
- cert.critical_options = read_options(buffer)
34
- cert.extensions = read_options(buffer)
35
- cert.reserved = buffer.read_string
36
- cert.signature_key = buffer.read_buffer.read_key
37
- cert.signature = buffer.read_string
38
- cert
39
- end
40
-
41
- def ssh_type
42
- key.ssh_type + "-cert-v01@openssh.com"
43
- end
44
-
45
- def ssh_signature_type
46
- key.ssh_type
47
- end
48
-
49
- # Serializes the certificate (and key).
50
- def to_blob
51
- Buffer.from(
52
- :raw, to_blob_without_signature,
53
- :string, signature
54
- ).to_s
55
- end
56
-
57
- def ssh_do_sign(data)
58
- key.ssh_do_sign(data)
59
- end
60
-
61
- def ssh_do_verify(sig, data)
62
- key.ssh_do_verify(sig, data)
63
- end
64
-
65
- def to_pem
66
- key.to_pem
67
- end
68
-
69
- def fingerprint
70
- key.fingerprint
71
- end
72
-
73
- # Signs the certificate with key.
74
- def sign!(key, sign_nonce=nil)
75
- # ssh-keygen uses 32 bytes of nonce.
76
- self.nonce = sign_nonce || SecureRandom.random_bytes(32)
77
- self.signature_key = key
78
- self.signature = Net::SSH::Buffer.from(
79
- :string, key.ssh_signature_type,
80
- :mstring, key.ssh_do_sign(to_blob_without_signature)
81
- ).to_s
82
- self
83
- end
84
-
85
- def sign(key, sign_nonce=nil)
86
- cert = clone
87
- cert.sign!(key, sign_nonce)
88
- end
89
-
90
- # Checks whether the certificate's signature was signed by signature key.
91
- def signature_valid?
92
- buffer = Buffer.new(signature)
93
- buffer.read_string # skip signature format
94
- signature_key.ssh_do_verify(buffer.read_string, to_blob_without_signature)
95
- end
96
-
97
- def self.read_options(buffer)
98
- names = []
99
- options = buffer.read_buffer.read_all do |b|
100
- name = b.read_string
101
- names << name
102
- data = b.read_string
103
- data = Buffer.new(data).read_string unless data.empty?
104
- [name, data]
105
- end
106
-
107
- if names.sort != names
108
- raise ArgumentError, "option/extension names must be in sorted order"
3
+ module Net
4
+ module SSH
5
+ module Authentication
6
+ # Class for representing an SSH certificate.
7
+ #
8
+ # http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/usr.bin/ssh/PROTOCOL.certkeys?rev=1.10&content-type=text/plain
9
+ class Certificate
10
+ attr_accessor :nonce
11
+ attr_accessor :key
12
+ attr_accessor :serial
13
+ attr_accessor :type
14
+ attr_accessor :key_id
15
+ attr_accessor :valid_principals
16
+ attr_accessor :valid_after
17
+ attr_accessor :valid_before
18
+ attr_accessor :critical_options
19
+ attr_accessor :extensions
20
+ attr_accessor :reserved
21
+ attr_accessor :signature_key
22
+ attr_accessor :signature
23
+
24
+ # Read a certificate blob associated with a key of the given type.
25
+ def self.read_certblob(buffer, type)
26
+ cert = Certificate.new
27
+ cert.nonce = buffer.read_string
28
+ cert.key = buffer.read_keyblob(type)
29
+ cert.serial = buffer.read_int64
30
+ cert.type = type_symbol(buffer.read_long)
31
+ cert.key_id = buffer.read_string
32
+ cert.valid_principals = buffer.read_buffer.read_all(&:read_string)
33
+ cert.valid_after = Time.at(buffer.read_int64)
34
+
35
+ cert.valid_before = if RUBY_PLATFORM == "java"
36
+ # 0x20c49ba5e353f7 = 0x7fffffffffffffff/1000, the largest value possible for JRuby
37
+ # JRuby Time.at multiplies the arg by 1000, and then stores it in a signed long.
38
+ # 0x20c49ba2d52500 = 292278993-01-01 00:00:00 +0000
39
+ # JRuby 9.1 does not accept the year 292278994 because of edge cases (https://github.com/JodaOrg/joda-time/issues/190)
40
+ Time.at([0x20c49ba2d52500, buffer.read_int64].min)
41
+ else
42
+ Time.at(buffer.read_int64)
43
+ end
44
+
45
+ cert.critical_options = read_options(buffer)
46
+ cert.extensions = read_options(buffer)
47
+ cert.reserved = buffer.read_string
48
+ cert.signature_key = buffer.read_buffer.read_key
49
+ cert.signature = buffer.read_string
50
+ cert
51
+ end
52
+
53
+ def ssh_type
54
+ key.ssh_type + "-cert-v01@openssh.com"
55
+ end
56
+
57
+ def ssh_signature_type
58
+ key.ssh_type
59
+ end
60
+
61
+ # Serializes the certificate (and key).
62
+ def to_blob
63
+ Buffer.from(
64
+ :raw, to_blob_without_signature,
65
+ :string, signature
66
+ ).to_s
67
+ end
68
+
69
+ def ssh_do_sign(data, sig_alg = nil)
70
+ key.ssh_do_sign(data, sig_alg)
71
+ end
72
+
73
+ def ssh_do_verify(sig, data, options = {})
74
+ key.ssh_do_verify(sig, data, options)
75
+ end
76
+
77
+ def to_pem
78
+ key.to_pem
79
+ end
80
+
81
+ def fingerprint
82
+ key.fingerprint
83
+ end
84
+
85
+ # Signs the certificate with key.
86
+ def sign!(key, sign_nonce = nil)
87
+ # ssh-keygen uses 32 bytes of nonce.
88
+ self.nonce = sign_nonce || SecureRandom.random_bytes(32)
89
+ self.signature_key = key
90
+ self.signature = Net::SSH::Buffer.from(
91
+ :string, key.ssh_signature_type,
92
+ :mstring, key.ssh_do_sign(to_blob_without_signature)
93
+ ).to_s
94
+ self
95
+ end
96
+
97
+ def sign(key, sign_nonce = nil)
98
+ cert = clone
99
+ cert.sign!(key, sign_nonce)
100
+ end
101
+
102
+ # Checks whether the certificate's signature was signed by signature key.
103
+ def signature_valid?
104
+ buffer = Buffer.new(signature)
105
+ buffer.read_string # skip signature format
106
+ signature_key.ssh_do_verify(buffer.read_string, to_blob_without_signature)
107
+ end
108
+
109
+ def self.read_options(buffer)
110
+ names = []
111
+ options = buffer.read_buffer.read_all do |b|
112
+ name = b.read_string
113
+ names << name
114
+ data = b.read_string
115
+ data = Buffer.new(data).read_string unless data.empty?
116
+ [name, data]
117
+ end
118
+
119
+ raise ArgumentError, "option/extension names must be in sorted order" if names.sort != names
120
+
121
+ Hash[options]
122
+ end
123
+ private_class_method :read_options
124
+
125
+ def self.type_symbol(type)
126
+ types = { 1 => :user, 2 => :host }
127
+ raise ArgumentError("unsupported type: #{type}") unless types.include?(type)
128
+
129
+ types.fetch(type)
130
+ end
131
+ private_class_method :type_symbol
132
+
133
+ private
134
+
135
+ def type_value(type)
136
+ types = { user: 1, host: 2 }
137
+ raise ArgumentError("unsupported type: #{type}") unless types.include?(type)
138
+
139
+ types.fetch(type)
140
+ end
141
+
142
+ def ssh_time(t)
143
+ # Times in certificates are represented as a uint64.
144
+ [[t.to_i, 0].max, 2 << 64 - 1].min
145
+ end
146
+
147
+ def to_blob_without_signature
148
+ Buffer.from(
149
+ :string, ssh_type,
150
+ :string, nonce,
151
+ :raw, key_without_type,
152
+ :int64, serial,
153
+ :long, type_value(type),
154
+ :string, key_id,
155
+ :string, valid_principals.inject(Buffer.new) { |acc, elem| acc.write_string(elem) }.to_s,
156
+ :int64, ssh_time(valid_after),
157
+ :int64, ssh_time(valid_before),
158
+ :string, options_to_blob(critical_options),
159
+ :string, options_to_blob(extensions),
160
+ :string, reserved,
161
+ :string, signature_key.to_blob
162
+ ).to_s
163
+ end
164
+
165
+ def key_without_type
166
+ # key.to_blob gives us e.g. "ssh-rsa,<key>" but we just want "<key>".
167
+ tmp = Buffer.new(key.to_blob)
168
+ tmp.read_string # skip the underlying key type
169
+ tmp.read
170
+ end
171
+
172
+ def options_to_blob(options)
173
+ options.keys.sort.inject(Buffer.new) do |b, name|
174
+ b.write_string(name)
175
+ data = options.fetch(name)
176
+ data = Buffer.from(:string, data).to_s unless data.empty?
177
+ b.write_string(data)
178
+ end.to_s
179
+ end
109
180
  end
110
-
111
- Hash[options]
112
- end
113
- private_class_method :read_options
114
-
115
- def self.type_symbol(type)
116
- types = {1 => :user, 2 => :host}
117
- raise ArgumentError("unsupported type: #{type}") unless types.include?(type)
118
- types.fetch(type)
119
- end
120
- private_class_method :type_symbol
121
-
122
- private
123
-
124
- def type_value(type)
125
- types = {user: 1, host: 2}
126
- raise ArgumentError("unsupported type: #{type}") unless types.include?(type)
127
- types.fetch(type)
128
- end
129
-
130
- def ssh_time(t)
131
- # Times in certificates are represented as a uint64.
132
- [[t.to_i, 0].max, 2<<64 - 1].min
133
- end
134
-
135
- def to_blob_without_signature
136
- Buffer.from(
137
- :string, ssh_type,
138
- :string, nonce,
139
- :raw, key_without_type,
140
- :int64, serial,
141
- :long, type_value(type),
142
- :string, key_id,
143
- :string, valid_principals.inject(Buffer.new) { |acc, elem| acc.write_string(elem) }.to_s,
144
- :int64, ssh_time(valid_after),
145
- :int64, ssh_time(valid_before),
146
- :string, options_to_blob(critical_options),
147
- :string, options_to_blob(extensions),
148
- :string, reserved,
149
- :string, signature_key.to_blob
150
- ).to_s
151
- end
152
-
153
- def key_without_type
154
- # key.to_blob gives us e.g. "ssh-rsa,<key>" but we just want "<key>".
155
- tmp = Buffer.new(key.to_blob)
156
- tmp.read_string # skip the underlying key type
157
- tmp.read
158
- end
159
-
160
- def options_to_blob(options)
161
- options.keys.sort.inject(Buffer.new) do |b, name|
162
- b.write_string(name)
163
- data = options.fetch(name)
164
- data = Buffer.from(:string, data).to_s unless data.empty?
165
- b.write_string(data)
166
- end.to_s
167
181
  end
168
182
  end
169
- end; end; end
183
+ end
@@ -1,18 +1,20 @@
1
- module Net; module SSH; module Authentication
1
+ module Net
2
+ module SSH
3
+ module Authentication
4
+ # Describes the constants used by the Net::SSH::Authentication components
5
+ # of the Net::SSH library. Individual authentication method implemenations
6
+ # may define yet more constants that are specific to their implementation.
7
+ module Constants
8
+ USERAUTH_REQUEST = 50
9
+ USERAUTH_FAILURE = 51
10
+ USERAUTH_SUCCESS = 52
11
+ USERAUTH_BANNER = 53
2
12
 
3
- # Describes the constants used by the Net::SSH::Authentication components
4
- # of the Net::SSH library. Individual authentication method implemenations
5
- # may define yet more constants that are specific to their implementation.
6
- module Constants
7
- USERAUTH_REQUEST = 50
8
- USERAUTH_FAILURE = 51
9
- USERAUTH_SUCCESS = 52
10
- USERAUTH_BANNER = 53
13
+ USERAUTH_PASSWD_CHANGEREQ = 60
14
+ USERAUTH_PK_OK = 60
11
15
 
12
- USERAUTH_PASSWD_CHANGEREQ = 60
13
- USERAUTH_PK_OK = 60
14
-
15
- USERAUTH_METHOD_RANGE = 60..79
16
+ USERAUTH_METHOD_RANGE = 60..79
17
+ end
18
+ end
16
19
  end
17
-
18
- end; end; end
20
+ end