Skip to content

Commit

Permalink
Add: Adding the structure for GVM 21.10. [#575]
Browse files Browse the repository at this point in the history
Prepare 21.10 release
  • Loading branch information
y0urself authored Nov 5, 2021
2 parents 37b55fd + bdd139d commit fe203be
Show file tree
Hide file tree
Showing 90 changed files with 5,938 additions and 47 deletions.
2 changes: 2 additions & 0 deletions gvm/protocols/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
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 21.10:
https://docs.greenbone.net/API/GMP/gmp-21.10.html
.. _OSP version 1:
https://docs.greenbone.net/API/OSP/osp-1.2.html
"""
12 changes: 8 additions & 4 deletions gvm/protocols/gmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from gvm.protocols.gmpv208 import Gmp as Gmpv208
from gvm.protocols.gmpv214 import Gmp as Gmpv214
from gvm.protocols.gmpv2110 import Gmp as Gmpv2110

from gvm.transforms import EtreeCheckCommandTransform

Expand Down Expand Up @@ -95,16 +96,19 @@ def determine_supported_gmp(self) -> SUPPORTED_GMP_VERSIONS:
"""Determine supported GMP version of the remote daemon and return a
corresponding Gmp class instance
"""
version = self.determine_remote_gmp_version()
major_version = int(version.split('.')[0])
version_str = self.determine_remote_gmp_version().split('.', 1)
major_version = int(version_str[0])
minor_version = int(version_str[1])
if major_version == 20:
gmp_class = Gmpv208
elif major_version == 21:
elif major_version == 21 and minor_version == 4:
gmp_class = Gmpv214
elif major_version == 21 and minor_version == 10:
gmp_class = Gmpv2110
else:
raise GvmError(
'Remote manager daemon uses an unsupported version of GMP. '
f'The GMP version was {version}.'
f'The GMP version was {major_version}.{minor_version}'
)

return gmp_class(self._connection, transform=self._gmp_transform)
Expand Down
30 changes: 0 additions & 30 deletions gvm/protocols/gmpv208/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,32 +130,6 @@

logger = logging.getLogger(__name__)

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


class Gmp(
GvmProtocol,
Expand Down Expand Up @@ -221,10 +195,6 @@ def __init__(
*,
transform: Optional[Callable[[str], Any]] = None,
):
self.types = {}
for t in _TYPE_FIELDS:
self.types[t.__name__] = t

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

# Is authenticated on gvmd
Expand Down
236 changes: 236 additions & 0 deletions gvm/protocols/gmpv2110/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2021 Greenbone Networks GmbH
#
# 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 21.10`_
.. _Greenbone Management Protocol version 21.10:
https://docs.greenbone.net/API/GMP/gmp-21.10.html
"""

import logging
from typing import Any, Callable, Optional

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.reports import ReportsMixin
from gvm.protocols.gmpv208.entities.report_formats import (
ReportFormatType,
ReportFormatsMixin,
)
from gvm.protocols.gmpv208.entities.results import ResultsMixin
from gvm.protocols.gmpv208.entities.roles import RolesMixin
from gvm.protocols.gmpv208.entities.scan_configs import ScanConfigsMixin
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 (
TicketStatus,
TicketsMixin,
)
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 (
FeedType,
FeedMixin,
)
from gvm.protocols.gmpv208.system.help import (
HelpFormat,
HelpMixin,
)
from gvm.protocols.gmpv208.system.system_reports import SystemReportsMixin
from gvm.protocols.gmpv208.system.user_settings import UserSettingsMixin
from gvm.protocols.gmpv208.system.trashcan import TrashcanMixin

# NEW IN 214
from gvm.protocols.gmpv214.entities.notes import NotesMixin
from gvm.protocols.gmpv214.entities.overrides import OverridesMixin
from gvm.protocols.gmpv214.entities.scanners import (
ScannerType,
ScannersMixin,
)
from gvm.protocols.gmpv214.entities.targets import (
AliveTest,
TargetsMixin,
)
from gvm.protocols.gmpv214.entities.users import UsersMixin

# NEW IN 2110
from gvm.protocols.gmpv2110.system.version import VersionMixin

from gvm.connections import GvmConnection

logger = logging.getLogger(__name__)

_TYPE_FIELDS = [
AggregateStatistic,
AlertCondition,
AlertEvent,
AlertMethod,
AliveTest,
CredentialFormat,
CredentialType,
EntityType,
FeedType,
FilterType,
HostsOrdering,
InfoType,
HelpFormat,
PortRangeType,
PermissionSubjectType,
ReportFormatType,
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,
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 21.10`_
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 21.10:
https://docs.greenbone.net/API/GMP/gmp-21.10.html
.. _callable:
https://docs.python.org/3/library/functions.html#callable
"""

def __init__(
self,
connection: GvmConnection,
*,
transform: Optional[Callable[[str], Any]] = None,
):
self.types = {}
for t in _TYPE_FIELDS:
self.types[t.__name__] = t

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

# Is authenticated on gvmd
self._authenticated = False
17 changes: 17 additions & 0 deletions gvm/protocols/gmpv2110/entities/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2021 Greenbone Networks GmbH
#
# 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/>.
17 changes: 17 additions & 0 deletions gvm/protocols/gmpv2110/system/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2021 Greenbone Networks GmbH
#
# 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/>.
36 changes: 36 additions & 0 deletions gvm/protocols/gmpv2110/system/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2021 Greenbone Networks GmbH
#
# 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/>.


from gvm.protocols.gmpv208.system.version import (
VersionMixin as Gmp208VersionMixin,
)

PROTOCOL_VERSION = (21, 10)


class VersionMixin(Gmp208VersionMixin):
@staticmethod
def get_protocol_version() -> tuple:
"""Determine the Greenbone Management Protocol (gmp) version used
by python-gvm version.
Returns:
tuple: Implemented version of the Greenbone Management Protocol
"""
return PROTOCOL_VERSION
Loading

0 comments on commit fe203be

Please sign in to comment.