Package: lib4sbom
Lib4SBOMLib4SBOM is a library to parse and generate Software Bill of Materials (SBOMs). It supports SBOMs created in bothSPDXandCycloneDXformats.It has been developed on the assumption that having a generic abstraction of SBOM regardless of the underlying format will be useful to developers.The following facilities are provided:Generate SPDX SBOM in TagValue, JSON and YAML formatsGenerate CycloneDX SBOM in JSON formatParse SPDX SBOM in TagValue, JSON, YAML, XML and RDF formatsParse CycloneDX SBOM in JSON and XMLformatCreate and manipulate a SBOM file objectCreate and manipulate a SBOM package objectCreate and manipulate a SBOM dependency relationship objectCreate and manipulate a Vulnerability objectGenerated SBOM can be output to a file or to the consoleInstallationTo install use the following command:pip install lib4sbomAlternatively, just clone the repo and install dependencies using the following command:pip install -U -r requirements.txtThe tool requires Python 3 (3.7+). It is recommended to use a virtual python environment especially
if you are using different versions of python.virtualenvis a tool for setting up virtual python environments which
allows you to have all the dependencies for the tool set up in a single environment, or have different environments set
up for testing using different versions of Python.APISBOMParserThe SBOMParser module provides methods for parsing a SBOM in either SPDX or CycloneDX format and
returns the file, package and relationship information from within the SBOM.The focus of the implementation is on providing a common set of SBOM data regardless of the SBOM format.SBOMs are supported in the following formatsSBOM TypeVersionFormatSPDX2.2TagValueSPDX2.2JSONSPDX2.2YAMLSPDX2.2RDFSPDX2.2XMLSPDX2.3TagValueSPDX2.3JSONSPDX2.3YAMLSPDX2.3RDFSPDX2.3XMLCycloneDX1.4JSONCycloneDX1.4XMLCycloneDX1.5JSONCycloneDX1.5XMLNotethat support for SPDX RDF and XML formats is limited to a few package attributes.classSBOMParser(sbom_type='auto')This creates a simple SBOM Parser object. A single optional parameter,sbom_type, can be specified
which represents the type of SBOM (either spdx, cyclonedx or auto). The default is auto in
which case the parser will automatically work out the SBOM type using the
following filename conventions.SBOMFormatFilename extensionSPDXTagValue.spdxSPDXJSON.spdx.jsonSPDXYAML.spdx.yamlSPDXYAML.spdx.ymlSPDXRDF.spdx.rdfSPDXXML.spdx.xmlCycloneDXJSON.jsonCycloneDXXML.xmlThe parser will check that the correct JSON files is being processed by the correct parser.
A SPDX JSON file submitted to the CycloneDX parser will result in no data being processed.Methodsparse_file(filename)
Parses the SBOM file. If the file does not exist, a FileNotFoundError exception is raised.get_files()
Returns a list of file elements from within a parsed SBOMget_packages()
Returns a list of packages elements from within a parsed SBOMget_relationships()
Returns the relationship elements from within a parsed SBOMget_type()
Returns the type of SBOM (either spdx or cyclonedx)ExampleA test SBOM file (test_sbom.spdx) is used in the following example.SPDXVersion:SPDX-2.2
DataLicense:CC0-1.0
SPDXID:SPDXRef-DOCUMENT
DocumentName:virtualenv
DocumentNamespace:http://spdx.org/spdxdocs/virtualenv-b7ac9cce-efe8-4fe7-a544-100e6a5664e6
LicenseListVersion:3.18
Creator:Tool:sbom4python-0.4.0
Created:2022-11-16T10:14:26Z
CreatorComment:<text>Thisdocumenthasbeenautomaticallygenerated.</text>#####PackageName:virtualenv
SPDXID:SPDXRef-Package-1-virtualenv
PackageSupplier:Person:Bernat_Gabor
PackageVersion:20.16.7
PackageDownloadLocation:NOASSERTION
FilesAnalyzed:falsePackageLicenseConcluded:MIT
PackageLicenseDeclared:MIT
PackageCopyrightText:NOASSERTION
ExternalRef:PACKAGE-MANAGERpurlpkg:pypi/virtualenv@20.16.7#####PackageName:distlib
SPDXID:SPDXRef-Package-2-distlib
PackageSupplier:Person:Vinay_Sajip
PackageVersion:0.3.6
PackageDownloadLocation:NOASSERTION
FilesAnalyzed:falsePackageLicenseConcluded:NOASSERTION
PackageLicenseDeclared:NOASSERTION
PackageCopyrightText:NOASSERTION
ExternalRef:PACKAGE-MANAGERpurlpkg:pypi/distlib@0.3.6#####PackageName:filelock
SPDXID:SPDXRef-Package-3-filelock
PackageSupplier:Person:Benedikt_Schmitt
PackageVersion:3.8.0
PackageDownloadLocation:NOASSERTION
FilesAnalyzed:falsePackageLicenseConcluded:Unlicense
PackageLicenseDeclared:Unlicense
PackageCopyrightText:NOASSERTION
ExternalRef:PACKAGE-MANAGERpurlpkg:pypi/filelock@3.8.0#####PackageName:platformdirs
SPDXID:SPDXRef-Package-4-platformdirs
PackageSupplier:NOASSERTION
PackageVersion:2.5.4
PackageDownloadLocation:NOASSERTION
FilesAnalyzed:falsePackageLicenseConcluded:NOASSERTION
PackageLicenseDeclared:NOASSERTION
PackageCopyrightText:NOASSERTION
ExternalRef:PACKAGE-MANAGERpurlpkg:pypi/platformdirs@2.5.4

