net-ssh 4.0.0.alpha1 → 4.0.0.alpha2
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.gitignore +6 -0
- data/.travis.yml +10 -7
- data/CHANGES.txt +4 -0
- data/Gemfile +2 -15
- data/README.rdoc +6 -37
- data/Rakefile +5 -57
- data/lib/net/ssh/connection/session.rb +13 -0
- data/lib/net/ssh/ruby_compat.rb +2 -24
- data/lib/net/ssh/version.rb +1 -1
- data/net-ssh.gemspec +34 -225
- metadata +26 -100
- metadata.gz.sig +0 -0
- data/test/README.txt +0 -18
- data/test/authentication/methods/common.rb +0 -28
- data/test/authentication/methods/test_abstract.rb +0 -51
- data/test/authentication/methods/test_hostbased.rb +0 -114
- data/test/authentication/methods/test_keyboard_interactive.rb +0 -121
- data/test/authentication/methods/test_none.rb +0 -41
- data/test/authentication/methods/test_password.rb +0 -95
- data/test/authentication/methods/test_publickey.rb +0 -148
- data/test/authentication/test_agent.rb +0 -224
- data/test/authentication/test_ed25519.rb +0 -77
- data/test/authentication/test_key_manager.rb +0 -240
- data/test/authentication/test_session.rb +0 -107
- data/test/common.rb +0 -109
- data/test/configs/auth_off +0 -5
- data/test/configs/auth_on +0 -4
- data/test/configs/empty +0 -0
- data/test/configs/eqsign +0 -3
- data/test/configs/exact_match +0 -8
- data/test/configs/host_plus +0 -10
- data/test/configs/multihost +0 -4
- data/test/configs/negative_match +0 -6
- data/test/configs/nohost +0 -19
- data/test/configs/numeric_host +0 -4
- data/test/configs/proxy_remote_user +0 -2
- data/test/configs/send_env +0 -2
- data/test/configs/substitutes +0 -8
- data/test/configs/wild_cards +0 -14
- data/test/connection/test_channel.rb +0 -487
- data/test/connection/test_session.rb +0 -563
- data/test/integration/README.md +0 -18
- data/test/integration/Vagrantfile +0 -12
- data/test/integration/common.rb +0 -65
- data/test/integration/playbook.yml +0 -57
- data/test/integration/test_ed25519_pkeys.rb +0 -70
- data/test/integration/test_forward.rb +0 -532
- data/test/integration/test_id_rsa_keys.rb +0 -96
- data/test/integration/test_proxy.rb +0 -93
- data/test/known_hosts/github +0 -1
- data/test/known_hosts/github_hash +0 -1
- data/test/manual/test_pageant.rb +0 -37
- data/test/start/test_connection.rb +0 -53
- data/test/start/test_options.rb +0 -57
- data/test/start/test_transport.rb +0 -28
- data/test/start/test_user_nil.rb +0 -27
- data/test/test_all.rb +0 -12
- data/test/test_buffer.rb +0 -433
- data/test/test_buffered_io.rb +0 -63
- data/test/test_config.rb +0 -268
- data/test/test_key_factory.rb +0 -191
- data/test/test_known_hosts.rb +0 -66
- data/test/transport/hmac/test_md5.rb +0 -41
- data/test/transport/hmac/test_md5_96.rb +0 -27
- data/test/transport/hmac/test_none.rb +0 -34
- data/test/transport/hmac/test_ripemd160.rb +0 -36
- data/test/transport/hmac/test_sha1.rb +0 -36
- data/test/transport/hmac/test_sha1_96.rb +0 -27
- data/test/transport/hmac/test_sha2_256.rb +0 -37
- data/test/transport/hmac/test_sha2_256_96.rb +0 -27
- data/test/transport/hmac/test_sha2_512.rb +0 -37
- data/test/transport/hmac/test_sha2_512_96.rb +0 -27
- data/test/transport/kex/test_diffie_hellman_group14_sha1.rb +0 -13
- data/test/transport/kex/test_diffie_hellman_group1_sha1.rb +0 -150
- data/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +0 -96
- data/test/transport/kex/test_diffie_hellman_group_exchange_sha256.rb +0 -19
- data/test/transport/kex/test_ecdh_sha2_nistp256.rb +0 -161
- data/test/transport/kex/test_ecdh_sha2_nistp384.rb +0 -38
- data/test/transport/kex/test_ecdh_sha2_nistp521.rb +0 -38
- data/test/transport/test_algorithms.rb +0 -328
- data/test/transport/test_cipher_factory.rb +0 -324
- data/test/transport/test_hmac.rb +0 -34
- data/test/transport/test_identity_cipher.rb +0 -40
- data/test/transport/test_packet_stream.rb +0 -1186
- data/test/transport/test_server_version.rb +0 -74
- data/test/transport/test_session.rb +0 -331
- data/test/transport/test_state.rb +0 -181
- data/test/verifiers/test_secure.rb +0 -40
data/test/test_buffered_io.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'common'
|
2
|
-
require 'net/ssh/buffered_io'
|
3
|
-
|
4
|
-
class TestBufferedIo < Test::Unit::TestCase
|
5
|
-
def test_fill_should_pull_from_underlying_io
|
6
|
-
io.expects(:recv).with(8192).returns("here is some data")
|
7
|
-
assert_equal 17, io.fill
|
8
|
-
assert_equal 17, io.available
|
9
|
-
assert_equal "here is some data", io.read_available(20)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_enqueue_should_not_write_to_underlying_io
|
13
|
-
assert !io.pending_write?
|
14
|
-
io.expects(:send).never
|
15
|
-
io.enqueue("here is some data")
|
16
|
-
assert io.pending_write?
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_send_pending_should_not_fail_when_no_writes_are_pending
|
20
|
-
assert !io.pending_write?
|
21
|
-
io.expects(:send).never
|
22
|
-
assert_nothing_raised { io.send_pending }
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_send_pending_with_pending_writes_should_write_to_underlying_io
|
26
|
-
io.enqueue("here is some data")
|
27
|
-
io.expects(:send).with("here is some data", 0).returns(17)
|
28
|
-
assert io.pending_write?
|
29
|
-
assert_nothing_raised { io.send_pending }
|
30
|
-
assert !io.pending_write?
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_wait_for_pending_sends_should_write_only_once_if_all_can_be_written_at_once
|
34
|
-
io.enqueue("here is some data")
|
35
|
-
io.expects(:send).with("here is some data", 0).returns(17)
|
36
|
-
assert io.pending_write?
|
37
|
-
assert_nothing_raised { io.wait_for_pending_sends }
|
38
|
-
assert !io.pending_write?
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_wait_for_pending_sends_should_write_multiple_times_if_first_write_was_partial
|
42
|
-
io.enqueue("here is some data")
|
43
|
-
|
44
|
-
io.expects(:send).with("here is some data", 0).returns(10)
|
45
|
-
io.expects(:send).with("me data", 0).returns(4)
|
46
|
-
io.expects(:send).with("ata", 0).returns(3)
|
47
|
-
|
48
|
-
IO.expects(:select).times(2).with(nil, [io]).returns([[], [io]])
|
49
|
-
|
50
|
-
assert_nothing_raised { io.wait_for_pending_sends }
|
51
|
-
assert !io.pending_write?
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
def io
|
57
|
-
@io ||= begin
|
58
|
-
io = mock("io")
|
59
|
-
io.extend(Net::SSH::BufferedIo)
|
60
|
-
io
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
data/test/test_config.rb
DELETED
@@ -1,268 +0,0 @@
|
|
1
|
-
require 'common'
|
2
|
-
require 'net/ssh/config'
|
3
|
-
require 'pathname'
|
4
|
-
require 'tempfile'
|
5
|
-
|
6
|
-
class TestConfig < Test::Unit::TestCase
|
7
|
-
def test_home_should_be_absolute_path
|
8
|
-
assert Pathname.new(ENV['HOME']).absolute?
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_load_for_non_existant_file_should_return_empty_hash
|
12
|
-
bogus_file = File.expand_path("/bogus/file")
|
13
|
-
File.expects(:readable?).with(bogus_file).returns(false)
|
14
|
-
assert_equal({}, Net::SSH::Config.load(bogus_file, "host.name"))
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_load_should_expand_path
|
18
|
-
expected = File.expand_path("~/.ssh/config")
|
19
|
-
File.expects(:readable?).with(expected).returns(false)
|
20
|
-
Net::SSH::Config.load("~/.ssh/config", "host.name")
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_load_with_exact_host_match_should_load_that_section
|
24
|
-
config = Net::SSH::Config.load(config(:exact_match), "test.host")
|
25
|
-
assert config['compression']
|
26
|
-
assert config['forwardagent']
|
27
|
-
assert_equal 1234, config['port']
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_load_with_wild_card_matches_should_load_all_matches_with_first_match_taking_precedence
|
31
|
-
config = Net::SSH::Config.load(config(:wild_cards), "test.host")
|
32
|
-
assert_equal 1234, config['port']
|
33
|
-
assert !config['compression']
|
34
|
-
assert config['forwardagent']
|
35
|
-
assert_equal %w(~/.ssh/id_dsa), config['identityfile']
|
36
|
-
assert !config.key?('rekeylimit')
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_load_with_wild_card_and_negative_pattern_does_not_match
|
40
|
-
config = Net::SSH::Config.load(config(:negative_match), "test.host")
|
41
|
-
assert_equal 9876, config['port']
|
42
|
-
assert !config.key?('compression')
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_load_with_pattern_does_match
|
46
|
-
data = %q{
|
47
|
-
Host test.*
|
48
|
-
Port 1234
|
49
|
-
Compression no
|
50
|
-
}
|
51
|
-
with_config_from_data data do |f|
|
52
|
-
config = Net::SSH::Config.load(f, "test.host")
|
53
|
-
assert_equal 1234, config['port']
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_load_with_regex_chars
|
58
|
-
data = %q{
|
59
|
-
Host |
|
60
|
-
Port 1234
|
61
|
-
Compression no
|
62
|
-
}
|
63
|
-
with_config_from_data data do |f|
|
64
|
-
config = Net::SSH::Config.load(f, "test.host")
|
65
|
-
assert_equal nil, config['port']
|
66
|
-
config = Net::SSH::Config.load(f, "|")
|
67
|
-
assert_equal 1234, config['port']
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
def test_for_should_load_all_files_and_translate_to_net_ssh_options
|
73
|
-
config = Net::SSH::Config.for("test.host", [config(:exact_match), config(:wild_cards)])
|
74
|
-
assert_equal 1234, config[:port]
|
75
|
-
assert config[:compression]
|
76
|
-
assert config[:forward_agent]
|
77
|
-
assert_equal %w(~/.ssh/id_dsa), config[:keys]
|
78
|
-
assert !config.key?(:rekey_limit)
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_load_with_no_host
|
82
|
-
config = Net::SSH::Config.load(config(:nohost), "test.host")
|
83
|
-
assert_equal %w(~/.ssh/id_dsa ~/.ssh/id_rsa), config['identityfile']
|
84
|
-
assert_equal 1985, config['port']
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_load_with_multiple_hosts
|
88
|
-
config = Net::SSH::Config.load(config(:multihost), "test.host")
|
89
|
-
assert config['compression']
|
90
|
-
assert_equal '2G', config['rekeylimit']
|
91
|
-
assert_equal 1980, config['port']
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_load_with_multiple_hosts_and_config_should_match_for_both
|
95
|
-
aconfig = Net::SSH::Config.load(config(:multihost), "test.host")
|
96
|
-
bconfig = Net::SSH::Config.load(config(:multihost), "other.host")
|
97
|
-
assert_equal aconfig['port'], bconfig['port']
|
98
|
-
assert_equal aconfig['compression'], bconfig['compression']
|
99
|
-
assert_equal aconfig['rekeylimit'], bconfig['rekeylimit']
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_load_should_parse_equal_sign_delimiters
|
103
|
-
config = Net::SSH::Config.load(config(:eqsign), "test.test")
|
104
|
-
assert config['compression']
|
105
|
-
assert_equal 1234, config['port']
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_translate_should_correctly_translate_from_openssh_to_net_ssh_names
|
109
|
-
open_ssh = {
|
110
|
-
'bindaddress' => "127.0.0.1",
|
111
|
-
'ciphers' => "a,b,c",
|
112
|
-
'compression' => true,
|
113
|
-
'compressionlevel' => 6,
|
114
|
-
'connecttimeout' => 100,
|
115
|
-
'forwardagent' => true,
|
116
|
-
'hostbasedauthentication' => true,
|
117
|
-
'hostkeyalgorithms' => "d,e,f",
|
118
|
-
'identityfile' => %w(g h i),
|
119
|
-
'macs' => "j,k,l",
|
120
|
-
'passwordauthentication' => true,
|
121
|
-
'port' => 1234,
|
122
|
-
'pubkeyauthentication' => true,
|
123
|
-
'rekeylimit' => 1024,
|
124
|
-
'sendenv' => "LC_*",
|
125
|
-
'numberofpasswordprompts' => '123',
|
126
|
-
'serveraliveinterval' => '2',
|
127
|
-
'serveralivecountmax' => '4'
|
128
|
-
}
|
129
|
-
|
130
|
-
net_ssh = Net::SSH::Config.translate(open_ssh)
|
131
|
-
|
132
|
-
assert_equal %w(a b c), net_ssh[:encryption]
|
133
|
-
assert_equal true, net_ssh[:compression]
|
134
|
-
assert_equal 6, net_ssh[:compression_level]
|
135
|
-
assert_equal 100, net_ssh[:timeout]
|
136
|
-
assert_equal true, net_ssh[:forward_agent]
|
137
|
-
assert_equal %w(hostbased keyboard-interactive none password publickey), net_ssh[:auth_methods].sort
|
138
|
-
assert_equal %w(d e f), net_ssh[:host_key]
|
139
|
-
assert_equal %w(g h i), net_ssh[:keys]
|
140
|
-
assert_equal %w(j k l), net_ssh[:hmac]
|
141
|
-
assert_equal 1234, net_ssh[:port]
|
142
|
-
assert_equal 1024, net_ssh[:rekey_limit]
|
143
|
-
assert_equal "127.0.0.1", net_ssh[:bind_address]
|
144
|
-
assert_equal [/^LC_.*$/], net_ssh[:send_env]
|
145
|
-
assert_equal 123, net_ssh[:number_of_password_prompts]
|
146
|
-
assert_equal 4, net_ssh[:keepalive_maxcount]
|
147
|
-
assert_equal 2, net_ssh[:keepalive_interval]
|
148
|
-
assert_equal true, net_ssh[:keepalive]
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_translate_should_turn_off_authentication_methods
|
152
|
-
open_ssh = {
|
153
|
-
'hostbasedauthentication' => false,
|
154
|
-
'passwordauthentication' => false,
|
155
|
-
'pubkeyauthentication' => false,
|
156
|
-
'challengeresponseauthentication' => false,
|
157
|
-
'kbdinteractiveauthentication' => false
|
158
|
-
}
|
159
|
-
|
160
|
-
net_ssh = Net::SSH::Config.translate(open_ssh)
|
161
|
-
|
162
|
-
assert_equal %w(none), net_ssh[:auth_methods].sort
|
163
|
-
end
|
164
|
-
|
165
|
-
def test_translate_should_turn_on_authentication_methods
|
166
|
-
open_ssh = {
|
167
|
-
'hostbasedauthentication' => true,
|
168
|
-
'passwordauthentication' => true,
|
169
|
-
'pubkeyauthentication' => true,
|
170
|
-
'challengeresponseauthentication' => true,
|
171
|
-
'kbdinteractiveauthentication' => true
|
172
|
-
}
|
173
|
-
|
174
|
-
net_ssh = Net::SSH::Config.translate(open_ssh)
|
175
|
-
|
176
|
-
assert_equal %w(hostbased keyboard-interactive none password publickey), net_ssh[:auth_methods].sort
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_translate_should_not_disable_keyboard_interactive_when_challange_or_keyboardinterective_is_on
|
180
|
-
open_ssh = {
|
181
|
-
'kbdinteractiveauthentication' => false
|
182
|
-
}
|
183
|
-
net_ssh = Net::SSH::Config.translate(open_ssh)
|
184
|
-
assert_equal %w(keyboard-interactive none password publickey), net_ssh[:auth_methods].sort
|
185
|
-
|
186
|
-
open_ssh = {
|
187
|
-
'challengeresponseauthentication' => false
|
188
|
-
}
|
189
|
-
net_ssh = Net::SSH::Config.translate(open_ssh)
|
190
|
-
assert_equal %w(keyboard-interactive none password publickey), net_ssh[:auth_methods].sort
|
191
|
-
end
|
192
|
-
|
193
|
-
def test_should_ddisable_keyboard_interactive_when_challeng_and_keyboardinteractive_is_off
|
194
|
-
open_ssh = {
|
195
|
-
'challengeresponseauthentication' => false,
|
196
|
-
'kbdinteractiveauthentication' => false
|
197
|
-
}
|
198
|
-
|
199
|
-
net_ssh = Net::SSH::Config.translate(open_ssh)
|
200
|
-
assert_equal %w(none password publickey), net_ssh[:auth_methods].sort
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_for_should_turn_off_authentication_methods
|
204
|
-
config = Net::SSH::Config.for("test.host", [config(:empty), config(:auth_off), config(:auth_on)])
|
205
|
-
assert_equal %w(none), config[:auth_methods].sort
|
206
|
-
end
|
207
|
-
|
208
|
-
def test_for_should_turn_on_authentication_methods
|
209
|
-
config = Net::SSH::Config.for("test.host", [config(:empty), config(:auth_on), config(:auth_off)])
|
210
|
-
assert_equal %w(hostbased keyboard-interactive none password publickey), config[:auth_methods].sort
|
211
|
-
end
|
212
|
-
|
213
|
-
def test_load_with_plus_sign_hosts
|
214
|
-
config = Net::SSH::Config.load(config(:host_plus), "test.host")
|
215
|
-
assert config['compression']
|
216
|
-
end
|
217
|
-
|
218
|
-
def test_load_with_numeric_host
|
219
|
-
config = Net::SSH::Config.load(config(:numeric_host), "1234")
|
220
|
-
assert config['compression']
|
221
|
-
assert_equal '2G', config['rekeylimit']
|
222
|
-
assert_equal 1980, config['port']
|
223
|
-
end
|
224
|
-
|
225
|
-
def test_load_wildcar_with_substitutes
|
226
|
-
config = Net::SSH::Config.load(config(:substitutes), "toto")
|
227
|
-
net_ssh = Net::SSH::Config.translate(config)
|
228
|
-
assert_equal 'toto', net_ssh[:host_name]
|
229
|
-
end
|
230
|
-
|
231
|
-
def test_load_sufix_with_substitutes
|
232
|
-
config = Net::SSH::Config.load(config(:substitutes), "test")
|
233
|
-
net_ssh = Net::SSH::Config.translate(config)
|
234
|
-
assert_equal 'test.sufix', net_ssh[:host_name]
|
235
|
-
end
|
236
|
-
|
237
|
-
def test_load_prefix_and_sufix_with_substitutes
|
238
|
-
config = Net::SSH::Config.load(config(:substitutes), "1234")
|
239
|
-
net_ssh = Net::SSH::Config.translate(config)
|
240
|
-
assert_equal 'prefix.1234.sufix', net_ssh[:host_name]
|
241
|
-
end
|
242
|
-
|
243
|
-
def test_load_with_send_env
|
244
|
-
config = Net::SSH::Config.load(config(:send_env), "1234")
|
245
|
-
net_ssh = Net::SSH::Config.translate(config)
|
246
|
-
assert_equal [/^GIT_.*$/, /^LANG$/, /^LC_.*$/], net_ssh[:send_env]
|
247
|
-
end
|
248
|
-
|
249
|
-
def test_load_with_remote_user
|
250
|
-
config = Net::SSH::Config.load(config(:proxy_remote_user), "behind-proxy")
|
251
|
-
net_ssh = Net::SSH::Config.translate(config)
|
252
|
-
assert net_ssh[:proxy]
|
253
|
-
end
|
254
|
-
|
255
|
-
private
|
256
|
-
|
257
|
-
def config(name)
|
258
|
-
"test/configs/#{name}"
|
259
|
-
end
|
260
|
-
|
261
|
-
def with_config_from_data(data, &block)
|
262
|
-
Tempfile.open('config') do |f|
|
263
|
-
f.write(data)
|
264
|
-
f.close
|
265
|
-
yield(f.path)
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|
data/test/test_key_factory.rb
DELETED
@@ -1,191 +0,0 @@
|
|
1
|
-
require 'common'
|
2
|
-
require 'net/ssh/key_factory'
|
3
|
-
|
4
|
-
class TestKeyFactory < Test::Unit::TestCase
|
5
|
-
def setup
|
6
|
-
@key_file = File.expand_path("/key-file")
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_load_unencrypted_private_RSA_key_should_return_key
|
10
|
-
File.expects(:read).with(@key_file).returns(rsa_key.export)
|
11
|
-
assert_equal rsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file).to_der
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_load_unencrypted_private_DSA_key_should_return_key
|
15
|
-
File.expects(:read).with(@key_file).returns(dsa_key.export)
|
16
|
-
assert_equal dsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file).to_der
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_load_encrypted_private_RSA_key_should_prompt_for_password_and_return_key
|
20
|
-
File.expects(:read).with(@key_file).returns(encrypted(rsa_key, "password"))
|
21
|
-
Net::SSH::KeyFactory.expects(:prompt).with("Enter passphrase for #{@key_file}:", false).returns("password")
|
22
|
-
assert_equal rsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file).to_der
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_load_encrypted_private_RSA_key_with_password_should_not_prompt_and_return_key
|
26
|
-
File.expects(:read).with(@key_file).returns(encrypted(rsa_key, "password"))
|
27
|
-
assert_equal rsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file, "password").to_der
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_load_encrypted_private_DSA_key_should_prompt_for_password_and_return_key
|
31
|
-
File.expects(:read).with(@key_file).returns(encrypted(dsa_key, "password"))
|
32
|
-
Net::SSH::KeyFactory.expects(:prompt).with("Enter passphrase for #{@key_file}:", false).returns("password")
|
33
|
-
assert_equal dsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file).to_der
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_load_encrypted_private_DSA_key_with_password_should_not_prompt_and_return_key
|
37
|
-
File.expects(:read).with(@key_file).returns(encrypted(dsa_key, "password"))
|
38
|
-
assert_equal dsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file, "password").to_der
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_load_encrypted_private_key_should_give_three_tries_for_the_password_and_then_raise_exception
|
42
|
-
File.expects(:read).with(@key_file).returns(encrypted(rsa_key, "password"))
|
43
|
-
Net::SSH::KeyFactory.expects(:prompt).times(3).with("Enter passphrase for #{@key_file}:", false).returns("passwod","passphrase","passwd")
|
44
|
-
if OpenSSL::PKey.respond_to?(:read)
|
45
|
-
error_class = ArgumentError
|
46
|
-
else
|
47
|
-
error_class = OpenSSL::PKey::RSAError
|
48
|
-
end
|
49
|
-
assert_raises(error_class) { Net::SSH::KeyFactory.load_private_key(@key_file) }
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_load_encrypted_private_key_should_raise_exception_without_asking_passphrase
|
53
|
-
File.expects(:read).with(@key_file).returns(encrypted(rsa_key, "password"))
|
54
|
-
Net::SSH::KeyFactory.expects(:prompt).never
|
55
|
-
if OpenSSL::PKey.respond_to?(:read)
|
56
|
-
error_class = ArgumentError
|
57
|
-
else
|
58
|
-
error_class = OpenSSL::PKey::RSAError
|
59
|
-
end
|
60
|
-
assert_raises(error_class) { Net::SSH::KeyFactory.load_private_key(@key_file, nil, false) }
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_load_public_rsa_key_should_return_key
|
64
|
-
File.expects(:read).with(@key_file).returns(public(rsa_key))
|
65
|
-
assert_equal rsa_key.to_blob, Net::SSH::KeyFactory.load_public_key(@key_file).to_blob
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_load_public_rsa_key_with_comment_should_return_key
|
69
|
-
File.expects(:read).with(@key_file).returns(public(rsa_key) + " key_comment")
|
70
|
-
assert_equal rsa_key.to_blob, Net::SSH::KeyFactory.load_public_key(@key_file).to_blob
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_load_public_rsa_key_with_options_should_return_key
|
74
|
-
File.expects(:read).with(@key_file).returns(public(rsa_key, 'environment="FOO=bar"'))
|
75
|
-
assert_equal rsa_key.to_blob, Net::SSH::KeyFactory.load_public_key(@key_file).to_blob
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_load_public_rsa_key_with_options_and_comment_should_return_key
|
79
|
-
File.expects(:read).with(@key_file).returns(public(rsa_key, 'environment="FOO=bar"') + " key_comment")
|
80
|
-
assert_equal rsa_key.to_blob, Net::SSH::KeyFactory.load_public_key(@key_file).to_blob
|
81
|
-
end
|
82
|
-
if defined?(OpenSSL::PKey::EC)
|
83
|
-
def test_load_unencrypted_private_ecdsa_sha2_nistp256_key_should_return_key
|
84
|
-
File.expects(:read).with("/key-file").returns(ecdsa_sha2_nistp256_key.to_pem)
|
85
|
-
assert_equal ecdsa_sha2_nistp256_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file").to_der
|
86
|
-
end
|
87
|
-
def test_load_unencrypted_private_ecdsa_sha2_nistp384_key_should_return_key
|
88
|
-
File.expects(:read).with("/key-file").returns(ecdsa_sha2_nistp384_key.to_pem)
|
89
|
-
assert_equal ecdsa_sha2_nistp384_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file").to_der
|
90
|
-
end
|
91
|
-
def test_load_unencrypted_private_ecdsa_sha2_nistp521_key_should_return_key
|
92
|
-
File.expects(:read).with("/key-file").returns(ecdsa_sha2_nistp521_key.to_pem)
|
93
|
-
assert_equal ecdsa_sha2_nistp521_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file").to_der
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_load_public_ecdsa_sha2_nistp256_key_should_return_key
|
97
|
-
File.expects(:read).with("/key-file").returns(public(ecdsa_sha2_nistp256_key))
|
98
|
-
assert_equal ecdsa_sha2_nistp256_key.to_blob, Net::SSH::KeyFactory.load_public_key("/key-file").to_blob
|
99
|
-
end
|
100
|
-
def test_load_public_ecdsa_sha2_nistp384_key_should_return_key
|
101
|
-
File.expects(:read).with("/key-file").returns(public(ecdsa_sha2_nistp384_key))
|
102
|
-
assert_equal ecdsa_sha2_nistp384_key.to_blob, Net::SSH::KeyFactory.load_public_key("/key-file").to_blob
|
103
|
-
end
|
104
|
-
def test_load_public_ecdsa_sha2_nistp521_key_should_return_key
|
105
|
-
File.expects(:read).with("/key-file").returns(public(ecdsa_sha2_nistp521_key))
|
106
|
-
assert_equal ecdsa_sha2_nistp521_key.to_blob, Net::SSH::KeyFactory.load_public_key("/key-file").to_blob
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_load_anonymous_private_key_should_return_key_or_raise_exception
|
111
|
-
File.expects(:read).with(@key_file).returns(anonymous_private_key)
|
112
|
-
if OpenSSL::PKey.respond_to?(:read)
|
113
|
-
assert_equal OpenSSL::PKey::RSA.new(anonymous_private_key).to_der, Net::SSH::KeyFactory.load_private_key(@key_file).to_der
|
114
|
-
else
|
115
|
-
assert_raises(OpenSSL::PKey::PKeyError) { Net::SSH::KeyFactory.load_private_key(@key_file) }
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
private
|
120
|
-
|
121
|
-
def rsa_key
|
122
|
-
# 512 bits
|
123
|
-
@rsa_key ||= OpenSSL::PKey::RSA.new("0\202\001;\002\001\000\002A\000\235\236\374N\e@2E\321\3757\003\354c\276N\f\003\3479Ko\005\317\0027\a\255=\345!\306\220\340\211;\027u\331\260\362\2063x\332\301y4\353\v%\032\214v\312\304\212\271GJ\353\2701\031\002\003\001\000\001\002@\022Y\306*\031\306\031\224Cde\231QV3{\306\256U\2477\377\017\000\020\323\363R\332\027\351\034\224OU\020\227H|pUS\n\263+%\304\341\321\273/\271\e\004L\250\273\020&,\t\304By\002!\000\311c\246%a\002\305\277\262R\266\244\250\025V_\351]\264\016\265\341\355\305\223\347Z$8\205#\023\002!\000\310\\\367|\243I\363\350\020\307\246\302\365\ed\212L\273\2158M\223w\a\367 C\t\224A4\243\002!\000\262]+}\327\231\331\002\2331^\312\036\204'g\363\f&\271\020\245\365-\024}\306\374e\202\2459\002 }\231\341\276\3551\277\307{5\\\361\233\353G\024wS\237\fk}\004\302&\205\277\340rb\211\327\002!\000\223\307\025I:\215_\260\370\252\3757\256Y&X\364\354\342\215\350\203E8\227|\f\237M\375D|")
|
124
|
-
end
|
125
|
-
|
126
|
-
def dsa_key
|
127
|
-
# 512 bits
|
128
|
-
@dsa_key ||= OpenSSL::PKey::DSA.new("0\201\367\002\001\000\002A\000\203\316/\037u\272&J\265\003l3\315d\324h\372{\t8\252#\331_\026\006\035\270\266\255\343\353Z\302\276\335\336\306\220\375\202L\244\244J\206>\346\b\315\211\302L\246x\247u\a\376\366\345\302\016#\002\025\000\244\274\302\221Og\275/\302+\356\346\360\024\373wI\2573\361\002@\027\215\270r*\f\213\350C\245\021:\350 \006\\\376\345\022`\210b\262\3643\023XLKS\320\370\002\276\347A\nU\204\276\324\256`=\026\240\330\306J\316V\213\024\e\030\215\355\006\037q\337\356ln\002@\017\257\034\f\260\333'S\271#\237\230E\321\312\027\021\226\331\251Vj\220\305\316\036\v\266+\000\230\270\177B\003?t\a\305]e\344\261\334\023\253\323\251\223M\2175)a(\004\"lI8\312\303\307\a\002\024_\aznW\345\343\203V\326\246ua\203\376\201o\350\302\002")
|
129
|
-
end
|
130
|
-
|
131
|
-
if defined?(OpenSSL::PKey::EC)
|
132
|
-
def ecdsa_sha2_nistp256_key
|
133
|
-
@ecdsa_sha2_nistp256_key ||= OpenSSL::PKey::EC.new("-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEINv6pPVLlkqvT1v5MJlWgaSWGwqupISG4U79bUXQDNCaoAoGCCqGSM49\nAwEHoUQDQgAElqubvi/GkSme+bwtncU1NiE0dWQ0EO07VufUQg8lUJ5+Fi6f96qa\n95T1zwOMQhY1h8PP9rQIZr4S48vN/ZnQLw==\n-----END EC PRIVATE KEY-----\n")
|
134
|
-
end
|
135
|
-
|
136
|
-
def ecdsa_sha2_nistp384_key
|
137
|
-
@ecdsa_sha2_nistp384_key ||= OpenSSL::PKey::EC.new("-----BEGIN EC PRIVATE KEY-----\nMIGkAgEBBDBxwkmydCn4mP4KMhlMpeBvIroQolWKVNoRPXpG7brFgK+Yiikqw8wd\nIZW5OlL4y3mgBwYFK4EEACKhZANiAARkoIR1oABi+aQJbKcmvzeYSKURQOyXM0HU\nR4T68v4hd/lJE4fFQRczj3wAaECe9u3CWI/oDlow4Vr0vab82ZGjIoblxblKQWYl\nyzENgzl226waGg1bLBo8Auilyf1B5yI=\n-----END EC PRIVATE KEY-----\n")
|
138
|
-
end
|
139
|
-
|
140
|
-
def ecdsa_sha2_nistp521_key
|
141
|
-
@ecdsa_sha2_nistp521_key ||= OpenSSL::PKey::EC.new("-----BEGIN EC PRIVATE KEY-----\nMIHbAgEBBEHQ2i7kjEGQHQB4pUQW9a2eCLWR2S5Go8U3CDyfbRCrYEp/pTSgI8uu\nMXyR3bf3SjqFQgZ6MZk5lkyrissJuwmvZKAHBgUrgQQAI6GBiQOBhgAEAN14FACK\nbs/KTqw4rxijeozGTVJTh1hNzBl2XaIhM4Fv8o3fE/pvogymyFu53GCng6gC4dmx\n/hycF41iIM29xVKPAeBnRNl6MdFBjuthOmE8eCRezgk1Bak8aBDUrzNT8OQssscw\npvQK4nc6ga/wTDaQGy5kV8tCOHNs2wKH+p2LpWTJ\n-----END EC PRIVATE KEY-----\n")
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
def anonymous_private_key
|
146
|
-
@anonymous_key = <<-EOF
|
147
|
-
-----BEGIN PRIVATE KEY-----
|
148
|
-
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC3id5gZ6bglJth
|
149
|
-
yli8JNaRxhsqKwwPlReEI/mplzz5IP6gWQ92LogXbdBXtHf9ZpA53BeLmtcNBEY0
|
150
|
-
Ygd7sPBhlHABS5D5///zltSSX2+L5GCEiC6dpfGsySjqymWF+SZ2PaqfZbkWLmCD
|
151
|
-
9u4ysueaHf7xbF6txGprNp69efttWxdy+vU5tno7HVxemMZQUalpShFrdAYKKXEo
|
152
|
-
cV7MtbkQjzubS14gaWGpWCXIl9uNKQeHpLKtre1Qn5Ft/zVpCHmhLQcYDuB1LAj9
|
153
|
-
7eoev4rIiOE2sfdkvKDlmFxvzq3myYH4o27WwAg9OZ5SBusn2zesKkRCBBEZ55rl
|
154
|
-
uVknOGHXAgMBAAECggEAZE0U2OxsNxkfXS6+lXswQ5PW7pF90towcsdSPgrniGIu
|
155
|
-
pKRnHbfKKbuaewOl+zZcpTIRL/rbgUKPtzrHSiJlC36aQyrvvJ/ZWV5ZJvC+vd19
|
156
|
-
nY/qob65NyrrkHwxRSjmiwGiR9/IaUXI+vUsMUqx5Ph1hawqhZ3sZlEAKR4LeDO8
|
157
|
-
M+OguG77jLaqj5/SNfi+GwyUDe85de4VfEG4S9HrMQk2Cp66rx0BqDnCLacyFQaI
|
158
|
-
R0VczMXTU52q0uETmgUr8G9A1SaRc5ZWKAfZwxJTvqdIImWC9E+CY7wm+mZD4FE6
|
159
|
-
iVzVC0ngcdEd596kTDdU2BPVMluWzLkfqIrTt/5CeQKBgQDzgRzCPNxFtai6RAIi
|
160
|
-
ekBSHqrDnrbeTaw32GVq5ACk1Zfk2I0svctz1iQ9qJ2SRINpygQhcyJKQ4r/LXi1
|
161
|
-
7Av9H/d6QV4T2AZzS4WcqBkxxRXFUfARtnKChzuCzNt9tNz4EZiv75RyQmztGZjV
|
162
|
-
i94+ZvCyqup5be4Svf4MBxin9QKBgQDA9P4nHzFWZakTMei78LGb/4Auc+r0rZp7
|
163
|
-
8xg8Z92tvrDeJjMdesdhiFrPP1qiSYHnQ81MSWpn6BycBsHZqitejQmYnYput/s4
|
164
|
-
qG+m7SrkN8WL6rijYsbB+U14VDjMlBlOgcEgjlSNU2oeS+68u+uVI/fgyXcXn4Jq
|
165
|
-
33TSWSgfGwKBgA2tRdE/G9wqfOShZ0FKfoxePpcoNfs8f5zPYbrkPYkEmjh3VU6b
|
166
|
-
Bm9mKrjv3JHXmU3608qRLe7f5lG42xvUu0OnZP4P59nTe2FEb6fB5VBfUn63wHUu
|
167
|
-
OzZLpDMPkJB59SNV0a6oFT1pr7aNhoEQDxaQL5rJcMwLOaEB3OAOEft1AoGASz7+
|
168
|
-
4Zi7b7rDPVYIMUpCqNfxT6wqovIUPWPmPqAuhXPIm0kAQ+2+VN2MtCc7m+/Ydawu
|
169
|
-
IiK7GPweNAY6kDxZH00WweolstmSYVzl9Y2lXUwWgGKvUB/T7I7g1Bzb7YOPftsA
|
170
|
-
ykZW2Kn/xwLLfdQ2oXleT82g4Jh2jmDHuMPF7qMCgYEA6QF45PvOgnrJessgmwO/
|
171
|
-
dEmkLl07PQYJPGZLaZteuWrvfMrn+AiW5aAdHzhzNaOtNy5B3T7zGUHtgxXegqgd
|
172
|
-
/QdCVCJgnZUO/zdAxkr22dDn+WEXkL4wgBVStQvvnQp9C2NJcoOExvex5PLzKWQg
|
173
|
-
WEKt5v3QsUEgVrzkM4K9UbI=
|
174
|
-
-----END PRIVATE KEY-----
|
175
|
-
EOF
|
176
|
-
end
|
177
|
-
|
178
|
-
def encrypted(key, password)
|
179
|
-
key.export(OpenSSL::Cipher::Cipher.new("des-ede3-cbc"), password)
|
180
|
-
end
|
181
|
-
|
182
|
-
def public(key, args = nil)
|
183
|
-
result = ""
|
184
|
-
if !args.nil?
|
185
|
-
result << "#{args} "
|
186
|
-
end
|
187
|
-
result << "#{key.ssh_type} "
|
188
|
-
result << [Net::SSH::Buffer.from(:key, key).to_s].pack("m*").strip.tr("\n\r\t ", "")
|
189
|
-
result << " joe@host.test"
|
190
|
-
end
|
191
|
-
end
|