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%} +