From 2ce6c15e15be473c3794b3a8652e63c56f6c1828 Mon Sep 17 00:00:00 2001 From: BenediktMKuehne Date: Fri, 8 Nov 2024 13:56:23 +0000 Subject: [PATCH] some fixes and updates add sbom to admin --- embark/dashboard/admin.py | 3 ++- embark/dashboard/models.py | 2 ++ embark/porter/importer.py | 26 +++++++++----------------- embark/templates/tracker/device.html | 2 +- embark/templates/tracker/results.html | 2 +- embark/templates/tracker/sbom.html | 25 +++++++++++++++++++++++++ embark/tracker/forms.py | 1 + embark/tracker/tables.py | 8 ++++++-- embark/tracker/urls.py | 2 +- embark/tracker/views.py | 17 ++++++++++++++--- embark/uploader/models.py | 2 +- 11 files changed, 63 insertions(+), 27 deletions(-) create mode 100644 embark/templates/tracker/sbom.html diff --git a/embark/dashboard/admin.py b/embark/dashboard/admin.py index 04580f52..4ecce3fb 100644 --- a/embark/dashboard/admin.py +++ b/embark/dashboard/admin.py @@ -4,8 +4,9 @@ from django.contrib import admin -from dashboard.models import Result, Vulnerability, SoftwareInfo +from dashboard.models import Result, Vulnerability, SoftwareInfo, SoftwareBillOfMaterial admin.site.register(Result) admin.site.register(Vulnerability) admin.site.register(SoftwareInfo) +admin.site.register(SoftwareBillOfMaterial) diff --git a/embark/dashboard/models.py b/embark/dashboard/models.py index bf3af3fb..d5f291d1 100644 --- a/embark/dashboard/models.py +++ b/embark/dashboard/models.py @@ -5,6 +5,7 @@ import uuid from django.db import models from django.core.validators import MinLengthValidator +from django.utils import timezone from uploader.models import FirmwareAnalysis @@ -51,6 +52,7 @@ class Result(models.Model): firmware_analysis = models.OneToOneField(FirmwareAnalysis, on_delete=models.CASCADE, primary_key=True) emba_command = models.CharField(blank=True, null=True, max_length=(FirmwareAnalysis.MAX_LENGTH * 6), help_text='') restricted = models.BooleanField(default=False, help_text='') + date = models.DateTimeField(default=timezone.now, blank=True) # base identifier os_verified = models.CharField(blank=True, null=True, max_length=256, help_text='') diff --git a/embark/porter/importer.py b/embark/porter/importer.py index 108ad5a0..554bb489 100644 --- a/embark/porter/importer.py +++ b/embark/porter/importer.py @@ -214,15 +214,10 @@ def f15_json(_file_path, _analysis_id): logger.debug("starting f15 json import") with open(_file_path, 'r', encoding='utf-8') as f15_json_file: f15_data = json.load(f15_json_file) - sbom_obj, add_sbom = SoftwareBillOfMaterial.objects.get_or_create( - id=f15_data['serialNumber'] #TODO grep uuid from this: "urn:uuid:f601dc24-7ba9-4821-b398-a30c59f7775e" - ) - if add_sbom: - res, _ = Result.objects.get_or_create( - firmware_analysis=FirmwareAnalysis.objects.get(id=_analysis_id), - sbom=add_sbom - ) - else: + sbom_uuid = f15_data['serialNumber'].split(":")[2] + logger.debug("Reading sbom uuid=%s", sbom_uuid) + sbom_obj, add_sbom = SoftwareBillOfMaterial.objects.get_or_create(id=sbom_uuid) + if not add_sbom: for component_ in f15_data['components']: logger.debug("Component is %s", component_) try: @@ -240,16 +235,13 @@ def f15_json(_file_path, _analysis_id): ) logger.debug("Was new? %s", add_sitem) logger.debug("Adding SBOM item: %s to sbom %s", new_sitem, sbom_obj) - if add_sitem: - sbom_obj.add(add_sitem) - else: - sbom_obj.add(new_sitem) + sbom_obj.component.add(new_sitem) except builtins.Exception as error_: logger.error("Error in f15 readin: %s", error_) - res, _ = Result.objects.get_or_create( - firmware_analysis=FirmwareAnalysis.objects.get(id=_analysis_id), - sbom=sbom_obj - ) + res, _ = Result.objects.get_or_create( + firmware_analysis=FirmwareAnalysis.objects.get(id=_analysis_id), + sbom=sbom_obj + ) logger.debug("read f15 json done") return res diff --git a/embark/templates/tracker/device.html b/embark/templates/tracker/device.html index fd40556a..4b53ac64 100644 --- a/embark/templates/tracker/device.html +++ b/embark/templates/tracker/device.html @@ -35,6 +35,7 @@ {% block sbom %}{% include "tracker/results.html" %}{% endblock sbom%} +

Device tracker

@@ -48,7 +49,6 @@

Device tracker

-