diff options
-rw-r--r-- | .classpath | 4 | ||||
-rw-r--r-- | build.moxie | 4 | ||||
-rw-r--r-- | gitblit.iml | 12 | ||||
-rw-r--r-- | src/main/java/com/gitblit/transport/ssh/DisabledFilesystemFactory.java | 6 | ||||
-rw-r--r-- | src/main/java/com/gitblit/transport/ssh/GitblitServerSession.java | 35 | ||||
-rw-r--r-- | src/main/java/com/gitblit/transport/ssh/NonForwardingFilter.java | 15 | ||||
-rw-r--r-- | src/main/java/com/gitblit/transport/ssh/SshDaemon.java | 2 | ||||
-rw-r--r-- | src/main/java/com/gitblit/transport/ssh/SshSessionFactory.java | 35 |
8 files changed, 81 insertions, 32 deletions
@@ -52,8 +52,8 @@ <classpathentry kind="lib" path="ext/bcprov-jdk15on-1.49.jar" sourcepath="ext/src/bcprov-jdk15on-1.49.jar" /> <classpathentry kind="lib" path="ext/bcmail-jdk15on-1.49.jar" sourcepath="ext/src/bcmail-jdk15on-1.49.jar" /> <classpathentry kind="lib" path="ext/bcpkix-jdk15on-1.49.jar" sourcepath="ext/src/bcpkix-jdk15on-1.49.jar" /> - <classpathentry kind="lib" path="ext/sshd-core-0.6.0.jar" sourcepath="ext/src/sshd-core-0.6.0.jar" /> - <classpathentry kind="lib" path="ext/mina-core-2.0.2.jar" sourcepath="ext/src/mina-core-2.0.2.jar" /> + <classpathentry kind="lib" path="ext/sshd-core-0.10.1.jar" sourcepath="ext/src/sshd-core-0.10.1.jar" /> + <classpathentry kind="lib" path="ext/mina-core-2.0.7.jar" sourcepath="ext/src/mina-core-2.0.7.jar" /> <classpathentry kind="lib" path="ext/rome-0.9.jar" sourcepath="ext/src/rome-0.9.jar" /> <classpathentry kind="lib" path="ext/jdom-1.0.jar" sourcepath="ext/src/jdom-1.0.jar" /> <classpathentry kind="lib" path="ext/gson-1.7.2.jar" sourcepath="ext/src/gson-1.7.2.jar" /> 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 @@ </library> </orderEntry> <orderEntry type="module-library"> - <library name="sshd-core-0.6.0.jar"> + <library name="sshd-core-0.10.1.jar"> <CLASSES> - <root url="jar://$MODULE_DIR$/ext/sshd-core-0.6.0.jar!/" /> + <root url="jar://$MODULE_DIR$/ext/sshd-core-0.10.1.jar!/" /> </CLASSES> <JAVADOC /> <SOURCES> - <root url="jar://$MODULE_DIR$/ext/src/sshd-core-0.6.0.jar!/" /> + <root url="jar://$MODULE_DIR$/ext/src/sshd-core-0.10.1.jar!/" /> </SOURCES> </library> </orderEntry> <orderEntry type="module-library"> - <library name="mina-core-2.0.2.jar"> + <library name="mina-core-2.0.7.jar"> <CLASSES> - <root url="jar://$MODULE_DIR$/ext/mina-core-2.0.2.jar!/" /> + <root url="jar://$MODULE_DIR$/ext/mina-core-2.0.7.jar!/" /> </CLASSES> <JAVADOC /> <SOURCES> - <root url="jar://$MODULE_DIR$/ext/src/mina-core-2.0.2.jar!/" /> + <root url="jar://$MODULE_DIR$/ext/src/mina-core-2.0.7.jar!/" /> </SOURCES> </library> </orderEntry> 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<CloseFuture> 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<IoFuture>() { + // TODO(davido): Log a session close without authentication as a + // failure. + s.addCloseSessionListener(new SshFutureListener<CloseFuture>() { @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); + } } |