python-gvm 24.1.0__py3-none-any.whl → 24.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gvm/__init__.py +1 -14
- gvm/__version__.py +1 -1
- gvm/_enum.py +38 -0
- gvm/connections.py +82 -63
- gvm/errors.py +1 -14
- gvm/protocols/__init__.py +1 -14
- gvm/protocols/base.py +1 -14
- gvm/protocols/gmp.py +1 -14
- gvm/protocols/gmpv208/__init__.py +1 -14
- gvm/protocols/gmpv208/entities/__init__.py +1 -14
- gvm/protocols/gmpv208/entities/alerts.py +2 -65
- gvm/protocols/gmpv208/entities/audits.py +1 -15
- gvm/protocols/gmpv208/entities/credentials.py +3 -87
- gvm/protocols/gmpv208/entities/entities.py +3 -30
- gvm/protocols/gmpv208/entities/filter.py +4 -26
- gvm/protocols/gmpv208/entities/groups.py +1 -14
- gvm/protocols/gmpv208/entities/hosts.py +3 -37
- gvm/protocols/gmpv208/entities/notes.py +1 -15
- gvm/protocols/gmpv208/entities/operating_systems.py +1 -14
- gvm/protocols/gmpv208/entities/overrides.py +1 -14
- gvm/protocols/gmpv208/entities/permissions.py +3 -39
- gvm/protocols/gmpv208/entities/policies.py +1 -14
- gvm/protocols/gmpv208/entities/port_lists.py +3 -40
- gvm/protocols/gmpv208/entities/report_formats.py +2 -32
- gvm/protocols/gmpv208/entities/reports.py +1 -14
- gvm/protocols/gmpv208/entities/results.py +1 -14
- gvm/protocols/gmpv208/entities/roles.py +1 -14
- gvm/protocols/gmpv208/entities/scan_configs.py +1 -14
- gvm/protocols/gmpv208/entities/scanners.py +1 -14
- gvm/protocols/gmpv208/entities/schedules.py +1 -14
- gvm/protocols/gmpv208/entities/secinfo.py +3 -32
- gvm/protocols/gmpv208/entities/severity.py +2 -35
- gvm/protocols/gmpv208/entities/tags.py +1 -14
- gvm/protocols/gmpv208/entities/targets.py +1 -15
- gvm/protocols/gmpv208/entities/tasks.py +1 -15
- gvm/protocols/gmpv208/entities/tickets.py +3 -33
- gvm/protocols/gmpv208/entities/tls_certificates.py +1 -15
- gvm/protocols/gmpv208/entities/users.py +3 -34
- gvm/protocols/gmpv208/entities/vulnerabilities.py +1 -14
- gvm/protocols/gmpv208/system/__init__.py +1 -14
- gvm/protocols/gmpv208/system/aggregates.py +3 -61
- gvm/protocols/gmpv208/system/authentication.py +1 -14
- gvm/protocols/gmpv208/system/feed.py +3 -30
- gvm/protocols/gmpv208/system/help.py +3 -37
- gvm/protocols/gmpv208/system/system_reports.py +1 -14
- gvm/protocols/gmpv208/system/trashcan.py +1 -14
- gvm/protocols/gmpv208/system/user_settings.py +1 -14
- gvm/protocols/gmpv208/system/version.py +1 -14
- gvm/protocols/gmpv214/__init__.py +1 -14
- gvm/protocols/gmpv214/entities/__init__.py +1 -14
- gvm/protocols/gmpv214/entities/notes.py +1 -15
- gvm/protocols/gmpv214/entities/overrides.py +1 -15
- gvm/protocols/gmpv214/entities/scanners.py +1 -14
- gvm/protocols/gmpv214/entities/targets.py +1 -14
- gvm/protocols/gmpv214/entities/users.py +1 -14
- gvm/protocols/gmpv214/system/__init__.py +1 -14
- gvm/protocols/gmpv214/system/version.py +1 -14
- gvm/protocols/gmpv224/__init__.py +1 -14
- gvm/protocols/gmpv224/entities/__init__.py +1 -14
- gvm/protocols/gmpv224/entities/scan_configs.py +1 -14
- gvm/protocols/gmpv224/entities/scanners.py +1 -14
- gvm/protocols/gmpv224/entities/users.py +1 -14
- gvm/protocols/gmpv224/system/__init__.py +1 -14
- gvm/protocols/gmpv224/system/version.py +1 -14
- gvm/protocols/gmpv225/__init__.py +1 -14
- gvm/protocols/gmpv225/entities/__init__.py +1 -14
- gvm/protocols/gmpv225/entities/resourcenames.py +3 -36
- gvm/protocols/gmpv225/system/__init__.py +1 -14
- gvm/protocols/gmpv225/system/version.py +1 -15
- gvm/protocols/latest.py +1 -14
- gvm/protocols/next.py +1 -14
- gvm/protocols/ospv1.py +1 -14
- gvm/transforms.py +1 -14
- gvm/utils.py +1 -14
- gvm/xml.py +1 -14
- {python_gvm-24.1.0.dist-info → python_gvm-24.3.0.dist-info}/METADATA +5 -6
- python_gvm-24.3.0.dist-info/RECORD +80 -0
- {python_gvm-24.1.0.dist-info → python_gvm-24.3.0.dist-info}/WHEEL +1 -1
- python_gvm-24.1.0.dist-info/RECORD +0 -79
- {python_gvm-24.1.0.dist-info → python_gvm-24.3.0.dist-info}/LICENSE +0 -0
gvm/__init__.py
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Copyright (C) 2018-2022 Greenbone AG
|
|
1
|
+
# SPDX-FileCopyrightText: 2018-2024 Greenbone AG
|
|
3
2
|
#
|
|
4
3
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
5
4
|
#
|
|
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
5
|
"""
|
|
19
6
|
Main module of python-gvm.
|
|
20
7
|
"""
|
gvm/__version__.py
CHANGED
gvm/_enum.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2024 Greenbone AG
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
4
|
+
#
|
|
5
|
+
|
|
6
|
+
from enum import Enum as PythonEnum
|
|
7
|
+
from typing import Optional
|
|
8
|
+
|
|
9
|
+
from typing_extensions import Self
|
|
10
|
+
|
|
11
|
+
from gvm.errors import InvalidArgument
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Enum(PythonEnum):
|
|
15
|
+
"""
|
|
16
|
+
Base class for Enums in python-gvm
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
@classmethod
|
|
20
|
+
def from_string(
|
|
21
|
+
cls,
|
|
22
|
+
value: Optional[str],
|
|
23
|
+
) -> Optional[Self]:
|
|
24
|
+
"""
|
|
25
|
+
Convert a string value into an Enum instance
|
|
26
|
+
|
|
27
|
+
If value is None or empty None is returned
|
|
28
|
+
"""
|
|
29
|
+
if not value:
|
|
30
|
+
return None
|
|
31
|
+
|
|
32
|
+
try:
|
|
33
|
+
return cls[value.replace(" ", "_").upper()]
|
|
34
|
+
except KeyError:
|
|
35
|
+
raise InvalidArgument(
|
|
36
|
+
f"Invalid argument {value} for {cls.__name__}.from_string. "
|
|
37
|
+
f"Allowed values are {','.join(e.name for e in cls)}."
|
|
38
|
+
) from None
|
gvm/connections.py
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Copyright (C) 2018-2022 Greenbone AG
|
|
1
|
+
# SPDX-FileCopyrightText: 2018-2024 Greenbone AG
|
|
3
2
|
#
|
|
4
3
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
5
4
|
#
|
|
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
5
|
"""
|
|
19
6
|
Module for connections to GVM server daemons like gvmd and ospd.
|
|
20
7
|
"""
|
|
@@ -26,11 +13,14 @@ import socket as socketlib
|
|
|
26
13
|
import ssl
|
|
27
14
|
import sys
|
|
28
15
|
import time
|
|
16
|
+
from abc import ABC, abstractmethod
|
|
17
|
+
from os import PathLike
|
|
29
18
|
from pathlib import Path
|
|
30
|
-
from typing import Optional, Union
|
|
19
|
+
from typing import Optional, Protocol, Union, runtime_checkable
|
|
31
20
|
|
|
32
21
|
import paramiko
|
|
33
22
|
import paramiko.ssh_exception
|
|
23
|
+
import paramiko.transport
|
|
34
24
|
from lxml import etree
|
|
35
25
|
|
|
36
26
|
from gvm.errors import GvmError
|
|
@@ -49,13 +39,28 @@ DEFAULT_HOSTNAME = "127.0.0.1"
|
|
|
49
39
|
DEFAULT_KNOWN_HOSTS_FILE = ".ssh/known_hosts"
|
|
50
40
|
MAX_SSH_DATA_LENGTH = 4095
|
|
51
41
|
|
|
42
|
+
Data = Union[str, bytes]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@runtime_checkable
|
|
46
|
+
class GvmConnection(Protocol):
|
|
47
|
+
def connect(self) -> None: ...
|
|
48
|
+
|
|
49
|
+
def disconnect(self) -> None: ...
|
|
50
|
+
|
|
51
|
+
def send(self, data: Data) -> None: ...
|
|
52
|
+
|
|
53
|
+
def read(self) -> str: ...
|
|
54
|
+
|
|
55
|
+
def finish_send(self): ...
|
|
56
|
+
|
|
52
57
|
|
|
53
58
|
class XmlReader:
|
|
54
59
|
"""
|
|
55
60
|
Read a XML command until its closing element
|
|
56
61
|
"""
|
|
57
62
|
|
|
58
|
-
def
|
|
63
|
+
def start_xml(self) -> None:
|
|
59
64
|
self._first_element = None
|
|
60
65
|
# act on start and end element events and
|
|
61
66
|
# allow huge text data (for report content)
|
|
@@ -63,7 +68,7 @@ class XmlReader:
|
|
|
63
68
|
events=("start", "end"), huge_tree=True
|
|
64
69
|
)
|
|
65
70
|
|
|
66
|
-
def
|
|
71
|
+
def is_end_xml(self) -> bool:
|
|
67
72
|
for action, obj in self._parser.read_events():
|
|
68
73
|
if not self._first_element and action in "start":
|
|
69
74
|
self._first_element = obj.tag
|
|
@@ -76,7 +81,7 @@ class XmlReader:
|
|
|
76
81
|
return True
|
|
77
82
|
return False
|
|
78
83
|
|
|
79
|
-
def
|
|
84
|
+
def feed_xml(self, data: Data) -> None:
|
|
80
85
|
try:
|
|
81
86
|
self._parser.feed(data)
|
|
82
87
|
except etree.ParseError as e:
|
|
@@ -86,7 +91,7 @@ class XmlReader:
|
|
|
86
91
|
) from None
|
|
87
92
|
|
|
88
93
|
|
|
89
|
-
class
|
|
94
|
+
class AbstractGvmConnection(ABC):
|
|
90
95
|
"""
|
|
91
96
|
Base class for establishing a connection to a remote server daemon.
|
|
92
97
|
|
|
@@ -95,18 +100,23 @@ class GvmConnection(XmlReader):
|
|
|
95
100
|
wait indefinitely
|
|
96
101
|
"""
|
|
97
102
|
|
|
98
|
-
def __init__(self, timeout: Optional[int] = DEFAULT_TIMEOUT):
|
|
103
|
+
def __init__(self, timeout: Optional[Union[int, float]] = DEFAULT_TIMEOUT):
|
|
99
104
|
self._socket = None
|
|
100
105
|
self._timeout = timeout if timeout is not None else DEFAULT_TIMEOUT
|
|
106
|
+
self._xml_reader = XmlReader()
|
|
101
107
|
|
|
102
108
|
def _read(self) -> bytes:
|
|
109
|
+
if self._socket is None:
|
|
110
|
+
raise GvmError("Socket is not connected")
|
|
111
|
+
|
|
103
112
|
return self._socket.recv(BUF_SIZE)
|
|
104
113
|
|
|
105
|
-
|
|
114
|
+
@abstractmethod
|
|
115
|
+
def connect(self) -> None:
|
|
106
116
|
"""Establish a connection to a remote server"""
|
|
107
117
|
raise NotImplementedError
|
|
108
118
|
|
|
109
|
-
def send(self, data:
|
|
119
|
+
def send(self, data: Data) -> None:
|
|
110
120
|
"""Send data to the connected remote server
|
|
111
121
|
|
|
112
122
|
Arguments:
|
|
@@ -117,9 +127,9 @@ class GvmConnection(XmlReader):
|
|
|
117
127
|
raise GvmError("Socket is not connected")
|
|
118
128
|
|
|
119
129
|
if isinstance(data, str):
|
|
120
|
-
|
|
130
|
+
self._socket.sendall(data.encode())
|
|
121
131
|
else:
|
|
122
|
-
|
|
132
|
+
self._socket.sendall(data)
|
|
123
133
|
|
|
124
134
|
def read(self) -> str:
|
|
125
135
|
"""Read data from the remote server
|
|
@@ -129,12 +139,11 @@ class GvmConnection(XmlReader):
|
|
|
129
139
|
"""
|
|
130
140
|
response = ""
|
|
131
141
|
|
|
132
|
-
self.
|
|
142
|
+
self._xml_reader.start_xml()
|
|
133
143
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
break_timeout = now + self._timeout
|
|
144
|
+
break_timeout = (
|
|
145
|
+
time.time() + self._timeout if self._timeout is not None else None
|
|
146
|
+
)
|
|
138
147
|
|
|
139
148
|
while True:
|
|
140
149
|
data = self._read()
|
|
@@ -143,19 +152,19 @@ class GvmConnection(XmlReader):
|
|
|
143
152
|
# Connection was closed by server
|
|
144
153
|
raise GvmError("Remote closed the connection")
|
|
145
154
|
|
|
146
|
-
self.
|
|
155
|
+
self._xml_reader.feed_xml(data)
|
|
147
156
|
|
|
148
157
|
response += data.decode("utf-8", errors="ignore")
|
|
149
158
|
|
|
150
|
-
if self.
|
|
159
|
+
if self._xml_reader.is_end_xml():
|
|
151
160
|
break
|
|
152
161
|
|
|
153
|
-
if time.time() > break_timeout:
|
|
162
|
+
if break_timeout and time.time() > break_timeout:
|
|
154
163
|
raise GvmError("Timeout while reading the response")
|
|
155
164
|
|
|
156
165
|
return response
|
|
157
166
|
|
|
158
|
-
def disconnect(self):
|
|
167
|
+
def disconnect(self) -> None:
|
|
159
168
|
"""Disconnect and close the connection to the remote server"""
|
|
160
169
|
try:
|
|
161
170
|
if self._socket is not None:
|
|
@@ -165,11 +174,12 @@ class GvmConnection(XmlReader):
|
|
|
165
174
|
|
|
166
175
|
def finish_send(self):
|
|
167
176
|
"""Indicate to the remote server you are done with sending data"""
|
|
168
|
-
|
|
169
|
-
|
|
177
|
+
if self._socket is not None:
|
|
178
|
+
# shutdown socket for sending. only allow reading data afterwards
|
|
179
|
+
self._socket.shutdown(socketlib.SHUT_WR)
|
|
170
180
|
|
|
171
181
|
|
|
172
|
-
class SSHConnection(
|
|
182
|
+
class SSHConnection(AbstractGvmConnection):
|
|
173
183
|
"""
|
|
174
184
|
SSH Class to connect, read and write from GVM via SSH
|
|
175
185
|
|
|
@@ -179,22 +189,21 @@ class SSHConnection(GvmConnection):
|
|
|
179
189
|
127.0.0.1.
|
|
180
190
|
port: Port of the remote SSH server. Default is port 22.
|
|
181
191
|
username: Username to use for SSH login. Default is "gmp".
|
|
182
|
-
password:
|
|
192
|
+
password: Password to use for SSH login. Default is "".
|
|
183
193
|
"""
|
|
184
194
|
|
|
185
195
|
def __init__(
|
|
186
196
|
self,
|
|
187
197
|
*,
|
|
188
|
-
timeout: Optional[int] = DEFAULT_TIMEOUT,
|
|
198
|
+
timeout: Optional[Union[int, float]] = DEFAULT_TIMEOUT,
|
|
189
199
|
hostname: Optional[str] = DEFAULT_HOSTNAME,
|
|
190
200
|
port: Optional[int] = DEFAULT_SSH_PORT,
|
|
191
201
|
username: Optional[str] = DEFAULT_SSH_USERNAME,
|
|
192
202
|
password: Optional[str] = DEFAULT_SSH_PASSWORD,
|
|
193
|
-
known_hosts_file: Optional[str] = None,
|
|
203
|
+
known_hosts_file: Optional[Union[str, PathLike]] = None,
|
|
194
204
|
auto_accept_host: Optional[bool] = None,
|
|
195
|
-
):
|
|
196
|
-
super().__init__(timeout
|
|
197
|
-
|
|
205
|
+
) -> None:
|
|
206
|
+
super().__init__(timeout)
|
|
198
207
|
self.hostname = hostname if hostname is not None else DEFAULT_HOSTNAME
|
|
199
208
|
self.port = int(port) if port is not None else DEFAULT_SSH_PORT
|
|
200
209
|
self.username = (
|
|
@@ -210,7 +219,7 @@ class SSHConnection(GvmConnection):
|
|
|
210
219
|
)
|
|
211
220
|
self.auto_accept_host = auto_accept_host
|
|
212
221
|
|
|
213
|
-
def _send_all(self, data) -> int:
|
|
222
|
+
def _send_all(self, data: bytes) -> int:
|
|
214
223
|
"""Returns the sum of sent bytes if success"""
|
|
215
224
|
sent_sum = 0
|
|
216
225
|
while data:
|
|
@@ -237,13 +246,15 @@ class SSHConnection(GvmConnection):
|
|
|
237
246
|
key,
|
|
238
247
|
)
|
|
239
248
|
try:
|
|
240
|
-
hostkeys.save(filename=self.known_hosts_file)
|
|
249
|
+
hostkeys.save(filename=str(self.known_hosts_file))
|
|
241
250
|
except OSError as e:
|
|
242
251
|
raise GvmError(
|
|
243
252
|
"Something went wrong with writing "
|
|
244
253
|
f"the known_hosts file: {e}"
|
|
245
254
|
) from None
|
|
255
|
+
|
|
246
256
|
key_type = key.get_name().replace("ssh-", "").upper()
|
|
257
|
+
|
|
247
258
|
logger.info(
|
|
248
259
|
"Warning: Permanently added '%s' (%s) to "
|
|
249
260
|
"the list of known hosts.",
|
|
@@ -260,12 +271,14 @@ class SSHConnection(GvmConnection):
|
|
|
260
271
|
hashlib.sha256(base64.b64decode(key.get_base64())).digest()
|
|
261
272
|
).decode("utf-8")[:-1]
|
|
262
273
|
key_type = key.get_name().replace("ssh-", "").upper()
|
|
274
|
+
|
|
263
275
|
print(
|
|
264
276
|
f"The authenticity of host '{self.hostname}' can't "
|
|
265
277
|
"be established."
|
|
266
278
|
)
|
|
267
279
|
print(f"{key_type} key fingerprint is {sha64_fingerprint}.")
|
|
268
280
|
print("Are you sure you want to continue connecting (yes/no)? ", end="")
|
|
281
|
+
|
|
269
282
|
add = input()
|
|
270
283
|
while True:
|
|
271
284
|
if add == "yes":
|
|
@@ -277,22 +290,25 @@ class SSHConnection(GvmConnection):
|
|
|
277
290
|
key.get_name(),
|
|
278
291
|
key,
|
|
279
292
|
)
|
|
293
|
+
|
|
280
294
|
# ask user if the key should be added permanently
|
|
281
295
|
print(
|
|
282
296
|
f"Do you want to add {self.hostname} "
|
|
283
297
|
"to known_hosts (yes/no)? ",
|
|
284
298
|
end="",
|
|
285
299
|
)
|
|
300
|
+
|
|
286
301
|
save = input()
|
|
287
302
|
while True:
|
|
288
303
|
if save == "yes":
|
|
289
304
|
try:
|
|
290
|
-
hostkeys.save(filename=self.known_hosts_file)
|
|
305
|
+
hostkeys.save(filename=str(self.known_hosts_file))
|
|
291
306
|
except OSError as e:
|
|
292
307
|
raise GvmError(
|
|
293
308
|
"Something went wrong with writing "
|
|
294
309
|
f"the known_hosts file: {e}"
|
|
295
310
|
) from None
|
|
311
|
+
|
|
296
312
|
logger.info(
|
|
297
313
|
"Warning: Permanently added '%s' (%s) to "
|
|
298
314
|
"the list of known hosts.",
|
|
@@ -318,7 +334,7 @@ class SSHConnection(GvmConnection):
|
|
|
318
334
|
print("Please type 'yes' or 'no': ", end="")
|
|
319
335
|
add = input()
|
|
320
336
|
|
|
321
|
-
def _get_remote_host_key(self):
|
|
337
|
+
def _get_remote_host_key(self) -> paramiko.PKey:
|
|
322
338
|
"""Get the remote host key for ssh connection"""
|
|
323
339
|
try:
|
|
324
340
|
tmp_socket = socketlib.socket()
|
|
@@ -355,7 +371,7 @@ class SSHConnection(GvmConnection):
|
|
|
355
371
|
# https://stackoverflow.com/q/32945533
|
|
356
372
|
try:
|
|
357
373
|
# load the keys into paramiko and check if remote is in the list
|
|
358
|
-
self._socket.load_host_keys(filename=self.known_hosts_file)
|
|
374
|
+
self._socket.load_host_keys(filename=str(self.known_hosts_file))
|
|
359
375
|
except OSError as e:
|
|
360
376
|
if e.errno != errno.ENOENT:
|
|
361
377
|
raise GvmError(
|
|
@@ -412,10 +428,13 @@ class SSHConnection(GvmConnection):
|
|
|
412
428
|
def _read(self) -> bytes:
|
|
413
429
|
return self._stdout.channel.recv(BUF_SIZE)
|
|
414
430
|
|
|
415
|
-
def send(self, data:
|
|
416
|
-
|
|
431
|
+
def send(self, data: Data) -> None:
|
|
432
|
+
if isinstance(data, str):
|
|
433
|
+
self._send_all(data.encode())
|
|
434
|
+
else:
|
|
435
|
+
self._send_all(data)
|
|
417
436
|
|
|
418
|
-
def finish_send(self):
|
|
437
|
+
def finish_send(self) -> None:
|
|
419
438
|
# shutdown socket for sending. only allow reading data afterwards
|
|
420
439
|
self._stdout.channel.shutdown(socketlib.SHUT_WR)
|
|
421
440
|
|
|
@@ -434,7 +453,7 @@ class SSHConnection(GvmConnection):
|
|
|
434
453
|
del self._socket, self._stdin, self._stdout, self._stderr
|
|
435
454
|
|
|
436
455
|
|
|
437
|
-
class TLSConnection(
|
|
456
|
+
class TLSConnection(AbstractGvmConnection):
|
|
438
457
|
"""
|
|
439
458
|
TLS class to connect, read and write from a remote GVM daemon via TLS
|
|
440
459
|
secured socket.
|
|
@@ -466,8 +485,8 @@ class TLSConnection(GvmConnection):
|
|
|
466
485
|
hostname: Optional[str] = DEFAULT_HOSTNAME,
|
|
467
486
|
port: Optional[int] = DEFAULT_GVM_PORT,
|
|
468
487
|
password: Optional[str] = None,
|
|
469
|
-
timeout: Optional[int] = DEFAULT_TIMEOUT,
|
|
470
|
-
):
|
|
488
|
+
timeout: Optional[Union[int, float]] = DEFAULT_TIMEOUT,
|
|
489
|
+
) -> None:
|
|
471
490
|
super().__init__(timeout=timeout)
|
|
472
491
|
|
|
473
492
|
self.hostname = hostname if hostname is not None else DEFAULT_HOSTNAME
|
|
@@ -505,7 +524,7 @@ class TLSConnection(GvmConnection):
|
|
|
505
524
|
|
|
506
525
|
return sock
|
|
507
526
|
|
|
508
|
-
def connect(self):
|
|
527
|
+
def connect(self) -> None:
|
|
509
528
|
self._socket = self._new_socket()
|
|
510
529
|
self._socket.connect((self.hostname, int(self.port)))
|
|
511
530
|
|
|
@@ -516,10 +535,10 @@ class TLSConnection(GvmConnection):
|
|
|
516
535
|
self._socket = self._socket.unwrap()
|
|
517
536
|
except OSError as e:
|
|
518
537
|
logger.debug("Connection closing error: %s", e)
|
|
519
|
-
return super(
|
|
538
|
+
return super().disconnect()
|
|
520
539
|
|
|
521
540
|
|
|
522
|
-
class UnixSocketConnection(
|
|
541
|
+
class UnixSocketConnection(AbstractGvmConnection):
|
|
523
542
|
"""
|
|
524
543
|
UNIX-Socket class to connect, read, write from a daemon via direct
|
|
525
544
|
communicating UNIX-Socket
|
|
@@ -533,7 +552,7 @@ class UnixSocketConnection(GvmConnection):
|
|
|
533
552
|
self,
|
|
534
553
|
*,
|
|
535
554
|
path: Optional[str] = DEFAULT_UNIX_SOCKET_PATH,
|
|
536
|
-
timeout: Optional[int] = DEFAULT_TIMEOUT,
|
|
555
|
+
timeout: Optional[Union[int, float]] = DEFAULT_TIMEOUT,
|
|
537
556
|
) -> None:
|
|
538
557
|
super().__init__(timeout=timeout)
|
|
539
558
|
|
|
@@ -572,8 +591,8 @@ class DebugConnection:
|
|
|
572
591
|
|
|
573
592
|
logging.basicConfig(level=logging.DEBUG)
|
|
574
593
|
|
|
575
|
-
|
|
576
|
-
connection = DebugConnection(
|
|
594
|
+
socket_connection = UnixSocketConnection(path='/var/run/gvm.sock')
|
|
595
|
+
connection = DebugConnection(socket_connection)
|
|
577
596
|
gmp = Gmp(connection=connection)
|
|
578
597
|
|
|
579
598
|
Arguments:
|
|
@@ -594,24 +613,24 @@ class DebugConnection:
|
|
|
594
613
|
self.last_read_data = data
|
|
595
614
|
return data
|
|
596
615
|
|
|
597
|
-
def send(self, data):
|
|
616
|
+
def send(self, data: Data) -> None:
|
|
598
617
|
self.last_send_data = data
|
|
599
618
|
|
|
600
619
|
logger.debug("Sending %s characters. Data %s", len(data), data)
|
|
601
620
|
|
|
602
621
|
return self._connection.send(data)
|
|
603
622
|
|
|
604
|
-
def connect(self):
|
|
623
|
+
def connect(self) -> None:
|
|
605
624
|
logger.debug("Connecting")
|
|
606
625
|
|
|
607
626
|
return self._connection.connect()
|
|
608
627
|
|
|
609
|
-
def disconnect(self):
|
|
628
|
+
def disconnect(self) -> None:
|
|
610
629
|
logger.debug("Disconnecting")
|
|
611
630
|
|
|
612
631
|
return self._connection.disconnect()
|
|
613
632
|
|
|
614
|
-
def finish_send(self):
|
|
633
|
+
def finish_send(self) -> None:
|
|
615
634
|
logger.debug("Finish send")
|
|
616
635
|
|
|
617
636
|
self._connection.finish_send()
|
gvm/errors.py
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Copyright (C) 2018-2022 Greenbone AG
|
|
1
|
+
# SPDX-FileCopyrightText: 2018-2024 Greenbone AG
|
|
3
2
|
#
|
|
4
3
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
5
4
|
#
|
|
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
5
|
"""
|
|
19
6
|
Module for GVM errors
|
|
20
7
|
"""
|
gvm/protocols/__init__.py
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Copyright (C) 2018-2022 Greenbone AG
|
|
1
|
+
# SPDX-FileCopyrightText: 2018-2024 Greenbone AG
|
|
3
2
|
#
|
|
4
3
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
5
4
|
#
|
|
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
5
|
"""
|
|
19
6
|
Package for supported Greenbone Protocol versions.
|
|
20
7
|
|
gvm/protocols/base.py
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Copyright (C) 2018-2022 Greenbone AG
|
|
1
|
+
# SPDX-FileCopyrightText: 2018-2024 Greenbone AG
|
|
3
2
|
#
|
|
4
3
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
5
4
|
#
|
|
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
5
|
|
|
19
6
|
from typing import Any, Callable, Optional
|
|
20
7
|
|
gvm/protocols/gmp.py
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Copyright (C) 2019-2022 Greenbone AG
|
|
1
|
+
# SPDX-FileCopyrightText: 2019-2024 Greenbone AG
|
|
3
2
|
#
|
|
4
3
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
5
4
|
#
|
|
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
5
|
|
|
19
6
|
"""
|
|
20
7
|
Module for communication with gvmd
|
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Copyright (C) 2018-2022 Greenbone AG
|
|
1
|
+
# SPDX-FileCopyrightText: 2018-2024 Greenbone AG
|
|
3
2
|
#
|
|
4
3
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
5
4
|
#
|
|
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
5
|
|
|
19
6
|
# pylint: disable=too-many-lines,redefined-builtin
|
|
20
7
|
"""
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Copyright (C) 2021-2022 Greenbone AG
|
|
1
|
+
# SPDX-FileCopyrightText: 2021-2024 Greenbone AG
|
|
3
2
|
#
|
|
4
3
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
5
4
|
#
|
|
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/>.
|