You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2022/02/08 16:37:35 UTC

[mina-sshd] branch master updated (df0febe -> 82c95e1)

This is an automated email from the ASF dual-hosted git repository.

lgoldstein pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git.


    from df0febe  Remove direct sftp URI instantiation example
     new a9f87e9  [SSHD-1244] Fixed channel window adjustment handling of large UINT32 values
     new 070c11d  [SSHD-1244] Re-defined channel identifiers as long rather than int to align with protocol UINT32 definition
     new 7f1a4be  [SSHD-1244] Renamed Channel#getId to Channel#getChannelId and moved it to its own interface
     new 410b0e7  Updated some SFTP related links in main README file
     new 82c95e1  Added support for quoted arguments in SftpCommandMain

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 CHANGES.md                                         | 29 ++++++++-
 README.md                                          | 32 +++++++---
 pom.xml                                            |  1 +
 .../main/java/org/apache/sshd/cli/CliSupport.java  | 72 +++++++++++++++++++++
 .../apache/sshd/cli/client/SftpCommandMain.java    | 43 ++++---------
 .../CliSupportSplitCommandLineArgumentsTest.java   | 73 ++++++++++------------
 .../common/config/keys/OpenSshCertificate.java     | 14 +++--
 .../sshd/common/kex/extension/KexExtensions.java   |  4 +-
 .../kex/extension/parser/DelayCompression.java     |  2 +-
 .../apache/sshd/common/session/SessionContext.java | 11 ++++
 .../sshd/common/session/SessionContextHolder.java  |  1 +
 .../signature/AbstractSecurityKeySignature.java    |  2 +-
 .../org/apache/sshd/common/util/buffer/Buffer.java | 30 ++++++---
 .../sshd/common/util/buffer/BufferUtils.java       |  8 +--
 .../sshd/common/util/buffer/ByteArrayBuffer.java   |  2 +-
 ...elIdTrackingUnknownChannelReferenceHandler.java | 12 ++--
 .../apache/sshd/agent/SshAgentKeyConstraint.java   |  2 +-
 .../sshd/agent/common/AbstractAgentClient.java     | 10 +--
 .../sshd/agent/common/AbstractAgentProxy.java      |  4 +-
 .../org/apache/sshd/agent/unix/AgentClient.java    |  2 +-
 .../auth/keyboard/UserAuthKeyboardInteractive.java |  2 +-
 .../sshd/client/channel/AbstractClientChannel.java | 12 ++--
 .../sshd/client/channel/ChannelDirectTcpip.java    | 10 +--
 .../apache/sshd/client/channel/ChannelExec.java    |  2 +-
 .../apache/sshd/client/channel/ChannelShell.java   |  2 +-
 .../sshd/client/channel/ChannelSubsystem.java      |  2 +-
 .../client/channel/PtyCapableChannelSession.java   |  4 +-
 .../sshd/client/session/AbstractClientSession.java |  8 +--
 .../sshd/common/channel/AbstractChannel.java       | 30 ++++-----
 .../common/channel/BufferedIoOutputStream.java     | 15 +++--
 .../org/apache/sshd/common/channel/Channel.java    | 28 ++++-----
 .../common/channel/ChannelAsyncOutputStream.java   |  9 ++-
 .../{ChannelHolder.java => ChannelIdentifier.java} |  6 +-
 .../sshd/common/channel/ChannelListener.java       |  2 +-
 .../sshd/common/channel/ChannelOutputStream.java   | 12 ++--
 .../org/apache/sshd/common/channel/Window.java     |  8 +--
 .../SshChannelBufferedOutputException.java         |  6 +-
 .../exception/SshChannelClosedException.java       |  6 +-
 .../channel/exception/SshChannelException.java     | 15 +++--
 .../exception/SshChannelNotFoundException.java     |  6 +-
 .../channel/exception/SshChannelOpenException.java |  4 +-
 .../sshd/common/forward/DefaultForwarder.java      |  4 +-
 .../sshd/common/forward/TcpipClientChannel.java    | 10 +--
 .../DefaultServerKexExtensionHandler.java          |  2 +
 .../sshd/common/session/ConnectionService.java     |  4 +-
 .../session/UnknownChannelReferenceHandler.java    |  2 +-
 .../session/helpers/AbstractConnectionService.java | 39 ++++++------
 .../common/session/helpers/AbstractSession.java    |  6 +-
 .../DefaultUnknownChannelReferenceHandler.java     |  6 +-
 .../sshd/common/session/helpers/SessionHelper.java |  2 +-
 .../org/apache/sshd/core/CoreModuleProperties.java | 10 ++-
 .../server/auth/hostbased/UserAuthHostBased.java   |  2 +-
 .../server/auth/keyboard/InteractiveChallenge.java |  2 +-
 .../sshd/server/channel/AbstractServerChannel.java |  6 +-
 .../sshd/server/forward/TcpipServerChannel.java    |  6 +-
 .../server/global/CancelTcpipForwardHandler.java   |  2 +-
 .../sshd/server/global/TcpipForwardHandler.java    |  2 +-
 .../sshd/server/x11/ChannelForwardedX11.java       |  8 +--
 .../java/org/apache/sshd/client/ClientTest.java    | 12 ++--
 .../apache/sshd/common/channel/WindowInitTest.java |  4 +-
 .../org/apache/sshd/common/channel/WindowTest.java |  4 +-
 .../sshd/common/channel/WindowTimeoutTest.java     |  4 +-
 .../session/helpers/AbstractSessionTest.java       |  6 +-
 .../deprecated/UserAuthKeyboardInteractive.java    |  2 +-
 .../sshd/server/channel/ChannelSessionTest.java    | 27 +++++++-
 .../sshd/util/test/AsyncEchoShellFactory.java      |  2 +-
 .../org/apache/sshd/util/test/BogusChannel.java    |  4 +-
 .../helpers/AbstractCheckFileExtension.java        |  2 +-
 .../org/apache/sshd/sftp/client/fs/SftpPath.java   |  1 +
 .../sshd/sftp/client/impl/AbstractSftpClient.java  |  5 +-
 .../sshd/sftp/client/impl/DefaultSftpClient.java   | 12 ++--
 .../sftp/client/impl/SftpInputStreamAsync.java     |  3 +-
 .../sftp/client/impl/SftpOutputStreamAsync.java    |  2 +-
 .../apache/sshd/sftp/client/impl/SftpPathImpl.java | 10 +--
 .../org/apache/sshd/sftp/common/SftpHelper.java    |  6 +-
 .../extensions/SpaceAvailableExtensionInfo.java    |  2 +-
 .../sftp/common/extensions/Supported2Parser.java   | 10 +--
 .../sftp/common/extensions/SupportedParser.java    | 12 ++--
 .../sftp/server/AbstractSftpSubsystemHelper.java   | 27 ++++----
 .../org/apache/sshd/sftp/server/SftpSubsystem.java | 10 +--
 .../org/apache/sshd/sftp/client/ClientTest.java    | 10 +--
 .../java/org/apache/sshd/sftp/client/SftpTest.java |  4 +-
 .../client/impl/SftpRemotePathChannelTest.java     |  2 +-
 83 files changed, 503 insertions(+), 336 deletions(-)
 copy sshd-common/src/test/java/org/apache/sshd/common/PropertyResolverParseBooleanTest.java => sshd-cli/src/test/java/org/apache/sshd/cli/CliSupportSplitCommandLineArgumentsTest.java (51%)
 copy sshd-core/src/main/java/org/apache/sshd/common/channel/{ChannelHolder.java => ChannelIdentifier.java} (89%)

[mina-sshd] 02/05: [SSHD-1244] Re-defined channel identifiers as long rather than int to align with protocol UINT32 definition

Posted by lg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lgoldstein pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git

commit 070c11ddc2fef5ad50a01709ca27598598cade85
Author: Lyor Goldstein <lg...@apache.org>
AuthorDate: Fri Feb 4 12:56:53 2022 +0200

    [SSHD-1244] Re-defined channel identifiers as long rather than int to align with protocol UINT32 definition
---
 CHANGES.md                                         | 27 ++++++++++++++-
 .../common/config/keys/OpenSshCertificate.java     | 14 +++++---
 .../sshd/common/kex/extension/KexExtensions.java   |  2 ++
 .../apache/sshd/common/session/SessionContext.java | 11 ++++++
 .../org/apache/sshd/common/util/buffer/Buffer.java | 21 +++++++-----
 .../sshd/common/util/buffer/BufferUtils.java       |  4 +--
 ...elIdTrackingUnknownChannelReferenceHandler.java | 12 +++----
 .../sshd/client/channel/AbstractClientChannel.java | 10 +++---
 .../sshd/client/channel/ChannelDirectTcpip.java    | 10 +++---
 .../apache/sshd/client/channel/ChannelExec.java    |  2 +-
 .../apache/sshd/client/channel/ChannelShell.java   |  2 +-
 .../sshd/client/channel/ChannelSubsystem.java      |  2 +-
 .../client/channel/PtyCapableChannelSession.java   |  2 +-
 .../sshd/client/session/AbstractClientSession.java |  8 ++---
 .../sshd/common/channel/AbstractChannel.java       | 24 ++++++-------
 .../common/channel/BufferedIoOutputStream.java     | 12 ++++---
 .../org/apache/sshd/common/channel/Channel.java    | 26 +++++++--------
 .../common/channel/ChannelAsyncOutputStream.java   |  7 ++--
 .../sshd/common/channel/ChannelListener.java       |  2 +-
 .../sshd/common/channel/ChannelOutputStream.java   |  6 ++--
 .../SshChannelBufferedOutputException.java         |  6 ++--
 .../exception/SshChannelClosedException.java       |  6 ++--
 .../channel/exception/SshChannelException.java     | 12 +++----
 .../exception/SshChannelNotFoundException.java     |  6 ++--
 .../channel/exception/SshChannelOpenException.java |  4 +--
 .../sshd/common/forward/TcpipClientChannel.java    | 10 +++---
 .../DefaultServerKexExtensionHandler.java          |  2 ++
 .../sshd/common/session/ConnectionService.java     |  4 +--
 .../session/UnknownChannelReferenceHandler.java    |  2 +-
 .../session/helpers/AbstractConnectionService.java | 39 +++++++++++-----------
 .../DefaultUnknownChannelReferenceHandler.java     |  6 ++--
 .../sshd/common/session/helpers/SessionHelper.java |  2 +-
 .../sshd/server/channel/AbstractServerChannel.java |  6 ++--
 .../sshd/server/forward/TcpipServerChannel.java    |  2 +-
 .../sshd/server/x11/ChannelForwardedX11.java       |  8 ++---
 .../java/org/apache/sshd/client/ClientTest.java    | 10 +++---
 .../apache/sshd/common/channel/WindowInitTest.java |  4 +--
 .../org/apache/sshd/common/channel/WindowTest.java |  2 +-
 .../sshd/common/channel/WindowTimeoutTest.java     |  4 +--
 .../sshd/util/test/AsyncEchoShellFactory.java      |  2 +-
 .../org/apache/sshd/util/test/BogusChannel.java    |  4 +--
 .../org/apache/sshd/sftp/client/fs/SftpPath.java   |  1 +
 .../sshd/sftp/client/impl/AbstractSftpClient.java  |  1 +
 .../sshd/sftp/client/impl/DefaultSftpClient.java   |  2 +-
 .../sftp/common/extensions/Supported2Parser.java   | 10 +++---
 .../sftp/common/extensions/SupportedParser.java    |  9 ++---
 .../sftp/server/AbstractSftpSubsystemHelper.java   |  5 +--
 .../org/apache/sshd/sftp/server/SftpSubsystem.java |  6 ++--
 .../org/apache/sshd/sftp/client/ClientTest.java    |  8 ++---
 .../java/org/apache/sshd/sftp/client/SftpTest.java |  4 +--
 50 files changed, 227 insertions(+), 164 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index 9063114..08c9d71 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -20,7 +20,9 @@
 
 ## Potential compatibility issues
 
-* A **new** SFTP configuration property has been introduced that limits the maximum amount of data that can be sent in a single *SSH_FXP_WRITE* packet - default=256KB
+Changes that may affect existing code
+
+### A **new** SFTP configuration property has been introduced that limits the maximum amount of data that can be sent in a single *SSH_FXP_WRITE* packet - default=256KB
 
 ```java
     /**
@@ -34,6 +36,27 @@
 This might cause SFTP write failures for clients that might have sent larger buffers and they have been accepted so far. If this happens, simply increase
 this value (though the choice of 256KB should be compatible with the vast majority of clients).
 
+### SSH channel identifiers have been changed to use *long* instead of *int* in order to align them with the standard that required them to be *UINT32* values.
+
+The relevant API(s) have been modified accordingly - which may cause a few incompatibility issues with code that extends/implements existing `Channel` classes
+and interfaces.
+
+### *long* used instead of *int* in most encoded/decoded packets that are specified as being *UINT32*
+
+There are several exceptions to this rule:
+
+* The SFTP packet *id* field - an "opaque" value anyway, not used for allocation or indexing anyway
+
+* Various flags and mask field - there is no reason to encapsulate them into a *long* value since they do not represent a cardinal number of 32 bits
+
+* Various status code fields - ditto.
+
+* Cases where the value serves as argument for allocation of other data structures based on its value - e.g., arrays, lists. This was
+done for *convenience* reasons since Java does not support unsigned array/list sizes. In such cases, special validation code was applied
+to make sure the requested value does not exceed `Integer#MAX_VALUE` (sometimes even less) in order to protected the code from malicious
+or malformed packets. It is important to bear in mind that in the vast majority of the cases we do not want to be able to allocate arrays
+or lists having billions of elements as it would almost definitely cause out-of-memory issues.
+
 ## Minor code helpers
 
 ## Behavioral changes and enhancements
