1 From aad61b320d65953fddec10b019a186fc67f57a5d Mon Sep 17 00:00:00 2001
2 From: OPNA2608 <opna2608@protonmail.com>
3 Date: Sat, 10 Feb 2024 12:20:29 +0100
4 Subject: [PATCH] src/model/transport.py: Port to paramiko 3.x
7 src/model/transport.py | 19 +++++++++----------
8 1 file changed, 9 insertions(+), 10 deletions(-)
10 diff --git a/src/model/transport.py b/src/model/transport.py
11 index 0c2ee16..5a2bd22 100644
12 --- a/src/model/transport.py
13 +++ b/src/model/transport.py
14 @@ -117,7 +117,6 @@ from paramiko.kex_gss import KexGSSGex, KexGSSGroup1, KexGSSGroup14
15 from paramiko.message import Message
16 from paramiko.packet import Packetizer, NeedRekeyException
17 from paramiko.primes import ModulusPack
18 -from paramiko.py3compat import string_types, long, byte_ord, b, input, PY2
19 from paramiko.rsakey import RSAKey
20 from paramiko.ecdsakey import ECDSAKey
21 from paramiko.server import ServerInterface
22 @@ -128,7 +127,7 @@ from paramiko.ssh_exception import (
26 -from paramiko.util import retry_on_signal, ClosingContextManager, clamp_value
27 +from paramiko.util import ClosingContextManager, clamp_value
31 @@ -396,7 +395,7 @@ class Transport(threading.Thread, ClosingContextManager):
35 - if isinstance(sock, string_types):
36 + if isinstance(sock, str):
37 # convert "host:port" into (host, port)
38 hl = sock.split(":", 1)
40 @@ -419,7 +418,7 @@ class Transport(threading.Thread, ClosingContextManager):
41 sock = socket.socket(af, socket.SOCK_STREAM)
44 - retry_on_signal(lambda: sock.connect((hostname, port)))
45 + sock.connect((hostname, port))
46 except socket.error as e:
49 @@ -542,7 +541,7 @@ class Transport(threading.Thread, ClosingContextManager):
51 Returns a string representation of this object, for debugging.
53 - id_ = hex(long(id(self)) & xffffffff)
54 + id_ = hex(int(id(self)) & xffffffff)
55 out = "<paramiko.Transport at {}".format(id_)
57 out += " (unconnected)"
58 @@ -1123,7 +1122,7 @@ class Transport(threading.Thread, ClosingContextManager):
60 m.add_byte(cMSG_IGNORE)
61 if byte_count is None:
62 - byte_count = (byte_ord(os.urandom(1)) % 32) + 10
63 + byte_count = (os.urandom(1) % 32) + 10
64 m.add_bytes(os.urandom(byte_count))
65 self._send_user_message(m)
67 @@ -1802,7 +1801,7 @@ class Transport(threading.Thread, ClosingContextManager):
68 def stop_thread(self):
70 self.packetizer.close()
73 # Original join logic; #520 doesn't appear commonly present under
75 while self.is_alive() and self is not threading.current_thread():
76 @@ -1909,7 +1908,7 @@ class Transport(threading.Thread, ClosingContextManager):
81 + m.add_byte(id.encode("utf8"))
82 m.add_bytes(self.session_id)
83 # Fallback to SHA1 for kex engines that fail to specify a hex
84 # algorithm, or for e.g. transport tests that don't run kexinit.
85 @@ -2037,14 +2036,14 @@ class Transport(threading.Thread, ClosingContextManager):
87 # active=True occurs before the thread is launched, to avoid a race
88 _active_threads.append(self)
89 - tid = hex(long(id(self)) & xffffffff)
90 + tid = hex(int(id(self)) & xffffffff)
92 self._log(DEBUG, "starting thread (server mode): {}".format(tid))
94 self._log(DEBUG, "starting thread (client mode): {}".format(tid))
97 - self.packetizer.write_all(b(self.local_version + "\r\n"))
98 + self.packetizer.write_all((self.local_version + "\r\n").encode("utf8"))
101 "Local version/idstring: {}".format(self.local_version),