end
end
+ def fingerprintable_key
+ return true unless key # Don't test if there is no key.
+ # `ssh-keygen -lf /dev/stdin <<< "#{key}"` errors with: redirection unexpected
+ file = Tempfile.new('key_file')
+ begin
+ file.puts key
+ file.rewind
+ fingerprint_output = `ssh-keygen -lf #{file.path} 2>&1` # Catch stderr.
+ ensure
+ file.close
+ file.unlink # deletes the temp file
+ end
+ errors.add(:key, "can't be fingerprinted") if fingerprint_output.match("failed")
+ end
+
def set_identifier
if is_deploy_key
- self.identifier = "deploy_" + Digest::MD5.hexdigest(key)
+ self.identifier = "deploy_#{Digest::MD5.hexdigest(key)}"
else
self.identifier = "#{user.identifier}_#{Time.now.to_i}"
end