From 8c2c04e7aa7f83444ae55e8937052f2340f92b6d Mon Sep 17 00:00:00 2001 From: Raul Santelices Date: Thu, 9 Nov 2023 17:12:43 -0500 Subject: [PATCH 1/2] Fix for issue #910: Bad packet received by server when hearbeat is enabled --- src/main/java/net/schmizz/sshj/SSHClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/schmizz/sshj/SSHClient.java b/src/main/java/net/schmizz/sshj/SSHClient.java index dd0e3817..78b91c5f 100644 --- a/src/main/java/net/schmizz/sshj/SSHClient.java +++ b/src/main/java/net/schmizz/sshj/SSHClient.java @@ -804,12 +804,12 @@ protected void onConnect() throws IOException { super.onConnect(); trans.init(getRemoteHostname(), getRemotePort(), getInputStream(), getOutputStream()); + doKex(); final KeepAlive keepAliveThread = conn.getKeepAlive(); if (keepAliveThread.isEnabled()) { ThreadNameProvider.setThreadName(conn.getKeepAlive(), trans); keepAliveThread.start(); } - doKex(); } /** From 9343b80b545c4befb0d20aa02b446be8608dec39 Mon Sep 17 00:00:00 2001 From: Raul Santelices Date: Fri, 10 Nov 2023 13:26:16 -0500 Subject: [PATCH 2/2] Address re-keying case too --- src/main/java/net/schmizz/sshj/SSHClient.java | 2 +- src/main/java/net/schmizz/sshj/transport/TransportImpl.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/schmizz/sshj/SSHClient.java b/src/main/java/net/schmizz/sshj/SSHClient.java index 78b91c5f..dd0e3817 100644 --- a/src/main/java/net/schmizz/sshj/SSHClient.java +++ b/src/main/java/net/schmizz/sshj/SSHClient.java @@ -804,12 +804,12 @@ protected void onConnect() throws IOException { super.onConnect(); trans.init(getRemoteHostname(), getRemotePort(), getInputStream(), getOutputStream()); - doKex(); final KeepAlive keepAliveThread = conn.getKeepAlive(); if (keepAliveThread.isEnabled()) { ThreadNameProvider.setThreadName(conn.getKeepAlive(), trans); keepAliveThread.start(); } + doKex(); } /** diff --git a/src/main/java/net/schmizz/sshj/transport/TransportImpl.java b/src/main/java/net/schmizz/sshj/transport/TransportImpl.java index 58107c5b..69632fc1 100644 --- a/src/main/java/net/schmizz/sshj/transport/TransportImpl.java +++ b/src/main/java/net/schmizz/sshj/transport/TransportImpl.java @@ -420,9 +420,9 @@ public long write(SSHPacket payload) try { if (kexer.isKexOngoing()) { - // Only transport layer packets (1 to 49) allowed except SERVICE_REQUEST + // Only transport layer packets (1 to 49) allowed except SERVICE_REQUEST and IGNORE final Message m = Message.fromByte(payload.array()[payload.rpos()]); - if (!m.in(1, 49) || m == Message.SERVICE_REQUEST) { + if (!m.in(1, 49) || m == Message.SERVICE_REQUEST || m == Message.IGNORE) { assert m != Message.KEXINIT; kexer.waitForDone(); }