diff options
author | delano <delano@delanotes.com> | 2014-02-01 11:10:42 -0500 |
---|---|---|
committer | delano <delano@delanotes.com> | 2014-02-01 11:10:42 -0500 |
commit | e777bfab9bea5adc31ee823029475d24871c4297 (patch) | |
tree | 05402c701549ec197c9519ad5640db93abb1be56 | |
parent | 60d3da31d2f6ce1167f1bd4564000789da8d7859 (diff) | |
parent | 7caa35677478340b432628e59273cec17919edc6 (diff) | |
download | net-ssh-bobtfish-fix_options_in_public_keys.tar.gz |
Merge branch 'fix_options_in_public_keys' of github.com:bobtfish/net-ssh into bobtfish-fix_options_in_public_keysbobtfish-fix_options_in_public_keys
-rw-r--r-- | lib/net/ssh/key_factory.rb | 8 | ||||
-rw-r--r-- | test/test_key_factory.rb | 22 |
2 files changed, 27 insertions, 3 deletions
diff --git a/lib/net/ssh/key_factory.rb b/lib/net/ssh/key_factory.rb index fdc7eda..94b4633 100644 --- a/lib/net/ssh/key_factory.rb +++ b/lib/net/ssh/key_factory.rb @@ -105,7 +105,13 @@ module Net; module SSH # the file describes an RSA or DSA key, and will load it # appropriately. The new public key is returned. def load_data_public_key(data, filename="") - _, blob = data.split(/ /) + fields = data.split(/ /) + + blob = nil + begin + blob = fields.shift + end while !blob.nil? && !/^(ssh-(rsa|dss)|ecdsa-sha2-nistp\d+)$/.match(blob) + blob = fields.shift raise Net::SSH::Exception, "public key at #{filename} is not valid" if blob.nil? diff --git a/test/test_key_factory.rb b/test/test_key_factory.rb index d5c6416..5bc90b2 100644 --- a/test/test_key_factory.rb +++ b/test/test_key_factory.rb @@ -65,6 +65,20 @@ class TestKeyFactory < Test::Unit::TestCase assert_equal rsa_key.to_blob, Net::SSH::KeyFactory.load_public_key(@key_file).to_blob end + def test_load_public_rsa_key_with_comment_should_return_key + File.expects(:read).with(@key_file).returns(public(rsa_key) + " key_comment") + assert_equal rsa_key.to_blob, Net::SSH::KeyFactory.load_public_key(@key_file).to_blob + end + + def test_load_public_rsa_key_with_options_should_return_key + File.expects(:read).with(@key_file).returns(public(rsa_key, 'environment="FOO=bar"')) + assert_equal rsa_key.to_blob, Net::SSH::KeyFactory.load_public_key(@key_file).to_blob + end + + def test_load_public_rsa_key_with_options_and_comment_should_return_key + File.expects(:read).with(@key_file).returns(public(rsa_key, 'environment="FOO=bar"') + " key_comment") + assert_equal rsa_key.to_blob, Net::SSH::KeyFactory.load_public_key(@key_file).to_blob + end if defined?(OpenSSL::PKey::EC) def test_load_unencrypted_private_ecdsa_sha2_nistp256_key_should_return_key File.expects(:read).with("/key-file").returns(ecdsa_sha2_nistp256_key.to_pem) @@ -165,8 +179,12 @@ WEKt5v3QsUEgVrzkM4K9UbI= key.export(OpenSSL::Cipher::Cipher.new("des-ede3-cbc"), password) end - def public(key) - result = "#{key.ssh_type} " + def public(key, args = nil) + result = "" + if !args.nil? + result << "#{args} " + end + result << "#{key.ssh_type} " result << [Net::SSH::Buffer.from(:key, key).to_s].pack("m*").strip.tr("\n\r\t ", "") result << " joe@host.test" end |