Skip to content

Commit 46636d6

Browse files
committed
Change compression to be disabled by default
This commit changes compression to default to off when AsyncSSH is acting as a client, only enabling it if the server requires it. This matches the OpenSSH default and avoids a potential bottleneck where running with compression enabled can actually slow down performance signficantly on high-bandwidth connections. This also cleans up some unintended cosmetic differences between the documentation for client and server connection options.
1 parent b5742a5 commit 46636d6

File tree

4 files changed

+41
-18
lines changed

4 files changed

+41
-18
lines changed

asyncssh/compression.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2013-2021 by Ron Frederick <ronf@timeheart.net> and others.
1+
# Copyright (c) 2013-2024 by Ron Frederick <ronf@timeheart.net> and others.
22
#
33
# This program and the accompanying materials are made available under
44
# the terms of the Eclipse Public License v2.0 which accompanies this
@@ -149,9 +149,9 @@ def get_decompressor(alg: bytes) -> Optional[Decompressor]:
149149

150150
return _cmp_decompressors[alg]()
151151

152+
register_compression_alg(b'none',
153+
_none, _none, False, True)
152154
register_compression_alg(b'zlib@openssh.com',
153155
_ZLibCompress, _ZLibDecompress, True, True)
154156
register_compression_alg(b'zlib',
155157
_ZLibCompress, _ZLibDecompress, False, False)
156-
register_compression_alg(b'none',
157-
_none, _none, False, True)

asyncssh/connection.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7544,16 +7544,17 @@ class SSHClientConnectionOptions(SSHConnectionOptions):
75447544
:param compression_algs: (optional)
75457545
A list of compression algorithms to use during the SSH handshake,
75467546
taken from :ref:`compression algorithms <CompressionAlgs>`, or
7547-
`None` to disable compression.
7547+
`None` to disable compression. The client prefers to disable
7548+
compression, but will enable it if the server requires it.
75487549
:param signature_algs: (optional)
75497550
A list of public key signature algorithms to use during the SSH
75507551
handshake, taken from :ref:`signature algorithms <SignatureAlgs>`.
75517552
:param rekey_bytes: (optional)
75527553
The number of bytes which can be sent before the SSH session
7553-
key is renegotiated. This defaults to 1 GB.
7554+
key is renegotiated, defaulting to 1 GB.
75547555
:param rekey_seconds: (optional)
75557556
The maximum time in seconds before the SSH session key is
7556-
renegotiated. This defaults to 1 hour.
7557+
renegotiated, defaulting to 1 hour.
75577558
:param connect_timeout: (optional)
75587559
The maximum time in seconds allowed to complete an outbound
75597560
SSH connection. This includes the time to establish the TCP
@@ -8289,26 +8290,28 @@ class SSHServerConnectionOptions(SSHConnectionOptions):
82898290
this server, defaulting to `'AsyncSSH'` and its version number.
82908291
:param kex_algs: (optional)
82918292
A list of allowed key exchange algorithms in the SSH handshake,
8292-
taken from :ref:`key exchange algorithms <KexAlgs>`
8293+
taken from :ref:`key exchange algorithms <KexAlgs>`,
82938294
:param encryption_algs: (optional)
82948295
A list of encryption algorithms to use during the SSH handshake,
8295-
taken from :ref:`encryption algorithms <EncryptionAlgs>`
8296+
taken from :ref:`encryption algorithms <EncryptionAlgs>`.
82968297
:param mac_algs: (optional)
82978298
A list of MAC algorithms to use during the SSH handshake, taken
8298-
from :ref:`MAC algorithms <MACAlgs>`
8299+
from :ref:`MAC algorithms <MACAlgs>`.
82998300
:param compression_algs: (optional)
83008301
A list of compression algorithms to use during the SSH handshake,
83018302
taken from :ref:`compression algorithms <CompressionAlgs>`, or
8302-
`None` to disable compression
8303+
`None` to disable compression. The server defaults to allowing
8304+
either no compression or compression after auth, depending on
8305+
what the client requests.
83038306
:param signature_algs: (optional)
83048307
A list of public key signature algorithms to use during the SSH
8305-
handshake, taken from :ref:`signature algorithms <SignatureAlgs>`
8308+
handshake, taken from :ref:`signature algorithms <SignatureAlgs>`.
83068309
:param rekey_bytes: (optional)
83078310
The number of bytes which can be sent before the SSH session
8308-
key is renegotiated, defaulting to 1 GB
8311+
key is renegotiated, defaulting to 1 GB.
83098312
:param rekey_seconds: (optional)
83108313
The maximum time in seconds before the SSH session key is
8311-
renegotiated, defaulting to 1 hour
8314+
renegotiated, defaulting to 1 hour.
83128315
:param connect_timeout: (optional)
83138316
The maximum time in seconds allowed to complete an outbound
83148317
SSH connection. This includes the time to establish the TCP
@@ -8318,8 +8321,8 @@ class SSHServerConnectionOptions(SSHConnectionOptions):
83188321
and AsyncSSH's login timeout.
83198322
:param login_timeout: (optional)
83208323
The maximum time in seconds allowed for authentication to
8321-
complete, defaulting to 2 minutes. Setting this to 0
8322-
will disable the login timeout.
8324+
complete, defaulting to 2 minutes. Setting this to 0 will
8325+
disable the login timeout.
83238326
83248327
.. note:: This timeout only applies after the SSH TCP
83258328
connection is established. To set a timeout

tests/test_channel.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,8 +1848,9 @@ async def test_dropbear_client(self):
18481848
"""Test reduced dropbear send packet size"""
18491849

18501850
with patch('asyncssh.connection.SSHServerChannel', _ServerChannel):
1851-
async with self.connect(client_version='dropbear',
1852-
max_pktsize=32759) as conn:
1851+
async with self.connect(
1852+
client_version='dropbear', max_pktsize=32759,
1853+
compression_algs=['zlib@openssh.com']) as conn:
18531854
_, stdout, _ = await conn.open_session('send_pktsize')
18541855
self.assertEqual((await stdout.read()), '32758')
18551856

@@ -1875,7 +1876,8 @@ async def test_dropbear_server(self):
18751876
"""Test reduced dropbear send packet size"""
18761877

18771878
with patch('asyncssh.connection.SSHClientChannel', _ClientChannel):
1878-
async with self.connect() as conn:
1879+
async with self.connect(
1880+
compression_algs='zlib@openssh.com') as conn:
18791881
stdin, _, _ = await conn.open_session()
18801882
self.assertEqual(stdin.channel.get_send_pktsize(), 32758)
18811883

tests/test_connection.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,24 @@ def send_newkeys(self, k, h):
12601260
with self.assertRaises(asyncssh.ProtocolError):
12611261
await self.connect()
12621262

1263+
@asynctest
1264+
async def test_client_decompression_failure(self):
1265+
"""Test client decompression failure"""
1266+
1267+
def send_packet(self, pkttype, *args, **kwargs):
1268+
"""Send an SSH packet"""
1269+
1270+
asyncssh.connection.SSHConnection.send_packet(
1271+
self, pkttype, *args, **kwargs)
1272+
1273+
if pkttype == MSG_USERAUTH_SUCCESS:
1274+
self._compressor = None
1275+
self.send_debug('Test')
1276+
1277+
with patch('asyncssh.connection.SSHServerConnection.send_packet',
1278+
send_packet):
1279+
await self.connect(compression_algs=['zlib@openssh.com'])
1280+
12631281
@asynctest
12641282
async def test_packet_decode_error(self):
12651283
"""Test SSH packet decode error"""

0 commit comments

Comments
 (0)