Skip to content

Commit f324559

Browse files
Add: New GMP version 22.05 (#1097)
* Add: New GMP version 22.05 Added new GMP command get_resource_names to get names and IDs of resources of given type. * Update tests for the new GMP version 22.05 * Increase test coverage
1 parent 96712c9 commit f324559

File tree

82 files changed

+4870
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+4870
-7
lines changed

gvm/protocols/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@
1919
Package for supported Greenbone Protocol versions.
2020
2121
Currently `GMP version 20.08`_, `GMP version 21.04`_
22-
`GMP version 22.04` and `OSP version 1`_ are supported.
22+
`GMP version 22.04`, `GMP version 22.05`
23+
and `OSP version 1`_ are supported.
2324
2425
.. _GMP version 20.08:
2526
https://docs.greenbone.net/API/GMP/gmp-20.08.html
2627
.. _GMP version 21.04:
2728
https://docs.greenbone.net/API/GMP/gmp-21.04.html
2829
.. _GMP version 22.04:
2930
https://docs.greenbone.net/API/GMP/gmp-22.04.html
31+
.. _GMP version 22.05:
32+
https://docs.greenbone.net/API/GMP/gmp-22.05.html
3033
.. _OSP version 1:
3134
https://docs.greenbone.net/API/OSP/osp-1.2.html
3235
"""

gvm/protocols/gmp.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@
2727
from gvm.protocols.gmpv208 import Gmp as Gmpv208
2828
from gvm.protocols.gmpv214 import Gmp as Gmpv214
2929
from gvm.protocols.gmpv224 import Gmp as Gmpv224
30+
from gvm.protocols.gmpv225 import Gmp as Gmpv225
3031
from gvm.transforms import EtreeCheckCommandTransform
3132
from gvm.xml import XmlCommand
3233

3334
SUPPORTED_GMP_VERSIONS = Union[ # pylint: disable=invalid-name
34-
Gmpv208, Gmpv214, Gmpv224
35+
Gmpv208, Gmpv214, Gmpv224, Gmpv225
3536
]
3637

3738

@@ -104,6 +105,8 @@ def determine_supported_gmp(self) -> SUPPORTED_GMP_VERSIONS:
104105
gmp_class = Gmpv214
105106
elif major_version == 22 and minor_version == 4:
106107
gmp_class = Gmpv224
108+
elif major_version == 22 and minor_version == 5:
109+
gmp_class = Gmpv225
107110
else:
108111
raise GvmError(
109112
"Remote manager daemon uses an unsupported version of GMP. "

gvm/protocols/gmpv225/__init__.py

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright (C) 2023 Greenbone AG
3+
#
4+
# SPDX-License-Identifier: GPL-3.0-or-later
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
# pylint: disable=too-many-lines,redefined-builtin
20+
21+
"""
22+
Module for communication with gvmd in
23+
`Greenbone Management Protocol version 22.05`_
24+
25+
.. _Greenbone Management Protocol version 22.05:
26+
https://docs.greenbone.net/API/GMP/gmp-22.05.html
27+
"""
28+
29+
import logging
30+
from typing import Any, Callable, Optional
31+
32+
from gvm.connections import GvmConnection
33+
from gvm.protocols.base import GvmProtocol
34+
from gvm.protocols.gmpv208.entities.alerts import (
35+
AlertCondition,
36+
AlertEvent,
37+
AlertMethod,
38+
AlertsMixin,
39+
)
40+
from gvm.protocols.gmpv208.entities.audits import AuditsMixin
41+
from gvm.protocols.gmpv208.entities.credentials import (
42+
CredentialFormat,
43+
CredentialsMixin,
44+
CredentialType,
45+
SnmpAuthAlgorithm,
46+
SnmpPrivacyAlgorithm,
47+
)
48+
from gvm.protocols.gmpv208.entities.entities import EntityType
49+
from gvm.protocols.gmpv208.entities.filter import FiltersMixin, FilterType
50+
from gvm.protocols.gmpv208.entities.groups import GroupsMixin
51+
from gvm.protocols.gmpv208.entities.hosts import HostsMixin, HostsOrdering
52+
from gvm.protocols.gmpv208.entities.operating_systems import (
53+
OperatingSystemsMixin,
54+
)
55+
from gvm.protocols.gmpv208.entities.permissions import (
56+
PermissionsMixin,
57+
PermissionSubjectType,
58+
)
59+
from gvm.protocols.gmpv208.entities.policies import PoliciesMixin
60+
from gvm.protocols.gmpv208.entities.port_lists import (
61+
PortListMixin,
62+
PortRangeType,
63+
)
64+
from gvm.protocols.gmpv208.entities.report_formats import (
65+
ReportFormatsMixin,
66+
ReportFormatType,
67+
)
68+
from gvm.protocols.gmpv208.entities.reports import ReportsMixin
69+
from gvm.protocols.gmpv208.entities.results import ResultsMixin
70+
from gvm.protocols.gmpv208.entities.roles import RolesMixin
71+
from gvm.protocols.gmpv208.entities.schedules import SchedulesMixin
72+
from gvm.protocols.gmpv208.entities.secinfo import InfoType, SecInfoMixin
73+
from gvm.protocols.gmpv208.entities.severity import SeverityLevel
74+
from gvm.protocols.gmpv208.entities.tags import TagsMixin
75+
from gvm.protocols.gmpv208.entities.tasks import TasksMixin
76+
from gvm.protocols.gmpv208.entities.tickets import TicketsMixin, TicketStatus
77+
from gvm.protocols.gmpv208.entities.tls_certificates import TLSCertificateMixin
78+
from gvm.protocols.gmpv208.entities.users import UserAuthType
79+
from gvm.protocols.gmpv208.entities.vulnerabilities import VulnerabilitiesMixin
80+
from gvm.protocols.gmpv208.system.aggregates import (
81+
AggregatesMixin,
82+
AggregateStatistic,
83+
SortOrder,
84+
)
85+
from gvm.protocols.gmpv208.system.authentication import AuthenticationMixin
86+
from gvm.protocols.gmpv208.system.feed import FeedMixin, FeedType
87+
from gvm.protocols.gmpv208.system.help import HelpFormat, HelpMixin
88+
from gvm.protocols.gmpv208.system.system_reports import SystemReportsMixin
89+
from gvm.protocols.gmpv208.system.trashcan import TrashcanMixin
90+
from gvm.protocols.gmpv208.system.user_settings import UserSettingsMixin
91+
92+
# NEW IN 214
93+
from gvm.protocols.gmpv214.entities.notes import NotesMixin
94+
from gvm.protocols.gmpv214.entities.overrides import OverridesMixin
95+
from gvm.protocols.gmpv214.entities.targets import AliveTest, TargetsMixin
96+
from gvm.protocols.gmpv224.entities.scan_configs import ScanConfigsMixin
97+
from gvm.protocols.gmpv224.entities.scanners import ScannersMixin, ScannerType
98+
99+
# NEW IN 224
100+
from gvm.protocols.gmpv224.entities.users import UsersMixin
101+
102+
# NEW IN 225
103+
from gvm.protocols.gmpv225.entities.resourcenames import (
104+
ResourceNamesMixin,
105+
ResourceType,
106+
)
107+
from gvm.protocols.gmpv225.system.version import VersionMixin
108+
from gvm.utils import to_dotted_types_dict
109+
110+
logger = logging.getLogger(__name__)
111+
112+
_TYPE_FIELDS = [
113+
AggregateStatistic,
114+
AlertCondition,
115+
AlertEvent,
116+
AlertMethod,
117+
AliveTest,
118+
CredentialFormat,
119+
CredentialType,
120+
EntityType,
121+
FeedType,
122+
FilterType,
123+
HostsOrdering,
124+
InfoType,
125+
HelpFormat,
126+
PortRangeType,
127+
PermissionSubjectType,
128+
ReportFormatType,
129+
ResourceType,
130+
ScannerType,
131+
SeverityLevel,
132+
SnmpAuthAlgorithm,
133+
SnmpPrivacyAlgorithm,
134+
SortOrder,
135+
TicketStatus,
136+
UserAuthType,
137+
]
138+
139+
140+
class Gmp(
141+
GvmProtocol,
142+
AggregatesMixin,
143+
AlertsMixin,
144+
AuditsMixin,
145+
AuthenticationMixin,
146+
CredentialsMixin,
147+
FeedMixin,
148+
FiltersMixin,
149+
GroupsMixin,
150+
HelpMixin,
151+
HostsMixin,
152+
NotesMixin,
153+
OperatingSystemsMixin,
154+
OverridesMixin,
155+
PermissionsMixin,
156+
PoliciesMixin,
157+
PortListMixin,
158+
ReportFormatsMixin,
159+
ReportsMixin,
160+
ResourceNamesMixin,
161+
ResultsMixin,
162+
RolesMixin,
163+
TagsMixin,
164+
TargetsMixin,
165+
TasksMixin,
166+
TicketsMixin,
167+
TLSCertificateMixin,
168+
TrashcanMixin,
169+
ScanConfigsMixin,
170+
ScannersMixin,
171+
SchedulesMixin,
172+
SecInfoMixin,
173+
SystemReportsMixin,
174+
UserSettingsMixin,
175+
UsersMixin,
176+
VersionMixin,
177+
VulnerabilitiesMixin,
178+
):
179+
"""Python interface for Greenbone Management Protocol
180+
181+
This class implements the `Greenbone Management Protocol version 22.05`_
182+
183+
Arguments:
184+
connection: Connection to use to talk with the gvmd daemon. See
185+
:mod:`gvm.connections` for possible connection types.
186+
transform: Optional transform `callable`_ to convert response data.
187+
After each request the callable gets passed the plain response data
188+
which can be used to check the data and/or conversion into different
189+
representations like a xml dom.
190+
191+
See :mod:`gvm.transforms` for existing transforms.
192+
193+
.. _Greenbone Management Protocol version 22.05:
194+
https://docs.greenbone.net/API/GMP/gmp-22.05.html
195+
.. _callable:
196+
https://docs.python.org/3/library/functions.html#callable
197+
"""
198+
199+
def __init__(
200+
self,
201+
connection: GvmConnection,
202+
*,
203+
transform: Optional[Callable[[str], Any]] = None,
204+
):
205+
self.types = to_dotted_types_dict(_TYPE_FIELDS)
206+
207+
super().__init__(connection, transform=transform)
208+
209+
# Is authenticated on gvmd
210+
self._authenticated = False
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright (C) 2023 Greenbone AG
3+
#
4+
# SPDX-License-Identifier: GPL-3.0-or-later
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.

0 commit comments

Comments
 (0)