net-ssh 4.0.0.alpha1 → 4.0.0.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- 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_known_hosts.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'common'
|
2
|
-
|
3
|
-
class TestKnownHosts < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def perform_test(source)
|
6
|
-
kh = Net::SSH::KnownHosts.new(source)
|
7
|
-
keys = kh.keys_for("github.com")
|
8
|
-
assert_equal(1, keys.count)
|
9
|
-
assert_equal("ssh-rsa", keys[0].ssh_type)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_key_for_when_all_hosts_are_recognized
|
13
|
-
perform_test(path("known_hosts/github"))
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_key_for_when_an_host_hash_is_recognized
|
17
|
-
perform_test(path("known_hosts/github_hash"))
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_missing_then_add
|
21
|
-
Tempfile.open('github') do |f|
|
22
|
-
f.write(File.read(path("known_hosts/github")))
|
23
|
-
kh = Net::SSH::KnownHosts.new(f.path)
|
24
|
-
keys = kh.keys_for("github2.com")
|
25
|
-
assert_equal(0, keys.count)
|
26
|
-
assert_equal([], keys.to_a)
|
27
|
-
|
28
|
-
kh.add('github2.com',rsa_key)
|
29
|
-
keys2 = kh.keys_for("github2.com")
|
30
|
-
assert_equal([rsa_key.to_blob], keys2.to_a.map(&:to_blob))
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_search_for
|
35
|
-
options = {user_known_hosts_file: path("known_hosts/github")}
|
36
|
-
keys = Net::SSH::KnownHosts.search_for('github.com',options)
|
37
|
-
assert_equal(["ssh-rsa"], keys.map(&:ssh_type))
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_search_for_then_add
|
41
|
-
Tempfile.open('github') do |f|
|
42
|
-
f.write(File.read(path("known_hosts/github")))
|
43
|
-
options = {user_known_hosts_file: f.path}
|
44
|
-
keys = Net::SSH::KnownHosts.search_for('github2.com',options)
|
45
|
-
assert_equal(0, keys.count)
|
46
|
-
|
47
|
-
keys.add_host_key(rsa_key)
|
48
|
-
|
49
|
-
assert_equal([rsa_key.to_blob], keys.map(&:to_blob))
|
50
|
-
keys = Net::SSH::KnownHosts.search_for('github2.com',options)
|
51
|
-
assert_equal([rsa_key.to_blob], keys.map(&:to_blob))
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
def path(relative_path)
|
57
|
-
File.join(File.dirname(__FILE__), "known_hosts/github")
|
58
|
-
end
|
59
|
-
|
60
|
-
def rsa_key
|
61
|
-
key = OpenSSL::PKey::RSA.new
|
62
|
-
key.e = 0xffeeddccbbaa9988
|
63
|
-
key.n = 0x7766554433221100
|
64
|
-
key
|
65
|
-
end
|
66
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# encoding: ASCII-8BIT
|
2
|
-
|
3
|
-
require 'common'
|
4
|
-
require 'net/ssh/transport/hmac/md5'
|
5
|
-
|
6
|
-
module Transport; module HMAC
|
7
|
-
|
8
|
-
class TestMD5 < Test::Unit::TestCase
|
9
|
-
def test_expected_digest_class
|
10
|
-
assert_equal OpenSSL::Digest::MD5, subject.digest_class
|
11
|
-
assert_equal OpenSSL::Digest::MD5, subject.new.digest_class
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_expected_key_length
|
15
|
-
assert_equal 16, subject.key_length
|
16
|
-
assert_equal 16, subject.new.key_length
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_expected_mac_length
|
20
|
-
assert_equal 16, subject.mac_length
|
21
|
-
assert_equal 16, subject.new.mac_length
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_expected_digest
|
25
|
-
hmac = subject.new("1234567890123456")
|
26
|
-
assert_equal "\275\345\006\307y~Oi\035<.\341\031\250<\257", hmac.digest("hello world")
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_key_should_be_truncated_to_required_length
|
30
|
-
hmac = subject.new("12345678901234567890")
|
31
|
-
assert_equal "1234567890123456", hmac.key
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def subject
|
37
|
-
Net::SSH::Transport::HMAC::MD5
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
end; end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# encoding: ASCII-8BIT
|
2
|
-
|
3
|
-
require 'common'
|
4
|
-
require 'transport/hmac/test_md5'
|
5
|
-
require 'net/ssh/transport/hmac/md5_96'
|
6
|
-
|
7
|
-
module Transport; module HMAC
|
8
|
-
|
9
|
-
class TestMD5_96 < TestMD5
|
10
|
-
def test_expected_mac_length
|
11
|
-
assert_equal 12, subject.mac_length
|
12
|
-
assert_equal 12, subject.new.mac_length
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_expected_digest
|
16
|
-
hmac = subject.new("1234567890123456")
|
17
|
-
assert_equal "\275\345\006\307y~Oi\035<.\341", hmac.digest("hello world")
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def subject
|
23
|
-
Net::SSH::Transport::HMAC::MD5_96
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end; end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'common'
|
2
|
-
require 'net/ssh/transport/hmac/none'
|
3
|
-
|
4
|
-
module Transport; module HMAC
|
5
|
-
|
6
|
-
class TestNone < Test::Unit::TestCase
|
7
|
-
def test_expected_digest_class
|
8
|
-
assert_equal nil, subject.digest_class
|
9
|
-
assert_equal nil, subject.new.digest_class
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_expected_key_length
|
13
|
-
assert_equal 0, subject.key_length
|
14
|
-
assert_equal 0, subject.new.key_length
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_expected_mac_length
|
18
|
-
assert_equal 0, subject.mac_length
|
19
|
-
assert_equal 0, subject.new.mac_length
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_expected_digest
|
23
|
-
hmac = subject.new("1234567890123456")
|
24
|
-
assert_equal "", hmac.digest("hello world")
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def subject
|
30
|
-
Net::SSH::Transport::HMAC::None
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end; end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# encoding: ASCII-8BIT
|
2
|
-
|
3
|
-
require 'common'
|
4
|
-
require 'net/ssh/transport/hmac/ripemd160'
|
5
|
-
|
6
|
-
module Transport; module HMAC
|
7
|
-
|
8
|
-
class TestRipemd160 < Test::Unit::TestCase
|
9
|
-
def test_expected_digest_class
|
10
|
-
assert_equal OpenSSL::Digest::RIPEMD160, subject.digest_class
|
11
|
-
assert_equal OpenSSL::Digest::RIPEMD160, subject.new.digest_class
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_expected_key_length
|
15
|
-
assert_equal 20, subject.key_length
|
16
|
-
assert_equal 20, subject.new.key_length
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_expected_mac_length
|
20
|
-
assert_equal 20, subject.mac_length
|
21
|
-
assert_equal 20, subject.new.mac_length
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_expected_digest
|
25
|
-
hmac = subject.new("1234567890123456")
|
26
|
-
assert_equal "\xE4\x10\t\xB3\xD8,\x14\xA0k\x10\xB5\x0F?\x0E\x96q\x02\x16;E", hmac.digest("hello world")
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def subject
|
32
|
-
Net::SSH::Transport::HMAC::RIPEMD160
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end; end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# encoding: ASCII-8BIT
|
2
|
-
|
3
|
-
require 'common'
|
4
|
-
require 'net/ssh/transport/hmac/sha1'
|
5
|
-
|
6
|
-
module Transport; module HMAC
|
7
|
-
|
8
|
-
class TestSHA1 < Test::Unit::TestCase
|
9
|
-
def test_expected_digest_class
|
10
|
-
assert_equal OpenSSL::Digest::SHA1, subject.digest_class
|
11
|
-
assert_equal OpenSSL::Digest::SHA1, subject.new.digest_class
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_expected_key_length
|
15
|
-
assert_equal 20, subject.key_length
|
16
|
-
assert_equal 20, subject.new.key_length
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_expected_mac_length
|
20
|
-
assert_equal 20, subject.mac_length
|
21
|
-
assert_equal 20, subject.new.mac_length
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_expected_digest
|
25
|
-
hmac = subject.new("1234567890123456")
|
26
|
-
assert_equal "\000\004W\202\204+&\335\311\251P\266\250\214\276\206;\022U\365", hmac.digest("hello world")
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def subject
|
32
|
-
Net::SSH::Transport::HMAC::SHA1
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end; end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# encoding: ASCII-8BIT
|
2
|
-
|
3
|
-
require 'common'
|
4
|
-
require 'transport/hmac/test_sha1'
|
5
|
-
require 'net/ssh/transport/hmac/sha1_96'
|
6
|
-
|
7
|
-
module Transport; module HMAC
|
8
|
-
|
9
|
-
class TestSHA1_96 < TestSHA1
|
10
|
-
def test_expected_mac_length
|
11
|
-
assert_equal 12, subject.mac_length
|
12
|
-
assert_equal 12, subject.new.mac_length
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_expected_digest
|
16
|
-
hmac = subject.new("1234567890123456")
|
17
|
-
assert_equal "\000\004W\202\204+&\335\311\251P\266", hmac.digest("hello world")
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def subject
|
23
|
-
Net::SSH::Transport::HMAC::SHA1_96
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end; end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# encoding: ASCII-8BIT
|
2
|
-
|
3
|
-
require 'common'
|
4
|
-
require 'net/ssh/transport/hmac/sha2_256'
|
5
|
-
|
6
|
-
module Transport; module HMAC
|
7
|
-
|
8
|
-
class TestSHA2_256 < Test::Unit::TestCase
|
9
|
-
def test_expected_digest_class
|
10
|
-
assert_equal OpenSSL::Digest::SHA256, subject.digest_class
|
11
|
-
assert_equal OpenSSL::Digest::SHA256, subject.new.digest_class
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_expected_key_length
|
15
|
-
assert_equal 32, subject.key_length
|
16
|
-
assert_equal 32, subject.new.key_length
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_expected_mac_length
|
20
|
-
assert_equal 32, subject.mac_length
|
21
|
-
assert_equal 32, subject.new.mac_length
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_expected_digest
|
25
|
-
hmac = subject.new("1234567890123456")
|
26
|
-
assert_equal "\x16^>\x9FhO}\xB1>(\xBAF\xFBW\xB8\xF2\xFA\x824+\xC0\x94\x95\xC2\r\xE6\x88/\xEF\t\xF5%", hmac.digest("hello world")
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def subject
|
33
|
-
Net::SSH::Transport::HMAC::SHA2_256
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end; end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# encoding: ASCII-8BIT
|
2
|
-
|
3
|
-
require 'common'
|
4
|
-
require 'transport/hmac/test_sha2_256'
|
5
|
-
require 'net/ssh/transport/hmac/sha2_256_96'
|
6
|
-
|
7
|
-
module Transport; module HMAC
|
8
|
-
|
9
|
-
class TestSHA2_256_96 < TestSHA2_256
|
10
|
-
def test_expected_mac_length
|
11
|
-
assert_equal 12, subject.mac_length
|
12
|
-
assert_equal 12, subject.new.mac_length
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_expected_digest
|
16
|
-
hmac = subject.new("1234567890123456")
|
17
|
-
assert_equal "\x16^>\x9FhO}\xB1>(\xBAF", hmac.digest("hello world")
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def subject
|
23
|
-
Net::SSH::Transport::HMAC::SHA2_256_96
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end; end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# encoding: ASCII-8BIT
|
2
|
-
|
3
|
-
require 'common'
|
4
|
-
require 'net/ssh/transport/hmac/sha2_512'
|
5
|
-
|
6
|
-
module Transport; module HMAC
|
7
|
-
|
8
|
-
class TestSHA2_512 < Test::Unit::TestCase
|
9
|
-
def test_expected_digest_class
|
10
|
-
assert_equal OpenSSL::Digest::SHA512, subject.digest_class
|
11
|
-
assert_equal OpenSSL::Digest::SHA512, subject.new.digest_class
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_expected_key_length
|
15
|
-
assert_equal 64, subject.key_length
|
16
|
-
assert_equal 64, subject.new.key_length
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_expected_mac_length
|
20
|
-
assert_equal 64, subject.mac_length
|
21
|
-
assert_equal 64, subject.new.mac_length
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_expected_digest
|
25
|
-
hmac = subject.new("1234567890123456")
|
26
|
-
assert_equal "^\xB6\"\xED\x8B\xC4\xDE\xD4\xCF\xD0\r\x18\xA0<\xF4\xB5\x01Efz\xA80i\xFC\x18\xC1\x9A+\xDD\xFE<\xA2\xFDE1Ac\xF4\xADU\r\xFB^0\x90= \x837z\xCC\xD5p4a4\x83\xC6\x04m\xAA\xC1\xC0m", hmac.digest("hello world")
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def subject
|
33
|
-
Net::SSH::Transport::HMAC::SHA2_512
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end; end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# encoding: ASCII-8BIT
|
2
|
-
|
3
|
-
require 'common'
|
4
|
-
require 'transport/hmac/test_sha2_512'
|
5
|
-
require 'net/ssh/transport/hmac/sha2_512_96'
|
6
|
-
|
7
|
-
module Transport; module HMAC
|
8
|
-
|
9
|
-
class TestSHA2_512_96 < TestSHA2_512
|
10
|
-
def test_expected_mac_length
|
11
|
-
assert_equal 12, subject.mac_length
|
12
|
-
assert_equal 12, subject.new.mac_length
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_expected_digest
|
16
|
-
hmac = subject.new("1234567890123456")
|
17
|
-
assert_equal "^\xB6\"\xED\x8B\xC4\xDE\xD4\xCF\xD0\r\x18", hmac.digest("hello world")
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def subject
|
23
|
-
Net::SSH::Transport::HMAC::SHA2_512_96
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end; end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'common'
|
2
|
-
require 'net/ssh/transport/kex/diffie_hellman_group14_sha1'
|
3
|
-
require 'transport/kex/test_diffie_hellman_group1_sha1'
|
4
|
-
require 'ostruct'
|
5
|
-
|
6
|
-
module Transport; module Kex
|
7
|
-
|
8
|
-
class TestDiffieHellmanGroup14SHA1 < TestDiffieHellmanGroup1SHA1
|
9
|
-
def subject
|
10
|
-
Net::SSH::Transport::Kex::DiffieHellmanGroup14SHA1
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end; end
|
@@ -1,150 +0,0 @@
|
|
1
|
-
require 'common'
|
2
|
-
require 'net/ssh/transport/kex/diffie_hellman_group1_sha1'
|
3
|
-
require 'ostruct'
|
4
|
-
|
5
|
-
module Transport; module Kex
|
6
|
-
|
7
|
-
class TestDiffieHellmanGroup1SHA1 < Test::Unit::TestCase
|
8
|
-
include Net::SSH::Transport::Constants
|
9
|
-
|
10
|
-
def setup
|
11
|
-
@dh_options = @dh = @algorithms = @connection = @server_key =
|
12
|
-
@packet_data = @shared_secret = nil
|
13
|
-
end
|
14
|
-
|
15
|
-
def digest_type
|
16
|
-
OpenSSL::Digest::SHA1
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_exchange_keys_should_return_expected_results_when_successful
|
20
|
-
result = exchange!
|
21
|
-
assert_equal session_id, result[:session_id]
|
22
|
-
assert_equal server_key.to_blob, result[:server_key].to_blob
|
23
|
-
assert_equal shared_secret, result[:shared_secret]
|
24
|
-
assert_equal digest_type, result[:hashing_algorithm]
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_exchange_keys_with_unverifiable_host_should_raise_exception
|
28
|
-
connection.verifier { false }
|
29
|
-
assert_raises(Net::SSH::Exception) { exchange! }
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_exchange_keys_with_signature_key_type_mismatch_should_raise_exception
|
33
|
-
assert_raises(Net::SSH::Exception) { exchange! :key_type => "ssh-dss" }
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_exchange_keys_with_host_key_type_mismatch_should_raise_exception
|
37
|
-
algorithms :host_key => "ssh-dss"
|
38
|
-
assert_raises(Net::SSH::Exception) { exchange! :key_type => "ssh-dss" }
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_exchange_keys_when_server_signature_could_not_be_verified_should_raise_exception
|
42
|
-
@signature = "1234567890"
|
43
|
-
assert_raises(Net::SSH::Exception) { exchange! }
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_exchange_keys_should_pass_expected_parameters_to_host_key_verifier
|
47
|
-
verified = false
|
48
|
-
connection.verifier do |data|
|
49
|
-
verified = true
|
50
|
-
assert_equal server_key.to_blob, data[:key].to_blob
|
51
|
-
|
52
|
-
blob = b(:key, data[:key]).to_s
|
53
|
-
fingerprint = OpenSSL::Digest::MD5.hexdigest(blob).scan(/../).join(":")
|
54
|
-
|
55
|
-
assert_equal blob, data[:key_blob]
|
56
|
-
assert_equal fingerprint, data[:fingerprint]
|
57
|
-
assert_equal connection, data[:session]
|
58
|
-
|
59
|
-
true
|
60
|
-
end
|
61
|
-
|
62
|
-
assert_nothing_raised { exchange! }
|
63
|
-
assert verified
|
64
|
-
end
|
65
|
-
|
66
|
-
private
|
67
|
-
|
68
|
-
def exchange!(options={})
|
69
|
-
connection.expect do |t, buffer|
|
70
|
-
assert_equal KEXDH_INIT, buffer.type
|
71
|
-
assert_equal dh.dh.pub_key, buffer.read_bignum
|
72
|
-
t.return(KEXDH_REPLY, :string, b(:key, server_key), :bignum, server_dh_pubkey, :string, b(:string, options[:key_type] || "ssh-rsa", :string, signature))
|
73
|
-
connection.expect do |t2, buffer2|
|
74
|
-
assert_equal NEWKEYS, buffer2.type
|
75
|
-
t2.return(NEWKEYS)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
dh.exchange_keys
|
80
|
-
end
|
81
|
-
|
82
|
-
def dh_options(options={})
|
83
|
-
@dh_options = options
|
84
|
-
end
|
85
|
-
|
86
|
-
def dh
|
87
|
-
@dh ||= subject.new(algorithms, connection, packet_data.merge(:need_bytes => 20).merge(@dh_options || {}))
|
88
|
-
end
|
89
|
-
|
90
|
-
def algorithms(options={})
|
91
|
-
@algorithms ||= OpenStruct.new(:host_key => options[:host_key] || "ssh-rsa")
|
92
|
-
end
|
93
|
-
|
94
|
-
def connection
|
95
|
-
@connection ||= MockTransport.new
|
96
|
-
end
|
97
|
-
|
98
|
-
def subject
|
99
|
-
Net::SSH::Transport::Kex::DiffieHellmanGroup1SHA1
|
100
|
-
end
|
101
|
-
|
102
|
-
# 512 bits is the smallest possible key that will work with this, so
|
103
|
-
# we use it for speed reasons
|
104
|
-
def server_key(bits=512)
|
105
|
-
@server_key ||= OpenSSL::PKey::RSA.new(bits)
|
106
|
-
end
|
107
|
-
|
108
|
-
def packet_data
|
109
|
-
@packet_data ||= { :client_version_string => "client version string",
|
110
|
-
:server_version_string => "server version string",
|
111
|
-
:server_algorithm_packet => "server algorithm packet",
|
112
|
-
:client_algorithm_packet => "client algorithm packet" }
|
113
|
-
end
|
114
|
-
|
115
|
-
def server_dh_pubkey
|
116
|
-
@server_dh_pubkey ||= bn(1234567890)
|
117
|
-
end
|
118
|
-
|
119
|
-
def shared_secret
|
120
|
-
@shared_secret ||= OpenSSL::BN.new(dh.dh.compute_key(server_dh_pubkey), 2)
|
121
|
-
end
|
122
|
-
|
123
|
-
def session_id
|
124
|
-
@session_id ||= begin
|
125
|
-
buffer = Net::SSH::Buffer.from(:string, packet_data[:client_version_string],
|
126
|
-
:string, packet_data[:server_version_string],
|
127
|
-
:string, packet_data[:client_algorithm_packet],
|
128
|
-
:string, packet_data[:server_algorithm_packet],
|
129
|
-
:string, Net::SSH::Buffer.from(:key, server_key),
|
130
|
-
:bignum, dh.dh.pub_key,
|
131
|
-
:bignum, server_dh_pubkey,
|
132
|
-
:bignum, shared_secret)
|
133
|
-
OpenSSL::Digest::SHA1.digest(buffer.to_s)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def signature
|
138
|
-
@signature ||= server_key.ssh_do_sign(session_id)
|
139
|
-
end
|
140
|
-
|
141
|
-
def bn(number, base=10)
|
142
|
-
OpenSSL::BN.new(number.to_s, base)
|
143
|
-
end
|
144
|
-
|
145
|
-
def b(*args)
|
146
|
-
Net::SSH::Buffer.from(*args)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
end; end
|