summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/net/ssh/authentication/agent/socket.rb14
-rw-r--r--test/authentication/test_agent.rb19
2 files changed, 29 insertions, 4 deletions
diff --git a/lib/net/ssh/authentication/agent/socket.rb b/lib/net/ssh/authentication/agent/socket.rb
index c80099e..7ca6d92 100644
--- a/lib/net/ssh/authentication/agent/socket.rb
+++ b/lib/net/ssh/authentication/agent/socket.rb
@@ -94,10 +94,16 @@ module Net; module SSH; module Authentication
identities = []
body.read_long.times do
- key = Buffer.new(body.read_string).read_key
- key.extend(Comment)
- key.comment = body.read_string
- identities.push key
+ key_str = body.read_string
+ comment_str = body.read_string
+ begin
+ key = Buffer.new(key_str).read_key
+ key.extend(Comment)
+ key.comment = comment_str
+ identities.push key
+ rescue NotImplementedError => e
+ error { "ignoring unimplemented key:#{e.message} #{comment_str}" }
+ end
end
return identities
diff --git a/test/authentication/test_agent.rb b/test/authentication/test_agent.rb
index 1e24d5e..1613727 100644
--- a/test/authentication/test_agent.rb
+++ b/test/authentication/test_agent.rb
@@ -110,6 +110,25 @@ module Authentication
assert_equal "Okay, but not the best", result.last.comment
end
+ def test_identities_should_ignore_unimplemented_ones
+ key1 = key
+ key2 = OpenSSL::PKey::DSA.new(512)
+ key2.to_blob[0..5]='badkey'
+ key3 = OpenSSL::PKey::DSA.new(512)
+
+ socket.expect do |s, type, buffer|
+ assert_equal SSH2_AGENT_REQUEST_IDENTITIES, type
+ s.return(SSH2_AGENT_IDENTITIES_ANSWER, :long, 3, :string, Net::SSH::Buffer.from(:key, key1), :string, "My favorite key", :string, Net::SSH::Buffer.from(:key, key2), :string, "bad", :string, Net::SSH::Buffer.from(:key, key3), :string, "Okay, but not the best")
+ end
+
+ result = agent.identities
+ assert_equal 2,result.size
+ assert_equal key1.to_blob, result.first.to_blob
+ assert_equal key3.to_blob, result.last.to_blob
+ assert_equal "My favorite key", result.first.comment
+ assert_equal "Okay, but not the best", result.last.comment
+ end
+
def test_close_should_close_socket
socket.expects(:close)
agent.close