|
| 1 | +# |
| 2 | +# Copyright (c) 2017 nexB Inc. and others. All rights reserved. |
| 3 | +# http://nexb.com and https://github.com/nexB/vulnerablecode/ |
| 4 | +# The VulnerableCode software is licensed under the Apache License version 2.0. |
| 5 | +# Data generated with VulnerableCode require an acknowledgment. |
| 6 | +# |
| 7 | +# You may not use this software except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0 |
| 9 | +# Unless required by applicable law or agreed to in writing, software distributed |
| 10 | +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 11 | +# CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 12 | +# specific language governing permissions and limitations under the License. |
| 13 | +# |
| 14 | +# When you publish or redistribute any data created with VulnerableCode or any VulnerableCode |
| 15 | +# derivative work, you must accompany this data with the following acknowledgment: |
| 16 | +# |
| 17 | +# Generated with VulnerableCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES |
| 18 | +# OR CONDITIONS OF ANY KIND, either express or implied. No content created from |
| 19 | +# VulnerableCode should be considered or used as legal advice. Consult an Attorney |
| 20 | +# for any legal advice. |
| 21 | +# VulnerableCode is a free software code scanning tool from nexB Inc. and others. |
| 22 | +# Visit https://github.com/nexB/vulnerablecode/ for support and download. |
| 23 | + |
| 24 | +import json |
| 25 | +from urllib.request import urlopen |
| 26 | + |
| 27 | + |
| 28 | +ARCHLINUX_TRACKER_URL = 'https://security.archlinux.org/json' |
| 29 | + |
| 30 | + |
| 31 | +def extract_vulnerabilities(arch_data): |
| 32 | + """ |
| 33 | + Return a sequence of mappings for each existing combination of |
| 34 | + package and vulnerability from a mapping of arch linux vulnerabilities |
| 35 | + data. |
| 36 | + """ |
| 37 | + package_vulnerabilities = [] |
| 38 | + |
| 39 | + for item in arch_data: |
| 40 | + if not item["name"] or not item["packages"][0]: |
| 41 | + continue |
| 42 | + |
| 43 | + package_vulnerabilities.append({ |
| 44 | + 'package_name': item["packages"][0], |
| 45 | + 'vulnerability_id': item["name"], |
| 46 | + 'status': item["status"], |
| 47 | + 'severity': item["severity"], |
| 48 | + 'affected_version': item["affected"], |
| 49 | + 'fixed_version': item["fixed"] |
| 50 | + }) |
| 51 | + return package_vulnerabilities |
| 52 | + |
| 53 | + |
| 54 | +def scrape_vulnerabilities(): |
| 55 | + """ |
| 56 | + Scrape arch linux' security tracker. |
| 57 | + """ |
| 58 | + json_content = urlopen(ARCHLINUX_TRACKER_URL).read() |
| 59 | + return extract_vulnerabilities(json.loads(json_content)) |
0 commit comments