-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CVEChecker which guesses the pkg name and version of an archive
- Loading branch information
Showing
3 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Copyright (C) 2018 Endless Mobile, Inc. | ||
# | ||
# Authors: | ||
# Andrew Hayzen <ahayzen@gmail.com> | ||
# Joaquim Rocha <jrocha@endlessm.com> | ||
# Patrick Griffis <tingping@tingping.se> | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, write to the Free Software Foundation, Inc., | ||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
|
||
import logging | ||
import re | ||
|
||
from lib.externaldata import ExternalData, CheckerRegistry, Checker | ||
from lib import utils | ||
|
||
|
||
class CVEChecker(Checker): | ||
|
||
def check(self, external_data): | ||
try: | ||
version = CVEChecker.extract_version_from_url( | ||
external_data.url, external_data.type, | ||
) | ||
logging.debug('CVEChecker: Found %s of the version %s' % | ||
(external_data.pkg_name, version)) | ||
except ValueError: | ||
external_data.state = ExternalData.State.BROKEN | ||
else: | ||
external_data.state = ExternalData.State.VALID | ||
|
||
# TODO: need similar to new_version but for cve_vuln | ||
# this should also output to JSON | ||
|
||
@staticmethod | ||
def extract_version_from_url(url, data_type): | ||
if data_type == ExternalData.Type.ARCHIVE: | ||
filename = url.rpartition('/')[2] | ||
match = re.search(r'(\d+\.\d+(?:\.\d+)?)', filename) | ||
|
||
if match: | ||
return match.groups()[-1] | ||
else: | ||
logging.debug('Version not found in {}'.format(sources)) | ||
raise ValueError | ||
else: | ||
logging.debug('CVEChecker: Unknown type %s' % data_type) | ||
raise ValueError | ||
|
||
|
||
CheckerRegistry.register_checker(CVEChecker) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters