def get_rule_to_stig_dict(xml: ElementTree.ElementTree, benchmark_creator: str) -> dict: rules = dict() for group in xml.findall(f'{XCCDF12}:Group', PREFIX_TO_NS): for sub_groups in group.findall(f'{XCCDF12}:Group', PREFIX_TO_NS): rules.update( get_rule_to_stig_dict(ElementTree.ElementTree(sub_groups), benchmark_creator)) for rule in group.findall(f'{XCCDF12}:Rule', PREFIX_TO_NS): rule_id = rule.attrib['id'] if benchmark_creator == "DISA": stig_id = rule.find(f'{XCCDF12}:version', PREFIX_TO_NS).text else: elm = rule.find( f"{XCCDF12}:reference[@href='{SSG_REF_URIS['stigid']}']", PREFIX_TO_NS) if elm is not None: stig_id = elm.text else: continue if stig_id in rules: rules[stig_id].append(rule_id) else: rules[stig_id] = [rule_id] return rules
def get_results(xml: ElementTree.ElementTree) -> dict: rules = dict() results_xml = xml.findall('.//xccdf-1.2:TestResult/xccdf-1.2:rule-result', ssg.constants.PREFIX_TO_NS) for result in results_xml: idref = result.attrib['idref'] rules[idref] = result.find('xccdf-1.2:result', ssg.constants.PREFIX_TO_NS).text return rules
def get_identifiers(xml: ElementTree.ElementTree) -> dict: rules = dict() results_xml = xml.findall('.//xccdf-1.2:rule-result', PREFIX_TO_NS) for result in results_xml: idref = result.attrib['idref'] idref = idref.replace("xccdf_mil.disa.stig_rule_", "") rules[idref] = result.find('xccdf-1.2:ident', PREFIX_TO_NS).text return rules
def get_results(xml: ElementTree.ElementTree) -> dict: rules = dict() results_xml = xml.findall('.//xccdf-1.2:rule-result', PREFIX_TO_NS) for result in results_xml: idref = result.attrib['idref'] idref = idref.replace("xccdf_mil.disa.stig_rule_", "") try: rules[idref] = result.find('xccdf-1.2:result', PREFIX_TO_NS).text except AttributeError: rules[idref] = "MISSING_RESULT" return rules