Skip to content

BOMFormat not set when reading XML CycloneDx SBOM #245

@chrsch-dev

Description

@chrsch-dev

Decoding this example SBOM

<?xml version="1.0" encoding="UTF-8"?>
<bom xmlns="http://cyclonedx.org/schema/bom/1.6"
    serialNumber="urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79"
    version="1">    
</bom>

results in a bom object that has no BOMFormat value. When encoding this to a json file it results in the following SBOM

{
  "bomFormat": "",
  "specVersion": "1.6",
  "serialNumber": "urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79",
  "version": 1
}

Expected Result:
Based on the input information the BOMFormat should have been set to CycloneDX.

Example coding:

bomFile, err := os.ReadFile("sbom_data/example.xml")
if err != nil {
	panic(err)
}

// Decode the BOM
bom := new(cdx.BOM)
decoder := cdx.NewBOMDecoder(bytes.NewReader(bomFile), cdx.BOMFileFormatXML)
if err = decoder.Decode(bom); err != nil {
	panic(err)
}

fmt.Printf("Successfully decoded BOM\n")
fmt.Printf("BomFormat %s\n", bom.BOMFormat)
// fmt.Printf("- Generated: %s with %s\n", bom.Metadata.Timestamp, (*bom.Metadata.Tools.Tools)[0].Name)
// fmt.Printf("- Components: %d\n", len(*bom.Components))

// Write SBOM into file
outputBuf := new(bytes.Buffer)
encoder := cdx.NewBOMEncoder(outputBuf, cdx.BOMFileFormatJSON)
encoder.SetPretty(true)
if err = encoder.Encode(bom); err != nil {
	panic(err)
}
os.WriteFile("sbom_data/example.json", outputBuf.Bytes(), 0644)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions