From 6e0f09ad2d76f95c0bb0557274d65827f1a22da5 Mon Sep 17 00:00:00 2001 From: Jan-Oliver Wagner Date: Sun, 9 Feb 2020 23:23:37 +0100 Subject: [PATCH 1/3] Create extended severities object. This is about the given values we might have at hand. It is not yet considering multiple severities from a NVT though. But if the internal severity structure has a origin or date, then it will be considered already. --- ospd_openvas/daemon.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ospd_openvas/daemon.py b/ospd_openvas/daemon.py index 17126d24..92f1ba90 100644 --- a/ospd_openvas/daemon.py +++ b/ospd_openvas/daemon.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2014-2020 Greenbone Networks GmbH +# Copyright (C) 2019-2020 Greenbone Networks GmbH # # SPDX-License-Identifier: AGPL-3.0-or-later # @@ -621,13 +621,18 @@ def get_severities_vt_as_xml_str(vt_id: str, severities: Dict) -> str: _severity = SubElement(_severities, 'severity') if 'severity_base_vector' in severities: try: - _severity.text = severities.get('severity_base_vector') + _value = SubElement(_severity, 'value') + _value.text = severities.get('severity_base_vector') except ValueError as e: logger.warning( "Not possible to parse severity tag for vt %s: %s", vt_id, e ) if 'severity_origin' in severities: - _severity.set('origin', severities.get('severity_origin')) + _origin = SubElement(_severity, 'origin') + _origin.text = severities.get('severity_origin') + if 'severity_date' in severities: + _date = SubElement(_severity, 'date') + _date.text = severities.get('severity_date') if 'severity_type' in severities: _severity.set('type', severities.get('severity_type')) From 802f6db4fc326e9a5549acdc963f274d49426bf9 Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Thu, 15 Oct 2020 04:17:08 -0500 Subject: [PATCH 2/3] Update tests. Check subelement origin date and value --- tests/dummydaemon.py | 2 ++ tests/test_daemon.py | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/dummydaemon.py b/tests/dummydaemon.py index fb72e204..bf7f77de 100644 --- a/tests/dummydaemon.py +++ b/tests/dummydaemon.py @@ -51,6 +51,8 @@ class DummyDaemon(OSPDopenvas): 'severities': { 'severity_base_vector': 'AV:N/AC:L/Au:N/C:N/I:N/A:N', 'severity_type': 'cvss_base_v2', + 'severity_date': '1237458156', + 'severity_origin': 'Greenbone', }, 'solution': 'some solution', 'solution_type': 'WillNotFix', diff --git a/tests/test_daemon.py b/tests/test_daemon.py index b0ad1388..eceb7b80 100644 --- a/tests/test_daemon.py +++ b/tests/test_daemon.py @@ -386,7 +386,9 @@ def test_get_severities_xml(self): out = ( '' '' - 'AV:N/AC:L/Au:N/C:N/I:N/A:N' + 'AV:N/AC:L/Au:N/C:N/I:N/A:N' + 'Greenbone' + '1237458156' '' '' ) @@ -687,7 +689,9 @@ def test_feed_is_outdated_none( @patch('ospd_openvas.daemon.Path.exists') @patch('ospd_openvas.daemon.Path.open') def test_feed_is_outdated_true( - self, mock_path_open: MagicMock, mock_path_exists: MagicMock, + self, + mock_path_open: MagicMock, + mock_path_exists: MagicMock, ): read_data = 'PLUGIN_SET = "1235";' @@ -710,7 +714,9 @@ def test_feed_is_outdated_true( @patch('ospd_openvas.daemon.Path.exists') @patch('ospd_openvas.daemon.Path.open') def test_feed_is_outdated_false( - self, mock_path_open: MagicMock, mock_path_exists: MagicMock, + self, + mock_path_open: MagicMock, + mock_path_exists: MagicMock, ): mock_path_exists.return_value = True @@ -808,7 +814,8 @@ def test_get_openvas_result_dead_hosts(self, MockDBClass): w.report_openvas_results(MockDBClass, '123-456') w.scan_collection.set_amount_dead_hosts.assert_called_with( - '123-456', total_dead=4, + '123-456', + total_dead=4, ) @patch('ospd_openvas.daemon.BaseDB') @@ -831,7 +838,9 @@ def test_get_openvas_result_host_start( w.report_openvas_results(MockDBClass, '123-456') mock_add_scan_log_to_list.assert_called_with( - host='192.168.10.124', name='HOST_START', value='today 1', + host='192.168.10.124', + name='HOST_START', + value='today 1', ) @patch('ospd_openvas.daemon.BaseDB') From f4ab2e6b1faa78c1aabcaa3912998473b6957b99 Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Thu, 15 Oct 2020 04:52:17 -0500 Subject: [PATCH 3/3] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c16e876f..8a9e4bd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - Get all results from main kb. [#285](https://github.com/greenbone/ospd-openvas/pull/285) +- Extend severities with origin and date. [#192](https://github.com/greenbone/ospd-openvas/pull/192) ### Removed - Remove methods handling the nvticache name. [#318](https://github.com/greenbone/ospd-openvas/pull/318)