You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2021/12/05 07:10:37 UTC

[karaf] branch main updated: [KARAF-7051] Upgrade to sshd 2.8.0

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

jbonofre pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/main by this push:
     new 1be86d3  [KARAF-7051] Upgrade to sshd 2.8.0
     new 5d38a81  Merge pull request #1462 from jbonofre/KARAF-7051
1be86d3 is described below

commit 1be86d383feda9cf678e13835d4074517276cca7
Author: Jean-Baptiste Onofré <jb...@apache.org>
AuthorDate: Sat Dec 4 07:43:44 2021 +0100

    [KARAF-7051] Upgrade to sshd 2.8.0
---
 client/src/main/java/org/apache/karaf/client/Main.java   | 12 +++++++-----
 pom.xml                                                  |  2 +-
 .../main/java/org/apache/karaf/shell/ssh/Activator.java  | 16 +++++++++-------
 .../org/apache/karaf/shell/ssh/KarafAgentFactory.java    |  3 ++-
 .../main/java/org/apache/karaf/shell/ssh/SshAction.java  |  4 ++--
 .../java/org/apache/karaf/shell/ssh/SshServerAction.java | 11 +++++++----
 .../karaf/shell/ssh/KarafJaasAuthenticatorTest.java      |  4 ++--
 .../java/org/apache/karaf/shell/ssh/SshUtilsTest.java    |  5 ++---
 8 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/client/src/main/java/org/apache/karaf/client/Main.java b/client/src/main/java/org/apache/karaf/client/Main.java
index 04c3d2f..f92b104 100644
--- a/client/src/main/java/org/apache/karaf/client/Main.java
+++ b/client/src/main/java/org/apache/karaf/client/Main.java
@@ -28,6 +28,7 @@ import java.lang.reflect.Proxy;
 import java.nio.charset.Charset;
 import java.nio.file.Paths;
 import java.security.KeyPair;
+import java.time.Duration;
 import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.List;
@@ -51,8 +52,9 @@ import org.apache.sshd.common.RuntimeSshException;
 import org.apache.sshd.common.channel.PtyMode;
 import org.apache.sshd.common.config.keys.FilePasswordProvider;
 import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
-import org.apache.sshd.common.util.io.NoCloseInputStream;
-import org.apache.sshd.common.util.io.NoCloseOutputStream;
+import org.apache.sshd.common.util.io.input.NoCloseInputStream;
+import org.apache.sshd.common.util.io.output.NoCloseOutputStream;
+import org.apache.sshd.core.CoreModuleProperties;
 import org.jline.terminal.Attributes;
 import org.jline.terminal.Attributes.ControlChar;
 import org.jline.terminal.Attributes.InputFlag;
@@ -158,9 +160,9 @@ public class Main {
 
             // define hearbeat (for the keep alive) and timeouts
             // TODO this should be dealt by Apache SSH client directly using .ssh/config
-            client.getProperties().put(ClientFactoryManager.HEARTBEAT_INTERVAL, "60000");
-            client.getProperties().put(ClientFactoryManager.IDLE_TIMEOUT, String.valueOf(config.getIdleTimeout()));
-            client.getProperties().put(ClientFactoryManager.NIO2_READ_TIMEOUT, String.valueOf(config.getIdleTimeout()));
+            CoreModuleProperties.HEARTBEAT_INTERVAL.set(client, Duration.ofMillis(60000));
+            CoreModuleProperties.IDLE_TIMEOUT.set(client, Duration.ofMillis(config.getIdleTimeout()));
+            CoreModuleProperties.NIO2_READ_TIMEOUT.set(client, Duration.ofMillis(config.getIdleTimeout()));
 
             // TODO: remove the line below when SSHD-732 is fixed
             // client.setKeyPairProvider(new FileKeyPairProvider());
diff --git a/pom.xml b/pom.xml
index b0026b6..177a059 100644
--- a/pom.xml
+++ b/pom.xml
@@ -339,7 +339,7 @@
         <spring.security55.version>5.5.2_1</spring.security55.version>
 
         <sling.commons.johnzon.version>1.2.6</sling.commons.johnzon.version>
-        <sshd.version>2.5.1</sshd.version>
+        <sshd.version>2.8.0</sshd.version>
         <struts.bundle.version>1.3.10_1</struts.bundle.version>
         <xbean.version>4.20</xbean.version>
         <javax.mail.version>1.4.7</javax.mail.version>
diff --git a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/Activator.java b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/Activator.java
index 9e2504f..d68d134 100644
--- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/Activator.java
+++ b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/Activator.java
@@ -21,6 +21,7 @@ package org.apache.karaf.shell.ssh;
 import java.io.IOException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.time.Duration;
 import java.util.Collections;
 
 import org.apache.karaf.shell.api.action.lifecycle.Manager;
@@ -35,10 +36,11 @@ import org.apache.karaf.util.tracker.annotation.RequireService;
 import org.apache.karaf.util.tracker.annotation.Services;
 import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
 import org.apache.sshd.common.keyprovider.KeyPairProvider;
+import org.apache.sshd.core.CoreModuleProperties;
+import org.apache.sshd.scp.server.ScpCommandFactory;
 import org.apache.sshd.server.SshServer;
 import org.apache.sshd.server.forward.AcceptAllForwardingFilter;
-import org.apache.sshd.server.scp.ScpCommandFactory;
-import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
+import org.apache.sshd.sftp.server.SftpSubsystemFactory;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.service.cm.ManagedService;
@@ -199,16 +201,16 @@ public class Activator extends BaseActivator implements ManagedService {
         server.setUserAuthFactories(authFactoriesFactory.getFactories());
         server.setAgentFactory(KarafAgentFactory.getInstance());
         server.setForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
-        server.getProperties().put(SshServer.IDLE_TIMEOUT, Long.toString(sshIdleTimeout));
-        server.getProperties().put(SshServer.NIO_WORKERS, Integer.toString(nioWorkers));
+        CoreModuleProperties.IDLE_TIMEOUT.set(server, Duration.ofMillis(sshIdleTimeout));
+        CoreModuleProperties.NIO_WORKERS.set(server, nioWorkers);
         if (maxConcurrentSessions != -1) {
-            server.getProperties().put(SshServer.MAX_CONCURRENT_SESSIONS, Integer.toString(maxConcurrentSessions));
+            CoreModuleProperties.MAX_CONCURRENT_SESSIONS.set(server, maxConcurrentSessions);
         }
         if (moduliUrl != null) {
-            server.getProperties().put(SshServer.MODULI_URL, moduliUrl);
+            CoreModuleProperties.MODULI_URL.set(server, moduliUrl);
         }
         if (welcomeBanner != null) {
-            server.getProperties().put(SshServer.WELCOME_BANNER, welcomeBanner);
+            CoreModuleProperties.WELCOME_BANNER.set(server, welcomeBanner);
         }
         return server;
     }
diff --git a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafAgentFactory.java b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafAgentFactory.java
index 9d7b412..ad786d8 100644
--- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafAgentFactory.java
+++ b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafAgentFactory.java
@@ -58,7 +58,8 @@ public class KarafAgentFactory implements SshAgentFactory {
         return LocalAgentFactory.DEFAULT_FORWARDING_CHANNELS;
     }
 
-    public SshAgent createClient(FactoryManager manager) throws IOException {
+    @Override
+    public SshAgent createClient(Session session, FactoryManager manager) throws IOException {
         String proxyId = (String) manager.getProperties().get(SshAgent.SSH_AUTHSOCKET_ENV_NAME);
         if (proxyId == null) {
             throw new IllegalStateException("No " + SshAgent.SSH_AUTHSOCKET_ENV_NAME + " environment variable set");
diff --git a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshAction.java b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshAction.java
index 694b8e8..b0d7b04 100644
--- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshAction.java
+++ b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshAction.java
@@ -47,8 +47,8 @@ import org.apache.sshd.client.future.ConnectFuture;
 import org.apache.sshd.client.session.ClientSession;
 import org.apache.sshd.common.channel.PtyMode;
 import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
-import org.apache.sshd.common.util.io.NoCloseInputStream;
-import org.apache.sshd.common.util.io.NoCloseOutputStream;
+import org.apache.sshd.common.util.io.input.NoCloseInputStream;
+import org.apache.sshd.common.util.io.output.NoCloseOutputStream;
 import org.jline.terminal.Attributes;
 import org.jline.terminal.Attributes.ControlChar;
 import org.jline.terminal.Attributes.InputFlag;
diff --git a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshServerAction.java b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshServerAction.java
index 2acc0a3..6f0ac40 100644
--- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshServerAction.java
+++ b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshServerAction.java
@@ -23,10 +23,13 @@ import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Reference;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.sshd.core.CoreModuleProperties;
 import org.apache.sshd.server.SshServer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.time.Duration;
+
 @Command(scope = "ssh", name = "sshd", description = "Creates a SSH server")
 @Service
 public class SshServerAction implements Action
@@ -65,19 +68,19 @@ public class SshServerAction implements Action
         server.setPort(port);
 
         // idle timeout
-        server.getProperties().put(SshServer.IDLE_TIMEOUT, Long.toString(idleTimeout));
+        CoreModuleProperties.IDLE_TIMEOUT.set(server, Duration.ofMillis(idleTimeout));
         
         // nio-workers
-        server.getProperties().put(SshServer.NIO_WORKERS, Integer.toString(nioWorkers));
+        CoreModuleProperties.NIO_WORKERS.set(server, nioWorkers);
 
         // max-concurrent-sessions
         if (maxConcurrentSessions != -1) {
-            server.getProperties().put(SshServer.MAX_CONCURRENT_SESSIONS, Integer.toString(maxConcurrentSessions));
+            CoreModuleProperties.MAX_CONCURRENT_SESSIONS.set(server, maxConcurrentSessions);
         }
         
         // welcome banner
         if (welcomeBanner != null) {
-            server.getProperties().put(SshServer.WELCOME_BANNER, welcomeBanner);
+            CoreModuleProperties.WELCOME_BANNER.set(server, welcomeBanner);
         } 
         
         // starting the SSHd server
diff --git a/shell/ssh/src/test/java/org/apache/karaf/shell/ssh/KarafJaasAuthenticatorTest.java b/shell/ssh/src/test/java/org/apache/karaf/shell/ssh/KarafJaasAuthenticatorTest.java
index 972f914..577d697 100644
--- a/shell/ssh/src/test/java/org/apache/karaf/shell/ssh/KarafJaasAuthenticatorTest.java
+++ b/shell/ssh/src/test/java/org/apache/karaf/shell/ssh/KarafJaasAuthenticatorTest.java
@@ -41,12 +41,12 @@ import org.apache.mina.core.session.DummySession;
 import org.apache.mina.core.write.WriteRequest;
 import org.apache.sshd.common.io.IoHandler;
 import org.apache.sshd.common.io.IoSession;
-import org.apache.sshd.common.io.mina.MinaConnector;
-import org.apache.sshd.common.io.mina.MinaSession;
 import org.apache.sshd.common.random.SingletonRandomFactory;
 import org.apache.sshd.common.util.Readable;
 import org.apache.sshd.common.util.net.SshdSocketAddress;
 import org.apache.sshd.common.util.security.SecurityUtils;
+import org.apache.sshd.mina.MinaConnector;
+import org.apache.sshd.mina.MinaSession;
 import org.apache.sshd.server.SshServer;
 import org.apache.sshd.server.session.ServerSessionImpl;
 import org.junit.After;
diff --git a/shell/ssh/src/test/java/org/apache/karaf/shell/ssh/SshUtilsTest.java b/shell/ssh/src/test/java/org/apache/karaf/shell/ssh/SshUtilsTest.java
index c463b6a..8c5beef 100644
--- a/shell/ssh/src/test/java/org/apache/karaf/shell/ssh/SshUtilsTest.java
+++ b/shell/ssh/src/test/java/org/apache/karaf/shell/ssh/SshUtilsTest.java
@@ -30,12 +30,11 @@ import org.junit.Assert;
 import org.junit.Test;
 
 public class SshUtilsTest {
-
    
     @Test
     public void testCiphersDefault() throws IOException {
         // verify our default configuration...
-        String ciphers = "aes128-ctr,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc";
+        String ciphers = "aes128-ctr,aes128-cbc";
 
         List<NamedFactory<Cipher>> list = SshUtils.buildCiphers(ciphers.split(","));
 
@@ -81,7 +80,7 @@ public class SshUtilsTest {
     @Test
     public void testKexAlgorithmsDefault() throws IOException {
         // verify our default configuration...
-        String kexAlgorithms = "diffie-hellman-group-exchange-sha256,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1";
+        String kexAlgorithms = "diffie-hellman-group-exchange-sha256,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256";
 
         List<KeyExchangeFactory> list = SshUtils.buildKexAlgorithms(kexAlgorithms.split(","));