ssg.xml module

class ssg.xml.XMLBenchmark(root)[source]

Bases: XMLElement

Represents an XCCDF Benchmark read from an XML file.

find_all_cpe_platforms(idref)[source]
find_rule(rule_id)[source]
find_rules(rule_id)[source]
class ssg.xml.XMLCPEPlatform(root)[source]

Bases: XMLElement

find_all_check_fact_ref_elements()[source]
class ssg.xml.XMLComponent(root)[source]

Bases: XMLElement

Represents the element of the Data stream component that has relevant content.

This make it easier to access contents pertaining to a SCAP component.

find_boolean_question(ocil_id)[source]
find_ocil_boolean_question(question_id)[source]
find_ocil_questionnaire(def_id)[source]
find_ocil_test_action(test_action_ref)[source]
find_oval_definition(def_id)[source]
class ssg.xml.XMLContent(root)[source]

Bases: XMLElement

Can represent a Data Stream or an XCCDF Benchmark read from an XML file.

check_engines = [('OVAL', 'oval:oval_definitions'), ('OCIL', 'ocil:ocil')]
find_benchmark(id_)[source]
get_benchmarks()[source]
get_component_refs()[source]
get_uris()[source]
is_benchmark()[source]
class ssg.xml.XMLElement(root)[source]

Bases: object

Represents an generic element read from an XML file.

get_attr(attr)[source]
get_namespace()[source]
ns = {'catalog': 'urn:oasis:names:tc:entity:xmlns:xml:catalog', 'cpe-lang': 'http://cpe.mitre.org/language/2.0', 'ds': 'http://scap.nist.gov/schema/scap/source/1.2', 'ocil': 'http://scap.nist.gov/schema/ocil/2.0', 'oval': 'http://oval.mitre.org/XMLSchema/oval-definitions-5', 'xccdf-1.1': 'http://checklists.nist.gov/xccdf/1.1', 'xccdf-1.2': 'http://checklists.nist.gov/xccdf/1.2', 'xlink': 'http://www.w3.org/1999/xlink'}
class ssg.xml.XMLOcilQuestion(root)[source]

Bases: XMLComponent

get_question_test_element()[source]
class ssg.xml.XMLOcilQuestionnaire(root)[source]

Bases: XMLComponent

get_test_action_ref_element()[source]
class ssg.xml.XMLOcilTestAction(root)[source]

Bases: XMLComponent

class ssg.xml.XMLOvalDefinition(root)[source]

Bases: XMLComponent

get_criteria_element()[source]
get_elements()[source]
class ssg.xml.XMLRule(root)[source]

Bases: XMLElement

Represents an XCCDF Rule read from an XML file.

get_all_platform_elements()[source]
get_check_content_ref_element(check_element)[source]
get_check_element(check_system_uri)[source]
get_element_text(el)[source]
get_fix_element(fix_uri)[source]
get_version_element()[source]
join_text_elements()[source]

This function collects the text of almost all subelements. Similar to what itertext() would do, except that this function skips some elements that are not relevant for comparison.

This function also injects a line for each element whose text was collected, to facilitate tracking of where in the rule the text came from.

ssg.xml.add_xhtml_namespace(data)[source]

Given a xml blob, adds the xhtml namespace to all relevant tags.

ssg.xml.determine_xccdf_tree_namespace(tree)[source]
ssg.xml.get_element_namespace(self)[source]
ssg.xml.get_element_tag_without_ns(xml_tag)[source]
ssg.xml.get_namespaces_from(file)[source]

Return dictionary of namespaces in file. Return empty dictionary in case of error.

ssg.xml.map_elements_to_their_ids(tree, xpath_expr)[source]

Given an ElementTree and an XPath expression, iterate through matching elements and create 1:1 id->element mapping.

Raises AssertionError if a matching element doesn’t have the id attribute.

Returns mapping as a dictionary

ssg.xml.open_xml(filename)[source]

Given a filename, register all possible namespaces, and return the XML tree.

ssg.xml.oval_generated_header(product_name, schema_version, ssg_version)[source]
ssg.xml.parse_file(filename)[source]

Given a filename, return the root of the ElementTree

ssg.xml.register_namespaces(ns=None)[source]

Register all possible namespaces