Skip to content

Commit c3dc869

Browse files
committed
Fix regression related to rekeying
This commit corrects a mistake in a change which went into 2.14.1 that could cause rekeying to fail in some cases where there was activity on the connection. Thanks go to GitHub user eyalgolan1337 for reporting this problem, helping to narrow down the source of it, and testing the fix!
1 parent 5159542 commit c3dc869

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

asyncssh/connection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,9 @@ def send_packet(self, pkttype: int, *args: bytes,
16341634
self._send_kexinit()
16351635
self._kexinit_sent = True
16361636

1637-
if ((pkttype == MSG_USERAUTH_BANNER and
1637+
if (((pkttype in {MSG_SERVICE_REQUEST, MSG_SERVICE_ACCEPT} or
1638+
pkttype > MSG_KEX_LAST) and not self._kex_complete) or
1639+
(pkttype == MSG_USERAUTH_BANNER and
16381640
not (self._auth_in_progress or self._auth_complete)) or
16391641
(pkttype > MSG_USERAUTH_LAST and not self._auth_complete)):
16401642
self._deferred_packets.append((pkttype, args))

tests/test_connection.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,8 @@ async def test_service_request_before_kex_complete(self):
11361136
def send_newkeys(self, k, h):
11371137
"""Finish a key exchange and send a new keys message"""
11381138

1139+
self._kex_complete = True
1140+
11391141
self.send_packet(MSG_SERVICE_REQUEST, String('ssh-userauth'))
11401142

11411143
asyncssh.connection.SSHConnection.send_newkeys(self, k, h)
@@ -1152,6 +1154,8 @@ async def test_service_accept_before_kex_complete(self):
11521154
def send_newkeys(self, k, h):
11531155
"""Finish a key exchange and send a new keys message"""
11541156

1157+
self._kex_complete = True
1158+
11551159
self.send_packet(MSG_SERVICE_ACCEPT, String('ssh-userauth'))
11561160

11571161
asyncssh.connection.SSHConnection.send_newkeys(self, k, h)
@@ -1438,6 +1442,8 @@ async def test_userauth_before_kex_complete(self):
14381442
def send_newkeys(self, k, h):
14391443
"""Finish a key exchange and send a new keys message"""
14401444

1445+
self._kex_complete = True
1446+
14411447
self.send_packet(MSG_USERAUTH_REQUEST, String('guest'),
14421448
String('ssh-connection'), String('none'))
14431449

0 commit comments

Comments
 (0)