Repository: mina-sshd
Updated Branches:
  refs/heads/master 89b60a883 -> 6de239d9b


[SSHD-750] Accept SSH clients advertising vesion 1.99


Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/6de239d9
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/6de239d9
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/6de239d9

Branch: refs/heads/master
Commit: 6de239d9b42b5510791d85eb12d3410b2f4fece1
Parents: 89b60a8
Author: Scott Meeuwsen <sc...@api-tech.com>
Authored: Sun May 28 19:10:36 2017 +0300
Committer: Lyor Goldstein <lyor.goldst...@gmail.com>
Committed: Sun May 28 19:11:27 2017 +0300

----------------------------------------------------------------------
 .../sshd/client/session/AbstractClientSession.java |  3 ++-
 .../org/apache/sshd/common/session/Session.java    | 17 +++++++++++++++++
 .../sshd/server/session/AbstractServerSession.java |  3 ++-
 3 files changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6de239d9/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java
----------------------------------------------------------------------
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 f2f1aea..9e85843 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
@@ -68,6 +68,7 @@ import org.apache.sshd.common.kex.KexState;
 import org.apache.sshd.common.scp.ScpFileOpener;
 import org.apache.sshd.common.scp.ScpTransferEventListener;
 import org.apache.sshd.common.session.ConnectionService;
+import org.apache.sshd.common.session.Session;
 import org.apache.sshd.common.session.helpers.AbstractConnectionService;
 import org.apache.sshd.common.session.helpers.AbstractSession;
 import org.apache.sshd.common.util.GenericUtils;
@@ -460,7 +461,7 @@ public abstract class AbstractClientSession extends 
AbstractSession implements C
             log.debug("readIdentification({}) Server version string: {}", 
this, serverVersion);
         }
 
-        if (!(serverVersion.startsWith(DEFAULT_SSH_VERSION_PREFIX) || 
serverVersion.startsWith("SSH-1.99-"))) {
+        if (!Session.isValidVersionPrefix(serverVersion)) {
             throw new 
SshException(SshConstants.SSH2_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED,
                     "Unsupported protocol version: " + serverVersion);
         }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6de239d9/sshd-core/src/main/java/org/apache/sshd/common/session/Session.java
----------------------------------------------------------------------
diff --git 
a/sshd-core/src/main/java/org/apache/sshd/common/session/Session.java 
b/sshd-core/src/main/java/org/apache/sshd/common/session/Session.java
index 2e7e27f..35bb96d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/Session.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/Session.java
@@ -38,6 +38,7 @@ import org.apache.sshd.common.kex.KexFactoryManager;
 import org.apache.sshd.common.kex.KexProposalOption;
 import org.apache.sshd.common.kex.KeyExchange;
 import org.apache.sshd.common.mac.MacInformation;
+import org.apache.sshd.common.util.GenericUtils;
 import org.apache.sshd.common.util.buffer.Buffer;
 
 /**
@@ -65,6 +66,12 @@ public interface Session
     String DEFAULT_SSH_VERSION_PREFIX = "SSH-2.0-";
 
     /**
+     * Backward compatible special prefix
+     * @see <A HREF="https://tools.ietf.org/html/rfc4253#section-5";>RFC 4253 - 
section 5</A>
+     */
+    String FALLBACK_SSH_VERSION_PREFIX = "SSH-1.99-";
+
+    /**
      * Maximum number of characters for any single line sent as part
      * of the initial handshake - according to
      * <A HREF="https://tools.ietf.org/html/rfc4253#section-4.2";>RFC 4253 - 
section 4.2</A>:</BR>
@@ -313,4 +320,14 @@ public interface Session
      * @throws Exception If failed to start it
      */
     void startService(String name) throws Exception;
+
+    /**
+     * @param version The reported client/server version
+     * @return {@code true} if version not empty and starts with either
+     * {@value #DEFAULT_SSH_VERSION_PREFIX} or {@value 
#FALLBACK_SSH_VERSION_PREFIX}
+     */
+    static boolean isValidVersionPrefix(String version) {
+        return GenericUtils.isNotEmpty(version)
+            && (version.startsWith(DEFAULT_SSH_VERSION_PREFIX) || 
version.startsWith(FALLBACK_SSH_VERSION_PREFIX));
+    }
 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6de239d9/sshd-core/src/main/java/org/apache/sshd/server/session/AbstractServerSession.java
----------------------------------------------------------------------
diff --git 
a/sshd-core/src/main/java/org/apache/sshd/server/session/AbstractServerSession.java
 
b/sshd-core/src/main/java/org/apache/sshd/server/session/AbstractServerSession.java
index 29c29e8..1385459 100644
--- 
a/sshd-core/src/main/java/org/apache/sshd/server/session/AbstractServerSession.java
+++ 
b/sshd-core/src/main/java/org/apache/sshd/server/session/AbstractServerSession.java
@@ -42,6 +42,7 @@ import org.apache.sshd.common.io.IoWriteFuture;
 import org.apache.sshd.common.kex.KexProposalOption;
 import org.apache.sshd.common.kex.KexState;
 import org.apache.sshd.common.keyprovider.KeyPairProvider;
+import org.apache.sshd.common.session.Session;
 import org.apache.sshd.common.session.helpers.AbstractSession;
 import org.apache.sshd.common.util.GenericUtils;
 import org.apache.sshd.common.util.ValidateUtils;
@@ -347,7 +348,7 @@ public abstract class AbstractServerSession extends 
AbstractSession implements S
         }
 
         String errorMessage = null;
-        if ((errorMessage == null) && 
(!clientVersion.startsWith(DEFAULT_SSH_VERSION_PREFIX))) {
+        if (!Session.isValidVersionPrefix(clientVersion)) {
             errorMessage = "Unsupported protocol version: " + clientVersion;
         }
 

Reply via email to