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 2019/02/20 05:14:44 UTC

[mina-sshd] 06/06: [SSHD-896] Added handling of SSH_MSG_NEWCOMPRESS via the registered KexExtensionHandler

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 8200e7cda22c665c74736e56383d9bc50b8bf708
Author: Lyor Goldstein <lg...@apache.org>
AuthorDate: Tue Feb 19 17:20:31 2019 +0200

    [SSHD-896] Added handling of SSH_MSG_NEWCOMPRESS via the registered KexExtensionHandler
---
 .../common/kex/extension/KexExtensionHandler.java  | 26 +++++++++++++++++++---
 .../common/session/helpers/AbstractSession.java    | 21 ++++++++++++++---
 2 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/KexExtensionHandler.java b/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/KexExtensionHandler.java
index 45c6384..a34c0f0 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/KexExtensionHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/KexExtensionHandler.java
@@ -109,24 +109,44 @@ public interface KexExtensionHandler {
 
     /**
      * Parses the {@code SSH_MSG_EXT_INFO} message. <B>Note:</B> this method
-     * is called only if {@link #isKexExtensionsAvailable(Session)} returns
+     * is called regardless of whether {@link #isKexExtensionsAvailable(Session)} returns
      * {@code true} for the session.
      *
      * @param session The {@link Session} through which the message was received
      * @param buffer The message buffer
+     * @return {@code true} if message handled - if {@code false} then {@code SSH_MSG_UNIMPLEMENTED}
+     * will be generated
      * @throws IOException If failed to handle the message
      * @see <A HREF="https://tools.ietf.org/html/rfc8308#section-2.3">RFC-8308 - section 2.3</A>
      * @see #handleKexExtensionRequest(Session, int, int, String, byte[])
      */
-    default void handleKexExtensionsMessage(Session session, Buffer buffer) throws IOException {
+    default boolean handleKexExtensionsMessage(Session session, Buffer buffer) throws IOException {
         int count = buffer.getInt();
         for (int index = 0; index < count; index++) {
             String name = buffer.getString();
             byte[] data = buffer.getBytes();
             if (!handleKexExtensionRequest(session, index, count, name, data)) {
-                return;
+                break;
             }
         }
+
+        return true;
+    }
+
+    /**
+     * Parses the {@code SSH_MSG_NEWCOMPRESS} message. <B>Note:</B> this method
+     * is called regardless of whether {@link #isKexExtensionsAvailable(Session)} returns
+     * {@code true} for the session.
+     *
+     * @param session The {@link Session} through which the message was received
+     * @param buffer The message buffer
+     * @return {@code true} if message handled - if {@code false} then {@code SSH_MSG_UNIMPLEMENTED}
+     * will be generated
+     * @throws IOException If failed to handle the message
+     * @see <A HREF="https://tools.ietf.org/html/rfc8308#section-3.2">RFC-8308 - section 3.2</A>
+     */
+    default boolean handleKexCompressionMessage(Session session, Buffer buffer) throws IOException {
+        return true;
     }
 
     /**
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 11c6d87..c452293 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
@@ -414,6 +414,9 @@ public abstract class AbstractSession extends SessionHelper {
             case KexExtensions.SSH_MSG_EXT_INFO:
                 handleKexExtension(cmd, buffer);
                 break;
+            case KexExtensions.SSH_MSG_NEWCOMPRESS:
+                handleNewCompression(cmd, buffer);
+                break;
             default:
                 if ((cmd >= SshConstants.SSH_MSG_KEX_FIRST) && (cmd <= SshConstants.SSH_MSG_KEX_LAST)) {
                     if (firstKexPacketFollows != null) {
@@ -545,12 +548,24 @@ public abstract class AbstractSession extends SessionHelper {
 
     protected void handleKexExtension(int cmd, Buffer buffer) throws Exception {
         KexExtensionHandler extHandler = getKexExtensionHandler();
-        if ((extHandler == null) || (!extHandler.isKexExtensionsAvailable(this))) {
-            notImplemented(cmd, buffer);
+        int startPos = buffer.rpos();
+        if ((extHandler != null) && extHandler.handleKexExtensionsMessage(this, buffer)) {
+            return;
+        }
+
+        buffer.rpos(startPos);  // restore original read position
+        notImplemented(cmd, buffer);
+    }
+
+    protected void handleNewCompression(int cmd, Buffer buffer) throws Exception {
+        KexExtensionHandler extHandler = getKexExtensionHandler();
+        int startPos = buffer.rpos();
+        if ((extHandler != null) && extHandler.handleKexCompressionMessage(this, buffer)) {
             return;
         }
 
-        extHandler.handleKexExtensionsMessage(this, buffer);
+        buffer.rpos(startPos);  // restore original read position
+        notImplemented(cmd, buffer);
     }
 
     protected void handleServiceRequest(Buffer buffer) throws Exception {