From 9ba6bc127276f4b092849336f793aac2135f7887 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Thu, 13 Mar 2014 23:39:26 +0100 Subject: [PATCH] Bump SSHD version to 0.10.1 Change-Id: Ic7e204fb7ee2eb172f4c8424fc3d4b7e6c631ddd --- .classpath | 4 +-- build.moxie | 4 ++- gitblit.iml | 12 +++---- .../ssh/DisabledFilesystemFactory.java | 6 ++-- .../transport/ssh/GitblitServerSession.java | 35 +++++++++++++++++++ .../transport/ssh/NonForwardingFilter.java | 15 ++++---- .../com/gitblit/transport/ssh/SshDaemon.java | 2 +- .../transport/ssh/SshSessionFactory.java | 35 +++++++++++++------ 8 files changed, 81 insertions(+), 32 deletions(-) create mode 100644 src/main/java/com/gitblit/transport/ssh/GitblitServerSession.java diff --git a/.classpath b/.classpath index 52377e2a..d3aec7e8 100644 --- a/.classpath +++ b/.classpath @@ -52,8 +52,8 @@ - - + + diff --git a/build.moxie b/build.moxie index 7c392266..6015becc 100644 --- a/build.moxie +++ b/build.moxie @@ -109,7 +109,8 @@ properties: { bouncycastle.version : 1.49 selenium.version : 2.28.0 wikitext.version : 1.4 - sshd.version: 0.6.0 + sshd.version: 0.10.1 + mina.version: 2.0.7 } # Dependencies @@ -157,6 +158,7 @@ dependencies: - compile 'org.bouncycastle:bcmail-jdk15on:${bouncycastle.version}' :war :authority - compile 'org.bouncycastle:bcpkix-jdk15on:${bouncycastle.version}' :war :authority - compile 'org.apache.sshd:sshd-core:${sshd.version}' :war !org.easymock +- compile 'org.apache.mina:mina-core:${mina.version}' :war !org.easymock - compile 'rome:rome:0.9' :war :manager :api - compile 'com.google.code.gson:gson:1.7.2' :war :fedclient :manager :api - compile 'org.codehaus.groovy:groovy-all:${groovy.version}' :war diff --git a/gitblit.iml b/gitblit.iml index c114d4d0..a48f12ad 100644 --- a/gitblit.iml +++ b/gitblit.iml @@ -529,24 +529,24 @@ - + - + - + - + - + - + diff --git a/src/main/java/com/gitblit/transport/ssh/DisabledFilesystemFactory.java b/src/main/java/com/gitblit/transport/ssh/DisabledFilesystemFactory.java index 32a896b8..c0578f9d 100644 --- a/src/main/java/com/gitblit/transport/ssh/DisabledFilesystemFactory.java +++ b/src/main/java/com/gitblit/transport/ssh/DisabledFilesystemFactory.java @@ -3,9 +3,9 @@ package com.gitblit.transport.ssh; import java.io.IOException; import org.apache.sshd.common.Session; -import org.apache.sshd.server.FileSystemFactory; -import org.apache.sshd.server.FileSystemView; -import org.apache.sshd.server.SshFile; +import org.apache.sshd.common.file.FileSystemFactory; +import org.apache.sshd.common.file.FileSystemView; +import org.apache.sshd.common.file.SshFile; public class DisabledFilesystemFactory implements FileSystemFactory { diff --git a/src/main/java/com/gitblit/transport/ssh/GitblitServerSession.java b/src/main/java/com/gitblit/transport/ssh/GitblitServerSession.java new file mode 100644 index 00000000..e5336025 --- /dev/null +++ b/src/main/java/com/gitblit/transport/ssh/GitblitServerSession.java @@ -0,0 +1,35 @@ +/* + * Copyright 2014 gitblit.com. + * + * Licensed 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 com.gitblit.transport.ssh; + +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.server.ServerFactoryManager; +import org.apache.sshd.server.session.ServerSession; + +// Expose addition of close session listeners +class GitblitServerSession extends ServerSession { + + GitblitServerSession(ServerFactoryManager server, IoSession ioSession) + throws Exception { + super(server, ioSession); + } + + void addCloseSessionListener(SshFutureListener l) { + closeFuture.addListener(l); + } +} diff --git a/src/main/java/com/gitblit/transport/ssh/NonForwardingFilter.java b/src/main/java/com/gitblit/transport/ssh/NonForwardingFilter.java index 82f84267..0ed7926c 100644 --- a/src/main/java/com/gitblit/transport/ssh/NonForwardingFilter.java +++ b/src/main/java/com/gitblit/transport/ssh/NonForwardingFilter.java @@ -1,28 +1,27 @@ package com.gitblit.transport.ssh; -import java.net.InetSocketAddress; - -import org.apache.sshd.server.ForwardingFilter; -import org.apache.sshd.server.session.ServerSession; +import org.apache.sshd.common.ForwardingFilter; +import org.apache.sshd.common.Session; +import org.apache.sshd.common.SshdSocketAddress; public class NonForwardingFilter implements ForwardingFilter { @Override - public boolean canForwardAgent(ServerSession session) { + public boolean canConnect(SshdSocketAddress address, Session session) { return false; } @Override - public boolean canForwardX11(ServerSession session) { + public boolean canForwardAgent(Session session) { return false; } @Override - public boolean canConnect(InetSocketAddress address, ServerSession session) { + public boolean canForwardX11(Session session) { return false; } @Override - public boolean canListen(InetSocketAddress address, ServerSession session) { + public boolean canListen(SshdSocketAddress address, Session session) { return false; } } diff --git a/src/main/java/com/gitblit/transport/ssh/SshDaemon.java b/src/main/java/com/gitblit/transport/ssh/SshDaemon.java index de57f5ff..5bd397d7 100644 --- a/src/main/java/com/gitblit/transport/ssh/SshDaemon.java +++ b/src/main/java/com/gitblit/transport/ssh/SshDaemon.java @@ -107,7 +107,7 @@ public class SshDaemon { sshd.setPasswordAuthenticator(new SshPasswordAuthenticator(gitblit)); sshd.setSessionFactory(new SshSessionFactory(idGenerator)); sshd.setFileSystemFactory(new DisabledFilesystemFactory()); - sshd.setForwardingFilter(new NonForwardingFilter()); + sshd.setTcpipForwardingFilter(new NonForwardingFilter()); DispatchCommand gitblitCmd = new DispatchCommand(); gitblitCmd.registerCommand(CreateRepository.class); diff --git a/src/main/java/com/gitblit/transport/ssh/SshSessionFactory.java b/src/main/java/com/gitblit/transport/ssh/SshSessionFactory.java index ef513404..4f61047d 100644 --- a/src/main/java/com/gitblit/transport/ssh/SshSessionFactory.java +++ b/src/main/java/com/gitblit/transport/ssh/SshSessionFactory.java @@ -17,11 +17,12 @@ package com.gitblit.transport.ssh; import java.net.SocketAddress; -import org.apache.mina.core.future.IoFuture; -import org.apache.mina.core.future.IoFutureListener; -import org.apache.mina.core.session.IoSession; import org.apache.mina.transport.socket.SocketSessionConfig; -import org.apache.sshd.server.session.ServerSession; +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.session.SessionFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,25 +46,37 @@ public class SshSessionFactory extends SessionFactory { } @Override - protected ServerSession createSession(final IoSession io) throws Exception { + protected AbstractSession createSession(final IoSession io) + throws Exception { log.info("connection accepted on " + io); - if (io.getConfig() instanceof SocketSessionConfig) { - final SocketSessionConfig c = (SocketSessionConfig) io.getConfig(); - c.setKeepAlive(true); + if (io instanceof MinaSession) { + if (((MinaSession) io).getSession().getConfig() instanceof SocketSessionConfig) { + ((SocketSessionConfig) ((MinaSession) io).getSession() + .getConfig()).setKeepAlive(true); + } } - final ServerSession s = (ServerSession) super.createSession(io); + final GitblitServerSession s = (GitblitServerSession) super + .createSession(io); SocketAddress peer = io.getRemoteAddress(); SshSession session = new SshSession(idGenerator.next(), peer); s.setAttribute(SshSession.KEY, session); - io.getCloseFuture().addListener(new IoFutureListener() { + // TODO(davido): Log a session close without authentication as a + // failure. + s.addCloseSessionListener(new SshFutureListener() { @Override - public void operationComplete(IoFuture future) { + public void operationComplete(CloseFuture future) { log.info("connection closed on " + io); } }); return s; } + + @Override + protected AbstractSession doCreateSession(IoSession ioSession) + throws Exception { + return new GitblitServerSession(server, ioSession); + } } -- 2.39.5