|
15 | 15 | from vulnerabilities.importer import AdvisoryData |
16 | 16 | from vulnerabilities.importer import Importer |
17 | 17 | from vulnerabilities.importer import Reference |
18 | | -from vulnerabilities.utils import create_etag |
19 | 18 | from vulnerabilities.utils import is_cve |
20 | 19 |
|
21 | 20 |
|
22 | 21 | class UbuntuUSNImporter(Importer): |
23 | | - def updated_advisories(self): |
24 | | - advisories = [] |
25 | | - if create_etag(data_src=self, url=self.config.db_url, etag_key="etag"): |
26 | | - advisories.extend(self.to_advisories(fetch(self.config.db_url))) |
27 | | - |
28 | | - return self.batch_advisories(advisories) |
29 | | - |
30 | | - def create_etag(self, url): |
31 | | - etag = requests.head(url).headers.get("etag") |
32 | | - if not etag: |
33 | | - return True |
34 | | - |
35 | | - elif url in self.config.etags: |
36 | | - if self.config.etags[url] == etag: |
37 | | - return False |
38 | | - |
39 | | - self.config.etags[url] = etag |
40 | | - return True |
| 22 | + db_url = "https://usn.ubuntu.com/usn-db/database-all.json.bz2" |
| 23 | + spdx_license_expression = "LicenseRef-scancode-other-permissive" |
| 24 | + notice = """ |
| 25 | + From: Seth Arnold <[email protected]> |
| 26 | + Date: Wed, Jan 25, 2023 at 2:02 AM |
| 27 | + Subject: Re: [ubuntu-hardened] Usage of Ubuntu Security Data in VulnerableCode |
| 28 | + To: Tushar Goel <[email protected]> |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + On Wed, Jan 11, 2023 at 06:27:38PM +0530, Tushar Goel wrote: |
| 33 | + > We would like to integrate the Ubuntu usn data[1][2] and |
| 34 | + > Ubuntu security data (OVAL format)[3] in vulnerablecode[4] |
| 35 | + > which is a FOSS db of FOSS vulnerability data. We were not |
| 36 | + > able to know under which license this security data comes. |
| 37 | + > We would be grateful to have your acknowledgement over usage of |
| 38 | + > the ubuntu security data in vulnerablecode and have |
| 39 | + > some kind of licensing declaration from your side. |
| 40 | + |
| 41 | + Hello Tushar, we do not have an explicit license on this data. |
| 42 | + |
| 43 | + We share our data with the intention that others will use it. Please |
| 44 | + feel free to use it for the general furtherance of security. |
| 45 | + |
| 46 | + Much of the data that's contained within our databases is sourced from |
| 47 | + third parties, who also shared their data with the intention that others |
| 48 | + will use it. I'm not sure what it would look like to try to put a license |
| 49 | + on data that is crowd-sourced from thousands of contributors. (If you were |
| 50 | + to start such a project today, it'd probably be one of the first things to |
| 51 | + formalize. But when CVE was started two decades ago, the primary goal was |
| 52 | + sharing knowledge and simplifying the vulnerability remediation process, |
| 53 | + and licensing the data was, as far as I can remember, not considered. |
| 54 | + Sharing was the goal.) |
| 55 | + |
| 56 | + I will ask that vulnerablecode 'be nice' to our infrastructure that |
| 57 | + hosts the databases -- some automated uses of our infrastructure by |
| 58 | + vulnerability scanner tools has lead to significant load and engineering |
| 59 | + effort. In general, please prefer a small handful of systems updating |
| 60 | + mirrors roughly twice a day rather than thousands of hosts pulling |
| 61 | + data hourly. |
| 62 | + |
| 63 | + Thanks |
| 64 | + """ |
| 65 | + |
| 66 | + def advisory_data(self): |
| 67 | + usn_db = fetch(self.db_url) |
| 68 | + yield from self.to_advisories(usn_db=usn_db) |
41 | 69 |
|
42 | 70 | @staticmethod |
43 | 71 | def to_advisories(usn_db): |
44 | | - advisories = [] |
45 | 72 | for usn in usn_db: |
46 | | - reference = get_usn_references(usn_db[usn]["id"]) |
47 | | - for cve in usn_db[usn].get("cves", [""]): |
| 73 | + usn_data = usn_db[usn] |
| 74 | + references = get_usn_references(usn_data.get("id")) |
| 75 | + for cve in usn_data.get("cves", []): |
48 | 76 | # The db sometimes contains entries like |
49 | 77 | # {'cves': ['python-pgsql vulnerabilities', 'CVE-2006-2313', 'CVE-2006-2314']} |
50 | 78 | # This `if` filters entries like 'python-pgsql vulnerabilities' |
51 | 79 | if not is_cve(cve): |
52 | | - cve = "" |
| 80 | + continue |
53 | 81 |
|
54 | | - advisories.append( |
55 | | - AdvisoryData( |
56 | | - vulnerability_id=cve, |
57 | | - summary="", |
58 | | - references=[reference], |
59 | | - ) |
| 82 | + yield AdvisoryData( |
| 83 | + aliases=[cve], |
| 84 | + summary="", |
| 85 | + references=references, |
60 | 86 | ) |
61 | 87 |
|
62 | | - return advisories |
63 | | - |
64 | 88 |
|
65 | 89 | def get_usn_references(usn_id): |
66 | | - return Reference(reference_id="USN-" + usn_id, url="https://usn.ubuntu.com/{}/".format(usn_id)) |
| 90 | + if not usn_id: |
| 91 | + return [] |
| 92 | + return [Reference(reference_id=f"USN-{usn_id}", url=f"https://usn.ubuntu.com/{usn_id}/")] |
67 | 93 |
|
68 | 94 |
|
69 | 95 | def fetch(url): |
|
0 commit comments