Relationship:SPDXRef-DOCUMENTDESCRIBESSPDXRef-Package-1-virtualenv
Relationship:SPDXRef-Package-1-virtualenvCONTAINSSPDXRef-Package-2-distlib
Relationship:SPDXRef-Package-1-virtualenvCONTAINSSPDXRef-Package-3-filelock
Relationship:SPDXRef-Package-1-virtualenvCONTAINSSPDXRef-Package-4-platformdirsThe following code sample shows the use of the SBOMParser module.>>>fromlib4sbom.parserimportSBOMParser>>>test_parser=SBOMParser()>>>print(f"SBOM type{test_parser.get_type()}")SBOMtypeauto>>>test_parser.parse_file("test_sbom.spdx")>>>print(f"SBOM type{test_parser.get_type()}")SBOMtypespdx>>>sbom_files=test_parser.get_files()>>>print(sbom_files)[]>>>sbom_packages=test_parser.get_packages()>>>print(sbom_packages)[{'name':'virtualenv','type':'library','id':'SPDXRef-Package-1-virtualenv','supplier_type':'Person','supplier':'Bernat_Gabor','version':'20.16.7','downloadlocation':'NOASSERTION','filesanalysis':'false','licenseconcluded':'MIT','licensedeclared':'MIT','externalreference':[['PACKAGE-MANAGER','purl','pkg:pypi/virtualenv@20.16.7']]},{'name':'distlib','type':'library','id':'SPDXRef-Package-2-distlib','supplier_type':'Person','supplier':'Vinay_Sajip','version':'0.3.6','downloadlocation':'NOASSERTION','filesanalysis':'false','licenseconcluded':'NOASSERTION','licensedeclared':'NOASSERTION','externalreference':[['PACKAGE-MANAGER','purl','pkg:pypi/distlib@0.3.6']]},{'name':'filelock','type':'library','id':'SPDXRef-Package-3-filelock','supplier_type':'Person','supplier':'Benedikt_Schmitt','version':'3.8.0','downloadlocation':'NOASSERTION','filesanalysis':'false','licenseconcluded':'Unlicense','licensedeclared':'Unlicense','externalreference':[['PACKAGE-MANAGER','purl','pkg:pypi/filelock@3.8.0']]},{'name':'platformdirs','type':'library','id':'SPDXRef-Package-4-platformdirs','supplier_type':'Organization','supplier':'Unknown','version':'2.5.4','downloadlocation':'NOASSERTION','filesanalysis':'false','licenseconcluded':'NOASSERTION','licensedeclared':'NOASSERTION','externalreference':[['PACKAGE-MANAGER','purl','pkg:pypi/platformdirs@2.5.4']]}]>>>print(len(sbom_packages))4>>>sbom_packages[0]{'name':'virtualenv','type':'library','id':'SPDXRef-Package-1-virtualenv','supplier_type':'Person','supplier':'Bernat_Gabor','version':'20.16.7','downloadlocation':'NOASSERTION','filesanalysis':'false','licenseconcluded':'MIT','licensedeclared':'MIT','externalreference':[['PACKAGE-MANAGER','purl','pkg:pypi/virtualenv@20.16.7']]}>>>sbom_relationships=test_parser.get_relationships()>>>print(sbom_relationships)[{'source':'TestDocument','type':'DESCRIBES','target':'virtualenv','source_id':'SPDXRef-DOCUMENT','target_id':'SPDXRef-Package-1-virtualenv'},{'source':'virtualenv','type':'CONTAINS','target':'distlib','source_id':'SPDXRef-Package-1-virtualenv','target_id':'SPDXRef-Package-2-distlib'},{'source':'virtualenv','type':'CONTAINS','target':'filelock','source_id':'SPDXRef-Package-1-virtualenv','target_id':'SPDXRef-Package-3-filelock'},{'source':'virtualenv','type':'CONTAINS','target':'platformdirs','source_id':'SPDXRef-Package-1-virtualenv','target_id':'SPDXRef-Package-4-platformdirs'}]>>>sbom_relationships[2]{'source':'virtualenv','type':'CONTAINS','target':'filelock','source_id':'SPDXRef-Package-1-virtualenv','target_id':'SPDXRef-Package-3-filelock'}>>>SBOMGeneratorThe SBOMGenerator module provides methods for generating a SBOM in either SPDX or CycloneDX format.The focus of the implementation is on providing a single interface regardless of the SBOM type and format.SBOMs can be generated in the following formatsSBOM TypeVersionFormatSPDX2.2TagSPDX2.2JSONSPDX2.2YAMLSPDX2.3TagSPDX2.3JSONSPDX2.3YAMLCycloneDX1.4JSONCycloneDX1.5JSONThe default version for CycloneDX is version 1.5. However, the version can be overridden by setting the environment variable LIB4SBOM_CYCLONEDX_VERSION to "1.4" if required.classSBOMGenerator(validate_license: True, sbom_type="spdx", format="tag", application="lib4sbom", version="0.1")This creates a simple SBOM Generator object. The following optional parameters can be specified:validate_licenseindicates if license information is validated against the set ofSPDX license identifiers. This option only applies for SPDX SBOMs
as this is mandatory for CycloneDX SBOMs.sbom_typeindicates the type of SBOM to be generated. Valid options are spdx or cyclonedxformatindicates the format that the SBOM is to be generated in. Valid options are Tag, JSON or YAML. If an invalid format is specified,
a default format of JSON will be assumed. If an unsupported format is specified for the type of SBOM (e.g. Tag or YAML for CycloneDX), a default
format is assumed (Tag for SPDX, JSON for CycloneDX)applicationandversionspecify the name and version of the tool which created the SBOM. If these are not specified, the application name is 'lib4sbom' and the version is '0.1'Methodsgenerate(project_name, sbom_data, filename = "", send_to_output = True)The method generates the SBOM file. The parameters areproject_namespecifies the name of the projectsbom_datacontain the SBOM data to be used in the generation. It contains details of the packages, files and relationships to be included in the SBOM.filenameis the name of the file to be generated. The default is for the output to be generated to a console.send_to_outputindicates if the output is to be sent to the filename.get_sbom()
Returns the generated SBOM in the requested formatget_type()
Returns the type of the generated SBOM (either spdx or cyclonedx)get_format()
Returns the format of the generated SBOM (one of tag, json or yaml)ExampleThe following code sample shows the use of the SBOMGenerator module being used
in the conversion of a SBOM from the Tag Value format to YAML format. The output is sent ot the console.>>>fromlib4sbom.parserimportSBOMParser>>>test_parser=SBOMParser()>>>test_parser.parse_file("test_sbom.spdx")>>>fromlib4sbom.generatorimportSBOMGenerator>>>test_generator=SBOMGenerator(format="yaml")>>>test_generator.get_type()'spdx'>>>test_generator.get_format()'yaml'>>>test_generator.generate("TestApp",test_parser.get_sbom())SPDXID:SPDXRef-DOCUMENTcreationInfo:comment:Thisdocumenthasbeenautomaticallygenerated.created:'2023-01-24T13:51:36Z'creators:-'Tool: lib4sbom-0.1.0'licenseListVersion:'3.18'dataLicense:CC0-1.0documentNamespace:http://spdx.org/spdxdocs/TestDocument-817c4e4c-eac4-49d9-bc41-65f0972edce8name:TestDocument...-relatedSpdxElement:SPDXRef-Package-4-platformdirsrelationshipType:DESCRIBESspdxElementId:SPDXRef-DOCUMENT-relatedSpdxElement:SPDXRef-Package-2-distlibrelationshipType:CONTAINSspdxElementId:SPDXRef-Package-1-virtualenv-relatedSpdxElement:SPDXRef-Package-3-filelockrelationshipType:CONTAINSspdxElementId:SPDXRef-Package-1-virtualenv-relatedSpdxElement:SPDXRef-Package-4-platformdirsrelationshipType:CONTAINSspdxElementId:SPDXRef-Package-1-virtualenvspdxVersion:SPDX-2.3>>>test_generator.get_sbom(){'SPDXID':'SPDXRef-DOCUMENT','spdxVersion':'SPDX-2.3','creationInfo':{'comment':'This document has been automatically generated.','creators':['Tool: lib4sbom-0.1.0'],'created':'2023-01-24T13:51:36Z','licenseListVersion':'3.18'},'name':'TestDocument','dataLicense':'CC0-1.0','documentNamespace':'http://spdx.org/spdxdocs/TestDocument-817c4e4c-eac4-49d9-bc41-65f0972edce8','packages':[{'SPDXID':'SPDXRef-Package-1-virtualenv','name':'virtualenv','versionInfo':'20.16.7','supplier':'Person: Bernat_Gabor','downloadLocation':'NONE','filesAnalyzed':'false','licenseConcluded':'MIT','licenseDeclared':'MIT','copyrightText':'NOASSERTION','externalRefs':[{'referenceCategory':'PACKAGE-MANAGER','referenceType':'purl','referenceLocator':'pkg:pypi/virtualenv@20.16.7'}]},{'SPDXID':'SPDXRef-Package-2-distlib','name':'distlib','versionInfo':'0.3.6','supplier':'Person: Vinay_Sajip','downloadLocation':'NONE','filesAnalyzed':'false','licenseConcluded':'NOASSERTION','licenseDeclared':'NOASSERTION','copyrightText':'NOASSERTION','externalRefs':[{'referenceCategory':'PACKAGE-MANAGER','referenceType':'purl','referenceLocator':'pkg:pypi/distlib@0.3.6'}]},{'SPDXID':'SPDXRef-Package-3-filelock','name':'filelock','versionInfo':'3.8.0','supplier':'Person: Benedikt_Schmitt','downloadLocation':'NONE','filesAnalyzed':'false','licenseConcluded':'Unlicense','licenseDeclared':'Unlicense','copyrightText':'NOASSERTION','externalRefs':[{'referenceCategory':'PACKAGE-MANAGER','referenceType':'purl','referenceLocator':'pkg:pypi/filelock@3.8.0'}]},{'SPDXID':'SPDXRef-Package-4-platformdirs','name':'platformdirs','versionInfo':'2.5.4','supplier':'Organization: Unknown','downloadLocation':'NONE','filesAnalyzed':'false','licenseConcluded':'NOASSERTION','licenseDeclared':'NOASSERTION','copyrightText':'NOASSERTION','externalRefs':[{'referenceCategory':'PACKAGE-MANAGER','referenceType':'purl','referenceLocator':'pkg:pypi/platformdirs@2.5.4'}]}],'relationships':[{'spdxElementId':'SPDXRef-DOCUMENT','relatedSpdxElement':'SPDXRef-Package-1-virtualenv','relationshipType':'DESCRIBES'},{'spdxElementId':'SPDXRef-DOCUMENT','relatedSpdxElement':'SPDXRef-Package-2-distlib','relationshipType':'DESCRIBES'},{'spdxElementId':'SPDXRef-DOCUMENT','relatedSpdxElement':'SPDXRef-Package-3-filelock','relationshipType':'DESCRIBES'},{'spdxElementId':'SPDXRef-DOCUMENT','relatedSpdxElement':'SPDXRef-Package-4-platformdirs','relationshipType':'DESCRIBES'},{'spdxElementId':'SPDXRef-Package-1-virtualenv','relatedSpdxElement':'SPDXRef-Package-2-distlib','relationshipType':'CONTAINS'},{'spdxElementId':'SPDXRef-Package-1-virtualenv','relatedSpdxElement':'SPDXRef-Package-3-filelock','relationshipType':'CONTAINS'},{'spdxElementId':'SPDXRef-Package-1-virtualenv','relatedSpdxElement':'SPDXRef-Package-4-platformdirs','relationshipType':'CONTAINS'}]}>>>SBOMOutputclassSBOMOutput(filename="", output_format="tag")This creates a simple SBOM Output object. The following optional parameters can be specified:filenameindicates the output destination of the SBOM to be generated. If a valid filename path is provided and a file can be created, then the output will be to a file otherwise
it will be output to the console.output_formatindicates the format that the SBOM is to be generated in. Valid options are Tag, JSON or YAML. If an invalid format is specified,
a default format of Tag will be assumed.Methodsgenerate_output(dataset) Outputs a SBOM file. The parameters aredatasetcontains SBOM data in the output format. If the SBOM data is NOT in the format specified by the output_format parameter, no output will be generated.NOTE A valid dataset will normally be generated by the SBOMGenerator class and obtained by a call to the get_sbom() method.get_type()
Return the destination of the generated SBOM. Either file or consoleget_format()
Return the format of the generated SBOM. One of Tag, JSON or YAML.ExampleThe following code sample shows the use of the SBOMOutput module.>>>fromlib4sbom.parserimportSBOMParser>>>test_parser=SBOMParser()>>>test_parser.parse_file("test_sbom.spdx")>>>fromlib4sbom.generatorimportSBOMGenerator>>>test_generator=SBOMGenerator(format="json")>>>test_generator.generate("TestApp",test_parser.get_sbom())>>>fromlib4sbom.outputimportSBOMOutput>>>sbom_output=SBOMOutput(filename="testapp.json",output_format="json")>>>sbom_output.generate_output(test_generator.get_sbom())>>>SBOM ObjectclassSBOM()This creates a simple SBOM object. This object contains all the items to be contained within the SBOM including
components and relationships. It is left to the application manipulating the SBOM object to apply validation as appropriate
for the presence of each attribute.MethodsSetter MethodsFor the following attributes, a methodset_attribute(value)is provided. Note that the attribute name is always inlowercase.
e.g. set_type(). Unless indicated, the method just takes a single parameter for the value. Where indicated, multiple instances of the attribute may be defined.AttributeMultipleNoteVersionNo(1)TypeNo(2)UuidNo(3)Bom_VersionNoNote1 This relates to the version of the specification of SBOM specified by the type atrribute. e.g. 1.4 for CycloneDX, SPDX-2.3 for SPDX.
2 This refers to the type of SBOM either SPDX or CycloneDX.
3 This relates to the unique identifier for the SBOM.Getter Methodsget_sbom()
Returns the SBOM object as a dictionary.Example>>>fromlib4sbom.sbomimportSBOM>>>sbom=SBOM()>>>sbom.set_type(sbom_type='cyclonedx')>>>sbom.set_version("1.4")>>>sbom.set_uuid("urn:uuid:My_uuid_1234")>>>sbom.set_bom_version("2")>>>sbom.get_type()'cyclonedx'>>>fromlib4sbom.data.documentimportSBOMDocument>>>my_doc=SBOMDocument()>>>my_doc.set_metadata_type("firmware")>>>sbom.add_document(my_doc.get_document())SBOMDocument ObjectclassSBOMDocument()This creates a simple SBOMDocument object. This object contains the values of the attributes
that can be associated with a SBOM. This includes attributes such as name, identifier, type of file,
checksum and licence information. As each of the attributes are optional, it is left to the application manipulating the
SBOMFile object to apply validation as appropriate for the presence of each attribute.MethodsSetter MethodsFor the following attributes, a methodset_attribute(value)is provided. Note that the attribute name is always inlowercase.
e.g. set_filetype(). The attribute names are aligned with the attributes of the File Object in the SPDX Specification. Unless
indicated, the method just takes a single parameter for the value. Where indicated, multiple instances of the attribute may be defined.AttributeMultipleNoteNameNoIdNoDataLicenseNoMetadata_TypeNo(1)Metadata_SupplierNoMetadata_VersionNoBom_VersionNoNote1 This relates to the type of component which the SBOM is describing. This is attribute is only used for CycloneDX SBOMs.There is an additional setter method,set_value(attribute, value) which allows the setting of any attribute.set_value("language", "Rust")Getter Methodsget_document()
Returns the SBOMDocument object as a list.get_name()
Returns the name of the SBOMDocument object or a default value if the attribute does not exist within the instance of the SBOMDocument object.get_value(attribute)
Returns the value of the attribute. A default value is returned if the attribute does not exist within the instance of the SBOMDocument object.Example>>>fromlib4sbom.data.documentimportSBOMDocument>>>sbom_document=SBOMDocument()>>>sbom_document.set_name("test_file")>>>sbom_document.set_metadata_type("firmware")>>>sbom_document.get_name()'test_file'>>>fromlib4sbom.sbomimportSBOM>>>my_sbom=SBOM()>>>my_sbom.add_document(sbom_document.get_document())SBOMFile ObjectclassSBOMFile()This creates a simple SBOM File object. This object contains the values of the attributes
that can be associated with a file artefact within an SBOM. This includes attributes such as name, identifier, type of file,
checksum and licence information. As each of the attributes are optional, it is left to the application manipulating the
SBOMFile object to apply validation as appropriate for the presence of each attribute.MethodsSetter MethodsFor the following attributes, a methodset_attribute(value)is provided. Note that the attribute name is always inlowercase.
e.g. set_filetype(). The attribute names are aligned with the attributes of the File Object in the SPDX Specification. Unless
indicated, the method just takes a single parameter for the value. Where indicated, multiple instances of the attribute may be defined.AttributeMultipleNoteNameNoIdNoFileTypeYesChecksumYes(1)LicenseConcludedNoLicenceInfoInFileYesLicenceCommentNoCopyrightTextNoCommentNoNoticeNoContributorYesAttributionNoNote1 The set_checksum method takes two parameters, the checksum algorithm (e.g. SHA256) and the actual checksum value (as a string)There is an additional setter method,set_value(attribute, value) which allows the setting of any attribute.set_value("language", "Rust")Getter Methodsget_file()
Returns the SBOMFile object as a dictionary. The value of an attribute is returned as a string except where multiple instances of an attribute are allowed in which
case the value of the attribute is returned as a List.get_name()
Returns the name of the SBOMFile object or None if the 'name' attribute does not exist within the instance of the SBOMFile object.get_value(attribute)
Returns the value of the attribute. A default value is returned if the attribute does not exist within the instance of the SBOMFile object.Utility Methodsinitialise() Reinitialises a SBOMFile Object. All data associated with the object is deleted.Example>>>fromlib4sbom.data.fileimportSBOMFile>>>sbom_file=SBOMFile()>>>sbom_files={}>>>sbom_file.initialise()>>>sbom_file.set_name("test_file.c")>>>sbom_file.set_licenseconcluded("MIT")>>>file_hash=<<<somecalculation>>>>>>sbom_file.set_checksum("SHA1",file_hash)>>>sbom_file.set_id("SPDXRef-File-0001")>>>sbom_files[sbom_file.get_name()]=sbom_file.get_file()>>>sbom_file.initialise()>>>sbom_file.set_name("makefile")>>>sbom_file.set_licenseconcluded("NOASSERTION")>>>sbom_file.set_id("SPDXRef-File-0002")>>>sbom_files[sbom_file.get_name()]=sbom_file.get_file()>>>fromlib4sbom.sbomimportSBOM>>>my_sbom=SBOM()>>>my_sbom.add_files(sbom_files)SBOMPackage ObjectclassSBOMPackage()This creates a simple SBOM Package object. This object contains the values of the attributes
that can be associated with a package or component artefact within an SBOM. This includes attributes such as name, identifier, supplier,
version and licence information. As each of the attributes are optional, it is left to the application manipulating the
SBOMPackage object to apply validation as appropriate for the presence of each attribute.Setter MethodsFor the following attributes, a methodset_attribute(value)is provided. Note that the attribute name is always inlowercase.
e.g. set_version(). The attribute names are aligned with the attributes of the Package Object in the SPDX Specification. Unless
indicated, the method just takes a single parameter for the value. Where indicated, multiple instances of the attribute may be defined.AttributeMultipleNoteNameNoIdNoTypeNo(1)ChecksumYes(2)LicenseConcludedNoLicenseDeclaredNo(3)LicenceInfoInFileYesLicenceCommentsNoFilesAnalysisNoCopyrightTextNoCommentNoOriginatorNoSupplierNoVersionNoHomepageNoPropertyYesDownloadLocationNoDescriptionNoExternalReferenceYesSummaryNoSourceInfoNoFilenameNoNote1 The set_type method is used to indicate the purpose of the package (e.g. Application, Library, Operating-System).2 The set_checksum method takes two parameters, the checksum algorithm (e.g. SHA256) and the actual checksum value (as a string)3 The set_licensedeclared method takes an optional second parameter which is the license name. In this case the first parameter, license, is assumed to be the license text rather than the license identity.There is an additional setter method,set_value(attribute, value) which allows the setting of any attribute.set_value("language", "Rust")Getter Methodsget_package()
Returns the SBOMPackage object as a dictionary. The value of an attribute is returned as a string except where multiple instances of an attribute are allowed in which
case the value of the attribute is returned as a List.get_name()
Returns the name of the SBOM File object or None if the 'name' attribute does not exist within the instance of the SBOMPackage object.get_value(attribute)
Returns the value of the attribute. A default value is returned if the attribute does not exist within the instance of the SBOMPackage object.Utility Methodsinitialise() Reinitialises a SBOMPackage Object. All data associated with the object is deleted.Example>>>fromlib4sbom.data.packageimportSBOMPackage>>>sbom_packages={}>>>my_package=SBOMPackage()>>>my_package.set_name("glibc")>>>my_package.set_version("2.15")>>>my_package.set_supplier("organisation","gnu")>>>my_package.set_licensedeclared("GPL3")>>>sbom_packages[(my_package.get_name(),my_package.get_value('version'))]=my_package.get_package()>>>my_package.initialise()>>>my_package.set_name("tomcat")>>>my_package.set_version("9.0.46")>>>my_package.set_supplier("organisation","apache")>>>my_package.set_licensedeclared("Apache-2.0")>>>sbom_packages[(my_package.get_name(),my_package.get_value('version'))]=my_package.get_package()>>>fromlib4sbom.sbomimportSBOM>>>my_sbom=SBOM()>>>my_sbom.add_packages(sbom_packages)SBOMRelationship ObjectclassSBOMRelationship()This creates a simple SBOMRelationship object which is used to show the relationship between two items within an SBOM.
As there are multiple types of relationships, it is left to the application manipulating the
SBOMRelationship object to apply validation as appropriate to ensure the semantics of the relationship are correct.Setter Methodsset_relationship (source, type, target)sourceandtargetare the unique identifiers of the components for which the relationship is being defined.typeis the type of relationship being defined.Getter Methodsget_relationship()
Returns the SBOMRelationship object as a dictionary.Example>>>fromlib4sbom.data.relationshipimportSBOMRelationship>>>sbom_relationships=[]>>>my_relationship=SBOMRelationship()>>>my_relationship.set_relationship("Package-1","CONTAINS","Package-2")>>>sbom_relationships.append(my_relationship)>>>fromlib4sbom.sbomimportSBOM>>>my_sbom=SBOM()>>>my_sbom.add_relationships(sbom_relationships)Vulnerability ObjectclassVulnerability(validation = None)This creates a simple vulnerability object which is used to define the details of a vulnerability typically for a component
specified within an SBOM. As there are multiple ways of specifying the status of a vulnerability, it is left to the
application manipulating the Vulnerability object to apply validation as appropriate to ensure the semantics of the vulnerability are correct.The following optional parameter can be specified:validationindicates that the status field is to be validated against theOpenVEX,CycloneDXorCSAFspecifcaitions.NOTEVulnerability objects are only included in CyclonedDX SBOMsSetter MethodsFor the following attributes, a methodset_attribute(value)is provided. Note that the attribute name is always inlowercase.
e.g. set_release(). Each method takes a single parameter for the value. Multiple instances of the attribute are not allowed.AttributeMultipleNoteNameNoIdNo(1)ReleaseNoStatusNo(2)CommentNo(3)DescriptionNo(4)NoteThe set_id method is used to indicate the identity of the vulnerability e.g. CVE-2021-44228The set_status is used to indicate the status of the vulnerability. Validation of the value of status may be optionally performed as determined by
the optional parametervalidationspecified in the creation of the Vulnerability object. An invalid status is indicated by a value of None.The set_comment method is used to provide additional information to support the status value e.g. a brief justificationThe set_description method is used to describe the vulnerability.There is an additional setter method,set_value(attribute, value) which allows the setting of any attribute.set_value("bom-ref", "rust@1.2.3")Getter Methodsget_vulnerability()
Returns the vulnerability object as a dictionary.Example>>>fromlib4sbom.data.vulnerabilityimportVulnerability>>>vulnerabilities=[]>>>vulnerability=Vulnerability(validation="cyclonedx")>>>vulnerability.set_id("CVE-2023-1235")>>>vulnerability.set_name("rust")>>>vulnerability.set_release("1.2.3")>>>vulnerability.set_value("bom-ref","rust@1.2.3")>>>vulnerability.set_status("in_triage")>>>vulnerabilities.append(vulnerability.get_vulnerability())>>>fromlib4sbom.sbomimportSBOM>>>my_sbom=SBOM()>>>my_sbom.add_vulnerabilities(vulnerabilities)ExamplesA number of example scripts are included in theexamplessubdirectory.Implementation NotesThe following design decisions have been made in processing the SBOM files:It is assumed that the SBOM is valid and contains syntactically valid data.In SPDX format, the tool assumes that the name of a package preceeds the version and license of the package.In SPDX format, the current implementation does not currently handle multi-line elements.When processing and validating licenses, the application will use a set of synonyms to attempt to map some license identifiers to the correctSPDX License Identifiers. However, the
user of the tool is reminded that they should assert the quality of any data which is provided by the tool particularly where the license identifier has been modified.Future DevelopmentSupport later versions of SPDX (3.0).Enhance validation of SBOM data to check for all mandatory elements.Implement Python typing across modules.Migrate packaging infrastructure away from setup.py.Utilise third-party SPDX and CycloneDX parsers and generatorsAdd further support for SPDX XML and RDF formatsAdd generator for CycloneDX XML documents.Implement test suite.LicenseLicensed under the Apache 2.0 Licence.The tool uses a local copy of theSPDX Licenses Listwhich is released underCreative Commons Attribution 3.0 (CC-BY-3.0).This tool uses information sourced from theBlue Oak Council's License Listwhich is released underCreative Commons Attribution 1.0 (CC-BY-1.0).LimitationsThis tool is meant to support software development. The usefulness of the tool is dependent on the SBOM data
which is provided to the tool. Unfortunately, the tool is unable to determine the validity or completeness of such a SBOM file; users of the tool
are therefore reminded that they should assert the quality of any data which is provided to the tool.Feedback and ContributionsBugs and feature requests can be made via GitHub Issues.