From abb041d2035e36c23191cf3c71640839e7708f8d Mon Sep 17 00:00:00 2001 From: Florian Zschocke Date: Fri, 8 Nov 2019 17:26:06 +0100 Subject: [PATCH] Update SSHD dependency to version 1.1.0. --- .classpath | 2 +- build.moxie | 2 +- gitblit.iml | 6 +++--- .../com/gitblit/transport/ssh/LdapKeyManager.java | 2 +- .../java/com/gitblit/transport/ssh/SshDaemon.java | 4 ++-- .../transport/ssh/SshServerSessionFactory.java | 10 ++++++---- src/test/java/com/gitblit/tests/SshDaemonTest.java | 5 +++-- src/test/java/com/gitblit/tests/SshUnitTest.java | 12 ++++++++---- 8 files changed, 25 insertions(+), 18 deletions(-) diff --git a/.classpath b/.classpath index 46210ac3..de9f9172 100644 --- a/.classpath +++ b/.classpath @@ -54,7 +54,7 @@ - + diff --git a/build.moxie b/build.moxie index 85e2f492..9deb2fbd 100644 --- a/build.moxie +++ b/build.moxie @@ -112,7 +112,7 @@ properties: { bouncycastle.version : 1.57 selenium.version : 2.28.0 wikitext.version : 1.4 - sshd.version: 1.0.0 + sshd.version: 1.1.0 mina.version: 2.0.21 guice.version : 4.0 # Gitblit maintains a fork of guice-servlet diff --git a/gitblit.iml b/gitblit.iml index f935fc17..07dc10a9 100644 --- a/gitblit.iml +++ b/gitblit.iml @@ -541,13 +541,13 @@ - + - + - + diff --git a/src/main/java/com/gitblit/transport/ssh/LdapKeyManager.java b/src/main/java/com/gitblit/transport/ssh/LdapKeyManager.java index c62c4dee..45b692db 100644 --- a/src/main/java/com/gitblit/transport/ssh/LdapKeyManager.java +++ b/src/main/java/com/gitblit/transport/ssh/LdapKeyManager.java @@ -212,7 +212,7 @@ public class LdapKeyManager extends IPublicKeyManager { List keyList = new ArrayList<>(authorizedKeys.size()); for (GbAuthorizedKeyEntry keyEntry : authorizedKeys) { try { - SshKey key = new SshKey(keyEntry.resolvePublicKey()); + SshKey key = new SshKey(keyEntry.resolvePublicKey(null)); key.setComment(keyEntry.getComment()); setKeyPermissions(key, keyEntry); keyList.add(key); diff --git a/src/main/java/com/gitblit/transport/ssh/SshDaemon.java b/src/main/java/com/gitblit/transport/ssh/SshDaemon.java index 5a053781..63fa51dd 100644 --- a/src/main/java/com/gitblit/transport/ssh/SshDaemon.java +++ b/src/main/java/com/gitblit/transport/ssh/SshDaemon.java @@ -31,7 +31,7 @@ import org.apache.sshd.common.io.mina.MinaServiceFactoryFactory; import org.apache.sshd.common.io.nio2.Nio2ServiceFactoryFactory; import org.apache.sshd.common.util.SecurityUtils; import org.apache.sshd.server.SshServer; -import org.apache.sshd.server.auth.CachingPublicKeyAuthenticator; +import org.apache.sshd.server.auth.pubkey.CachingPublicKeyAuthenticator; import org.bouncycastle.openssl.PEMWriter; import org.eclipse.jgit.internal.JGitText; import org.slf4j.Logger; @@ -158,7 +158,7 @@ public class SshDaemon { log.info("SSH: adding GSSAPI authentication method."); } - sshd.setSessionFactory(new SshServerSessionFactory()); + sshd.setSessionFactory(new SshServerSessionFactory(sshd)); sshd.setFileSystemFactory(new DisabledFilesystemFactory()); sshd.setTcpipForwardingFilter(new NonForwardingFilter()); sshd.setCommandFactory(new SshCommandFactory(gitblit, workQueue)); diff --git a/src/main/java/com/gitblit/transport/ssh/SshServerSessionFactory.java b/src/main/java/com/gitblit/transport/ssh/SshServerSessionFactory.java index bc67cec0..fb85781a 100644 --- a/src/main/java/com/gitblit/transport/ssh/SshServerSessionFactory.java +++ b/src/main/java/com/gitblit/transport/ssh/SshServerSessionFactory.java @@ -22,7 +22,8 @@ import org.apache.sshd.common.future.CloseFuture; import org.apache.sshd.common.future.SshFutureListener; import org.apache.sshd.common.io.IoSession; import org.apache.sshd.common.io.mina.MinaSession; -import org.apache.sshd.common.session.AbstractSession; +import org.apache.sshd.server.ServerFactoryManager; +import org.apache.sshd.server.session.ServerSessionImpl; import org.apache.sshd.server.session.SessionFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,11 +37,12 @@ public class SshServerSessionFactory extends SessionFactory { private final Logger log = LoggerFactory.getLogger(getClass()); - public SshServerSessionFactory() { + public SshServerSessionFactory(ServerFactoryManager server) { + super(server); } @Override - protected AbstractSession createSession(final IoSession io) throws Exception { + protected ServerSessionImpl createSession(final IoSession io) throws Exception { log.info("creating ssh session from {}", io.getRemoteAddress()); if (io instanceof MinaSession) { @@ -66,7 +68,7 @@ public class SshServerSessionFactory extends SessionFactory { } @Override - protected AbstractSession doCreateSession(IoSession ioSession) throws Exception { + protected ServerSessionImpl doCreateSession(IoSession ioSession) throws Exception { return new SshServerSession(getServer(), ioSession); } } diff --git a/src/test/java/com/gitblit/tests/SshDaemonTest.java b/src/test/java/com/gitblit/tests/SshDaemonTest.java index c5deb7d5..c7d06198 100644 --- a/src/test/java/com/gitblit/tests/SshDaemonTest.java +++ b/src/test/java/com/gitblit/tests/SshDaemonTest.java @@ -44,9 +44,9 @@ public class SshDaemonTest extends SshUnitTest { @Test public void testPublicKeyAuthentication() throws Exception { SshClient client = getClient(); - ClientSession session = client.connect(username, "localhost", GitBlitSuite.sshPort).await().getSession(); + ClientSession session = client.connect(username, "localhost", GitBlitSuite.sshPort).verify().getSession(); session.addPublicKeyIdentity(rwKeyPair); - assertTrue(session.auth().await().isSuccess()); + assertTrue(session.auth().await()); } @Test @@ -64,6 +64,7 @@ public class SshDaemonTest extends SshUnitTest { // set clone restriction RepositoryModel model = repositories().getRepositoryModel("ticgit.git"); + assertNotNull("Could not get repository modle for ticgit.git", model); model.accessRestriction = AccessRestrictionType.CLONE; model.authorizationControl = AuthorizationControl.NAMED; repositories().updateRepositoryModel(model.name, model, false); diff --git a/src/test/java/com/gitblit/tests/SshUnitTest.java b/src/test/java/com/gitblit/tests/SshUnitTest.java index 27b4ec73..dd354d85 100644 --- a/src/test/java/com/gitblit/tests/SshUnitTest.java +++ b/src/test/java/com/gitblit/tests/SshUnitTest.java @@ -24,11 +24,13 @@ import java.net.SocketAddress; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.PublicKey; +import java.util.EnumSet; import java.util.concurrent.atomic.AtomicBoolean; -import org.apache.sshd.client.ServerKeyVerifier; import org.apache.sshd.client.SshClient; import org.apache.sshd.client.channel.ClientChannel; +import org.apache.sshd.client.future.AuthFuture; +import org.apache.sshd.client.keyverifier.ServerKeyVerifier; import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.common.util.SecurityUtils; import org.junit.After; @@ -112,9 +114,11 @@ public abstract class SshUnitTest extends GitblitUnitTest { protected String testSshCommand(String cmd, String stdin) throws IOException, InterruptedException { SshClient client = getClient(); - ClientSession session = client.connect(username, "localhost", GitBlitSuite.sshPort).await().getSession(); + ClientSession session = client.connect(username, "localhost", GitBlitSuite.sshPort).verify().getSession(); session.addPublicKeyIdentity(rwKeyPair); - assertTrue(session.auth().await().isSuccess()); + AuthFuture authFuture = session.auth(); + assertTrue(authFuture.await()); + assertTrue(authFuture.isSuccess()); ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_EXEC, cmd); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -131,7 +135,7 @@ public abstract class SshUnitTest extends GitblitUnitTest { channel.setErr(err); channel.open(); - channel.waitFor(ClientChannel.CLOSED, 0); + channel.waitFor(EnumSet.of(ClientChannel.ClientChannelEvent.CLOSED), 0); String result = out.toString().trim(); channel.close(false); -- 2.39.5