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
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'common'
|
2
|
-
require 'fileutils'
|
3
|
-
require 'tmpdir'
|
4
|
-
|
5
|
-
require 'net/ssh'
|
6
|
-
|
7
|
-
# see Vagrantfile,playbook for env.
|
8
|
-
# we're running as net_ssh_1 user password foo
|
9
|
-
# and usually connecting to net_ssh_2 user password foo2pwd
|
10
|
-
class TestIDRSAPKeys < Test::Unit::TestCase
|
11
|
-
include IntegrationTestHelpers
|
12
|
-
|
13
|
-
def test_in_file_no_password
|
14
|
-
tmpdir do |dir|
|
15
|
-
sh "rm -rf #{dir}/id_rsa #{dir}/id_rsa.pub"
|
16
|
-
sh "ssh-keygen -q -f #{dir}/id_rsa -t rsa -N ''"
|
17
|
-
set_authorized_key('net_ssh_1',"#{dir}/id_rsa.pub")
|
18
|
-
|
19
|
-
#sshopts = '-vvvv -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
|
20
|
-
#sh "ssh -i #{dir}/id_rsa #{sshopts} net_ssh_1@localhost echo 'hello'"
|
21
|
-
|
22
|
-
ret = Net::SSH.start("localhost", "net_ssh_1", {keys: "#{dir}/id_rsa"}) do |ssh|
|
23
|
-
ssh.exec! 'echo "hello from:$USER"'
|
24
|
-
end
|
25
|
-
assert_equal "hello from:net_ssh_1\n", ret
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
def test_ssh_agent
|
31
|
-
tmpdir do |dir|
|
32
|
-
with_agent do
|
33
|
-
sh "rm -rf #{dir}/id_rsa #{dir}/id_rsa.pub"
|
34
|
-
sh "ssh-keygen -q -f #{dir}/id_rsa -t rsa -N 'pwd123'"
|
35
|
-
set_authorized_key('net_ssh_1',"#{dir}/id_rsa.pub")
|
36
|
-
ssh_add("#{dir}/id_rsa","pwd123")
|
37
|
-
|
38
|
-
ret = Net::SSH.start("localhost", "net_ssh_1") do |ssh|
|
39
|
-
ssh.exec! 'echo "hello from:$USER"'
|
40
|
-
end
|
41
|
-
assert_equal "hello from:net_ssh_1\n", ret
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_ssh_agent_ignores_if_already_in_agent
|
47
|
-
tmpdir do |dir|
|
48
|
-
with_agent do
|
49
|
-
sh "rm -rf #{dir}/id_rsa #{dir}/id_rsa.pub"
|
50
|
-
sh "ssh-keygen -q -f #{dir}/id_rsa -t rsa -N 'pwd123'"
|
51
|
-
set_authorized_key('net_ssh_1',"#{dir}/id_rsa.pub")
|
52
|
-
ssh_add("#{dir}/id_rsa","pwd123")
|
53
|
-
|
54
|
-
ret = Net::SSH.start("localhost", "net_ssh_1", keys: ["#{dir}/id_rsa"]) do |ssh|
|
55
|
-
ssh.exec! 'echo "hello from:$USER"'
|
56
|
-
end
|
57
|
-
assert_equal "hello from:net_ssh_1\n", ret
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_in_file_with_password
|
63
|
-
tmpdir do |dir|
|
64
|
-
sh "rm -rf #{dir}/id_rsa #{dir}/id_rsa.pub"
|
65
|
-
sh "ssh-keygen -q -f #{dir}/id_rsa -t rsa -N 'pwd12'"
|
66
|
-
set_authorized_key('net_ssh_1',"#{dir}/id_rsa.pub")
|
67
|
-
|
68
|
-
#sshopts = '-vvvv -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
|
69
|
-
#sh "ssh -i #{dir}/id_rsa #{sshopts} net_ssh_1@localhost echo 'hello'"
|
70
|
-
|
71
|
-
ret = Net::SSH.start("localhost", "net_ssh_1", {keys: "#{dir}/id_rsa",
|
72
|
-
passphrase: 'pwd12'}) do |ssh|
|
73
|
-
ssh.exec! 'echo "hello from:$USER"'
|
74
|
-
end
|
75
|
-
assert_equal "hello from:net_ssh_1\n", ret
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_asks_for_passwords_when_read_from_memory
|
80
|
-
tmpdir do |dir|
|
81
|
-
sh "rm -rf #{dir}/id_rsa #{dir}/id_rsa.pub"
|
82
|
-
sh "ssh-keygen -q -f #{dir}/id_rsa -t rsa -N 'pwd12'"
|
83
|
-
set_authorized_key('net_ssh_1',"#{dir}/id_rsa.pub")
|
84
|
-
private_key = File.read("#{dir}/id_rsa")
|
85
|
-
|
86
|
-
options = {keys: [], key_data: [private_key]}
|
87
|
-
|
88
|
-
#key_manager = Net::SSH::Authentication::KeyManager.new(nil, options)
|
89
|
-
|
90
|
-
Net::SSH::KeyFactory.expects(:prompt).with('Enter passphrase for :', false).returns('pwd12')
|
91
|
-
Net::SSH.start("localhost", "net_ssh_1", options) do |ssh|
|
92
|
-
ssh.exec! 'whoami'
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
require_relative './common'
|
2
|
-
require 'net/ssh/buffer'
|
3
|
-
require 'net/ssh'
|
4
|
-
require 'timeout'
|
5
|
-
require 'tempfile'
|
6
|
-
require 'net/ssh/proxy/command'
|
7
|
-
|
8
|
-
class TestProxy < Test::Unit::TestCase
|
9
|
-
include IntegrationTestHelpers
|
10
|
-
|
11
|
-
def localhost
|
12
|
-
'localhost'
|
13
|
-
end
|
14
|
-
|
15
|
-
def user
|
16
|
-
'net_ssh_1'
|
17
|
-
end
|
18
|
-
|
19
|
-
def ssh_start_params(options)
|
20
|
-
[localhost ,user , {:keys => @key_id_rsa}.merge(options)]
|
21
|
-
end
|
22
|
-
|
23
|
-
def setup_ssh_env(&block)
|
24
|
-
tmpdir do |dir|
|
25
|
-
@key_id_rsa = "#{dir}/id_rsa"
|
26
|
-
sh "rm -rf #{@key_id_rsa} #{@key_id_rsa}.pub"
|
27
|
-
sh "ssh-keygen -q -f #{@key_id_rsa} -t rsa -N ''"
|
28
|
-
set_authorized_key(user,"#{@key_id_rsa}.pub")
|
29
|
-
yield
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_smoke
|
34
|
-
setup_ssh_env do
|
35
|
-
proxy = Net::SSH::Proxy::Command.new("/bin/nc localhost 22")
|
36
|
-
msg = 'echo123'
|
37
|
-
ret = Net::SSH.start(*ssh_start_params(:proxy => proxy)) do |ssh|
|
38
|
-
ssh.exec! "echo \"$USER:#{msg}\""
|
39
|
-
end
|
40
|
-
assert_equal "net_ssh_1:#{msg}\n", ret
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def with_spurious_write_wakeup_emulate(rate=99,&block)
|
45
|
-
orig_io_select = Net::SSH::Compat.method(:io_select)
|
46
|
-
count = 0
|
47
|
-
Net::SSH::Compat.singleton_class.send(:define_method,:io_select) do |*params|
|
48
|
-
count += 1
|
49
|
-
if (count % rate != 0)
|
50
|
-
if params && params[1] && !params[1].empty?
|
51
|
-
return [[],params[1],[]]
|
52
|
-
end
|
53
|
-
#if params && params[0] && !params[0].empty?
|
54
|
-
#return [params[0],[],[]]
|
55
|
-
#end
|
56
|
-
end
|
57
|
-
IO.select(*params)
|
58
|
-
end
|
59
|
-
begin
|
60
|
-
yield
|
61
|
-
ensure
|
62
|
-
Net::SSH::Compat.singleton_class.send(:define_method,:io_select,&orig_io_select)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_with_rate_limit_and_spurious_wakeup
|
67
|
-
system("sudo sh -c 'echo 4096 > /proc/sys/fs/pipe-max-size'")
|
68
|
-
begin
|
69
|
-
setup_ssh_env do
|
70
|
-
proxy = Net::SSH::Proxy::Command.new("/usr/bin/pv --rate-limit 100k | /bin/nc localhost 22")
|
71
|
-
#proxy = Net::SSH::Proxy::Command.new("/bin/nc localhost 22")
|
72
|
-
begin
|
73
|
-
large_msg = 'echo123'*30000
|
74
|
-
ok = Net::SSH.start(*ssh_start_params(:proxy => proxy)) do |ssh|
|
75
|
-
with_spurious_write_wakeup_emulate do
|
76
|
-
ret = ssh.exec! "echo \"$USER:#{large_msg}\""
|
77
|
-
#assert_equal "net_ssh_1:#{large_msg}\n", ret
|
78
|
-
assert_equal "/bin/sh: Argument list too long\n", ret
|
79
|
-
hello_count = 1000
|
80
|
-
ret = ssh.exec! "ruby -e 'puts \"Hello\"*#{hello_count}'"
|
81
|
-
assert_equal "Hello"*hello_count+"\n", ret
|
82
|
-
end
|
83
|
-
:ok
|
84
|
-
end
|
85
|
-
end
|
86
|
-
assert_equal :ok, ok
|
87
|
-
end
|
88
|
-
ensure
|
89
|
-
system("sudo sh -c 'echo 1048576 > /proc/sys/fs/pipe-max-size'")
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
data/test/known_hosts/github
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
|
@@ -1 +0,0 @@
|
|
1
|
-
|1|eKp+6E0rZ3lONgsIziurXEnaIik=|rcQB/rlJMUquUyFta64KugPjX4o= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
|
data/test/manual/test_pageant.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Tests for communication capability with Pageant (or KeeAgent)
|
3
|
-
# process, to include the case where it is running in different UAC
|
4
|
-
# context.
|
5
|
-
#
|
6
|
-
# To run:
|
7
|
-
# - Ensure that Pageant is running (not as administrator).
|
8
|
-
# - Open two command prompts, one as an administrator and one limited
|
9
|
-
# (normal).
|
10
|
-
# - Within each, from the root net/ssh project directory, execute:
|
11
|
-
# ruby -Ilib -Itest -rrubygems test/manual/test_pageant.rb
|
12
|
-
#
|
13
|
-
|
14
|
-
require 'common'
|
15
|
-
require 'net/ssh/authentication/agent'
|
16
|
-
|
17
|
-
module Authentication
|
18
|
-
|
19
|
-
class TestPageant < Test::Unit::TestCase
|
20
|
-
|
21
|
-
def test_agent_should_be_able_to_negotiate
|
22
|
-
assert_nothing_raised(Net::SSH::Authentication::AgentNotAvailable) { agent.negotiate! }
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def agent(auto=:connect)
|
28
|
-
@agent ||= begin
|
29
|
-
agent = Net::SSH::Authentication::Agent.new
|
30
|
-
agent.connect! if auto == :connect
|
31
|
-
agent
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'common'
|
2
|
-
require 'net/ssh'
|
3
|
-
|
4
|
-
module NetSSH
|
5
|
-
class TestConnection < Test::Unit::TestCase
|
6
|
-
attr_reader :connection_session
|
7
|
-
|
8
|
-
def setup
|
9
|
-
authentication_session = mock('authentication_session')
|
10
|
-
authentication_session.stubs(:authenticate).returns(true)
|
11
|
-
Net::SSH::Authentication::Session.stubs(:new).returns(authentication_session)
|
12
|
-
Net::SSH::Transport::Session.stubs(:new).returns(mock('transport_session'))
|
13
|
-
@connection_session = mock('connection_session')
|
14
|
-
Net::SSH::Connection::Session.expects(:new => connection_session)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_close_connection_on_exception
|
18
|
-
@connection_session.expects(:closed?).returns(false)
|
19
|
-
@connection_session.expects(:close).once
|
20
|
-
|
21
|
-
begin
|
22
|
-
Net::SSH.start('localhost', 'testuser') { raise "error" }
|
23
|
-
rescue RuntimeError
|
24
|
-
# We aren't interested in the exception
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_close_connection_on_exception_only_if_still_open
|
29
|
-
conn_open = states('conn').starts_as(true)
|
30
|
-
@connection_session.expects(:close).then(conn_open.is(false)).once
|
31
|
-
@connection_session.expects(:closed?).when(conn_open.is(false)).returns(true)
|
32
|
-
|
33
|
-
begin
|
34
|
-
Net::SSH.start('localhost', 'testuser') do |ssh|
|
35
|
-
ssh.close
|
36
|
-
raise "error"
|
37
|
-
end
|
38
|
-
rescue RuntimeError
|
39
|
-
# We aren't interested in the exception
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_return_value_is_returned
|
44
|
-
@connection_session.expects(:closed?).returns(false)
|
45
|
-
@connection_session.expects(:close).once
|
46
|
-
|
47
|
-
val = 1
|
48
|
-
retval = Net::SSH.start('localhost', 'testuser') { val }
|
49
|
-
assert_equal(val, retval)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
data/test/start/test_options.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'common'
|
2
|
-
require 'net/ssh'
|
3
|
-
|
4
|
-
module NetSSH
|
5
|
-
class TestStartOptions < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
authentication_session = mock('authentication_session')
|
8
|
-
authentication_session.stubs(:authenticate).returns(true)
|
9
|
-
Net::SSH::Authentication::Session.stubs(:new).returns(authentication_session)
|
10
|
-
Net::SSH::Transport::Session.stubs(:new).returns(mock('transport_session'))
|
11
|
-
Net::SSH::Connection::Session.stubs(:new).returns(mock('connection_session'))
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_start_should_accept_keepalive_option
|
15
|
-
assert_nothing_raised do
|
16
|
-
options = { :keepalive => true }
|
17
|
-
Net::SSH.start('localhost', 'testuser', options)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_start_should_accept_keepalive_interval_option
|
22
|
-
assert_nothing_raised do
|
23
|
-
options = { :keepalive_interval => 10 }
|
24
|
-
Net::SSH.start('localhost', 'testuser', options)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_start_should_accept_send_env_option
|
29
|
-
assert_nothing_raised do
|
30
|
-
options = { :send_env => [ /^LC_.*$/, "LANG" ] }
|
31
|
-
Net::SSH.start('localhost', 'testuser', options)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_start_should_accept_number_of_password_prompts_option
|
36
|
-
assert_nothing_raised do
|
37
|
-
options = { :number_of_password_prompts => 2 }
|
38
|
-
Net::SSH.start('localhost', 'testuser', options)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_start_should_accept_non_interactive_option
|
43
|
-
assert_nothing_raised do
|
44
|
-
options = { :non_interactive => true }
|
45
|
-
Net::SSH.start('localhost', 'testuser', options)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_start_should_accept_remote_user_option
|
50
|
-
assert_nothing_raised do
|
51
|
-
options = { :remote_user => 'foo' }
|
52
|
-
Net::SSH.start('localhost', 'testuser', options)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'common'
|
2
|
-
require 'net/ssh'
|
3
|
-
|
4
|
-
module NetSSH
|
5
|
-
class TestStart < Test::Unit::TestCase
|
6
|
-
attr_reader :transport_session
|
7
|
-
attr_reader :authentication_session
|
8
|
-
|
9
|
-
def setup
|
10
|
-
@transport_session = mock('transport_session')
|
11
|
-
@authentication_session = mock('authentication_session')
|
12
|
-
Net::SSH::Transport::Session.expects(:new => transport_session)
|
13
|
-
Net::SSH::Authentication::Session.expects(:new => authentication_session)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_close_transport_when_authentication_fails
|
17
|
-
authentication_session.expects(:authenticate => false)
|
18
|
-
|
19
|
-
transport_session.expects(:close).at_least_once
|
20
|
-
|
21
|
-
begin
|
22
|
-
Net::SSH.start('localhost', 'testuser') {}
|
23
|
-
rescue Net::SSH::AuthenticationFailed
|
24
|
-
# Authentication should fail, as it is part of the context
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/test/start/test_user_nil.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'common'
|
2
|
-
require 'net/ssh'
|
3
|
-
|
4
|
-
module NetSSH
|
5
|
-
class TestStartUserNil < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
@authentication_session = mock('authentication_session')
|
8
|
-
Net::SSH::Authentication::Session.stubs(:new).returns(@authentication_session)
|
9
|
-
Net::SSH::Transport::Session.stubs(:new).returns(mock('transport_session'))
|
10
|
-
Net::SSH::Connection::Session.stubs(:new).returns(mock('connection_session'))
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_start_should_accept_nil_user
|
14
|
-
@authentication_session.stubs(:authenticate).returns(true)
|
15
|
-
assert_nothing_raised do
|
16
|
-
Net::SSH.start('localhost')
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_start_should_use_default_user_when_nil
|
21
|
-
@authentication_session.stubs(:authenticate).with() {|_next_service, user, _password| user == Etc.getlogin }.returns(true)
|
22
|
-
assert_nothing_raised do
|
23
|
-
Net::SSH.start('localhost')
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/test/test_all.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
$: << '.'
|
2
|
-
|
3
|
-
# $ ruby -Ilib -Itest -rrubygems test/test_all.rb
|
4
|
-
# $ ruby -Ilib -Itest -rrubygems test/transport/test_server_version.rb
|
5
|
-
Dir.chdir(File.dirname(__FILE__)) do
|
6
|
-
test_files = Dir['**/test_*.rb']-['test_all.rb'] # prevent circular require
|
7
|
-
test_files -= Dir['integration/test_*.rb'] unless ENV['NET_SSH_RUN_INTEGRATION_TESTS']
|
8
|
-
test_files = test_files.reject { |f| f =~ /^manual/ }
|
9
|
-
test_files = test_files.select { |f| f =~ Regexp.new(ENV['ONLY']) } if ENV['ONLY']
|
10
|
-
test_files = test_files.reject { |f| f =~ Regexp.new(ENV['EXCEPT']) } if ENV['EXCEPT']
|
11
|
-
test_files.each { |file| require(file) }
|
12
|
-
end
|
data/test/test_buffer.rb
DELETED
@@ -1,433 +0,0 @@
|
|
1
|
-
# encoding: ASCII-8BIT
|
2
|
-
|
3
|
-
require 'common'
|
4
|
-
require 'net/ssh/buffer'
|
5
|
-
|
6
|
-
class TestBuffer < Test::Unit::TestCase
|
7
|
-
def test_constructor_should_initialize_buffer_to_empty_by_default
|
8
|
-
buffer = new
|
9
|
-
assert buffer.empty?
|
10
|
-
assert_equal 0, buffer.position
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_constructor_with_string_should_initialize_buffer_to_the_string
|
14
|
-
buffer = new("hello")
|
15
|
-
assert !buffer.empty?
|
16
|
-
assert_equal "hello", buffer.to_s
|
17
|
-
assert_equal 0, buffer.position
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_from_should_require_an_even_number_of_arguments
|
21
|
-
assert_raises(ArgumentError) { Net::SSH::Buffer.from("this") }
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_from_should_build_new_buffer_from_definition
|
25
|
-
buffer = Net::SSH::Buffer.from(:byte, 1, :long, 2, :int64, 3, :string, "4", :bool, true, :bool, false, :bignum, OpenSSL::BN.new("1234567890", 10), :raw, "something")
|
26
|
-
assert_equal "\1\0\0\0\2\0\0\0\0\0\0\0\3\0\0\0\0014\1\0\000\000\000\004I\226\002\322something", buffer.to_s
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_from_with_array_argument_should_write_multiple_of_the_given_type
|
30
|
-
buffer = Net::SSH::Buffer.from(:byte, [1,2,3,4,5])
|
31
|
-
assert_equal "\1\2\3\4\5", buffer.to_s
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_from_should_measure_bytesize_of_utf_8_string_correctly
|
35
|
-
buffer = Net::SSH::Buffer.from(:string, "\u2603") # Snowman is 3 bytes
|
36
|
-
assert_equal "\0\0\0\3\u2603", buffer.to_s
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_read_without_argument_should_read_to_end
|
40
|
-
buffer = new("hello world")
|
41
|
-
assert_equal "hello world", buffer.read
|
42
|
-
assert buffer.eof?
|
43
|
-
assert_equal 11, buffer.position
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_read_with_argument_that_is_less_than_length_should_read_that_many_bytes
|
47
|
-
buffer = new "hello world"
|
48
|
-
assert_equal "hello", buffer.read(5)
|
49
|
-
assert_equal 5, buffer.position
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_read_with_argument_that_is_more_than_length_should_read_no_more_than_length
|
53
|
-
buffer = new "hello world"
|
54
|
-
assert_equal "hello world", buffer.read(500)
|
55
|
-
assert_equal 11, buffer.position
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_read_at_eof_should_return_empty_string
|
59
|
-
buffer = new "hello"
|
60
|
-
buffer.position = 5
|
61
|
-
assert_equal "", buffer.read
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_consume_without_argument_should_resize_buffer_to_start_at_position
|
65
|
-
buffer = new "hello world"
|
66
|
-
buffer.read(5)
|
67
|
-
assert_equal 5, buffer.position
|
68
|
-
assert_equal 11, buffer.length
|
69
|
-
buffer.consume!
|
70
|
-
assert_equal 0, buffer.position
|
71
|
-
assert_equal 6, buffer.length
|
72
|
-
assert_equal " world", buffer.to_s
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_consume_with_argument_should_resize_buffer_starting_at_n
|
76
|
-
buffer = new "hello world"
|
77
|
-
assert_equal 0, buffer.position
|
78
|
-
buffer.consume!(5)
|
79
|
-
assert_equal 0, buffer.position
|
80
|
-
assert_equal 6, buffer.length
|
81
|
-
assert_equal " world", buffer.to_s
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_read_bang_should_read_and_consume_and_return_read_portion
|
85
|
-
buffer = new "hello world"
|
86
|
-
assert_equal "hello", buffer.read!(5)
|
87
|
-
assert_equal 0, buffer.position
|
88
|
-
assert_equal 6, buffer.length
|
89
|
-
assert_equal " world", buffer.to_s
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_available_should_return_length_after_position_to_end_of_string
|
93
|
-
buffer = new "hello world"
|
94
|
-
buffer.read(5)
|
95
|
-
assert_equal 6, buffer.available
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_clear_bang_should_reset_buffer_contents_and_counters
|
99
|
-
buffer = new "hello world"
|
100
|
-
buffer.read(5)
|
101
|
-
buffer.clear!
|
102
|
-
assert_equal 0, buffer.length
|
103
|
-
assert_equal 0, buffer.position
|
104
|
-
assert_equal "", buffer.to_s
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_append_should_append_argument_without_changing_position_and_should_return_self
|
108
|
-
buffer = new "hello world"
|
109
|
-
buffer.read(5)
|
110
|
-
buffer.append(" again")
|
111
|
-
assert_equal 5, buffer.position
|
112
|
-
assert_equal 12, buffer.available
|
113
|
-
assert_equal 17, buffer.length
|
114
|
-
assert_equal "hello world again", buffer.to_s
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_remainder_as_buffer_should_return_a_new_buffer_filled_with_the_text_after_the_current_position
|
118
|
-
buffer = new "hello world"
|
119
|
-
buffer.read(6)
|
120
|
-
b2 = buffer.remainder_as_buffer
|
121
|
-
assert_equal 6, buffer.position
|
122
|
-
assert_equal 0, b2.position
|
123
|
-
assert_equal "world", b2.to_s
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_read_int64_should_return_8_byte_integer
|
127
|
-
buffer = new "\xff\xee\xdd\xcc\xbb\xaa\x99\x88"
|
128
|
-
assert_equal 0xffeeddccbbaa9988, buffer.read_int64
|
129
|
-
assert_equal 8, buffer.position
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_read_int64_should_return_nil_on_partial_read
|
133
|
-
buffer = new "\0\0\0\0\0\0\0"
|
134
|
-
assert_nil buffer.read_int64
|
135
|
-
assert buffer.eof?
|
136
|
-
end
|
137
|
-
|
138
|
-
def test_read_long_should_return_4_byte_integer
|
139
|
-
buffer = new "\xff\xee\xdd\xcc\xbb\xaa\x99\x88"
|
140
|
-
assert_equal 0xffeeddcc, buffer.read_long
|
141
|
-
assert_equal 4, buffer.position
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_read_long_should_return_nil_on_partial_read
|
145
|
-
buffer = new "\0\0\0"
|
146
|
-
assert_nil buffer.read_long
|
147
|
-
assert buffer.eof?
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_read_byte_should_return_single_byte_integer
|
151
|
-
buffer = new "\xfe\xdc"
|
152
|
-
assert_equal 0xfe, buffer.read_byte
|
153
|
-
assert_equal 1, buffer.position
|
154
|
-
end
|
155
|
-
|
156
|
-
def test_read_byte_should_return_nil_at_eof
|
157
|
-
assert_nil new.read_byte
|
158
|
-
end
|
159
|
-
|
160
|
-
def test_read_string_should_read_length_and_data_from_buffer
|
161
|
-
buffer = new "\0\0\0\x0bhello world"
|
162
|
-
assert_equal "hello world", buffer.read_string
|
163
|
-
end
|
164
|
-
|
165
|
-
def test_read_string_should_return_nil_if_4_byte_length_cannot_be_read
|
166
|
-
assert_nil new("\0\1").read_string
|
167
|
-
end
|
168
|
-
|
169
|
-
def test_read_bool_should_return_true_if_non_zero_byte_is_read
|
170
|
-
buffer = new "\1\2\3\4\5\6"
|
171
|
-
6.times { assert_equal true, buffer.read_bool }
|
172
|
-
end
|
173
|
-
|
174
|
-
def test_read_bool_should_return_false_if_zero_byte_is_read
|
175
|
-
buffer = new "\0"
|
176
|
-
assert_equal false, buffer.read_bool
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_read_bool_should_return_nil_at_eof
|
180
|
-
assert_nil new.read_bool
|
181
|
-
end
|
182
|
-
|
183
|
-
def test_read_bignum_should_read_openssl_formatted_bignum
|
184
|
-
buffer = new("\000\000\000\004I\226\002\322")
|
185
|
-
assert_equal OpenSSL::BN.new("1234567890", 10), buffer.read_bignum
|
186
|
-
end
|
187
|
-
|
188
|
-
def test_read_bignum_should_return_nil_if_length_cannot_be_read
|
189
|
-
assert_nil new("\0\1\2").read_bignum
|
190
|
-
end
|
191
|
-
|
192
|
-
def test_read_key_blob_should_read_dsa_keys
|
193
|
-
random_dss { |buffer| buffer.read_keyblob("ssh-dss") }
|
194
|
-
end
|
195
|
-
|
196
|
-
def test_read_key_blob_should_read_rsa_keys
|
197
|
-
random_rsa { |buffer| buffer.read_keyblob("ssh-rsa") }
|
198
|
-
end
|
199
|
-
|
200
|
-
def test_read_key_should_read_dsa_key_type_and_keyblob
|
201
|
-
random_dss do |buffer|
|
202
|
-
b2 = Net::SSH::Buffer.from(:string, "ssh-dss", :raw, buffer)
|
203
|
-
b2.read_key
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
def test_read_key_should_read_rsa_key_type_and_keyblob
|
208
|
-
random_rsa do |buffer|
|
209
|
-
b2 = Net::SSH::Buffer.from(:string, "ssh-rsa", :raw, buffer)
|
210
|
-
b2.read_key
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
def test_read_buffer_should_read_a_string_and_return_it_wrapped_in_a_buffer
|
215
|
-
buffer = new("\0\0\0\x0bhello world")
|
216
|
-
b2 = buffer.read_buffer
|
217
|
-
assert_equal 0, b2.position
|
218
|
-
assert_equal 11, b2.length
|
219
|
-
assert_equal "hello world", b2.read
|
220
|
-
end
|
221
|
-
|
222
|
-
def test_read_to_should_return_nil_if_pattern_does_not_exist_in_buffer
|
223
|
-
buffer = new("one two three")
|
224
|
-
assert_nil buffer.read_to("\n")
|
225
|
-
end
|
226
|
-
|
227
|
-
def test_read_to_should_grok_string_patterns
|
228
|
-
buffer = new("one two three")
|
229
|
-
assert_equal "one tw", buffer.read_to("tw")
|
230
|
-
assert_equal 6, buffer.position
|
231
|
-
end
|
232
|
-
|
233
|
-
def test_read_to_should_grok_regex_patterns
|
234
|
-
buffer = new("one two three")
|
235
|
-
assert_equal "one tw", buffer.read_to(/tw/)
|
236
|
-
assert_equal 6, buffer.position
|
237
|
-
end
|
238
|
-
|
239
|
-
def test_read_to_should_grok_fixnum_patterns
|
240
|
-
buffer = new("one two three")
|
241
|
-
assert_equal "one tw", buffer.read_to(?w)
|
242
|
-
assert_equal 6, buffer.position
|
243
|
-
end
|
244
|
-
|
245
|
-
def test_reset_bang_should_reset_position_to_0
|
246
|
-
buffer = new("hello world")
|
247
|
-
buffer.read(5)
|
248
|
-
assert_equal 5, buffer.position
|
249
|
-
buffer.reset!
|
250
|
-
assert_equal 0, buffer.position
|
251
|
-
end
|
252
|
-
|
253
|
-
def test_write_should_write_arguments_directly_to_end_buffer
|
254
|
-
buffer = new("start")
|
255
|
-
buffer.write "hello", " ", "world"
|
256
|
-
assert_equal "starthello world", buffer.to_s
|
257
|
-
assert_equal 0, buffer.position
|
258
|
-
end
|
259
|
-
|
260
|
-
def test_write_int64_should_write_arguments_as_8_byte_integers_to_end_of_buffer
|
261
|
-
buffer = new("start")
|
262
|
-
buffer.write_int64 0xffeeddccbbaa9988, 0x7766554433221100
|
263
|
-
assert_equal "start\xff\xee\xdd\xcc\xbb\xaa\x99\x88\x77\x66\x55\x44\x33\x22\x11\x00", buffer.to_s
|
264
|
-
end
|
265
|
-
|
266
|
-
def test_write_long_should_write_arguments_as_4_byte_integers_to_end_of_buffer
|
267
|
-
buffer = new("start")
|
268
|
-
buffer.write_long 0xffeeddcc, 0xbbaa9988
|
269
|
-
assert_equal "start\xff\xee\xdd\xcc\xbb\xaa\x99\x88", buffer.to_s
|
270
|
-
end
|
271
|
-
|
272
|
-
def test_write_byte_should_write_arguments_as_1_byte_integers_to_end_of_buffer
|
273
|
-
buffer = new("start")
|
274
|
-
buffer.write_byte 1, 2, 3, 4, 5
|
275
|
-
assert_equal "start\1\2\3\4\5", buffer.to_s
|
276
|
-
end
|
277
|
-
|
278
|
-
def test_write_bool_should_write_arguments_as_1_byte_boolean_values_to_end_of_buffer
|
279
|
-
buffer = new("start")
|
280
|
-
buffer.write_bool nil, false, true, 1, Object.new
|
281
|
-
assert_equal "start\0\0\1\1\1", buffer.to_s
|
282
|
-
end
|
283
|
-
|
284
|
-
def test_write_bignum_should_write_arguments_as_ssh_formatted_bignum_values_to_end_of_buffer
|
285
|
-
buffer = new("start")
|
286
|
-
buffer.write_bignum OpenSSL::BN.new('1234567890', 10)
|
287
|
-
assert_equal "start\000\000\000\004I\226\002\322", buffer.to_s
|
288
|
-
end
|
289
|
-
|
290
|
-
def test_write_dss_key_should_write_argument_to_end_of_buffer
|
291
|
-
buffer = new("start")
|
292
|
-
|
293
|
-
key = OpenSSL::PKey::DSA.new
|
294
|
-
key.p = 0xffeeddccbbaa9988
|
295
|
-
key.q = 0x7766554433221100
|
296
|
-
key.g = 0xffddbb9977553311
|
297
|
-
key.pub_key = 0xeeccaa8866442200
|
298
|
-
|
299
|
-
buffer.write_key(key)
|
300
|
-
assert_equal "start\0\0\0\7ssh-dss\0\0\0\011\0\xff\xee\xdd\xcc\xbb\xaa\x99\x88\0\0\0\010\x77\x66\x55\x44\x33\x22\x11\x00\0\0\0\011\0\xff\xdd\xbb\x99\x77\x55\x33\x11\0\0\0\011\0\xee\xcc\xaa\x88\x66\x44\x22\x00", buffer.to_s
|
301
|
-
end
|
302
|
-
|
303
|
-
def test_write_rsa_key_should_write_argument_to_end_of_buffer
|
304
|
-
buffer = new("start")
|
305
|
-
|
306
|
-
key = OpenSSL::PKey::RSA.new
|
307
|
-
key.e = 0xffeeddccbbaa9988
|
308
|
-
key.n = 0x7766554433221100
|
309
|
-
|
310
|
-
buffer.write_key(key)
|
311
|
-
assert_equal "start\0\0\0\7ssh-rsa\0\0\0\011\0\xff\xee\xdd\xcc\xbb\xaa\x99\x88\0\0\0\010\x77\x66\x55\x44\x33\x22\x11\x00", buffer.to_s
|
312
|
-
end
|
313
|
-
|
314
|
-
if defined?(OpenSSL::PKey::EC)
|
315
|
-
def test_read_key_blob_should_read_ecdsa_sha2_nistp256_keys
|
316
|
-
random_ecdsa_sha2_nistp256 { |buffer|
|
317
|
-
buffer.read_keyblob("ecdsa-sha2-nistp256")
|
318
|
-
}
|
319
|
-
end
|
320
|
-
def test_read_key_blob_should_read_ecdsa_sha2_nistp384_keys
|
321
|
-
random_ecdsa_sha2_nistp384 { |buffer|
|
322
|
-
buffer.read_keyblob("ecdsa-sha2-nistp384")
|
323
|
-
}
|
324
|
-
end
|
325
|
-
def test_read_key_blob_should_read_ecdsa_sha2_nistp521_keys
|
326
|
-
random_ecdsa_sha2_nistp521 { |buffer|
|
327
|
-
buffer.read_keyblob("ecdsa-sha2-nistp521")
|
328
|
-
}
|
329
|
-
end
|
330
|
-
|
331
|
-
def test_read_key_should_read_ecdsa_sha2_nistp256_key_type_and_keyblob
|
332
|
-
random_ecdsa_sha2_nistp256 do |buffer|
|
333
|
-
b2 = Net::SSH::Buffer.from(:string, "ecdsa-sha2-nistp256", :raw, buffer)
|
334
|
-
b2.read_key
|
335
|
-
end
|
336
|
-
end
|
337
|
-
def test_read_key_should_read_ecdsa_sha2_nistp384_key_type_and_keyblob
|
338
|
-
random_ecdsa_sha2_nistp384 do |buffer|
|
339
|
-
b2 = Net::SSH::Buffer.from(:string, "ecdsa-sha2-nistp384", :raw, buffer)
|
340
|
-
b2.read_key
|
341
|
-
end
|
342
|
-
end
|
343
|
-
def test_read_key_should_read_ecdsa_sha2_nistp521_key_type_and_keyblob
|
344
|
-
random_ecdsa_sha2_nistp521 do |buffer|
|
345
|
-
b2 = Net::SSH::Buffer.from(:string, "ecdsa-sha2-nistp521", :raw, buffer)
|
346
|
-
b2.read_key
|
347
|
-
end
|
348
|
-
end
|
349
|
-
|
350
|
-
def test_write_ecdsa_sha2_nistp256_key_should_write_argument_to_end_of_buffer
|
351
|
-
buffer = new("start")
|
352
|
-
key = OpenSSL::PKey::EC.new("-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIISGj5vAJCWt2KPI8NwaWVDSNLl2vbRxDIOkY+n6O0VVoAoGCCqGSM49\nAwEHoUQDQgAEnKbs0yEogTKT4QRu8T9nb2svl2mEWXb6g224oCpD2o6TYNXNw54H\nmWkdCv+kFCqSlfSi5fqFhrXdfEY6zSzQYQ==\n-----END EC PRIVATE KEY-----\n")
|
353
|
-
|
354
|
-
buffer.write_key(key)
|
355
|
-
assert_equal "start\000\000\000\023ecdsa-sha2-nistp256\000\000\000\bnistp256\000\000\000A\004\234\246\354\323!(\2012\223\341\004n\361?gok/\227i\204Yv\372\203m\270\240*C\332\216\223`\325\315\303\236\a\231i\035\n\377\244\024*\222\225\364\242\345\372\205\206\265\335|F:\315,\320a", buffer.to_s
|
356
|
-
end
|
357
|
-
|
358
|
-
def test_write_ecdsa_sha2_nistp384_key_should_write_argument_to_end_of_buffer
|
359
|
-
buffer = new("start")
|
360
|
-
key = OpenSSL::PKey::EC.new("-----BEGIN EC PRIVATE KEY-----\nMIGkAgEBBDBAfxJpzhsR7O+wMol6BcDgualR8rJBvYegUDYbBUrDnPzDx2/gD1lZ\nnwG1FuD2s9igBwYFK4EEACKhZANiAATsfiU4Kxyvvj1DdvFYsdDnZIT7loRlan9I\n8geCWPPl6x7NFRP+awrnTaarMgieGqxG8IQaIA0SsDOICfbDBkuatRi0S1Et/in4\nZwVEZvO81Ro5YSrjuUDAsytnI6OXS28=\n-----END EC PRIVATE KEY-----\n")
|
361
|
-
|
362
|
-
buffer.write_key(key)
|
363
|
-
assert_equal "start\000\000\000\023ecdsa-sha2-nistp384\000\000\000\bnistp384\000\000\000a\004\354~%8+\034\257\276=Cv\361X\261\320\347d\204\373\226\204ej\177H\362\a\202X\363\345\353\036\315\025\023\376k\n\347M\246\2532\b\236\032\254F\360\204\032 \r\022\2603\210\t\366\303\006K\232\265\030\264KQ-\376)\370g\005Df\363\274\325\0329a*\343\271@\300\263+g#\243\227Ko", buffer.to_s
|
364
|
-
end
|
365
|
-
|
366
|
-
def test_write_ecdsa_sha2_nistp521_key_should_write_argument_to_end_of_buffer
|
367
|
-
buffer = new("start")
|
368
|
-
key = OpenSSL::PKey::EC.new("-----BEGIN EC PRIVATE KEY-----\nMIHbAgEBBEGhnQF/SFo4Vym88HnCfc6BR8WwYqDh9wNTPeqzR8auxIpp0GKQlCG2\nuHzyteJX5/YalV8empYhEzNmNLNn8x7j0aAHBgUrgQQAI6GBiQOBhgAEAYygOgV9\nVI8UyLQ3BDlv+rb3es+ufrIcj++cqcc9QcmRn237NiWRr/1NKy2AKijsEdACtZXo\nxPC0x9Vs9ieC2oR+ANOBubcxPl2giDnBYm8ywAmmlXsP5ByAM17k97CzW5O+Z/uO\nbxGUzzhoXTNcjqpAckhRVKdnh6FL/rKelT0tBYi+\n-----END EC PRIVATE KEY-----\n")
|
369
|
-
|
370
|
-
buffer.write_key(key)
|
371
|
-
assert_equal "start\000\000\000\023ecdsa-sha2-nistp521\000\000\000\bnistp521\000\000\000\205\004\001\214\240:\005}T\217\024\310\2647\0049o\372\266\367z\317\256~\262\034\217\357\234\251\307=A\311\221\237m\3736%\221\257\375M+-\200*(\354\021\320\002\265\225\350\304\360\264\307\325l\366'\202\332\204~\000\323\201\271\2671>]\240\2109\301bo2\300\t\246\225{\017\344\034\2003^\344\367\260\263[\223\276g\373\216o\021\224\3178h]3\\\216\252@rHQT\247g\207\241K\376\262\236\225=-\005\210\276", buffer.to_s
|
372
|
-
end
|
373
|
-
end
|
374
|
-
|
375
|
-
private
|
376
|
-
|
377
|
-
def random_rsa
|
378
|
-
n1 = OpenSSL::BN.new(rand(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF).to_s, 10)
|
379
|
-
n2 = OpenSSL::BN.new(rand(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF).to_s, 10)
|
380
|
-
buffer = Net::SSH::Buffer.from(:bignum, [n1, n2])
|
381
|
-
key = yield(buffer)
|
382
|
-
assert_equal "ssh-rsa", key.ssh_type
|
383
|
-
assert_equal n1, key.e
|
384
|
-
assert_equal n2, key.n
|
385
|
-
end
|
386
|
-
|
387
|
-
def random_dss
|
388
|
-
n1 = OpenSSL::BN.new(rand(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF).to_s, 10)
|
389
|
-
n2 = OpenSSL::BN.new(rand(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF).to_s, 10)
|
390
|
-
n3 = OpenSSL::BN.new(rand(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF).to_s, 10)
|
391
|
-
n4 = OpenSSL::BN.new(rand(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF).to_s, 10)
|
392
|
-
buffer = Net::SSH::Buffer.from(:bignum, [n1, n2, n3, n4])
|
393
|
-
key = yield(buffer)
|
394
|
-
assert_equal "ssh-dss", key.ssh_type
|
395
|
-
assert_equal n1, key.p
|
396
|
-
assert_equal n2, key.q
|
397
|
-
assert_equal n3, key.g
|
398
|
-
assert_equal n4, key.pub_key
|
399
|
-
end
|
400
|
-
|
401
|
-
if defined?(OpenSSL::PKey::EC)
|
402
|
-
def random_ecdsa_sha2_nistp256
|
403
|
-
k = OpenSSL::PKey::EC.new("prime256v1").generate_key
|
404
|
-
buffer = Net::SSH::Buffer.from(:string, "nistp256",
|
405
|
-
:string, k.public_key.to_bn.to_s(2))
|
406
|
-
key = yield(buffer)
|
407
|
-
assert_equal "ecdsa-sha2-nistp256", key.ssh_type
|
408
|
-
assert_equal k.public_key, key.public_key
|
409
|
-
end
|
410
|
-
|
411
|
-
def random_ecdsa_sha2_nistp384
|
412
|
-
k = OpenSSL::PKey::EC.new("secp384r1").generate_key
|
413
|
-
buffer = Net::SSH::Buffer.from(:string, "nistp384",
|
414
|
-
:string, k.public_key.to_bn.to_s(2))
|
415
|
-
key = yield(buffer)
|
416
|
-
assert_equal "ecdsa-sha2-nistp384", key.ssh_type
|
417
|
-
assert_equal k.public_key, key.public_key
|
418
|
-
end
|
419
|
-
|
420
|
-
def random_ecdsa_sha2_nistp521
|
421
|
-
k = OpenSSL::PKey::EC.new("secp521r1").generate_key
|
422
|
-
buffer = Net::SSH::Buffer.from(:string, "nistp521",
|
423
|
-
:string, k.public_key.to_bn.to_s(2))
|
424
|
-
key = yield(buffer)
|
425
|
-
assert_equal "ecdsa-sha2-nistp521", key.ssh_type
|
426
|
-
assert_equal k.public_key, key.public_key
|
427
|
-
end
|
428
|
-
end
|
429
|
-
|
430
|
-
def new(*args)
|
431
|
-
Net::SSH::Buffer.new(*args)
|
432
|
-
end
|
433
|
-
end
|