Commits

genbit  committed f1d563e

support multiple ssh keys

  • Participants
  • Parent commits 6610c14

Comments (0)

Files changed (1)

File lib/custom_value_path.rb

   module InstanceMethods
     def validate_ssh
       begin
-        type, blob = value.split(/ /)
-
-        raise Net::SSH::Exception, "public key is not valid" if blob.nil?
-
-        blob = blob.unpack("m*").first
-        reader = Net::SSH::Buffer.new(blob)
-        reader.read_key or raise OpenSSL::PKey::PKeyError, "not a public key"
+        return true if value == ""
+        keys = value.split("\n\n")
+				for key in keys do
+					type, blob, host = key.split(/ /)
+					raise Net::SSH::Exception, "public key is not valid (hostname: #{host.to_s})" if blob.nil?
+          blob = blob.unpack("m*").first
+				  reader = Net::SSH::Buffer.new(blob)
+					reader.read_key or raise OpenSSL::PKey::PKeyError, "not a public key (hostname: #{host.to_s})"
+				end
       rescue
         errors.add(:value, :invalid)
       end