diff --git a/Dockerfile b/Dockerfile index beeb30e..c159be2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 FROM ruby:latest -RUN apt-get update -qq && apt-get install -y nodejs postgresql-client less +RUN apt-get update -qq && apt-get install -y nodejs postgresql-client less bzip2 WORKDIR /data_importer COPY Gemfile /data_importer/Gemfile COPY Gemfile.lock /data_importer/Gemfile.lock diff --git a/lib/oval_parser.rb b/lib/oval_parser.rb new file mode 100644 index 0000000..02effd2 --- /dev/null +++ b/lib/oval_parser.rb @@ -0,0 +1,79 @@ +require 'nokogiri' + +class OvalParser + attr_accessor :data + def initialize + @data = data + @doc = Nokogiri::XML(data) + end + + def cve_hash + oval_defs = doc.xpath() + title = + end +end + +=begin + +THIS CODE GETS THE DEF ID LIST + + def _get_list_cve_def_ids(self, _root): + '''Returns a list of cve definition ids in the result file''' + _def_id_list = [] + definitions = _root.findall("{http://oval.mitre.org/XMLSchema/" + "oval-results-5}results/{http://oval.mitre" + ".org/XMLSchema/oval-results-5}system/{" + "http://oval.mitre.org/XMLSchema/oval-" + "results-5}definitions/*[@result='true']") + for def_id in definitions: + _def_id_list.append(def_id.attrib['definition_id']) + + return _def_id_list + +THIS CODE LOOPS THROUGH THE DEF ID LIS + +def _get_cve_def_info(self, _def_id_list, _root): + ''' + Returns a list of tuples that contain information about the + cve themselves. Currently return are: title, severity, ref_id + and ref_url for the cve and rhsa, the cve id, and description + ''' + + cve_info_list = [] + for def_id in _def_id_list: + oval_defs = _root.find("{http://oval.mitre.org/XMLSchema/oval-" + "definitions-5}oval_definitions/{http://" + "oval.mitre.org/XMLSchema/oval-definitions-" + "5}definitions/*[@id='%s']/{http://oval." + "mitre.org/XMLSchema/oval-definitions-5}" + "metadata" % def_id) + # title + title = oval_defs.find("{http://oval.mitre.org/XMLSchema/oval-" + "definitions-5}title").text + rhsa_meta = oval_defs.find("{http://oval.mitre.org/XMLSchema/oval" + "-definitions-5}reference[@source=" + "'RHSA']") + cve_meta = oval_defs.find("{http://oval.mitre.org/XMLSchema/oval-" + "definitions-5}reference[@source='CVE']") + # description + description = oval_defs.find("{http://oval.mitre.org/XMLSchema/" + "oval-definitions-5}description").text + # severity + severity = oval_defs.find("{http://oval.mitre.org/XMLSchema/oval-" + "definitions-5}advisory/{http://oval." + "mitre.org/XMLSchema/oval-definitions" + "-5}severity").text + cve_info_list.append( + self._cve_tuple(title=title, severity=severity, + cve_ref_id=None if cve_meta is None + else cve_meta.attrib['ref_id'], + cve_ref_url=None if cve_meta is None + else cve_meta.attrib['ref_url'], + rhsa_ref_id=rhsa_meta.attrib['ref_id'], + rhsa_ref_url=rhsa_meta.attrib['ref_url'], + cve=def_id.replace( + "oval:com.redhat.rhsa:def:", ""), + description=description)) + + return cve_info_list + =end \ No newline at end of file