summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDelano Mandelbaum <delano@solutious.com>2014-09-30 17:16:54 -0700
committerDelano Mandelbaum <delano@solutious.com>2014-09-30 17:16:54 -0700
commit2c10a94e81d9f6f0cbf38c8e8c023d5ece9e334b (patch)
tree966d2a4033e0a1d90505f7b173f693afc65b412a
parentaf273f19c46c6545bc62cbcfe6b977289d664496 (diff)
parent9f3958b84433bb3f845d477a404bd670459f7e8c (diff)
downloadnet-ssh-2c10a94e81d9f6f0cbf38c8e8c023d5ece9e334b.tar.gz
Merge pull request #186 from mfazekas/ignore_unknown_pubkey
Ignore unkown identities instead of failing on it
-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