begin setting up experimenting with oval parser
This commit is contained in:
parent
1221d76340
commit
4868ef67d9
2 changed files with 80 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
||||||
# syntax=docker/dockerfile:1
|
# syntax=docker/dockerfile:1
|
||||||
FROM ruby:latest
|
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
|
WORKDIR /data_importer
|
||||||
COPY Gemfile /data_importer/Gemfile
|
COPY Gemfile /data_importer/Gemfile
|
||||||
COPY Gemfile.lock /data_importer/Gemfile.lock
|
COPY Gemfile.lock /data_importer/Gemfile.lock
|
||||||
|
|
79
lib/oval_parser.rb
Normal file
79
lib/oval_parser.rb
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue