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

No purl version #293

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/redhat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ pipenv install -e .

Needs to be run in a folder where the Red Hat CSAF documents to convert already exist. Files can be downloaded the [Red Hat Customer Portal Security Data section](https://access.redhat.com/security/data/csaf/v2/advisories/)
~~~
$ pipenv run convert_redhat testdata/rhsa-2024_4546.json
$ pipenv run python3 convert_redhat.py testdata/rhsa-2024_4546.json
~~~

OSV documents will be output in the `osv` directory by default. Override the default with the `--output_directory` option.
Expand Down
7 changes: 6 additions & 1 deletion tools/redhat/redhat_osv/osv.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class Package:
Class to hold package data for an Affect.
Expects an ecosystem string that starts with CPE_PATTERN.
Replaces the CPE prefix 'redhat' part with 'Red Hat'
to match more closely with other ecosystem identifiers in the OSV database
to match more closely with other ecosystem identifiers in the OSV database.
Also removes version and qualifiers from the CSAF remediation PURL
"""

cpe_pattern: re.Pattern = field(init=False,
Expand All @@ -98,6 +99,10 @@ def __post_init__(self):
if not self.cpe_pattern.match(self.ecosystem):
raise ValueError(f"Got unsupported ecosystem: {self.ecosystem}")
self.ecosystem = f"Red Hat{self.cpe_pattern.split(self.ecosystem, maxsplit=1)[-1]}"
if "@" in self.purl:
version_index = self.purl.index("@")
self.purl = self.purl[:version_index]



@dataclass
Expand Down
5 changes: 5 additions & 0 deletions tools/redhat/redhat_osv/osv_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ def test_missing_cvss_v3(self):
assert csaf
assert len(csaf.vulnerabilities) == 1
assert not csaf.vulnerabilities[0].cvss_v3_base_score
for vuln in csaf.vulnerabilities:
for remediation in vuln.remediations:
assert "@" in remediation.purl

osv = OSV(csaf, "test_date")
assert not hasattr(osv, "severity")
for affected in osv.affected:
assert "@" not in affected.package.purl


class EventTest(unittest.TestCase):
Expand Down
32 changes: 16 additions & 16 deletions tools/redhat/testdata/RHSA-2024_4546.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"schema_version": "1.6.5",
"schema_version": "1.6.7",
"id": "RHSA-2024:4546",
"related": [
"CVE-2023-45288",
Expand All @@ -19,7 +19,7 @@
"package": {
"name": "git-lfs",
"ecosystem": "Red Hat:rhel_aus:8.6::appstream",
"purl": "pkg:rpm/redhat/git-lfs@2.13.3-3.el8_6.1?arch=src"
"purl": "pkg:rpm/redhat/git-lfs"
},
"ranges": [
{
Expand All @@ -39,7 +39,7 @@
"package": {
"name": "git-lfs",
"ecosystem": "Red Hat:rhel_aus:8.6::appstream",
"purl": "pkg:rpm/redhat/git-lfs@2.13.3-3.el8_6.1?arch=x86_64"
"purl": "pkg:rpm/redhat/git-lfs"
},
"ranges": [
{
Expand All @@ -59,7 +59,7 @@
"package": {
"name": "git-lfs-debuginfo",
"ecosystem": "Red Hat:rhel_aus:8.6::appstream",
"purl": "pkg:rpm/redhat/git-lfs-debuginfo@2.13.3-3.el8_6.1?arch=x86_64"
"purl": "pkg:rpm/redhat/git-lfs-debuginfo"
},
"ranges": [
{
Expand All @@ -79,7 +79,7 @@
"package": {
"name": "git-lfs-debugsource",
"ecosystem": "Red Hat:rhel_aus:8.6::appstream",
"purl": "pkg:rpm/redhat/git-lfs-debugsource@2.13.3-3.el8_6.1?arch=x86_64"
"purl": "pkg:rpm/redhat/git-lfs-debugsource"
},
"ranges": [
{
Expand All @@ -99,7 +99,7 @@
"package": {
"name": "git-lfs",
"ecosystem": "Red Hat:rhel_e4s:8.6::appstream",
"purl": "pkg:rpm/redhat/git-lfs@2.13.3-3.el8_6.1?arch=ppc64le"
"purl": "pkg:rpm/redhat/git-lfs"
},
"ranges": [
{
Expand All @@ -119,7 +119,7 @@
"package": {
"name": "git-lfs",
"ecosystem": "Red Hat:rhel_e4s:8.6::appstream",
"purl": "pkg:rpm/redhat/git-lfs@2.13.3-3.el8_6.1?arch=src"
"purl": "pkg:rpm/redhat/git-lfs"
},
"ranges": [
{
Expand All @@ -139,7 +139,7 @@
"package": {
"name": "git-lfs",
"ecosystem": "Red Hat:rhel_e4s:8.6::appstream",
"purl": "pkg:rpm/redhat/git-lfs@2.13.3-3.el8_6.1?arch=x86_64"
"purl": "pkg:rpm/redhat/git-lfs"
},
"ranges": [
{
Expand All @@ -159,7 +159,7 @@
"package": {
"name": "git-lfs-debuginfo",
"ecosystem": "Red Hat:rhel_e4s:8.6::appstream",
"purl": "pkg:rpm/redhat/git-lfs-debuginfo@2.13.3-3.el8_6.1?arch=ppc64le"
"purl": "pkg:rpm/redhat/git-lfs-debuginfo"
},
"ranges": [
{
Expand All @@ -179,7 +179,7 @@
"package": {
"name": "git-lfs-debuginfo",
"ecosystem": "Red Hat:rhel_e4s:8.6::appstream",
"purl": "pkg:rpm/redhat/git-lfs-debuginfo@2.13.3-3.el8_6.1?arch=x86_64"
"purl": "pkg:rpm/redhat/git-lfs-debuginfo"
},
"ranges": [
{
Expand All @@ -199,7 +199,7 @@
"package": {
"name": "git-lfs-debugsource",
"ecosystem": "Red Hat:rhel_e4s:8.6::appstream",
"purl": "pkg:rpm/redhat/git-lfs-debugsource@2.13.3-3.el8_6.1?arch=ppc64le"
"purl": "pkg:rpm/redhat/git-lfs-debugsource"
},
"ranges": [
{
Expand All @@ -219,7 +219,7 @@
"package": {
"name": "git-lfs-debugsource",
"ecosystem": "Red Hat:rhel_e4s:8.6::appstream",
"purl": "pkg:rpm/redhat/git-lfs-debugsource@2.13.3-3.el8_6.1?arch=x86_64"
"purl": "pkg:rpm/redhat/git-lfs-debugsource"
},
"ranges": [
{
Expand All @@ -239,7 +239,7 @@
"package": {
"name": "git-lfs",
"ecosystem": "Red Hat:rhel_tus:8.6::appstream",
"purl": "pkg:rpm/redhat/git-lfs@2.13.3-3.el8_6.1?arch=src"
"purl": "pkg:rpm/redhat/git-lfs"
},
"ranges": [
{
Expand All @@ -259,7 +259,7 @@
"package": {
"name": "git-lfs",
"ecosystem": "Red Hat:rhel_tus:8.6::appstream",
"purl": "pkg:rpm/redhat/git-lfs@2.13.3-3.el8_6.1?arch=x86_64"
"purl": "pkg:rpm/redhat/git-lfs"
},
"ranges": [
{
Expand All @@ -279,7 +279,7 @@
"package": {
"name": "git-lfs-debuginfo",
"ecosystem": "Red Hat:rhel_tus:8.6::appstream",
"purl": "pkg:rpm/redhat/git-lfs-debuginfo@2.13.3-3.el8_6.1?arch=x86_64"
"purl": "pkg:rpm/redhat/git-lfs-debuginfo"
},
"ranges": [
{
Expand All @@ -299,7 +299,7 @@
"package": {
"name": "git-lfs-debugsource",
"ecosystem": "Red Hat:rhel_tus:8.6::appstream",
"purl": "pkg:rpm/redhat/git-lfs-debugsource@2.13.3-3.el8_6.1?arch=x86_64"
"purl": "pkg:rpm/redhat/git-lfs-debugsource"
},
"ranges": [
{
Expand Down