Skip to content

Commit

Permalink
UI part for SBOM
Browse files Browse the repository at this point in the history
  • Loading branch information
BenediktMKuehne committed Sep 27, 2024
1 parent b979df1 commit 6b63ba1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
10 changes: 9 additions & 1 deletion embark/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
__author__ = 'Benedikt Kuehne'
__license__ = 'MIT'

import uuid
from django.db import models
from django.core.validators import MinLengthValidator

Expand All @@ -13,8 +14,14 @@ class Vulnerability(models.Model):
Many-to-Many object for CVEs
"""
cve = models.CharField(max_length=18, validators=[MinLengthValidator(13)], help_text='CVE-XXXX-XXXXXXX')
info = models.JSONField(null=True)
info = models.JSONField(null=True, editable=True)

class SoftwareBillofMaterial(models.Model):
"""
1-1 object for SBOM
"""
id = models.UUIDField(primary_key=True, default=uuid.uuid4)
data = models.JSONField(null=True)

class Result(models.Model):
"""
Expand Down Expand Up @@ -71,3 +78,4 @@ class Result(models.Model):
system_bin = models.TextField(default='{}')

vulnerability = models.ManyToManyField(Vulnerability, help_text='CVE/Vulnerability', related_query_name='CVE', editable=True, blank=True)
sbom = models.OneToOneField(SoftwareBillofMaterial, help_text='Software Bill of Material', related_query_name='sbom', editable=True, on_delete=models.CASCADE, null=True)
29 changes: 28 additions & 1 deletion embark/static/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function navToggle() {
function expertModeOn() {
"use strict";
try {
var expertOptions = document.querySelectorAll('div.expertModeOptions');
var expertOptions = document.querySelectorAll('div.expertModeOptions:not(.SBOMOption)');

for (var i = 0; i < expertOptions.length; i++) {
var expertDiv = expertOptions[i];
Expand Down Expand Up @@ -67,3 +67,30 @@ function confirmDelete(event) {
successAlert(`firmware file deleted: ${event.target.elements.firmware.value}`);
}
}

/**
* To toggle SBOM mode option during analysing the Firmware
*/
function SBOMModeToggle() {
"use strict";
try {
var sbomOptions = document.querySelectorAll('div.expertModeOptions.SBOMOption');

for (var i = 0; i < sbomOptions.length; i++) {
var expertDiv = sbomOptions[i];
if (expertDiv.getAttribute("value") === "expmode_off") {
expertDiv.setAttribute("value","expmode_on");
} else {
expertDiv.setAttribute("value","expmode_off");
}
}
// turn on too
let checkbox = document.getElementById('id_sbom_only_test');
checkbox.click();

} catch (error) {
console.log(error.message);
}
/* we enable the help text automatically in sbom mode */
helpTextOn();
}
11 changes: 11 additions & 0 deletions embark/templates/uploader/start.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@
<form action="{% url 'embark-uploader-start-analysis' %}" method="post" id="analyze-form">
{% csrf_token %}
<div class="innerBlock">
<label for="SBOMModeSwitch">SBOM mode</label>
<label class="switch">
<input id="SBOMModeSwitch" type="checkbox" onclick="SBOMModeToggle()"/>
<span class="slider round"></span>
</label>
<br>
<label for="expertModeSwitch">Expert mode</label>
<label class="switch">
<input id="expertModeSwitch" type="checkbox" onclick="expertModeOn()"/>
<span class="slider round"></span>
</label>

{% load filters %}
<!-- Iterate over all fields and set expmode on fields in expert mode -->
{% for field in analysis_form %}
Expand All @@ -24,6 +31,10 @@
<div class="row expertModeOptions" value="expmode_off">
{% bootstrap_field field %}
</div>
{% elif field.name == "sbom_only_test" %}
<div class="row expertModeOptions SBOMOption" value="expmode_off">
{% bootstrap_field field %}
</div>
{% else %}
{% bootstrap_field field %}
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion embark/uploader/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class FirmwareAnalysisForm(forms.ModelForm):
class Meta:
model = models.FirmwareAnalysis

fields = ['firmware', 'version', 'device', 'notes', 'firmware_Architecture', 'user_emulation_test', 'system_emulation_test', 'scan_modules']
fields = ['firmware', 'version', 'device', 'notes', 'firmware_Architecture', 'user_emulation_test', 'system_emulation_test', 'sbom_only_test', 'scan_modules']
widgets = {
"device": forms.CheckboxSelectMultiple,
}
Expand Down
3 changes: 3 additions & 0 deletions embark/uploader/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ class Firmware
user_emulation_test = BooleanFieldExpertMode(help_text='Enables automated qemu emulation tests', default=False, expert_mode=True, blank=True)
system_emulation_test = BooleanFieldExpertMode(help_text='Enables automated qemu system emulation tests', default=False, expert_mode=True, blank=True)

# SBOM mode option
sbom_only_test = models.BooleanField(verbose_name='SBOM only test', help_text='Enables SBOM tests', default=False, blank=True)

# S-modules
scan_modules = models.JSONField(blank=True, null=True, default=scan_modules_default_value)

Expand Down

0 comments on commit 6b63ba1

Please sign in to comment.