From e58d2f1e1dc4b4e93eb5cb076aefbe343b14648a Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 22 Jul 2024 18:26:32 +0200 Subject: [PATCH 1/2] Support for new client side extension --- .../DefaultClientKexExtensionHandler.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/DefaultClientKexExtensionHandler.java b/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/DefaultClientKexExtensionHandler.java index f70128e40..a0924c559 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/DefaultClientKexExtensionHandler.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/DefaultClientKexExtensionHandler.java @@ -23,9 +23,12 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.TreeSet; +import java.util.function.BiConsumer; import org.apache.sshd.common.AttributeRepository.AttributeKey; import org.apache.sshd.common.NamedFactory; @@ -33,6 +36,7 @@ import org.apache.sshd.common.kex.extension.parser.ServerSignatureAlgorithms; import org.apache.sshd.common.session.Session; import org.apache.sshd.common.signature.Signature; +import org.apache.sshd.common.util.buffer.Buffer; import org.apache.sshd.common.util.logging.AbstractLoggingBean; /** @@ -133,4 +137,33 @@ protected void handleServerSignatureAlgorithms(Session session, Collection extensions = new LinkedHashMap<>(); + collectExtensions(session, phase, extensions::put); + if (!extensions.isEmpty()) { + Buffer buffer = session.createBuffer(KexExtensions.SSH_MSG_EXT_INFO); + KexExtensions.putExtensions(extensions.entrySet(), buffer); + if (log.isDebugEnabled()) { + log.debug("sendKexExtensions({})[{}]: sending SSH_MSG_EXT_INFO with {} info records", session, phase, + extensions.size()); + } + session.writePacket(buffer); + } + } + + /** + * Collects extension info records, handing them off to the given {@code marshaller} for writing into an + * {@link KexExtensions#SSH_MSG_EXT_INFO} message. + *

+ * This default implementation does not marshal any extension. + *

+ * + * @param session {@link Session} to send the KEX extension information for + * @param phase {@link KexPhase} of the SSH protocol + * @param marshaller {@link BiConsumer} writing the extensions into an SSH message + */ + public void collectExtensions(Session session, KexPhase phase, BiConsumer marshaller) { + } } From 5435c4cceba09f28f79614c15f7172700547cdce Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 25 Jul 2024 12:34:58 +0200 Subject: [PATCH 2/2] [GH-539] Implement no-flow-control extension (fixes #539) --- CHANGES.md | 1 + .../sshd/cli/client/ScpCommandMain.java | 25 +- .../sshd/cli/client/SftpCommandMain.java | 11 +- .../sshd/cli/client/SshClientCliSupport.java | 13 +- .../kex/extension/parser/NoFlowControl.java | 3 + .../sshd/common/channel/LocalWindow.java | 5 + .../sshd/common/channel/RemoteWindow.java | 5 + .../apache/sshd/common/channel/Window.java | 5 + .../DefaultClientKexExtensionHandler.java | 22 +- .../DefaultServerKexExtensionHandler.java | 32 +- .../apache/sshd/common/session/Session.java | 6 + .../helpers/AbstractConnectionService.java | 7 + .../session/helpers/AbstractSession.java | 18 + .../helpers/KeyExchangeMessageHandler.java | 3 +- .../sshd/core/CoreModuleProperties.java | 8 + .../org/apache/sshd/NoFlowControlTest.java | 352 ++++++++++++++++++ 16 files changed, 503 insertions(+), 13 deletions(-) create mode 100644 sshd-core/src/test/java/org/apache/sshd/NoFlowControlTest.java diff --git a/CHANGES.md b/CHANGES.md index 09d2d4c15..6b7239fdc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -43,6 +43,7 @@ ## New Features * New utility methods `SftpClient.put(Path localFile, String remoteFileName)` and `SftpClient.put(InputStream in, String remoteFileName)` facilitate SFTP file uploading. +* [GH-539](https://github.com/apache/mina-sshd/issues/539) Implement no-flow-control extension ## Potential compatibility issues diff --git a/sshd-cli/src/main/java/org/apache/sshd/cli/client/ScpCommandMain.java b/sshd-cli/src/main/java/org/apache/sshd/cli/client/ScpCommandMain.java index 72102c8cf..977b7ce8f 100644 --- a/sshd-cli/src/main/java/org/apache/sshd/cli/client/ScpCommandMain.java +++ b/sshd-cli/src/main/java/org/apache/sshd/cli/client/ScpCommandMain.java @@ -32,6 +32,7 @@ import java.util.Collection; import java.util.Collections; import java.util.EnumSet; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Set; @@ -42,12 +43,14 @@ import org.apache.sshd.client.auth.AuthenticationIdentitiesProvider; import org.apache.sshd.client.config.hosts.HostConfigEntry; import org.apache.sshd.client.session.ClientSession; +import org.apache.sshd.common.PropertyResolver; import org.apache.sshd.common.SshConstants; import org.apache.sshd.common.session.Session; import org.apache.sshd.common.util.GenericUtils; import org.apache.sshd.common.util.ReflectionUtils; import org.apache.sshd.common.util.io.input.NoCloseInputStream; import org.apache.sshd.common.util.threads.ThreadUtils; +import org.apache.sshd.core.CoreModuleProperties; import org.apache.sshd.scp.client.ScpClient; import org.apache.sshd.scp.client.ScpClient.Option; import org.apache.sshd.scp.client.ScpClientCreator; @@ -61,6 +64,8 @@ import org.apache.sshd.scp.common.helpers.ScpTimestampCommandDetails; import org.slf4j.Logger; +import static org.apache.sshd.common.PropertyResolverUtils.toPropertyResolver; + /** * @see SCP(1) - manual page * @author Apache MINA SSHD Project @@ -151,7 +156,7 @@ public static String[] normalizeCommandArguments(PrintStream stdout, PrintStream return null; } - return effective.toArray(new String[effective.size()]); + return effective.toArray(new String[0]); } /* -------------------------------------------------------------------------------- */ @@ -248,11 +253,11 @@ public static void showUsageMessage(PrintStream stderr) { public static void xferLocalToRemote( BufferedReader stdin, PrintStream stdout, PrintStream stderr, String[] args, ScpLocation source, ScpLocation target, Collection