You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2015/06/08 13:30:17 UTC
[4/6] mina-sshd git commit: [SSHD-483] Move classes from
org.apache.sshd to their rightful location - common, client or server
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSession.java b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSession.java
new file mode 100644
index 0000000..d4bd108
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSession.java
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sshd.client.session;
+
+import java.io.IOException;
+import java.nio.file.FileSystem;
+import java.security.KeyPair;
+import java.util.Map;
+
+import org.apache.sshd.client.ClientFactoryManager;
+import org.apache.sshd.client.SshClient;
+import org.apache.sshd.client.UserInteraction;
+import org.apache.sshd.client.channel.ChannelDirectTcpip;
+import org.apache.sshd.client.channel.ChannelExec;
+import org.apache.sshd.client.channel.ChannelShell;
+import org.apache.sshd.client.channel.ChannelSubsystem;
+import org.apache.sshd.client.channel.ClientChannel;
+import org.apache.sshd.client.future.AuthFuture;
+import org.apache.sshd.client.scp.ScpClient;
+import org.apache.sshd.client.sftp.SftpClient;
+import org.apache.sshd.common.SshdSocketAddress;
+import org.apache.sshd.common.future.CloseFuture;
+import org.apache.sshd.common.future.SshFuture;
+import org.apache.sshd.common.scp.ScpTransferEventListener;
+import org.apache.sshd.common.session.Session;
+
+/**
+ * An authenticated session to a given SSH server
+ *
+ * A client session is established using the {@link SshClient}.
+ * Once the session has been created, the user has to authenticate
+ * using either {@link #authPassword(String, String)} or
+ * {@link #authPublicKey(String, java.security.KeyPair)}.
+ *
+ * From this session, channels can be created using the
+ * {@link #createChannel(String)} method. Multiple channels can
+ * be created on a given session concurrently.
+ *
+ * When using the client in an interactive mode, the
+ * {@link #waitFor(int, long)} method can be used to listen to specific
+ * events such as the session being established, authenticated or closed.
+ *
+ * When a given session is no longer used, it must be closed using the
+ * {@link #close(boolean)} method.
+ *
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public interface ClientSession extends Session {
+
+ int TIMEOUT = 0x0001;
+ int CLOSED = 0x0002;
+ int WAIT_AUTH = 0x0004;
+ int AUTHED = 0x0008;
+
+ void addPasswordIdentity(String password);
+ void addPublicKeyIdentity(KeyPair key);
+
+ UserInteraction getUserInteraction();
+ void setUserInteraction(UserInteraction userInteraction);
+
+ /**
+ * Starts the authentication process.
+ * User identities will be tried until the server successfully authenticate the user.
+ * User identities must be provided before calling this method using
+ * {@link #addPasswordIdentity(String)} or {@link #addPublicKeyIdentity(java.security.KeyPair)}.
+ *
+ * @return the authentication future
+ * @throws IOException
+ * @see #addPasswordIdentity(String)
+ * @see #addPublicKeyIdentity(java.security.KeyPair)
+ */
+ AuthFuture auth() throws IOException;
+
+ /**
+ * Create a channel of the given type.
+ * Same as calling <code>createChannel(type, null)</code>.
+ */
+ ClientChannel createChannel(String type) throws IOException;
+
+ /**
+ * Create a channel of the given type and subtype.
+ */
+ ClientChannel createChannel(String type, String subType) throws IOException;
+
+ /**
+ * Create a channel to start a shell.
+ */
+ ChannelShell createShellChannel() throws IOException;
+
+ /**
+ * Create a channel to execute a command.
+ */
+ ChannelExec createExecChannel(String command) throws IOException;
+
+ /**
+ * Create a subsystem channel.
+ */
+ ChannelSubsystem createSubsystemChannel(String subsystem) throws IOException;
+
+ /**
+ * Create a direct tcp-ip channel which can be used to stream data to a remote port from the server.
+ */
+ ChannelDirectTcpip createDirectTcpipChannel(SshdSocketAddress local, SshdSocketAddress remote) throws IOException;
+
+ /**
+ * Create an SCP client from this session.
+ * @return An {@link ScpClient} instance. <B>Note:</B> uses the currently
+ * registered {@link ScpTransferEventListener} if any
+ * @see #setScpTransferEventListener(ScpTransferEventListener)
+ */
+ ScpClient createScpClient();
+
+ /**
+ * Create an SCP client from this session.
+ * @param listener A {@link ScpTransferEventListener} that can be used
+ * to receive information about the SCP operations - may be {@code null}
+ * to indicate no more events are required. <B>Note:</B> this listener
+ * is used <U>instead</U> of any listener set via {@link #setScpTransferEventListener(ScpTransferEventListener)}
+ * @return An {@link ScpClient} instance
+ */
+ ScpClient createScpClient(ScpTransferEventListener listener);
+
+ /**
+ * @return The last {@link ScpTransferEventListener} set via
+ * {@link #setScpTransferEventListener(ScpTransferEventListener)}
+ */
+ ScpTransferEventListener getScpTransferEventListener();
+
+ /**
+ * @param listener A default {@link ScpTransferEventListener} that can be used
+ * to receive information about the SCP operations - may be {@code null}
+ * to indicate no more events are required
+ * @see #createScpClient(ScpTransferEventListener)
+ */
+ void setScpTransferEventListener(ScpTransferEventListener listener);
+
+ /**
+ * Create an SFTP client from this session.
+ */
+ SftpClient createSftpClient() throws IOException;
+
+ FileSystem createSftpFileSystem() throws IOException;
+ FileSystem createSftpFileSystem(int readBufferSize, int writeBufferSize) throws IOException;
+
+ /**
+ * Start forwarding the given local address on the client to the given address on the server.
+ */
+ SshdSocketAddress startLocalPortForwarding(SshdSocketAddress local, SshdSocketAddress remote) throws IOException;
+
+ /**
+ * Stop forwarding the given local address.
+ */
+ void stopLocalPortForwarding(SshdSocketAddress local) throws IOException;
+
+ /**
+ * Start forwarding tcpip from the given address on the server to the
+ * given address on the client.
+ *
+ * The remote host name is the address to bind to on the server:
+ * <ul>
+ * <li>"" means that connections are to be accepted on all protocol families
+ * supported by the SSH implementation</li>
+ * <li>"0.0.0.0" means to listen on all IPv4 addresses</li>
+ * <li>"::" means to listen on all IPv6 addresses</li>
+ * <li>"localhost" means to listen on all protocol families supported by the SSH
+ * implementation on loopback addresses only, [RFC3330] and RFC3513]</li>
+ * <li>"127.0.0.1" and "::1" indicate listening on the loopback interfaces for
+ * IPv4 and IPv6 respectively</li>
+ * </ul>
+ *
+ */
+ SshdSocketAddress startRemotePortForwarding(SshdSocketAddress remote, SshdSocketAddress local) throws IOException;
+
+ /**
+ * Stop forwarding of the given remote address.
+ */
+ void stopRemotePortForwarding(SshdSocketAddress remote) throws IOException;
+
+ /**
+ * Start dynamic local port forwarding using a SOCKS proxy.
+ *
+ * @param local
+ * @return
+ * @throws IOException
+ */
+ SshdSocketAddress startDynamicPortForwarding(SshdSocketAddress local) throws IOException;
+
+ /**
+ * Stop a previously started dynamic port forwarding.
+ *
+ * @param local
+ * @throws IOException
+ */
+ void stopDynamicPortForwarding(SshdSocketAddress local) throws IOException;
+
+ /**
+ * Wait for a specific state.
+ */
+ int waitFor(int mask, long timeout);
+
+ /**
+ * Close this session.
+ */
+ @Override
+ CloseFuture close(boolean immediately);
+
+ /**
+ * Access to the metadata.
+ */
+ Map<Object, Object> getMetadataMap();
+
+ /**
+ * Return ClientFactoryManager for this session.
+ */
+ @Override
+ ClientFactoryManager getFactoryManager();
+
+ /**
+ * Switch to a none cipher for performance.
+ *
+ * This should be done after the authentication phase has been performed.
+ * After such a switch, interactive channels are not allowed anymore.
+ * Both client and server must have been configured to support the none cipher.
+ * If that's not the case, the returned future will be set with an exception.
+ *
+ * @return an {@link SshFuture} that can be used to wait for the exchange
+ * to be finished
+ * @throws IOException if a key exchange is already running
+ */
+ @SuppressWarnings("rawtypes")
+ SshFuture switchToNoneCipher() throws IOException;
+
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
index 806a160..d29b350 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
@@ -27,8 +27,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.sshd.ClientChannel;
-import org.apache.sshd.ClientSession;
import org.apache.sshd.client.ClientFactoryManager;
import org.apache.sshd.client.ServerKeyVerifier;
import org.apache.sshd.client.UserInteraction;
@@ -36,6 +34,7 @@ import org.apache.sshd.client.channel.ChannelDirectTcpip;
import org.apache.sshd.client.channel.ChannelExec;
import org.apache.sshd.client.channel.ChannelShell;
import org.apache.sshd.client.channel.ChannelSubsystem;
+import org.apache.sshd.client.channel.ClientChannel;
import org.apache.sshd.client.future.AuthFuture;
import org.apache.sshd.client.future.DefaultAuthFuture;
import org.apache.sshd.client.scp.DefaultScpClient;
@@ -47,7 +46,6 @@ import org.apache.sshd.client.sftp.SftpFileSystemProvider;
import org.apache.sshd.common.NamedResource;
import org.apache.sshd.common.Service;
import org.apache.sshd.common.ServiceFactory;
-import org.apache.sshd.common.SessionListener;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.SshdSocketAddress;
@@ -59,6 +57,7 @@ import org.apache.sshd.common.scp.ScpTransferEventListener;
import org.apache.sshd.common.session.AbstractConnectionService;
import org.apache.sshd.common.session.AbstractSession;
import org.apache.sshd.common.session.ConnectionService;
+import org.apache.sshd.common.session.SessionListener;
import org.apache.sshd.common.util.buffer.Buffer;
/**
@@ -177,6 +176,7 @@ public class ClientSessionImpl extends AbstractSession implements ClientSession
}
@Override
+ @SuppressWarnings("rawtypes")
public SshFuture switchToNoneCipher() throws IOException {
if (!(currentService instanceof AbstractConnectionService)
|| !((AbstractConnectionService) currentService).getChannels().isEmpty()) {
@@ -291,7 +291,7 @@ public class ClientSessionImpl extends AbstractSession implements ClientSession
@Override
public FileSystem createSftpFileSystem(int readBufferSize, int writeBufferSize) throws IOException {
- SftpFileSystem fs=new SftpFileSystem(new SftpFileSystemProvider((org.apache.sshd.SshClient) factoryManager), this);
+ SftpFileSystem fs=new SftpFileSystem(new SftpFileSystemProvider((org.apache.sshd.client.SshClient) factoryManager), this);
fs.setReadBufferSize(readBufferSize);
fs.setWriteBufferSize(writeBufferSize);
return fs;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthService.java b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthService.java
index 3f955a4..1bb5b58 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthService.java
@@ -32,9 +32,9 @@ import org.apache.sshd.common.FactoryManagerUtils;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.Service;
import org.apache.sshd.common.ServiceFactory;
-import org.apache.sshd.common.Session;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
+import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.util.CloseableUtils;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.buffer.Buffer;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java
index c934cd8..809bc91 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java
@@ -103,9 +103,9 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.sshd.ClientSession;
import org.apache.sshd.client.SftpException;
import org.apache.sshd.client.channel.ChannelSubsystem;
+import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.sftp.SftpConstants;
import org.apache.sshd.common.util.GenericUtils;
@@ -192,7 +192,12 @@ public class DefaultSftpClient extends AbstractSftpClient {
}
// Process commands
int rpos = incoming.rpos();
- while (receive(incoming));
+ for (int count=0; receive(incoming); count++) {
+ if (log.isTraceEnabled()) {
+ log.trace("Processed " + count + " data messages");
+ }
+ }
+
int read = incoming.rpos() - rpos;
// Compact and add remaining data
receiveBuffer.compact();
@@ -209,12 +214,12 @@ public class DefaultSftpClient extends AbstractSftpClient {
int rpos = incoming.rpos();
int wpos = incoming.wpos();
clientSession.resetIdleTimeout();
- if (wpos - rpos > 4) {
+ if ((wpos - rpos) > 4) {
int length = incoming.getInt();
if (length < 5) {
throw new IOException("Illegal sftp packet length: " + length);
}
- if (wpos - rpos >= length + 4) {
+ if ((wpos - rpos) >= (length + 4)) {
incoming.rpos(rpos);
incoming.wpos(rpos + 4 + length);
process(incoming);
@@ -231,7 +236,7 @@ public class DefaultSftpClient extends AbstractSftpClient {
* Process an SFTP packet
*/
protected void process(Buffer incoming) throws IOException {
- Buffer buffer = new ByteArrayBuffer();
+ Buffer buffer = new ByteArrayBuffer(incoming.available());
buffer.putBuffer(incoming);
buffer.rpos(5);
int id = buffer.getInt();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystem.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystem.java b/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystem.java
index de861af..026d13c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystem.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystem.java
@@ -33,7 +33,7 @@ import java.util.Set;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.sshd.ClientSession;
+import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.file.util.BaseFileSystem;
import org.apache.sshd.common.file.util.ImmutableList;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystemProvider.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystemProvider.java b/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystemProvider.java
index 99d7b5a..d4c171a 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystemProvider.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystemProvider.java
@@ -72,10 +72,10 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
-import org.apache.sshd.ClientSession;
-import org.apache.sshd.SshBuilder;
-import org.apache.sshd.SshClient;
+import org.apache.sshd.client.ClientBuilder;
import org.apache.sshd.client.SftpException;
+import org.apache.sshd.client.SshClient;
+import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.client.sftp.SftpClient.Attributes;
import org.apache.sshd.common.FactoryManagerUtils;
import org.apache.sshd.common.SshException;
@@ -102,7 +102,7 @@ public class SftpFileSystemProvider extends FileSystemProvider {
this.log = LoggerFactory.getLogger(getClass());
if (client == null) {
// TODO: make this configurable using system properties
- client = SshBuilder.client().build();
+ client = ClientBuilder.builder().build();
}
this.client = client;
this.client.start();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/AbstractFactoryManager.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/AbstractFactoryManager.java b/sshd-core/src/main/java/org/apache/sshd/common/AbstractFactoryManager.java
index 8c0e32f..f021e25 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/AbstractFactoryManager.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/AbstractFactoryManager.java
@@ -28,19 +28,28 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.apache.sshd.agent.SshAgentFactory;
+import org.apache.sshd.common.channel.Channel;
+import org.apache.sshd.common.channel.RequestHandler;
+import org.apache.sshd.common.cipher.Cipher;
import org.apache.sshd.common.compression.Compression;
import org.apache.sshd.common.file.FileSystemFactory;
+import org.apache.sshd.common.forward.TcpipForwarderFactory;
import org.apache.sshd.common.io.DefaultIoServiceFactoryFactory;
import org.apache.sshd.common.io.IoServiceFactory;
import org.apache.sshd.common.io.IoServiceFactoryFactory;
+import org.apache.sshd.common.kex.KeyExchange;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
+import org.apache.sshd.common.mac.Mac;
+import org.apache.sshd.common.random.Random;
import org.apache.sshd.common.session.AbstractSessionFactory;
import org.apache.sshd.common.session.ConnectionService;
import org.apache.sshd.common.session.SessionTimeoutListener;
+import org.apache.sshd.common.signature.Signature;
import org.apache.sshd.common.util.CloseableUtils;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.threads.ThreadUtils;
+import org.apache.sshd.server.forward.ForwardingFilter;
/**
* TODO Add javadoc
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/AbstractSessionIoHandler.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/AbstractSessionIoHandler.java b/sshd-core/src/main/java/org/apache/sshd/common/AbstractSessionIoHandler.java
deleted file mode 100644
index 2ca762a..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/AbstractSessionIoHandler.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.sshd.common;
-
-import org.apache.sshd.common.io.IoHandler;
-import org.apache.sshd.common.io.IoSession;
-import org.apache.sshd.common.session.AbstractSession;
-import org.apache.sshd.common.util.Readable;
-
-/**
- * TODO Add javadoc
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public abstract class AbstractSessionIoHandler implements IoHandler {
-
- protected abstract AbstractSession createSession(IoSession ioSession) throws Exception;
-
- @Override
- public void sessionCreated(IoSession ioSession) throws Exception {
- AbstractSession session = createSession(ioSession);
- AbstractSession.attachSession(ioSession, session);
- }
-
- @Override
- public void sessionClosed(IoSession ioSession) throws Exception {
- AbstractSession.getSession(ioSession).close(true);
- }
-
- @Override
- public void exceptionCaught(IoSession ioSession, Throwable cause) throws Exception {
- AbstractSession session = AbstractSession.getSession(ioSession, true);
- if (session != null) {
- session.exceptionCaught(cause);
- } else {
- throw new IllegalStateException("No session available", cause);
- }
- }
-
- @Override
- public void messageReceived(IoSession ioSession, Readable message) throws Exception {
- AbstractSession.getSession(ioSession).messageReceived(message);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/BaseBuilder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/BaseBuilder.java b/sshd-core/src/main/java/org/apache/sshd/common/BaseBuilder.java
new file mode 100644
index 0000000..ee0b2b1
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/common/BaseBuilder.java
@@ -0,0 +1,327 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.sshd.common;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.sshd.common.channel.Channel;
+import org.apache.sshd.common.channel.RequestHandler;
+import org.apache.sshd.common.cipher.BuiltinCiphers;
+import org.apache.sshd.common.cipher.Cipher;
+import org.apache.sshd.common.compression.BuiltinCompressions;
+import org.apache.sshd.common.compression.Compression;
+import org.apache.sshd.common.file.FileSystemFactory;
+import org.apache.sshd.common.file.nativefs.NativeFileSystemFactory;
+import org.apache.sshd.common.forward.DefaultTcpipForwarderFactory;
+import org.apache.sshd.common.forward.TcpipForwarderFactory;
+import org.apache.sshd.common.kex.BuiltinDHFactories;
+import org.apache.sshd.common.kex.KeyExchange;
+import org.apache.sshd.common.mac.BuiltinMacs;
+import org.apache.sshd.common.mac.Mac;
+import org.apache.sshd.common.random.BouncyCastleRandom;
+import org.apache.sshd.common.random.JceRandom;
+import org.apache.sshd.common.random.Random;
+import org.apache.sshd.common.random.SingletonRandomFactory;
+import org.apache.sshd.common.session.ConnectionService;
+import org.apache.sshd.common.signature.BuiltinSignatures;
+import org.apache.sshd.common.signature.Signature;
+import org.apache.sshd.common.util.ObjectBuilder;
+import org.apache.sshd.common.util.SecurityUtils;
+import org.apache.sshd.server.forward.ForwardingFilter;
+
+/**
+ * Base class for dedicated client/server instance builders
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public class BaseBuilder<T extends AbstractFactoryManager, S extends BaseBuilder<T, S>> implements ObjectBuilder<T> {
+ protected Factory<T> factory;
+ protected List<NamedFactory<KeyExchange>> keyExchangeFactories;
+ protected List<NamedFactory<Cipher>> cipherFactories;
+ protected List<NamedFactory<Compression>> compressionFactories;
+ protected List<NamedFactory<Mac>> macFactories;
+ protected List<NamedFactory<Signature>> signatureFactories;
+ protected Factory<Random> randomFactory;
+ protected List<NamedFactory<Channel>> channelFactories;
+ protected FileSystemFactory fileSystemFactory;
+ protected TcpipForwarderFactory tcpipForwarderFactory;
+ protected List<RequestHandler<ConnectionService>> globalRequestHandlers;
+ protected ForwardingFilter forwardingFilter;
+
+ public BaseBuilder() {
+ super();
+ }
+
+ protected S fillWithDefaultValues() {
+ if (signatureFactories == null) {
+ signatureFactories = setUpDefaultSignatures(false);
+ }
+
+ if (randomFactory == null) {
+ if (SecurityUtils.isBouncyCastleRegistered()) {
+ randomFactory = new SingletonRandomFactory(BouncyCastleRandom.BouncyCastleRandomFactory.INSTANCE);
+ } else {
+ randomFactory = new SingletonRandomFactory(JceRandom.JceRandomFactory.INSTANCE);
+ }
+ }
+
+ if (cipherFactories == null) {
+ cipherFactories = setUpDefaultCiphers(false);
+ }
+
+ // Compression is not enabled by default
+ //if (compressionFactories == null) {
+ // compressionFactories = Arrays.<NamedFactory<Compression>>asList(
+ // new CompressionNone.Factory(),
+ // new CompressionZlib.Factory(),
+ // new CompressionDelayedZlib.Factory());
+ //}
+ if (compressionFactories == null) {
+ compressionFactories = Arrays.<NamedFactory<Compression>>asList(BuiltinCompressions.none);
+ }
+
+ if (macFactories == null) {
+ macFactories = setUpDefaultMacs(false);
+ }
+
+ if (fileSystemFactory == null) {
+ fileSystemFactory = new NativeFileSystemFactory();
+ }
+
+ if (forwardingFilter == null) {
+ forwardingFilter = ForwardingFilter.RejectAllForwardingFilter.INSTANCE;
+ }
+
+ if (tcpipForwarderFactory == null) {
+ tcpipForwarderFactory = DefaultTcpipForwarderFactory.INSTANCE;
+ }
+
+ return me();
+ }
+
+ public S keyExchangeFactories(List<NamedFactory<KeyExchange>> keyExchangeFactories) {
+ this.keyExchangeFactories = keyExchangeFactories;
+ return me();
+ }
+
+ public S signatureFactories(final List<NamedFactory<Signature>> signatureFactories) {
+ this.signatureFactories = signatureFactories;
+ return me();
+ }
+
+ public S randomFactory(final Factory<Random> randomFactory) {
+ this.randomFactory = randomFactory;
+ return me();
+ }
+
+ public S cipherFactories(final List<NamedFactory<Cipher>> cipherFactories) {
+ this.cipherFactories = cipherFactories;
+ return me();
+ }
+
+ public S compressionFactories(final List<NamedFactory<Compression>> compressionFactories) {
+ this.compressionFactories = compressionFactories;
+ return me();
+ }
+
+ public S macFactories(final List<NamedFactory<Mac>> macFactories) {
+ this.macFactories = macFactories;
+ return me();
+ }
+
+ public S channelFactories(final List<NamedFactory<Channel>> channelFactories) {
+ this.channelFactories = channelFactories;
+ return me();
+ }
+
+ public S fileSystemFactory(final FileSystemFactory fileSystemFactory) {
+ this.fileSystemFactory = fileSystemFactory;
+ return me();
+ }
+
+ public S forwardingFilter(final ForwardingFilter filter) {
+ this.forwardingFilter = filter;
+ return me();
+ }
+
+ public S tcpipForwarderFactory(final TcpipForwarderFactory tcpipForwarderFactory) {
+ this.tcpipForwarderFactory = tcpipForwarderFactory;
+ return me();
+ }
+
+ public S globalRequestHandlers(final List<RequestHandler<ConnectionService>> globalRequestHandlers) {
+ this.globalRequestHandlers = globalRequestHandlers;
+ return me();
+ }
+
+ public S factory(final Factory<T> factory) {
+ this.factory = factory;
+ return me();
+ }
+
+ public T build(final boolean isFillWithDefaultValues) {
+ if (isFillWithDefaultValues) {
+ fillWithDefaultValues();
+ }
+
+ T ssh = factory.create();
+
+ ssh.setKeyExchangeFactories(keyExchangeFactories);
+ ssh.setSignatureFactories(signatureFactories);
+ ssh.setRandomFactory(randomFactory);
+ ssh.setCipherFactories(cipherFactories);
+ ssh.setCompressionFactories(compressionFactories);
+ ssh.setMacFactories(macFactories);
+ ssh.setChannelFactories(channelFactories);
+ ssh.setFileSystemFactory(fileSystemFactory);
+ ssh.setTcpipForwardingFilter(forwardingFilter);
+ ssh.setTcpipForwarderFactory(tcpipForwarderFactory);
+ ssh.setGlobalRequestHandlers(globalRequestHandlers);
+ return ssh;
+ }
+
+ @Override
+ public T build() {
+ return build(true);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected S me() {
+ return (S) this;
+ }
+
+ /**
+ * The default {@link BuiltinCiphers} setup in order of preference
+ * as specified by <A HREF="https://www.freebsd.org/cgi/man.cgi?query=ssh_config&sektion=5">
+ * ssh_config(5)</A>
+ */
+ public static final List<BuiltinCiphers> DEFAULT_CIPHERS_PREFERENCE =
+ Collections.unmodifiableList(
+ Arrays.asList(
+ BuiltinCiphers.aes128ctr,
+ BuiltinCiphers.aes192ctr,
+ BuiltinCiphers.aes256ctr,
+ BuiltinCiphers.arcfour256,
+ BuiltinCiphers.arcfour128,
+ BuiltinCiphers.aes128cbc,
+ BuiltinCiphers.tripledescbc,
+ BuiltinCiphers.blowfishcbc,
+ // TODO add support for cast128-cbc cipher
+ BuiltinCiphers.aes192cbc,
+ BuiltinCiphers.aes256cbc
+ // TODO add support for arcfour cipher
+ ));
+
+ /**
+ * @param ignoreUnsupported If {@code true} then all the default
+ * ciphers are included, regardless of whether they are currently
+ * supported by the JCE. Otherwise, only the supported ones out of the
+ * list are included
+ * @return A {@link List} of the default {@link NamedFactory}
+ * instances of the {@link Cipher}s according to the preference
+ * order defined by {@link #DEFAULT_CIPHERS_PREFERENCE}.
+ * <B>Note:</B> the list may be filtered to exclude unsupported JCE
+ * ciphers according to the <tt>ignoreUnsupported</tt> parameter
+ * @see BuiltinCiphers#isSupported()
+ */
+ public static List<NamedFactory<Cipher>> setUpDefaultCiphers(boolean ignoreUnsupported) {
+ return NamedFactory.Utils.setUpBuiltinFactories(ignoreUnsupported, DEFAULT_CIPHERS_PREFERENCE);
+ }
+
+ /**
+ * The default {@link BuiltinDHFactories} setup in order of preference
+ * as specified by <A HREF="https://www.freebsd.org/cgi/man.cgi?query=ssh_config&sektion=5">
+ * ssh_config(5)</A>
+ */
+ public static final List<BuiltinDHFactories> DEFAULT_KEX_PREFERENCE=
+ Collections.unmodifiableList(
+ Arrays.asList(
+ BuiltinDHFactories.ecdhp521,
+ BuiltinDHFactories.ecdhp384,
+ BuiltinDHFactories.ecdhp256,
+
+ BuiltinDHFactories.dhgex256,
+ BuiltinDHFactories.dhgex,
+
+ BuiltinDHFactories.dhg14,
+ BuiltinDHFactories.dhg1
+ ));
+
+ /**
+ * The default {@link BuiltinMacs} setup in order of preference
+ * as specified by <A HREF="https://www.freebsd.org/cgi/man.cgi?query=ssh_config&sektion=5">
+ * ssh_config(5)</A>
+ */
+ public static final List<BuiltinMacs> DEFAULT_MAC_PREFERENCE=
+ Collections.unmodifiableList(
+ Arrays.asList(
+ BuiltinMacs.hmacmd5,
+ BuiltinMacs.hmacsha1,
+ BuiltinMacs.hmacsha256,
+ BuiltinMacs.hmacsha512,
+ BuiltinMacs.hmacsha196,
+ BuiltinMacs.hmacmd596
+ ));
+ /**
+ * @param ignoreUnsupported If {@code true} all the available built-in
+ * {@link Mac} factories are added, otherwise only those that are supported
+ * by the current JDK setup
+ * @return A {@link List} of the default {@link NamedFactory}
+ * instances of the {@link Mac}s according to the preference
+ * order defined by {@link #DEFAULT_MAC_PREFERENCE}.
+ * <B>Note:</B> the list may be filtered to exclude unsupported JCE
+ * MACs according to the <tt>ignoreUnsupported</tt> parameter
+ * @see BuiltinMacs#isSupported()
+ */
+ public static final List<NamedFactory<Mac>> setUpDefaultMacs(boolean ignoreUnsupported) {
+ return NamedFactory.Utils.setUpBuiltinFactories(ignoreUnsupported, DEFAULT_MAC_PREFERENCE);
+ }
+
+ /**
+ * Preferred {@link BuiltinSignatures} according to
+ * <A HREF="https://www.freebsd.org/cgi/man.cgi?query=ssh_config&sektion=5>sshd_config(5)</A>
+ * {@code HostKeyAlgorithms} recommendation
+ */
+ public static final List<BuiltinSignatures> DEFAULT_SIGNATURE_PREFERENCE=
+ Collections.unmodifiableList(
+ Arrays.asList(
+ BuiltinSignatures.nistp256,
+ BuiltinSignatures.nistp384,
+ BuiltinSignatures.nistp521,
+ BuiltinSignatures.rsa,
+ BuiltinSignatures.dsa
+ ));
+
+ /**
+ * @param ignoreUnsupported If {@code true} all the available built-in
+ * {@link Signature} factories are added, otherwise only those that are supported
+ * by the current JDK setup
+ * @return A {@link List} of the default {@link NamedFactory}
+ * instances of the {@link Signature}s according to the preference
+ * order defined by {@link #DEFAULT_SIGNATURE_PREFERENCE}.
+ * <B>Note:</B> the list may be filtered to exclude unsupported JCE
+ * signatures according to the <tt>ignoreUnsupported</tt> parameter
+ * @see BuiltinSignatures#isSupported()
+ */
+ public static final List<NamedFactory<Signature>> setUpDefaultSignatures(boolean ignoreUnsupported) {
+ return NamedFactory.Utils.setUpBuiltinFactories(ignoreUnsupported, DEFAULT_SIGNATURE_PREFERENCE);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/Channel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/Channel.java b/sshd-core/src/main/java/org/apache/sshd/common/Channel.java
deleted file mode 100644
index f343686..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/Channel.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.sshd.common;
-
-import java.io.IOException;
-
-import org.apache.sshd.client.future.OpenFuture;
-import org.apache.sshd.common.channel.Window;
-import org.apache.sshd.common.future.CloseFuture;
-import org.apache.sshd.common.session.ConnectionService;
-import org.apache.sshd.common.util.buffer.Buffer;
-
-/**
- * TODO Add javadoc
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public interface Channel extends Closeable {
-
- int getId();
-
- int getRecipient();
-
- Window getLocalWindow();
-
- Window getRemoteWindow();
-
- Session getSession();
-
- void handleClose() throws IOException;
-
- void handleWindowAdjust(Buffer buffer) throws IOException;
-
- void handleRequest(Buffer buffer) throws IOException;
-
- void handleData(Buffer buffer) throws IOException;
-
- void handleExtendedData(Buffer buffer) throws IOException;
-
- void handleEof() throws IOException;
-
- void handleFailure() throws IOException;
-
- @Override
- CloseFuture close(boolean immediately);
-
- void init(ConnectionService service, Session session, int id) throws IOException;
-
- /**
- * For a server channel, this method will actually open the channel
- */
- OpenFuture open(int recipient, int rwsize, int rmpsize, Buffer buffer);
-
- /**
- * For a client channel, this method will be called internally by the session when the confirmation
- * has been received.
- */
- void handleOpenSuccess(int recipient, int rwsize, int rmpsize, Buffer buffer) throws IOException;
-
- /**
- * For a client channel, this method will be called internally by the session when
- * the server has rejected this channel opening.
- */
- void handleOpenFailure(Buffer buffer) throws IOException;
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/Cipher.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/Cipher.java b/sshd-core/src/main/java/org/apache/sshd/common/Cipher.java
deleted file mode 100644
index 9a1c33a..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/Cipher.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.sshd.common;
-
-/**
- * Wrapper for a cryptographic cipher, used either for encryption
- * or decryption.
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public interface Cipher {
-
- enum Mode {
- Encrypt, Decrypt
- }
-
- /**
- * Retrieves the size of the initialization vector
- *
- * @return
- */
- int getIVSize();
-
- /**
- * Retrieves the block size for this cipher
- *
- * @return
- */
- int getBlockSize();
-
- /**
- * Initialize the cipher for encryption or decryption with
- * the given private key and initialization vector
- *
- * @param mode
- * @param key
- * @param iv
- * @throws Exception
- */
- void init(Mode mode, byte[] key, byte[] iv) throws Exception;
-
- /**
- * Performs in-place encryption or decryption on the given data.
- *
- * @param input
- * @param inputOffset
- * @param inputLen
- * @throws Exception
- */
- void update(byte[] input, int inputOffset, int inputLen) throws Exception;
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/Digest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/Digest.java b/sshd-core/src/main/java/org/apache/sshd/common/Digest.java
deleted file mode 100644
index 6d9097d..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/Digest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.sshd.common;
-
-/**
- * Interface used to compute digests, based on algorithms such as MD5 or SHA1.
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public interface Digest {
-
- void init() throws Exception;
-
- int getBlockSize();
-
- void update(byte[] foo, int start, int len) throws Exception;
-
- byte[] digest() throws Exception;
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/FactoryManager.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/FactoryManager.java b/sshd-core/src/main/java/org/apache/sshd/common/FactoryManager.java
index 172eac4..8367e5b 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/FactoryManager.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/FactoryManager.java
@@ -23,11 +23,20 @@ import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
import org.apache.sshd.agent.SshAgentFactory;
+import org.apache.sshd.common.channel.Channel;
+import org.apache.sshd.common.channel.RequestHandler;
+import org.apache.sshd.common.cipher.Cipher;
import org.apache.sshd.common.compression.Compression;
import org.apache.sshd.common.file.FileSystemFactory;
+import org.apache.sshd.common.forward.TcpipForwarderFactory;
import org.apache.sshd.common.io.IoServiceFactory;
+import org.apache.sshd.common.kex.KeyExchange;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
+import org.apache.sshd.common.mac.Mac;
+import org.apache.sshd.common.random.Random;
import org.apache.sshd.common.session.ConnectionService;
+import org.apache.sshd.common.signature.Signature;
+import org.apache.sshd.server.forward.ForwardingFilter;
/**
* This interface allows retrieving all the <code>NamedFactory</code> used
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/FactoryManagerUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/FactoryManagerUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/FactoryManagerUtils.java
index a8ee0cc..ecfc04e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/FactoryManagerUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/FactoryManagerUtils.java
@@ -21,6 +21,7 @@ package org.apache.sshd.common;
import java.util.Map;
+import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.util.GenericUtils;
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/ForwardingFilter.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/ForwardingFilter.java b/sshd-core/src/main/java/org/apache/sshd/common/ForwardingFilter.java
deleted file mode 100644
index b3e33af..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/ForwardingFilter.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.sshd.common;
-
-import java.util.Collections;
-import java.util.EnumSet;
-import java.util.Set;
-
-import org.apache.sshd.agent.SshAgent;
-import org.apache.sshd.common.util.AbstractLoggingBean;
-import org.apache.sshd.common.util.GenericUtils;
-
-/**
- * Determines if a forwarding request will be permitted.
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public interface ForwardingFilter {
- /**
- * Determine if the session may arrange for agent forwarding.
- * <p>
- * This server process will open a new listen socket locally and export
- * the address in the {@link SshAgent#SSH_AUTHSOCKET_ENV_NAME} environment
- * variable.
- *
- * @param session session requesting permission to forward the agent.
- * @return true if the agent forwarding is permitted, false if denied.
- */
- boolean canForwardAgent(Session session);
-
- /**
- * Determine if the session may arrange for X11 forwarding.
- * <p>
- * This server process will open a new listen socket locally and export
- * the address in the environment so X11 clients can be tunneled to the
- * user's X11 display server.
- *
- * @param session session requesting permission to forward X11 connections.
- * @return true if the X11 forwarding is permitted, false if denied.
- */
- boolean canForwardX11(Session session);
-
- /**
- * Determine if the session may listen for inbound connections.
- * <p>
- * This server process will open a new listen socket on the address given
- * by the client (usually 127.0.0.1 but may be any address). Any inbound
- * connections to this socket will be tunneled over the session to the
- * client, which the client will then forward the connection to another
- * host on the client's side of the network.
- *
- * @param address address the client has requested this server listen
- * for inbound connections on, and relay them through the client.
- * @param session session requesting permission to listen for connections.
- * @return true if the socket is permitted; false if it must be denied.
- */
- boolean canListen(SshdSocketAddress address, Session session);
-
- /**
- * The type of requested connection forwarding. The type's {@link #getName()}
- * method returns the SSH request type
- */
- enum Type implements NamedResource {
- Direct("direct-tcpip"),
- Forwarded("forwarded-tcpip");
-
- private final String name;
-
- @Override
- public final String getName() {
- return name;
- }
-
- Type(String name) {
- this.name = name;
- }
-
- public static final Set<Type> VALUES =
- Collections.unmodifiableSet(EnumSet.allOf(Type.class));
-
- /**
- * @param name Either the enum name or the request - ignored if {@code null}/empty
- * @return The matching {@link Type} value - case <U>insensitive</U>,
- * or {@code null} if no match found
- * @see #fromName(String)
- * @see #fromEnumName(String)
- */
- public static final Type fromString(String name) {
- if (GenericUtils.isEmpty(name)) {
- return null;
- }
-
- Type t = fromName(name);
- if (t == null) {
- t = fromEnumName(name);
- }
-
- return t;
- }
-
- /**
- * @param name The request name - ignored if {@code null}/empty
- * @return The matching {@link Type} value - case <U>insensitive</U>,
- * or {@code null} if no match found
- */
- public static final Type fromName(String name) {
- if (GenericUtils.isEmpty(name)) {
- return null;
- }
-
- for (Type t : VALUES) {
- if (name.equalsIgnoreCase(t.getName())) {
- return t;
- }
- }
-
- return null;
- }
-
- /**
- * @param name The enum value name - ignored if {@code null}/empty
- * @return The matching {@link Type} value - case <U>insensitive</U>,
- * or {@code null} if no match found
- */
- public static final Type fromEnumName(String name) {
- if (GenericUtils.isEmpty(name)) {
- return null;
- }
-
- for (Type t : VALUES) {
- if (name.equalsIgnoreCase(t.name())) {
- return t;
- }
- }
-
- return null;
- }
- }
-
- /**
- * Determine if the session may create an outbound connection.
- * <p>
- * This server process will connect to another server listening on the
- * address specified by the client. Usually this is to another port on
- * the same host (127.0.0.1) but may be to any other system this server
- * can reach on the server's side of the network.
- *
- * @param type The {@link Type} of requested connection forwarding
- * @param address address the client has requested this server listen
- * for inbound connections on, and relay them through the client.
- * @param session session requesting permission to listen for connections.
- * @return true if the socket is permitted; false if it must be denied.
- */
- boolean canConnect(Type type, SshdSocketAddress address, Session session);
-
- /**
- * A {@link ForwardingFilter} implementation that returns the same "static"
- * result for <U>all</U> the queries.
- */
- public static class StaticDecisionForwardingFilter extends AbstractLoggingBean implements ForwardingFilter {
- private final boolean acceptance;
-
- /**
- * @param acceptance The acceptance status for <U>all</U> the queries
- */
- public StaticDecisionForwardingFilter(boolean acceptance) {
- this.acceptance = acceptance;
- }
-
- public final boolean isAccepted() {
- return acceptance;
- }
-
- @Override
- public boolean canForwardAgent(Session session) {
- return checkAcceptance("auth-agent-req@openssh.com", session, SshdSocketAddress.LOCALHOST_ADDRESS);
- }
-
- @Override
- public boolean canForwardX11(Session session) {
- return checkAcceptance("x11-req", session, SshdSocketAddress.LOCALHOST_ADDRESS);
- }
-
- @Override
- public boolean canListen(SshdSocketAddress address, Session session) {
- return checkAcceptance("tcpip-forward", session, address);
- }
-
- @Override
- public boolean canConnect(Type type, SshdSocketAddress address, Session session) {
- return checkAcceptance(type.getName(), session, address);
- }
-
- /**
- * @param request The SSH request that ultimately led to this filter being consulted
- * @param session The requesting {@link Session}
- * @param target The request target - may be {@link SshdSocketAddress#LOCALHOST_ADDRESS}
- * if no real target
- * @return The (static) {@link #isAccepted()} flag
- */
- protected boolean checkAcceptance(String request, Session session, SshdSocketAddress target) {
- boolean accepted = isAccepted();
- if (log.isDebugEnabled()) {
- log.debug("checkAcceptance(" + request + ")[" + session + "] acceptance for target=" + target + " is " + accepted);
- }
- return accepted;
- }
- }
-
- /**
- * A {@link ForwardingFilter} that accepts all requests
- */
- public static class AcceptAllForwardingFilter extends StaticDecisionForwardingFilter {
- public static final AcceptAllForwardingFilter INSTANCE = new AcceptAllForwardingFilter();
-
- public AcceptAllForwardingFilter() {
- super(true);
- }
- }
-
- /**
- * A {@link ForwardingFilter} that rejects all requests
- */
- public static class RejectAllForwardingFilter extends StaticDecisionForwardingFilter {
- public static final RejectAllForwardingFilter INSTANCE = new RejectAllForwardingFilter();
-
- public RejectAllForwardingFilter() {
- super(false);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/KeyExchange.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/KeyExchange.java b/sshd-core/src/main/java/org/apache/sshd/common/KeyExchange.java
deleted file mode 100644
index d0c3e7a..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/KeyExchange.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.sshd.common;
-
-import java.security.PublicKey;
-
-import org.apache.sshd.common.session.AbstractSession;
-import org.apache.sshd.common.util.buffer.Buffer;
-
-/**
- * Key exchange algorithm.
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public interface KeyExchange {
-
- /**
- * Initialize the key exchange algorithm.
- *
- * @param session the session using this algorithm
- * @param V_S the server identification string
- * @param V_C the client identification string
- * @param I_S the server key init packet
- * @param I_C the client key init packet
- * @throws Exception if an error occurs
- */
- void init(AbstractSession session, byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception;
-
- /**
- * Process the next packet
- *
- * @param buffer the packet
- * @return a boolean indicating if the processing is complete or if more packets are to be received
- * @throws Exception if an error occurs
- */
- boolean next(Buffer buffer) throws Exception;
-
- /**
- * The message digest used by this key exchange algorithm.
- *
- * @return the message digest
- */
- Digest getHash();
-
- /**
- * Retrieves the computed H parameter
- *
- * @return
- */
- byte[] getH();
-
- /**
- * Retrieves the computed K parameter
- *
- * @return
- */
- byte[] getK();
-
- /**
- * Retrieves the server's key
- */
- PublicKey getServerKey();
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/Mac.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/Mac.java b/sshd-core/src/main/java/org/apache/sshd/common/Mac.java
deleted file mode 100644
index 296eac1..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/Mac.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.sshd.common;
-
-/**
- * Message Authentication Code for use in SSH.
- * It usually wraps a javax.crypto.Mac class.
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public interface Mac {
-
- int getBlockSize();
-
- void init(byte[] key) throws Exception;
-
- void update(byte[] foo, int start, int len);
-
- void updateUInt(long foo);
-
- void doFinal(byte[] buf, int offset) throws Exception;
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/PtyMode.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/PtyMode.java b/sshd-core/src/main/java/org/apache/sshd/common/PtyMode.java
deleted file mode 100644
index 5b06714..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/PtyMode.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.sshd.common;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * A enum describing the tty modes according to
- * <a href="https://tools.ietf.org/html/rfc4254#section-8">RFC 4254 - section 8</a>.
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public enum PtyMode {
-
- // Chars
- VINTR(1), VQUIT(2), VERASE(3), VKILL(4), VEOF(5), VEOL(6), VEOL2(7), VSTART(8), VSTOP(9),
- VSUSP(10), VDSUSP(11), VREPRINT(12), VWERASE(13), VLNEXT(14), VFLUSH(15), VSWTCH(16), VSTATUS(17), VDISCARD(18),
-
- // I flags
- IGNPAR(30), PARMRK(31), INPCK(32), ISTRIP(33), INLCR(34), IGNCR(35), ICRNL(36), IUCLC(37), IXON(38), IXANY(39),
- IXOFF(40), IMAXBEL(41),
-
- // L flags
- ISIG(50), ICANON(51), XCASE(52), ECHO(53), ECHOE(54), ECHOK(55), ECHONL(56), NOFLSH(57), TOSTOP(58), IEXTEN(59),
- ECHOCTL(60), ECHOKE(61), PENDIN(62),
-
- // O flags
- OPOST(70), OLCUC(71), ONLCR(72), OCRNL(73), ONOCR(74), ONLRET(75),
-
- // C flags
- CS7(90), CS8(91), PARENB(92), PARODD(93),
-
- // Speeed
- TTY_OP_ISPEED(128), TTY_OP_OSPEED(129);
-
- private int v;
-
- private PtyMode(int v) {
- this.v = v;
- }
-
- public int toInt() {
- return v;
- }
-
- static Map<Integer, PtyMode> commands;
-
- static {
- commands = new HashMap<Integer, PtyMode>();
- for (PtyMode c : PtyMode.values()) {
- commands.put(Integer.valueOf(c.toInt()), c);
- }
- }
-
- public static PtyMode fromInt(int b) {
- return commands.get(Integer.valueOf(0x00FF & (b + 256)));
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/Random.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/Random.java b/sshd-core/src/main/java/org/apache/sshd/common/Random.java
deleted file mode 100644
index 0e11ad6..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/Random.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.sshd.common;
-
-/**
- * A pseudo random number generator.
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public interface Random {
-
- /**
- * Fill part of bytes with random values.
- *
- * @param bytes byte array to be filled.
- * @param start index to start filling at.
- * @param len length of segment to fill.
- */
- void fill(byte[] bytes, int start, int len);
-
- /**
- * Returns a pseudo-random uniformly distributed {@code int}
- * in the half-open range [0, n).
- */
- int random(int n);
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/RequestHandler.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/RequestHandler.java b/sshd-core/src/main/java/org/apache/sshd/common/RequestHandler.java
deleted file mode 100644
index db688eb..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/RequestHandler.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.sshd.common;
-
-import org.apache.sshd.common.util.buffer.Buffer;
-
-/**
- * A global request handler.
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public interface RequestHandler<T> {
-
- enum Result {
- Unsupported,
- Replied,
- ReplySuccess,
- ReplyFailure
- }
-
- /**
- * Process the ssh-connection global request.
- * If an exception is thrown, the ConnectionService will send a failure message if needed
- * and the request will be considered handled.
- *
- * @param t
- * @param request
- * @param wantReply
- * @param buffer
- * @return
- * @throws Exception
- */
- Result process(T t, String request, boolean wantReply, Buffer buffer) throws Exception;
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/Service.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/Service.java b/sshd-core/src/main/java/org/apache/sshd/common/Service.java
index b62a905..2339c4c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/Service.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/Service.java
@@ -19,6 +19,7 @@
package org.apache.sshd.common;
import org.apache.sshd.common.future.CloseFuture;
+import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.util.buffer.Buffer;
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/ServiceFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/ServiceFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/ServiceFactory.java
index d74989c..340f827 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/ServiceFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/ServiceFactory.java
@@ -21,6 +21,7 @@ package org.apache.sshd.common;
import java.io.IOException;
import java.util.Collection;
+import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.util.GenericUtils;
public interface ServiceFactory extends NamedResource {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/Session.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/Session.java b/sshd-core/src/main/java/org/apache/sshd/common/Session.java
deleted file mode 100644
index 50f7144..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/Session.java
+++ /dev/null
@@ -1,255 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.sshd.common;
-
-import java.io.IOException;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.sshd.common.future.SshFuture;
-import org.apache.sshd.common.io.IoSession;
-import org.apache.sshd.common.io.IoWriteFuture;
-import org.apache.sshd.common.util.buffer.Buffer;
-
-/**
- * Represents an SSH session
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public interface Session extends Closeable {
-
- /**
- * Timeout status.
- */
- enum TimeoutStatus {
- NoTimeout,
- AuthTimeout,
- IdleTimeout
- }
-
- /**
- * Returns the value of the user-defined attribute of this session.
- *
- * @param key the key of the attribute; must not be null.
- * @return <tt>null</tt> if there is no attribute with the specified key
- */
- <T> T getAttribute(AttributeKey<T> key);
-
- /**
- * Sets a user-defined attribute.
- *
- * @param key the key of the attribute; must not be null.
- * @param value the value of the attribute; must not be null.
- * @return The old value of the attribute. <tt>null</tt> if it is new.
- */
- <T, E extends T> T setAttribute(AttributeKey<T> key, E value);
-
- /**
- * Retrieve the name of the user authenticated on this session
- * or null if the session has not been authenticated yet.
- *
- * @return the user name.
- */
- String getUsername();
-
- /**
- * Retrieve the client version for this session.
- *
- * @return the client version.
- */
- String getClientVersion();
-
- /**
- * Retrieve the server version for this session.
- *
- * @return the server version.
- */
- String getServerVersion();
-
- /**
- * Retrieve the FactoryManager that has created this session
- *
- * @return the factory manager, can not be <tt>null</tt>.
- */
- FactoryManager getFactoryManager();
-
- /**
- * Retrieve one of the negotiated values during the KEX stage
- * @param paramType The parameter type index - one of the {@link SSHConstants}
- * {@code PROPOSAL_XXX} values
- * @return The negotiated parameter value - {@code null} if invalid
- * parameter index or no negotiated value
- */
- String getNegotiatedKexParameter(int paramType);
-
- /**
- * Retrieve a configuration property as an integer
- *
- * @param name the name of the property
- * @param defaultValue the default value
- * @return the value of the configuration property or the default value if not found
- */
- int getIntProperty(String name, int defaultValue);
-
- /**
- * Create a new buffer for the specified SSH packet and reserve the needed space
- * (5 bytes) for the packet header.
- *
- * @param cmd the SSH command
- * @return a new buffer ready for write
- */
- Buffer createBuffer(byte cmd);
-
- /**
- * Create a new buffer for the specified SSH packet and reserve the needed space
- * (5 bytes) for the packet header.
- *
- * @param cmd the SSH command
- * @param estimatedSize estimated number of bytes the buffer will hold, 0 if unknown.
- * @return a new buffer ready for write
- */
- Buffer createBuffer(byte cmd, int estimatedSize);
-
- /**
- * Encode and send the given buffer.
- * The buffer has to have 5 bytes free at the beginning to allow the encoding to take place.
- * Also, the write position of the buffer has to be set to the position of the last byte to write.
- *
- * @param buffer the buffer to encode and send
- * @return a future that can be used to check when the packet has actually been sent
- * @throws java.io.IOException if an error occurred when encoding sending the packet
- */
- IoWriteFuture writePacket(Buffer buffer) throws IOException;
-
- /**
- * Encode and send the given buffer with the specified timeout.
- * If the buffer could not be written before the timeout elapses, the returned
- * {@link org.apache.sshd.common.io.IoWriteFuture} will be set with a
- * {@link java.util.concurrent.TimeoutException} exception to indicate a timeout.
- *
- * @param buffer the buffer to encode and spend
- * @param timeout the timeout
- * @param unit the time unit of the timeout parameter
- * @return a future that can be used to check when the packet has actually been sent
- * @throws java.io.IOException if an error occurred when encoding sending the packet
- */
- IoWriteFuture writePacket(Buffer buffer, long timeout, TimeUnit unit) throws IOException;
-
- /**
- * Send a global request and wait for the response.
- * This must only be used when sending a SSH_MSG_GLOBAL_REQUEST with a result expected,
- * else it will wait forever.
- *
- * @param buffer the buffer containing the global request
- * @return the return buffer if the request was successful, <code>null</code> otherwise.
- * @throws java.io.IOException if an error occurred when encoding sending the packet
- */
- Buffer request(Buffer buffer) throws IOException;
-
- /**
- * Handle any exceptions that occured on this session.
- * The session will be closed and a disconnect packet will be
- * sent before if the given exception is an
- * {@link org.apache.sshd.common.SshException}.
- *
- * @param t the exception to process
- */
- void exceptionCaught(Throwable t);
-
- /**
- * Add a session |listener|.
- *
- * @param listener the session listener to add
- */
- void addListener(SessionListener listener);
-
- /**
- * Remove a session |listener|.
- *
- * @param listener the session listener to remove
- */
- void removeListener(SessionListener listener);
-
- /**
- * Initiate a new key exchange.
- */
- SshFuture reExchangeKeys() throws IOException;
-
- /**
- * Get the service of the specified type.
- * If the service is not of the specified class,
- * an IllegalStateException will be thrown.
- *
- * @throws java.lang.IllegalStateException
- */
- <T extends Service> T getService(Class<T> clazz);
-
- /**
- * Returns the IoSession associated to this ssh session
- */
- IoSession getIoSession();
-
- /**
- * Type safe key for storage within the user attributes of {@link org.apache.sshd.common.session.AbstractSession}.
- * Typically it is used as a static variable that is shared between the producer
- * and the consumer. To further restrict access the setting or getting it from
- * the Session you can add static get and set methods, e.g:
- *
- * <pre>
- * private static final AttributeKey<MyValue> MY_KEY = new AttributeKey<MyValue>();
- *
- * public static MyValue getMyValue(Session s) {
- * return s.getAttribute(MY_KEY);
- * }
- *
- * private void setMyValue(Session s, MyValue value) {
- * s.setAttribute(MY_KEY, value);
- * }
- * </pre>
- *
- * @param <T> type of value stored in the attribute.
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
- public class AttributeKey<T> {
- public AttributeKey() {
- super();
- }
- }
-
- public void resetIdleTimeout();
-
- /**
- * Check if timeout has occurred.
- * @return the timeout status, never <code>null</code>
- */
- public TimeoutStatus getTimeoutStatus();
-
- /**
- * What is timeout value in milliseconds for authentication stage
- * @return
- */
- public long getAuthTimeout();
-
- /**
- * What is timeout value in milliseconds for communication
- * @return
- */
-
- public long getIdleTimeout();
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/SessionListener.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/SessionListener.java b/sshd-core/src/main/java/org/apache/sshd/common/SessionListener.java
deleted file mode 100644
index 6bbfecc..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/SessionListener.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.sshd.common;
-
-import java.util.EventListener;
-
-/**
- * Represents an interface receiving Session events.
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public interface SessionListener extends EventListener {
-
- enum Event {
- KeyEstablished, Authenticated, KexCompleted
- }
-
- /**
- * A new session just been created
- * @param session
- */
- void sessionCreated(Session session);
-
- /**
- * An event has been triggered
- * @param session
- * @param event
- */
- void sessionEvent(Session session, Event event);
-
- /**
- * A session has been closed
- * @param session
- */
- void sessionClosed(Session session);
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/Signature.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/Signature.java b/sshd-core/src/main/java/org/apache/sshd/common/Signature.java
deleted file mode 100644
index cab014c..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/Signature.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.sshd.common;
-
-import java.security.PrivateKey;
-import java.security.PublicKey;
-
-/**
- * Signature interface for SSH used to sign or verify packets
- * Usually wraps a javax.crypto.Signature object
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public interface Signature {
-
- /**
- * Initialize this signature with the given public key and private key.
- * If the private key is null, only signature verification can be performed.
- *
- * @param pubkey
- * @param prvkey
- * @throws Exception
- */
- void init(PublicKey pubkey, PrivateKey prvkey) throws Exception;
-
- /**
- * Update the computed signature with the given data
- *
- * @param H
- * @param off
- * @param len
- * @throws Exception
- */
- void update(byte[] H, int off, int len) throws Exception;
-
- /**
- * Verify against the given signature
- *
- * @param sig
- * @return
- * @throws Exception
- */
- boolean verify(byte[] sig) throws Exception;
-
- /**
- * Compute the signature
- *
- * @return
- * @throws Exception
- */
- byte[] sign() throws Exception;
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b98f342/sshd-core/src/main/java/org/apache/sshd/common/TcpipForwarder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/TcpipForwarder.java b/sshd-core/src/main/java/org/apache/sshd/common/TcpipForwarder.java
deleted file mode 100644
index bd77bf9..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/TcpipForwarder.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.sshd.common;
-
-
-import java.io.IOException;
-
-public interface TcpipForwarder extends Closeable {
-
- /**
- * Start forwarding the given local address on the client to the given address on the server.
- */
- SshdSocketAddress startLocalPortForwarding(SshdSocketAddress local, SshdSocketAddress remote) throws IOException;
-
- /**
- * Stop forwarding the given local address.
- */
- void stopLocalPortForwarding(SshdSocketAddress local) throws IOException;
-
- /**
- * Start forwarding tcpip from the given remote address to the
- * given local address.
- *
- * The remote host name is the address to bind to on the server:
- * <ul>
- * <li>"" means that connections are to be accepted on all protocol families
- * supported by the SSH implementation</li>
- * <li>"0.0.0.0" means to listen on all IPv4 addresses</li>
- * <li>"::" means to listen on all IPv6 addresses</li>
- * <li>"localhost" means to listen on all protocol families supported by the SSH
- * implementation on loopback addresses only, [RFC3330] and RFC3513]</li>
- * <li>"127.0.0.1" and "::1" indicate listening on the loopback interfaces for
- * IPv4 and IPv6 respectively</li>
- * </ul>
- *
- */
- SshdSocketAddress startRemotePortForwarding(SshdSocketAddress remote, SshdSocketAddress local) throws IOException;
-
- /**
- * Stop forwarding of the given remote address.
- */
- void stopRemotePortForwarding(SshdSocketAddress remote) throws IOException;
-
- /**
- * Retrieve the local address that the remote port is forwarded to
- * @param remotePort
- * @return
- */
- SshdSocketAddress getForwardedPort(int remotePort);
-
- /**
- * Called when the other side requested a remote port forward.
- * @param local
- * @return the list of bound local addresses
- * @throws IOException
- */
- SshdSocketAddress localPortForwardingRequested(SshdSocketAddress local) throws IOException;
-
- /**
- * Called when the other side cancelled a remote port forward.
- * @param local
- * @throws IOException
- */
- void localPortForwardingCancelled(SshdSocketAddress local) throws IOException;
-
- SshdSocketAddress startDynamicPortForwarding(SshdSocketAddress local) throws IOException;
-
- void stopDynamicPortForwarding(SshdSocketAddress local) throws IOException;
-
-}