Skip to content

Commit efdb97a

Browse files
authored
Fix/bsi 2 testing (#450)
* remove ordering * lineup features in ordering * add sbom bomlinks attributes for bsi 2 * fix linting * fix values
1 parent 7883b89 commit efdb97a

File tree

6 files changed

+78
-43
lines changed

6 files changed

+78
-43
lines changed

cmd/list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ var listCmd = &cobra.Command{
7474
# SBOM features:
7575
[sbom_creation_timestamp, sbom_authors, sbom_with_creator_and_version, sbom_with_primary_component, sbom_dependencies,
7676
sbom_sharable, sbom_parsable, sbom_spec, sbom_file_format, sbom_spec_version, spec_with_version_compliant, sbom_with_uri,
77-
sbom_with_vuln, sbom_build_process]
77+
sbom_with_vuln, sbom_build_process, sbom_with_bomlinks]
7878
`,
7979

8080
Args: func(_ *cobra.Command, args []string) error {
@@ -267,5 +267,6 @@ var isFeaturePresent = map[string]bool{
267267
"sbom_with_uri": true,
268268
"sbom_with_vuln": true,
269269
"sbom_build_process": true,
270+
"sbom_with_bomlinks": true,
270271
// "sbom_with_signature": true,
271272
}

pkg/compliance/bsiV2.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func bsiV2Result(ctx context.Context, doc sbom.Document, fileName string, outFor
6464
}
6565
}
6666

67+
// bomlinks
6768
func bsiV2SbomLinks(doc sbom.Document) *db.Record {
6869
result, score := "", 0.0
6970

pkg/list/list.go

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,13 @@ func evaluateComponentFeature(feature string, comp sbom.GetComponent, doc sbom.D
291291
return evaluateCompWithAssociatedLicense(doc, comp)
292292

293293
case "comp_with_concluded_license":
294-
return evaluateCompWithConcludedLicense(doc, comp)
294+
return evaluateCompWithConcludedLicense(comp)
295295

296296
case "comp_with_declared_license":
297-
return evaluateCompWithDeclaredLicense(doc, comp)
297+
return evaluateCompWithDeclaredLicense(comp)
298298

299299
case "comp_with_dependencies":
300-
return evaluateCompWithDependencies(doc, comp)
300+
return evaluateCompWithDependencies(comp)
301301

302302
case "comp_with_any_vuln_lookup_id":
303303
return evaluateCompWithAnyVulnLookupID(comp)
@@ -312,7 +312,7 @@ func evaluateComponentFeature(feature string, comp sbom.GetComponent, doc sbom.D
312312
return evaluateCompWithPrimaryPurpose(doc, comp)
313313

314314
case "comp_with_restrictive_licenses":
315-
return evaluateCompWithRestrictedLicenses(doc, comp)
315+
return evaluateCompWithRestrictedLicenses(comp)
316316

317317
case "comp_with_checksums":
318318
return evaluateCompWithChecksums(comp)
@@ -372,6 +372,9 @@ func evaluateSBOMFeature(feature string, doc sbom.Document) (bool, string, error
372372
case "sbom_build_process":
373373
return evaluateSBOMBuildLifeCycle(doc)
374374

375+
case "sbom_with_bomlinks":
376+
return evaluateSBOMWithBomLinks(doc)
377+
375378
// case "sbom_with_signature":
376379
// return evaluateSBOMWithSignature(doc)
377380

@@ -434,6 +437,9 @@ func evaluateCompWithVersion(comp sbom.GetComponent) (bool, string, error) {
434437

435438
// evaluateCompWithSupplier evaluates if the component has a supplier
436439
func evaluateCompWithSupplier(comp sbom.GetComponent) (bool, string, error) {
440+
if !comp.Suppliers().IsPresent() {
441+
return false, "", nil
442+
}
437443
return comp.Suppliers().IsPresent(), comp.Suppliers().GetName() + "," + comp.Suppliers().GetEmail(), nil
438444
}
439445

@@ -457,7 +463,7 @@ func evaluateCompWithValidLicenses(comp sbom.GetComponent) (bool, string, error)
457463
}
458464

459465
if len(validLicenses) == 0 {
460-
return false, "", nil
466+
return true, "", nil
461467
}
462468
return true, strings.Join(validLicenses, ","), nil
463469
}
@@ -479,6 +485,9 @@ func evaluateCompWithAnyVulnLookupID(comp sbom.GetComponent) (bool, string, erro
479485
allIDs = append(allIDs, purl.String()) // Assuming purl.PURL has a String() method
480486
}
481487

488+
if len(allIDs) == 0 {
489+
return true, "", nil
490+
}
482491
return true, strings.Join(allIDs, ","), nil
483492
}
484493

@@ -500,6 +509,9 @@ func evaluateCompWithMultiVulnLookupID(comp sbom.GetComponent) (bool, string, er
500509
for _, purl := range purls {
501510
allIDs = append(allIDs, purl.String()) // Assuming purl.PURL has a String() method
502511
}
512+
if len(allIDs) == 0 {
513+
return true, "", nil
514+
}
503515

504516
return hasFeature, strings.Join(allIDs, ","), nil
505517
}
@@ -537,7 +549,7 @@ func evaluateCompWithPrimaryPurpose(doc sbom.Document, comp sbom.GetComponent) (
537549
}
538550

539551
// evaluateCompWithRestrictedLicenses evaluates if the component has any restrictive licenses
540-
func evaluateCompWithRestrictedLicenses(doc sbom.Document, comp sbom.GetComponent) (bool, string, error) {
552+
func evaluateCompWithRestrictedLicenses(comp sbom.GetComponent) (bool, string, error) {
541553
licenses := comp.Licenses()
542554
if len(licenses) == 0 {
543555
return false, "", nil
@@ -573,6 +585,9 @@ func evaluateCompWithChecksums(comp sbom.GetComponent) (bool, string, error) {
573585
for _, checksum := range checksums {
574586
checksumValues = append(checksumValues, checksum.GetAlgo()) // Assuming sbom.GetChecksum has a GetAlgo() method
575587
}
588+
if len(checksumValues) == 0 {
589+
return true, "", nil
590+
}
576591
return true, strings.Join(checksumValues, ","), nil
577592
}
578593

@@ -589,6 +604,9 @@ func evaluateCompWithLicenses(comp sbom.GetComponent) (bool, string, error) {
589604
licenseNames = append(licenseNames, l.Name())
590605
}
591606
}
607+
if len(licenseNames) == 0 {
608+
return true, "", nil
609+
}
592610

593611
return true, strings.Join(licenseNames, ","), nil
594612
}
@@ -610,7 +628,7 @@ func evaluateCompWithSHA256Checksums(comp sbom.GetComponent) (bool, string, erro
610628
}
611629

612630
if len(sha256Checksums) == 0 {
613-
return false, "", nil
631+
return true, "", nil
614632
}
615633
return true, strings.Join(sha256Checksums, ","), nil
616634
}
@@ -685,7 +703,7 @@ func evaluateCompWithAssociatedLicense(doc sbom.Document, comp sbom.GetComponent
685703
}
686704

687705
// evaluateCompWithConcludedLicense evaluates if the component has a concluded license
688-
func evaluateCompWithConcludedLicense(doc sbom.Document, comp sbom.GetComponent) (bool, string, error) {
706+
func evaluateCompWithConcludedLicense(comp sbom.GetComponent) (bool, string, error) {
689707
var concludedLicense []string
690708
for _, l := range comp.ConcludedLicenses() {
691709
if l != nil {
@@ -700,7 +718,7 @@ func evaluateCompWithConcludedLicense(doc sbom.Document, comp sbom.GetComponent)
700718
}
701719

702720
// evaluateCompWithDeclaredLicense evaluates if the component has a declared license
703-
func evaluateCompWithDeclaredLicense(doc sbom.Document, comp sbom.GetComponent) (bool, string, error) {
721+
func evaluateCompWithDeclaredLicense(comp sbom.GetComponent) (bool, string, error) {
704722
var declaredLicense []string
705723
for _, l := range comp.DeclaredLicenses() {
706724
if l != nil {
@@ -715,7 +733,7 @@ func evaluateCompWithDeclaredLicense(doc sbom.Document, comp sbom.GetComponent)
715733
}
716734

717735
// evaluateCompWithDependencies evaluates if the component has dependencies
718-
func evaluateCompWithDependencies(doc sbom.Document, comp sbom.GetComponent) (bool, string, error) {
736+
func evaluateCompWithDependencies(comp sbom.GetComponent) (bool, string, error) {
719737
if comp == nil {
720738
return false, "", fmt.Errorf("component is nil")
721739
}
@@ -905,3 +923,18 @@ func evaluateSBOMBuildLifeCycle(doc sbom.Document) (bool, string, error) {
905923

906924
return true, lifecycles[found-1], nil
907925
}
926+
927+
// evaluateSBOMWithBomLinks evaluates if the SBOM has BOM links
928+
func evaluateSBOMWithBomLinks(doc sbom.Document) (bool, string, error) {
929+
bomLinks := doc.Spec().GetExtDocRef()
930+
if len(bomLinks) == 0 {
931+
return false, "", nil
932+
}
933+
934+
linkValues := make([]string, 0, len(bomLinks))
935+
linkValues = append(linkValues, bomLinks...)
936+
if len(linkValues) == 0 {
937+
return false, "", nil
938+
}
939+
return true, strings.Join(linkValues, ", "), nil
940+
}

pkg/reporter/detailed.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ package reporter
1717
import (
1818
"fmt"
1919
"os"
20-
"sort"
21-
"strings"
2220

2321
"github.com/fatih/color"
2422
"github.com/olekukonko/tablewriter"
@@ -41,16 +39,6 @@ func (r *Reporter) detailedReport() {
4139
outDoc = append(outDoc, l)
4240
}
4341

44-
sort.Slice(outDoc, func(i, j int) bool {
45-
switch strings.Compare(outDoc[i][0], outDoc[j][0]) {
46-
case -1:
47-
return true
48-
case 1:
49-
return false
50-
}
51-
return outDoc[i][1] < outDoc[j][1]
52-
})
53-
5442
fmt.Printf("SBOM Quality by Interlynk Score:%0.1f\tcomponents:%d\t%s\n", scores.AvgScore(), len(doc.Components()), path)
5543

5644
// Initialize tablewriter table with borders

pkg/scorer/bsi.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,20 @@ func compWithSourceCodeHashCheck(d sbom.Document, c *check) score {
258258
return *s
259259
}
260260

261+
func sbomWithBomLinksCheck(doc sbom.Document, c *check) score {
262+
s := newScoreFromCheck(c)
263+
bom := doc.Spec().GetExtDocRef()
264+
if len(bom) == 0 {
265+
s.setScore(0.0)
266+
s.setDesc("no bom links found")
267+
// s.setIgnore(true)
268+
return *s
269+
}
270+
s.setScore(10.0)
271+
s.setDesc(fmt.Sprintf("found %d bom links", len(bom)))
272+
return *s
273+
}
274+
261275
// v2.1
262276
func sbomWithVulnCheck(doc sbom.Document, c *check) score {
263277
s := newScoreFromCheck(c)
@@ -326,7 +340,7 @@ func sbomWithSignatureCheck(doc sbom.Document, c *check) score {
326340
pubKeyData, err := os.ReadFile(pubKey)
327341
if err != nil {
328342
s.setScore(0.0)
329-
s.setDesc("No signature provided or public key not found!")
343+
s.setDesc("No signature or public key provided!")
330344
// s.setIgnore(true)
331345
return *s
332346
}

pkg/scorer/criteria.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,14 @@ type check struct {
3939
}
4040

4141
var checks = []check{
42-
// structural
43-
{string(structural), "sbom_spec", false, "SBOM Specification", specCheck},
44-
{string(structural), "sbom_spec_version", false, "Spec Version", specVersionCheck},
45-
{string(structural), "sbom_file_format", false, "SBOM File Format", sbomFileFormatCheck},
46-
{string(structural), "sbom_parsable", false, "Spec is parsable", specParsableCheck},
47-
4842
// ntia minimum
49-
{string(ntiam), "comp_with_supplier", false, "components have suppliers", compWithSupplierCheck},
5043
{string(ntiam), "comp_with_name", false, "components have a name", compWithNameCheck},
5144
{string(ntiam), "comp_with_version", false, "components have a version", compWithVersionCheck},
5245
{string(ntiam), "comp_with_uniq_ids", false, "components have uniq ids", compWithUniqIDCheck},
53-
{string(ntiam), "sbom_dependencies", false, "sbom has dependencies", sbomWithDepedenciesCheck},
54-
{string(ntiam), "sbom_authors", false, "sbom has authors", sbomWithAuthorsCheck},
46+
{string(ntiam), "comp_with_supplier", false, "components have suppliers", compWithSupplierCheck},
5547
{string(ntiam), "sbom_creation_timestamp", false, "sbom has creation timestamp", sbomWithTimeStampCheck},
48+
{string(ntiam), "sbom_authors", false, "sbom has authors", sbomWithAuthorsCheck},
49+
{string(ntiam), "sbom_dependencies", false, "primary comp has dependencies", sbomWithDepedenciesCheck},
5650

5751
// bsi-v1.1
5852
{string(bsiv1_1), "comp_with_name", false, "components have a name", compWithNameCheck},
@@ -64,36 +58,34 @@ var checks = []check{
6458
{string(bsiv1_1), "comp_with_source_code_uri", false, "components have source code URI", compWithSourceCodeURICheck},
6559
{string(bsiv1_1), "comp_with_source_code_hash", false, "components have source code hash", compWithSourceCodeHashCheck},
6660
{string(bsiv1_1), "comp_with_executable_uri", false, "components have executable URI", compWithExecutableURICheck},
61+
{string(bsiv1_1), "comp_with_dependencies", false, "components have dependencies", compWithDependencyCheck},
6762
{string(bsiv1_1), "spec_with_version_compliant", false, "SBOM Specification", specWithVersionCompliant},
68-
{string(bsiv1_1), "sbom_authors", false, "sbom has authors", sbomWithAuthorsCheck},
6963
{string(bsiv1_1), "sbom_creation_timestamp", false, "sbom has creation timestamp", sbomWithTimeStampCheck},
64+
{string(bsiv1_1), "sbom_authors", false, "sbom has authors", sbomWithAuthorsCheck},
7065
{string(bsiv1_1), "sbom_dependencies", false, "sbom has dependencies", sbomWithDepedenciesCheck},
7166
{string(bsiv1_1), "sbom_with_uri", false, "sbom has URI", sbomWithURICheck},
72-
{string(bsiv1_1), "comp_with_dependencies", false, "components have dependencies", compWithDependencyCheck},
7367

7468
// bsi-v2.0.0
7569
{string(bsiv2_0), "comp_with_name", false, "components have a name", compWithNameCheck},
7670
{string(bsiv2_0), "comp_with_version", false, "components have a version", compWithVersionCheck},
7771
{string(bsiv2_0), "comp_with_uniq_ids", false, "components have uniq ids", bsiCompWithUniqIDCheck},
7872
{string(bsiv2_0), "comp_with_supplier", false, "components have suppliers", compWithSupplierCheck},
79-
8073
{string(bsiv2_0), "comp_with_associated_license", false, "components have associated licenses", compWithAssociatedLicensesCheck},
8174
{string(bsiv2_0), "comp_with_concluded_license", false, "components have concluded licenses", compWithConcludedLicensesCheck},
8275
{string(bsiv2_0), "comp_with_declared_license", false, "components have declared licenses", compWithDeclaredLicensesCheck},
83-
{string(bsiv2_0), "comp_with_dependencies", false, "components have dependencies", compWithDependencyCheck},
84-
8576
{string(bsiv2_0), "comp_with_source_code_uri", false, "components have source code URI", compWithSourceCodeURICheck},
8677
{string(bsiv2_0), "comp_with_source_code_hash", false, "components have source code hash", compWithSourceCodeHashCheck},
8778
{string(bsiv2_0), "comp_with_executable_uri", false, "components have executable URI", compWithExecutableURICheck},
8879
{string(bsiv2_0), "comp_with_executable_hash", false, "components have executable checksums", compWithSHA256ChecksumsCheck},
89-
90-
{string(bsiv2_0), "sbom_with_vuln", false, "SBOM has vulnerability", sbomWithVulnCheck},
80+
{string(bsiv2_0), "comp_with_dependencies", false, "components have dependencies", compWithDependencyCheck},
9181
{string(bsiv2_0), "spec_with_version_compliant", false, "SBOM Specification", specWithVersionCompliant},
92-
{string(bsiv2_0), "sbom_build_process", false, "SBOM build process", sbomBuildLifecycleCheck},
93-
{string(bsiv2_0), "sbom_authors", false, "sbom has authors", sbomWithAuthorsCheck},
9482
{string(bsiv2_0), "sbom_creation_timestamp", false, "sbom has creation timestamp", sbomWithTimeStampCheck},
95-
{string(bsiv2_0), "sbom_dependencies", false, "primary comp has dependencies", sbomWithDepedenciesCheck},
83+
{string(bsiv2_0), "sbom_authors", false, "sbom has authors", sbomWithAuthorsCheck},
84+
{string(bsiv2_0), "sbom_build_process", false, "SBOM build process", sbomBuildLifecycleCheck},
9685
{string(bsiv2_0), "sbom_with_uri", false, "sbom has URI", sbomWithURICheck},
86+
{string(bsiv2_0), "sbom_dependencies", false, "primary comp has dependencies", sbomWithDepedenciesCheck},
87+
{string(bsiv2_0), "sbom_with_bomlinks", false, "sbom has bomlinks", sbomWithBomLinksCheck},
88+
{string(bsiv2_0), "sbom_with_vuln", false, "SBOM has vulnerability", sbomWithVulnCheck},
9789
{string(bsiv2_0), "sbom_with_signature", false, "sbom has signature", sbomWithSignatureCheck},
9890

9991
// semantic
@@ -113,4 +105,10 @@ var checks = []check{
113105

114106
// sharing
115107
{string(sharing), "sbom_sharable", false, "sbom document has a sharable license", sharableLicenseCheck},
108+
109+
// structural
110+
{string(structural), "sbom_spec", false, "SBOM Specification", specCheck},
111+
{string(structural), "sbom_spec_version", false, "Spec Version", specVersionCheck},
112+
{string(structural), "sbom_file_format", false, "SBOM File Format", sbomFileFormatCheck},
113+
{string(structural), "sbom_parsable", false, "Spec is parsable", specParsableCheck},
116114
}

0 commit comments

Comments
 (0)