# File lib/smart_proxy_openscap/openscap_lib.rb, line 20 def self.common_name(request) client_cert = request.env['SSL_CLIENT_CERT'] raise Proxy::Error::Unauthorized, "Client certificate required!" if client_cert.to_s.empty? begin client_cert = OpenSSL::X509::Certificate.new(client_cert) rescue OpenSSL::OpenSSLError => e raise Proxy::Error::Unauthorized, e.message end cn = client_cert.subject.to_a.detect { |name, value| name == 'CN' } cn = cn[1] unless cn.nil? raise Proxy::Error::Unauthorized, "Common Name not found in the certificate" unless cn return cn end
# File lib/smart_proxy_openscap/openscap_lib.rb, line 55 def self.send_spool_to_foreman arf_dir = File.join(Proxy::OpenSCAP::Plugin.settings.spooldir, "/arf") return unless File.exists? arf_dir ForemanForwarder.new.do(arf_dir) end
# File lib/smart_proxy_openscap/openscap_lib.rb, line 35 def self.spool_arf_dir(common_name, policy_id) validate_policy_id(policy_id) date = Time.now.strftime("%Y-%m-%d") dir = Proxy::OpenSCAP::Plugin.settings.spooldir + "/arf/#{common_name}/#{policy_id}/#{date}/" begin FileUtils.mkdir_p dir rescue StandardError => e logger.error "Could not create '#{dir}' directory: #{e.message}" raise e end dir end
# File lib/smart_proxy_openscap/openscap_lib.rb, line 48 def self.store_arf(spool_arf_dir, data) filename = Digest::SHA256.hexdigest data target_path = spool_arf_dir + filename File.open(target_path,'w') { |f| f.write(data) } return target_path end
# File lib/smart_proxy_openscap/openscap_lib.rb, line 62 def self.validate_policy_id(id) unless /[\d]+/ =~ id raise Proxy::Error::BadRequest, "Malformed policy ID" end end