Skip to content

Commit

Permalink
Add: New GMP version 22.05 (#1097)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
a-h-abdelsalam authored Dec 13, 2023
1 parent 96712c9 commit f324559
Show file tree
Hide file tree
Showing 82 changed files with 4,870 additions and 7 deletions.
5 changes: 4 additions & 1 deletion gvm/protocols/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
Package for supported Greenbone Protocol versions.
Currently `GMP version 20.08`_, `GMP version 21.04`_
`GMP version 22.04` and `OSP version 1`_ are supported.
`GMP version 22.04`, `GMP version 22.05`
and `OSP version 1`_ are supported.
.. _GMP version 20.08:
https://docs.greenbone.net/API/GMP/gmp-20.08.html
.. _GMP version 21.04:
https://docs.greenbone.net/API/GMP/gmp-21.04.html
.. _GMP version 22.04:
https://docs.greenbone.net/API/GMP/gmp-22.04.html
.. _GMP version 22.05:
https://docs.greenbone.net/API/GMP/gmp-22.05.html
.. _OSP version 1:
https://docs.greenbone.net/API/OSP/osp-1.2.html
"""
5 changes: 4 additions & 1 deletion gvm/protocols/gmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
from gvm.protocols.gmpv208 import Gmp as Gmpv208
from gvm.protocols.gmpv214 import Gmp as Gmpv214
from gvm.protocols.gmpv224 import Gmp as Gmpv224
from gvm.protocols.gmpv225 import Gmp as Gmpv225
from gvm.transforms import EtreeCheckCommandTransform
from gvm.xml import XmlCommand

SUPPORTED_GMP_VERSIONS = Union[ # pylint: disable=invalid-name
Gmpv208, Gmpv214, Gmpv224
Gmpv208, Gmpv214, Gmpv224, Gmpv225
]


Expand Down Expand Up @@ -104,6 +105,8 @@ def determine_supported_gmp(self) -> SUPPORTED_GMP_VERSIONS:
gmp_class = Gmpv214
elif major_version == 22 and minor_version == 4:
gmp_class = Gmpv224
elif major_version == 22 and minor_version == 5:
gmp_class = Gmpv225
else:
raise GvmError(
"Remote manager daemon uses an unsupported version of GMP. "
Expand Down
210 changes: 210 additions & 0 deletions gvm/protocols/gmpv225/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2023 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# 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 3 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, see <http://www.gnu.org/licenses/>.

# pylint: disable=too-many-lines,redefined-builtin

"""
Module for communication with gvmd in
`Greenbone Management Protocol version 22.05`_
.. _Greenbone Management Protocol version 22.05:
https://docs.greenbone.net/API/GMP/gmp-22.05.html
"""

import logging
from typing import Any, Callable, Optional

from gvm.connections import GvmConnection
from gvm.protocols.base import GvmProtocol
from gvm.protocols.gmpv208.entities.alerts import (
AlertCondition,
AlertEvent,
AlertMethod,
AlertsMixin,
)
from gvm.protocols.gmpv208.entities.audits import AuditsMixin
from gvm.protocols.gmpv208.entities.credentials import (
CredentialFormat,
CredentialsMixin,
CredentialType,
SnmpAuthAlgorithm,
SnmpPrivacyAlgorithm,
)
from gvm.protocols.gmpv208.entities.entities import EntityType
from gvm.protocols.gmpv208.entities.filter import FiltersMixin, FilterType
from gvm.protocols.gmpv208.entities.groups import GroupsMixin
from gvm.protocols.gmpv208.entities.hosts import HostsMixin, HostsOrdering
from gvm.protocols.gmpv208.entities.operating_systems import (
OperatingSystemsMixin,
)
from gvm.protocols.gmpv208.entities.permissions import (
PermissionsMixin,
PermissionSubjectType,
)
from gvm.protocols.gmpv208.entities.policies import PoliciesMixin
from gvm.protocols.gmpv208.entities.port_lists import (
PortListMixin,
PortRangeType,
)
from gvm.protocols.gmpv208.entities.report_formats import (
ReportFormatsMixin,
ReportFormatType,
)
from gvm.protocols.gmpv208.entities.reports import ReportsMixin
from gvm.protocols.gmpv208.entities.results import ResultsMixin
from gvm.protocols.gmpv208.entities.roles import RolesMixin
from gvm.protocols.gmpv208.entities.schedules import SchedulesMixin
from gvm.protocols.gmpv208.entities.secinfo import InfoType, SecInfoMixin
from gvm.protocols.gmpv208.entities.severity import SeverityLevel
from gvm.protocols.gmpv208.entities.tags import TagsMixin
from gvm.protocols.gmpv208.entities.tasks import TasksMixin
from gvm.protocols.gmpv208.entities.tickets import TicketsMixin, TicketStatus
from gvm.protocols.gmpv208.entities.tls_certificates import TLSCertificateMixin
from gvm.protocols.gmpv208.entities.users import UserAuthType
from gvm.protocols.gmpv208.entities.vulnerabilities import VulnerabilitiesMixin
from gvm.protocols.gmpv208.system.aggregates import (
AggregatesMixin,
AggregateStatistic,
SortOrder,
)
from gvm.protocols.gmpv208.system.authentication import AuthenticationMixin
from gvm.protocols.gmpv208.system.feed import FeedMixin, FeedType
from gvm.protocols.gmpv208.system.help import HelpFormat, HelpMixin
from gvm.protocols.gmpv208.system.system_reports import SystemReportsMixin
from gvm.protocols.gmpv208.system.trashcan import TrashcanMixin
from gvm.protocols.gmpv208.system.user_settings import UserSettingsMixin

# NEW IN 214
from gvm.protocols.gmpv214.entities.notes import NotesMixin
from gvm.protocols.gmpv214.entities.overrides import OverridesMixin
from gvm.protocols.gmpv214.entities.targets import AliveTest, TargetsMixin
from gvm.protocols.gmpv224.entities.scan_configs import ScanConfigsMixin
from gvm.protocols.gmpv224.entities.scanners import ScannersMixin, ScannerType

# NEW IN 224
from gvm.protocols.gmpv224.entities.users import UsersMixin

# NEW IN 225
from gvm.protocols.gmpv225.entities.resourcenames import (
ResourceNamesMixin,
ResourceType,
)
from gvm.protocols.gmpv225.system.version import VersionMixin
from gvm.utils import to_dotted_types_dict

logger = logging.getLogger(__name__)

_TYPE_FIELDS = [
AggregateStatistic,
AlertCondition,
AlertEvent,
AlertMethod,
AliveTest,
CredentialFormat,
CredentialType,
EntityType,
FeedType,
FilterType,
HostsOrdering,
InfoType,
HelpFormat,
PortRangeType,
PermissionSubjectType,
ReportFormatType,
ResourceType,
ScannerType,
SeverityLevel,
SnmpAuthAlgorithm,
SnmpPrivacyAlgorithm,
SortOrder,
TicketStatus,
UserAuthType,
]


class Gmp(
GvmProtocol,
AggregatesMixin,
AlertsMixin,
AuditsMixin,
AuthenticationMixin,
CredentialsMixin,
FeedMixin,
FiltersMixin,
GroupsMixin,
HelpMixin,
HostsMixin,
NotesMixin,
OperatingSystemsMixin,
OverridesMixin,
PermissionsMixin,
PoliciesMixin,
PortListMixin,
ReportFormatsMixin,
ReportsMixin,
ResourceNamesMixin,
ResultsMixin,
RolesMixin,
TagsMixin,
TargetsMixin,
TasksMixin,
TicketsMixin,
TLSCertificateMixin,
TrashcanMixin,
ScanConfigsMixin,
ScannersMixin,
SchedulesMixin,
SecInfoMixin,
SystemReportsMixin,
UserSettingsMixin,
UsersMixin,
VersionMixin,
VulnerabilitiesMixin,
):
"""Python interface for Greenbone Management Protocol
This class implements the `Greenbone Management Protocol version 22.05`_
Arguments:
connection: Connection to use to talk with the gvmd daemon. See
:mod:`gvm.connections` for possible connection types.
transform: Optional transform `callable`_ to convert response data.
After each request the callable gets passed the plain response data
which can be used to check the data and/or conversion into different
representations like a xml dom.
See :mod:`gvm.transforms` for existing transforms.
.. _Greenbone Management Protocol version 22.05:
https://docs.greenbone.net/API/GMP/gmp-22.05.html
.. _callable:
https://docs.python.org/3/library/functions.html#callable
"""

def __init__(
self,
connection: GvmConnection,
*,
transform: Optional[Callable[[str], Any]] = None,
):
self.types = to_dotted_types_dict(_TYPE_FIELDS)

super().__init__(connection, transform=transform)

# Is authenticated on gvmd
self._authenticated = False
17 changes: 17 additions & 0 deletions gvm/protocols/gmpv225/entities/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2023 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
Loading

0 comments on commit f324559

Please sign in to comment.