Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update spdx_parser.py to handle spdx file parsing logic to generate correct key value pair of dictionary #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ravi-mishra-10
Copy link

@ravi-mishra-10 ravi-mishra-10 commented Aug 1, 2024

Problem statement:

Showing same software b/w two SPDX file as diff and generating result with same product removed then later added back.

If spdx file [1] contains:

#### Package: cloud.google.com/go/networksecurity

PackageName: cloud.google.com/go/networksecurity
SPDXID: SPDXRef-Pkg-cloud.google.com-go-networksecurity-v0.6.0-5311591
PackageVersion: v0.6.0
PackageSupplier: Organization: go:cloud.google.com/go/networksecurity
PackageHomePage: https://pkg.go.dev/cloud.google.com/go/networksecurity
PackageDownloadLocation: NOASSERTION
PackageLicenseConcluded: Apache-2.0
PackageLicenseDeclared: Apache-2.0
PackageCopyrightText: NOASSERTION
FilesAnalyzed: False
ExternalRef: PACKAGE-MANAGER purl pkg:golang/cloud.google.com/go/[email protected]

If spdx file [2] contains:

#### Package: networksecurity

PackageName: networksecurity
SPDXID: SPDXRef-Pkg-cloud.google.com-go-networksecurity-v0.5.0-5311454
PackageVersion: v0.5.0
PackageSupplier: Organization: go:cloud.google.com/go/networksecurity
PackageHomePage: https://pkg.go.dev/cloud.google.com/go/networksecurity
PackageDownloadLocation: NOASSERTION
PackageLicenseConcluded: Apache-2.0
PackageLicenseDeclared: Apache-2.0
PackageCopyrightText: NOASSERTION
FilesAnalyzed: False
ExternalRef: PACKAGE-MANAGER purl pkg:golang/cloud.google.com/go/[email protected]

Command used to generate report:

#python ./cli.py --sbom spdx -o sbom_diff_reports.txt -f text file1.spdx file2.spdx
#echo $?
#1

cat sbom_diff_reports.txt

[REMOVED] networksecurity: (Version v0.5.0)
[ADDED  ] cloud.google.com/go/networksecurity: (Version v0.6.0) (License Apache-2.0)
Summary
-------
Version changes:  0
License changes:  0
Removed packages: 1
New packages:     1

Solution:

Addition regex logic will help to find right delta between two SPDX file. Without this fix sometime ProductName getting recorded incorrectly as "v2" or "without full path of software" this enhancement will help to detect same product name b/w two spdx file(s).

With fix report contains will be like:

cat sbom_diff_reports.txt

[REMOVED] networksecurity: (Version v0.5.0)
[ADDED  ] cloud.google.com/go/networksecurity: (Version v0.5.0) (License Apache-2.0)
Summary
-------
Version changes:  1
License changes:  0
Removed packages: 0
New packages:     0

Reviewers:

@anthonyharrison @briancaine

…orrect key value pair of dictionary

Addition regex logic will help to find right delta between two SPDX file. Without this fix sometime ProductName getting recorded incorrectly as "v2" or "without full path of software" this enhancement will help to detect same product name b/w two spdx file(s).
@ravi-mishra-10
Copy link
Author

@anthonyharrison kindly start the review.

Copy link
Owner

@anthonyharrison anthonyharrison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not convinced that this is a valid or complete change.

@@ -34,16 +34,31 @@ def parse_spdx_tag(self, sbom_file):
packages = {}
package = ""
version = None
githubStr = "pkg.go.dev/"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not appropriate as this only works for Go packages. sbomdiff needs to be generic for all SBOMs and languages

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree I will add some check to do this only for GO libs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you suggest how to find packages for other language like java, python etc.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you suggest how to find packages for other language like java, python etc.

I don't think this is a valid change,

The differences in package name is due to the differences in the SBOM generator. Comparing SBOMs from different generators is a valid use case and I can see how useful it is to detect that the generators are creating different names for the same package. Trying to make sbomdiff cater for different generators and establish that the different package names are actually the same package is beyond the scope of sbomdiff as it is not viable to accommodate the approaches adopted by all the different SBOM generators for generating package names.

version = None
license = None
if line_elements[0] == "PackageVersion":
version = line[16:].strip().rstrip("\n")
if line_elements[0] == "PackageLicenseConcluded":
license = line_elements[1].strip().rstrip("\n")
if line_elements[0] == "PackageHomePage":
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add this check,we also need to do a corresponding check for all formats of SBOMs not just SPDX tag value SBOMs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I will add same check for json, xml, yaml and rdf.
Thanks @anthonyharrison

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants