diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index d351def8d..07e576e10 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,5 +1,9 @@ === (unreleased) +* Make key manager use private keys instead of requiring public key to exist [arilerner@mac.com] + +* Fix failing tests [arilerner@mac.com] + * Don't include pageant when running under JRuby [Angel N. Sciortino] diff --git a/Manifest b/Manifest index 55682c663..2e9d4a79e 100644 --- a/Manifest +++ b/Manifest @@ -62,6 +62,7 @@ lib/net/ssh/verifiers/strict.rb lib/net/ssh/version.rb lib/net/ssh.rb Manifest +net-ssh.gemspec Rakefile README.rdoc setup.rb @@ -101,4 +102,3 @@ test/transport/test_server_version.rb test/transport/test_session.rb test/transport/test_state.rb THANKS.rdoc -TODO diff --git a/lib/net/ssh/authentication/key_manager.rb b/lib/net/ssh/authentication/key_manager.rb index d12b30e18..0a4c3f660 100644 --- a/lib/net/ssh/authentication/key_manager.rb +++ b/lib/net/ssh/authentication/key_manager.rb @@ -87,12 +87,12 @@ def identities known_identities[key] = { :from => :agent } end end - + key_files.each do |file| - public_key_file = file + '.pub' - if File.readable?(public_key_file) + if File.readable?(file) begin - key = KeyFactory.load_public_key(public_key_file) + private_key = KeyFactory.load_private_key(file) + key = private_key.send :public_key identities.push key known_identities[key] = { :from => :file, :file => file } rescue Exception => e diff --git a/test/authentication/methods/test_hostbased.rb b/test/authentication/methods/test_hostbased.rb index 1245e136e..0a994fb64 100644 --- a/test/authentication/methods/test_hostbased.rb +++ b/test/authentication/methods/test_hostbased.rb @@ -16,6 +16,7 @@ def test_authenticate_should_return_false_when_key_manager_has_no_keys end def test_authenticate_should_return_false_if_no_keys_can_authenticate + ENV.stubs(:[]).with('USER').returns(nil) key_manager.expects(:sign).with(&signature_parameters(keys.first)).returns("sig-one") key_manager.expects(:sign).with(&signature_parameters(keys.last)).returns("sig-two") @@ -37,6 +38,7 @@ def test_authenticate_should_return_false_if_no_keys_can_authenticate end def test_authenticate_should_return_true_if_any_key_can_authenticate + ENV.stubs(:[]).with('USER').returns(nil) key_manager.expects(:sign).with(&signature_parameters(keys.first)).returns("sig-one") transport.expect do |t, packet| diff --git a/test/authentication/test_key_manager.rb b/test/authentication/test_key_manager.rb index f6486f996..00f5f4a23 100644 --- a/test/authentication/test_key_manager.rb +++ b/test/authentication/test_key_manager.rb @@ -32,13 +32,13 @@ def test_identities_should_load_from_key_files manager.stubs(:agent).returns(nil) stub_file_key "/first", rsa - stub_file_key "/second", dsa + stub_file_key "/second", dsa identities = manager.identities assert_equal 2, identities.length assert_equal rsa.to_blob, identities.first.to_blob assert_equal dsa.to_blob, identities.last.to_blob - + assert_equal({:from => :file, :file => "/first"}, manager.known_identities[rsa]) assert_equal({:from => :file, :file => "/second"}, manager.known_identities[dsa]) end @@ -75,8 +75,8 @@ def test_sign_with_file_originated_key_should_load_private_key_and_sign_with_it def stub_file_key(name, key, also_private=false) manager.add(name) File.expects(:readable?).returns(true) - Net::SSH::KeyFactory.expects(:load_public_key).with("#{name}.pub").returns(key) - Net::SSH::KeyFactory.expects(:load_private_key).with(name, nil).returns(key) if also_private + Net::SSH::KeyFactory.expects(:load_private_key).with(name, nil).returns(key).at_least_once + key.expects(:public_key).returns(key) end def rsa(size=32)