@@ -41,6 +64,8 @@ this value (though the choice of 256KB should be compatible with the vast majori
 * [SSHD-1231](https://issues.apache.org/jira/browse/SSHD-1231) Public key authentication: wrong signature algorithm used (ed25519 key with ssh-rsa signature)
 * [SSHD-1233](https://issues.apache.org/jira/browse/SSHD-1233) Added support for "limits@openssh.com" SFTP extension
 * [SSHD-1244](https://issues.apache.org/jira/browse/SSHD-1244) Fixed channel window adjustment handling of large UINT32 values
+* [SSHD-1244](https://issues.apache.org/jira/browse/SSHD-1244) Re-defined channel identifiers as `long` rather than `int` to align with protocol UINT32 definition
+
 
 
 
diff --git a/sshd-common/src/main/java/org/apache/sshd/common/config/keys/OpenSshCertificate.java b/sshd-common/src/main/java/org/apache/sshd/common/config/keys/OpenSshCertificate.java
index 525c4f6..c794cf7 100644
--- a/sshd-common/src/main/java/org/apache/sshd/common/config/keys/OpenSshCertificate.java
+++ b/sshd-common/src/main/java/org/apache/sshd/common/config/keys/OpenSshCertificate.java
@@ -20,7 +20,9 @@ package org.apache.sshd.common.config.keys;
 
 import java.security.PrivateKey;
 import java.security.PublicKey;
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 import java.util.concurrent.TimeUnit;
@@ -37,21 +39,25 @@ public interface OpenSshCertificate extends PublicKey, PrivateKey {
 
     /**
      * {@link OpenSshCertificate}s have a type indicating whether the certificate if for a host key (certifying a host
-     * identity) or for a user key (certifying a user identity).
+     * identity) or for a user key (certifying a user identity). <B>Note:</B> values order is significant
      */
     enum Type {
-
         /** User key certificate. */
         USER,
         /** Host key certificate. */
-        HOST;
+        HOST,
+        ;
+
+        public static final List<Type> VALUES = Collections.unmodifiableList(Arrays.asList(values()));
 
         public int getCode() {
             return ordinal() + 1;
         }
 
         public static Type fromCode(int code) {
-            return Type.values()[code - 1];
+            ValidateUtils.checkTrue((code > 0) && (code <= VALUES.size()),
+                    "Invalid type code: %d", code);
+            return VALUES.get(code - 1);
         }
     }
 
diff --git a/sshd-common/src/main/java/org/apache/sshd/common/kex/extension/KexExtensions.java b/sshd-common/src/main/java/org/apache/sshd/common/kex/extension/KexExtensions.java
index af82982..9fac45c 100644
--- a/sshd-common/src/main/java/org/apache/sshd/common/kex/extension/KexExtensions.java
+++ b/sshd-common/src/main/java/org/apache/sshd/common/kex/extension/KexExtensions.java
@@ -143,6 +143,8 @@ public final class KexExtensions {
      */
     public static List<Map.Entry<String, ?>> parseExtensions(Buffer buffer) throws IOException {
         int count = buffer.getInt();
+        // Protect agains malicious packets
+        ValidateUtils.checkTrue(count >= 0, "Invalid extensions count: %d", count);
         if (count == 0) {
             return Collections.emptyList();
         }
diff --git a/sshd-common/src/main/java/org/apache/sshd/common/session/SessionContext.java b/sshd-common/src/main/java/org/apache/sshd/common/session/SessionContext.java
index 622c5db..ad5d2c8 100644
--- a/sshd-common/src/main/java/org/apache/sshd/common/session/SessionContext.java
+++ b/sshd-common/src/main/java/org/apache/sshd/common/session/SessionContext.java
@@ -23,6 +23,7 @@ import java.util.Map;
 
 import org.apache.sshd.common.AttributeStore;
 import org.apache.sshd.common.Closeable;
+import org.apache.sshd.common.SshConstants;
 import org.apache.sshd.common.auth.UsernameHolder;
 import org.apache.sshd.common.cipher.BuiltinCiphers;
 import org.apache.sshd.common.cipher.CipherInformation;
@@ -31,6 +32,7 @@ import org.apache.sshd.common.kex.KexProposalOption;
 import org.apache.sshd.common.kex.KexState;
 import org.apache.sshd.common.mac.MacInformation;
 import org.apache.sshd.common.util.GenericUtils;
+import org.apache.sshd.common.util.ValidateUtils;
 import org.apache.sshd.common.util.net.ConnectionEndpointsIndicator;
 
 /**
@@ -207,4 +209,13 @@ public interface SessionContext
 
         return true;
     }
+
+    static boolean isValidSessionPayloadSize(long value) {
+        return (value >= 0L) && (value < (Integer.MAX_VALUE - SshConstants.SSH_PACKET_HEADER_LEN - 8 /* some padding */));
+    }
+
+    static long validateSessionPayloadSize(long value, String format) {
+        ValidateUtils.checkTrue(isValidSessionPayloadSize(value), format, value);
+        return value;
+    }
 }
diff --git a/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java b/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java
index c7c9df5..7a2fa6d 100644
--- a/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java
+++ b/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java
@@ -478,6 +478,11 @@ public abstract class Buffer implements Readable {
     }
 
     public byte[] getBytes() {
+        /*
+         * NOTE: technically we should support UINT32 but
+         * we cannot support them since an array of bytes
+         * can be allocated only with and integer value
+         */
         int reqLen = getInt();
         int len = ensureAvailable(reqLen);
         byte[] b = new byte[len];
@@ -698,11 +703,6 @@ public abstract class Buffer implements Readable {
         putRawBytes(workBuf, 0, Short.BYTES);
     }
 
-    /**
-     * Writes 32 bits
-     *
-     * @param i The 32-bit value
-     */
     public void putInt(long i) {
         BufferUtils.validateInt32Value(i, "Invalid INT32 value: %d");
         ensureCapacity(Integer.BYTES);
@@ -710,6 +710,11 @@ public abstract class Buffer implements Readable {
         putRawBytes(workBuf, 0, Integer.BYTES);
     }
 
+    /**
+     * Writes 32 bits
+     *
+     * @param i The 32-bit value
+     */
     public void putUInt(long i) {
         BufferUtils.validateUint32Value(i, "Invalid UINT32 value: %d");
         ensureCapacity(Integer.BYTES);
@@ -943,7 +948,7 @@ public abstract class Buffer implements Readable {
             putUInt(mpInt.length + 1 /* padding */);
             putByte((byte) 0);
         } else {
-            putInt(mpInt.length);
+            putUInt(mpInt.length);
         }
         putRawBytes(mpInt);
     }
@@ -961,7 +966,7 @@ public abstract class Buffer implements Readable {
         putRawPublicKey(key);
         int ow2 = wpos();
         wpos(ow);
-        putInt(ow2 - ow1);
+        putUInt(ow2 - ow1);
         wpos(ow2);
     }
 
@@ -1007,7 +1012,7 @@ public abstract class Buffer implements Readable {
             putBytes(cert.getNonce());
             putRawPublicKeyBytes(cert.getCertPubKey());
             putLong(cert.getSerial());
-            putInt(cert.getType().getCode());
+            putUInt(cert.getType().getCode());
             putString(cert.getId());
 
             ByteArrayBuffer tmpBuffer = new ByteArrayBuffer();
diff --git a/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java b/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java
index beaf150..77b201a 100644
--- a/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java
+++ b/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java
@@ -656,9 +656,9 @@ public final class BufferUtils {
      * @param buffer     The {@link Buffer}
      * @param lenPos     The offset in the buffer where the length placeholder is to be update - <B>Note:</B> assumption
      *                   is that the encoded data starts <U>immediately</U> after the placeholder
-     * @param dataLength The length to update
+     * @param dataLength The length to update - a UINT32 value as a {@code long}
      */
-    public static void updateLengthPlaceholder(Buffer buffer, int lenPos, int dataLength) {
+    public static void updateLengthPlaceholder(Buffer buffer, int lenPos, long dataLength) {
         int curPos = buffer.wpos();
         buffer.wpos(lenPos);
         buffer.putUInt(dataLength);
diff --git a/sshd-contrib/src/main/java/org/apache/sshd/contrib/common/session/helpers/ChannelIdTrackingUnknownChannelReferenceHandler.java b/sshd-contrib/src/main/java/org/apache/sshd/contrib/common/session/helpers/ChannelIdTrackingUnknownChannelReferenceHandler.java
index e791d1c..7d282b9 100644
--- a/sshd-contrib/src/main/java/org/apache/sshd/contrib/common/session/helpers/ChannelIdTrackingUnknownChannelReferenceHandler.java
+++ b/sshd-contrib/src/main/java/org/apache/sshd/contrib/common/session/helpers/ChannelIdTrackingUnknownChannelReferenceHandler.java
@@ -41,7 +41,7 @@ import org.apache.sshd.common.util.buffer.Buffer;
 public class ChannelIdTrackingUnknownChannelReferenceHandler
         extends DefaultUnknownChannelReferenceHandler
         implements ChannelListener {
-    public static final AttributeKey<Integer> LAST_CHANNEL_ID_KEY = new AttributeKey<>();
+    public static final AttributeKey<Long> LAST_CHANNEL_ID_KEY = new AttributeKey<>();
 
     public static final ChannelIdTrackingUnknownChannelReferenceHandler TRACKER
             = new ChannelIdTrackingUnknownChannelReferenceHandler();
@@ -52,9 +52,9 @@ public class ChannelIdTrackingUnknownChannelReferenceHandler
 
     @Override
     public void channelInitialized(Channel channel) {
-        int channelId = channel.getId();
+        long channelId = channel.getId();
         Session session = channel.getSession();
-        Integer lastTracked = session.setAttribute(LAST_CHANNEL_ID_KEY, channelId);
+        Long lastTracked = session.setAttribute(LAST_CHANNEL_ID_KEY, channelId);
         if (log.isDebugEnabled()) {
             log.debug("channelInitialized({}) updated last tracked channel ID {} => {}",
                     channel, lastTracked, channelId);
@@ -63,11 +63,11 @@ public class ChannelIdTrackingUnknownChannelReferenceHandler
 
     @Override
     public Channel handleUnknownChannelCommand(
-            ConnectionService service, byte cmd, int channelId, Buffer buffer)
+            ConnectionService service, byte cmd, long channelId, Buffer buffer)
             throws IOException {
         Session session = service.getSession();
-        Integer lastTracked = session.getAttribute(LAST_CHANNEL_ID_KEY);
-        if ((lastTracked != null) && (channelId <= lastTracked.intValue())) {
+        Long lastTracked = session.getAttribute(LAST_CHANNEL_ID_KEY);
+        if ((lastTracked != null) && (channelId <= lastTracked.longValue())) {
             // Use TRACE level in order to avoid messages flooding
             if (log.isTraceEnabled()) {
                 log.trace("handleUnknownChannelCommand({}) apply default handling for {} on channel={} (lastTracked={})",
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
index d960388..4124408 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
@@ -329,21 +329,21 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
         Window wLocal = getLocalWindow();
         Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN, type.length() + Integer.SIZE);
         buffer.putString(type);
-        buffer.putInt(getId());
-        buffer.putInt(wLocal.getSize());
-        buffer.putInt(wLocal.getPacketSize());
+        buffer.putUInt(getId());
+        buffer.putUInt(wLocal.getSize());
+        buffer.putUInt(wLocal.getPacketSize());
         writePacket(buffer);
         return openFuture;
     }
 
     @Override
-    public OpenFuture open(int recipient, long rwSize, long packetSize, Buffer buffer) {
+    public OpenFuture open(long recipient, long rwSize, long packetSize, Buffer buffer) {
         throw new UnsupportedOperationException(
                 "open(" + recipient + "," + rwSize + "," + packetSize + ") N/A");
     }
 
     @Override
-    public void handleOpenSuccess(int recipient, long rwSize, long packetSize, Buffer buffer) {
+    public void handleOpenSuccess(long recipient, long rwSize, long packetSize, Buffer buffer) {
         setRecipient(recipient);
 
         Session session = getSession();
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java
index 59c7b74..b8b2ab8 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java
@@ -84,13 +84,13 @@ public class ChannelDirectTcpip extends AbstractClientChannel {
         Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN,
                 type.length() + remoteName.length() + localName.length() + Long.SIZE);
         buffer.putString(type);
-        buffer.putInt(getId());
-        buffer.putInt(wLocal.getSize());
-        buffer.putInt(wLocal.getPacketSize());
+        buffer.putUInt(getId());
+        buffer.putUInt(wLocal.getSize());
+        buffer.putUInt(wLocal.getPacketSize());
         buffer.putString(remoteName);
-        buffer.putInt(remote.getPort());
+        buffer.putUInt(remote.getPort());
         buffer.putString(localName);
-        buffer.putInt(local.getPort());
+        buffer.putUInt(local.getPort());
         writePacket(buffer);
         return openFuture;
     }
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelExec.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelExec.java
index 498ea29..f0608af 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelExec.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelExec.java
@@ -55,7 +55,7 @@ public class ChannelExec extends PtyCapableChannelSession {
         Session session = getSession();
         boolean wantReply = CoreModuleProperties.REQUEST_EXEC_REPLY.getRequired(this);
         Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_REQUEST, command.length() + Integer.SIZE);
-        buffer.putInt(getRecipient());
+        buffer.putUInt(getRecipient());
         buffer.putString(Channel.CHANNEL_EXEC);
         buffer.putBoolean(wantReply);
         buffer.putString(command);
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelShell.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelShell.java
index 2fd7c4b..fe6d958 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelShell.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelShell.java
@@ -51,7 +51,7 @@ public class ChannelShell extends PtyCapableChannelSession {
         Session session = getSession();
         boolean wantReply = CoreModuleProperties.REQUEST_SHELL_REPLY.getRequired(this);
         Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_REQUEST, Integer.SIZE);
-        buffer.putInt(getRecipient());
+        buffer.putUInt(getRecipient());
         buffer.putString(Channel.CHANNEL_SHELL);
         buffer.putBoolean(wantReply);
         addPendingRequest(Channel.CHANNEL_SHELL, wantReply);
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSubsystem.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSubsystem.java
index f779dcd..e8a7838 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSubsystem.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSubsystem.java
@@ -64,7 +64,7 @@ public class ChannelSubsystem extends ChannelSession {
         boolean wantReply = CoreModuleProperties.REQUEST_SUBSYSTEM_REPLY.getRequired(this);
         Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_REQUEST,
                 Channel.CHANNEL_SUBSYSTEM.length() + systemName.length() + Integer.SIZE);
-        buffer.putInt(getRecipient());
+        buffer.putUInt(getRecipient());
         buffer.putString(Channel.CHANNEL_SUBSYSTEM);
         buffer.putBoolean(wantReply);
         buffer.putString(systemName);
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
index 214a6d9..71e4dbf 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
@@ -232,7 +232,7 @@ public class PtyCapableChannelSession extends ChannelSession implements PtyChann
 
         Session session = getSession();
         Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_REQUEST, Long.SIZE);
-        buffer.putInt(getRecipient());
+        buffer.putUInt(getRecipient());
         buffer.putString("window-change");
         buffer.putBoolean(false); // want-reply
         buffer.putInt(getPtyColumns());
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java b/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java
index 12cd13f..8b73180 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java
@@ -383,7 +383,7 @@ public abstract class AbstractClientSession extends AbstractSession implements C
             throws IOException {
         ChannelExec channel = new ChannelExec(command, ptyConfig, env);
         ConnectionService service = getConnectionService();
-        int id = service.registerChannel(channel);
+        long id = service.registerChannel(channel);
         if (log.isDebugEnabled()) {
             log.debug("createExecChannel({})[{}] created id={} - PTY={}", this, command, id, ptyConfig);
         }
@@ -394,7 +394,7 @@ public abstract class AbstractClientSession extends AbstractSession implements C
     public ChannelSubsystem createSubsystemChannel(String subsystem) throws IOException {
         ChannelSubsystem channel = new ChannelSubsystem(subsystem);
         ConnectionService service = getConnectionService();
-        int id = service.registerChannel(channel);
+        long id = service.registerChannel(channel);
         if (log.isDebugEnabled()) {
             log.debug("createSubsystemChannel({})[{}] created id={}", this, subsystem, id);
         }
@@ -406,7 +406,7 @@ public abstract class AbstractClientSession extends AbstractSession implements C
             throws IOException {
         ChannelDirectTcpip channel = new ChannelDirectTcpip(local, remote);
         ConnectionService service = getConnectionService();
-        int id = service.registerChannel(channel);
+        long id = service.registerChannel(channel);
         if (log.isDebugEnabled()) {
             log.debug("createDirectTcpipChannel({})[{} => {}] created id={}", this, local, remote, id);
         }
@@ -496,7 +496,7 @@ public abstract class AbstractClientSession extends AbstractSession implements C
 
         ChannelShell channel = new ChannelShell(ptyConfig, env);
         ConnectionService service = getConnectionService();
-        int id = service.registerChannel(channel);
+        long id = service.registerChannel(channel);
         if (log.isDebugEnabled()) {
             log.debug("createShellChannel({}) created id={} - PTY={}", this, id, ptyConfig);
         }
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
index 69c6d24..3ee3fd2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
@@ -98,8 +98,8 @@ public abstract class AbstractChannel extends AbstractInnerCloseable implements
     protected final Collection<ChannelListener> channelListeners = new CopyOnWriteArraySet<>();
     protected final ChannelListener channelListenerProxy;
 
-    private int id = -1;
-    private int recipient = -1;
+    private long id = -1L;
+    private long recipient = -1L;
     private Session sessionInstance;
     private CloseableExecutorService executor;
     private final List<RequestHandler<Channel>> requestHandlers = new CopyOnWriteArrayList<>();
@@ -155,16 +155,16 @@ public abstract class AbstractChannel extends AbstractInnerCloseable implements
     }
 
     @Override
-    public int getId() {
+    public long getId() {
         return id;
     }
 
     @Override
-    public int getRecipient() {
+    public long getRecipient() {
         return recipient;
     }
 
-    protected void setRecipient(int recipient) {
+    protected void setRecipient(long recipient) {
         if (log.isDebugEnabled()) {
             log.debug("setRecipient({}) recipient={}", this, recipient);
         }
@@ -355,12 +355,12 @@ public abstract class AbstractChannel extends AbstractInnerCloseable implements
                 : SshConstants.SSH_MSG_CHANNEL_FAILURE;
         Session session = getSession();
         Buffer rsp = session.createBuffer(cmd, Integer.BYTES);
-        rsp.putInt(recipient);
+        rsp.putUInt(recipient);
         return session.writePacket(rsp);
     }
 
     @Override
-    public void init(ConnectionService service, Session session, int id) throws IOException {
+    public void init(ConnectionService service, Session session, long id) throws IOException {
         if (log.isDebugEnabled()) {
             log.debug("init() service={} session={} id={}", service, session, id);
         }
@@ -436,7 +436,7 @@ public abstract class AbstractChannel extends AbstractInnerCloseable implements
 
     @Override
     public void handleChannelRegistrationResult(
-            ConnectionService service, Session session, int channelId,
+            ConnectionService service, Session session, long channelId,
             boolean registered) {
         notifyStateChanged("registered=" + registered);
         if (registered) {
@@ -624,7 +624,7 @@ public abstract class AbstractChannel extends AbstractInnerCloseable implements
 
                 Session s = getSession();
                 Buffer buffer = s.createBuffer(SshConstants.SSH_MSG_CHANNEL_CLOSE, Short.SIZE);
-                buffer.putInt(getRecipient());
+                buffer.putUInt(getRecipient());
 
                 try {
                     Duration timeout = CoreModuleProperties.CHANNEL_CLOSE_TIMEOUT.getRequired(channel);
@@ -811,7 +811,7 @@ public abstract class AbstractChannel extends AbstractInnerCloseable implements
             }
             Session s = getSession();
             Buffer rsp = s.createBuffer(SshConstants.SSH_MSG_CHANNEL_FAILURE, Integer.BYTES);
-            rsp.putInt(getRecipient());
+            rsp.putUInt(getRecipient());
             writePacket(rsp);
             return;
         }
@@ -944,7 +944,7 @@ public abstract class AbstractChannel extends AbstractInnerCloseable implements
 
         Session s = getSession();
         Buffer buffer = s.createBuffer(SshConstants.SSH_MSG_CHANNEL_EOF, Short.SIZE);
-        buffer.putInt(getRecipient());
+        buffer.putUInt(getRecipient());
         /*
          * The default "writePacket" does not send packets if state is not open
          * so we need to bypass it.
@@ -1012,7 +1012,7 @@ public abstract class AbstractChannel extends AbstractInnerCloseable implements
         }
         Session s = getSession();
         Buffer buffer = s.createBuffer(SshConstants.SSH_MSG_CHANNEL_WINDOW_ADJUST, Short.SIZE);
-        buffer.putInt(getRecipient());
+        buffer.putUInt(getRecipient());
         buffer.putUInt(len);
         writePacket(buffer);
     }
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/BufferedIoOutputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/BufferedIoOutputStream.java
index 477852e..15cee93 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/BufferedIoOutputStream.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/BufferedIoOutputStream.java
@@ -45,7 +45,7 @@ import org.apache.sshd.core.CoreModuleProperties;
  */
 public class BufferedIoOutputStream extends AbstractInnerCloseable implements IoOutputStream {
     protected final Object id;
-    protected final int channelId;
+    protected final long channelId;
     protected final int maxPendingBytesCount;
     protected final Duration maxWaitForPendingWrites;
     protected final IoOutputStream out;
@@ -55,13 +55,13 @@ public class BufferedIoOutputStream extends AbstractInnerCloseable implements Io
     protected final AtomicReference<IoWriteFutureImpl> currentWrite = new AtomicReference<>();
     protected final AtomicReference<SshChannelBufferedOutputException> pendingException = new AtomicReference<>();
 
-    public BufferedIoOutputStream(Object id, int channelId, IoOutputStream out, PropertyResolver resolver) {
+    public BufferedIoOutputStream(Object id, long channelId, IoOutputStream out, PropertyResolver resolver) {
         this(id, channelId, out, CoreModuleProperties.BUFFERED_IO_OUTPUT_MAX_PENDING_WRITE_SIZE.getRequired(resolver),
              CoreModuleProperties.BUFFERED_IO_OUTPUT_MAX_PENDING_WRITE_WAIT.getRequired(resolver));
     }
 
     public BufferedIoOutputStream(
-                                  Object id, int channelId, IoOutputStream out, int maxPendingBytesCount,
+                                  Object id, long channelId, IoOutputStream out, int maxPendingBytesCount,
                                   Duration maxWaitForPendingWrites) {
         this.id = Objects.requireNonNull(id, "No stream identifier provided");
         this.channelId = channelId;
@@ -71,6 +71,10 @@ public class BufferedIoOutputStream extends AbstractInnerCloseable implements Io
         this.maxWaitForPendingWrites = Objects.requireNonNull(maxWaitForPendingWrites, "No max. pending time value provided");
     }
 
+    public long getChannelId() {
+        return channelId;
+    }
+
     public Object getId() {
         return id;
     }
@@ -259,6 +263,6 @@ public class BufferedIoOutputStream extends AbstractInnerCloseable implements Io
 
     @Override
     public String toString() {
-        return getClass().getSimpleName() + "(" + getId() + ")[" + out + "]";
+        return getClass().getSimpleName() + "(" + getId() + "@" + channelId + ")[" + out + "]";
     }
 }
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java
index 2bfd095..41a86be 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java
@@ -55,14 +55,14 @@ public interface Channel
     String CHANNEL_SUBSYSTEM = "subsystem";
 
     /**
-     * @return Local channel identifier
+     * @return Local channel UINT32 identifier
      */
-    int getId();
+    long getId();
 
     /**
-     * @return Remote channel identifier
+     * @return Remote channel UITN32 identifier
      */
-    int getRecipient();
+    long getRecipient();
 
     Window getLocalWindow();
 
@@ -147,10 +147,10 @@ public interface Channel
      *
      * @param  service     The {@link ConnectionService} through which the channel is initialized
      * @param  session     The {@link Session} associated with the channel
-     * @param  id          The locally assigned channel identifier
+     * @param  id          The locally assigned channel identifier (UINT32 represented as a {@code long})
      * @throws IOException If failed to process the initialization
      */
-    void init(ConnectionService service, Session session, int id) throws IOException;
+    void init(ConnectionService service, Session session, long id) throws IOException;
 
     /**
      * Invoked after being successfully registered by the connection service - should throw a {@link RuntimeException}
@@ -158,10 +158,10 @@ public interface Channel
      *
      * @param service    The {@link ConnectionService} through which the channel is registered
      * @param session    The {@link Session} associated with the channel
-     * @param id         The locally assigned channel identifier
+     * @param id         The locally assigned channel identifier (UINT32 represented as a {@code long})
      * @param registered Whether registration was successful or not
      */
-    void handleChannelRegistrationResult(ConnectionService service, Session session, int id, boolean registered);
+    void handleChannelRegistrationResult(ConnectionService service, Session session, long id, boolean registered);
 
     /**
      * Called by the connection service to inform the channel that it has bee unregistered.
@@ -171,7 +171,7 @@ public interface Channel
     void handleChannelUnregistration(ConnectionService service);
 
     /**
-     * @return {@code true} if call to {@link #init(ConnectionService, Session, int)} was successfully completed
+     * @return {@code true} if call to {@link #init(ConnectionService, Session, long)} was successfully completed
      */
     boolean isInitialized();
 
@@ -185,27 +185,27 @@ public interface Channel
     /**
      * For a server channel, this method will actually open the channel
      *
-     * @param  recipient  Recipient identifier
+     * @param  recipient  Recipient identifier (UINT32 represented as a {@code long})
      * @param  rwSize     Read/Write window size ({@code uint32})
      * @param  packetSize Preferred maximum packet size ({@code uint32})
      * @param  buffer     Incoming {@link Buffer} that triggered the call. <B>Note:</B> the buffer's read position is
      *                    exactly <U>after</U> the information that read to this call was decoded
      * @return            An {@link OpenFuture} for the channel open request
      */
-    OpenFuture open(int recipient, long rwSize, long packetSize, Buffer buffer);
+    OpenFuture open(long recipient, long rwSize, long packetSize, Buffer buffer);
 
     /**
      * For a client channel, this method will be called internally by the session when the confirmation has been
      * received.
      *
-     * @param  recipient   Recipient identifier
+     * @param  recipient   Recipient identifier (UINT32 represented as a {@code long})
      * @param  rwSize      Read/Write window size ({@code uint32})
      * @param  packetSize  Preferred maximum packet size ({@code uint32})
      * @param  buffer      Incoming {@link Buffer} that triggered the call. <B>Note:</B> the buffer's read position is
      *                     exactly <U>after</U> the information that read to this call was decoded
      * @throws IOException If failed to handle the success
      */
-    void handleOpenSuccess(int recipient, long rwSize, long packetSize, Buffer buffer) throws IOException;
+    void handleOpenSuccess(long recipient, long rwSize, long packetSize, Buffer buffer) throws IOException;
 
     /**
      * For a client channel, this method will be called internally by the session when the server has rejected this
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java
index 81844a6..49838a2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java
@@ -30,6 +30,7 @@ import org.apache.sshd.common.io.IoOutputStream;
 import org.apache.sshd.common.io.IoWriteFuture;
 import org.apache.sshd.common.io.WritePendingException;
 import org.apache.sshd.common.session.Session;
+import org.apache.sshd.common.session.SessionContext;
 import org.apache.sshd.common.util.buffer.Buffer;
 import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
 import org.apache.sshd.common.util.closeable.AbstractCloseable;
@@ -255,11 +256,13 @@ public class ChannelAsyncOutputStream extends AbstractCloseable implements IoOut
     }
 
     protected Buffer createSendBuffer(Buffer buffer, Channel channel, long length) {
+        SessionContext.validateSessionPayloadSize(length, "Invalid send buffer length: %d");
+
         Session s = channel.getSession();
         Buffer buf = s.createBuffer(cmd, (int) length + 12);
-        buf.putInt(channel.getRecipient());
+        buf.putUInt(channel.getRecipient());
         if (cmd == SshConstants.SSH_MSG_CHANNEL_EXTENDED_DATA) {
-            buf.putInt(SshConstants.SSH_EXTENDED_DATA_STDERR);
+            buf.putUInt(SshConstants.SSH_EXTENDED_DATA_STDERR);
         }
         buf.putUInt(length);
         buf.putRawBytes(buffer.array(), buffer.rpos(), (int) length);
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelListener.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelListener.java
index 1b57038..d48dea3 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelListener.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelListener.java
@@ -38,7 +38,7 @@ public interface ChannelListener extends SshdEventListener {
 
     /**
      * Called to inform about initial setup of a channel via the
-     * {@link Channel#init(org.apache.sshd.common.session.ConnectionService, org.apache.sshd.common.session.Session, int)}
+     * {@link Channel#init(org.apache.sshd.common.session.ConnectionService, org.apache.sshd.common.session.Session, long)}
      * method. <B>Note:</B> this method is guaranteed to be called before either of the
      * {@link #channelOpenSuccess(Channel)} or {@link #channelOpenFailure(Channel, Throwable)} will be called
      *
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java
index ec08f8a..188fb78 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java
@@ -302,11 +302,11 @@ public class ChannelOutputStream extends OutputStream implements java.nio.channe
         Channel channel = getChannel();
         Session session = channel.getSession();
         buffer = session.createBuffer(cmd, size <= 0 ? 12 : 12 + size);
-        buffer.putInt(channel.getRecipient());
+        buffer.putUInt(channel.getRecipient());
         if (cmd == SshConstants.SSH_MSG_CHANNEL_EXTENDED_DATA) {
-            buffer.putInt(SshConstants.SSH_EXTENDED_DATA_STDERR);
+            buffer.putUInt(SshConstants.SSH_EXTENDED_DATA_STDERR);
         }
-        buffer.putInt(0);
+        buffer.putUInt(0L);
         bufferLength = 0;
     }
 
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelBufferedOutputException.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelBufferedOutputException.java
index 97e6105..bd41e54 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelBufferedOutputException.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelBufferedOutputException.java
@@ -27,15 +27,15 @@ package org.apache.sshd.common.channel.exception;
 public class SshChannelBufferedOutputException extends SshChannelException {
     private static final long serialVersionUID = -8663890657820958046L;
 
-    public SshChannelBufferedOutputException(int channelId, String message) {
+    public SshChannelBufferedOutputException(long channelId, String message) {
         this(channelId, message, null);
     }
 
-    public SshChannelBufferedOutputException(int channelId, Throwable cause) {
+    public SshChannelBufferedOutputException(long channelId, Throwable cause) {
         this(channelId, cause.getMessage(), cause);
     }
 
-    public SshChannelBufferedOutputException(int channelId, String message, Throwable cause) {
+    public SshChannelBufferedOutputException(long channelId, String message, Throwable cause) {
         super(channelId, message, cause);
     }
 }
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelClosedException.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelClosedException.java
index ee4b6ff..4e2f2a8 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelClosedException.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelClosedException.java
@@ -25,15 +25,15 @@ package org.apache.sshd.common.channel.exception;
 public class SshChannelClosedException extends SshChannelException {
     private static final long serialVersionUID = 4201656251593797929L;
 
-    public SshChannelClosedException(int channelId, String message) {
+    public SshChannelClosedException(long channelId, String message) {
         this(channelId, message, null);
     }
 
-    public SshChannelClosedException(int channelId, Throwable cause) {
+    public SshChannelClosedException(long channelId, Throwable cause) {
         this(channelId, cause.getMessage(), cause);
     }
 
-    public SshChannelClosedException(int channelId, String message, Throwable cause) {
+    public SshChannelClosedException(long channelId, String message, Throwable cause) {
         super(channelId, message, cause);
     }
 }
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelException.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelException.java
index 57c9669..13d9f6e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelException.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelException.java
@@ -24,25 +24,25 @@ import java.io.IOException;
 /**
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  */
-public class SshChannelException extends IOException {
+public abstract class SshChannelException extends IOException {
     private static final long serialVersionUID = 7355720478400167933L;
 
-    private final int channelId;
+    private final long channelId;
 
-    public SshChannelException(int channelId, String message) {
+    protected SshChannelException(long channelId, String message) {
         this(channelId, message, null);
     }
 
-    public SshChannelException(int channelId, Throwable cause) {
+    protected SshChannelException(long channelId, Throwable cause) {
         this(channelId, cause.getMessage(), cause);
     }
 
-    public SshChannelException(int channelId, String message, Throwable cause) {
+    protected SshChannelException(long channelId, String message, Throwable cause) {
         super(message, cause);
         this.channelId = channelId;
     }
 
-    public int getChannelId() {
+    public long getChannelId() {
         return channelId;
     }
 }
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelNotFoundException.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelNotFoundException.java
index 26fb9ab..3494390 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelNotFoundException.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelNotFoundException.java
@@ -25,15 +25,15 @@ package org.apache.sshd.common.channel.exception;
 public class SshChannelNotFoundException extends SshChannelException {
     private static final long serialVersionUID = 6235323779982884257L;
 
-    public SshChannelNotFoundException(int channelId, String message) {
+    public SshChannelNotFoundException(long channelId, String message) {
         this(channelId, message, null);
     }
 
-    public SshChannelNotFoundException(int channelId, Throwable cause) {
+    public SshChannelNotFoundException(long channelId, Throwable cause) {
         this(channelId, cause.getMessage(), cause);
     }
 
-    public SshChannelNotFoundException(int channelId, String message, Throwable cause) {
+    public SshChannelNotFoundException(long channelId, String message, Throwable cause) {
         super(channelId, message, cause);
     }
 }
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelOpenException.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelOpenException.java
index e272d2b..6daa73c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelOpenException.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelOpenException.java
@@ -28,11 +28,11 @@ public class SshChannelOpenException extends SshChannelException {
 
     private final int code;
 
-    public SshChannelOpenException(int channelId, int code, String message) {
+    public SshChannelOpenException(long channelId, int code, String message) {
         this(channelId, code, message, null);
     }
 
-    public SshChannelOpenException(int channelId, int code, String message, Throwable cause) {
+    public SshChannelOpenException(long channelId, int code, String message, Throwable cause) {
         super(channelId, message, cause);
         this.code = code;
     }
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java b/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java
index 853581b..17c6003 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java
@@ -150,13 +150,13 @@ public class TcpipClientChannel extends AbstractClientChannel implements Forward
         Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN,
                 type.length() + srcHost.length() + dstHost.length() + Long.SIZE);
         buffer.putString(type);
-        buffer.putInt(getId());
-        buffer.putInt(wLocal.getSize());
-        buffer.putInt(wLocal.getPacketSize());
+        buffer.putUInt(getId());
+        buffer.putUInt(wLocal.getSize());
+        buffer.putUInt(wLocal.getPacketSize());
         buffer.putString(dstHost);
-        buffer.putInt(dst.getPort());
+        buffer.putUInt(dst.getPort());
         buffer.putString(srcHost);
-        buffer.putInt(src.getPort());
+        buffer.putUInt(src.getPort());
         writePacket(buffer);
         return openFuture;
     }
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/DefaultServerKexExtensionHandler.java b/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/DefaultServerKexExtensionHandler.java
index ef48290..7d59246 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/DefaultServerKexExtensionHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/DefaultServerKexExtensionHandler.java
@@ -69,6 +69,7 @@ public class DefaultServerKexExtensionHandler extends AbstractLoggingBean implem
      * <dd>The EXT_INFO message at {@link KexPhase#NEWKEYS} was done.</dd>
      * </dl>
      */
+    @SuppressWarnings("javadoc")
     public static final AttributeKey<Boolean> EXT_INFO_SENT_AT_NEWKEYS = new AttributeKey<>();
 
     public DefaultServerKexExtensionHandler() {
@@ -141,6 +142,7 @@ public class DefaultServerKexExtensionHandler extends AbstractLoggingBean implem
      * @param phase      {@link KexPhase} of the SSH protocol
      * @param marshaller {@link BiConsumer} writing the extensions into an SSH message
      */
+    @SuppressWarnings("javadoc")
     public void collectExtensions(Session session, KexPhase phase, BiConsumer<String, Object> marshaller) {
         if (phase == KexPhase.NEWKEYS) {
             Collection<String> algorithms = session.getSignatureFactoriesNames();
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/ConnectionService.java b/sshd-core/src/main/java/org/apache/sshd/common/session/ConnectionService.java
index 9e6a8e6..4340da3 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/ConnectionService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/ConnectionService.java
@@ -44,10 +44,10 @@ public interface ConnectionService
      * Register a newly created channel with a new unique identifier
      *
      * @param  channel     The {@link Channel} to register
-     * @return             The assigned id of this channel
+     * @return             The assigned id of this channel - a UINT32 represented as a {@code long}
      * @throws IOException If failed to initialize and register the channel
      */
-    int registerChannel(Channel channel) throws IOException;
+    long registerChannel(Channel channel) throws IOException;
 
     /**
      * Remove this channel from the list of managed channels
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/UnknownChannelReferenceHandler.java b/sshd-core/src/main/java/org/apache/sshd/common/session/UnknownChannelReferenceHandler.java
index 11f749d..debee20 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/UnknownChannelReferenceHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/UnknownChannelReferenceHandler.java
@@ -41,5 +41,5 @@ public interface UnknownChannelReferenceHandler {
      *                     ignored.
      * @throws IOException If failed to handle the request
      */
-    Channel handleUnknownChannelCommand(ConnectionService service, byte cmd, int channelId, Buffer buffer) throws IOException;
+    Channel handleUnknownChannelCommand(ConnectionService service, byte cmd, long channelId, Buffer buffer) throws IOException;
 }
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractConnectionService.java b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractConnectionService.java
index 147ef16..d390fd5 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractConnectionService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractConnectionService.java
@@ -31,7 +31,6 @@ import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.IntUnaryOperator;
@@ -90,11 +89,11 @@ public abstract class AbstractConnectionService
     /**
      * Map of channels keyed by the identifier
      */
-    protected final Map<Integer, Channel> channels = new ConcurrentHashMap<>();
+    protected final Map<Long, Channel> channels = new ConcurrentHashMap<>();
     /**
-     * Next channel identifier
+     * Next channel identifier - a UINT32 represented as a long
      */
-    protected final AtomicInteger nextChannelId = new AtomicInteger(0);
+    protected final AtomicLong nextChannelId = new AtomicLong(0L);
     protected final AtomicLong heartbeatCount = new AtomicLong(0L);
     private ScheduledFuture<?> heartBeat;
 
@@ -392,12 +391,12 @@ public abstract class AbstractConnectionService
                 .build();
     }
 
-    protected int getNextChannelId() {
+    protected long getNextChannelId() {
         return nextChannelId.getAndIncrement();
     }
 
     @Override
-    public int registerChannel(Channel channel) throws IOException {
+    public long registerChannel(Channel channel) throws IOException {
         Session session = getSession();
         int maxChannels = CoreModuleProperties.MAX_CONCURRENT_CHANNELS.getRequired(this);
         int curSize = channels.size();
@@ -405,7 +404,7 @@ public abstract class AbstractConnectionService
             throw new IllegalStateException("Currently active channels (" + curSize + ") at max.: " + maxChannels);
         }
 
-        int channelId = getNextChannelId();
+        long channelId = getNextChannelId();
         channel.init(this, session, channelId);
 
         boolean registered = false;
@@ -431,7 +430,7 @@ public abstract class AbstractConnectionService
      */
     @Override
     public void unregisterChannel(Channel channel) {
-        int channelId = channel.getId();
+        long channelId = channel.getId();
         Channel result;
         synchronized (channels) {
             result = channels.remove(channelId);
@@ -551,7 +550,7 @@ public abstract class AbstractConnectionService
             return; // debug breakpoint
         }
 
-        int id = channel.getId();
+        long id = channel.getId();
         boolean debugEnabled = log.isDebugEnabled();
         if (debugEnabled) {
             log.debug("channelOpenFailure({}) Received SSH_MSG_CHANNEL_OPEN_FAILURE", channel);
@@ -698,10 +697,10 @@ public abstract class AbstractConnectionService
      * @throws IOException if the channel does not exists
      */
     protected Channel getChannel(byte cmd, Buffer buffer) throws IOException {
-        return getChannel(cmd, buffer.getInt(), buffer);
+        return getChannel(cmd, buffer.getUInt(), buffer);
     }
 
-    protected Channel getChannel(byte cmd, int recipient, Buffer buffer) throws IOException {
+    protected Channel getChannel(byte cmd, long recipient, Buffer buffer) throws IOException {
         Channel channel = channels.get(recipient);
         if (channel != null) {
             return channel;
@@ -732,7 +731,7 @@ public abstract class AbstractConnectionService
 
     protected void channelOpen(Buffer buffer) throws Exception {
         String type = buffer.getString();
-        int sender = buffer.getInt();
+        long sender = buffer.getUInt();
         long rwsize = buffer.getUInt();
         long rmpsize = buffer.getUInt();
         /*
@@ -767,7 +766,7 @@ public abstract class AbstractConnectionService
             return;
         }
 
-        int channelId = registerChannel(channel);
+        long channelId = registerChannel(channel);
         OpenFuture openFuture = channel.open(sender, rwsize, rmpsize, buffer);
         openFuture.addListener(future -> {
             try {
@@ -779,10 +778,10 @@ public abstract class AbstractConnectionService
                                 channel, sender, channelId, window.getSize(), window.getPacketSize());
                     }
                     Buffer buf = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN_CONFIRMATION, Integer.SIZE);
-                    buf.putInt(sender); // remote (server side) identifier
-                    buf.putInt(channelId); // local (client side) identifier
-                    buf.putInt(window.getSize());
-                    buf.putInt(window.getPacketSize());
+                    buf.putUInt(sender); // remote (server side) identifier
+                    buf.putUInt(channelId); // local (client side) identifier
+                    buf.putUInt(window.getSize());
+                    buf.putUInt(window.getPacketSize());
                     session.writePacket(buf);
                 } else {
                     int reasonCode = 0;
@@ -811,7 +810,7 @@ public abstract class AbstractConnectionService
     }
 
     protected IoWriteFuture sendChannelOpenFailure(
-            Buffer buffer, int sender, int reasonCode, String message, String lang)
+            Buffer buffer, long sender, int reasonCode, String message, String lang)
             throws IOException {
         if (log.isDebugEnabled()) {
             log.debug("sendChannelOpenFailure({}) sender={}, reason={}, lang={}, message='{}'",
@@ -821,8 +820,8 @@ public abstract class AbstractConnectionService
         Session session = getSession();
         Buffer buf = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN_FAILURE,
                 Long.SIZE + GenericUtils.length(message) + GenericUtils.length(lang));
-        buf.putInt(sender);
-        buf.putInt(reasonCode);
+        buf.putUInt(sender);
+        buf.putUInt(reasonCode);
         buf.putString(message);
         buf.putString(lang);
         return session.writePacket(buf);
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/DefaultUnknownChannelReferenceHandler.java b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/DefaultUnknownChannelReferenceHandler.java
index e5723b9..c5e9318 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/DefaultUnknownChannelReferenceHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/DefaultUnknownChannelReferenceHandler.java
@@ -46,7 +46,7 @@ public class DefaultUnknownChannelReferenceHandler
 
     @Override
     public Channel handleUnknownChannelCommand(
-            ConnectionService service, byte cmd, int channelId, Buffer buffer)
+            ConnectionService service, byte cmd, long channelId, Buffer buffer)
             throws IOException {
         Session session = service.getSession();
         // Use DEBUG level to avoid log overflow due to invalid messages flood
@@ -97,7 +97,7 @@ public class DefaultUnknownChannelReferenceHandler
     }
 
     protected IoWriteFuture sendFailureResponse(
-            ConnectionService service, byte cmd, int channelId)
+            ConnectionService service, byte cmd, long channelId)
             throws IOException {
         Session session = service.getSession();
         // Use DEBUG level to avoid log overflow due to invalid messages flood
@@ -107,7 +107,7 @@ public class DefaultUnknownChannelReferenceHandler
         }
 
         Buffer rsp = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_FAILURE, Integer.BYTES);
-        rsp.putInt(channelId);
+        rsp.putUInt(channelId);
         return session.writePacket(rsp);
     }
 }
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/SessionHelper.java b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/SessionHelper.java
index a08d37e..2efccca 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/SessionHelper.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/SessionHelper.java
@@ -429,7 +429,7 @@ public abstract class SessionHelper extends AbstractKexFactoryManager implements
      */
     protected IoWriteFuture sendNotImplemented(long seqNoValue) throws IOException {
         Buffer buffer = createBuffer(SshConstants.SSH_MSG_UNIMPLEMENTED, Byte.SIZE);
-        buffer.putInt(seqNoValue);
+        buffer.putUInt(seqNoValue);
         return writePacket(buffer);
     }
 
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/channel/AbstractServerChannel.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/AbstractServerChannel.java
index 788ac55..7fd7d68 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/channel/AbstractServerChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/AbstractServerChannel.java
@@ -56,7 +56,7 @@ public abstract class AbstractServerChannel extends AbstractChannel implements S
     }
 
     @Override
-    public OpenFuture open(int recipient, long rwSize, long packetSize, Buffer buffer) {
+    public OpenFuture open(long recipient, long rwSize, long packetSize, Buffer buffer) {
         setRecipient(recipient);
 
         Session s = getSession();
@@ -69,7 +69,7 @@ public abstract class AbstractServerChannel extends AbstractChannel implements S
 
     @Override
     public void handleOpenSuccess(
-            int recipient, long rwSize, long packetSize, Buffer buffer)
+            long recipient, long rwSize, long packetSize, Buffer buffer)
             throws IOException {
         throw new UnsupportedOperationException(
                 "handleOpenSuccess(" + recipient + "," + rwSize + "," + packetSize + ") N/A");
@@ -114,7 +114,7 @@ public abstract class AbstractServerChannel extends AbstractChannel implements S
         Session session = getSession();
         Buffer buffer = session.createBuffer(
                 SshConstants.SSH_MSG_CHANNEL_REQUEST, Long.SIZE);
-        buffer.putInt(getRecipient());
+        buffer.putUInt(getRecipient());
         buffer.putString("exit-status");
         // want-reply - must be FALSE - see https://tools.ietf.org/html/rfc4254 section 6.10
         buffer.putBoolean(false);
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java b/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
index 7ea6c72..2a14a35 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
@@ -215,7 +215,7 @@ public class TcpipServerChannel extends AbstractServerChannel implements Streami
         }
 
         if (streaming == Streaming.Async) {
-            int channelId = getId();
+            long channelId = getId();
             out = new BufferedIoOutputStream(
                     "aysnc-tcpip-channel@" + channelId, channelId,
                     new ChannelAsyncOutputStream(this, SshConstants.SSH_MSG_CHANNEL_DATA) {
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/x11/ChannelForwardedX11.java b/sshd-core/src/main/java/org/apache/sshd/server/x11/ChannelForwardedX11.java
index 9dd046a..cde200b 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/x11/ChannelForwardedX11.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/x11/ChannelForwardedX11.java
@@ -67,11 +67,11 @@ public class ChannelForwardedX11 extends AbstractClientChannel {
         Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN,
                 remoteHost.length() + type.length() + Integer.SIZE);
         buffer.putString(type);
-        buffer.putInt(getId());
-        buffer.putInt(wLocal.getSize());
-        buffer.putInt(wLocal.getPacketSize());
+        buffer.putUInt(getId());
+        buffer.putUInt(wLocal.getSize());
+        buffer.putUInt(wLocal.getPacketSize());
         buffer.putString(remoteHost);
-        buffer.putInt(remote.getPort());
+        buffer.putUInt(remote.getPort());
         writePacket(buffer);
         return openFuture;
     }
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
index b1ae9b1..bc466e2 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
@@ -208,7 +208,7 @@ public class ClientTest extends BaseTestSupport {
                         return new ChannelSession() {
                             @SuppressWarnings("synthetic-access")
                             @Override
-                            public OpenFuture open(int recipient, long rwsize, long rmpsize, Buffer buffer) {
+                            public OpenFuture open(long recipient, long rwsize, long rmpsize, Buffer buffer) {
                                 try {
                                     channelLatch.await();
                                 } catch (InterruptedException e) {
@@ -342,7 +342,7 @@ public class ClientTest extends BaseTestSupport {
 
     @Test
     public void testClientStillActiveIfListenerExceptions() throws Exception {
-        Map<String, Integer> eventsMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+        Map<String, Long> eventsMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
         Collection<String> failuresSet = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
         Logger log = LoggerFactory.getLogger(getClass());
         client.addChannelListener(new ChannelListener() {
@@ -377,7 +377,7 @@ public class ClientTest extends BaseTestSupport {
             }
 
             private void handleChannelEvent(String name, Channel channel) {
-                int id = channel.getId();
+                long id = channel.getId();
                 synchronized (eventsMap) {
                     if (eventsMap.put(name, id) != null) {
                         return; // already generated an exception for this event
@@ -1475,9 +1475,9 @@ public class ClientTest extends BaseTestSupport {
             channels.add(session.createChannel(Channel.CHANNEL_EXEC, getCurrentTestName()));
             channels.add(session.createChannel(Channel.CHANNEL_SHELL, getClass().getSimpleName()));
 
-            Set<Integer> ids = new HashSet<>(channels.size());
+            Set<Long> ids = new HashSet<>(channels.size());
             for (ClientChannel c : channels) {
-                int id = c.getId();
+                long id = c.getId();
                 assertTrue("Channel ID repeated: " + id, ids.add(id));
             }
         } finally {
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowInitTest.java b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowInitTest.java
index 81f0362..64a64a6 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowInitTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowInitTest.java
@@ -49,12 +49,12 @@ import org.junit.runners.Parameterized.UseParametersRunnerFactory;
 public class WindowInitTest extends BaseTestSupport {
     private static final AbstractChannel MOCK_CHANNEL = new AbstractChannel(true) {
         @Override
-        public OpenFuture open(int recipient, long rwSize, long packetSize, Buffer buffer) {
+        public OpenFuture open(long recipient, long rwSize, long packetSize, Buffer buffer) {
             return null;
         }
 
         @Override
-        public void handleOpenSuccess(int recipient, long rwSize, long packetSize, Buffer buffer) throws IOException {
+        public void handleOpenSuccess(long recipient, long rwSize, long packetSize, Buffer buffer) throws IOException {
             // ignored
         }
 
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java
index f42ad61..77965f2 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java
@@ -110,7 +110,7 @@ public class WindowTest extends BaseTestSupport {
                         return new ChannelSession() {
                             @SuppressWarnings("synthetic-access")
                             @Override
-                            public OpenFuture open(int recipient, long rwsize, long rmpsize, Buffer buffer) {
+                            public OpenFuture open(long recipient, long rwsize, long rmpsize, Buffer buffer) {
                                 try {
                                     channelLatch.await();
                                 } catch (InterruptedException e) {
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTimeoutTest.java b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTimeoutTest.java
index cbb4865..d312bbd 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTimeoutTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTimeoutTest.java
@@ -56,12 +56,12 @@ public class WindowTimeoutTest extends BaseTestSupport {
     public void setUp() throws Exception {
         channel = new AbstractChannel(getCurrentTestName(), true) {
             @Override
-            public OpenFuture open(int recipient, long rwSize, long packetSize, Buffer buffer) {
+            public OpenFuture open(long recipient, long rwSize, long packetSize, Buffer buffer) {
                 throw new UnsupportedOperationException();
             }
 
             @Override
-            public void handleOpenSuccess(int recipient, long rwSize, long packetSize, Buffer buffer) throws IOException {
+            public void handleOpenSuccess(long recipient, long rwSize, long packetSize, Buffer buffer) throws IOException {
                 throw new UnsupportedOperationException();
             }
 
diff --git a/sshd-core/src/test/java/org/apache/sshd/util/test/AsyncEchoShellFactory.java b/sshd-core/src/test/java/org/apache/sshd/util/test/AsyncEchoShellFactory.java
index 2373539..22f7fec 100644
--- a/sshd-core/src/test/java/org/apache/sshd/util/test/AsyncEchoShellFactory.java
+++ b/sshd-core/src/test/java/org/apache/sshd/util/test/AsyncEchoShellFactory.java
@@ -112,7 +112,7 @@ public class AsyncEchoShellFactory implements ShellFactory {
                 return (BufferedIoOutputStream) stream;
             }
 
-            int channelId = session.getId();
+            long channelId = session.getId();
             return new BufferedIoOutputStream(prefix + "@" + channelId, channelId, stream, session);
         }
 
diff --git a/sshd-core/src/test/java/org/apache/sshd/util/test/BogusChannel.java b/sshd-core/src/test/java/org/apache/sshd/util/test/BogusChannel.java
index 80e576c..7138ded 100644
--- a/sshd-core/src/test/java/org/apache/sshd/util/test/BogusChannel.java
+++ b/sshd-core/src/test/java/org/apache/sshd/util/test/BogusChannel.java
@@ -50,12 +50,12 @@ public class BogusChannel extends AbstractChannel {
     }
 
     @Override
-    public OpenFuture open(int recipient, long rwsize, long rmpsize, Buffer buffer) {
+    public OpenFuture open(long recipient, long rwsize, long rmpsize, Buffer buffer) {
         return new DefaultOpenFuture(this, this.futureLock);
     }
 
     @Override
-    public void handleOpenSuccess(int recipient, long rwsize, long rmpsize, Buffer buffer) throws IOException {
+    public void handleOpenSuccess(long recipient, long rwsize, long rmpsize, Buffer buffer) throws IOException {
         // ignored
     }
 
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/fs/SftpPath.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/fs/SftpPath.java
index a8c6468..807c062 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/fs/SftpPath.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/fs/SftpPath.java
@@ -41,6 +41,7 @@ public class SftpPath extends BasePath<SftpPath, SftpFileSystem> {
      *
      * @return the cached {@link SftpClient.Attributes} or {@code null} if there are none cached
      */
+    @SuppressWarnings("javadoc")
     public SftpClient.Attributes getAttributes() {
         // Subclasses may override
         return null;
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/AbstractSftpClient.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/AbstractSftpClient.java
index 78f0b2f..373fdf3 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/AbstractSftpClient.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/AbstractSftpClient.java
@@ -682,6 +682,7 @@ public abstract class AbstractSftpClient
 
         if (type == SftpConstants.SSH_FXP_DATA) {
             int len = buffer.getInt();
+            ValidateUtils.checkTrue(len >= 0, "Invalid response data len: %d", len);
             buffer.getRawBytes(dst, dstoff, len);
             Boolean indicator = SftpHelper.getEndOfFileIndicatorValue(buffer, getVersion());
             if (log.isTraceEnabled()) {
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/DefaultSftpClient.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/DefaultSftpClient.java
index a543a61..cf4518b 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/DefaultSftpClient.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/DefaultSftpClient.java
@@ -551,7 +551,7 @@ public class DefaultSftpClient extends AbstractSftpClient {
             boolean wantReply = CoreModuleProperties.REQUEST_SUBSYSTEM_REPLY.getRequired(this);
             Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_REQUEST,
                     Channel.CHANNEL_SUBSYSTEM.length() + systemName.length() + Integer.SIZE);
-            buffer.putInt(getRecipient());
+            buffer.putUInt(getRecipient());
             buffer.putString(Channel.CHANNEL_SUBSYSTEM);
             buffer.putBoolean(wantReply);
             buffer.putString(systemName);
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/extensions/Supported2Parser.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/extensions/Supported2Parser.java
index c2e3b3a..4e0cbe6 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/extensions/Supported2Parser.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/extensions/Supported2Parser.java
@@ -28,14 +28,15 @@ import org.apache.sshd.sftp.common.extensions.Supported2Parser.Supported2;
 
 /**
  * Parses the &quot;supported2&quot; extension as defined in
- * <A HREF="https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#page-10">DRAFT 13 section 5.4</A>
+ * <A HREF="https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-13#section-5.4">DRAFT 13 section 5.4</A>
  *
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  */
 public class Supported2Parser extends AbstractParser<Supported2> {
     /**
      * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
-     * @see    <A HREF="https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#page-10">DRAFT 13 section 5.4</A>
+     * @see    <A HREF="https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-13#section-5.4">DRAFT 13 section
+     *         5.4</A>
      */
     public static class Supported2 {
         // CHECKSTYLE:OFF
@@ -43,7 +44,8 @@ public class Supported2Parser extends AbstractParser<Supported2> {
         public int supportedAttributeBits;
         public int supportedOpenFlags;
         public int supportedAccessMask;
-        public int maxReadSize;
+        // Actually UINT32
+        public long maxReadSize;
         public short supportedOpenBlockVector;
         public short supportedBlock;
         //        uint32 attrib-extension-count
@@ -87,7 +89,7 @@ public class Supported2Parser extends AbstractParser<Supported2> {
         sup2.supportedAttributeBits = buffer.getInt();
         sup2.supportedOpenFlags = buffer.getInt();
         sup2.supportedAccessMask = buffer.getInt();
-        sup2.maxReadSize = buffer.getInt();
+        sup2.maxReadSize = buffer.getUInt();
         sup2.supportedOpenBlockVector = buffer.getShort();
         sup2.supportedBlock = buffer.getShort();
         sup2.attribExtensionNames = buffer.getStringList(true);
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/extensions/SupportedParser.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/extensions/SupportedParser.java
index dde1da1..28ebe4b 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/extensions/SupportedParser.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/extensions/SupportedParser.java
@@ -36,8 +36,8 @@ import org.apache.sshd.sftp.common.extensions.SupportedParser.Supported;
 public class SupportedParser extends AbstractParser<Supported> {
     /**
      * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
-     * @see    <A HREF="http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-05.txt">DRAFT
-     *         05 - section 4.4</A>
+     * @see    <A HREF="http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-05">DRAFT 05
+     *         - section 4.4</A>
      */
     public static class Supported {
         // CHECKSTYLE:OFF
@@ -45,7 +45,8 @@ public class SupportedParser extends AbstractParser<Supported> {
         public int supportedAttributeBits;
         public int supportedOpenFlags;
         public int supportedAccessMask;
-        public int maxReadSize;
+        // Actually UINT32
+        public long maxReadSize;
         public Collection<String> extensionNames;
         // CHECKSTYLE:ON
 
@@ -81,7 +82,7 @@ public class SupportedParser extends AbstractParser<Supported> {
         sup.supportedAttributeBits = buffer.getInt();
         sup.supportedOpenFlags = buffer.getInt();
         sup.supportedAccessMask = buffer.getInt();
-        sup.maxReadSize = buffer.getInt();
+        sup.maxReadSize = buffer.getUInt();
         sup.extensionNames = buffer.getStringList(false);
         return sup;
     }
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java
index ba8ca69..f87eb6a 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java
@@ -556,6 +556,7 @@ public abstract class AbstractSftpSubsystemHelper
         }
 
         try {
+            // protected against malicious packets
             ValidateUtils.checkTrue(readLen >= 0, "Illegal requested read length: %d", readLen);
 
             buffer = prepareReply(buffer);
@@ -564,7 +565,7 @@ public abstract class AbstractSftpSubsystemHelper
             buffer.putByte((byte) SftpConstants.SSH_FXP_DATA);
             buffer.putInt(id);
             int lenPos = buffer.wpos();
-            buffer.putInt(0);
+            buffer.putUInt(0L); // save room for length
 
             AtomicReference<Boolean> eofRef = new AtomicReference<>();
             int startPos = buffer.wpos();
@@ -2180,7 +2181,7 @@ public abstract class AbstractSftpSubsystemHelper
             throws IOException {
         buffer.putByte((byte) SftpConstants.SSH_FXP_NAME);
         buffer.putInt(id);
-        buffer.putInt(1); // one reply
+        buffer.putUInt(1L); // one reply
 
         String originalPath = f.toString();
         // in case we are running on Windows
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystem.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystem.java
index fdd4bae..ae48894 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystem.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystem.java
@@ -241,7 +241,7 @@ public class SftpSubsystem
     @Override
     public void setIoOutputStream(IoOutputStream out) {
         ChannelSession channel = getServerChannelSession();
-        int channelId = channel.getId();
+        long channelId = channel.getId();
         this.out = new BufferedIoOutputStream("sftp-out@" + channelId, channelId, out, channel);
     }
 
@@ -274,7 +274,7 @@ public class SftpSubsystem
             int msglen = buffer.getInt();
             if (buffer.available() >= msglen) {
                 Buffer b = new ByteArrayBuffer(msglen + Integer.BYTES + Long.SIZE /* a bit extra */, false);
-                b.putInt(msglen);
+                b.putUInt(msglen);
                 b.putRawBytes(buffer.array(), buffer.rpos(), msglen);
                 requests.add(b);
                 buffer.rpos(rpos + msglen + Integer.BYTES);
@@ -719,7 +719,7 @@ public class SftpSubsystem
                 reply.putInt(id);
 
                 int lenPos = reply.wpos();
-                reply.putInt(0);
+                reply.putUInt(0L);  // save room for actual length
 
                 int maxDataSize = SftpModuleProperties.MAX_READDIR_DATA_SIZE.getRequired(session);
                 int count = doReadDir(id, handle, dh, reply, maxDataSize, false);
diff --git a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/ClientTest.java b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/ClientTest.java
index a99e566..b2c3dad 100644
--- a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/ClientTest.java
+++ b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/ClientTest.java
@@ -147,7 +147,7 @@ public class ClientTest extends BaseTestSupport {
                         return new ChannelSession() {
                             @SuppressWarnings("synthetic-access")
                             @Override
-                            public OpenFuture open(int recipient, long rwsize, long rmpsize, Buffer buffer) {
+                            public OpenFuture open(long recipient, long rwsize, long rmpsize, Buffer buffer) {
                                 try {
                                     channelLatch.await();
                                 } catch (InterruptedException e) {
@@ -278,9 +278,9 @@ public class ClientTest extends BaseTestSupport {
             channels.add(session.createChannel(Channel.CHANNEL_EXEC, getCurrentTestName()));
             channels.add(session.createChannel(Channel.CHANNEL_SHELL, getClass().getSimpleName()));
 
-            Set<Integer> ids = new HashSet<>(channels.size());
+            Set<Long> ids = new HashSet<>(channels.size());
             for (ClientChannel c : channels) {
-                int id = c.getId();
+                long id = c.getId();
                 assertTrue("Channel ID repeated: " + id, ids.add(id));
             }
         } finally {
@@ -300,7 +300,7 @@ public class ClientTest extends BaseTestSupport {
     /**
      * Makes sure that the {@link ChannelListener}s added to the client, session and channel are <U>cumulative</U> -
      * i.e., all of them invoked
-     * 
+     *
      * @throws Exception If failed
      */
     @Test
diff --git a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/SftpTest.java b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/SftpTest.java
index ce4904d..f247ed5 100644
--- a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/SftpTest.java
+++ b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/SftpTest.java
@@ -519,7 +519,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
         buffer.putInt(SftpConstants.SSH_FILEXFER_ATTR_PERMISSIONS);
         buffer.putByte((byte) SftpConstants.SSH_FILEXFER_TYPE_REGULAR);
 
-        buffer.putInt(0);
+        buffer.putUInt(0L);
 
         int reqId = sftp.send(SftpConstants.SSH_FXP_OPEN, buffer);
         Buffer response = sftp.receive(reqId);
@@ -528,7 +528,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
     }
 
     private byte[] getRawFileHandle(Buffer buffer) {
-        buffer.getInt(); // length
+        buffer.getUInt(); // length
         int type = buffer.getUByte();
         assertEquals("Mismatched response type", SftpConstants.SSH_FXP_HANDLE, type);
         buffer.getInt(); // id

[mina-sshd] 05/05: Added support for quoted arguments in SftpCommandMain

Posted by lg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lgoldstein pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git

commit 82c95e18d3f9a0b960cd0a65b9cd2c37dc0d9d2e
Author: Lyor Goldstein <lg...@apache.org>
AuthorDate: Sat Feb 5 07:46:47 2022 +0200

    Added support for quoted arguments in SftpCommandMain
---
 .../main/java/org/apache/sshd/cli/CliSupport.java  | 72 +++++++++++++++++
 .../apache/sshd/cli/client/SftpCommandMain.java    | 43 +++-------
 .../CliSupportSplitCommandLineArgumentsTest.java   | 94 ++++++++++++++++++++++
 3 files changed, 179 insertions(+), 30 deletions(-)

diff --git a/sshd-cli/src/main/java/org/apache/sshd/cli/CliSupport.java b/sshd-cli/src/main/java/org/apache/sshd/cli/CliSupport.java
index f7306e7..e7cda7d 100644
--- a/sshd-cli/src/main/java/org/apache/sshd/cli/CliSupport.java
+++ b/sshd-cli/src/main/java/org/apache/sshd/cli/CliSupport.java
@@ -20,10 +20,14 @@ package org.apache.sshd.cli;
 
 import java.io.IOException;
 import java.io.PrintStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
 import java.net.SocketAddress;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.logging.Level;
@@ -341,4 +345,72 @@ public abstract class CliSupport {
 
         return new ArrayList<>(available);
     }
+
+    public static String[] splitCommandLineArguments(String line) {
+        line = GenericUtils.trimToEmpty(line);
+        if (GenericUtils.isBlank(line)) {
+            return GenericUtils.EMPTY_STRING_ARRAY;
+        }
+
+        Collection<String> args = Collections.emptyList();
+        for (int index = 0; index < GenericUtils.QUOTES.length(); index++) {
+            char delim = GenericUtils.QUOTES.charAt(index);
+            int startPos = line.indexOf(delim);
+            int endPos = -1;
+            if (startPos >= 0) {
+                endPos = line.indexOf(delim, startPos + 1);
+            }
+
+            if ((startPos >= 0) && (endPos > startPos)) {
+                if (GenericUtils.isEmpty(args)) {
+                    args = new LinkedList<>();
+                }
+
+                String prefix = (startPos > 0) ? line.substring(0, startPos).trim() : "";
+                String[] extra = GenericUtils.split(prefix, ' ');
+                if (!GenericUtils.isEmpty(extra)) {
+                    args.addAll(Arrays.asList(extra));
+                }
+
+                String value = line.substring(startPos + 1, endPos);
+                args.add(value);
+
+                line = (endPos < (line.length() - 1)) ? line.substring(endPos + 1).trim() : "";
+                if (GenericUtils.isBlank(line)) {
+                    break;
+                }
+
+                index = -1; // start delimiters again
+            }
+        }
+
+        // see if any leftovers
+        String[] extra = GenericUtils.split(line, ' ');
+        if (GenericUtils.isEmpty(args)) {
+            return extra;
+        }
+
+        if (!GenericUtils.isEmpty(extra)) {
+            if (GenericUtils.isEmpty(args)) {
+                args = new LinkedList<>();
+            }
+            args.addAll(Arrays.asList(extra));
+        }
+
+        return args.toArray(GenericUtils.EMPTY_STRING_ARRAY);
+    }
+
+    public static void printFieldsValues(Object info, PrintStream stdout) throws Exception {
+        Field[] fields = info.getClass().getFields();
+        for (Field f : fields) {
+            String name = f.getName();
+            int mod = f.getModifiers();
+            if (Modifier.isStatic(mod)) {
+                continue;
+            }
+
+            Object value = f.get(info);
+            stdout.append("    ").append(name).append(": ").println(value);
+        }
+    }
 }
diff --git a/sshd-cli/src/main/java/org/apache/sshd/cli/client/SftpCommandMain.java b/sshd-cli/src/main/java/org/apache/sshd/cli/client/SftpCommandMain.java
index 2e98012..e9e6a9c 100644
--- a/sshd-cli/src/main/java/org/apache/sshd/cli/client/SftpCommandMain.java
+++ b/sshd-cli/src/main/java/org/apache/sshd/cli/client/SftpCommandMain.java
@@ -26,8 +26,6 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.PrintStream;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
 import java.nio.channels.Channel;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.DirectoryStream;
@@ -44,6 +42,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.logging.Level;
 
 import org.apache.sshd.cli.CliLogger;
+import org.apache.sshd.cli.CliSupport;
 import org.apache.sshd.cli.client.helper.SftpFileTransferProgressOutputStream;
 import org.apache.sshd.client.ClientFactoryManager;
 import org.apache.sshd.client.session.ClientSession;
@@ -719,7 +718,7 @@ public class SftpCommandMain extends SshClientCliSupport implements SftpClientHo
         public boolean executeCommand(
                 String args, BufferedReader stdin, PrintStream stdout, PrintStream stderr)
                 throws Exception {
-            String[] comps = GenericUtils.split(args, ' ');
+            String[] comps = CliSupport.splitCommandLineArguments(args);
             int numComps = GenericUtils.length(comps);
             String pathArg = (numComps <= 0) ? null : GenericUtils.trimToEmpty(comps[numComps - 1]);
             String flags = (numComps >= 2) ? GenericUtils.trimToEmpty(comps[0]) : null;
@@ -763,7 +762,7 @@ public class SftpCommandMain extends SshClientCliSupport implements SftpClientHo
         public boolean executeCommand(
                 String args, BufferedReader stdin, PrintStream stdout, PrintStream stderr)
                 throws Exception {
-            String[] comps = GenericUtils.split(args, ' ');
+            String[] comps = CliSupport.splitCommandLineArguments(args);
             int numComps = GenericUtils.length(comps);
             String pathArg = (numComps <= 0) ? null : GenericUtils.trimToEmpty(comps[numComps - 1]);
             String flags = (numComps >= 2) ? GenericUtils.trimToEmpty(comps[0]) : null;
@@ -818,7 +817,7 @@ public class SftpCommandMain extends SshClientCliSupport implements SftpClientHo
         public boolean executeCommand(
                 String args, BufferedReader stdin, PrintStream stdout, PrintStream stderr)
                 throws Exception {
-            String[] comps = GenericUtils.split(args, ' ');
+            String[] comps = CliSupport.splitCommandLineArguments(args);
             int numArgs = GenericUtils.length(comps);
             ValidateUtils.checkTrue(numArgs >= 1, "No arguments");
             ValidateUtils.checkTrue(numArgs <= 2, "Too many arguments: %s", args);
@@ -932,7 +931,7 @@ public class SftpCommandMain extends SshClientCliSupport implements SftpClientHo
         public boolean executeCommand(
                 String args, BufferedReader stdin, PrintStream stdout, PrintStream stderr)
                 throws Exception {
-            String[] comps = GenericUtils.split(args, ' ');
+            String[] comps = CliSupport.splitCommandLineArguments(args);
             ValidateUtils.checkTrue(GenericUtils.length(comps) == 2, "Invalid number of arguments: %s", args);
 
             String oldPath = resolveRemotePath(GenericUtils.trimToEmpty(comps[0]));
@@ -959,7 +958,7 @@ public class SftpCommandMain extends SshClientCliSupport implements SftpClientHo
         public boolean executeCommand(
                 String args, BufferedReader stdin, PrintStream stdout, PrintStream stderr)
                 throws Exception {
-            String[] comps = GenericUtils.split(args, ' ');
+            String[] comps = CliSupport.splitCommandLineArguments(args);
             int numArgs = GenericUtils.length(comps);
             ValidateUtils.checkTrue(numArgs <= 1, "Invalid number of arguments: %s", args);
 
@@ -967,7 +966,7 @@ public class SftpCommandMain extends SshClientCliSupport implements SftpClientHo
             OpenSSHLimitsExtension ext = sftp.getExtension(OpenSSHLimitsExtension.class);
             ValidateUtils.checkTrue(ext.isSupported(), "Extension not supported by server: %s", ext.getName());
             OpenSSHLimitsExtensionInfo info = ext.limits();
-            printFieldsValues(info, stdout);
+            CliSupport.printFieldsValues(info, stdout);
             return false;
         }
     }
@@ -988,7 +987,7 @@ public class SftpCommandMain extends SshClientCliSupport implements SftpClientHo
         public boolean executeCommand(
                 String args, BufferedReader stdin, PrintStream stdout, PrintStream stderr)
                 throws Exception {
-            String[] comps = GenericUtils.split(args, ' ');
+            String[] comps = CliSupport.splitCommandLineArguments(args);
             int numArgs = GenericUtils.length(comps);
             ValidateUtils.checkTrue(numArgs <= 1, "Invalid number of arguments: %s", args);
 
@@ -999,7 +998,7 @@ public class SftpCommandMain extends SshClientCliSupport implements SftpClientHo
             String remPath = resolveRemotePath(
                     (numArgs >= 1) ? GenericUtils.trimToEmpty(comps[0]) : GenericUtils.trimToEmpty(args));
             OpenSSHStatExtensionInfo info = ext.stat(remPath);
-            printFieldsValues(info, stdout);
+            CliSupport.printFieldsValues(info, stdout);
             return false;
         }
     }
@@ -1020,7 +1019,7 @@ public class SftpCommandMain extends SshClientCliSupport implements SftpClientHo
         public boolean executeCommand(
                 String args, BufferedReader stdin, PrintStream stdout, PrintStream stderr)
                 throws Exception {
-            String[] comps = GenericUtils.split(args, ' ');
+            String[] comps = CliSupport.splitCommandLineArguments(args);
             ValidateUtils.checkTrue(GenericUtils.length(comps) <= 1, "Invalid number of arguments: %s", args);
 
             String path = GenericUtils.trimToEmpty(resolveRemotePath(args));
@@ -1046,7 +1045,7 @@ public class SftpCommandMain extends SshClientCliSupport implements SftpClientHo
         @Override
         public boolean executeCommand(String args, BufferedReader stdin, PrintStream stdout, PrintStream stderr)
                 throws Exception {
-            String[] comps = GenericUtils.split(args, ' ');
+            String[] comps = CliSupport.splitCommandLineArguments(args);
             ValidateUtils.checkTrue(GenericUtils.length(comps) <= 1, "Invalid number of arguments: %s", args);
 
             String path = GenericUtils.trimToEmpty(resolveRemotePath(args));
@@ -1202,7 +1201,7 @@ public class SftpCommandMain extends SshClientCliSupport implements SftpClientHo
         }
 
         protected void executeCommand(String args, boolean upload, PrintStream stdout) throws IOException {
-            String[] comps = GenericUtils.split(args, ' ');
+            String[] comps = CliSupport.splitCommandLineArguments(args);
             int numArgs = GenericUtils.length(comps);
             ValidateUtils.checkTrue((numArgs >= 1) && (numArgs <= 3), "Invalid number of arguments: %s", args);
 
@@ -1325,7 +1324,7 @@ public class SftpCommandMain extends SshClientCliSupport implements SftpClientHo
         public boolean executeCommand(
                 String args, BufferedReader stdin, PrintStream stdout, PrintStream stderr)
                 throws Exception {
-            String[] comps = GenericUtils.split(args, ' ');
+            String[] comps = CliSupport.splitCommandLineArguments(args);
             int numArgs = GenericUtils.length(comps);
             if (numArgs <= 0) {
                 stdout.append("    ").append(getName()).append(' ').println(isShowProgress() ? "on" : "off");
@@ -1345,20 +1344,4 @@ public class SftpCommandMain extends SshClientCliSupport implements SftpClientHo
             return false;
         }
     }
-
-    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-    public static void printFieldsValues(Object info, PrintStream stdout) throws Exception {
-        Field[] fields = info.getClass().getFields();
-        for (Field f : fields) {
-            String name = f.getName();
-            int mod = f.getModifiers();
-            if (Modifier.isStatic(mod)) {
-                continue;
-            }
-
-            Object value = f.get(info);
-            stdout.append("    ").append(name).append(": ").println(value);
-        }
-    }
 }
diff --git a/sshd-cli/src/test/java/org/apache/sshd/cli/CliSupportSplitCommandLineArgumentsTest.java b/sshd-cli/src/test/java/org/apache/sshd/cli/CliSupportSplitCommandLineArgumentsTest.java
new file mode 100644
index 0000000..dcdd29b
--- /dev/null
+++ b/sshd-cli/src/test/java/org/apache/sshd/cli/CliSupportSplitCommandLineArgumentsTest.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sshd.cli;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.sshd.common.util.GenericUtils;
+import org.apache.sshd.util.test.BaseTestSupport;
+import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory;
+import org.apache.sshd.util.test.NoIoTestCase;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.junit.runners.Parameterized.UseParametersRunnerFactory;
+
+/**
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+@Category({ NoIoTestCase.class })
+@RunWith(Parameterized.class) // see https://github.com/junit-team/junit/wiki/Parameterized-tests
+@UseParametersRunnerFactory(JUnit4ClassRunnerWithParametersFactory.class)
+public class CliSupportSplitCommandLineArgumentsTest extends BaseTestSupport {
+    private final String line;
+    private final String[] expected;
+
+    public CliSupportSplitCommandLineArgumentsTest(String line, String[] expected) {
+        this.line = line;
+        this.expected = expected;
+    }
+
+    @Parameters(name = "{0}")
+    public static List<Object[]> parameters() {
+        return new ArrayList<Object[]>() {
+            // not serializing it
+            private static final long serialVersionUID = 1L;
+
+            {
+                addTestCase(null, GenericUtils.EMPTY_STRING_ARRAY);
+                addTestCase("", GenericUtils.EMPTY_STRING_ARRAY);
+                addTestCase("   ", GenericUtils.EMPTY_STRING_ARRAY);
+                addPaddedTestCase("hello", "hello");
+                addPaddedTestCase("hello world", "hello", "world");
+
+                for (int index = 0; index < GenericUtils.QUOTES.length(); index++) {
+                    char delim = GenericUtils.QUOTES.charAt(index);
+                    addPaddedTestCase(delim + "hello world" + delim, "hello world");
+                    addPaddedTestCase(delim + "hello" + delim + " world", "hello", "world");
+                    addPaddedTestCase("hello " + delim + "world" + delim, "hello", "world");
+                    addPaddedTestCase(delim + "hello" + delim + " " + delim + "world" + delim, "hello", "world");
+                }
+            }
+
+            private void addPaddedTestCase(String line, String... expected) {
+                addTestCase(line, expected);
+                addTestCase("    " + line, expected);
+                addTestCase(line + "    ", expected);
+                addTestCase("    " + line + "    ", expected);
+            }
+
+            private void addTestCase(String line, String... expected) {
+                add(new Object[] { line, expected });
+            }
+        };
+    }
+
+    @Test
+    public void testSplitCommandLineArguments() {
+        String[] actual = CliSupport.splitCommandLineArguments(line);
+        assertArrayEquals(expected, actual);
+    }
+}

[mina-sshd] 04/05: Updated some SFTP related links in main README file

Posted by lg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lgoldstein pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git

commit 410b0e7c466d4a5d6c765adaa6c3fda466495342
Author: Lyor Goldstein <lg...@apache.org>
AuthorDate: Fri Feb 4 14:03:01 2022 +0200

    Updated some SFTP related links in main README file
---
 README.md | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md
index 2a3a1c0..b0caf12 100644
--- a/README.md
+++ b/README.md
@@ -41,16 +41,16 @@ based applications requiring SSH support.
 * [OpenSSH public-key certificate authentication system for use by SSH](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.certkeys)
 * [SSH proxy jumps](./docs/internals.md#ssh-jumps)
 * SFTP version 3-6 + extensions
-    * `supported` - [DRAFT 05 - section 4.4](http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-05.tx)
-    * `supported2` - [DRAFT 13 section 5.4](https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#page-10)
-    * `versions` - [DRAFT 09 Section 4.6](http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-09.txt)
-    * `vendor-id` - [DRAFT 09 - section 4.4](http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-09.txt)
-    * `acl-supported` - [DRAFT 11 - section 5.4](https://tools.ietf.org/html/draft-ietf-secsh-filexfer-11)
-    * `newline` - [DRAFT 09 Section 4.3](http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-09.txt)
-    * `md5-hash`, `md5-hash-handle` - [DRAFT 09 - section 9.1.1](http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-09.txt)
-    * `check-file-handle`, `check-file-name` - [DRAFT 09 - section 9.1.2](http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-09.txt)
+    * `supported` - [DRAFT 05 - section 4.4](https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-05#section-4.4)
+    * `supported2` - [DRAFT 13 section 5.4](https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-13#section-5.4)
+    * `versions` - [DRAFT 09 Section 4.6](https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-09#section-4.6)
+    * `vendor-id` - [DRAFT 09 - section 4.4](https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-09#section-4.4)
+    * `acl-supported` - [DRAFT 11 - section 5.4](https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-11#section-5.4)
+    * `newline` - [DRAFT 09 Section 4.3](https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-09#section-4.3)
+    * `md5-hash`, `md5-hash-handle` - [DRAFT 09 - section 9.1.1](https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-09#section-9.1.1)
+    * `check-file-handle`, `check-file-name` - [DRAFT 09 - section 9.1.2](https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-09#section-9.1.2)
     * `copy-file`, `copy-data` - [DRAFT 00 - sections 6, 7](http://tools.ietf.org/id/draft-ietf-secsh-filexfer-extensions-00.txt)
-    * `space-available` - [DRAFT 09 - section 9.3](http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-09.txt)
+    * `space-available` - [DRAFT 09 - section 9.2](https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-09#section-9.2)
     * `filename-charset`, `filename-translation-control` - [DRAFT 13 - section 6](https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-6) - only client side
     * Several [OpenSSH SFTP extensions](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL)
 * [Endless tarpit](https://nullprogram.com/blog/2019/03/22/) - see [HOWTO(s)](./docs/howto.md) section.
@@ -148,6 +148,20 @@ implementation of the logging API can be selected from the many existing adaptor
 
 # Quick reference
 
+## Building the code
+
+Including tests
+
+```
+mvn clean install
+```
+
+Without tests
+
+```
+mvn -Pquick clean install
+```
+
 ## [Set up an SSH client in 5 minutes](./docs/client-setup.md)
 
 ## [Embedding an SSHD server instance in 5 minutes](./docs/server-setup.md)

[mina-sshd] 01/05: [SSHD-1244] Fixed channel window adjustment handling of large UINT32 values

Posted by lg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lgoldstein pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git

commit a9f87e9dd91df8d993f3346336de2cfd6fb3e088
Author: Lyor Goldstein <lg...@apache.org>
AuthorDate: Fri Feb 4 08:09:16 2022 +0200

    [SSHD-1244] Fixed channel window adjustment handling of large UINT32 values
---
 CHANGES.md                                         |  2 ++
 pom.xml                                            |  1 +
 .../sshd/common/kex/extension/KexExtensions.java   |  2 +-
 .../kex/extension/parser/DelayCompression.java     |  2 +-
 .../signature/AbstractSecurityKeySignature.java    |  2 +-
 .../org/apache/sshd/common/util/buffer/Buffer.java | 17 ++++++++++----
 .../sshd/common/util/buffer/BufferUtils.java       |  4 ++--
 .../sshd/common/util/buffer/ByteArrayBuffer.java   |  2 +-
 .../apache/sshd/agent/SshAgentKeyConstraint.java   |  2 +-
 .../sshd/agent/common/AbstractAgentClient.java     | 10 ++++----
 .../sshd/agent/common/AbstractAgentProxy.java      |  4 ++--
 .../org/apache/sshd/agent/unix/AgentClient.java    |  2 +-
 .../auth/keyboard/UserAuthKeyboardInteractive.java |  2 +-
 .../client/channel/PtyCapableChannelSession.java   |  2 +-
 .../sshd/common/channel/AbstractChannel.java       |  4 ++--
 .../common/channel/ChannelAsyncOutputStream.java   |  2 +-
 .../sshd/common/channel/ChannelOutputStream.java   |  2 +-
 .../org/apache/sshd/common/channel/Window.java     |  8 +++----
 .../sshd/common/forward/DefaultForwarder.java      |  4 ++--
 .../common/session/helpers/AbstractSession.java    |  6 ++---
 .../org/apache/sshd/core/CoreModuleProperties.java | 10 +++++---
 .../server/auth/hostbased/UserAuthHostBased.java   |  2 +-
 .../server/auth/keyboard/InteractiveChallenge.java |  2 +-
 .../server/global/CancelTcpipForwardHandler.java   |  2 +-
 .../sshd/server/global/TcpipForwardHandler.java    |  2 +-
 .../session/helpers/AbstractSessionTest.java       |  6 ++---
 .../deprecated/UserAuthKeyboardInteractive.java    |  2 +-
 .../sshd/server/channel/ChannelSessionTest.java    | 27 +++++++++++++++++++++-
 .../helpers/AbstractCheckFileExtension.java        |  2 +-
 .../sshd/sftp/client/impl/AbstractSftpClient.java  |  4 ++--
 .../sshd/sftp/client/impl/DefaultSftpClient.java   | 10 ++++----
 .../sftp/client/impl/SftpInputStreamAsync.java     |  3 ++-
 .../sftp/client/impl/SftpOutputStreamAsync.java    |  2 +-
 .../org/apache/sshd/sftp/common/SftpHelper.java    |  6 ++---
 .../extensions/SpaceAvailableExtensionInfo.java    |  2 +-
 .../sftp/server/AbstractSftpSubsystemHelper.java   | 22 +++++++++---------
 .../org/apache/sshd/sftp/server/SftpSubsystem.java |  4 ++--
 .../client/impl/SftpRemotePathChannelTest.java     |  2 +-
 38 files changed, 115 insertions(+), 75 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index c884827..9063114 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -40,5 +40,7 @@ this value (though the choice of 256KB should be compatible with the vast majori
 
 * [SSHD-1231](https://issues.apache.org/jira/browse/SSHD-1231) Public key authentication: wrong signature algorithm used (ed25519 key with ssh-rsa signature)
 * [SSHD-1233](https://issues.apache.org/jira/browse/SSHD-1233) Added support for "limits@openssh.com" SFTP extension
+* [SSHD-1244](https://issues.apache.org/jira/browse/SSHD-1244) Fixed channel window adjustment handling of large UINT32 values
+
 
 
diff --git a/pom.xml b/pom.xml
index 1ec30dc..7e66769 100644
--- a/pom.xml
+++ b/pom.xml
@@ -111,6 +111,7 @@
         <slf4j.version>1.7.32</slf4j.version>
         <logback.version>1.2.9</logback.version>
         <spring.version>5.3.14</spring.version>
+            <!-- NOTE: upgrading to 6.x requires Java 11 -->
         <jgit.version>5.13.0.202109080827-r</jgit.version>
         <junit.version>4.13.2</junit.version>
         <bytebuddy.version>1.12.6</bytebuddy.version>
diff --git a/sshd-common/src/main/java/org/apache/sshd/common/kex/extension/KexExtensions.java b/sshd-common/src/main/java/org/apache/sshd/common/kex/extension/KexExtensions.java
index bc21f2e..af82982 100644
--- a/sshd-common/src/main/java/org/apache/sshd/common/kex/extension/KexExtensions.java
+++ b/sshd-common/src/main/java/org/apache/sshd/common/kex/extension/KexExtensions.java
@@ -172,7 +172,7 @@ public final class KexExtensions {
      */
     public static void putExtensions(Collection<? extends Map.Entry<String, ?>> exts, Buffer buffer) throws IOException {
         int count = GenericUtils.size(exts);
-        buffer.putInt(count);
+        buffer.putUInt(count);
         if (count <= 0) {
             return;
         }
diff --git a/sshd-common/src/main/java/org/apache/sshd/common/kex/extension/parser/DelayCompression.java b/sshd-common/src/main/java/org/apache/sshd/common/kex/extension/parser/DelayCompression.java
index 96a0c31..d09a654 100644
--- a/sshd-common/src/main/java/org/apache/sshd/common/kex/extension/parser/DelayCompression.java
+++ b/sshd-common/src/main/java/org/apache/sshd/common/kex/extension/parser/DelayCompression.java
@@ -48,7 +48,7 @@ public class DelayCompression extends AbstractKexExtensionParser<DelayedCompress
     @Override
     protected void encode(DelayedCompressionAlgorithms algos, Buffer buffer) throws IOException {
         int lenPos = buffer.wpos();
-        buffer.putInt(0); // total length placeholder
+        buffer.putUInt(0L); // total length placeholder
         buffer.putNameList(algos.getClient2Server());
         buffer.putNameList(algos.getServer2Client());
         BufferUtils.updateLengthPlaceholder(buffer, lenPos);
diff --git a/sshd-common/src/main/java/org/apache/sshd/common/signature/AbstractSecurityKeySignature.java b/sshd-common/src/main/java/org/apache/sshd/common/signature/AbstractSecurityKeySignature.java
index 66bebb2..f27ce1b 100644
--- a/sshd-common/src/main/java/org/apache/sshd/common/signature/AbstractSecurityKeySignature.java
+++ b/sshd-common/src/main/java/org/apache/sshd/common/signature/AbstractSecurityKeySignature.java
@@ -94,7 +94,7 @@ public abstract class AbstractSecurityKeySignature implements Signature {
         byte[] appNameDigest = md.digest(publicKey.getAppName().getBytes(StandardCharsets.UTF_8));
         byte[] challengeDigest = this.challengeDigest.digest();
         ByteArrayBuffer counterData = new ByteArrayBuffer(Integer.BYTES, false);
-        counterData.putInt(counter);
+        counterData.putUInt(counter);
 
         Signature delegate = getDelegateSignature();
         delegate.initVerifier(session, publicKey.getDelegatePublicKey());
diff --git a/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java b/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java
index 4c30537..c7c9df5 100644
--- a/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java
+++ b/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java
@@ -704,7 +704,14 @@ public abstract class Buffer implements Readable {
      * @param i The 32-bit value
      */
     public void putInt(long i) {
-        BufferUtils.validateInt32Value(i, "Invalid 32-bit value: %d");
+        BufferUtils.validateInt32Value(i, "Invalid INT32 value: %d");
+        ensureCapacity(Integer.BYTES);
+        BufferUtils.putUInt(i, workBuf, 0, Integer.BYTES);
+        putRawBytes(workBuf, 0, Integer.BYTES);
+    }
+
+    public void putUInt(long i) {
+        BufferUtils.validateUint32Value(i, "Invalid UINT32 value: %d");
         ensureCapacity(Integer.BYTES);
         BufferUtils.putUInt(i, workBuf, 0, Integer.BYTES);
         putRawBytes(workBuf, 0, Integer.BYTES);
@@ -755,7 +762,7 @@ public abstract class Buffer implements Readable {
     }
 
     public void putBytes(byte[] b, int off, int len) {
-        putInt(len);
+        putUInt(len);
         putRawBytes(b, off, len);
     }
 
@@ -783,7 +790,7 @@ public abstract class Buffer implements Readable {
     public void putStringList(Collection<?> objects, Charset charset, boolean prependLength) {
         int numObjects = GenericUtils.size(objects);
         if (prependLength) {
-            putInt(numObjects);
+            putUInt(numObjects);
         }
 
         if (numObjects <= 0) {
@@ -933,7 +940,7 @@ public abstract class Buffer implements Readable {
 
     public void putMPInt(byte[] mpInt) {
         if ((mpInt[0] & 0x80) != 0) {
-            putInt(mpInt.length + 1 /* padding */);
+            putUInt(mpInt.length + 1 /* padding */);
             putByte((byte) 0);
         } else {
             putInt(mpInt.length);
@@ -949,7 +956,7 @@ public abstract class Buffer implements Readable {
 
     public void putPublicKey(PublicKey key) {
         int ow = wpos();
-        putInt(0);
+        putUInt(0L);
         int ow1 = wpos();
         putRawPublicKey(key);
         int ow2 = wpos();
diff --git a/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java b/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java
index 2ee33a8..beaf150 100644
--- a/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java
+++ b/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java
@@ -644,7 +644,7 @@ public final class BufferUtils {
         // NOTE: although data length is defined as UINT32, we do not expected sizes above Integer.MAX_VALUE
         ValidateUtils.checkTrue(dataLength >= 0, "Illegal data length: %d", dataLength);
         buffer.wpos(lenPos);
-        buffer.putInt(dataLength);
+        buffer.putUInt(dataLength);
         buffer.wpos(endPos);
         return dataLength;
     }
@@ -661,7 +661,7 @@ public final class BufferUtils {
     public static void updateLengthPlaceholder(Buffer buffer, int lenPos, int dataLength) {
         int curPos = buffer.wpos();
         buffer.wpos(lenPos);
-        buffer.putInt(dataLength);
+        buffer.putUInt(dataLength);
         buffer.wpos(curPos);
     }
 
diff --git a/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/ByteArrayBuffer.java b/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/ByteArrayBuffer.java
index 04085ed..3efa761 100644
--- a/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/ByteArrayBuffer.java
+++ b/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/ByteArrayBuffer.java
@@ -220,7 +220,7 @@ public class ByteArrayBuffer extends Buffer {
     public void putBuffer(ByteBuffer buffer) {
         int required = buffer.remaining();
         ensureCapacity(required + Integer.SIZE);
-        putInt(required);
+        putUInt(required);
         buffer.get(data, wpos, required);
         wpos += required;
     }
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentKeyConstraint.java b/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentKeyConstraint.java
index 20bafea..c5f5c57 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentKeyConstraint.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentKeyConstraint.java
@@ -96,7 +96,7 @@ public abstract class SshAgentKeyConstraint {
         @Override
         public void put(Buffer buffer) {
             super.put(buffer);
-            buffer.putInt(secondsToLive);
+            buffer.putUInt(secondsToLive);
         }
     }
 
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentClient.java b/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentClient.java
index 520068c..970c86e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentClient.java
@@ -71,7 +71,7 @@ public abstract class AbstractAgentClient extends AbstractLoggingBean {
         }
 
         Buffer rep = new ByteArrayBuffer();
-        rep.putInt(0);
+        rep.putUInt(0L);
         rep.rpos(rep.wpos());
 
         Buffer req = new ByteArrayBuffer(buffer.getBytes());
@@ -83,9 +83,9 @@ public abstract class AbstractAgentClient extends AbstractLoggingBean {
             debug("Failed ({}) to handle command={}: {}",
                     e.getClass().getSimpleName(), cmd, e.getMessage(), e);
             rep.clear();
-            rep.putInt(0);
+            rep.putUInt(0L);
             rep.rpos(rep.wpos());
-            rep.putInt(1);
+            rep.putUInt(1L);
             rep.putByte(SshAgentConstants.SSH2_AGENT_FAILURE);
         }
         reply(prepare(rep));
@@ -111,7 +111,7 @@ public abstract class AbstractAgentClient extends AbstractLoggingBean {
                 }
 
                 rep.putByte(SshAgentConstants.SSH2_AGENT_IDENTITIES_ANSWER);
-                rep.putInt(keys.size());
+                rep.putUInt(keys.size());
                 for (Map.Entry<PublicKey, String> key : keys) {
                     rep.putPublicKey(key.getKey());
                     rep.putString(key.getValue());
@@ -178,7 +178,7 @@ public abstract class AbstractAgentClient extends AbstractLoggingBean {
         int wpos = buf.wpos();
         buf.rpos(rpos - 4);
         buf.wpos(rpos - 4);
-        buf.putInt(len);
+        buf.putUInt(len);
         buf.wpos(wpos);
         return buf;
     }
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentProxy.java b/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentProxy.java
index 428d07a..a0fa391 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentProxy.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentProxy.java
@@ -253,7 +253,7 @@ public abstract class AbstractAgentProxy extends AbstractLoggingBean implements
 
     protected Buffer createBuffer(byte cmd, int extraLen) {
         Buffer buffer = new ByteArrayBuffer((extraLen <= 0) ? ByteArrayBuffer.DEFAULT_SIZE : extraLen + Byte.SIZE, false);
-        buffer.putInt(0);
+        buffer.putUInt(0L);
         buffer.putByte(cmd);
         return buffer;
     }
@@ -261,7 +261,7 @@ public abstract class AbstractAgentProxy extends AbstractLoggingBean implements
     protected Buffer prepare(Buffer buffer) {
         int wpos = buffer.wpos();
         buffer.wpos(0);
-        buffer.putInt(wpos - 4);
+        buffer.putUInt(wpos - 4);
         buffer.wpos(wpos);
         return buffer;
     }
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentClient.java b/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentClient.java
index ab0966a..7d9ac35 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentClient.java
@@ -195,7 +195,7 @@ public class AgentClient extends AbstractAgentProxy implements Runnable, Factory
     protected synchronized Buffer request(Buffer buffer) throws IOException {
         int wpos = buffer.wpos();
         buffer.wpos(0);
-        buffer.putInt(wpos - 4);
+        buffer.putUInt(wpos - 4);
         buffer.wpos(wpos);
         synchronized (messages) {
             int result = Socket.send(handle, buffer.array(), buffer.rpos(), buffer.available());
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/keyboard/UserAuthKeyboardInteractive.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/keyboard/UserAuthKeyboardInteractive.java
index ccb942a..412c894 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/keyboard/UserAuthKeyboardInteractive.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/keyboard/UserAuthKeyboardInteractive.java
@@ -174,7 +174,7 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth {
         int numResponses = rep.length;
         buffer = session.createBuffer(
                 SshConstants.SSH_MSG_USERAUTH_INFO_RESPONSE, numResponses * Long.SIZE + Byte.SIZE);
-        buffer.putInt(numResponses);
+        buffer.putUInt(numResponses);
         for (int index = 0; index < numResponses; index++) {
             String r = rep[index];
             if (traceEnabled) {
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
index 88f8f03..214a6d9 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
@@ -281,7 +281,7 @@ public class PtyCapableChannelSession extends ChannelSession implements PtyChann
             if (numModes > 0) {
                 ptyModes.forEach((mode, value) -> {
                     modes.putByte((byte) mode.toInt());
-                    modes.putInt(value.longValue());
+                    modes.putUInt(value.longValue());
                 });
             }
             modes.putByte(PtyMode.TTY_OP_END);
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
index 1bf627e..69c6d24 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
@@ -885,7 +885,7 @@ public abstract class AbstractChannel extends AbstractInnerCloseable implements
 
     @Override
     public void handleWindowAdjust(Buffer buffer) throws IOException {
-        int window = buffer.getInt();
+        long window = buffer.getUInt();
         if (log.isDebugEnabled()) {
             log.debug("handleWindowAdjust({}) SSH_MSG_CHANNEL_WINDOW_ADJUST window={}", this, window);
         }
@@ -1013,7 +1013,7 @@ public abstract class AbstractChannel extends AbstractInnerCloseable implements
         Session s = getSession();
         Buffer buffer = s.createBuffer(SshConstants.SSH_MSG_CHANNEL_WINDOW_ADJUST, Short.SIZE);
         buffer.putInt(getRecipient());
-        buffer.putInt(len);
+        buffer.putUInt(len);
         writePacket(buffer);
     }
 
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java
index 84fbf34..81844a6 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java
@@ -261,7 +261,7 @@ public class ChannelAsyncOutputStream extends AbstractCloseable implements IoOut
         if (cmd == SshConstants.SSH_MSG_CHANNEL_EXTENDED_DATA) {
             buf.putInt(SshConstants.SSH_EXTENDED_DATA_STDERR);
         }
-        buf.putInt(length);
+        buf.putUInt(length);
         buf.putRawBytes(buffer.array(), buffer.rpos(), (int) length);
         buffer.rpos(buffer.rpos() + (int) length);
         return buf;
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java
index 2937c7d..ec08f8a 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java
@@ -230,7 +230,7 @@ public class ChannelOutputStream extends OutputStream implements java.nio.channe
 
                 int pos = buf.wpos();
                 buf.wpos((cmd == SshConstants.SSH_MSG_CHANNEL_EXTENDED_DATA) ? 14 : 10);
-                buf.putInt(length);
+                buf.putUInt(length);
                 buf.wpos(buf.wpos() + (int) length);
                 if (total == length) {
                     newBuffer((int) length);
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/Window.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/Window.java
index 9b175c6..2bb3d8b 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/Window.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/Window.java
@@ -119,8 +119,8 @@ public class Window extends AbstractLoggingBean implements java.nio.channels.Cha
         }
     }
 
-    public void expand(int window) {
-        ValidateUtils.checkTrue(window >= 0, "Negative window size: %d", window);
+    public void expand(long window) {
+        BufferUtils.validateUint32Value(window, "Invalid expansion window size: %d");
         checkInitialized("expand");
 
         long expandedSize;
@@ -128,8 +128,8 @@ public class Window extends AbstractLoggingBean implements java.nio.channels.Cha
             /*
              * See RFC-4254 section 5.2:
              *
-             * "Implementations MUST correctly handle window sizes of up to 2^32 - 1 bytes. The window MUST NOT be
-             * increased above 2^32 - 1 bytes.
+             * "Implementations MUST correctly handle window sizes of up to 2^32 - 1 bytes.
+             * The window MUST NOT be increased above 2^32 - 1 bytes.
              */
             expandedSize = size + window;
             if (expandedSize > BufferUtils.MAX_UINT32_VALUE) {
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultForwarder.java b/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultForwarder.java
index 1c25ec1..df46433 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultForwarder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultForwarder.java
@@ -292,7 +292,7 @@ public class DefaultForwarder
         buffer.putString("tcpip-forward");
         buffer.putBoolean(true); // want reply
         buffer.putString(remoteHost);
-        buffer.putInt(remotePort);
+        buffer.putUInt(remotePort);
 
         Duration timeout = CoreModuleProperties.FORWARD_REQUEST_TIMEOUT.getRequired(session);
         Buffer result;
@@ -358,7 +358,7 @@ public class DefaultForwarder
             buffer.putString("cancel-tcpip-forward");
             buffer.putBoolean(false); // want reply
             buffer.putString(remoteHost);
-            buffer.putInt(port);
+            buffer.putUInt(port);
 
             signalTearingDownExplicitTunnel(bound, false, remote);
             try {
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java
index 08e5d7e..17023d7 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java
@@ -1013,7 +1013,7 @@ public abstract class AbstractSession extends SessionHelper {
         int ignoreDataLen = resolveIgnoreBufferDataLength();
         if (ignoreDataLen > 0) {
             ignoreBuf = createBuffer(SshConstants.SSH_MSG_IGNORE, ignoreDataLen + Byte.SIZE);
-            ignoreBuf.putInt(ignoreDataLen);
+            ignoreBuf.putUInt(ignoreDataLen);
 
             int wpos = ignoreBuf.wpos();
             synchronized (random) {
@@ -1315,7 +1315,7 @@ public abstract class AbstractSession extends SessionHelper {
 
             // Write 5 header bytes
             buffer.wpos(off);
-            buffer.putInt(len);
+            buffer.putUInt(len);
             buffer.putByte((byte) pad);
             // Make sure enough room for padding and then fill it
             buffer.wpos(off + oldLen + SshConstants.SSH_PACKET_HEADER_LEN + pad);
@@ -1600,7 +1600,7 @@ public abstract class AbstractSession extends SessionHelper {
         }
 
         buffer.putBoolean(false); // first kex packet follows
-        buffer.putInt(0); // reserved (FFU)
+        buffer.putUInt(0L); // reserved (FFU)
 
         ReservedSessionMessagesHandler handler = getReservedSessionMessagesHandler();
         IoWriteFuture future = (handler == null) ? null : handler.sendKexInitRequest(this, proposal, buffer);
diff --git a/sshd-core/src/main/java/org/apache/sshd/core/CoreModuleProperties.java b/sshd-core/src/main/java/org/apache/sshd/core/CoreModuleProperties.java
index 71cb4f8..efa7d5f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/core/CoreModuleProperties.java
+++ b/sshd-core/src/main/java/org/apache/sshd/core/CoreModuleProperties.java
@@ -265,11 +265,13 @@ public final class CoreModuleProperties {
     public static final Property<Integer> PROP_DHGEX_CLIENT_PRF_KEY
             = Property.integer("dhgex-client-prf");
 
+    public static final long DEFAULT_WINDOW_SIZE = 0x200000L;
+
     /**
      * Key used to retrieve the value of the channel window size in the configuration properties map.
      */
     public static final Property<Long> WINDOW_SIZE
-            = Property.long_("window-size", 0x200000L);
+            = Property.long_("window-size", DEFAULT_WINDOW_SIZE);
 
     /**
      * Key used to retrieve timeout (msec.) to wait for data to become available when reading from a channel. If not set
@@ -296,17 +298,19 @@ public final class CoreModuleProperties {
     public static final Property<Duration> BUFFERED_IO_OUTPUT_MAX_PENDING_WRITE_WAIT
             = Property.duration("buffered-io-output-max-pending-write-wait", Duration.ofSeconds(30L));
 
+    public static final long DEFAULT_MAX_PACKET_SIZE = 0x8000L;
     /**
      * Key used to retrieve the value of the maximum packet size in the configuration properties map.
      */
     public static final Property<Long> MAX_PACKET_SIZE
-            = Property.long_("packet-size", 0x8000L);
+            = Property.long_("packet-size", DEFAULT_MAX_PACKET_SIZE);
 
+    public static final long DEFAULT_LIMIT_PACKET_SIZE = Integer.MAX_VALUE / 4L;
     /**
      * A safety value that is designed to avoid an attack that uses large channel packet sizes
      */
     public static final Property<Long> LIMIT_PACKET_SIZE
-            = Property.long_("max-packet-size", Integer.MAX_VALUE / 4L);
+            = Property.long_("max-packet-size", DEFAULT_LIMIT_PACKET_SIZE);
 
     /**
      * Number of NIO worker threads to use.
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/hostbased/UserAuthHostBased.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/hostbased/UserAuthHostBased.java
index db3cdb8..6082f6e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/hostbased/UserAuthHostBased.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/hostbased/UserAuthHostBased.java
@@ -164,7 +164,7 @@ public class UserAuthHostBased extends AbstractUserAuth implements SignatureFact
         buf.putString(getService());
         buf.putString(getName());
         buf.putString(keyType);
-        buf.putInt(keyLen);
+        buf.putUInt(keyLen);
         // copy the key + certificates
         buf.putRawBytes(buffer.array(), keyOffset, keyLen);
         buf.putString(clientHostName);
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/InteractiveChallenge.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/InteractiveChallenge.java
index 24053f8..6c64a29 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/InteractiveChallenge.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/InteractiveChallenge.java
@@ -98,7 +98,7 @@ public class InteractiveChallenge implements Cloneable {
 
         List<PromptEntry> entries = getPrompts();
         int numEntries = GenericUtils.size(entries);
-        buffer.putInt(numEntries);
+        buffer.putUInt(numEntries);
 
         for (int index = 0; index < numEntries; index++) {
             PromptEntry e = entries.get(index);
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java b/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
index a2fc226..0b7da84 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
@@ -70,7 +70,7 @@ public class CancelTcpipForwardHandler extends AbstractConnectionServiceRequestH
         if (wantReply) {
             Session session = connectionService.getSession();
             buffer = session.createBuffer(SshConstants.SSH_MSG_REQUEST_SUCCESS, Integer.BYTES);
-            buffer.putInt(port);
+            buffer.putUInt(port);
             session.writePacket(buffer);
         }
 
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java b/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
index b64d1b2..db983fd 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
@@ -76,7 +76,7 @@ public class TcpipForwardHandler extends AbstractConnectionServiceRequestHandler
         if (wantReply) {
             Session session = connectionService.getSession();
             buffer = session.createBuffer(SshConstants.SSH_MSG_REQUEST_SUCCESS, Integer.BYTES);
-            buffer.putInt(port);
+            buffer.putUInt(port);
             session.writePacket(buffer);
         }
 
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/session/helpers/AbstractSessionTest.java b/sshd-core/src/test/java/org/apache/sshd/common/session/helpers/AbstractSessionTest.java
index a143cab..a0c3d53 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/session/helpers/AbstractSessionTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/session/helpers/AbstractSessionTest.java
@@ -250,7 +250,7 @@ public class AbstractSessionTest extends BaseTestSupport {
         });
 
         Buffer buffer = new ByteArrayBuffer(Long.SIZE + Byte.MAX_VALUE);
-        buffer.putInt(Byte.MAX_VALUE + 1); // bad message length
+        buffer.putUInt(Byte.MAX_VALUE + 1L); // bad message length
         for (int index = 0; index < Byte.MAX_VALUE; index++) {
             buffer.putByte((byte) index);
             session.handleIgnore(buffer);
@@ -272,7 +272,7 @@ public class AbstractSessionTest extends BaseTestSupport {
         buffer.putBoolean(true);
         session.handleDebug(buffer); // no message field
 
-        buffer.putInt(Byte.MAX_VALUE + 1); // bad message field length
+        buffer.putUInt(Byte.MAX_VALUE + 1L); // bad message field length
         for (int index = 0; index < Byte.MAX_VALUE; index++) {
             buffer.putByte((byte) index);
             session.handleDebug(buffer);
@@ -293,7 +293,7 @@ public class AbstractSessionTest extends BaseTestSupport {
         buffer.putString(getCurrentTestName());
         session.handleDebug(buffer); // no language tag
 
-        buffer.putInt(Byte.SIZE + 1); // bad language tag length
+        buffer.putUInt(Byte.SIZE + 1L); // bad language tag length
         for (int index = 0; index < Byte.SIZE; index++) {
             buffer.putByte((byte) index);
             session.handleDebug(buffer);
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java
index d334846..1b0b3de 100644
--- a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java
@@ -109,7 +109,7 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth {
                     }
 
                     buffer = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_INFO_RESPONSE);
-                    buffer.putInt(rep.length);
+                    buffer.putUInt(rep.length);
                     for (String r : rep) {
                         buffer.putString(r);
                     }
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/channel/ChannelSessionTest.java b/sshd-core/src/test/java/org/apache/sshd/server/channel/ChannelSessionTest.java
index b9caf27..803b6c1 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/channel/ChannelSessionTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/channel/ChannelSessionTest.java
@@ -38,7 +38,9 @@ import org.apache.sshd.common.channel.Channel;
 import org.apache.sshd.common.channel.ChannelAsyncOutputStream;
 import org.apache.sshd.common.channel.Window;
 import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.BufferUtils;
 import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
+import org.apache.sshd.core.CoreModuleProperties;
 import org.apache.sshd.server.SshServer;
 import org.apache.sshd.util.test.BaseTestSupport;
 import org.apache.sshd.util.test.BogusChannel;
@@ -109,7 +111,7 @@ public class ChannelSessionTest extends BaseTestSupport {
     @Test
     public void testHandleWindowAdjust() throws Exception {
         Buffer buffer = new ByteArrayBuffer();
-        buffer.putInt(1234);
+        buffer.putUInt(1234L);
 
         try (ChannelSession channelSession = new ChannelSession() {
             {
@@ -148,4 +150,27 @@ public class ChannelSessionTest extends BaseTestSupport {
 
         assertEquals("Close listener not called", 1, closeCount.get());
     }
+
+    @Test   // SSHD-1244
+    public void testLargeWindowSizeAdjust() throws Exception {
+        try (ChannelSession session = new ChannelSession() {
+            {
+                Window wRemote = getRemoteWindow();
+                wRemote.init(PropertyResolverUtils.toPropertyResolver(Collections.emptyMap()));
+            }
+        }) {
+            Window wRemote = session.getRemoteWindow();
+            long initialSize = wRemote.getSize();
+            assertTrue("Bad initial window size: " + initialSize,
+                    (initialSize >= CoreModuleProperties.DEFAULT_WINDOW_SIZE)
+                            && (initialSize < BufferUtils.MAX_UINT32_VALUE));
+
+            Buffer buffer = new ByteArrayBuffer();
+            buffer.putUInt(BufferUtils.MAX_UINT32_VALUE);
+            session.handleWindowAdjust(buffer);
+
+            long updatedSize = wRemote.getSize();
+            assertEquals("Mismatched updated window size", BufferUtils.MAX_UINT32_VALUE, updatedSize);
+        }
+    }
 }
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/extensions/helpers/AbstractCheckFileExtension.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/extensions/helpers/AbstractCheckFileExtension.java
index 3a1aefc..bc2cf06 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/extensions/helpers/AbstractCheckFileExtension.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/extensions/helpers/AbstractCheckFileExtension.java
@@ -48,7 +48,7 @@ public abstract class AbstractCheckFileExtension extends AbstractSftpClientExten
         buffer.putString(GenericUtils.join(algorithms, ','));
         buffer.putLong(offset);
         buffer.putLong(length);
-        buffer.putInt(blockSize);
+        buffer.putUInt(blockSize);
 
         if (log.isDebugEnabled()) {
             log.debug("doGetHash({})[{}] - offset={}, length={}, block-size={}",
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/AbstractSftpClient.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/AbstractSftpClient.java
index cef3a6e..78f0b2f 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/AbstractSftpClient.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/AbstractSftpClient.java
@@ -660,7 +660,7 @@ public abstract class AbstractSftpClient
         Buffer buffer = new ByteArrayBuffer(id.length + Long.SIZE /* some extra fields */, false);
         buffer.putBytes(id);
         buffer.putLong(fileOffset);
-        buffer.putInt(len);
+        buffer.putUInt(len);
         return checkData(SftpConstants.SSH_FXP_READ, buffer, dstOffset, dst, eofSignalled);
     }
 
@@ -795,7 +795,7 @@ public abstract class AbstractSftpClient
 
         Buffer buffer = new ByteArrayBuffer(path.length() + Long.SIZE /* some extra fields */, false);
         buffer = putReferencedName(SftpConstants.SSH_FXP_MKDIR, buffer, path, 0);
-        buffer.putInt(0);
+        buffer.putUInt(0L);
 
         int version = getVersion();
         if (version != SftpConstants.SFTP_V3) {
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/DefaultSftpClient.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/DefaultSftpClient.java
index 21f21ac..a543a61 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/DefaultSftpClient.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/DefaultSftpClient.java
@@ -282,14 +282,14 @@ public class DefaultSftpClient extends AbstractSftpClient {
             int s = buffer.rpos() - hdr;
             buffer.rpos(s);
             buffer.wpos(s);
-            buffer.putInt(1 /* cmd */ + Integer.BYTES /* id */ + len); // length
+            buffer.putUInt(1 /* cmd */ + Integer.BYTES /* id */ + len); // length
             buffer.putByte((byte) (cmd & 0xFF)); // cmd
-            buffer.putInt(id); // id
+            buffer.putInt(id);
             buffer.wpos(wpos);
             buf = buffer;
         } else {
             buf = new ByteArrayBuffer(hdr + len);
-            buf.putInt(1 /* cmd */ + Integer.BYTES /* id */ + len);
+            buf.putUInt(1 /* cmd */ + Integer.BYTES /* id */ + len);
             buf.putByte((byte) (cmd & 0xFF));
             buf.putInt(id);
             buf.putBuffer(buffer);
@@ -367,9 +367,9 @@ public class DefaultSftpClient extends AbstractSftpClient {
 
         // Send init packet
         Buffer buf = new ByteArrayBuffer(INIT_COMMAND_SIZE + SshConstants.SSH_PACKET_HEADER_LEN);
-        buf.putInt(INIT_COMMAND_SIZE);
+        buf.putUInt(INIT_COMMAND_SIZE);
         buf.putByte((byte) SftpConstants.SSH_FXP_INIT);
-        buf.putInt(initialVersion);
+        buf.putUInt(initialVersion);
 
         boolean traceEnabled = log.isTraceEnabled();
         ClientChannel clientChannel = getClientChannel();
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/SftpInputStreamAsync.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/SftpInputStreamAsync.java
index 3c822e8..a4083f4 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/SftpInputStreamAsync.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/SftpInputStreamAsync.java
@@ -155,6 +155,7 @@ public class SftpInputStreamAsync extends InputStreamWithChannel implements Sftp
         return numXfered;
     }
 
+    @Override
     @SuppressWarnings("PMD.MissingOverride")
     public long transferTo(OutputStream out) throws IOException {
         if (!isOpen()) {
@@ -236,7 +237,7 @@ public class SftpInputStreamAsync extends InputStreamWithChannel implements Sftp
             buf.wpos(23);
             buf.putBytes(id);
             buf.putLong(requestOffset);
-            buf.putInt(bufferSize);
+            buf.putUInt(bufferSize);
             int reqId = client.send(SftpConstants.SSH_FXP_READ, buf);
             SftpAckData ack = new SftpAckData(reqId, requestOffset, bufferSize);
             if (traceEnabled) {
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/SftpOutputStreamAsync.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/SftpOutputStreamAsync.java
index db6147e..3de58d9 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/SftpOutputStreamAsync.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/SftpOutputStreamAsync.java
@@ -194,7 +194,7 @@ public class SftpOutputStreamAsync extends OutputStreamWithChannel implements Sf
             buffer.wpos(buffer.rpos());
             buffer.putBytes(id);
             buffer.putLong(offset);
-            buffer.putInt(avail);
+            buffer.putUInt(avail);
             buffer.wpos(wpos);
             buf = buffer;
         } else {
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/SftpHelper.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/SftpHelper.java
index 5de859d..a394150 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/SftpHelper.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/SftpHelper.java
@@ -795,7 +795,7 @@ public final class SftpHelper {
 
     public static <B extends Buffer> B writeExtensions(B buffer, Map<?, ?> extensions) {
         int numExtensions = MapEntryUtils.size(extensions);
-        buffer.putInt(numExtensions);
+        buffer.putUInt(numExtensions);
         if (numExtensions <= 0) {
             return buffer;
         }
@@ -1005,7 +1005,7 @@ public final class SftpHelper {
 
     public static <B extends Buffer> B writeACLs(B buffer, int version, Collection<? extends AclEntry> acl) {
         int lenPos = buffer.wpos();
-        buffer.putInt(0); // length placeholder
+        buffer.putUInt(0L); // length placeholder
         buffer = encodeACLs(buffer, version, acl);
         BufferUtils.updateLengthPlaceholder(buffer, lenPos);
         return buffer;
@@ -1014,7 +1014,7 @@ public final class SftpHelper {
     public static <B extends Buffer> B encodeACLs(B buffer, int version, Collection<? extends AclEntry> acl) {
         Objects.requireNonNull(acl, "No ACL");
         if (version >= SftpConstants.SFTP_V6) {
-            buffer.putInt(0); // TODO handle ACL flags
+            buffer.putUInt(0L); // TODO handle ACL flags
         }
 
         int numEntries = GenericUtils.size(acl);
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/extensions/SpaceAvailableExtensionInfo.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/extensions/SpaceAvailableExtensionInfo.java
index 961bc25..abc7fe7 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/extensions/SpaceAvailableExtensionInfo.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/extensions/SpaceAvailableExtensionInfo.java
@@ -121,6 +121,6 @@ public class SpaceAvailableExtensionInfo implements Cloneable {
         buffer.putLong(info.unusedBytesOnDevice);
         buffer.putLong(info.bytesAvailableToUser);
         buffer.putLong(info.unusedBytesAvailableToUser);
-        buffer.putInt(info.bytesPerAllocationUnit & 0xFFFFFFFFL);
+        buffer.putUInt(info.bytesPerAllocationUnit & 0xFFFFFFFFL);
     }
 }
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java
index b3e32bf..ba8ca69 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java
@@ -1847,7 +1847,7 @@ public abstract class AbstractSftpSubsystemHelper
 
             // placeholder for length
             int lenPos = buffer.wpos();
-            buffer.putInt(0);
+            buffer.putUInt(0L);
             buffer.putInt(mask);
             BufferUtils.updateLengthPlaceholder(buffer, lenPos);
         }
@@ -2053,7 +2053,7 @@ public abstract class AbstractSftpSubsystemHelper
                 Collections.unmodifiableMap(versionProperties));
         // placeholder for length
         int lenPos = buffer.wpos();
-        buffer.putInt(0);
+        buffer.putUInt(0L);
         buffer.putString(resolver.getStringProperty("groupId", getClass().getPackage().getName())); // vendor-name
         buffer.putString(resolver.getStringProperty("artifactId", getClass().getSimpleName())); // product-name
         buffer.putString(resolver.getStringProperty("version", FactoryManager.DEFAULT_VERSION)); // product-version
@@ -2073,21 +2073,21 @@ public abstract class AbstractSftpSubsystemHelper
         buffer.putString(SftpConstants.EXT_SUPPORTED);
 
         int lenPos = buffer.wpos();
-        buffer.putInt(0); // length placeholder
+        buffer.putUInt(0L); // length placeholder
         // supported-attribute-mask
         buffer.putInt(SftpConstants.SSH_FILEXFER_ATTR_SIZE | SftpConstants.SSH_FILEXFER_ATTR_PERMISSIONS
                       | SftpConstants.SSH_FILEXFER_ATTR_ACCESSTIME | SftpConstants.SSH_FILEXFER_ATTR_CREATETIME
                       | SftpConstants.SSH_FILEXFER_ATTR_MODIFYTIME | SftpConstants.SSH_FILEXFER_ATTR_OWNERGROUP
                       | SftpConstants.SSH_FILEXFER_ATTR_BITS);
         // TODO: supported-attribute-bits
-        buffer.putInt(0);
+        buffer.putUInt(0L);
         // supported-open-flags
         buffer.putInt(SftpConstants.SSH_FXF_READ | SftpConstants.SSH_FXF_WRITE | SftpConstants.SSH_FXF_APPEND
                       | SftpConstants.SSH_FXF_CREAT | SftpConstants.SSH_FXF_TRUNC | SftpConstants.SSH_FXF_EXCL);
         // TODO: supported-access-mask
-        buffer.putInt(0);
+        buffer.putUInt(0L);
         // max-read-size
-        buffer.putInt(0);
+        buffer.putUInt(0L);
         // supported extensions
         buffer.putStringList(extras, false);
 
@@ -2108,20 +2108,20 @@ public abstract class AbstractSftpSubsystemHelper
         buffer.putString(SftpConstants.EXT_SUPPORTED2);
 
         int lenPos = buffer.wpos();
-        buffer.putInt(0); // length placeholder
+        buffer.putUInt(0L); // length placeholder
         // supported-attribute-mask
         buffer.putInt(SftpConstants.SSH_FILEXFER_ATTR_SIZE | SftpConstants.SSH_FILEXFER_ATTR_PERMISSIONS
                       | SftpConstants.SSH_FILEXFER_ATTR_ACCESSTIME | SftpConstants.SSH_FILEXFER_ATTR_CREATETIME
                       | SftpConstants.SSH_FILEXFER_ATTR_MODIFYTIME | SftpConstants.SSH_FILEXFER_ATTR_OWNERGROUP
                       | SftpConstants.SSH_FILEXFER_ATTR_BITS);
         // TODO: supported-attribute-bits
-        buffer.putInt(0);
+        buffer.putUInt(0L);
         // supported-open-flags
         buffer.putInt(SftpConstants.SSH_FXF_ACCESS_DISPOSITION | SftpConstants.SSH_FXF_APPEND_DATA);
         // TODO: supported-access-mask
-        buffer.putInt(0);
+        buffer.putUInt(0L);
         // max-read-size
-        buffer.putInt(0);
+        buffer.putUInt(0L);
         // supported-open-block-vector
         buffer.putShort(0);
         // supported-block-vector
@@ -2151,7 +2151,7 @@ public abstract class AbstractSftpSubsystemHelper
     protected void sendLink(Buffer buffer, int id, Path file, String link) throws IOException {
         buffer.putByte((byte) SftpConstants.SSH_FXP_NAME);
         buffer.putInt(id);
-        buffer.putInt(1); // one response
+        buffer.putUInt(1L); // one response
 
         // in case we are running on Windows
         String unixPath = link.replace(File.separatorChar, '/');
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystem.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystem.java
index 34421cb..fdd4bae 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystem.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystem.java
@@ -991,7 +991,7 @@ public class SftpSubsystem
         buffer = prepareReply(buffer);
 
         buffer.putByte((byte) SftpConstants.SSH_FXP_VERSION);
-        buffer.putInt(version);
+        buffer.putUInt(version);
         appendExtensions(buffer, negotiated.getValue());
 
         SftpEventListener listener = getSftpEventListenerProxy();
@@ -1003,7 +1003,7 @@ public class SftpSubsystem
     @Override
     protected Buffer prepareReply(Buffer buffer) {
         buffer.clear();
-        buffer.putInt(0); // reserve space for actual packet length
+        buffer.putUInt(0L); // reserve space for actual packet length
         return buffer;
     }
 
diff --git a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/impl/SftpRemotePathChannelTest.java b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/impl/SftpRemotePathChannelTest.java
index bdabd91..62fba0b 100644
--- a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/impl/SftpRemotePathChannelTest.java
+++ b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/impl/SftpRemotePathChannelTest.java
@@ -309,7 +309,7 @@ public class SftpRemotePathChannelTest extends AbstractSftpClientTestSupport {
                 Buffer requestBuffer = new ByteArrayBuffer(id.length + Long.SIZE, false);
                 requestBuffer.putBytes(id);
                 requestBuffer.putLong(curPos);
-                requestBuffer.putInt(readLength);
+                requestBuffer.putUInt(readLength);
                 ((RawSftpClient) sftp).send(SftpConstants.SSH_FXP_READ, requestBuffer);
 
                 Thread.sleep(1L);

[mina-sshd] 03/05: [SSHD-1244] Renamed Channel#getId to Channel#getChannelId and moved it to its own interface

Posted by lg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lgoldstein pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git

commit 7f1a4be462982d417a7df9f7806e559297265797
Author: Lyor Goldstein <lg...@apache.org>
AuthorDate: Fri Feb 4 13:57:41 2022 +0200

    [SSHD-1244] Renamed Channel#getId to Channel#getChannelId and moved it to its own interface
---
 CHANGES.md                                                     |  2 +-
 .../org/apache/sshd/common/session/SessionContextHolder.java   |  1 +
 .../ChannelIdTrackingUnknownChannelReferenceHandler.java       |  2 +-
 .../org/apache/sshd/client/channel/AbstractClientChannel.java  |  4 ++--
 .../org/apache/sshd/client/channel/ChannelDirectTcpip.java     |  2 +-
 .../java/org/apache/sshd/common/channel/AbstractChannel.java   |  4 ++--
 .../org/apache/sshd/common/channel/BufferedIoOutputStream.java |  3 ++-
 .../src/main/java/org/apache/sshd/common/channel/Channel.java  |  6 +-----
 .../java/org/apache/sshd/common/channel/ChannelIdentifier.java | 10 +++++++---
 .../org/apache/sshd/common/channel/ChannelOutputStream.java    |  4 ++--
 .../sshd/common/channel/exception/SshChannelException.java     |  5 ++++-
 .../org/apache/sshd/common/forward/TcpipClientChannel.java     |  2 +-
 .../sshd/common/session/helpers/AbstractConnectionService.java |  4 ++--
 .../org/apache/sshd/server/forward/TcpipServerChannel.java     |  6 +++---
 .../java/org/apache/sshd/server/x11/ChannelForwardedX11.java   |  2 +-
 sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java |  6 +++---
 .../test/java/org/apache/sshd/common/channel/WindowTest.java   |  2 +-
 .../java/org/apache/sshd/util/test/AsyncEchoShellFactory.java  |  2 +-
 .../java/org/apache/sshd/sftp/client/impl/SftpPathImpl.java    | 10 +++++-----
 .../apache/sshd/sftp/common/extensions/SupportedParser.java    |  7 +++----
 .../main/java/org/apache/sshd/sftp/server/SftpSubsystem.java   |  2 +-
 .../src/test/java/org/apache/sshd/sftp/client/ClientTest.java  |  4 ++--
 22 files changed, 47 insertions(+), 43 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index 08c9d71..9fc8652 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -39,7 +39,7 @@ this value (though the choice of 256KB should be compatible with the vast majori
 ### SSH channel identifiers have been changed to use *long* instead of *int* in order to align them with the standard that required them to be *UINT32* values.
 
 The relevant API(s) have been modified accordingly - which may cause a few incompatibility issues with code that extends/implements existing `Channel` classes
-and interfaces.
+and interfaces. In this context, the *Channel* interface now extends *ChannelIdentifier* where *getId()* has been renamed to *getChannelId()*
 
 ### *long* used instead of *int* in most encoded/decoded packets that are specified as being *UINT32*
 
diff --git a/sshd-common/src/main/java/org/apache/sshd/common/session/SessionContextHolder.java b/sshd-common/src/main/java/org/apache/sshd/common/session/SessionContextHolder.java
index 79edb7e..c72aa66 100644
--- a/sshd-common/src/main/java/org/apache/sshd/common/session/SessionContextHolder.java
+++ b/sshd-common/src/main/java/org/apache/sshd/common/session/SessionContextHolder.java
@@ -22,6 +22,7 @@ package org.apache.sshd.common.session;
 /**
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  */
+@FunctionalInterface
 public interface SessionContextHolder {
     SessionContext getSessionContext();
 }
diff --git a/sshd-contrib/src/main/java/org/apache/sshd/contrib/common/session/helpers/ChannelIdTrackingUnknownChannelReferenceHandler.java b/sshd-contrib/src/main/java/org/apache/sshd/contrib/common/session/helpers/ChannelIdTrackingUnknownChannelReferenceHandler.java
index 7d282b9..5686a29 100644
--- a/sshd-contrib/src/main/java/org/apache/sshd/contrib/common/session/helpers/ChannelIdTrackingUnknownChannelReferenceHandler.java
+++ b/sshd-contrib/src/main/java/org/apache/sshd/contrib/common/session/helpers/ChannelIdTrackingUnknownChannelReferenceHandler.java
@@ -52,7 +52,7 @@ public class ChannelIdTrackingUnknownChannelReferenceHandler
 
     @Override
     public void channelInitialized(Channel channel) {
-        long channelId = channel.getId();
+        long channelId = channel.getChannelId();
         Session session = channel.getSession();
         Long lastTracked = session.setAttribute(LAST_CHANNEL_ID_KEY, channelId);
         if (log.isDebugEnabled()) {
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
index 4124408..1f6f569 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
@@ -329,7 +329,7 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
         Window wLocal = getLocalWindow();
         Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN, type.length() + Integer.SIZE);
         buffer.putString(type);
-        buffer.putUInt(getId());
+        buffer.putUInt(getChannelId());
         buffer.putUInt(wLocal.getSize());
         buffer.putUInt(wLocal.getPacketSize());
         writePacket(buffer);
@@ -385,7 +385,7 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
         this.openFailureReason = reason;
         this.openFailureMsg = msg;
         this.openFailureLang = lang;
-        this.openFuture.setException(new SshChannelOpenException(getId(), reason, msg));
+        this.openFuture.setException(new SshChannelOpenException(getChannelId(), reason, msg));
         this.closeFuture.setClosed();
         this.doCloseImmediately();
         notifyStateChanged("SSH_MSG_CHANNEL_OPEN_FAILURE");
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java
index b8b2ab8..aecdb2d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java
@@ -84,7 +84,7 @@ public class ChannelDirectTcpip extends AbstractClientChannel {
         Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN,
                 type.length() + remoteName.length() + localName.length() + Long.SIZE);
         buffer.putString(type);
-        buffer.putUInt(getId());
+        buffer.putUInt(getChannelId());
         buffer.putUInt(wLocal.getSize());
         buffer.putUInt(wLocal.getPacketSize());
         buffer.putString(remoteName);
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
index 3ee3fd2..ac2ac68 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
@@ -155,7 +155,7 @@ public abstract class AbstractChannel extends AbstractInnerCloseable implements
     }
 
     @Override
-    public long getId() {
+    public long getChannelId() {
         return id;
     }
 
@@ -1019,7 +1019,7 @@ public abstract class AbstractChannel extends AbstractInnerCloseable implements
 
     @Override
     public String toString() {
-        return getClass().getSimpleName() + "[id=" + getId() + ", recipient=" + getRecipient() + "]" + "-"
+        return getClass().getSimpleName() + "[id=" + getChannelId() + ", recipient=" + getRecipient() + "]" + "-"
                + getSession();
     }
 }
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/BufferedIoOutputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/BufferedIoOutputStream.java
index 15cee93..ad83c67 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/BufferedIoOutputStream.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/BufferedIoOutputStream.java
@@ -43,7 +43,7 @@ import org.apache.sshd.core.CoreModuleProperties;
 /**
  * An {@link IoOutputStream} capable of queuing write requests.
  */
-public class BufferedIoOutputStream extends AbstractInnerCloseable implements IoOutputStream {
+public class BufferedIoOutputStream extends AbstractInnerCloseable implements IoOutputStream, ChannelIdentifier {
     protected final Object id;
     protected final long channelId;
     protected final int maxPendingBytesCount;
@@ -71,6 +71,7 @@ public class BufferedIoOutputStream extends AbstractInnerCloseable implements Io
         this.maxWaitForPendingWrites = Objects.requireNonNull(maxWaitForPendingWrites, "No max. pending time value provided");
     }
 
+    @Override
     public long getChannelId() {
         return channelId;
     }
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java
index 41a86be..b2106aa 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java
@@ -44,6 +44,7 @@ import org.apache.sshd.common.util.buffer.Buffer;
  */
 public interface Channel
         extends SessionHolder<Session>,
+        ChannelIdentifier,
         ChannelListenerManager,
         PropertyResolver,
         AttributeStore,
@@ -55,11 +56,6 @@ public interface Channel
     String CHANNEL_SUBSYSTEM = "subsystem";
 
     /**
-     * @return Local channel UINT32 identifier
-     */
-    long getId();
-
-    /**
      * @return Remote channel UITN32 identifier
      */
     long getRecipient();
diff --git a/sshd-common/src/main/java/org/apache/sshd/common/session/SessionContextHolder.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelIdentifier.java
similarity index 82%
copy from sshd-common/src/main/java/org/apache/sshd/common/session/SessionContextHolder.java
copy to sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelIdentifier.java
index 79edb7e..092a566 100644
--- a/sshd-common/src/main/java/org/apache/sshd/common/session/SessionContextHolder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelIdentifier.java
@@ -17,11 +17,15 @@
  * under the License.
  */
 
-package org.apache.sshd.common.session;
+package org.apache.sshd.common.channel;
 
 /**
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  */
-public interface SessionContextHolder {
-    SessionContext getSessionContext();
+@FunctionalInterface
+public interface ChannelIdentifier {
+    /**
+     * @return Local channel UINT32 identifier
+     */
+    long getChannelId();
 }
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java
index 188fb78..7dda557 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java
@@ -129,7 +129,7 @@ public class ChannelOutputStream extends OutputStream implements java.nio.channe
         Channel channel = getChannel();
         if (!isOpen()) {
             throw new SshChannelClosedException(
-                    channel.getId(),
+                    channel.getChannelId(),
                     "write(" + this + ") len=" + l + " - channel already closed");
         }
 
@@ -196,7 +196,7 @@ public class ChannelOutputStream extends OutputStream implements java.nio.channe
         Channel channel = getChannel();
         if (!isOpen()) {
             throw new SshChannelClosedException(
-                    channel.getId(),
+                    channel.getChannelId(),
                     "flush(" + this + ") length=" + bufferLength + " - stream is already closed");
         }
 
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelException.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelException.java
index 13d9f6e..27b2799 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelException.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/exception/SshChannelException.java
@@ -21,10 +21,12 @@ package org.apache.sshd.common.channel.exception;
 
 import java.io.IOException;
 
+import org.apache.sshd.common.channel.ChannelIdentifier;
+
 /**
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  */
-public abstract class SshChannelException extends IOException {
+public abstract class SshChannelException extends IOException implements ChannelIdentifier {
     private static final long serialVersionUID = 7355720478400167933L;
 
     private final long channelId;
@@ -42,6 +44,7 @@ public abstract class SshChannelException extends IOException {
         this.channelId = channelId;
     }
 
+    @Override
     public long getChannelId() {
         return channelId;
     }
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java b/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java
index 17c6003..cdcbc6f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java
@@ -150,7 +150,7 @@ public class TcpipClientChannel extends AbstractClientChannel implements Forward
         Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN,
                 type.length() + srcHost.length() + dstHost.length() + Long.SIZE);
         buffer.putString(type);
-        buffer.putUInt(getId());
+        buffer.putUInt(getChannelId());
         buffer.putUInt(wLocal.getSize());
         buffer.putUInt(wLocal.getPacketSize());
         buffer.putString(dstHost);
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractConnectionService.java b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractConnectionService.java
index d390fd5..18c7181 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractConnectionService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractConnectionService.java
@@ -430,7 +430,7 @@ public abstract class AbstractConnectionService
      */
     @Override
     public void unregisterChannel(Channel channel) {
-        long channelId = channel.getId();
+        long channelId = channel.getChannelId();
         Channel result;
         synchronized (channels) {
             result = channels.remove(channelId);
@@ -550,7 +550,7 @@ public abstract class AbstractConnectionService
             return; // debug breakpoint
         }
 
-        long id = channel.getId();
+        long id = channel.getChannelId();
         boolean debugEnabled = log.isDebugEnabled();
         if (debugEnabled) {
             log.debug("channelOpenFailure({}) Received SSH_MSG_CHANNEL_OPEN_FAILURE", channel);
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java b/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
index 2a14a35..db22a51 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
@@ -201,7 +201,7 @@ public class TcpipServerChannel extends AbstractServerChannel implements Streami
                 }
                 try {
                     f.setException(new SshChannelOpenException(
-                            getId(),
+                            getChannelId(),
                             SshConstants.SSH_OPEN_ADMINISTRATIVELY_PROHIBITED, "Connection denied"));
                 } finally {
                     super.close(true);
@@ -215,7 +215,7 @@ public class TcpipServerChannel extends AbstractServerChannel implements Streami
         }
 
         if (streaming == Streaming.Async) {
-            long channelId = getId();
+            long channelId = getChannelId();
             out = new BufferedIoOutputStream(
                     "aysnc-tcpip-channel@" + channelId, channelId,
                     new ChannelAsyncOutputStream(this, SshConstants.SSH_MSG_CHANNEL_DATA) {
@@ -343,7 +343,7 @@ public class TcpipServerChannel extends AbstractServerChannel implements Streami
         try {
             if (problem instanceof ConnectException) {
                 f.setException(new SshChannelOpenException(
-                        getId(), SshConstants.SSH_OPEN_CONNECT_FAILED, problem.getMessage(), problem));
+                        getChannelId(), SshConstants.SSH_OPEN_CONNECT_FAILED, problem.getMessage(), problem));
             } else {
                 f.setException(problem);
             }
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/x11/ChannelForwardedX11.java b/sshd-core/src/main/java/org/apache/sshd/server/x11/ChannelForwardedX11.java
index cde200b..2781c38 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/x11/ChannelForwardedX11.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/x11/ChannelForwardedX11.java
@@ -67,7 +67,7 @@ public class ChannelForwardedX11 extends AbstractClientChannel {
         Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN,
                 remoteHost.length() + type.length() + Integer.SIZE);
         buffer.putString(type);
-        buffer.putUInt(getId());
+        buffer.putUInt(getChannelId());
         buffer.putUInt(wLocal.getSize());
         buffer.putUInt(wLocal.getPacketSize());
         buffer.putString(remoteHost);
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
index bc466e2..ad40b46 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
@@ -219,7 +219,7 @@ public class ClientTest extends BaseTestSupport {
 
                             @Override
                             public String toString() {
-                                return "ChannelSession" + "[id=" + getId() + ", recipient=" + getRecipient() + "]";
+                                return "ChannelSession" + "[id=" + getChannelId() + ", recipient=" + getRecipient() + "]";
                             }
                         };
                     }
@@ -377,7 +377,7 @@ public class ClientTest extends BaseTestSupport {
             }
 
             private void handleChannelEvent(String name, Channel channel) {
-                long id = channel.getId();
+                long id = channel.getChannelId();
                 synchronized (eventsMap) {
                     if (eventsMap.put(name, id) != null) {
                         return; // already generated an exception for this event
@@ -1477,7 +1477,7 @@ public class ClientTest extends BaseTestSupport {
 
             Set<Long> ids = new HashSet<>(channels.size());
             for (ClientChannel c : channels) {
-                long id = c.getId();
+                long id = c.getChannelId();
                 assertTrue("Channel ID repeated: " + id, ids.add(id));
             }
         } finally {
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java
index 77965f2..a4817fd 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java
@@ -121,7 +121,7 @@ public class WindowTest extends BaseTestSupport {
 
                             @Override
                             public String toString() {
-                                return "ChannelSession" + "[id=" + getId() + ", recipient=" + getRecipient() + "]";
+                                return "ChannelSession" + "[id=" + getChannelId() + ", recipient=" + getRecipient() + "]";
                             }
                         };
                     }
diff --git a/sshd-core/src/test/java/org/apache/sshd/util/test/AsyncEchoShellFactory.java b/sshd-core/src/test/java/org/apache/sshd/util/test/AsyncEchoShellFactory.java
index 22f7fec..9a45920 100644
--- a/sshd-core/src/test/java/org/apache/sshd/util/test/AsyncEchoShellFactory.java
+++ b/sshd-core/src/test/java/org/apache/sshd/util/test/AsyncEchoShellFactory.java
@@ -112,7 +112,7 @@ public class AsyncEchoShellFactory implements ShellFactory {
                 return (BufferedIoOutputStream) stream;
             }
 
-            long channelId = session.getId();
+            long channelId = session.getChannelId();
             return new BufferedIoOutputStream(prefix + "@" + channelId, channelId, stream, session);
         }
 
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/SftpPathImpl.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/SftpPathImpl.java
index d9d76cc..fa27fe2 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/SftpPathImpl.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/SftpPathImpl.java
@@ -28,7 +28,7 @@ import org.apache.sshd.sftp.client.fs.SftpFileSystem;
 import org.apache.sshd.sftp.client.fs.SftpPath;
 
 /**
- * An {@link SftpPath} that can cache {@link SftpClient.Attributes}.
+ * An {@link SftpPath} that can cache {@code SftpClient.Attributes}.
  */
 public class SftpPathImpl extends SftpPath {
 
@@ -41,7 +41,7 @@ public class SftpPathImpl extends SftpPath {
     }
 
     /**
-     * {@link SftpPath} instances can cache SFTP {@link SftpClient.Attributes}. Caching can be enabled by passing
+     * {@link SftpPath} instances can cache SFTP {@code SftpClient.Attributes}. Caching can be enabled by passing
      * {@code true}. If the {@link SftpPath} instance is already caching attributes, a counter is increased only. To
      * disable caching, pass {@code false}, which decreases the counter. The cache is cleared when the counter reaches
      * zero again.
@@ -81,7 +81,7 @@ public class SftpPathImpl extends SftpPath {
      * Sets the cached attributes to the argument if this {@link SftpPath} instance is currently caching attributes.
      * Otherwise a no-op.
      *
-     * @param attributes the {@link SftpClient.Attributes} to cache
+     * @param attributes the {@code SftpClient.Attributes} to cache
      */
     public void cacheAttributes(SftpClient.Attributes attributes) {
         if (cachingLevel > 0) {
@@ -92,7 +92,7 @@ public class SftpPathImpl extends SftpPath {
     /**
      * Unconditionally set the cached attributes, whether or not this instance's attribute cache is enabled.
      *
-     * @param attributes the {@link SftpClient.Attributes} to cache
+     * @param attributes the {@code SftpClient.Attributes} to cache
      */
     public void setAttributes(SftpClient.Attributes attributes) {
         this.attributes = attributes;
@@ -104,7 +104,7 @@ public class SftpPathImpl extends SftpPath {
     }
 
     /**
-     * Performs the given operation with attribute caching. If {@link SftpClient.Attributes} are fetched by the
+     * Performs the given operation with attribute caching. If {@code SftpClient.Attributes} are fetched by the
      * operation, they will be cached and subsequently these cached attributes will be re-used for this {@link SftpPath}
      * instance throughout the operation. Calls to {@link #withAttributeCache(IOFunction)} may be nested. The cache is
      * cleared at the start and at the end of the outermost invocation.
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/extensions/SupportedParser.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/extensions/SupportedParser.java
index 28ebe4b..193dd7a 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/extensions/SupportedParser.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/extensions/SupportedParser.java
@@ -28,16 +28,15 @@ import org.apache.sshd.sftp.common.extensions.SupportedParser.Supported;
 
 /**
  * Parses the &quot;supported&quot; extension as defined in
- * <A HREF="http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-05.txt">DRAFT 05 -
- * section 4.4</A>
+ * <A HREF="https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-05#section-4.4">DRAFT 05 - section 4.4</A>
  *
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  */
 public class SupportedParser extends AbstractParser<Supported> {
     /**
      * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
-     * @see    <A HREF="http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-05">DRAFT 05
-     *         - section 4.4</A>
+     * @see    <A HREF="https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-05#section-4.4">DRAFT 05 -
+     *         section 4.4</A>
      */
     public static class Supported {
         // CHECKSTYLE:OFF
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystem.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystem.java
index ae48894..00e1c59 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystem.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/SftpSubsystem.java
@@ -241,7 +241,7 @@ public class SftpSubsystem
     @Override
     public void setIoOutputStream(IoOutputStream out) {
         ChannelSession channel = getServerChannelSession();
-        long channelId = channel.getId();
+        long channelId = channel.getChannelId();
         this.out = new BufferedIoOutputStream("sftp-out@" + channelId, channelId, out, channel);
     }
 
diff --git a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/ClientTest.java b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/ClientTest.java
index b2c3dad..5b01a18 100644
--- a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/ClientTest.java
+++ b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/ClientTest.java
@@ -158,7 +158,7 @@ public class ClientTest extends BaseTestSupport {
 
                             @Override
                             public String toString() {
-                                return "ChannelSession" + "[id=" + getId() + ", recipient=" + getRecipient() + "]";
+                                return "ChannelSession" + "[id=" + getChannelId() + ", recipient=" + getRecipient() + "]";
                             }
                         };
                     }
@@ -280,7 +280,7 @@ public class ClientTest extends BaseTestSupport {
 
             Set<Long> ids = new HashSet<>(channels.size());
             for (ClientChannel c : channels) {
-                long id = c.getId();
+                long id = c.getChannelId();
                 assertTrue("Channel ID repeated: " + id, ids.add(id));
             }
         } finally {