From 5811520227b16a72b11f6770ad3f54945260de6a Mon Sep 17 00:00:00 2001 From: Jan Rodak Date: Tue, 5 Mar 2024 11:53:34 +0100 Subject: [PATCH] Fix CPE OVAL references --- build-scripts/cpe_generate.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/build-scripts/cpe_generate.py b/build-scripts/cpe_generate.py index f406558b6a8f..d07b8c8a759d 100755 --- a/build-scripts/cpe_generate.py +++ b/build-scripts/cpe_generate.py @@ -156,6 +156,13 @@ def _save_minimal_cpe_oval(oval_document, path, oval_def_ids): oval_document.save_as_xml(path, references_to_keep) +def _update_oval_href_in_xccdf(shorthand_tree, file_name): + for check_fact_ref in shorthand_tree.findall( + ".//{%s}check-fact-ref" % ssg.constants.PREFIX_TO_NS["cpe-lang"] + ): + check_fact_ref.set("href", file_name) + + def _generate_cpe_for_thin_xccdf(args, oval_document, cpe_dict): for xccdf_path in glob.glob("{}/xccdf*.xml".format(args.thin_ds_components_dir)): cpe_oval_path = xccdf_path.replace("xccdf_", "cpe_oval_") @@ -166,8 +173,10 @@ def _generate_cpe_for_thin_xccdf(args, oval_document, cpe_dict): used_cpe_oval_def_ids = get_all_cpe_oval_def_ids( shorthand_tree, cpe_dict, benchmark_cpe_names ) - cpe_dict.to_file(cpe_dict_path, cpe_oval_path, benchmark_cpe_names) + cpe_dict.to_file(cpe_dict_path, os.path.basename(cpe_oval_path), benchmark_cpe_names) _save_minimal_cpe_oval(oval_document, cpe_oval_path, used_cpe_oval_def_ids) + _update_oval_href_in_xccdf(shorthand_tree, os.path.basename(cpe_oval_path)) + ssg.xml.ElementTree.ElementTree(shorthand_tree).write(xccdf_path, encoding="utf-8") def main():