|
| 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 |
0 commit comments