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/05/14 02:44:47 UTC
[1/4] mina-sshd git commit: [SSHD-459] Make Buffer an abstract class
Repository: mina-sshd
Updated Branches:
refs/heads/master 7ccbd0663 -> 9f0bb1bce
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/test/java/org/apache/sshd/deprecated/ClientUserAuthServiceOld.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/ClientUserAuthServiceOld.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/ClientUserAuthServiceOld.java
index 5265af0..f2dfc68 100644
--- a/sshd-core/src/test/java/org/apache/sshd/deprecated/ClientUserAuthServiceOld.java
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/ClientUserAuthServiceOld.java
@@ -29,8 +29,8 @@ 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.util.Buffer;
import org.apache.sshd.common.util.CloseableUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuth.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuth.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuth.java
index d5aa426..993575b 100644
--- a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuth.java
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuth.java
@@ -20,7 +20,7 @@ package org.apache.sshd.deprecated;
import java.io.IOException;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* TODO Add javadoc
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java
index d6906e6..efcd610 100644
--- a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java
@@ -25,8 +25,9 @@ import java.util.Iterator;
import org.apache.sshd.agent.SshAgent;
import org.apache.sshd.client.session.ClientSessionImpl;
import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.KeyUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
/**
* Authentication delegating to an SSH agent
@@ -59,8 +60,8 @@ public class UserAuthAgent extends AbstractUserAuth {
buffer.putPublicKey(key);
- Buffer bs = new Buffer();
- bs.putString(session.getKex().getH());
+ Buffer bs = new ByteArrayBuffer();
+ bs.putBytes(session.getKex().getH());
bs.putByte(SshConstants.SSH_MSG_USERAUTH_REQUEST);
bs.putString(session.getUsername());
bs.putString(service);
@@ -69,7 +70,7 @@ public class UserAuthAgent extends AbstractUserAuth {
bs.putString(KeyUtils.getKeyType(key));
bs.putPublicKey(key);
- Buffer bs2 = new Buffer();
+ Buffer bs2 = new ByteArrayBuffer();
bs2.putString(KeyUtils.getKeyType(key));
bs2.putBytes(agent.sign(key, bs.getCompactData()));
buffer.putBytes(bs2.array(), bs2.rpos(), bs2.available());
@@ -82,6 +83,7 @@ public class UserAuthAgent extends AbstractUserAuth {
}
}
+ @Override
public Result next(Buffer buffer) throws IOException {
if (buffer == null) {
if (keys.hasNext()) {
@@ -108,7 +110,7 @@ public class UserAuthAgent extends AbstractUserAuth {
}
} else {
// TODO: check packets
- log.info("Received unknown packet: {}", cmd);
+ log.info("Received unknown packet: {}", Byte.valueOf(cmd));
return Result.Continued;
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java
index 0ff3353..126b1b3 100644
--- a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java
@@ -23,7 +23,7 @@ import java.io.IOException;
import org.apache.sshd.client.UserInteraction;
import org.apache.sshd.client.session.ClientSessionImpl;
import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
import static org.apache.sshd.common.SshConstants.*;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java
index 9410c9a..43aec24 100644
--- a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java
@@ -22,7 +22,7 @@ import java.io.IOException;
import org.apache.sshd.client.session.ClientSessionImpl;
import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java
index 6cb43bd..73f15bb 100644
--- a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java
@@ -25,8 +25,9 @@ import org.apache.sshd.client.session.ClientSessionImpl;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.Signature;
import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.KeyUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -46,6 +47,7 @@ public class UserAuthPublicKey extends AbstractUserAuth {
this.key = key;
}
+ @Override
public Result next(Buffer buffer) throws IOException {
if (buffer == null) {
try {
@@ -64,8 +66,8 @@ public class UserAuthPublicKey extends AbstractUserAuth {
Signature verif = NamedFactory.Utils.create(session.getFactoryManager().getSignatureFactories(), alg);
verif.init(key.getPublic(), key.getPrivate());
- Buffer bs = new Buffer();
- bs.putString(session.getKex().getH());
+ Buffer bs = new ByteArrayBuffer();
+ bs.putBytes(session.getKex().getH());
bs.putByte(SshConstants.SSH_MSG_USERAUTH_REQUEST);
bs.putString(session.getUsername());
bs.putString(service);
@@ -75,7 +77,7 @@ public class UserAuthPublicKey extends AbstractUserAuth {
bs.putPublicKey(key.getPublic());
verif.update(bs.array(), bs.rpos(), bs.available());
- bs = new Buffer();
+ bs = new ByteArrayBuffer();
bs.putString(alg);
bs.putBytes(verif.sign());
buffer.putBytes(bs.array(), bs.rpos(), bs.available());
@@ -96,7 +98,7 @@ public class UserAuthPublicKey extends AbstractUserAuth {
log.debug("Received SSH_MSG_USERAUTH_FAILURE");
return Result.Failure;
} else {
- log.debug("Received unknown packet {}", cmd);
+ log.debug("Received unknown packet {}", Byte.valueOf(cmd));
// TODO: check packets
return Result.Continued;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/test/java/org/apache/sshd/server/channel/ChannelSessionTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/channel/ChannelSessionTest.java b/sshd-core/src/test/java/org/apache/sshd/server/channel/ChannelSessionTest.java
index 02d4444..15bb12c 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/channel/ChannelSessionTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/channel/ChannelSessionTest.java
@@ -18,14 +18,15 @@
*/
package org.apache.sshd.server.channel;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.Collection;
import org.apache.sshd.common.channel.ChannelAsyncOutputStream;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.server.Signal;
import org.apache.sshd.server.SignalListener;
import org.apache.sshd.util.BaseTest;
@@ -41,7 +42,7 @@ public class ChannelSessionTest extends BaseTest {
*/
@Test
public void testHandleWindowAdjust() throws Exception {
- final Buffer buffer = new Buffer();
+ final Buffer buffer = new ByteArrayBuffer();
buffer.putInt(1234);
final ChannelSession channelSession = new ChannelSession();
@@ -60,6 +61,7 @@ public class ChannelSessionTest extends BaseTest {
public void testAddSignalListenerOnDuplicateSignals() {
ChannelSession.StandardEnvironment environ = new ChannelSession.StandardEnvironment();
SignalListener listener = new SignalListener() {
+ @Override
public void signal(Signal signal) {
// ignored
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/test/java/org/apache/sshd/util/AsyncEchoShellFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/util/AsyncEchoShellFactory.java b/sshd-core/src/test/java/org/apache/sshd/util/AsyncEchoShellFactory.java
index 3d02bb7..dc86ab9 100644
--- a/sshd-core/src/test/java/org/apache/sshd/util/AsyncEchoShellFactory.java
+++ b/sshd-core/src/test/java/org/apache/sshd/util/AsyncEchoShellFactory.java
@@ -29,7 +29,7 @@ import org.apache.sshd.common.future.SshFutureListener;
import org.apache.sshd.common.io.IoInputStream;
import org.apache.sshd.common.io.IoOutputStream;
import org.apache.sshd.common.io.IoWriteFuture;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.server.AsyncCommand;
import org.apache.sshd.server.ChannelSessionAware;
import org.apache.sshd.server.Command;
@@ -45,6 +45,7 @@ import org.apache.sshd.server.channel.ChannelSession;
*/
public class AsyncEchoShellFactory implements Factory<Command> {
+ @Override
public Command create() {
return new EchoShell();
}
@@ -70,57 +71,71 @@ public class AsyncEchoShellFactory implements Factory<Command> {
return environment;
}
+ @Override
public void setInputStream(InputStream in) {
}
+ @Override
public void setOutputStream(OutputStream out) {
}
+ @Override
public void setErrorStream(OutputStream err) {
}
+ @Override
public void setIoInputStream(IoInputStream in) {
}
+ @Override
public void setIoOutputStream(IoOutputStream out) {
this.out = new BufferedIoOutputStream(out);
}
+ @Override
public void setIoErrorStream(IoOutputStream err) {
this.err = new BufferedIoOutputStream(err);
}
+ @Override
public void setExitCallback(ExitCallback callback) {
this.callback = callback;
}
+ @Override
public void setChannelSession(ChannelSession session) {
this.session = session;
}
+ @Override
public void start(Environment env) throws IOException {
environment = env;
session.setDataReceiver(this);
}
+ @Override
public void close() throws IOException {
out.close(false).addListener(new SshFutureListener<CloseFuture>() {
+ @Override
public void operationComplete(CloseFuture future) {
callback.onExit(0);
}
});
}
+ @Override
public void destroy() {
}
+ @Override
public int data(final ChannelSession channel, byte[] buf, int start, int len) throws IOException {
buffer.append(new String(buf, start, len));
for (int i = 0; i < buffer.length(); i++) {
if (buffer.charAt(i) == '\n') {
final String s = buffer.substring(0, i + 1);
final byte[] bytes = s.getBytes();
- out.write(new Buffer(bytes)).addListener(new SshFutureListener<IoWriteFuture>() {
+ out.write(new ByteArrayBuffer(bytes)).addListener(new SshFutureListener<IoWriteFuture>() {
+ @Override
public void operationComplete(IoWriteFuture future) {
try {
channel.getLocalWindow().consumeAndCheck(bytes.length);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/test/java/org/apache/sshd/util/BogusChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/util/BogusChannel.java b/sshd-core/src/test/java/org/apache/sshd/util/BogusChannel.java
index f4a9d18..ce47b18 100644
--- a/sshd-core/src/test/java/org/apache/sshd/util/BogusChannel.java
+++ b/sshd-core/src/test/java/org/apache/sshd/util/BogusChannel.java
@@ -23,7 +23,7 @@ import java.io.IOException;
import org.apache.sshd.client.future.DefaultOpenFuture;
import org.apache.sshd.client.future.OpenFuture;
import org.apache.sshd.common.channel.AbstractChannel;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
public class BogusChannel extends AbstractChannel {
[4/4] mina-sshd git commit: [SSHD-459] Make Buffer an abstract class
Posted by lg...@apache.org.
[SSHD-459] Make Buffer an abstract class
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/9f0bb1bc
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/9f0bb1bc
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/9f0bb1bc
Branch: refs/heads/master
Commit: 9f0bb1bceeaa3d613fc971a70fcd86e3e20f3345
Parents: 7ccbd06
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Thu May 14 03:44:36 2015 +0300
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Thu May 14 03:44:36 2015 +0300
----------------------------------------------------------------------
.../sshd/agent/common/AbstractAgentClient.java | 25 +-
.../sshd/agent/common/AbstractAgentProxy.java | 30 +-
.../sshd/agent/local/AgentForwardedChannel.java | 10 +-
.../agent/local/ChannelAgentForwarding.java | 13 +-
.../org/apache/sshd/agent/unix/AgentClient.java | 11 +-
.../org/apache/sshd/agent/unix/AgentServer.java | 8 +-
.../sshd/agent/unix/ChannelAgentForwarding.java | 2 +-
.../java/org/apache/sshd/client/UserAuth.java | 2 +-
.../auth/UserAuthKeyboardInteractive.java | 2 +-
.../sshd/client/auth/UserAuthPassword.java | 2 +-
.../sshd/client/auth/UserAuthPublicKey.java | 13 +-
.../client/channel/AbstractClientChannel.java | 29 +-
.../sshd/client/channel/ChannelDirectTcpip.java | 2 +-
.../apache/sshd/client/channel/ChannelExec.java | 2 +-
.../sshd/client/channel/ChannelShell.java | 2 +-
.../sshd/client/channel/ChannelSubsystem.java | 2 +-
.../channel/PtyCapableChannelSession.java | 15 +-
.../org/apache/sshd/client/kex/DHGClient.java | 19 +-
.../org/apache/sshd/client/kex/DHGEXClient.java | 20 +-
.../keyverifier/RequiredServerKeyVerifier.java | 2 +-
.../client/session/ClientConnectionService.java | 2 +-
.../sshd/client/session/ClientSessionImpl.java | 2 +-
.../client/session/ClientUserAuthService.java | 2 +-
.../sshd/client/sftp/DefaultSftpClient.java | 156 ++++-
.../java/org/apache/sshd/common/Channel.java | 2 +-
.../org/apache/sshd/common/KeyExchange.java | 2 +-
.../org/apache/sshd/common/RequestHandler.java | 2 +-
.../java/org/apache/sshd/common/Service.java | 2 +-
.../java/org/apache/sshd/common/Session.java | 2 +-
.../sshd/common/channel/AbstractChannel.java | 32 +-
.../common/channel/BufferedIoOutputStream.java | 2 +-
.../common/channel/ChannelAsyncInputStream.java | 10 +-
.../channel/ChannelAsyncOutputStream.java | 2 +-
.../common/channel/ChannelOutputStream.java | 2 +-
.../common/channel/ChannelPipedInputStream.java | 8 +-
.../org/apache/sshd/common/cipher/ECCurves.java | 3 +-
.../sshd/common/compression/Compression.java | 2 +-
.../common/compression/CompressionZlib.java | 2 +-
.../common/forward/DefaultTcpipForwarder.java | 20 +-
.../apache/sshd/common/forward/SocksProxy.java | 15 +-
.../sshd/common/forward/TcpipClientChannel.java | 13 +-
.../sshd/common/forward/TcpipServerChannel.java | 24 +-
.../apache/sshd/common/io/IoInputStream.java | 2 +-
.../apache/sshd/common/io/IoOutputStream.java | 2 +-
.../org/apache/sshd/common/io/IoReadFuture.java | 2 +-
.../org/apache/sshd/common/io/IoSession.java | 2 +-
.../apache/sshd/common/io/mina/MinaSession.java | 2 +-
.../apache/sshd/common/io/mina/MinaSupport.java | 2 +-
.../apache/sshd/common/io/nio2/Nio2Session.java | 2 +-
.../session/AbstractConnectionService.java | 2 +-
.../sshd/common/session/AbstractSession.java | 55 +-
.../sshd/common/signature/SignatureECDSA.java | 8 +-
.../org/apache/sshd/common/util/Buffer.java | 577 -------------------
.../apache/sshd/common/util/BufferUtils.java | 73 ---
.../apache/sshd/common/util/GenericUtils.java | 1 +
.../org/apache/sshd/common/util/KeyUtils.java | 5 +-
.../apache/sshd/common/util/buffer/Buffer.java | 489 ++++++++++++++++
.../common/util/buffer/BufferException.java | 30 +
.../sshd/common/util/buffer/BufferUtils.java | 81 +++
.../common/util/buffer/ByteArrayBuffer.java | 178 ++++++
.../util/io/LoggingFilterOutputStream.java | 2 +-
.../java/org/apache/sshd/server/UserAuth.java | 2 +-
.../sshd/server/auth/AbstractUserAuth.java | 2 +-
.../auth/UserAuthKeyboardInteractive.java | 2 +-
.../apache/sshd/server/auth/UserAuthNone.java | 2 +-
.../sshd/server/auth/UserAuthPassword.java | 2 +-
.../sshd/server/auth/UserAuthPublicKey.java | 14 +-
.../sshd/server/auth/gss/UserAuthGSS.java | 14 +-
.../server/channel/AbstractServerChannel.java | 2 +-
.../sshd/server/channel/AsyncDataReceiver.java | 6 +-
.../sshd/server/channel/ChannelSession.java | 24 +-
.../server/channel/PuttyRequestHandler.java | 2 +-
.../global/CancelTcpipForwardHandler.java | 2 +-
.../sshd/server/global/KeepAliveHandler.java | 2 +-
.../server/global/NoMoreSessionsHandler.java | 2 +-
.../sshd/server/global/TcpipForwardHandler.java | 2 +-
.../org/apache/sshd/server/kex/DHGEXServer.java | 29 +-
.../org/apache/sshd/server/kex/DHGServer.java | 26 +-
.../sshd/server/session/ServerSession.java | 13 +-
.../server/session/ServerUserAuthService.java | 2 +-
.../apache/sshd/server/sftp/SftpSubsystem.java | 63 +-
.../sshd/server/shell/ProcessShellFactory.java | 15 +-
.../sshd/server/x11/X11ForwardSupport.java | 13 +-
.../org/apache/sshd/AbstractSessionTest.java | 23 +-
.../org/apache/sshd/AuthenticationTest.java | 2 +-
.../test/java/org/apache/sshd/ClientTest.java | 45 +-
.../org/apache/sshd/SftpFileSystemTest.java | 4 +-
.../src/test/java/org/apache/sshd/SftpTest.java | 44 +-
.../java/org/apache/sshd/WindowAdjustTest.java | 7 +-
.../test/java/org/apache/sshd/WindowTest.java | 56 +-
.../org/apache/sshd/common/util/BufferTest.java | 8 +-
.../deprecated/ClientUserAuthServiceOld.java | 2 +-
.../org/apache/sshd/deprecated/UserAuth.java | 2 +-
.../apache/sshd/deprecated/UserAuthAgent.java | 12 +-
.../deprecated/UserAuthKeyboardInteractive.java | 2 +-
.../sshd/deprecated/UserAuthPassword.java | 2 +-
.../sshd/deprecated/UserAuthPublicKey.java | 12 +-
.../sshd/server/channel/ChannelSessionTest.java | 8 +-
.../apache/sshd/util/AsyncEchoShellFactory.java | 19 +-
.../java/org/apache/sshd/util/BogusChannel.java | 2 +-
100 files changed, 1522 insertions(+), 1002 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentClient.java b/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentClient.java
index e7855d9..6f68856 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentClient.java
@@ -18,14 +18,6 @@
*/
package org.apache.sshd.agent.common;
-import java.io.IOException;
-import java.security.PublicKey;
-import java.util.List;
-
-import org.apache.sshd.agent.SshAgent;
-import org.apache.sshd.common.util.Buffer;
-import org.apache.sshd.common.util.KeyUtils;
-
import static org.apache.sshd.agent.SshAgentConstants.SSH2_AGENTC_ADD_IDENTITY;
import static org.apache.sshd.agent.SshAgentConstants.SSH2_AGENTC_REMOVE_ALL_IDENTITIES;
import static org.apache.sshd.agent.SshAgentConstants.SSH2_AGENTC_REMOVE_IDENTITY;
@@ -36,9 +28,18 @@ import static org.apache.sshd.agent.SshAgentConstants.SSH2_AGENT_IDENTITIES_ANSW
import static org.apache.sshd.agent.SshAgentConstants.SSH2_AGENT_SIGN_RESPONSE;
import static org.apache.sshd.agent.SshAgentConstants.SSH_AGENT_SUCCESS;
+import java.io.IOException;
+import java.security.PublicKey;
+import java.util.List;
+
+import org.apache.sshd.agent.SshAgent;
+import org.apache.sshd.common.util.KeyUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
+
public abstract class AbstractAgentClient {
- private final Buffer buffer = new Buffer();
+ private final Buffer buffer = new ByteArrayBuffer();
private final SshAgent agent;
public AbstractAgentClient(SshAgent agent) {
@@ -56,11 +57,11 @@ public abstract class AbstractAgentClient {
if (buffer.available() < len + 4) {
return;
}
- Buffer rep = new Buffer();
+ Buffer rep = new ByteArrayBuffer();
rep.putInt(0);
rep.rpos(rep.wpos());
try {
- process(new Buffer(buffer.getBytes()), rep);
+ process(new ByteArrayBuffer(buffer.getBytes()), rep);
} catch (Exception e) {
rep.clear();
rep.putInt(0);
@@ -90,7 +91,7 @@ public abstract class AbstractAgentClient {
PublicKey key = req.getPublicKey();
byte[] data = req.getBytes();
int flags = req.getInt();
- Buffer sig = new Buffer();
+ Buffer sig = new ByteArrayBuffer();
sig.putString(KeyUtils.getKeyType(key));
sig.putBytes(agent.sign(key, data));
rep.putByte(SSH2_AGENT_SIGN_RESPONSE);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentProxy.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentProxy.java b/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentProxy.java
index 9960c0d..7af4ee2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentProxy.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentProxy.java
@@ -18,16 +18,6 @@
*/
package org.apache.sshd.agent.common;
-import java.io.IOException;
-import java.security.KeyPair;
-import java.security.PublicKey;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.sshd.agent.SshAgent;
-import org.apache.sshd.common.SshException;
-import org.apache.sshd.common.util.Buffer;
-
import static org.apache.sshd.agent.SshAgentConstants.SSH2_AGENTC_ADD_IDENTITY;
import static org.apache.sshd.agent.SshAgentConstants.SSH2_AGENTC_REMOVE_ALL_IDENTITIES;
import static org.apache.sshd.agent.SshAgentConstants.SSH2_AGENTC_REMOVE_IDENTITY;
@@ -37,8 +27,20 @@ import static org.apache.sshd.agent.SshAgentConstants.SSH2_AGENT_IDENTITIES_ANSW
import static org.apache.sshd.agent.SshAgentConstants.SSH2_AGENT_SIGN_RESPONSE;
import static org.apache.sshd.agent.SshAgentConstants.SSH_AGENT_SUCCESS;
+import java.io.IOException;
+import java.security.KeyPair;
+import java.security.PublicKey;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.sshd.agent.SshAgent;
+import org.apache.sshd.common.SshException;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
+
public abstract class AbstractAgentProxy implements SshAgent {
+ @Override
public List<Pair<PublicKey, String>> getIdentities() throws IOException {
Buffer buffer = createBuffer(SSH2_AGENTC_REQUEST_IDENTITIES);
buffer = request(prepare(buffer));
@@ -58,6 +60,7 @@ public abstract class AbstractAgentProxy implements SshAgent {
return keys;
}
+ @Override
public byte[] sign(PublicKey key, byte[] data) throws IOException {
Buffer buffer = createBuffer(SSH2_AGENTC_SIGN_REQUEST);
buffer.putPublicKey(key);
@@ -67,11 +70,12 @@ public abstract class AbstractAgentProxy implements SshAgent {
if (buffer.getByte() != SSH2_AGENT_SIGN_RESPONSE) {
throw new SshException("SSH agent failure");
}
- Buffer buf = new Buffer(buffer.getBytes());
+ Buffer buf = new ByteArrayBuffer(buffer.getBytes());
buf.getString(); // algo
return buf.getBytes();
}
+ @Override
public void addIdentity(KeyPair key, String comment) throws IOException {
Buffer buffer = createBuffer(SSH2_AGENTC_ADD_IDENTITY);
buffer.putKeyPair(key);
@@ -82,6 +86,7 @@ public abstract class AbstractAgentProxy implements SshAgent {
}
}
+ @Override
public void removeIdentity(PublicKey key) throws IOException {
Buffer buffer = createBuffer(SSH2_AGENTC_REMOVE_IDENTITY);
buffer.putPublicKey(key);
@@ -91,6 +96,7 @@ public abstract class AbstractAgentProxy implements SshAgent {
}
}
+ @Override
public void removeAllIdentities() throws IOException {
Buffer buffer = createBuffer(SSH2_AGENTC_REMOVE_ALL_IDENTITIES);
buffer = request(prepare(buffer));
@@ -105,7 +111,7 @@ public abstract class AbstractAgentProxy implements SshAgent {
}
protected Buffer createBuffer(byte cmd) {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putInt(0);
buffer.putByte(cmd);
return buffer;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentForwardedChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentForwardedChannel.java b/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentForwardedChannel.java
index 4f05443..7901af2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentForwardedChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentForwardedChannel.java
@@ -28,12 +28,13 @@ import org.apache.sshd.agent.common.AbstractAgentProxy;
import org.apache.sshd.client.channel.AbstractClientChannel;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.channel.ChannelOutputStream;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
public class AgentForwardedChannel extends AbstractClientChannel {
private final Queue<Buffer> messages = new ArrayBlockingQueue<Buffer>(10);
- private final Buffer receiveBuffer = new Buffer();
+ private final Buffer receiveBuffer = new ByteArrayBuffer();
public AgentForwardedChannel() {
super("auth-agent@openssh.com");
@@ -77,16 +78,17 @@ public class AgentForwardedChannel extends AbstractClientChannel {
invertedIn = new ChannelOutputStream(this, remoteWindow, log, SshConstants.SSH_MSG_CHANNEL_DATA);
}
+ @Override
protected void doWriteData(byte[] data, int off, int len) throws IOException {
Buffer message = null;
synchronized (receiveBuffer) {
- receiveBuffer.putBuffer(new Buffer(data, off, len));
+ receiveBuffer.putBuffer(new ByteArrayBuffer(data, off, len));
if (receiveBuffer.available() >= 4) {
off = receiveBuffer.rpos();
len = receiveBuffer.getInt();
receiveBuffer.rpos(off);
if (receiveBuffer.available() >= 4 + len) {
- message = new Buffer(receiveBuffer.getBytes());
+ message = new ByteArrayBuffer(receiveBuffer.getBytes());
receiveBuffer.compact();
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/agent/local/ChannelAgentForwarding.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/local/ChannelAgentForwarding.java b/sshd-core/src/main/java/org/apache/sshd/agent/local/ChannelAgentForwarding.java
index dfdf288..6691031 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/local/ChannelAgentForwarding.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/local/ChannelAgentForwarding.java
@@ -30,9 +30,9 @@ import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.channel.ChannelOutputStream;
import org.apache.sshd.common.future.CloseFuture;
-import org.apache.sshd.common.future.SshFuture;
import org.apache.sshd.common.future.SshFutureListener;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.server.channel.AbstractServerChannel;
/**
@@ -42,10 +42,12 @@ public class ChannelAgentForwarding extends AbstractServerChannel {
public static class Factory implements NamedFactory<Channel> {
+ @Override
public String getName() {
return "auth-agent@openssh.com";
}
+ @Override
public Channel create() {
return new ChannelAgentForwarding();
}
@@ -62,6 +64,7 @@ public class ChannelAgentForwarding extends AbstractServerChannel {
public ChannelAgentForwarding() {
}
+ @Override
protected OpenFuture doInit(Buffer buffer) {
final OpenFuture f = new DefaultOpenFuture(this);
try {
@@ -89,8 +92,10 @@ public class ChannelAgentForwarding extends AbstractServerChannel {
// Socket.close(handle);
}
+ @Override
public CloseFuture close(boolean immediately) {
return super.close(immediately).addListener(new SshFutureListener<CloseFuture>() {
+ @Override
public void operationComplete(CloseFuture sshFuture) {
closeImmediately0();
}
@@ -103,10 +108,12 @@ public class ChannelAgentForwarding extends AbstractServerChannel {
// close(true);
}
+ @Override
protected void doWriteData(byte[] data, int off, int len) throws IOException {
- client.messageReceived(new Buffer(data, off, len));
+ client.messageReceived(new ByteArrayBuffer(data, off, len));
}
+ @Override
protected void doWriteExtendedData(byte[] data, int off, int len) throws IOException {
throw new UnsupportedOperationException("AgentForward channel does not support extended data");
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentClient.java b/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentClient.java
index 87f9a26..45b33e1 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentClient.java
@@ -25,7 +25,8 @@ import java.util.concurrent.ArrayBlockingQueue;
import org.apache.sshd.agent.common.AbstractAgentProxy;
import org.apache.sshd.common.SshException;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.tomcat.jni.Local;
import org.apache.tomcat.jni.Pool;
import org.apache.tomcat.jni.Socket;
@@ -52,7 +53,7 @@ public class AgentClient extends AbstractAgentProxy implements Runnable {
if (result != Status.APR_SUCCESS) {
throwException(result);
}
- receiveBuffer = new Buffer();
+ receiveBuffer = new ByteArrayBuffer();
messages = new ArrayBlockingQueue<Buffer>(10);
new Thread(this).start();
} catch (IOException e) {
@@ -62,6 +63,7 @@ public class AgentClient extends AbstractAgentProxy implements Runnable {
}
}
+ @Override
public void run() {
try {
byte[] buf = new byte[1024];
@@ -70,7 +72,7 @@ public class AgentClient extends AbstractAgentProxy implements Runnable {
if (result < Status.APR_SUCCESS) {
throwException(result);
}
- messageReceived(new Buffer(buf, 0, result));
+ messageReceived(new ByteArrayBuffer(buf, 0, result));
}
} catch (Exception e) {
if (!closed) {
@@ -94,7 +96,7 @@ public class AgentClient extends AbstractAgentProxy implements Runnable {
int len = receiveBuffer.getInt();
receiveBuffer.rpos(rpos);
if (receiveBuffer.available() >= 4 + len) {
- message = new Buffer(receiveBuffer.getBytes());
+ message = new ByteArrayBuffer(receiveBuffer.getBytes());
receiveBuffer.compact();
}
}
@@ -115,6 +117,7 @@ public class AgentClient extends AbstractAgentProxy implements Runnable {
}
}
+ @Override
protected synchronized Buffer request(Buffer buffer) throws IOException {
int wpos = buffer.wpos();
buffer.wpos(0);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServer.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServer.java b/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServer.java
index d38b0b2..4536df0 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServer.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServer.java
@@ -24,7 +24,8 @@ import java.io.IOException;
import org.apache.sshd.agent.SshAgent;
import org.apache.sshd.agent.common.AbstractAgentClient;
import org.apache.sshd.agent.local.AgentImpl;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.tomcat.jni.Local;
import org.apache.tomcat.jni.Pool;
import org.apache.tomcat.jni.Socket;
@@ -68,6 +69,7 @@ public class AgentServer implements Closeable {
throwException(result);
}
thread = new Thread() {
+ @Override
public void run() {
try {
while (true) {
@@ -100,6 +102,7 @@ public class AgentServer implements Closeable {
new Thread(this).start();
}
+ @Override
public void run() {
try {
byte[] buf = new byte[1024];
@@ -110,7 +113,7 @@ public class AgentServer implements Closeable {
} else if (result < Status.APR_SUCCESS) {
throwException(result);
}
- messageReceived(new Buffer(buf, 0, result));
+ messageReceived(new ByteArrayBuffer(buf, 0, result));
}
} catch (Exception e) {
e.printStackTrace();
@@ -119,6 +122,7 @@ public class AgentServer implements Closeable {
}
}
+ @Override
protected void reply(Buffer buf) throws IOException {
int result = Socket.send(socket, buf.array(), buf.rpos(), buf.available());
if (result < Status.APR_SUCCESS) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/agent/unix/ChannelAgentForwarding.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/unix/ChannelAgentForwarding.java b/sshd-core/src/main/java/org/apache/sshd/agent/unix/ChannelAgentForwarding.java
index 4f6516e..471c668 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/unix/ChannelAgentForwarding.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/unix/ChannelAgentForwarding.java
@@ -31,7 +31,7 @@ import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.channel.ChannelOutputStream;
import org.apache.sshd.common.future.CloseFuture;
import org.apache.sshd.common.future.SshFutureListener;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.server.channel.AbstractServerChannel;
import org.apache.tomcat.jni.Local;
import org.apache.tomcat.jni.Pool;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/client/UserAuth.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/UserAuth.java b/sshd-core/src/main/java/org/apache/sshd/client/UserAuth.java
index a2e8cb7..7f864ac 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/UserAuth.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/UserAuth.java
@@ -21,7 +21,7 @@ package org.apache.sshd.client;
import java.util.List;
import org.apache.sshd.ClientSession;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* TODO Add javadoc
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthKeyboardInteractive.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthKeyboardInteractive.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthKeyboardInteractive.java
index cce5bf1..c623cec 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthKeyboardInteractive.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthKeyboardInteractive.java
@@ -28,7 +28,7 @@ import org.apache.sshd.client.UserAuth;
import org.apache.sshd.client.UserInteraction;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPassword.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPassword.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPassword.java
index d1db9de..ba64d12 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPassword.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPassword.java
@@ -26,7 +26,7 @@ import org.apache.sshd.ClientSession;
import org.apache.sshd.client.UserAuth;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPublicKey.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPublicKey.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPublicKey.java
index d58f7be..2e228fd 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPublicKey.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPublicKey.java
@@ -18,6 +18,8 @@
*/
package org.apache.sshd.client.auth;
+import static org.apache.sshd.common.util.KeyUtils.getKeyType;
+
import java.io.IOException;
import java.security.KeyPair;
import java.security.PublicKey;
@@ -35,12 +37,11 @@ import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.Signature;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.session.AbstractSession;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.apache.sshd.common.util.KeyUtils.getKeyType;
-
/**
* TODO Add javadoc
*
@@ -124,8 +125,8 @@ public class UserAuthPublicKey implements UserAuth {
buffer.putString(algo);
buffer.putPublicKey(key);
- Buffer bs = new Buffer();
- bs.putString(((AbstractSession) session).getKex().getH());
+ Buffer bs = new ByteArrayBuffer();
+ bs.putBytes(((AbstractSession) session).getKex().getH());
bs.putByte(SshConstants.SSH_MSG_USERAUTH_REQUEST);
bs.putString(session.getUsername());
bs.putString(service);
@@ -135,7 +136,7 @@ public class UserAuthPublicKey implements UserAuth {
bs.putPublicKey(key);
byte[] sig = current.sign(bs.getCompactData());
- bs = new Buffer();
+ bs = new ByteArrayBuffer();
bs.putString(algo);
bs.putBytes(sig);
buffer.putBytes(bs.array(), bs.rpos(), bs.available());
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
index 5eb907d..9fff35c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
@@ -36,8 +36,9 @@ import org.apache.sshd.common.channel.ChannelAsyncInputStream;
import org.apache.sshd.common.channel.ChannelAsyncOutputStream;
import org.apache.sshd.common.io.IoInputStream;
import org.apache.sshd.common.io.IoOutputStream;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.IoUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
/**
* TODO Add javadoc
@@ -75,26 +76,32 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
addRequestHandler(new ExitSignalChannelRequestHandler());
}
+ @Override
public Streaming getStreaming() {
return streaming;
}
+ @Override
public void setStreaming(Streaming streaming) {
this.streaming = streaming;
}
+ @Override
public IoOutputStream getAsyncIn() {
return asyncIn;
}
+ @Override
public IoInputStream getAsyncOut() {
return asyncOut;
}
+ @Override
public IoInputStream getAsyncErr() {
return asyncErr;
}
+ @Override
public OutputStream getInvertedIn() {
return invertedIn;
}
@@ -103,10 +110,12 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
return in;
}
+ @Override
public void setIn(InputStream in) {
this.in = in;
}
+ @Override
public InputStream getInvertedOut() {
return invertedOut;
}
@@ -115,10 +124,12 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
return out;
}
+ @Override
public void setOut(OutputStream out) {
this.out = out;
}
+ @Override
public InputStream getInvertedErr() {
return invertedErr;
}
@@ -127,6 +138,7 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
return err;
}
+ @Override
public void setErr(OutputStream err) {
this.err = err;
}
@@ -136,6 +148,7 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
return builder()
.when(openFuture)
.run(new Runnable() {
+ @Override
public void run() {
// If the channel has not been opened yet,
// skip the SSH_MSG_CHANNEL_CLOSE exchange
@@ -157,6 +170,7 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
.build();
}
+ @Override
public int waitFor(int mask, long timeout) {
long t = 0;
synchronized (lock) {
@@ -207,6 +221,7 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
}
}
+ @Override
public synchronized OpenFuture open() throws IOException {
if (isClosing()) {
throw new SshException("Session has been closed");
@@ -222,10 +237,12 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
return openFuture;
}
+ @Override
public OpenFuture open(int recipient, int rwsize, int rmpsize, Buffer buffer) {
throw new IllegalStateException();
}
+ @Override
public void handleOpenSuccess(int recipient, int rwsize, int rmpsize, Buffer buffer) {
this.recipient = recipient;
this.remoteWindow.init(rwsize, rmpsize);
@@ -244,6 +261,7 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
protected abstract void doOpen() throws IOException;
+ @Override
public void handleOpenFailure(Buffer buffer) {
int reason = buffer.getInt();
String msg = buffer.getString();
@@ -255,13 +273,14 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
notifyStateChanged();
}
+ @Override
protected void doWriteData(byte[] data, int off, int len) throws IOException {
// If we're already closing, ignore incoming data
if (isClosing()) {
return;
}
if (asyncOut != null) {
- asyncOut.write(new Buffer(data, off, len));
+ asyncOut.write(new ByteArrayBuffer(data, off, len));
} else if (out != null) {
out.write(data, off, len);
out.flush();
@@ -273,13 +292,14 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
}
}
+ @Override
protected void doWriteExtendedData(byte[] data, int off, int len) throws IOException {
// If we're already closing, ignore incoming data
if (isClosing()) {
return;
}
if (asyncErr != null) {
- asyncErr.write(new Buffer(data, off, len));
+ asyncErr.write(new ByteArrayBuffer(data, off, len));
} else if (err != null) {
err.write(data, off, len);
err.flush();
@@ -299,11 +319,13 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
}
}
+ @Override
public Integer getExitStatus() {
return exitStatus;
}
private class ExitStatusChannelRequestHandler implements RequestHandler<Channel> {
+ @Override
public Result process(Channel channel, String request, boolean wantReply, Buffer buffer) throws Exception {
if (request.equals("exit-status")) {
exitStatus = buffer.getInt();
@@ -315,6 +337,7 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
}
private class ExitSignalChannelRequestHandler implements RequestHandler<Channel> {
+ @Override
public Result process(Channel channel, String request, boolean wantReply, Buffer buffer) throws Exception {
if (request.equals("exit-signal")) {
exitSignal = buffer.getString();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java
index 453c0ef..bb3c94f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java
@@ -34,7 +34,7 @@ import org.apache.sshd.common.channel.ChannelAsyncOutputStream;
import org.apache.sshd.common.channel.ChannelOutputStream;
import org.apache.sshd.common.channel.ChannelPipedInputStream;
import org.apache.sshd.common.channel.ChannelPipedOutputStream;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* TODO Add javadoc
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelExec.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelExec.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelExec.java
index 3a1f2ee..0d4dcfe 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelExec.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelExec.java
@@ -21,7 +21,7 @@ package org.apache.sshd.client.channel;
import java.io.IOException;
import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* TODO Add javadoc
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelShell.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelShell.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelShell.java
index 355a3da..f9a1c25 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelShell.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelShell.java
@@ -21,7 +21,7 @@ package org.apache.sshd.client.channel;
import java.io.IOException;
import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* TODO Add javadoc
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSubsystem.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSubsystem.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSubsystem.java
index fd75810..1073b05 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSubsystem.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSubsystem.java
@@ -23,7 +23,7 @@ import java.io.IOException;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.future.CloseFuture;
import org.apache.sshd.common.future.SshFutureListener;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* Client channel to run a subsystem
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
index bbcb016..2c7448b 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
@@ -18,17 +18,18 @@
*/
package org.apache.sshd.client.channel;
-import org.apache.sshd.common.PtyMode;
-import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.util.Buffer;
-import org.apache.sshd.common.util.OsUtils;
-import org.apache.sshd.common.util.SttySupport;
-
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
+import org.apache.sshd.common.PtyMode;
+import org.apache.sshd.common.SshConstants;
+import org.apache.sshd.common.util.OsUtils;
+import org.apache.sshd.common.util.SttySupport;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
+
/**
* TODO Add javadoc
*
@@ -171,7 +172,7 @@ public class PtyCapableChannelSession extends ChannelSession {
buffer.putInt(ptyLines);
buffer.putInt(ptyHeight);
buffer.putInt(ptyWidth);
- Buffer modes = new Buffer();
+ Buffer modes = new ByteArrayBuffer();
for (PtyMode mode : ptyModes.keySet()) {
modes.putByte((byte) mode.toInt());
modes.putInt(ptyModes.get(mode));
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java b/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
index 69bea58..5e98ac2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
@@ -26,8 +26,9 @@ import org.apache.sshd.common.SshException;
import org.apache.sshd.common.kex.AbstractDH;
import org.apache.sshd.common.kex.DHFactory;
import org.apache.sshd.common.session.AbstractSession;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.KeyUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
/**
* Base class for DHG key exchange algorithms.
@@ -67,6 +68,7 @@ public class DHGClient extends AbstractDHClientKeyExchange {
this.factory = factory;
}
+ @Override
public void init(AbstractSession s, byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception {
super.init(s, V_S, V_C, I_S, I_C);
dh = getDH();
@@ -84,6 +86,7 @@ public class DHGClient extends AbstractDHClientKeyExchange {
return factory.create();
}
+ @Override
public boolean next(Buffer buffer) throws Exception {
byte cmd = buffer.getByte();
if (cmd != SshConstants.SSH_MSG_KEXDH_REPLY) {
@@ -99,19 +102,19 @@ public class DHGClient extends AbstractDHClientKeyExchange {
dh.setF(f);
K = dh.getK();
- buffer = new Buffer(K_S);
+ buffer = new ByteArrayBuffer(K_S);
serverKey = buffer.getRawPublicKey();
final String keyAlg = KeyUtils.getKeyType(serverKey);
if (keyAlg == null) {
throw new SshException("Unsupported server key type");
}
- buffer = new Buffer();
- buffer.putString(V_C);
- buffer.putString(V_S);
- buffer.putString(I_C);
- buffer.putString(I_S);
- buffer.putString(K_S);
+ buffer = new ByteArrayBuffer();
+ buffer.putBytes(V_C);
+ buffer.putBytes(V_S);
+ buffer.putBytes(I_C);
+ buffer.putBytes(I_S);
+ buffer.putBytes(K_S);
buffer.putMPInt(e);
buffer.putMPInt(f);
buffer.putMPInt(K);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java b/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java
index 38fca91..b1a05f9 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java
@@ -29,8 +29,9 @@ import org.apache.sshd.common.SshException;
import org.apache.sshd.common.kex.AbstractDH;
import org.apache.sshd.common.kex.DHFactory;
import org.apache.sshd.common.session.AbstractSession;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.KeyUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
/**
@@ -49,10 +50,12 @@ public class DHGEXClient extends AbstractDHClientKeyExchange {
public static final NamedFactory<KeyExchange> newFactory(final DHFactory delegate) {
return new NamedFactory<KeyExchange>() {
+ @Override
public String getName() {
return delegate.getName();
}
+ @Override
public KeyExchange create() {
return new DHGEXClient(delegate);
}
@@ -83,6 +86,7 @@ public class DHGEXClient extends AbstractDHClientKeyExchange {
expected = SshConstants.SSH_MSG_KEX_DH_GEX_GROUP;
}
+ @Override
public boolean next(Buffer buffer) throws Exception {
byte cmd = buffer.getByte();
if (cmd != expected) {
@@ -116,19 +120,19 @@ public class DHGEXClient extends AbstractDHClientKeyExchange {
dh.setF(f);
K = dh.getK();
- buffer = new Buffer(K_S);
+ buffer = new ByteArrayBuffer(K_S);
serverKey = buffer.getRawPublicKey();
final String keyAlg = KeyUtils.getKeyType(serverKey);
if (keyAlg == null) {
throw new SshException("Unsupported server key type");
}
- buffer = new Buffer();
- buffer.putString(V_C);
- buffer.putString(V_S);
- buffer.putString(I_C);
- buffer.putString(I_S);
- buffer.putString(K_S);
+ buffer = new ByteArrayBuffer();
+ buffer.putBytes(V_C);
+ buffer.putBytes(V_S);
+ buffer.putBytes(I_C);
+ buffer.putBytes(I_S);
+ buffer.putBytes(K_S);
buffer.putInt(min);
buffer.putInt(prf);
buffer.putInt(max);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/RequiredServerKeyVerifier.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/RequiredServerKeyVerifier.java b/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/RequiredServerKeyVerifier.java
index c3823cd..9a29f6d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/RequiredServerKeyVerifier.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/RequiredServerKeyVerifier.java
@@ -23,7 +23,7 @@ import java.security.PublicKey;
import org.apache.sshd.ClientSession;
import org.apache.sshd.client.ServerKeyVerifier;
-import org.apache.sshd.common.util.BufferUtils;
+import org.apache.sshd.common.util.buffer.BufferUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java
index 7c03fb8..d9988f2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java
@@ -31,7 +31,7 @@ import org.apache.sshd.common.Session;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.session.AbstractConnectionService;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* Client side <code>ssh-connection</code> service.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/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 2b3b60a..195be0c 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
@@ -60,7 +60,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.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* TODO Add javadoc
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/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 cc1c655..3e8d64d 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
@@ -35,9 +35,9 @@ 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.util.Buffer;
import org.apache.sshd.common.util.CloseableUtils;
import org.apache.sshd.common.util.GenericUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* Client side <code>ssh-auth</code> service.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/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 99e60af..4e5c395 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
@@ -18,6 +18,75 @@
*/
package org.apache.sshd.client.sftp;
+import static org.apache.sshd.common.sftp.SftpConstants.ACE4_APPEND_DATA;
+import static org.apache.sshd.common.sftp.SftpConstants.ACE4_READ_ATTRIBUTES;
+import static org.apache.sshd.common.sftp.SftpConstants.ACE4_READ_DATA;
+import static org.apache.sshd.common.sftp.SftpConstants.ACE4_WRITE_ATTRIBUTES;
+import static org.apache.sshd.common.sftp.SftpConstants.ACE4_WRITE_DATA;
+import static org.apache.sshd.common.sftp.SftpConstants.SFTP_V3;
+import static org.apache.sshd.common.sftp.SftpConstants.SFTP_V4;
+import static org.apache.sshd.common.sftp.SftpConstants.SFTP_V5;
+import static org.apache.sshd.common.sftp.SftpConstants.SFTP_V6;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FILEXFER_ATTR_ACCESSTIME;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FILEXFER_ATTR_ACMODTIME;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FILEXFER_ATTR_ALL;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FILEXFER_ATTR_CREATETIME;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FILEXFER_ATTR_MODIFYTIME;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FILEXFER_ATTR_OWNERGROUP;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FILEXFER_ATTR_PERMISSIONS;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FILEXFER_ATTR_SIZE;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FILEXFER_ATTR_SUBSECOND_TIMES;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FILEXFER_ATTR_UIDGID;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FILEXFER_TYPE_DIRECTORY;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FILEXFER_TYPE_REGULAR;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FILEXFER_TYPE_SYMLINK;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXF_APPEND;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXF_CREAT;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXF_CREATE_NEW;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXF_CREATE_TRUNCATE;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXF_EXCL;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXF_OPEN_EXISTING;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXF_OPEN_OR_CREATE;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXF_READ;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXF_TRUNC;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXF_TRUNCATE_EXISTING;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXF_WRITE;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_ATTRS;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_BLOCK;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_CLOSE;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_DATA;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_FSETSTAT;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_FSTAT;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_HANDLE;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_INIT;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_LINK;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_LSTAT;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_MKDIR;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_NAME;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_OPEN;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_OPENDIR;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_READ;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_READDIR;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_READLINK;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_REALPATH;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_REMOVE;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_RENAME;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_RENAME_ATOMIC;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_RENAME_OVERWRITE;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_RMDIR;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_SETSTAT;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_STAT;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_STATUS;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_SYMLINK;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_UNBLOCK;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_VERSION;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FXP_WRITE;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FX_EOF;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FX_OK;
+import static org.apache.sshd.common.sftp.SftpConstants.S_IFDIR;
+import static org.apache.sshd.common.sftp.SftpConstants.S_IFLNK;
+import static org.apache.sshd.common.sftp.SftpConstants.S_IFREG;
+
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -40,9 +109,8 @@ import org.apache.sshd.client.SftpClient;
import org.apache.sshd.client.SftpException;
import org.apache.sshd.client.channel.ChannelSubsystem;
import org.apache.sshd.common.SshException;
-import org.apache.sshd.common.util.Buffer;
-
-import static org.apache.sshd.common.sftp.SftpConstants.*;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
@@ -52,7 +120,7 @@ public class DefaultSftpClient implements SftpClient {
private final ChannelSubsystem channel;
private final Map<Integer, Buffer> messages;
private final AtomicInteger cmdId = new AtomicInteger(100);
- private final Buffer receiveBuffer = new Buffer();
+ private final Buffer receiveBuffer = new ByteArrayBuffer();
private boolean closing;
private int version;
private final Map<String, byte[]> extensions = new HashMap<>();
@@ -78,6 +146,7 @@ public class DefaultSftpClient implements SftpClient {
throw (IOException) new InterruptedIOException().initCause(e);
}
this.channel.onClose(new Runnable() {
+ @Override
public void run() {
synchronized (messages) {
closing = true;
@@ -93,10 +162,12 @@ public class DefaultSftpClient implements SftpClient {
return version;
}
+ @Override
public boolean isClosing() {
return closing;
}
+ @Override
public void close() throws IOException {
this.channel.close(false);
}
@@ -105,7 +176,7 @@ public class DefaultSftpClient implements SftpClient {
* Receive binary data
*/
protected int data(byte[] buf, int start, int len) throws IOException {
- Buffer incoming = new Buffer(buf, start, len);
+ Buffer incoming = new ByteArrayBuffer(buf, start, len);
// If we already have partial data, we need to append it to the buffer and use it
if (receiveBuffer.available() > 0) {
receiveBuffer.putBuffer(incoming);
@@ -152,7 +223,7 @@ public class DefaultSftpClient implements SftpClient {
* Process an SFTP packet
*/
protected void process(Buffer incoming) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putBuffer(incoming);
buffer.rpos(5);
int id = buffer.getInt();
@@ -200,7 +271,7 @@ public class DefaultSftpClient implements SftpClient {
if (length < 5) {
throw new IllegalArgumentException();
}
- Buffer buffer = new Buffer(length + 4);
+ Buffer buffer = new ByteArrayBuffer(length + 4);
buffer.putInt(length);
int nb = length;
while (nb > 0) {
@@ -516,8 +587,9 @@ public class DefaultSftpClient implements SftpClient {
}
}
+ @Override
public Handle open(String path, Collection<OpenMode> options) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(path);
if (version == SFTP_V3) {
int mode = 0;
@@ -576,24 +648,28 @@ public class DefaultSftpClient implements SftpClient {
return checkHandle(receive(send(SSH_FXP_OPEN, buffer)));
}
+ @Override
public void close(Handle handle) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(handle.id);
checkStatus(receive(send(SSH_FXP_CLOSE, buffer)));
}
+ @Override
public void remove(String path) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(path);
checkStatus(receive(send(SSH_FXP_REMOVE, buffer)));
}
+ @Override
public void rename(String oldPath, String newPath) throws IOException {
rename(oldPath, newPath, new CopyMode[0]);
}
+ @Override
public void rename(String oldPath, String newPath, CopyMode... options) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(oldPath);
buffer.putString(newPath);
if (version >= SFTP_V5) {
@@ -615,8 +691,9 @@ public class DefaultSftpClient implements SftpClient {
checkStatus(receive(send(SSH_FXP_RENAME, buffer)));
}
+ @Override
public int read(Handle handle, long fileOffset, byte[] dst, int dstoff, int len) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(handle.id);
buffer.putLong(fileOffset);
buffer.putInt(len);
@@ -645,6 +722,7 @@ public class DefaultSftpClient implements SftpClient {
}
}
+ @Override
public void write(Handle handle, long fileOffset, byte[] src, int srcoff, int len) throws IOException {
// do some bounds checking first
if (fileOffset < 0 || srcoff < 0 || len < 0) {
@@ -653,15 +731,16 @@ public class DefaultSftpClient implements SftpClient {
if (srcoff + len > src.length) {
throw new IllegalArgumentException("cannot read bytes " + srcoff + " to " + (srcoff + len) + " when array is only of length " + src.length);
}
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(handle.id);
buffer.putLong(fileOffset);
buffer.putBytes(src, srcoff, len);
checkStatus(receive(send(SSH_FXP_WRITE, buffer)));
}
+ @Override
public void mkdir(String path) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(path, StandardCharsets.UTF_8);
buffer.putInt(0);
if (version != SFTP_V3) {
@@ -670,20 +749,23 @@ public class DefaultSftpClient implements SftpClient {
checkStatus(receive(send(SSH_FXP_MKDIR, buffer)));
}
+ @Override
public void rmdir(String path) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(path);
checkStatus(receive(send(SSH_FXP_RMDIR, buffer)));
}
+ @Override
public Handle openDir(String path) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(path);
return checkHandle(receive(send(SSH_FXP_OPENDIR, buffer)));
}
+ @Override
public DirEntry[] readDir(Handle handle) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(handle.id);
return checkDir(receive(send(SSH_FXP_READDIR, buffer)));
}
@@ -715,14 +797,16 @@ public class DefaultSftpClient implements SftpClient {
}
}
+ @Override
public String canonicalPath(String path) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(path);
return checkOneName(receive(send(SSH_FXP_REALPATH, buffer)));
}
+ @Override
public Attributes stat(String path) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(path);
if (version >= SFTP_V4) {
buffer.putInt(SSH_FILEXFER_ATTR_ALL);
@@ -730,8 +814,9 @@ public class DefaultSftpClient implements SftpClient {
return checkAttributes(receive(send(SSH_FXP_STAT, buffer)));
}
+ @Override
public Attributes lstat(String path) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(path);
if (version >= SFTP_V4) {
buffer.putInt(SSH_FILEXFER_ATTR_ALL);
@@ -739,8 +824,9 @@ public class DefaultSftpClient implements SftpClient {
return checkAttributes(receive(send(SSH_FXP_LSTAT, buffer)));
}
+ @Override
public Attributes stat(Handle handle) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(handle.id);
if (version >= SFTP_V4) {
buffer.putInt(SSH_FILEXFER_ATTR_ALL);
@@ -748,41 +834,46 @@ public class DefaultSftpClient implements SftpClient {
return checkAttributes(receive(send(SSH_FXP_FSTAT, buffer)));
}
+ @Override
public void setStat(String path, Attributes attributes) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(path);
writeAttributes(buffer, attributes);
checkStatus(receive(send(SSH_FXP_SETSTAT, buffer)));
}
+ @Override
public void setStat(Handle handle, Attributes attributes) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(handle.id);
writeAttributes(buffer, attributes);
checkStatus(receive(send(SSH_FXP_FSETSTAT, buffer)));
}
+ @Override
public String readLink(String path) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(path);
return checkOneName(receive(send(SSH_FXP_READLINK, buffer)));
}
+ @Override
public void symLink(String linkPath, String targetPath) throws IOException {
link(linkPath, targetPath, true);
}
+ @Override
public void link(String linkPath, String targetPath, boolean symbolic) throws IOException {
if (version < SFTP_V6) {
if (!symbolic) {
throw new UnsupportedOperationException("Hard links are not supported in sftp v" + version);
}
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(targetPath);
buffer.putString(linkPath);
checkStatus(receive(send(SSH_FXP_SYMLINK, buffer)));
} else {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(targetPath);
buffer.putString(linkPath);
buffer.putBoolean(symbolic);
@@ -792,7 +883,7 @@ public class DefaultSftpClient implements SftpClient {
@Override
public void lock(Handle handle, long offset, long length, int mask) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(handle.id);
buffer.putLong(offset);
buffer.putLong(length);
@@ -802,15 +893,17 @@ public class DefaultSftpClient implements SftpClient {
@Override
public void unlock(Handle handle, long offset, long length) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putString(handle.id);
buffer.putLong(offset);
buffer.putLong(length);
checkStatus(receive(send(SSH_FXP_UNBLOCK, buffer)));
}
+ @Override
public Iterable<DirEntry> readDir(final String path) throws IOException {
return new Iterable<DirEntry>() {
+ @Override
public Iterator<DirEntry> iterator() {
return new Iterator<DirEntry>() {
Handle handle;
@@ -820,9 +913,11 @@ public class DefaultSftpClient implements SftpClient {
open();
load();
}
+ @Override
public boolean hasNext() {
return entries != null && index < entries.length;
}
+ @Override
public DirEntry next() {
DirEntry entry = entries[index++];
if (index >= entries.length) {
@@ -854,6 +949,7 @@ public class DefaultSftpClient implements SftpClient {
throw new RuntimeException(e);
}
}
+ @Override
public void remove() {
throw new UnsupportedOperationException();
}
@@ -862,10 +958,12 @@ public class DefaultSftpClient implements SftpClient {
};
}
+ @Override
public InputStream read(final String path) throws IOException {
return read(path, EnumSet.of(OpenMode.Read));
}
+ @Override
public InputStream read(final String path, final EnumSet<OpenMode> mode) throws IOException {
return new InputStream() {
byte[] buffer = new byte[32 * 1024];
@@ -922,10 +1020,12 @@ public class DefaultSftpClient implements SftpClient {
};
}
+ @Override
public OutputStream write(final String path) throws IOException {
return write(path, EnumSet.of(OpenMode.Write, OpenMode.Create, OpenMode.Truncate));
}
+ @Override
public OutputStream write(final String path, final EnumSet<OpenMode> mode) throws IOException {
return new OutputStream() {
byte[] buffer = new byte[32 * 1024];
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/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
index d0ec2b3..e353b38 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/Channel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/Channel.java
@@ -24,7 +24,7 @@ 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;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* TODO Add javadoc
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/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
index cd9de71..d0c3e7a 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/KeyExchange.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/KeyExchange.java
@@ -21,7 +21,7 @@ package org.apache.sshd.common;
import java.security.PublicKey;
import org.apache.sshd.common.session.AbstractSession;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* Key exchange algorithm.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/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
index 1a239c4..0a78f45 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/RequestHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/RequestHandler.java
@@ -19,7 +19,7 @@
package org.apache.sshd.common;
import org.apache.sshd.common.session.ConnectionService;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* A global request handler.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/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 1023475..fabdac0 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
@@ -21,7 +21,7 @@ package org.apache.sshd.common;
import java.io.IOException;
import org.apache.sshd.common.future.CloseFuture;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* See RFC 4253 [SSH-TRANS] and the SSH_MSG_SERVICE_REQUEST packet. Examples include ssh-userauth
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/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
index 66143ec..6ec08d1 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/Session.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/Session.java
@@ -24,7 +24,7 @@ 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;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* Represents an SSH session
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
index fd2aa0f..a5c6555 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
@@ -36,9 +36,10 @@ import org.apache.sshd.common.future.DefaultCloseFuture;
import org.apache.sshd.common.future.SshFutureListener;
import org.apache.sshd.common.io.IoWriteFuture;
import org.apache.sshd.common.session.ConnectionService;
-import org.apache.sshd.common.util.Buffer;
-import org.apache.sshd.common.util.BufferUtils;
import org.apache.sshd.common.util.CloseableUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.BufferUtils;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
/**
* TODO Add javadoc
@@ -71,30 +72,38 @@ public abstract class AbstractChannel extends CloseableUtils.AbstractInnerClosea
handlers.add(handler);
}
+ @Override
public int getId() {
return id;
}
+ @Override
public int getRecipient() {
return recipient;
}
+ @Override
public Window getLocalWindow() {
return localWindow;
}
+ @Override
public Window getRemoteWindow() {
return remoteWindow;
}
+ @Override
public Session getSession() {
return session;
}
+ @Override
public void handleRequest(Buffer buffer) throws IOException {
String req = buffer.getString();
boolean wantReply = buffer.getBoolean();
- log.debug("Received SSH_MSG_CHANNEL_REQUEST {} on channel {} (wantReply {})", new Object[] { req, this, wantReply });
+ if (log.isDebugEnabled()) {
+ log.debug("Received SSH_MSG_CHANNEL_REQUEST {} on channel {} (wantReply {})", new Object[] { req, this, Boolean.valueOf(wantReply) });
+ }
for (RequestHandler<Channel> handler : handlers) {
RequestHandler.Result result;
try {
@@ -130,6 +139,7 @@ public abstract class AbstractChannel extends CloseableUtils.AbstractInnerClosea
}
}
+ @Override
public void init(ConnectionService service, Session session, int id) {
this.service = service;
this.session = session;
@@ -143,6 +153,7 @@ public abstract class AbstractChannel extends CloseableUtils.AbstractInnerClosea
}
}
+ @Override
public void handleClose() throws IOException {
log.debug("Received SSH_MSG_CHANNEL_CLOSE on channel {}", this);
if (gracefulState.compareAndSet(GracefulState.Opened, GracefulState.CloseReceived)) {
@@ -152,6 +163,7 @@ public abstract class AbstractChannel extends CloseableUtils.AbstractInnerClosea
}
}
+ @Override
protected Closeable getInnerCloseable() {
return new GracefulChannelCloseable();
}
@@ -160,12 +172,15 @@ public abstract class AbstractChannel extends CloseableUtils.AbstractInnerClosea
protected volatile boolean closing;
+ @Override
public boolean isClosing() {
return closing;
}
+ @Override
public boolean isClosed() {
return gracefulFuture.isClosed();
}
+ @Override
public CloseFuture close(boolean immediately) {
closing = true;
if (immediately) {
@@ -177,6 +192,7 @@ public abstract class AbstractChannel extends CloseableUtils.AbstractInnerClosea
try {
long timeout = FactoryManagerUtils.getLongProperty(getSession(), FactoryManager.CHANNEL_CLOSE_TIMEOUT, DEFAULT_CHANNEL_CLOSE_TIMEOUT);
session.writePacket(buffer, timeout, TimeUnit.MILLISECONDS).addListener(new SshFutureListener<IoWriteFuture>() {
+ @Override
public void operationComplete(IoWriteFuture future) {
if (future.isWritten()) {
log.debug("Message SSH_MSG_CHANNEL_CLOSE written on channel {}", AbstractChannel.this);
@@ -214,9 +230,10 @@ public abstract class AbstractChannel extends CloseableUtils.AbstractInnerClosea
}
}
+ @Override
public void handleData(Buffer buffer) throws IOException {
int len = buffer.getInt();
- if (len < 0 || len > Buffer.MAX_LEN) {
+ if (len < 0 || len > ByteArrayBuffer.MAX_LEN) {
throw new IllegalStateException("Bad item length: " + len);
}
log.debug("Received SSH_MSG_CHANNEL_DATA on channel {}", this);
@@ -226,6 +243,7 @@ public abstract class AbstractChannel extends CloseableUtils.AbstractInnerClosea
doWriteData(buffer.array(), buffer.rpos(), len);
}
+ @Override
public void handleExtendedData(Buffer buffer) throws IOException {
int ex = buffer.getInt();
// Only accept extended data for stderr
@@ -237,7 +255,7 @@ public abstract class AbstractChannel extends CloseableUtils.AbstractInnerClosea
return;
}
int len = buffer.getInt();
- if (len < 0 || len > Buffer.MAX_LEN) {
+ if (len < 0 || len > ByteArrayBuffer.MAX_LEN) {
throw new IllegalStateException("Bad item length: " + len);
}
log.debug("Received SSH_MSG_CHANNEL_EXTENDED_DATA on channel {}", this);
@@ -247,18 +265,21 @@ public abstract class AbstractChannel extends CloseableUtils.AbstractInnerClosea
doWriteExtendedData(buffer.array(), buffer.rpos(), len);
}
+ @Override
public void handleEof() throws IOException {
log.debug("Received SSH_MSG_CHANNEL_EOF on channel {}", this);
eof = true;
notifyStateChanged();
}
+ @Override
public void handleWindowAdjust(Buffer buffer) throws IOException {
log.debug("Received SSH_MSG_CHANNEL_WINDOW_ADJUST on channel {}", this);
int window = buffer.getInt();
remoteWindow.expand(window);
}
+ @Override
public void handleFailure() throws IOException {
log.debug("Received SSH_MSG_CHANNEL_FAILURE on channel {}", this);
// TODO: do something to report failed requests?
@@ -289,6 +310,7 @@ public abstract class AbstractChannel extends CloseableUtils.AbstractInnerClosea
writePacket(buffer);
}
+ @Override
public String toString() {
return getClass().getSimpleName() + "[id=" + id + ", recipient=" + recipient + "]";
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/channel/BufferedIoOutputStream.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/BufferedIoOutputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/BufferedIoOutputStream.java
index 3c342c3..b9defba 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/BufferedIoOutputStream.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/BufferedIoOutputStream.java
@@ -27,8 +27,8 @@ import org.apache.sshd.common.Closeable;
import org.apache.sshd.common.future.SshFutureListener;
import org.apache.sshd.common.io.IoOutputStream;
import org.apache.sshd.common.io.IoWriteFuture;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.CloseableUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* An IoOutputStream capable of queuing write requests
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncInputStream.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncInputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncInputStream.java
index b7cbbb5..5a41887 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncInputStream.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncInputStream.java
@@ -28,14 +28,15 @@ import org.apache.sshd.common.future.DefaultSshFuture;
import org.apache.sshd.common.io.IoInputStream;
import org.apache.sshd.common.io.IoReadFuture;
import org.apache.sshd.common.io.ReadPendingException;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.CloseableUtils;
import org.apache.sshd.common.util.Readable;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
public class ChannelAsyncInputStream extends CloseableUtils.AbstractCloseable implements IoInputStream {
private final Channel channel;
- private final Buffer buffer = new Buffer();
+ private final Buffer buffer = new ByteArrayBuffer();
private IoReadFutureImpl pending;
public ChannelAsyncInputStream(Channel channel) {
@@ -49,6 +50,7 @@ public class ChannelAsyncInputStream extends CloseableUtils.AbstractCloseable im
doRead(true);
}
+ @Override
public IoReadFuture read(Buffer buf) {
IoReadFutureImpl future = new IoReadFutureImpl(buf);
if (isClosing()) {
@@ -127,10 +129,12 @@ public class ChannelAsyncInputStream extends CloseableUtils.AbstractCloseable im
this.buffer = buffer;
}
+ @Override
public Buffer getBuffer() {
return buffer;
}
+ @Override
public void verify() throws SshException {
try {
await();
@@ -142,6 +146,7 @@ public class ChannelAsyncInputStream extends CloseableUtils.AbstractCloseable im
throw new SshException("Write failed", getException());
}
}
+ @Override
public int getRead() {
Object v = getValue();
if (v instanceof RuntimeException) {
@@ -157,6 +162,7 @@ public class ChannelAsyncInputStream extends CloseableUtils.AbstractCloseable im
}
}
+ @Override
public Throwable getException() {
Object v = getValue();
if (v instanceof Throwable) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java
index 6aabdeb..11089c9 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java
@@ -30,8 +30,8 @@ import org.apache.sshd.common.future.SshFutureListener;
import org.apache.sshd.common.io.IoOutputStream;
import org.apache.sshd.common.io.IoWriteFuture;
import org.apache.sshd.common.io.WritePendingException;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.CloseableUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
public class ChannelAsyncOutputStream extends CloseableUtils.AbstractCloseable implements IoOutputStream {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java
index 5c3c959..19d0bb2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java
@@ -24,7 +24,7 @@ import java.io.OutputStream;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
import org.slf4j.Logger;
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedInputStream.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedInputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedInputStream.java
index cb003b7..d3e5b9e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedInputStream.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedInputStream.java
@@ -27,7 +27,8 @@ import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
/**
* TODO Add javadoc
@@ -37,7 +38,7 @@ import org.apache.sshd.common.util.Buffer;
public class ChannelPipedInputStream extends InputStream {
private final Window localWindow;
- private final Buffer buffer = new Buffer();
+ private final Buffer buffer = new ByteArrayBuffer();
private final byte[] b = new byte[1];
private boolean closed;
private boolean eofSent;
@@ -80,13 +81,14 @@ public class ChannelPipedInputStream extends InputStream {
}
}
+ @Override
public int read() throws IOException {
synchronized (b) {
int l = read(b, 0, 1);
if (l == -1) {
return -1;
}
- return ((int) b[0] & 0xff);
+ return (b[0] & 0xff);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/cipher/ECCurves.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/ECCurves.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/ECCurves.java
index 14d979b..2cc250c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/ECCurves.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/cipher/ECCurves.java
@@ -28,6 +28,7 @@ import java.util.TreeMap;
import org.apache.sshd.common.Digest;
import org.apache.sshd.common.digest.BuiltinDigests;
+import org.apache.sshd.common.util.GenericUtils;
/**
* Utilities for working with elliptic curves.
@@ -53,7 +54,7 @@ public class ECCurves {
public static String getCurveName(ECParameterSpec params) {
int fieldSize = getCurveSize(params);
final String curveName = getCurveName(fieldSize);
- if (curveName == null) {
+ if (GenericUtils.isEmpty(curveName)) {
throw new RuntimeException("invalid curve size " + fieldSize);
}
return curveName;
[2/4] mina-sshd git commit: [SSHD-459] Make Buffer an abstract class
Posted by lg...@apache.org.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java
new file mode 100644
index 0000000..36bed35
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java
@@ -0,0 +1,81 @@
+/*
+ * 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.util.buffer;
+
+/**
+ * TODO Add javadoc
+ *
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public class BufferUtils {
+
+ public static String printHex(byte[] array) {
+ return printHex(array, 0, array.length);
+ }
+
+ public static String printHex(byte[] array, int offset, int len) {
+ return printHex(array, offset, len, ' ');
+ }
+
+ public static String printHex(byte[] array, int offset, int len, char sep) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < len; i++) {
+ byte b = array[offset + i];
+ if (sb.length() > 0) {
+ sb.append(sep);
+ }
+ sb.append(digits[(b >> 4) & 0x0F]);
+ sb.append(digits[b & 0x0F]);
+ }
+ return sb.toString();
+ }
+
+ public static boolean equals(byte[] a1, byte[] a2) {
+ if (a1.length != a2.length) {
+ return false;
+ }
+ return equals(a1, 0, a2, 0, a1.length);
+ }
+
+ public static boolean equals(byte[] a1, int a1Offset, byte[] a2, int a2Offset, int length) {
+ if (a1.length < a1Offset + length || a2.length < a2Offset + length) {
+ return false;
+ }
+ while (length-- > 0) {
+ if (a1[a1Offset++] != a2[a2Offset++]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ final static char[] digits = {
+ '0' , '1' , '2' , '3' , '4' , '5' ,
+ '6' , '7' , '8' , '9' , 'a' , 'b' ,
+ 'c' , 'd' , 'e' , 'f'
+ };
+
+ public static final int getNextPowerOf2(int i) {
+ int j = 1;
+ while (j < i) {
+ j <<= 1;
+ }
+ return j;
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/ByteArrayBuffer.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/ByteArrayBuffer.java b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/ByteArrayBuffer.java
new file mode 100644
index 0000000..da05aef
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/ByteArrayBuffer.java
@@ -0,0 +1,178 @@
+/*
+ * 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.util.buffer;
+
+import java.nio.charset.Charset;
+
+import org.apache.sshd.common.util.Readable;
+
+/**
+ * Provides an implementation of {@link Buffer} using a backing byte array
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public final class ByteArrayBuffer extends Buffer {
+ public static final int DEFAULT_SIZE = 256;
+ public static final int MAX_LEN = 65536;
+
+ private byte[] data;
+ private int rpos;
+ private int wpos;
+
+ public ByteArrayBuffer() {
+ this(DEFAULT_SIZE);
+ }
+
+ public ByteArrayBuffer(int size) {
+ this(new byte[BufferUtils.getNextPowerOf2(size)], false);
+ }
+
+ public ByteArrayBuffer(byte[] data) {
+ this(data, 0, data.length, true);
+ }
+
+ public ByteArrayBuffer(byte[] data, boolean read) {
+ this(data, 0, data.length, read);
+ }
+
+ public ByteArrayBuffer(byte[] data, int off, int len) {
+ this(data, off, len, true);
+ }
+
+ public ByteArrayBuffer(byte[] data, int off, int len, boolean read) {
+ this.data = data;
+ this.rpos = off;
+ this.wpos = (read ? len : 0) + off;
+ }
+
+ @Override
+ public int rpos() {
+ return rpos;
+ }
+
+ @Override
+ public void rpos(int rpos) {
+ this.rpos = rpos;
+ }
+
+ @Override
+ public int wpos() {
+ return wpos;
+ }
+
+ @Override
+ public void wpos(int wpos) {
+ ensureCapacity(wpos - this.wpos);
+ this.wpos = wpos;
+ }
+
+ @Override
+ public int available() {
+ return wpos - rpos;
+ }
+
+ @Override
+ public int capacity() {
+ return data.length - wpos;
+ }
+
+ @Override
+ public byte[] array() {
+ return data;
+ }
+
+ @Override
+ public void compact() {
+ if (available() > 0) {
+ System.arraycopy(data, rpos, data, 0, wpos - rpos);
+ }
+ wpos -= rpos;
+ rpos = 0;
+ }
+
+ @Override
+ public void clear() {
+ rpos = 0;
+ wpos = 0;
+ }
+
+ @Override
+ public byte getByte() {
+ // TODO use Byte.BYTES for JDK-8
+ ensureAvailable(Byte.SIZE / Byte.SIZE);
+ return data[rpos++];
+ }
+
+ @Override
+ public void putByte(byte b) {
+ // TODO use Byte.BYTES in JDK-8
+ ensureCapacity(Byte.SIZE / Byte.SIZE);
+ data[wpos++] = b;
+ }
+
+ @Override
+ public int putBuffer(Readable buffer, boolean expand) {
+ int r = expand ? buffer.available() : Math.min(buffer.available(), capacity());
+ ensureCapacity(r);
+ buffer.getRawBytes(data, wpos, r);
+ wpos += r;
+ return r;
+ }
+
+ @Override
+ public void putRawBytes(byte[] d, int off, int len) {
+ ensureCapacity(len);
+ System.arraycopy(d, off, data, wpos, len);
+ wpos += len;
+ }
+
+ @Override
+ public String getString(Charset charset) {
+ int len = getInt();
+ if (len < 0) {
+ throw new BufferException("Bad item length: " + len);
+ }
+ ensureAvailable(len);
+ String s = new String(data, rpos, len, charset);
+ rpos += len;
+ return s;
+ }
+
+ @Override
+ public void getRawBytes(byte[] buf, int off, int len) {
+ ensureAvailable(len);
+ System.arraycopy(data, rpos, buf, off, len);
+ rpos += len;
+ }
+
+ @Override
+ protected void ensureCapacity(int capacity) {
+ if (data.length - wpos < capacity) {
+ int cw = wpos + capacity;
+ byte[] tmp = new byte[BufferUtils.getNextPowerOf2(cw)];
+ System.arraycopy(data, 0, tmp, 0, data.length);
+ data = tmp;
+ }
+ }
+
+ @Override
+ protected int size() {
+ return data.length;
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/util/io/LoggingFilterOutputStream.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/io/LoggingFilterOutputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/util/io/LoggingFilterOutputStream.java
index ab1676e..abcd43b 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/io/LoggingFilterOutputStream.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/io/LoggingFilterOutputStream.java
@@ -22,7 +22,7 @@ import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
-import org.apache.sshd.common.util.BufferUtils;
+import org.apache.sshd.common.util.buffer.BufferUtils;
import org.slf4j.Logger;
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/UserAuth.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/UserAuth.java b/sshd-core/src/main/java/org/apache/sshd/server/UserAuth.java
index c581cbd..bb80288 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/UserAuth.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/UserAuth.java
@@ -18,7 +18,7 @@
*/
package org.apache.sshd.server;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.server.session.ServerSession;
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/auth/AbstractUserAuth.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/AbstractUserAuth.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/AbstractUserAuth.java
index 947beb1..7d70939 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/AbstractUserAuth.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/AbstractUserAuth.java
@@ -18,7 +18,7 @@
*/
package org.apache.sshd.server.auth;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.server.UserAuth;
import org.apache.sshd.server.session.ServerSession;
import org.slf4j.Logger;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthKeyboardInteractive.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthKeyboardInteractive.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthKeyboardInteractive.java
index db439ff..e061b5c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthKeyboardInteractive.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthKeyboardInteractive.java
@@ -21,7 +21,7 @@ package org.apache.sshd.server.auth;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.server.PasswordAuthenticator;
import org.apache.sshd.server.UserAuth;
import org.apache.sshd.server.session.ServerSession;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthNone.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthNone.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthNone.java
index 8b9f5a7..980b119 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthNone.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthNone.java
@@ -19,7 +19,7 @@
package org.apache.sshd.server.auth;
import org.apache.sshd.common.NamedFactory;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.server.UserAuth;
import org.apache.sshd.server.session.ServerSession;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPassword.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPassword.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPassword.java
index 6219c3a..f4b2372 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPassword.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPassword.java
@@ -21,7 +21,7 @@ package org.apache.sshd.server.auth;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.server.PasswordAuthenticator;
import org.apache.sshd.server.UserAuth;
import org.apache.sshd.server.session.ServerSession;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java
index 58fa336..e6e8874 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java
@@ -23,7 +23,8 @@ import java.security.PublicKey;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.Signature;
import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.server.PublickeyAuthenticator;
import org.apache.sshd.server.UserAuth;
@@ -35,14 +36,17 @@ import org.apache.sshd.server.UserAuth;
public class UserAuthPublicKey extends AbstractUserAuth {
public static class Factory implements NamedFactory<UserAuth> {
+ @Override
public String getName() {
return "publickey";
}
+ @Override
public UserAuth create() {
return new UserAuthPublicKey();
}
}
+ @Override
public Boolean doAuth(Buffer buffer, boolean init) throws Exception {
if (!init) {
throw new IllegalStateException();
@@ -70,7 +74,7 @@ public class UserAuthPublicKey extends AbstractUserAuth {
}
if (!authenticator.authenticate(username, key, session)) {
- return false;
+ return Boolean.FALSE;
}
if (!hasSig) {
Buffer buf = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_PK_OK);
@@ -79,8 +83,8 @@ public class UserAuthPublicKey extends AbstractUserAuth {
session.writePacket(buf);
return null;
} else {
- Buffer buf = new Buffer();
- buf.putString(session.getKex().getH());
+ Buffer buf = new ByteArrayBuffer();
+ buf.putBytes(session.getKex().getH());
buf.putByte(SshConstants.SSH_MSG_USERAUTH_REQUEST);
buf.putString(username);
buf.putString(service);
@@ -94,7 +98,7 @@ public class UserAuthPublicKey extends AbstractUserAuth {
if (!verif.verify(sig)) {
throw new Exception("Key verification failed");
}
- return true;
+ return Boolean.TRUE;
}
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSS.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSS.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSS.java
index 4b5db95..8893f94 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSS.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSS.java
@@ -21,7 +21,8 @@ package org.apache.sshd.server.auth.gss;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.server.UserAuth;
import org.apache.sshd.server.auth.AbstractUserAuth;
import org.apache.sshd.server.session.ServerSession;
@@ -54,6 +55,7 @@ public class UserAuthGSS extends AbstractUserAuth {
/**
* Handle the first authentication step.
*/
+ @Override
protected Boolean doAuth(Buffer buffer, boolean initial) throws Exception {
GSSAuthenticator auth = getAuthenticator(session);
@@ -120,11 +122,11 @@ public class UserAuthGSS extends AbstractUserAuth {
// Make the MIC message so the token can be verified
- Buffer msgbuf = new Buffer();
+ Buffer msgbuf = new ByteArrayBuffer();
- msgbuf.putString(session.getSessionId());
+ msgbuf.putBytes(session.getSessionId());
msgbuf.putByte(SshConstants.SSH_MSG_USERAUTH_REQUEST);
- msgbuf.putString(username.getBytes("UTF-8"));
+ msgbuf.putString(username);
msgbuf.putString(service);
msgbuf.putString("gssapi-with-mic");
@@ -180,6 +182,7 @@ public class UserAuthGSS extends AbstractUserAuth {
*
* @return The user name
*/
+ @Override
public String getUserName() {
return identity != null ? identity : username;
}
@@ -187,6 +190,7 @@ public class UserAuthGSS extends AbstractUserAuth {
/**
* Free any system resources used by the module.
*/
+ @Override
public void destroy() {
if (context != null) {
try {
@@ -241,6 +245,7 @@ public class UserAuthGSS extends AbstractUserAuth {
*
* @return Tge name, always 'gssapi-with-mic' here.
*/
+ @Override
public String getName() {
return "gssapi-with-mic";
}
@@ -250,6 +255,7 @@ public class UserAuthGSS extends AbstractUserAuth {
*
* @return The instance
*/
+ @Override
public UserAuth create() {
return new UserAuthGSS();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/channel/AbstractServerChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/channel/AbstractServerChannel.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/AbstractServerChannel.java
index e55b687..8f6bb24 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/channel/AbstractServerChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/AbstractServerChannel.java
@@ -24,7 +24,7 @@ import org.apache.sshd.client.future.DefaultOpenFuture;
import org.apache.sshd.client.future.OpenFuture;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.channel.AbstractChannel;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* TODO Add javadoc
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/channel/AsyncDataReceiver.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/channel/AsyncDataReceiver.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/AsyncDataReceiver.java
index 24d19b3..fbc8396 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/channel/AsyncDataReceiver.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/AsyncDataReceiver.java
@@ -23,7 +23,7 @@ import java.io.IOException;
import org.apache.sshd.common.Channel;
import org.apache.sshd.common.channel.ChannelAsyncInputStream;
import org.apache.sshd.common.io.IoInputStream;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
public class AsyncDataReceiver implements ChannelDataReceiver {
@@ -37,11 +37,13 @@ public class AsyncDataReceiver implements ChannelDataReceiver {
return in;
}
+ @Override
public int data(ChannelSession channel, byte[] buf, int start, int len) throws IOException {
- in.write(new Buffer(buf, start, len));
+ in.write(new ByteArrayBuffer(buf, start, len));
return 0;
}
+ @Override
public void close() throws IOException {
in.close(false);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java
index ea8ef71..c977c20 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java
@@ -29,7 +29,6 @@ import java.util.Set;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.apache.sshd.agent.SshAgent;
@@ -42,7 +41,6 @@ import org.apache.sshd.common.ForwardingFilter;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.PtyMode;
import org.apache.sshd.common.RequestHandler;
-import org.apache.sshd.common.Session;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.channel.ChannelAsyncOutputStream;
import org.apache.sshd.common.channel.ChannelOutputStream;
@@ -51,9 +49,10 @@ import org.apache.sshd.common.file.FileSystemFactory;
import org.apache.sshd.common.future.CloseFuture;
import org.apache.sshd.common.future.DefaultCloseFuture;
import org.apache.sshd.common.future.SshFutureListener;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.CloseableUtils;
import org.apache.sshd.common.util.IoUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.common.util.io.LoggingFilterOutputStream;
import org.apache.sshd.server.AsyncCommand;
import org.apache.sshd.server.ChannelSessionAware;
@@ -78,10 +77,12 @@ public class ChannelSession extends AbstractServerChannel {
public static class Factory implements NamedFactory<Channel> {
+ @Override
public String getName() {
return "session";
}
+ @Override
public Channel create() {
return new ChannelSession();
}
@@ -99,6 +100,7 @@ public class ChannelSession extends AbstractServerChannel {
ptyModes = new ConcurrentHashMap<PtyMode, Integer>();
}
+ @Override
public void addSignalListener(SignalListener listener, Signal... signals) {
if (signals == null) {
throw new IllegalArgumentException("signals may not be null");
@@ -107,6 +109,7 @@ public class ChannelSession extends AbstractServerChannel {
addSignalListener(listener, Arrays.asList(signals));
}
+ @Override
public void addSignalListener(SignalListener listener) {
addSignalListener(listener, Signal.SIGNALS);
}
@@ -116,6 +119,7 @@ public class ChannelSession extends AbstractServerChannel {
* we hold the listeners inside a Set, so even if we add several times
* the same listener to the same signal set, it is harmless
*/
+ @Override
public void addSignalListener(SignalListener listener, Collection<Signal> signals) {
if (listener == null) {
throw new IllegalArgumentException("listener may not be null");
@@ -130,14 +134,17 @@ public class ChannelSession extends AbstractServerChannel {
}
}
+ @Override
public Map<String, String> getEnv() {
return env;
}
+ @Override
public Map<PtyMode, Integer> getPtyModes() {
return ptyModes;
}
+ @Override
public void removeSignalListener(SignalListener listener) {
if (listener == null) {
throw new IllegalArgumentException("listener may not be null");
@@ -219,12 +226,15 @@ public class ChannelSession extends AbstractServerChannel {
}
public class CommandCloseable extends CloseableUtils.IoBaseCloseable {
+ @Override
public boolean isClosed() {
return commandExitFuture.isClosed();
}
+ @Override
public boolean isClosing() {
return isClosed();
}
+ @Override
public CloseFuture close(boolean immediately) {
if (immediately || command == null) {
commandExitFuture.setClosed();
@@ -245,6 +255,7 @@ public class ChannelSession extends AbstractServerChannel {
manager.getScheduledExecutorService().schedule(task, timeout, TimeUnit.MILLISECONDS);
commandExitFuture.addListener(new SshFutureListener<CloseFuture>() {
+ @Override
public void operationComplete(CloseFuture future) {
task.cancel();
}
@@ -271,6 +282,7 @@ public class ChannelSession extends AbstractServerChannel {
IoUtils.closeQuietly(receiver);
}
+ @Override
protected void doWriteData(byte[] data, int off, int len) throws IOException {
// If we're already closing, ignore incoming data
if (isClosing()) {
@@ -283,12 +295,13 @@ public class ChannelSession extends AbstractServerChannel {
}
} else {
if (tempBuffer == null) {
- tempBuffer = new Buffer(len);
+ tempBuffer = new ByteArrayBuffer(len);
}
tempBuffer.putRawBytes(data, off, len);
}
}
+ @Override
protected void doWriteExtendedData(byte[] data, int off, int len) throws IOException {
throw new UnsupportedOperationException("Server channel does not support extended data");
}
@@ -540,6 +553,7 @@ public class ChannelSession extends AbstractServerChannel {
doWriteData(buffer.array(), buffer.rpos(), buffer.available());
}
command.setExitCallback(new ExitCallback() {
+ @Override
public void onExit(int exitValue) {
try {
closeShell(exitValue);
@@ -547,6 +561,7 @@ public class ChannelSession extends AbstractServerChannel {
log.info("Error closing shell", e);
}
}
+ @Override
public void onExit(int exitValue, String exitMessage) {
onExit(exitValue);
}
@@ -608,6 +623,7 @@ public class ChannelSession extends AbstractServerChannel {
}
private class ChannelSessionRequestHandler implements RequestHandler<Channel> {
+ @Override
public Result process(Channel channel, String request, boolean wantReply, Buffer buffer) throws Exception {
Boolean r = handleRequest(request, buffer);
if (r == null) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/channel/PuttyRequestHandler.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/channel/PuttyRequestHandler.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/PuttyRequestHandler.java
index 4f2e980..0c43929 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/channel/PuttyRequestHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/PuttyRequestHandler.java
@@ -20,7 +20,7 @@ package org.apache.sshd.server.channel;
import org.apache.sshd.common.Channel;
import org.apache.sshd.common.RequestHandler;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java b/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
index 1f34f24..189f328 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
@@ -22,7 +22,7 @@ import org.apache.sshd.common.RequestHandler;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshdSocketAddress;
import org.apache.sshd.common.session.ConnectionService;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* Handler for cancel-tcpip-forward global request.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/global/KeepAliveHandler.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/global/KeepAliveHandler.java b/sshd-core/src/main/java/org/apache/sshd/server/global/KeepAliveHandler.java
index 20ab0b9..c6881d0 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/global/KeepAliveHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/global/KeepAliveHandler.java
@@ -21,7 +21,7 @@ package org.apache.sshd.server.global;
import org.apache.sshd.common.RequestHandler;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.session.ConnectionService;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* Handler for keepalive@xxx global request.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/global/NoMoreSessionsHandler.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/global/NoMoreSessionsHandler.java b/sshd-core/src/main/java/org/apache/sshd/server/global/NoMoreSessionsHandler.java
index bfd5b26..38bf122 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/global/NoMoreSessionsHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/global/NoMoreSessionsHandler.java
@@ -21,7 +21,7 @@ package org.apache.sshd.server.global;
import org.apache.sshd.common.RequestHandler;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.session.ConnectionService;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* Handler for no-more-sessions@xxx global request.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java b/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
index 1de692b..7151e4b 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
@@ -22,7 +22,7 @@ import org.apache.sshd.common.RequestHandler;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshdSocketAddress;
import org.apache.sshd.common.session.ConnectionService;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* Handler for tcpip-forward global request.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEXServer.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEXServer.java b/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEXServer.java
index 5473d65..335cafe 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEXServer.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEXServer.java
@@ -34,14 +34,15 @@ import org.apache.sshd.common.Random;
import org.apache.sshd.common.Signature;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
-import org.apache.sshd.common.kex.DHG;
import org.apache.sshd.common.kex.DHFactory;
+import org.apache.sshd.common.kex.DHG;
import org.apache.sshd.common.kex.DHGroupData;
import org.apache.sshd.common.session.AbstractSession;
-import org.apache.sshd.common.util.Buffer;
-import org.apache.sshd.common.util.BufferUtils;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.SecurityUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.BufferUtils;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.server.ServerFactoryManager;
/**
@@ -83,11 +84,13 @@ public class DHGEXServer extends AbstractDHServerKeyExchange {
this.factory = factory;
}
+ @Override
public void init(AbstractSession s, byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception {
super.init(s, V_S, V_C, I_S, I_C);
expected = SshConstants.SSH_MSG_KEX_DH_GEX_REQUEST;
}
+ @Override
public boolean next(Buffer buffer) throws Exception {
byte cmd = buffer.getByte();
@@ -157,16 +160,16 @@ public class DHGEXServer extends AbstractDHServerKeyExchange {
Signature sig = NamedFactory.Utils.create(session.getFactoryManager().getSignatureFactories(), algo);
sig.init(kp.getPublic(), kp.getPrivate());
- buffer = new Buffer();
+ buffer = new ByteArrayBuffer();
buffer.putRawPublicKey(kp.getPublic());
K_S = buffer.getCompactData();
buffer.clear();
- buffer.putString(V_C);
- buffer.putString(V_S);
- buffer.putString(I_C);
- buffer.putString(I_S);
- buffer.putString(K_S);
+ buffer.putBytes(V_C);
+ buffer.putBytes(V_S);
+ buffer.putBytes(I_C);
+ buffer.putBytes(I_S);
+ buffer.putBytes(K_S);
if (oldRequest) {
buffer.putInt(prf);
} else {
@@ -186,7 +189,7 @@ public class DHGEXServer extends AbstractDHServerKeyExchange {
buffer.clear();
sig.update(H, 0, H.length);
buffer.putString(algo);
- buffer.putString(sig.sign());
+ buffer.putBytes(sig.sign());
sigH = buffer.getCompactData();
if (log.isDebugEnabled()) {
@@ -201,9 +204,9 @@ public class DHGEXServer extends AbstractDHServerKeyExchange {
buffer.rpos(5);
buffer.wpos(5);
buffer.putByte(SshConstants.SSH_MSG_KEX_DH_GEX_REPLY);
- buffer.putString(K_S);
- buffer.putString(f);
- buffer.putString(sigH);
+ buffer.putBytes(K_S);
+ buffer.putBytes(f);
+ buffer.putBytes(sigH);
session.writePacket(buffer);
return true;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGServer.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGServer.java b/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGServer.java
index 13df5c2..c18d532 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGServer.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGServer.java
@@ -28,8 +28,9 @@ import org.apache.sshd.common.SshException;
import org.apache.sshd.common.kex.AbstractDH;
import org.apache.sshd.common.kex.DHFactory;
import org.apache.sshd.common.session.AbstractSession;
-import org.apache.sshd.common.util.Buffer;
-import org.apache.sshd.common.util.BufferUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.BufferUtils;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
@@ -74,6 +75,7 @@ public class DHGServer extends AbstractDHServerKeyExchange {
f = dh.getE();
}
+ @Override
public boolean next(Buffer buffer) throws Exception {
byte cmd = buffer.getByte();
if (cmd != SshConstants.SSH_MSG_KEXDH_INIT) {
@@ -91,16 +93,16 @@ public class DHGServer extends AbstractDHServerKeyExchange {
Signature sig = NamedFactory.Utils.create(session.getFactoryManager().getSignatureFactories(), algo);
sig.init(kp.getPublic(), kp.getPrivate());
- buffer = new Buffer();
+ buffer = new ByteArrayBuffer();
buffer.putRawPublicKey(kp.getPublic());
K_S = buffer.getCompactData();
buffer.clear();
- buffer.putString(V_C);
- buffer.putString(V_S);
- buffer.putString(I_C);
- buffer.putString(I_S);
- buffer.putString(K_S);
+ buffer.putBytes(V_C);
+ buffer.putBytes(V_S);
+ buffer.putBytes(I_C);
+ buffer.putBytes(I_S);
+ buffer.putBytes(K_S);
buffer.putMPInt(e);
buffer.putMPInt(f);
buffer.putMPInt(K);
@@ -111,7 +113,7 @@ public class DHGServer extends AbstractDHServerKeyExchange {
buffer.clear();
sig.update(H, 0, H.length);
buffer.putString(algo);
- buffer.putString(sig.sign());
+ buffer.putBytes(sig.sign());
sigH = buffer.getCompactData();
if (log.isDebugEnabled()) {
@@ -126,9 +128,9 @@ public class DHGServer extends AbstractDHServerKeyExchange {
buffer.rpos(5);
buffer.wpos(5);
buffer.putByte(SshConstants.SSH_MSG_KEXDH_REPLY);
- buffer.putString(K_S);
- buffer.putString(f);
- buffer.putString(sigH);
+ buffer.putBytes(K_S);
+ buffer.putBytes(f);
+ buffer.putBytes(sigH);
session.writePacket(buffer);
return true;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSession.java b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSession.java
index 0a779a7..f195abc 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSession.java
@@ -33,8 +33,9 @@ import org.apache.sshd.common.future.SshFutureListener;
import org.apache.sshd.common.io.IoSession;
import org.apache.sshd.common.io.IoWriteFuture;
import org.apache.sshd.common.session.AbstractSession;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.GenericUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.server.ServerFactoryManager;
/**
@@ -63,13 +64,17 @@ public class ServerSession extends AbstractSession {
return negotiated[index];
}
+ @Override
public ServerFactoryManager getFactoryManager() {
return (ServerFactoryManager) factoryManager;
}
+ @Override
protected void checkKeys() {
+ // nothing
}
+ @Override
public void startService(String name) throws Exception {
currentService = ServiceFactory.Utils.create(getFactoryManager().getServiceFactories(), name, this);
}
@@ -80,6 +85,7 @@ public class ServerSession extends AbstractSession {
disconnect(SshConstants.SSH2_DISCONNECT_PROTOCOL_ERROR, "Unsupported packet: SSH_MSG_SERVICE_ACCEPT");
}
+ @Override
protected void checkRekey() throws IOException {
if (kexState.get() == KEX_STATE_DONE) {
if ( inPackets > MAX_PACKETS || outPackets > MAX_PACKETS
@@ -102,6 +108,7 @@ public class ServerSession extends AbstractSession {
sendIdentification(serverVersion);
}
+ @Override
protected void sendKexInit() throws IOException {
/*
* Make sure that the provided host keys have at least one supported signature factory
@@ -154,6 +161,7 @@ public class ServerSession extends AbstractSession {
I_S = sendKexInit(serverProposal);
}
+ @Override
protected boolean readIdentification(Buffer buffer) throws IOException {
clientVersion = doReadIdentification(buffer, true);
if (clientVersion == null) {
@@ -162,7 +170,7 @@ public class ServerSession extends AbstractSession {
log.debug("Client version string: {}", clientVersion);
if (!clientVersion.startsWith(DEFAULT_SSH_VERSION_PREFIX)) {
String msg = "Unsupported protocol version: " + clientVersion;
- ioSession.write(new Buffer((msg + "\n").getBytes())).addListener(new SshFutureListener<IoWriteFuture>() {
+ ioSession.write(new ByteArrayBuffer((msg + "\n").getBytes())).addListener(new SshFutureListener<IoWriteFuture>() {
@Override
public void operationComplete(IoWriteFuture future) {
close(true);
@@ -176,6 +184,7 @@ public class ServerSession extends AbstractSession {
return true;
}
+ @Override
protected void receiveKexInit(Buffer buffer) throws IOException {
clientProposal = new String[SshConstants.PROPOSAL_MAX];
I_C = receiveKexInit(buffer, clientProposal);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java
index 49d7712..f31851a 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java
@@ -34,9 +34,9 @@ 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.util.Buffer;
import org.apache.sshd.common.util.CloseableUtils;
import org.apache.sshd.common.util.GenericUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.server.ServerFactoryManager;
import org.apache.sshd.server.UserAuth;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java b/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java
index 218b27d..3a8ce58 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java
@@ -81,12 +81,13 @@ import java.util.concurrent.TimeUnit;
import org.apache.sshd.common.FactoryManagerUtils;
import org.apache.sshd.common.file.FileSystemAware;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.IoUtils;
import org.apache.sshd.common.util.OsUtils;
import org.apache.sshd.common.util.SelectorUtils;
import org.apache.sshd.common.util.ThreadUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.Environment;
import org.apache.sshd.server.ExitCallback;
@@ -161,6 +162,7 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste
return file;
}
+ @Override
public void close() throws IOException {
// ignored
}
@@ -191,14 +193,17 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste
this.done = done;
}
+ @Override
public boolean hasNext() {
return fileList.hasNext();
}
+ @Override
public Path next() {
return fileList.next();
}
+ @Override
public void remove() {
throw new UnsupportedOperationException("Not allowed to remove " + toString());
}
@@ -364,10 +369,12 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste
return unsupportedAttributePolicy;
}
+ @Override
public void setSession(ServerSession session) {
this.session = session;
}
+ @Override
public void setFileSystem(FileSystem fileSystem) {
if (fileSystem != this.fileSystem) {
this.fileSystem = fileSystem;
@@ -375,22 +382,27 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste
}
}
+ @Override
public void setExitCallback(ExitCallback callback) {
this.callback = callback;
}
+ @Override
public void setInputStream(InputStream in) {
this.in = in;
}
+ @Override
public void setOutputStream(OutputStream out) {
this.out = out;
}
+ @Override
public void setErrorStream(OutputStream err) {
this.err = err;
}
+ @Override
public void start(Environment env) throws IOException {
this.env = env;
try {
@@ -401,6 +413,7 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste
}
}
+ @Override
public void run() {
DataInputStream dis = null;
try {
@@ -410,7 +423,7 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste
if (length < 5) {
throw new IllegalArgumentException();
}
- Buffer buffer = new Buffer(length + 4);
+ Buffer buffer = new ByteArrayBuffer(length + 4);
buffer.putInt(length);
int nb = length;
while (nb > 0) {
@@ -1122,7 +1135,7 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste
sendStatus(id, SSH_FX_INVALID_HANDLE, handle);
} else {
FileHandle fh = (FileHandle) p;
- Buffer buf = new Buffer(len + 9);
+ Buffer buf = new ByteArrayBuffer(len + 9);
buf.putByte((byte) SSH_FXP_DATA);
buf.putInt(id);
int pos = buf.wpos();
@@ -1308,7 +1321,7 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste
}
protected void sendHandle(int id, String handle) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putByte((byte) SSH_FXP_HANDLE);
buffer.putInt(id);
buffer.putString(handle);
@@ -1316,7 +1329,7 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste
}
protected void sendAttrs(int id, Path file, int flags, boolean followLinks) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putByte((byte) SSH_FXP_ATTRS);
buffer.putInt(id);
writeAttrs(buffer, file, flags, followLinks);
@@ -1324,7 +1337,7 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste
}
protected void sendPath(int id, Path f, Map<String, Object> attrs) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putByte((byte) SSH_FXP_NAME);
buffer.putInt(id);
buffer.putInt(1);
@@ -1352,7 +1365,7 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste
}
protected void sendLink(int id, String link) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putByte((byte) SSH_FXP_NAME);
buffer.putInt(id);
buffer.putInt(1);
@@ -1364,7 +1377,7 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste
}
protected void sendName(int id, Iterator<Path> files) throws IOException {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putByte((byte) SSH_FXP_NAME);
buffer.putInt(id);
int wpos = buffer.wpos();
@@ -1732,10 +1745,20 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste
}
continue;
}
- case "uid": view = "unix"; break;
- case "gid": view = "unix"; break;
- case "owner": view = "posix"; value = toUser(file, (UserPrincipal) value); break;
- case "group": view = "posix"; value = toGroup(file, (GroupPrincipal) value); break;
+ case "uid":
+ view = "unix";
+ break;
+ case "gid":
+ view = "unix";
+ break;
+ case "owner":
+ view = "posix";
+ value = toUser(file, (UserPrincipal) value);
+ break;
+ case "group":
+ view = "posix";
+ value = toGroup(file, (GroupPrincipal) value);
+ break;
case "permissions":
if (OsUtils.isWin32()) {
@SuppressWarnings("unchecked")
@@ -1746,9 +1769,15 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste
view = "posix";
break;
- case "creationTime": view = "basic"; break;
- case "lastModifiedTime": view = "basic"; break;
- case "lastAccessTime": view = "basic"; break;
+ case "creationTime":
+ view = "basic";
+ break;
+ case "lastModifiedTime":
+ view = "basic";
+ break;
+ case "lastAccessTime":
+ view = "basic";
+ break;
default: // ignored
}
if (view != null && value != null) {
@@ -2096,7 +2125,7 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste
log.debug("Send SSH_FXP_STATUS (substatus={}, lang={}, msg={})", new Object[] { substatus, lang, msg });
}
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putByte((byte) SSH_FXP_STATUS);
buffer.putInt(id);
buffer.putInt(substatus);
@@ -2112,6 +2141,7 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste
dos.flush();
}
+ @Override
public void destroy() {
if (!closed) {
if (log.isDebugEnabled()) {
@@ -2225,6 +2255,7 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste
this.name = name;
}
+ @Override
public final String getName() {
return name;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/shell/ProcessShellFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/shell/ProcessShellFactory.java b/sshd-core/src/main/java/org/apache/sshd/server/shell/ProcessShellFactory.java
index 608c953..44f2137 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/shell/ProcessShellFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/shell/ProcessShellFactory.java
@@ -27,7 +27,8 @@ import java.util.EnumSet;
import java.util.Map;
import org.apache.sshd.common.Factory;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.server.Command;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -73,6 +74,7 @@ public class ProcessShellFactory implements Factory<Command> {
this.command = command;
}
+ @Override
public Command create() {
return new InvertedShellWrapper(new ProcessShell());
}
@@ -84,6 +86,7 @@ public class ProcessShellFactory implements Factory<Command> {
private TtyFilterInputStream out;
private TtyFilterInputStream err;
+ @Override
public void start(Map<String,String> env) throws IOException {
String[] cmds = new String[command.length];
for (int i = 0; i < cmds.length; i++) {
@@ -108,18 +111,22 @@ public class ProcessShellFactory implements Factory<Command> {
in = new TtyFilterOutputStream(process.getOutputStream(), err);
}
+ @Override
public OutputStream getInputStream() {
return in;
}
+ @Override
public InputStream getOutputStream() {
return out;
}
+ @Override
public InputStream getErrorStream() {
return err;
}
+ @Override
public boolean isAlive() {
try {
process.exitValue();
@@ -129,6 +136,7 @@ public class ProcessShellFactory implements Factory<Command> {
}
}
+ @Override
public int exitValue() {
try {
return process.waitFor();
@@ -137,6 +145,7 @@ public class ProcessShellFactory implements Factory<Command> {
}
}
+ @Override
public void destroy() {
if (process != null) {
process.destroy();
@@ -148,7 +157,7 @@ public class ProcessShellFactory implements Factory<Command> {
private int lastChar;
public TtyFilterInputStream(InputStream in) {
super(in);
- buffer = new Buffer(32);
+ buffer = new ByteArrayBuffer(32);
}
synchronized void write(int c) {
buffer.putByte((byte) c);
@@ -171,7 +180,7 @@ public class ProcessShellFactory implements Factory<Command> {
}
if (c == '\n' && ttyOptions.contains(TtyOptions.ONlCr) && lastChar != '\r') {
c = '\r';
- Buffer buf = new Buffer();
+ Buffer buf = new ByteArrayBuffer();
buf.putByte((byte) '\n');
buf.putBuffer(buffer);
buffer = buf;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java b/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java
index 992d5b4..a04ff11 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java
@@ -33,9 +33,10 @@ import org.apache.sshd.common.io.IoAcceptor;
import org.apache.sshd.common.io.IoHandler;
import org.apache.sshd.common.io.IoSession;
import org.apache.sshd.common.session.ConnectionService;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.CloseableUtils;
import org.apache.sshd.common.util.Readable;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
@@ -128,6 +129,7 @@ public class X11ForwardSupport extends CloseableUtils.AbstractInnerCloseable imp
}
}
+ @Override
public void sessionCreated(IoSession session) throws Exception {
ChannelForwardedX11 channel = new ChannelForwardedX11(session);
session.setAttribute(ChannelForwardedX11.class, channel);
@@ -141,6 +143,7 @@ public class X11ForwardSupport extends CloseableUtils.AbstractInnerCloseable imp
}
}
+ @Override
public void sessionClosed(IoSession session) throws Exception {
ChannelForwardedX11 channel = (ChannelForwardedX11) session.getAttribute(ChannelForwardedX11.class);
if ( channel != null ){
@@ -148,14 +151,16 @@ public class X11ForwardSupport extends CloseableUtils.AbstractInnerCloseable imp
}
}
+ @Override
public void messageReceived(IoSession session, Readable message) throws Exception {
ChannelForwardedX11 channel = (ChannelForwardedX11) session.getAttribute(ChannelForwardedX11.class);
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putBuffer(message);
channel.getInvertedIn().write(buffer.array(), buffer.rpos(), buffer.available());
channel.getInvertedIn().flush();
}
+ @Override
public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
cause.printStackTrace();
session.close(false);
@@ -169,6 +174,7 @@ public class X11ForwardSupport extends CloseableUtils.AbstractInnerCloseable imp
this.serverSession = serverSession;
}
+ @Override
public synchronized OpenFuture open() throws IOException {
InetSocketAddress remote = (InetSocketAddress) serverSession.getRemoteAddress();
if (closeFuture.isClosed()) {
@@ -200,9 +206,10 @@ public class X11ForwardSupport extends CloseableUtils.AbstractInnerCloseable imp
return builder().sequential(serverSession, super.getInnerCloseable()).build();
}
+ @Override
protected synchronized void doWriteData(byte[] data, int off, int len) throws IOException {
localWindow.consumeAndCheck(len);
- serverSession.write(new Buffer(data, off, len));
+ serverSession.write(new ByteArrayBuffer(data, off, len));
}
@Override
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/test/java/org/apache/sshd/AbstractSessionTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/AbstractSessionTest.java b/sshd-core/src/test/java/org/apache/sshd/AbstractSessionTest.java
index 38a4018..5f9428d 100644
--- a/sshd-core/src/test/java/org/apache/sshd/AbstractSessionTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/AbstractSessionTest.java
@@ -18,17 +18,18 @@
*/
package org.apache.sshd;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
import java.io.IOException;
import org.apache.sshd.common.session.AbstractSession;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.util.BaseTest;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
/**
* Test basic stuff on AbstractSession.
*
@@ -45,28 +46,28 @@ public class AbstractSessionTest extends BaseTest {
@Test
public void testReadIdentSimple() {
- Buffer buf = new Buffer("SSH-2.0-software\r\n".getBytes());
+ Buffer buf = new ByteArrayBuffer("SSH-2.0-software\r\n".getBytes());
String ident = session.doReadIdentification(buf);
assertEquals("SSH-2.0-software", ident);
}
@Test
public void testReadIdentWithoutCR() {
- Buffer buf = new Buffer("SSH-2.0-software\n".getBytes());
+ Buffer buf = new ByteArrayBuffer("SSH-2.0-software\n".getBytes());
String ident = session.doReadIdentification(buf);
assertEquals("SSH-2.0-software", ident);
}
@Test
public void testReadIdentWithHeaders() {
- Buffer buf = new Buffer(("a header line\r\nSSH-2.0-software\r\n").getBytes());
+ Buffer buf = new ByteArrayBuffer(("a header line\r\nSSH-2.0-software\r\n").getBytes());
String ident = session.doReadIdentification(buf);
assertEquals("SSH-2.0-software", ident);
}
@Test
public void testReadIdentWithSplitPackets() {
- Buffer buf = new Buffer("header line\r\nSSH".getBytes());
+ Buffer buf = new ByteArrayBuffer("header line\r\nSSH".getBytes());
String ident = session.doReadIdentification(buf);
assertNull(ident);
buf.putRawBytes("-2.0-software\r\n".getBytes());
@@ -76,13 +77,13 @@ public class AbstractSessionTest extends BaseTest {
@Test(expected = IllegalStateException.class)
public void testReadIdentBadLineEnding() {
- Buffer buf = new Buffer(("SSH-2.0-software\ra").getBytes());
+ Buffer buf = new ByteArrayBuffer(("SSH-2.0-software\ra").getBytes());
String ident = session.doReadIdentification(buf);
}
@Test(expected = IllegalStateException.class)
public void testReadIdentLongLine() {
- Buffer buf = new Buffer(("SSH-2.0-software" +
+ Buffer buf = new ByteArrayBuffer(("SSH-2.0-software" +
"01234567890123456789012345678901234567890123456789" +
"01234567890123456789012345678901234567890123456789" +
"01234567890123456789012345678901234567890123456789" +
@@ -99,7 +100,7 @@ public class AbstractSessionTest extends BaseTest {
sb.append("01234567890123456789012345678901234567890123456789\r\n");
}
sb.append("SSH-2.0-software\r\n");
- Buffer buf = new Buffer(sb.toString().getBytes());
+ Buffer buf = new ByteArrayBuffer(sb.toString().getBytes());
String ident = session.doReadIdentification(buf);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java b/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java
index 95b23c6..4a86365 100644
--- a/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java
@@ -28,7 +28,7 @@ import org.apache.sshd.client.session.ClientSessionImpl;
import org.apache.sshd.common.KeyPairProvider;
import org.apache.sshd.common.io.IoSession;
import org.apache.sshd.common.session.AbstractSession;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.deprecated.ClientUserAuthServiceOld;
import org.apache.sshd.deprecated.UserAuthKeyboardInteractive;
import org.apache.sshd.deprecated.UserAuthPassword;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/test/java/org/apache/sshd/ClientTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/ClientTest.java b/sshd-core/src/test/java/org/apache/sshd/ClientTest.java
index 56ed4ed..fb7e389 100644
--- a/sshd-core/src/test/java/org/apache/sshd/ClientTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/ClientTest.java
@@ -18,6 +18,12 @@
*/
package org.apache.sshd;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -44,6 +50,7 @@ import org.apache.sshd.client.channel.ChannelShell;
import org.apache.sshd.client.future.AuthFuture;
import org.apache.sshd.client.future.OpenFuture;
import org.apache.sshd.common.Channel;
+import org.apache.sshd.common.FactoryManager;
import org.apache.sshd.common.KeyPairProvider;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.RuntimeSshException;
@@ -52,7 +59,6 @@ import org.apache.sshd.common.Session;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.cipher.BuiltinCiphers;
-import org.apache.sshd.common.cipher.CipherNone;
import org.apache.sshd.common.forward.TcpipServerChannel;
import org.apache.sshd.common.future.CloseFuture;
import org.apache.sshd.common.future.SshFutureListener;
@@ -63,8 +69,9 @@ import org.apache.sshd.common.io.mina.MinaSession;
import org.apache.sshd.common.io.nio2.Nio2Session;
import org.apache.sshd.common.session.AbstractSession;
import org.apache.sshd.common.session.ConnectionService;
-import org.apache.sshd.common.util.Buffer;
-import org.apache.sshd.common.util.BufferUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.BufferUtils;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.common.util.io.NoCloseOutputStream;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.CommandFactory;
@@ -86,12 +93,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
/**
* TODO Add javadoc
*
@@ -114,6 +115,7 @@ public class ClientTest extends BaseTest {
sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
sshd.setShellFactory(new TestEchoShellFactory());
sshd.setCommandFactory(new CommandFactory() {
+ @Override
public Command createCommand(String command) {
return new UnknownCommand(command);
}
@@ -176,10 +178,10 @@ public class ClientTest extends BaseTest {
@Test
public void testAsyncClient() throws Exception {
- sshd.getProperties().put(SshServer.WINDOW_SIZE, "1024");
+ sshd.getProperties().put(FactoryManager.WINDOW_SIZE, "1024");
sshd.setShellFactory(new AsyncEchoShellFactory());
- client.getProperties().put(SshClient.WINDOW_SIZE, "1024");
+ client.getProperties().put(FactoryManager.WINDOW_SIZE, "1024");
client.start();
ClientSession session = client.connect("smx", "localhost", port).await().getSession();
session.addPasswordIdentity("smx");
@@ -196,13 +198,14 @@ public class ClientTest extends BaseTest {
final ByteArrayOutputStream baosErr = new ByteArrayOutputStream();
final AtomicInteger writes = new AtomicInteger(nbMessages);
- channel.getAsyncIn().write(new Buffer(message))
+ channel.getAsyncIn().write(new ByteArrayBuffer(message))
.addListener(new SshFutureListener<IoWriteFuture>() {
+ @Override
public void operationComplete(IoWriteFuture future) {
try {
if (future.isWritten()) {
if (writes.decrementAndGet() > 0) {
- channel.getAsyncIn().write(new Buffer(message)).addListener(this);
+ channel.getAsyncIn().write(new ByteArrayBuffer(message)).addListener(this);
} else {
channel.getAsyncIn().close(false);
}
@@ -217,8 +220,9 @@ public class ClientTest extends BaseTest {
}
}
});
- channel.getAsyncOut().read(new Buffer())
+ channel.getAsyncOut().read(new ByteArrayBuffer())
.addListener(new SshFutureListener<IoReadFuture>() {
+ @Override
public void operationComplete(IoReadFuture future) {
try {
future.verify();
@@ -235,8 +239,9 @@ public class ClientTest extends BaseTest {
}
}
});
- channel.getAsyncErr().read(new Buffer())
+ channel.getAsyncErr().read(new ByteArrayBuffer())
.addListener(new SshFutureListener<IoReadFuture>() {
+ @Override
public void operationComplete(IoReadFuture future) {
try {
future.verify();
@@ -280,7 +285,7 @@ public class ClientTest extends BaseTest {
} catch (SshException e) {
// That's ok, the channel is being closed by the other side
}
- assertEquals(ChannelExec.CLOSED, channel.waitFor(ChannelExec.CLOSED, 0) & ChannelExec.CLOSED);
+ assertEquals(ClientChannel.CLOSED, channel.waitFor(ClientChannel.CLOSED, 0) & ClientChannel.CLOSED);
session.close(false).await();
client.stop();
}
@@ -568,6 +573,7 @@ public class ClientTest extends BaseTest {
public void testPublicKeyAuthNewWithFailureOnFirstIdentity() throws Exception {
final KeyPair pair = Utils.createTestHostKeyProvider().loadKey(KeyPairProvider.SSH_RSA);
sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {
+ @Override
public boolean authenticate(String username, PublicKey key, ServerSession session) {
return key.equals(pair.getPublic());
}
@@ -624,8 +630,10 @@ public class ClientTest extends BaseTest {
client.getProperties().put(ClientFactoryManager.PASSWORD_PROMPTS, "3");
client.setUserAuthFactories(Arrays.<NamedFactory<UserAuth>>asList(new UserAuthKeyboardInteractive.Factory()));
client.setUserInteraction(new UserInteraction() {
+ @Override
public void welcome(String banner) {
}
+ @Override
public String[] interactive(String destination, String name, String instruction, String[] prompt, boolean[] echo) {
count.incrementAndGet();
return new String[] { "bad" };
@@ -649,9 +657,11 @@ public class ClientTest extends BaseTest {
client.start();
ClientSession session = client.connect("smx", "localhost", port).await().getSession();
session.setUserInteraction(new UserInteraction() {
+ @Override
public void welcome(String banner) {
}
+ @Override
public String[] interactive(String destination, String name, String instruction,
String[] prompt, boolean[] echo) {
count.incrementAndGet();
@@ -674,9 +684,11 @@ public class ClientTest extends BaseTest {
client.start();
ClientSession session = client.connect("smx", "localhost", port).await().getSession();
session.setUserInteraction(new UserInteraction() {
+ @Override
public void welcome(String banner) {
}
+ @Override
public String[] interactive(String destination, String name, String instruction,
String[] prompt, boolean[] echo) {
count.incrementAndGet();
@@ -728,6 +740,7 @@ public class ClientTest extends BaseTest {
final AtomicBoolean ok = new AtomicBoolean();
client.setServerKeyVerifier(
new ServerKeyVerifier() {
+ @Override
public boolean verifyServerKey(
ClientSession sshClientSession,
SocketAddress remoteAddress,
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/test/java/org/apache/sshd/SftpFileSystemTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/SftpFileSystemTest.java b/sshd-core/src/test/java/org/apache/sshd/SftpFileSystemTest.java
index 2eb9309..1e0dd98 100644
--- a/sshd-core/src/test/java/org/apache/sshd/SftpFileSystemTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/SftpFileSystemTest.java
@@ -56,6 +56,7 @@ import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.Utils;
import org.junit.After;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -186,8 +187,9 @@ public class SftpFileSystemTest extends BaseTest {
Files.write(file, "Hello world\n".getBytes());
Map<String, Object> attrs = Files.readAttributes(file, "posix:*");
+ Assert.assertNotNull("NO attributes read for " + file, attrs);
- Files.setAttribute(file, "basic:size", 2l);
+ Files.setAttribute(file, "basic:size", Long.valueOf(2l));
Files.setAttribute(file, "posix:permissions", PosixFilePermissions.fromString("rwxr-----"));
Files.setAttribute(file, "basic:lastModifiedTime", FileTime.fromMillis(100000l));
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/test/java/org/apache/sshd/SftpTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/SftpTest.java b/sshd-core/src/test/java/org/apache/sshd/SftpTest.java
index c2b4832..cec1d11 100644
--- a/sshd-core/src/test/java/org/apache/sshd/SftpTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/SftpTest.java
@@ -18,6 +18,17 @@
*/
package org.apache.sshd;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FX_FILE_ALREADY_EXISTS;
+import static org.apache.sshd.common.sftp.SftpConstants.SSH_FX_NO_SUCH_FILE;
+import static org.apache.sshd.common.sftp.SftpConstants.S_IRUSR;
+import static org.apache.sshd.common.sftp.SftpConstants.S_IWUSR;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -29,13 +40,10 @@ import java.util.Arrays;
import java.util.EnumSet;
import java.util.Vector;
-import com.jcraft.jsch.ChannelSftp;
-import com.jcraft.jsch.JSch;
-import com.jcraft.jsch.SftpException;
import org.apache.sshd.client.SftpClient;
import org.apache.sshd.common.NamedFactory;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.OsUtils;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.command.ScpCommandFactory;
import org.apache.sshd.server.sftp.SftpSubsystemFactory;
@@ -46,21 +54,13 @@ import org.apache.sshd.util.JSchLogger;
import org.apache.sshd.util.SimpleUserInfo;
import org.apache.sshd.util.Utils;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
-import static org.apache.sshd.common.sftp.SftpConstants.SSH_FX_FILE_ALREADY_EXISTS;
-import static org.apache.sshd.common.sftp.SftpConstants.SSH_FX_NO_SUCH_FILE;
-import static org.apache.sshd.common.sftp.SftpConstants.S_IRUSR;
-import static org.apache.sshd.common.sftp.SftpConstants.S_IWUSR;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import com.jcraft.jsch.ChannelSftp;
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.SftpException;
public class SftpTest extends BaseTest {
@@ -291,14 +291,14 @@ public class SftpTest extends BaseTest {
uploadAndVerifyFile(sftp, 0, "emptyFile.txt");
uploadAndVerifyFile(sftp, 1000, "smallFile.txt");
- uploadAndVerifyFile(sftp, Buffer.MAX_LEN - 1, "bufferMaxLenMinusOneFile.txt");
- uploadAndVerifyFile(sftp, Buffer.MAX_LEN, "bufferMaxLenFile.txt");
+ uploadAndVerifyFile(sftp, ByteArrayBuffer.MAX_LEN - 1, "bufferMaxLenMinusOneFile.txt");
+ uploadAndVerifyFile(sftp, ByteArrayBuffer.MAX_LEN, "bufferMaxLenFile.txt");
// were chunking not implemented, these would fail. these sizes should invoke our internal chunking mechanism
- uploadAndVerifyFile(sftp, Buffer.MAX_LEN + 1, "bufferMaxLenPlusOneFile.txt");
- uploadAndVerifyFile(sftp, (int)(1.5 * Buffer.MAX_LEN), "1point5BufferMaxLenFile.txt");
- uploadAndVerifyFile(sftp, (2 * Buffer.MAX_LEN) - 1, "2TimesBufferMaxLenMinusOneFile.txt");
- uploadAndVerifyFile(sftp, 2 * Buffer.MAX_LEN, "2TimesBufferMaxLenFile.txt");
- uploadAndVerifyFile(sftp, (2 * Buffer.MAX_LEN) + 1, "2TimesBufferMaxLenPlusOneFile.txt");
+ uploadAndVerifyFile(sftp, ByteArrayBuffer.MAX_LEN + 1, "bufferMaxLenPlusOneFile.txt");
+ uploadAndVerifyFile(sftp, (int)(1.5 * ByteArrayBuffer.MAX_LEN), "1point5BufferMaxLenFile.txt");
+ uploadAndVerifyFile(sftp, (2 * ByteArrayBuffer.MAX_LEN) - 1, "2TimesBufferMaxLenMinusOneFile.txt");
+ uploadAndVerifyFile(sftp, 2 * ByteArrayBuffer.MAX_LEN, "2TimesBufferMaxLenFile.txt");
+ uploadAndVerifyFile(sftp, (2 * ByteArrayBuffer.MAX_LEN) + 1, "2TimesBufferMaxLenPlusOneFile.txt");
uploadAndVerifyFile(sftp, 200000, "largerFile.txt");
// test erroneous calls that check for negative values
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java b/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java
index 4a866ef..cf56589 100644
--- a/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java
@@ -32,7 +32,8 @@ import org.apache.sshd.common.io.IoInputStream;
import org.apache.sshd.common.io.IoOutputStream;
import org.apache.sshd.common.io.IoWriteFuture;
import org.apache.sshd.common.io.WritePendingException;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.common.util.io.NoCloseOutputStream;
import org.apache.sshd.server.AsyncCommand;
import org.apache.sshd.server.Command;
@@ -141,9 +142,9 @@ public class WindowAdjustTest {
new Thread(new Runnable() {
public void run() {
for (int i = 0; i < sendCount; i++) {
- a.write(new Buffer(msg));
+ a.write(new ByteArrayBuffer(msg));
}
- a.write(new Buffer((lastMsg.getBytes())));
+ a.write(new ByteArrayBuffer((lastMsg.getBytes())));
}
}).start();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/test/java/org/apache/sshd/WindowTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/WindowTest.java b/sshd-core/src/test/java/org/apache/sshd/WindowTest.java
index 40df419..b57d2f4 100644
--- a/sshd-core/src/test/java/org/apache/sshd/WindowTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/WindowTest.java
@@ -18,6 +18,9 @@
*/
package org.apache.sshd;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
@@ -31,6 +34,7 @@ import java.util.concurrent.CountDownLatch;
import org.apache.sshd.client.channel.ChannelShell;
import org.apache.sshd.client.future.OpenFuture;
import org.apache.sshd.common.Channel;
+import org.apache.sshd.common.FactoryManager;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.RuntimeSshException;
import org.apache.sshd.common.Service;
@@ -38,7 +42,8 @@ import org.apache.sshd.common.Session;
import org.apache.sshd.common.channel.Window;
import org.apache.sshd.common.forward.TcpipServerChannel;
import org.apache.sshd.common.io.IoReadFuture;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.CommandFactory;
import org.apache.sshd.server.channel.ChannelSession;
@@ -55,9 +60,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-
/**
* TODO Add javadoc
*
@@ -80,6 +82,7 @@ public class WindowTest extends BaseTest {
sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
sshd.setShellFactory(new TestEchoShellFactory());
sshd.setCommandFactory(new CommandFactory() {
+ @Override
public Command createCommand(String command) {
return new UnknownCommand(command);
}
@@ -143,8 +146,8 @@ public class WindowTest extends BaseTest {
@Test
public void testWindowConsumptionWithInvertedStreams() throws Exception {
sshd.setShellFactory(new AsyncEchoShellFactory());
- sshd.getProperties().put(SshServer.WINDOW_SIZE, "1024");
- client.getProperties().put(SshClient.WINDOW_SIZE, "1024");
+ sshd.getProperties().put(FactoryManager.WINDOW_SIZE, "1024");
+ client.getProperties().put(FactoryManager.WINDOW_SIZE, "1024");
client.start();
ClientSession session = client.connect("smx", "localhost", port).await().getSession();
session.addPasswordIdentity("smx");
@@ -183,8 +186,8 @@ public class WindowTest extends BaseTest {
@Test
public void testWindowConsumptionWithDirectStreams() throws Exception {
sshd.setShellFactory(new AsyncEchoShellFactory());
- sshd.getProperties().put(SshServer.WINDOW_SIZE, "1024");
- client.getProperties().put(SshClient.WINDOW_SIZE, "1024");
+ sshd.getProperties().put(FactoryManager.WINDOW_SIZE, "1024");
+ client.getProperties().put(FactoryManager.WINDOW_SIZE, "1024");
client.start();
ClientSession session = client.connect("smx", "localhost", port).await().getSession();
session.addPasswordIdentity("smx");
@@ -210,28 +213,29 @@ public class WindowTest extends BaseTest {
final String message = "0123456789";
final int nbMessages = 500;
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(inPos));
- BufferedReader reader = new BufferedReader(new InputStreamReader(outPis));
- for (int i = 0; i < nbMessages; i++) {
- writer.write(message);
- writer.write("\n");
- writer.flush();
-
- waitForWindowEquals(clientLocal, serverRemote, "client local", "server remote");
-
- String line = reader.readLine();
- assertEquals(message, line);
-
- waitForWindowEquals(clientLocal, serverRemote, "client local", "server remote");
- waitForWindowEquals(clientRemote, serverLocal, "client remote", "server local");
+ try(BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(inPos));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(outPis))) {
+ for (int i = 0; i < nbMessages; i++) {
+ writer.write(message);
+ writer.write("\n");
+ writer.flush();
+
+ waitForWindowEquals(clientLocal, serverRemote, "client local", "server remote");
+
+ String line = reader.readLine();
+ assertEquals(message, line);
+
+ waitForWindowEquals(clientLocal, serverRemote, "client local", "server remote");
+ waitForWindowEquals(clientRemote, serverLocal, "client remote", "server local");
+ }
}
}
@Test
public void testWindowConsumptionWithAsyncStreams() throws Exception {
sshd.setShellFactory(new AsyncEchoShellFactory());
- sshd.getProperties().put(SshServer.WINDOW_SIZE, "1024");
- client.getProperties().put(SshClient.WINDOW_SIZE, "1024");
+ sshd.getProperties().put(FactoryManager.WINDOW_SIZE, "1024");
+ client.getProperties().put(FactoryManager.WINDOW_SIZE, "1024");
client.start();
ClientSession session = client.connect("smx", "localhost", port).await().getSession();
session.addPasswordIdentity("smx");
@@ -253,12 +257,12 @@ public class WindowTest extends BaseTest {
for (int i = 0; i < nbMessages; i++) {
- Buffer buffer = new Buffer((message + "\n").getBytes());
+ Buffer buffer = new ByteArrayBuffer((message + "\n").getBytes());
channel.getAsyncIn().write(buffer).verify();
waitForWindowNotEquals(clientLocal, serverRemote, "client local", "server remote");
- Buffer buf = new Buffer(16);
+ Buffer buf = new ByteArrayBuffer(16);
IoReadFuture future = channel.getAsyncOut().read(buf);
future.verify();
assertEquals(11, buf.available());
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/test/java/org/apache/sshd/common/util/BufferTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/BufferTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/BufferTest.java
index d939ed3..481c117 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/BufferTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/util/BufferTest.java
@@ -18,14 +18,16 @@
*/
package org.apache.sshd.common.util;
+import static org.junit.Assert.assertEquals;
+
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.util.BaseTest;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-
public class BufferTest extends BaseTest {
@Test
@@ -33,7 +35,7 @@ public class BufferTest extends BaseTest {
long v = 1234567890123456789L;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
new DataOutputStream(stream).writeLong(v);
- Buffer buffer = new Buffer(stream.toByteArray());
+ Buffer buffer = new ByteArrayBuffer(stream.toByteArray());
assertEquals(v, buffer.getLong());
}
}
[3/4] mina-sshd git commit: [SSHD-459] Make Buffer an abstract class
Posted by lg...@apache.org.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/compression/Compression.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/compression/Compression.java b/sshd-core/src/main/java/org/apache/sshd/common/compression/Compression.java
index 95294da..38ea52f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/compression/Compression.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/compression/Compression.java
@@ -20,7 +20,7 @@ package org.apache.sshd.common.compression;
import java.io.IOException;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* Interface used to compress the stream of data between the
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionZlib.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionZlib.java b/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionZlib.java
index 5e9a56c..4b50c3b 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionZlib.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/compression/CompressionZlib.java
@@ -23,7 +23,7 @@ import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
* ZLib based Compression.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java b/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
index cb68ea4..458b483 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
@@ -40,9 +40,10 @@ import org.apache.sshd.common.io.IoAcceptor;
import org.apache.sshd.common.io.IoHandler;
import org.apache.sshd.common.io.IoSession;
import org.apache.sshd.common.session.ConnectionService;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.CloseableUtils;
import org.apache.sshd.common.util.Readable;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
/**
* TODO Add javadoc
@@ -68,6 +69,7 @@ public class DefaultTcpipForwarder extends CloseableUtils.AbstractInnerCloseable
// TcpIpForwarder implementation
//
+ @Override
public synchronized SshdSocketAddress startLocalPortForwarding(SshdSocketAddress local, SshdSocketAddress remote) throws IOException {
if (local == null) {
throw new IllegalArgumentException("Local address is null");
@@ -89,12 +91,14 @@ public class DefaultTcpipForwarder extends CloseableUtils.AbstractInnerCloseable
return bound;
}
+ @Override
public synchronized void stopLocalPortForwarding(SshdSocketAddress local) throws IOException {
if (localToRemote.remove(local.getPort()) != null && acceptor != null) {
acceptor.unbind(local.toInetSocketAddress());
}
}
+ @Override
public synchronized SshdSocketAddress startRemotePortForwarding(SshdSocketAddress remote, SshdSocketAddress local) throws IOException {
Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_GLOBAL_REQUEST);
buffer.putString("tcpip-forward");
@@ -111,6 +115,7 @@ public class DefaultTcpipForwarder extends CloseableUtils.AbstractInnerCloseable
return new SshdSocketAddress(remote.getHostName(), port);
}
+ @Override
public synchronized void stopRemotePortForwarding(SshdSocketAddress remote) throws IOException {
if (remoteToLocal.remove(remote.getPort()) != null) {
Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_GLOBAL_REQUEST);
@@ -122,6 +127,7 @@ public class DefaultTcpipForwarder extends CloseableUtils.AbstractInnerCloseable
}
}
+ @Override
public synchronized SshdSocketAddress startDynamicPortForwarding(SshdSocketAddress local) throws IOException {
if (local == null) {
throw new IllegalArgumentException("Local address is null");
@@ -141,6 +147,7 @@ public class DefaultTcpipForwarder extends CloseableUtils.AbstractInnerCloseable
return bound;
}
+ @Override
public synchronized void stopDynamicPortForwarding(SshdSocketAddress local) throws IOException {
Closeable obj = dynamicLocal.remove(local.getPort());
if (obj != null) {
@@ -149,10 +156,12 @@ public class DefaultTcpipForwarder extends CloseableUtils.AbstractInnerCloseable
}
}
+ @Override
public synchronized SshdSocketAddress getForwardedPort(int remotePort) {
return remoteToLocal.get(remotePort);
}
+ @Override
public synchronized SshdSocketAddress localPortForwardingRequested(SshdSocketAddress local) throws IOException {
if (local == null) {
throw new IllegalArgumentException("Local address is null");
@@ -169,6 +178,7 @@ public class DefaultTcpipForwarder extends CloseableUtils.AbstractInnerCloseable
return bound;
}
+ @Override
public synchronized void localPortForwardingCancelled(SshdSocketAddress local) throws IOException {
if (localForwards.remove(local) && acceptor != null) {
acceptor.unbind(local.toInetSocketAddress());
@@ -209,6 +219,7 @@ public class DefaultTcpipForwarder extends CloseableUtils.AbstractInnerCloseable
}
}
+ @Override
public String toString() {
return getClass().getSimpleName() + "[" + session + "]";
}
@@ -219,6 +230,7 @@ public class DefaultTcpipForwarder extends CloseableUtils.AbstractInnerCloseable
class StaticIoHandler implements IoHandler {
+ @Override
public void sessionCreated(final IoSession session) throws Exception {
final TcpipClientChannel channel;
int localPort = ((InetSocketAddress) session.getLocalAddress()).getPort();
@@ -231,6 +243,7 @@ public class DefaultTcpipForwarder extends CloseableUtils.AbstractInnerCloseable
session.setAttribute(TcpipClientChannel.class, channel);
service.registerChannel(channel);
channel.open().addListener(new SshFutureListener<OpenFuture>() {
+ @Override
public void operationComplete(OpenFuture future) {
Throwable t = future.getException();
if (t != null) {
@@ -241,6 +254,7 @@ public class DefaultTcpipForwarder extends CloseableUtils.AbstractInnerCloseable
});
}
+ @Override
public void sessionClosed(IoSession session) throws Exception {
TcpipClientChannel channel = (TcpipClientChannel) session.getAttribute(TcpipClientChannel.class);
if (channel != null) {
@@ -249,15 +263,17 @@ public class DefaultTcpipForwarder extends CloseableUtils.AbstractInnerCloseable
}
}
+ @Override
public void messageReceived(IoSession session, Readable message) throws Exception {
TcpipClientChannel channel = (TcpipClientChannel) session.getAttribute(TcpipClientChannel.class);
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putBuffer(message);
channel.waitFor(ClientChannel.OPENED | ClientChannel.CLOSED, Long.MAX_VALUE);
channel.getInvertedIn().write(buffer.array(), buffer.rpos(), buffer.available());
channel.getInvertedIn().flush();
}
+ @Override
public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
cause.printStackTrace();
session.close(false);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/forward/SocksProxy.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/SocksProxy.java b/sshd-core/src/main/java/org/apache/sshd/common/forward/SocksProxy.java
index bbe4fe7..a009144 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/SocksProxy.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/SocksProxy.java
@@ -30,8 +30,9 @@ import org.apache.sshd.common.future.SshFutureListener;
import org.apache.sshd.common.io.IoHandler;
import org.apache.sshd.common.io.IoSession;
import org.apache.sshd.common.session.ConnectionService;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.CloseableUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
/**
* SOCKS proxy server, supporting simple socks4/5 protocols.
@@ -47,12 +48,14 @@ public class SocksProxy extends CloseableUtils.AbstractCloseable implements IoHa
this.service = service;
}
+ @Override
public void sessionCreated(IoSession session) throws Exception {
if (isClosing()) {
throw new SshException("SocksProxy is closing or closed");
}
}
+ @Override
public void sessionClosed(IoSession session) throws Exception {
Proxy proxy = proxies.remove(session);
if (proxy != null) {
@@ -60,8 +63,9 @@ public class SocksProxy extends CloseableUtils.AbstractCloseable implements IoHa
}
}
+ @Override
public void messageReceived(final IoSession session, org.apache.sshd.common.util.Readable message) throws Exception {
- Buffer buffer = new Buffer(message.available());
+ Buffer buffer = new ByteArrayBuffer(message.available());
buffer.putBuffer(message);
Proxy proxy = proxies.get(session);
if (proxy == null) {
@@ -80,6 +84,7 @@ public class SocksProxy extends CloseableUtils.AbstractCloseable implements IoHa
}
}
+ @Override
public void exceptionCaught(IoSession ioSession, Throwable cause) throws Exception {
log.warn("Exception caught, closing socks proxy", cause);
ioSession.close(false);
@@ -142,6 +147,7 @@ public class SocksProxy extends CloseableUtils.AbstractCloseable implements IoHa
channel = new TcpipClientChannel(TcpipClientChannel.Type.Direct, session, remote);
service.registerChannel(channel);
channel.open().addListener(new SshFutureListener<OpenFuture>() {
+ @Override
public void operationComplete(OpenFuture future) {
onChannelOpened(future);
}
@@ -152,7 +158,7 @@ public class SocksProxy extends CloseableUtils.AbstractCloseable implements IoHa
}
protected void onChannelOpened(OpenFuture future) {
- Buffer buffer = new Buffer(8);
+ Buffer buffer = new ByteArrayBuffer(8);
buffer.putByte((byte) 0x00);
Throwable t = future.getException();
if (t != null) {
@@ -201,7 +207,7 @@ public class SocksProxy extends CloseableUtils.AbstractCloseable implements IoHa
for (int i = 0; i < nbAuthMethods; i++) {
foundNoAuth |= authMethods[i] == 0;
}
- buffer = new Buffer(8);
+ buffer = new ByteArrayBuffer(8);
buffer.putByte((byte) 0x05);
buffer.putByte((byte) (foundNoAuth ? 0x00 : 0xFF));
session.write(buffer);
@@ -248,6 +254,7 @@ public class SocksProxy extends CloseableUtils.AbstractCloseable implements IoHa
channel = new TcpipClientChannel(TcpipClientChannel.Type.Direct, session, remote);
service.registerChannel(channel);
channel.open().addListener(new SshFutureListener<OpenFuture>() {
+ @Override
public void operationComplete(OpenFuture future) {
onChannelOpened(future);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java b/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java
index 0d95acf..cb93049 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java
@@ -29,12 +29,9 @@ import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.SshdSocketAddress;
import org.apache.sshd.common.channel.ChannelOutputStream;
-import org.apache.sshd.common.future.CloseFuture;
-import org.apache.sshd.common.future.DefaultCloseFuture;
-import org.apache.sshd.common.future.SshFutureListener;
import org.apache.sshd.common.io.IoSession;
-import org.apache.sshd.common.util.Buffer;
-import org.apache.sshd.common.util.CloseableUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
/**
* TODO Add javadoc
@@ -64,6 +61,7 @@ public class TcpipClientChannel extends AbstractClientChannel {
return openFuture;
}
+ @Override
public synchronized OpenFuture open() throws IOException {
InetSocketAddress src = null, dst = null;
switch (typeEnum) {
@@ -107,10 +105,11 @@ public class TcpipClientChannel extends AbstractClientChannel {
return builder().sequential(serverSession, super.getInnerCloseable()).build();
}
+ @Override
protected synchronized void doWriteData(byte[] data, int off, int len) throws IOException {
// Make sure we copy the data as the incoming buffer may be reused
- Buffer buf = new Buffer(data, off, len);
- buf = new Buffer(buf.getCompactData());
+ Buffer buf = new ByteArrayBuffer(data, off, len);
+ buf = new ByteArrayBuffer(buf.getCompactData());
localWindow.consumeAndCheck(len);
serverSession.write(buf);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipServerChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipServerChannel.java b/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipServerChannel.java
index f2e0925..a828de6 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipServerChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipServerChannel.java
@@ -37,8 +37,9 @@ import org.apache.sshd.common.io.IoConnector;
import org.apache.sshd.common.io.IoHandler;
import org.apache.sshd.common.io.IoSession;
import org.apache.sshd.common.io.IoWriteFuture;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.Readable;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.server.channel.AbstractServerChannel;
import org.apache.sshd.server.channel.OpenChannelException;
@@ -51,10 +52,12 @@ public class TcpipServerChannel extends AbstractServerChannel {
public static class DirectTcpipFactory implements NamedFactory<Channel> {
+ @Override
public String getName() {
return "direct-tcpip";
}
+ @Override
public Channel create() {
return new TcpipServerChannel(Type.Direct);
}
@@ -62,10 +65,12 @@ public class TcpipServerChannel extends AbstractServerChannel {
public static class ForwardedTcpipFactory implements NamedFactory<Channel> {
+ @Override
public String getName() {
return "forwarded-tcpip";
}
+ @Override
public Channel create() {
return new TcpipServerChannel(Type.Forwarded);
}
@@ -85,6 +90,7 @@ public class TcpipServerChannel extends AbstractServerChannel {
this.type = type;
}
+ @Override
protected OpenFuture doInit(Buffer buffer) {
final OpenFuture f = new DefaultOpenFuture(this);
@@ -111,21 +117,25 @@ public class TcpipServerChannel extends AbstractServerChannel {
// TODO: revisit for better threading. Use async io ?
out = new ChannelOutputStream(this, remoteWindow, log, SshConstants.SSH_MSG_CHANNEL_DATA);
IoHandler handler = new IoHandler() {
+ @Override
public void messageReceived(IoSession session, Readable message) throws Exception {
if (isClosing()) {
log.debug("Ignoring write to channel {} in CLOSING state", id);
} else {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putBuffer(message);
out.write(buffer.array(), buffer.rpos(), buffer.available());
out.flush();
}
}
+ @Override
public void sessionCreated(IoSession session) throws Exception {
}
+ @Override
public void sessionClosed(IoSession session) throws Exception {
close(false);
}
+ @Override
public void exceptionCaught(IoSession ioSession, Throwable cause) throws Exception {
close(true);
}
@@ -134,6 +144,7 @@ public class TcpipServerChannel extends AbstractServerChannel {
.createConnector(handler);
IoConnectFuture future = connector.connect(address.toInetSocketAddress());
future.addListener(new SshFutureListener<IoConnectFuture>() {
+ @Override
public void operationComplete(IoConnectFuture future) {
if (future.isConnected()) {
ioSession = future.getSession();
@@ -176,19 +187,23 @@ public class TcpipServerChannel extends AbstractServerChannel {
}.start();
}
+ @Override
public CloseFuture close(boolean immediately) {
return super.close(immediately).addListener(new SshFutureListener<CloseFuture>() {
+ @Override
public void operationComplete(CloseFuture sshFuture) {
closeImmediately0();
}
});
}
+ @Override
protected void doWriteData(byte[] data, int off, final int len) throws IOException {
// Make sure we copy the data as the incoming buffer may be reused
- Buffer buf = new Buffer(data, off, len);
- buf = new Buffer(buf.getCompactData());
+ Buffer buf = new ByteArrayBuffer(data, off, len);
+ buf = new ByteArrayBuffer(buf.getCompactData());
ioSession.write(buf).addListener(new SshFutureListener<IoWriteFuture>() {
+ @Override
public void operationComplete(IoWriteFuture future) {
try {
localWindow.consumeAndCheck(len);
@@ -199,6 +214,7 @@ public class TcpipServerChannel extends AbstractServerChannel {
});
}
+ @Override
protected void doWriteExtendedData(byte[] data, int off, int len) throws IOException {
throw new UnsupportedOperationException(type + "Tcpip channel does not support extended data");
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/io/IoInputStream.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/IoInputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/io/IoInputStream.java
index c585b67..d61419c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/IoInputStream.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/IoInputStream.java
@@ -19,7 +19,7 @@
package org.apache.sshd.common.io;
import org.apache.sshd.common.Closeable;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
public interface IoInputStream extends Closeable {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/io/IoOutputStream.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/IoOutputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/io/IoOutputStream.java
index f2b8994..104d5fb 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/IoOutputStream.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/IoOutputStream.java
@@ -19,7 +19,7 @@
package org.apache.sshd.common.io;
import org.apache.sshd.common.Closeable;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
public interface IoOutputStream extends Closeable {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/io/IoReadFuture.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/IoReadFuture.java b/sshd-core/src/main/java/org/apache/sshd/common/io/IoReadFuture.java
index d4f07a9..ebf9c20 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/IoReadFuture.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/IoReadFuture.java
@@ -20,7 +20,7 @@ package org.apache.sshd.common.io;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.future.SshFuture;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
public interface IoReadFuture extends SshFuture<IoReadFuture> {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/io/IoSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/IoSession.java b/sshd-core/src/main/java/org/apache/sshd/common/io/IoSession.java
index caccfca..0158064 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/IoSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/IoSession.java
@@ -22,7 +22,7 @@ import java.net.SocketAddress;
import org.apache.sshd.common.Closeable;
import org.apache.sshd.common.future.CloseFuture;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
public interface IoSession extends Closeable {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaSession.java b/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaSession.java
index ed8f380..64d245c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaSession.java
@@ -31,8 +31,8 @@ import org.apache.sshd.common.future.DefaultSshFuture;
import org.apache.sshd.common.io.IoService;
import org.apache.sshd.common.io.IoSession;
import org.apache.sshd.common.io.IoWriteFuture;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.CloseableUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
*/
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaSupport.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaSupport.java b/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaSupport.java
index f9259f4..9b623e5 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaSupport.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaSupport.java
@@ -19,8 +19,8 @@
package org.apache.sshd.common.io.mina;
import org.apache.mina.core.buffer.IoBuffer;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.Readable;
+import org.apache.sshd.common.util.buffer.Buffer;
public class MinaSupport {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java
index 9822c2d..a0ceaf0 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java
@@ -39,9 +39,9 @@ import org.apache.sshd.common.io.IoHandler;
import org.apache.sshd.common.io.IoService;
import org.apache.sshd.common.io.IoSession;
import org.apache.sshd.common.io.IoWriteFuture;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.CloseableUtils;
import org.apache.sshd.common.util.Readable;
+import org.apache.sshd.common.util.buffer.Buffer;
/**
*/
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
index 6a709df..26f589e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
@@ -37,8 +37,8 @@ import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.TcpipForwarder;
import org.apache.sshd.common.future.SshFutureListener;
-import org.apache.sshd.common.util.Buffer;
import org.apache.sshd.common.util.CloseableUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.server.channel.OpenChannelException;
import org.apache.sshd.server.x11.X11ForwardSupport;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
index 0903c39..378cce6 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
@@ -61,17 +61,18 @@ import org.apache.sshd.common.future.SshFuture;
import org.apache.sshd.common.future.SshFutureListener;
import org.apache.sshd.common.io.IoSession;
import org.apache.sshd.common.io.IoWriteFuture;
-import org.apache.sshd.common.util.Buffer;
-import org.apache.sshd.common.util.BufferUtils;
import org.apache.sshd.common.util.CloseableUtils;
import org.apache.sshd.common.util.EventListenerUtils;
import org.apache.sshd.common.util.Readable;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.BufferUtils;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
/**
* The AbstractSession handles all the basic SSH protocol such as key exchange, authentication,
* encoding and decoding. Both server side and client side sessions should inherit from this
* abstract class. Some basic packet processing methods are defined but the actual call to these
- * methods should be done from the {@link #handleMessage(org.apache.sshd.common.util.Buffer)}
+ * methods should be done from the {@link #handleMessage(org.apache.sshd.common.util.buffer.Buffer)}
* method, which is dependant on the state and side of this session.
*
* TODO: if there is any very big packet, decoderBuffer and uncompressBuffer will get quite big
@@ -139,7 +140,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
protected Compression inCompression;
protected long seqi;
protected long seqo;
- protected Buffer decoderBuffer = new Buffer();
+ protected Buffer decoderBuffer = new ByteArrayBuffer();
protected Buffer uncompressBuffer;
protected int decoderState;
protected int decoderLength;
@@ -228,10 +229,12 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
ioSession.setAttribute(SESSION, session);
}
+ @Override
public String getServerVersion() {
return serverVersion;
}
+ @Override
public String getClientVersion() {
return clientVersion;
}
@@ -250,6 +253,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
*
* @return the mina session
*/
+ @Override
public IoSession getIoSession() {
return ioSession;
}
@@ -259,10 +263,12 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
*
* @return the factory manager for this session
*/
+ @Override
public FactoryManager getFactoryManager() {
return factoryManager;
}
+ @Override
public String getNegotiatedKexParameter(int paramType) {
if ((paramType < 0) || (negotiated == null) || (paramType >= negotiated.length)) {
return null;
@@ -447,6 +453,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
*
* @param t the exception to process
*/
+ @Override
public void exceptionCaught(Throwable t) {
// Ignore exceptions that happen while closing
synchronized (lock) {
@@ -488,6 +495,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
return currentService != null ? new Service[] { currentService } : new Service[0];
}
+ @Override
public <T extends Service> T getService(Class<T> clazz) {
for (Service s : getServices()) {
if (clazz.isInstance(s)) {
@@ -506,6 +514,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
* @return a future that can be used to check when the packet has actually been sent
* @throws java.io.IOException if an error occured when encoding sending the packet
*/
+ @Override
public IoWriteFuture writePacket(Buffer buffer) throws IOException {
// While exchanging key, queue high level packets
if (kexState.get() != KEX_STATE_DONE) {
@@ -571,6 +580,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
* @return <code>true</code> if the request was successful, <code>false</code> otherwise.
* @throws java.io.IOException if an error occured when encoding sending the packet
*/
+ @Override
public Buffer request(Buffer buffer) throws IOException {
synchronized (requestLock) {
try {
@@ -585,6 +595,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
}
}
+ @Override
public Buffer createBuffer(byte cmd) {
return createBuffer(cmd, 0);
}
@@ -597,10 +608,11 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
* @param len estimated number of bytes the buffer will hold, 0 if unknown.
* @return a new buffer ready for write
*/
+ @Override
public Buffer createBuffer(byte cmd, int len) {
Buffer buffer;
if (len <= 0) {
- buffer = new Buffer();
+ buffer = new ByteArrayBuffer();
} else {
// Since the caller claims to know how many bytes they will need
// increase their request to account for our headers/footers if
@@ -616,7 +628,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
if (outMac != null) {
len += outMac.getBlockSize();
}
- buffer = new Buffer(new byte[Math.max(len, Buffer.DEFAULT_SIZE)], false);
+ buffer = new ByteArrayBuffer(new byte[Math.max(len, ByteArrayBuffer.DEFAULT_SIZE)], false);
}
buffer.rpos(5);
buffer.wpos(5);
@@ -637,7 +649,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
if (buffer.rpos() < 5) {
log.warn("Performance cost: when sending a packet, ensure that "
+ "5 bytes are available in front of the buffer");
- Buffer nb = new Buffer();
+ Buffer nb = new ByteArrayBuffer();
nb.wpos(5);
nb.putBuffer(buffer);
buffer = nb;
@@ -763,7 +775,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
// Decompress if needed
if (inCompression != null && (authed || !inCompression.isDelayed())) {
if (uncompressBuffer == null) {
- uncompressBuffer = new Buffer();
+ uncompressBuffer = new ByteArrayBuffer();
} else {
uncompressBuffer.clear();
}
@@ -803,13 +815,13 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
protected void sendIdentification(String ident) {
log.debug("Send identification: {}", ident);
byte[] data = (ident + "\r\n").getBytes();
- ioSession.write(new Buffer(data));
+ ioSession.write(new ByteArrayBuffer(data));
}
/**
* Read the other side identification.
* This method is specific to the client or server side, but both should call
- * {@link #doReadIdentification(org.apache.sshd.common.util.Buffer,boolean)} and
+ * {@link #doReadIdentification(org.apache.sshd.common.util.buffer.Buffer,boolean)} and
* store the result in the needed property.
*
* @param buffer the buffer containing the remote identification
@@ -983,7 +995,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
System.arraycopy(H, 0, sessionId, 0, H.length);
}
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putMPInt(K);
buffer.putRawBytes(H);
buffer.putByte((byte) 0x41);
@@ -1079,7 +1091,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
*/
private byte[] resizeKey(byte[] E, int blockSize, Digest hash, byte[] K, byte[] H) throws Exception {
while (blockSize > E.length) {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putMPInt(K);
buffer.putRawBytes(H);
buffer.putRawBytes(E);
@@ -1111,6 +1123,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
// Write the packet with a timeout to ensure a timely close of the session
// in case the consumer does not read packets anymore.
writePacket(buffer, disconnectTimeoutMs, TimeUnit.MILLISECONDS).addListener(new SshFutureListener<IoWriteFuture>() {
+ @Override
public void operationComplete(IoWriteFuture future) {
close(true);
}
@@ -1188,7 +1201,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
protected void requestSuccess(Buffer buffer) throws Exception{
synchronized (requestResult) {
- requestResult.set(new Buffer(buffer.getCompactData()));
+ requestResult.set(new ByteArrayBuffer(buffer.getCompactData()));
resetIdleTimeout();
requestResult.notify();
}
@@ -1209,6 +1222,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
* @param defaultValue the default value
* @return the value of the configuration property or the default value if not found
*/
+ @Override
public int getIntProperty(String name, int defaultValue) {
try {
String v = factoryManager.getProperties().get(name);
@@ -1239,6 +1253,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
* @param key the key of the attribute; must not be null.
* @return <tt>null</tt> if there is no attribute with the specified key
*/
+ @Override
@SuppressWarnings("unchecked")
public <T> T getAttribute(AttributeKey<T> key) {
return (T)attributes.get(key);
@@ -1251,11 +1266,13 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
* @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.
*/
+ @Override
@SuppressWarnings("unchecked")
public <T, E extends T> T setAttribute(AttributeKey<T> key, E value) {
return (T)attributes.put(key, value);
}
+ @Override
public String getUsername() {
return username;
}
@@ -1267,6 +1284,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
/**
* {@inheritDoc}
*/
+ @Override
public void addListener(SessionListener listener) {
if (listener == null) {
throw new IllegalArgumentException();
@@ -1277,6 +1295,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
/**
* {@inheritDoc}
*/
+ @Override
public void removeListener(SessionListener listener) {
this.listeners.remove(listener);
}
@@ -1288,6 +1307,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
/**
* {@inheritDoc}
*/
+ @Override
public SshFuture reExchangeKeys() throws IOException {
if (kexState.compareAndSet(KEX_STATE_DONE, KEX_STATE_INIT)) {
log.info("Initiating key re-exchange");
@@ -1331,6 +1351,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
}
}
+ @Override
public void resetIdleTimeout() {
this.idleTimeoutTimestamp = System.currentTimeMillis() + idleTimeoutMs;
}
@@ -1339,6 +1360,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
* Check if timeout has occurred.
* @return
*/
+ @Override
public TimeoutStatus getTimeoutStatus() {
return timeoutStatus.get();
}
@@ -1347,6 +1369,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
* What is timeout value in milliseconds for authentication stage
* @return
*/
+ @Override
public long getAuthTimeout() {
return authTimeoutMs;
}
@@ -1355,6 +1378,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
* What is timeout value in milliseconds for communication
* @return
*/
+ @Override
public long getIdleTimeout() {
return idleTimeoutMs;
}
@@ -1376,6 +1400,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
return buffer;
}
+ @Override
public void verify() throws SshException {
try {
await();
@@ -1388,10 +1413,12 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
}
}
+ @Override
public boolean isWritten() {
return getValue() instanceof Boolean;
}
+ @Override
public Throwable getException() {
Object v = getValue();
return v instanceof Throwable ? (Throwable) v : null;
@@ -1408,6 +1435,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
setValue(cause);
}
+ @Override
public void operationComplete(IoWriteFuture future) {
if (future.isWritten()) {
setWritten();
@@ -1417,6 +1445,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
}
}
+ @Override
public String toString() {
return getClass().getSimpleName() + "[" + getUsername() + "@" + getIoSession().getRemoteAddress() + "]";
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureECDSA.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureECDSA.java b/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureECDSA.java
index 5801801..2fdef4e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureECDSA.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureECDSA.java
@@ -20,7 +20,9 @@ package org.apache.sshd.common.signature;
import java.io.IOException;
import java.math.BigInteger;
-import org.apache.sshd.common.util.Buffer;
+
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
/**
* Signature algorithm for EC keys using ECDSA. There
@@ -61,7 +63,7 @@ public class SignatureECDSA extends AbstractSignature {
BigInteger s = new BigInteger(sArray);
// Write the <r,s> to its own types writer.
- Buffer rsBuf = new Buffer();
+ Buffer rsBuf = new ByteArrayBuffer();
rsBuf.putMPInt(r);
rsBuf.putMPInt(s);
@@ -72,7 +74,7 @@ public class SignatureECDSA extends AbstractSignature {
public boolean verify(byte[] sig) throws Exception {
sig = extractSig(sig);
- Buffer rsBuf = new Buffer(sig);
+ Buffer rsBuf = new ByteArrayBuffer(sig);
byte[] rArray = rsBuf.getMPIntAsBytes();
byte[] sArray = rsBuf.getMPIntAsBytes();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/util/Buffer.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/Buffer.java b/sshd-core/src/main/java/org/apache/sshd/common/util/Buffer.java
deleted file mode 100644
index 9697bb3..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/Buffer.java
+++ /dev/null
@@ -1,577 +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.util;
-
-import java.math.BigInteger;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.security.KeyFactory;
-import java.security.KeyPair;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-import java.security.interfaces.DSAPrivateKey;
-import java.security.interfaces.DSAPublicKey;
-import java.security.interfaces.ECPrivateKey;
-import java.security.interfaces.ECPublicKey;
-import java.security.interfaces.RSAPrivateCrtKey;
-import java.security.interfaces.RSAPublicKey;
-import java.security.spec.DSAPrivateKeySpec;
-import java.security.spec.DSAPublicKeySpec;
-import java.security.spec.ECParameterSpec;
-import java.security.spec.ECPoint;
-import java.security.spec.ECPrivateKeySpec;
-import java.security.spec.ECPublicKeySpec;
-import java.security.spec.InvalidKeySpecException;
-import java.security.spec.RSAPrivateCrtKeySpec;
-import java.security.spec.RSAPublicKeySpec;
-
-import org.apache.sshd.common.KeyPairProvider;
-import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.SshException;
-import org.apache.sshd.common.cipher.ECCurves;
-
-/**
- * TODO Add javadoc
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public final class Buffer implements Readable {
-
- public static final int DEFAULT_SIZE = 256;
- public static final int MAX_LEN = 65536;
-
- private byte[] data;
- private int rpos;
- private int wpos;
-
- public Buffer() {
- this(DEFAULT_SIZE);
- }
-
- public Buffer(int size) {
- this(new byte[getNextPowerOf2(size)], false);
- }
-
- public Buffer(byte[] data) {
- this(data, 0, data.length, true);
- }
-
- public Buffer(byte[] data, boolean read) {
- this(data, 0, data.length, read);
- }
-
- public Buffer(byte[] data, int off, int len) {
- this(data, off, len, true);
- }
-
- public Buffer(byte[] data, int off, int len, boolean read) {
- this.data = data;
- this.rpos = off;
- this.wpos = (read ? len : 0) + off;
- }
-
- @Override
- public String toString() {
- return "Buffer [rpos=" + rpos + ", wpos=" + wpos + ", size=" + data.length + "]";
- }
-
- /*======================
- Global methods
- ======================*/
-
- public int rpos() {
- return rpos;
- }
-
- public void rpos(int rpos) {
- this.rpos = rpos;
- }
-
- public int wpos() {
- return wpos;
- }
-
- public void wpos(int wpos) {
- ensureCapacity(wpos - this.wpos);
- this.wpos = wpos;
- }
-
- public int available() {
- return wpos - rpos;
- }
-
- public int capacity() {
- return data.length - wpos;
- }
-
- public byte[] array() {
- return data;
- }
-
- public void compact() {
- if (available() > 0) {
- System.arraycopy(data, rpos, data, 0, wpos - rpos);
- }
- wpos -= rpos;
- rpos = 0;
- }
-
- public byte[] getCompactData() {
- int l = available();
- if (l > 0) {
- byte[] b = new byte[l];
- System.arraycopy(data, rpos, b, 0, l);
- return b;
- } else {
- return new byte[0];
- }
- }
-
- public void clear() {
- rpos = 0;
- wpos = 0;
- }
-
- public String printHex() {
- return BufferUtils.printHex(array(), rpos(), available());
- }
-
- /*======================
- Read methods
- ======================*/
-
- public byte getByte() {
- ensureAvailable(1);
- return data[rpos++];
- }
-
- public int getInt() {
- return (int) getUInt();
- }
-
- public long getUInt()
- {
- ensureAvailable(4);
- long l = ((data[rpos++] << 24) & 0xff000000L)|
- ((data[rpos++] << 16) & 0x00ff0000L)|
- ((data[rpos++] << 8) & 0x0000ff00L)|
- ((data[rpos++] ) & 0x000000ffL);
- return l;
- }
-
- public long getLong()
- {
- ensureAvailable(8);
- long l = (((long) data[rpos++] << 56) & 0xff00000000000000L)|
- (((long) data[rpos++] << 48) & 0x00ff000000000000L)|
- (((long) data[rpos++] << 40) & 0x0000ff0000000000L)|
- (((long) data[rpos++] << 32) & 0x000000ff00000000L)|
- (((long) data[rpos++] << 24) & 0x00000000ff000000L)|
- (((long) data[rpos++] << 16) & 0x0000000000ff0000L)|
- (((long) data[rpos++] << 8) & 0x000000000000ff00L)|
- (((long) data[rpos++] ) & 0x00000000000000ffL);
- return l;
- }
-
- public boolean getBoolean() {
- return getByte() != 0;
- }
-
- public String getString() {
- return getString(StandardCharsets.UTF_8);
- }
-
- public String getString(Charset charset) {
- int len = getInt();
- if (len < 0) {
- throw new IllegalStateException("Bad item length: " + len);
- }
- ensureAvailable(len);
- String s = new String(data, rpos, len, charset);
- rpos += len;
- return s;
- }
-
- public byte[] getStringAsBytes() {
- return getBytes();
- }
-
- public BigInteger getMPInt() {
- return new BigInteger(getMPIntAsBytes());
- }
-
- public byte[] getMPIntAsBytes() {
- return getBytes();
- }
-
- public byte[] getBytes() {
- int len = getInt();
- if (len < 0) {
- throw new IllegalStateException("Bad item length: " + len);
- }
- ensureAvailable(len);
- byte[] b = new byte[len];
- getRawBytes(b);
- return b;
- }
-
- public void getRawBytes(byte[] buf) {
- getRawBytes(buf, 0, buf.length);
- }
-
- public void getRawBytes(byte[] buf, int off, int len) {
- ensureAvailable(len);
- System.arraycopy(data, rpos, buf, off, len);
- rpos += len;
- }
-
- public PublicKey getPublicKey() throws SshException {
- int ow = wpos;
- int len = getInt();
- wpos = rpos + len;
- try {
- return getRawPublicKey();
- } finally {
- wpos = ow;
- }
- }
-
- public PublicKey getRawPublicKey() throws SshException {
- try {
- PublicKey key;
- String keyAlg = getString();
- if (KeyPairProvider.SSH_RSA.equals(keyAlg)) {
- BigInteger e = getMPInt();
- BigInteger n = getMPInt();
- KeyFactory keyFactory = SecurityUtils.getKeyFactory("RSA");
- key = keyFactory.generatePublic(new RSAPublicKeySpec(n, e));
- } else if (KeyPairProvider.SSH_DSS.equals(keyAlg)) {
- BigInteger p = getMPInt();
- BigInteger q = getMPInt();
- BigInteger g = getMPInt();
- BigInteger y = getMPInt();
- KeyFactory keyFactory = SecurityUtils.getKeyFactory("DSA");
- key = keyFactory.generatePublic(new DSAPublicKeySpec(y, p, q, g));
- } else if (KeyPairProvider.ECDSA_SHA2_NISTP256.equals(keyAlg)) {
- key = getRawECKey("nistp256", ECCurves.EllipticCurves.nistp256);
- } else if (KeyPairProvider.ECDSA_SHA2_NISTP384.equals(keyAlg)) {
- key = getRawECKey("nistp384", ECCurves.EllipticCurves.nistp384);
- } else if (KeyPairProvider.ECDSA_SHA2_NISTP521.equals(keyAlg)) {
- key = getRawECKey("nistp521", ECCurves.EllipticCurves.nistp521);
- } else {
- throw new IllegalStateException("Unsupported algorithm: " + keyAlg);
- }
- return key;
- } catch (InvalidKeySpecException e) {
- throw new SshException(e);
- } catch (NoSuchAlgorithmException e) {
- throw new SshException(e);
- } catch (NoSuchProviderException e) {
- throw new SshException(e);
- }
- }
-
- private PublicKey getRawECKey(String expectedCurve, ECParameterSpec spec) throws InvalidKeySpecException,
- SshException, NoSuchAlgorithmException, NoSuchProviderException {
- String curveName = getString();
- if (!expectedCurve.equals(curveName)) {
- throw new InvalidKeySpecException("Curve name does not match expected: " + curveName + " vs "
- + expectedCurve);
- }
- ECPoint w = ECCurves.decodeECPoint(getStringAsBytes(), spec.getCurve());
- KeyFactory keyFactory = SecurityUtils.getKeyFactory("EC");
- return keyFactory.generatePublic(new ECPublicKeySpec(w, spec));
- }
-
- public KeyPair getKeyPair() throws SshException {
- try {
- PublicKey pub;
- PrivateKey prv;
- String keyAlg = getString();
- if (KeyPairProvider.SSH_RSA.equals(keyAlg)) {
- BigInteger e = getMPInt();
- BigInteger n = getMPInt();
- BigInteger d = getMPInt();
- BigInteger qInv = getMPInt();
- BigInteger q = getMPInt();
- BigInteger p = getMPInt();
- BigInteger dP = d.remainder(p.subtract(BigInteger.valueOf(1)));
- BigInteger dQ = d.remainder(q.subtract(BigInteger.valueOf(1)));
- KeyFactory keyFactory = SecurityUtils.getKeyFactory("RSA");
- pub = keyFactory.generatePublic(new RSAPublicKeySpec(n, e));
- prv = keyFactory.generatePrivate(new RSAPrivateCrtKeySpec(n, e, d, p, q, dP, dQ, qInv));
- } else if (KeyPairProvider.SSH_DSS.equals(keyAlg)) {
- BigInteger p = getMPInt();
- BigInteger q = getMPInt();
- BigInteger g = getMPInt();
- BigInteger y = getMPInt();
- BigInteger x = getMPInt();
- KeyFactory keyFactory = SecurityUtils.getKeyFactory("DSA");
- pub = keyFactory.generatePublic(new DSAPublicKeySpec(y, p, q, g));
- prv = keyFactory.generatePrivate(new DSAPrivateKeySpec(x, p, q, g));
- } else if (KeyPairProvider.ECDSA_SHA2_NISTP256.equals(keyAlg)) {
- return extractEC("nistp256", ECCurves.EllipticCurves.nistp256);
- } else if (KeyPairProvider.ECDSA_SHA2_NISTP384.equals(keyAlg)) {
- return extractEC("nistp384", ECCurves.EllipticCurves.nistp384);
- } else if (KeyPairProvider.ECDSA_SHA2_NISTP521.equals(keyAlg)) {
- return extractEC("nistp521", ECCurves.EllipticCurves.nistp521);
- } else {
- throw new IllegalStateException("Unsupported algorithm: " + keyAlg);
- }
- return new KeyPair(pub, prv);
- } catch (InvalidKeySpecException e) {
- throw new SshException(e);
- } catch (NoSuchAlgorithmException e) {
- throw new SshException(e);
- } catch (NoSuchProviderException e) {
- throw new SshException(e);
- }
- }
-
- private KeyPair extractEC(String expectedCurveName, ECParameterSpec spec) throws NoSuchAlgorithmException,
- NoSuchProviderException, InvalidKeySpecException, SshException {
- String curveName = getString();
- byte[] groupBytes = getStringAsBytes();
- BigInteger exponent = getMPInt();
-
- if (!expectedCurveName.equals(curveName)) {
- throw new SshException("Expected curve " + expectedCurveName + " but was " + curveName);
- }
-
- ECPoint group = ECCurves.decodeECPoint(groupBytes, spec.getCurve());
- if (group == null) {
- throw new InvalidKeySpecException("Couldn't decode EC group");
- }
-
- KeyFactory keyFactory = SecurityUtils.getKeyFactory("EC");
- PublicKey pubKey = keyFactory.generatePublic(new ECPublicKeySpec(group, spec));
- PrivateKey privKey = keyFactory.generatePrivate(new ECPrivateKeySpec(exponent, spec));
- return new KeyPair(pubKey, privKey);
- }
-
- private void ensureAvailable(int a) {
- if (available() < a) {
- throw new BufferException("Underflow");
- }
- }
-
- /*======================
- Write methods
- ======================*/
-
- public void putByte(byte b) {
- ensureCapacity(1);
- data[wpos++] = b;
- }
-
- public void putBuffer(Readable buffer) {
- putBuffer(buffer, true);
- }
-
- public int putBuffer(Readable buffer, boolean expand) {
- int r = expand ? buffer.available() : Math.min(buffer.available(), capacity());
- ensureCapacity(r);
- buffer.getRawBytes(data, wpos, r);
- wpos += r;
- return r;
- }
-
- /**
- * Writes 16 bits
- * @param i
- */
- public void putShort(int i) {
- ensureCapacity(2);
- data[wpos++] = (byte) (i >> 8);
- data[wpos++] = (byte) (i );
- }
-
- /**
- * Writes 32 bits
- * @param i
- */
- public void putInt(long i) {
- ensureCapacity(4);
- data[wpos++] = (byte) (i >> 24);
- data[wpos++] = (byte) (i >> 16);
- data[wpos++] = (byte) (i >> 8);
- data[wpos++] = (byte) (i );
- }
-
- /**
- * Writes 64 bits
- * @param i
- */
- public void putLong(long i) {
- ensureCapacity(8);
- data[wpos++] = (byte) (i >> 56);
- data[wpos++] = (byte) (i >> 48);
- data[wpos++] = (byte) (i >> 40);
- data[wpos++] = (byte) (i >> 32);
- data[wpos++] = (byte) (i >> 24);
- data[wpos++] = (byte) (i >> 16);
- data[wpos++] = (byte) (i >> 8);
- data[wpos++] = (byte) (i );
- }
-
- public void putBoolean(boolean b) {
- putByte(b ? (byte) 1 : (byte) 0);
- }
-
- public void putBytes(byte[] b) {
- putBytes(b, 0, b.length);
- }
-
- public void putBytes(byte[] b, int off, int len) {
- putInt(len);
- ensureCapacity(len);
- System.arraycopy(b, off, data, wpos, len);
- wpos += len;
- }
-
- public void putString(String string) {
- putString(string, Charset.defaultCharset());
- }
-
- public void putString(String string, Charset charset) {
- putString(string.getBytes(charset));
- }
-
- public void putString(byte[] str) {
- putInt(str.length);
- putRawBytes(str);
- }
-
- public void putMPInt(BigInteger bi) {
- putMPInt(bi.toByteArray());
- }
-
- public void putMPInt(byte[] foo) {
- int i = foo.length;
- if ((foo[0] & 0x80) != 0) {
- i++;
- putInt(i);
- putByte((byte)0);
- } else {
- putInt(i);
- }
- putRawBytes(foo);
- }
-
- public void putRawBytes(byte[] d) {
- putRawBytes(d, 0, d.length);
- }
-
- public void putRawBytes(byte[] d, int off, int len) {
- ensureCapacity(len);
- System.arraycopy(d, off, data, wpos, len);
- wpos += len;
- }
-
- public void putPublicKey(PublicKey key) {
- int ow = wpos;
- putInt(0);
- int ow1 = wpos;
- putRawPublicKey(key);
- int ow2 = wpos;
- wpos = ow;
- putInt(ow2 - ow1);
- wpos = ow2;
- }
-
- public void putRawPublicKey(PublicKey key) {
- if (key instanceof RSAPublicKey) {
- putString(KeyPairProvider.SSH_RSA);
- putMPInt(((RSAPublicKey) key).getPublicExponent());
- putMPInt(((RSAPublicKey) key).getModulus());
- } else if (key instanceof DSAPublicKey) {
- putString(KeyPairProvider.SSH_DSS);
- putMPInt(((DSAPublicKey) key).getParams().getP());
- putMPInt(((DSAPublicKey) key).getParams().getQ());
- putMPInt(((DSAPublicKey) key).getParams().getG());
- putMPInt(((DSAPublicKey) key).getY());
- } else if (key instanceof ECPublicKey) {
- ECPublicKey ecKey = (ECPublicKey) key;
- ECParameterSpec ecParams = ecKey.getParams();
- String curveName = ECCurves.getCurveName(ecParams);
- putString(ECCurves.ECDSA_SHA2_PREFIX + curveName);
- putString(curveName);
- putBytes(ECCurves.encodeECPoint(ecKey.getW(), ecParams.getCurve()));
- } else {
- throw new IllegalStateException("Unsupported algorithm: " + key.getAlgorithm());
- }
- }
-
- public void putKeyPair(KeyPair key) {
- if (key.getPrivate() instanceof RSAPrivateCrtKey) {
- putString(KeyPairProvider.SSH_RSA);
- putMPInt(((RSAPublicKey) key.getPublic()).getPublicExponent());
- putMPInt(((RSAPublicKey) key.getPublic()).getModulus());
- putMPInt(((RSAPrivateCrtKey) key.getPrivate()).getPrivateExponent());
- putMPInt(((RSAPrivateCrtKey) key.getPrivate()).getCrtCoefficient());
- putMPInt(((RSAPrivateCrtKey) key.getPrivate()).getPrimeQ());
- putMPInt(((RSAPrivateCrtKey) key.getPrivate()).getPrimeP());
- } else if (key.getPublic() instanceof DSAPublicKey) {
- putString(KeyPairProvider.SSH_DSS);
- putMPInt(((DSAPublicKey) key.getPublic()).getParams().getP());
- putMPInt(((DSAPublicKey) key.getPublic()).getParams().getQ());
- putMPInt(((DSAPublicKey) key.getPublic()).getParams().getG());
- putMPInt(((DSAPublicKey) key.getPublic()).getY());
- putMPInt(((DSAPrivateKey) key.getPrivate()).getX());
- } else if (key.getPublic() instanceof ECPublicKey) {
- ECPublicKey ecPub = (ECPublicKey) key.getPublic();
- ECPrivateKey ecPriv = (ECPrivateKey) key.getPrivate();
- ECParameterSpec ecParams = ecPub.getParams();
- String curveName = ECCurves.getCurveName(ecParams);
-
- putString(ECCurves.ECDSA_SHA2_PREFIX + curveName);
- putString(curveName);
- putString(ECCurves.encodeECPoint(ecPub.getW(), ecParams.getCurve()));
- putMPInt(ecPriv.getS());
- } else {
- throw new IllegalStateException("Unsupported algorithm: " + key.getPublic().getAlgorithm());
- }
- }
-
- private void ensureCapacity(int capacity) {
- if (data.length - wpos < capacity) {
- int cw = wpos + capacity;
- byte[] tmp = new byte[getNextPowerOf2(cw)];
- System.arraycopy(data, 0, tmp, 0, data.length);
- data = tmp;
- }
- }
-
- public static class BufferException extends RuntimeException {
- public BufferException(String message) {
- super(message);
- }
- }
-
- private static int getNextPowerOf2(int i) {
- int j = 1;
- while (j < i) {
- j <<= 1;
- }
- return j;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/util/BufferUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/BufferUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/BufferUtils.java
deleted file mode 100644
index dde95e6..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/BufferUtils.java
+++ /dev/null
@@ -1,73 +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.util;
-
-/**
- * TODO Add javadoc
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class BufferUtils {
-
- public static String printHex(byte[] array) {
- return printHex(array, 0, array.length);
- }
-
- public static String printHex(byte[] array, int offset, int len) {
- return printHex(array, offset, len, ' ');
- }
-
- public static String printHex(byte[] array, int offset, int len, char sep) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < len; i++) {
- byte b = array[offset + i];
- if (sb.length() > 0) {
- sb.append(sep);
- }
- sb.append(digits[(b >> 4) & 0x0F]);
- sb.append(digits[b & 0x0F]);
- }
- return sb.toString();
- }
-
- public static boolean equals(byte[] a1, byte[] a2) {
- if (a1.length != a2.length) {
- return false;
- }
- return equals(a1, 0, a2, 0, a1.length);
- }
-
- public static boolean equals(byte[] a1, int a1Offset, byte[] a2, int a2Offset, int length) {
- if (a1.length < a1Offset + length || a2.length < a2Offset + length) {
- return false;
- }
- while (length-- > 0) {
- if (a1[a1Offset++] != a2[a2Offset++]) {
- return false;
- }
- }
- return true;
- }
-
- final static char[] digits = {
- '0' , '1' , '2' , '3' , '4' , '5' ,
- '6' , '7' , '8' , '9' , 'a' , 'b' ,
- 'c' , 'd' , 'e' , 'f'
- };
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java
index ebc600a..0fad1b7 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java
@@ -36,6 +36,7 @@ import java.util.TreeSet;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class GenericUtils {
+ public static final byte[] EMPTY_BYTE_ARRAY={ };
public static final String[] EMPTY_STRING_ARRAY={ };
public static final Object[] EMPTY_OBJECT_ARRAY={ };
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/util/KeyUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/KeyUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/KeyUtils.java
index 6c7800a..d86c024 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/KeyUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/KeyUtils.java
@@ -30,6 +30,9 @@ import org.apache.sshd.common.Digest;
import org.apache.sshd.common.KeyPairProvider;
import org.apache.sshd.common.cipher.ECCurves;
import org.apache.sshd.common.digest.BuiltinDigests;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.BufferUtils;
+import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
/**
* Utility class for keys
@@ -46,7 +49,7 @@ public class KeyUtils {
*/
public static String getFingerPrint(PublicKey key) {
try {
- Buffer buffer = new Buffer();
+ Buffer buffer = new ByteArrayBuffer();
buffer.putRawPublicKey(key);
Digest md5 = BuiltinDigests.md5.create();
md5.init();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java
new file mode 100644
index 0000000..93d006c
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java
@@ -0,0 +1,489 @@
+/*
+ * 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.util.buffer;
+
+import java.math.BigInteger;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.security.GeneralSecurityException;
+import java.security.KeyFactory;
+import java.security.KeyPair;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.interfaces.DSAParams;
+import java.security.interfaces.DSAPrivateKey;
+import java.security.interfaces.DSAPublicKey;
+import java.security.interfaces.ECPrivateKey;
+import java.security.interfaces.ECPublicKey;
+import java.security.interfaces.RSAPrivateCrtKey;
+import java.security.interfaces.RSAPublicKey;
+import java.security.spec.DSAPrivateKeySpec;
+import java.security.spec.DSAPublicKeySpec;
+import java.security.spec.ECParameterSpec;
+import java.security.spec.ECPoint;
+import java.security.spec.ECPrivateKeySpec;
+import java.security.spec.ECPublicKeySpec;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.RSAPrivateCrtKeySpec;
+import java.security.spec.RSAPublicKeySpec;
+
+import org.apache.sshd.common.KeyPairProvider;
+import org.apache.sshd.common.SshException;
+import org.apache.sshd.common.cipher.ECCurves;
+import org.apache.sshd.common.util.GenericUtils;
+import org.apache.sshd.common.util.Readable;
+import org.apache.sshd.common.util.SecurityUtils;
+
+/**
+ * Provides an abstract message buffer for encoding SSH messages
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public abstract class Buffer implements Readable {
+
+ // TODO use Long.BYTES in JDK-8
+ protected final byte[] workBuf = new byte[Long.SIZE / Byte.SIZE];
+
+ protected Buffer() {
+ super();
+ }
+
+ /*======================
+ Global methods
+ ======================*/
+
+ public abstract int rpos();
+ public abstract void rpos(int rpos);
+
+ public abstract int wpos();
+
+ public abstract void wpos(int wpos);
+
+ public abstract int capacity();
+ public abstract byte[] array();
+
+ public abstract void compact();
+
+ public byte[] getCompactData() {
+ int l = available();
+ if (l > 0) {
+ byte[] b = new byte[l];
+ System.arraycopy(array(), rpos(), b, 0, l);
+ return b;
+ } else {
+ return GenericUtils.EMPTY_BYTE_ARRAY;
+ }
+ }
+
+ public abstract void clear();
+
+ public String printHex() {
+ return BufferUtils.printHex(array(), rpos(), available());
+ }
+
+ /*======================
+ Read methods
+ ======================*/
+
+ public byte getByte() {
+ // TODO use Byte.BYTES for JDK-8
+ ensureAvailable(Byte.SIZE / Byte.SIZE);
+ getRawBytes(workBuf, 0, Byte.SIZE / Byte.SIZE);
+ return workBuf[0];
+ }
+
+ public int getInt() {
+ return (int) getUInt();
+ }
+
+ public long getUInt() {
+ // TODO use Integer.BYTES for JDK-8
+ ensureAvailable(Integer.SIZE / Byte.SIZE);
+ getRawBytes(workBuf, 0, Integer.SIZE / Byte.SIZE);
+ long l = ((workBuf[0] << 24) & 0xff000000L)|
+ ((workBuf[1] << 16) & 0x00ff0000L)|
+ ((workBuf[2] << 8) & 0x0000ff00L)|
+ ((workBuf[3] ) & 0x000000ffL);
+ return l;
+ }
+
+ public long getLong() {
+ // TODO use Long.BYTES for JDK-8
+ ensureAvailable(Long.SIZE / Byte.SIZE);
+ getRawBytes(workBuf, 0, Long.SIZE / Byte.SIZE);
+ @SuppressWarnings("cast")
+ long l = (((long) workBuf[0] << 56) & 0xff00000000000000L)|
+ (((long) workBuf[1] << 48) & 0x00ff000000000000L)|
+ (((long) workBuf[2] << 40) & 0x0000ff0000000000L)|
+ (((long) workBuf[3] << 32) & 0x000000ff00000000L)|
+ (((long) workBuf[4] << 24) & 0x00000000ff000000L)|
+ (((long) workBuf[5] << 16) & 0x0000000000ff0000L)|
+ (((long) workBuf[6] << 8) & 0x000000000000ff00L)|
+ (((long) workBuf[7] ) & 0x00000000000000ffL);
+ return l;
+ }
+
+ public boolean getBoolean() {
+ return getByte() != 0;
+ }
+
+ public String getString() {
+ return getString(StandardCharsets.UTF_8);
+ }
+
+ public abstract String getString(Charset charset);
+
+ public byte[] getStringAsBytes() {
+ return getBytes();
+ }
+
+ public BigInteger getMPInt() {
+ return new BigInteger(getMPIntAsBytes());
+ }
+
+ public byte[] getMPIntAsBytes() {
+ return getBytes();
+ }
+
+ public byte[] getBytes() {
+ int len = getInt();
+ if (len < 0) {
+ throw new BufferException("Bad item length: " + len);
+ }
+ ensureAvailable(len);
+ byte[] b = new byte[len];
+ getRawBytes(b);
+ return b;
+ }
+
+ public void getRawBytes(byte[] buf) {
+ getRawBytes(buf, 0, buf.length);
+ }
+
+ public PublicKey getPublicKey() throws SshException {
+ int ow = wpos();
+ int len = getInt();
+ wpos(rpos() + len);
+ try {
+ return getRawPublicKey();
+ } finally {
+ wpos(ow);
+ }
+ }
+
+ public PublicKey getRawPublicKey() throws SshException {
+ try {
+ PublicKey key;
+ String keyAlg = getString();
+ if (KeyPairProvider.SSH_RSA.equals(keyAlg)) {
+ BigInteger e = getMPInt();
+ BigInteger n = getMPInt();
+ KeyFactory keyFactory = SecurityUtils.getKeyFactory("RSA");
+ key = keyFactory.generatePublic(new RSAPublicKeySpec(n, e));
+ } else if (KeyPairProvider.SSH_DSS.equals(keyAlg)) {
+ BigInteger p = getMPInt();
+ BigInteger q = getMPInt();
+ BigInteger g = getMPInt();
+ BigInteger y = getMPInt();
+ KeyFactory keyFactory = SecurityUtils.getKeyFactory("DSA");
+ key = keyFactory.generatePublic(new DSAPublicKeySpec(y, p, q, g));
+ } else if (KeyPairProvider.ECDSA_SHA2_NISTP256.equals(keyAlg)) {
+ key = getRawECKey("nistp256", ECCurves.EllipticCurves.nistp256);
+ } else if (KeyPairProvider.ECDSA_SHA2_NISTP384.equals(keyAlg)) {
+ key = getRawECKey("nistp384", ECCurves.EllipticCurves.nistp384);
+ } else if (KeyPairProvider.ECDSA_SHA2_NISTP521.equals(keyAlg)) {
+ key = getRawECKey("nistp521", ECCurves.EllipticCurves.nistp521);
+ } else {
+ throw new NoSuchAlgorithmException("Unsupported raw public algorithm: " + keyAlg);
+ }
+ return key;
+ } catch (GeneralSecurityException e) {
+ throw new SshException(e);
+ }
+ }
+
+ protected PublicKey getRawECKey(String expectedCurve, ECParameterSpec spec) throws GeneralSecurityException, SshException {
+ String curveName = getString();
+ if (!expectedCurve.equals(curveName)) {
+ throw new InvalidKeySpecException("Curve name does not match expected: " + curveName + " vs "
+ + expectedCurve);
+ }
+ ECPoint w = ECCurves.decodeECPoint(getStringAsBytes(), spec.getCurve());
+ KeyFactory keyFactory = SecurityUtils.getKeyFactory("EC");
+ return keyFactory.generatePublic(new ECPublicKeySpec(w, spec));
+ }
+
+ public KeyPair getKeyPair() throws SshException {
+ try {
+ PublicKey pub;
+ PrivateKey prv;
+ String keyAlg = getString();
+ if (KeyPairProvider.SSH_RSA.equals(keyAlg)) {
+ BigInteger e = getMPInt();
+ BigInteger n = getMPInt();
+ BigInteger d = getMPInt();
+ BigInteger qInv = getMPInt();
+ BigInteger q = getMPInt();
+ BigInteger p = getMPInt();
+ BigInteger dP = d.remainder(p.subtract(BigInteger.valueOf(1)));
+ BigInteger dQ = d.remainder(q.subtract(BigInteger.valueOf(1)));
+ KeyFactory keyFactory = SecurityUtils.getKeyFactory("RSA");
+ pub = keyFactory.generatePublic(new RSAPublicKeySpec(n, e));
+ prv = keyFactory.generatePrivate(new RSAPrivateCrtKeySpec(n, e, d, p, q, dP, dQ, qInv));
+ } else if (KeyPairProvider.SSH_DSS.equals(keyAlg)) {
+ BigInteger p = getMPInt();
+ BigInteger q = getMPInt();
+ BigInteger g = getMPInt();
+ BigInteger y = getMPInt();
+ BigInteger x = getMPInt();
+ KeyFactory keyFactory = SecurityUtils.getKeyFactory("DSA");
+ pub = keyFactory.generatePublic(new DSAPublicKeySpec(y, p, q, g));
+ prv = keyFactory.generatePrivate(new DSAPrivateKeySpec(x, p, q, g));
+ } else if (KeyPairProvider.ECDSA_SHA2_NISTP256.equals(keyAlg)) {
+ return extractEC("nistp256", ECCurves.EllipticCurves.nistp256);
+ } else if (KeyPairProvider.ECDSA_SHA2_NISTP384.equals(keyAlg)) {
+ return extractEC("nistp384", ECCurves.EllipticCurves.nistp384);
+ } else if (KeyPairProvider.ECDSA_SHA2_NISTP521.equals(keyAlg)) {
+ return extractEC("nistp521", ECCurves.EllipticCurves.nistp521);
+ } else {
+ throw new NoSuchAlgorithmException("Unsupported key pair algorithm: " + keyAlg);
+ }
+ return new KeyPair(pub, prv);
+ } catch (GeneralSecurityException e) {
+ throw new SshException(e);
+ }
+ }
+
+ protected KeyPair extractEC(String expectedCurveName, ECParameterSpec spec) throws GeneralSecurityException, SshException {
+ String curveName = getString();
+ byte[] groupBytes = getStringAsBytes();
+ BigInteger exponent = getMPInt();
+
+ if (!expectedCurveName.equals(curveName)) {
+ throw new SshException("Expected curve " + expectedCurveName + " but was " + curveName);
+ }
+
+ ECPoint group = ECCurves.decodeECPoint(groupBytes, spec.getCurve());
+ if (group == null) {
+ throw new InvalidKeySpecException("Couldn't decode EC group");
+ }
+
+ KeyFactory keyFactory = SecurityUtils.getKeyFactory("EC");
+ PublicKey pubKey = keyFactory.generatePublic(new ECPublicKeySpec(group, spec));
+ PrivateKey privKey = keyFactory.generatePrivate(new ECPrivateKeySpec(exponent, spec));
+ return new KeyPair(pubKey, privKey);
+ }
+
+ public void ensureAvailable(int a) throws BufferException {
+ if (available() < a) {
+ throw new BufferException("Underflow");
+ }
+ }
+
+ /*======================
+ Write methods
+ ======================*/
+
+ public void putByte(byte b) {
+ // TODO use Byte.BYTES in JDK-8
+ ensureCapacity(Byte.SIZE / Byte.SIZE);
+ workBuf[0] = b;
+ putRawBytes(workBuf, 0, Byte.SIZE / Byte.SIZE);
+ }
+
+ public void putBuffer(Readable buffer) {
+ putBuffer(buffer, true);
+ }
+
+ public abstract int putBuffer(Readable buffer, boolean expand);
+
+ /**
+ * Writes 16 bits
+ * @param i
+ */
+ public void putShort(int i) {
+ // TODO use Short.BYTES for JDK-8
+ ensureCapacity(Short.SIZE / Byte.SIZE);
+ workBuf[0] = (byte) (i >> 8);
+ workBuf[1] = (byte) (i );
+ putRawBytes(workBuf, 0, Short.SIZE / Byte.SIZE);
+ }
+
+ /**
+ * Writes 32 bits
+ * @param i
+ */
+ public void putInt(long i) {
+ // TODO use Integer.BYTES for JDK-8
+ ensureCapacity(Integer.SIZE / Byte.SIZE);
+ workBuf[0] = (byte) (i >> 24);
+ workBuf[1] = (byte) (i >> 16);
+ workBuf[2] = (byte) (i >> 8);
+ workBuf[3] = (byte) (i );
+ putRawBytes(workBuf, 0, Integer.SIZE / Byte.SIZE);
+ }
+
+ /**
+ * Writes 64 bits
+ * @param i
+ */
+ public void putLong(long i) {
+ // TODO use Long.BYTES for JDK-8
+ ensureCapacity(Long.SIZE / Byte.SIZE);
+ workBuf[0] = (byte) (i >> 56);
+ workBuf[1] = (byte) (i >> 48);
+ workBuf[2] = (byte) (i >> 40);
+ workBuf[3] = (byte) (i >> 32);
+ workBuf[4] = (byte) (i >> 24);
+ workBuf[5] = (byte) (i >> 16);
+ workBuf[6] = (byte) (i >> 8);
+ workBuf[7] = (byte) (i );
+ putRawBytes(workBuf, 0, Long.SIZE / Byte.SIZE);
+ }
+
+ public void putBoolean(boolean b) {
+ putByte(b ? (byte) 1 : (byte) 0);
+ }
+
+ public void putBytes(byte[] b) {
+ putBytes(b, 0, b.length);
+ }
+
+ public void putBytes(byte[] b, int off, int len) {
+ putInt(len);
+ putRawBytes(b, off, len);
+ }
+
+ public void putString(String string) {
+ putString(string, StandardCharsets.UTF_8);
+ }
+
+ public void putString(String string, Charset charset) {
+ putBytes(string.getBytes(charset));
+ }
+
+ public void putMPInt(BigInteger bi) {
+ putMPInt(bi.toByteArray());
+ }
+
+ public void putMPInt(byte[] foo) {
+ int i = foo.length;
+ if ((foo[0] & 0x80) != 0) {
+ i++;
+ putInt(i);
+ putByte((byte)0);
+ } else {
+ putInt(i);
+ }
+ putRawBytes(foo);
+ }
+
+ public void putRawBytes(byte[] d) {
+ putRawBytes(d, 0, d.length);
+ }
+
+ public abstract void putRawBytes(byte[] d, int off, int len);
+
+ public void putPublicKey(PublicKey key) {
+ int ow = wpos();
+ putInt(0);
+ int ow1 = wpos();
+ putRawPublicKey(key);
+ int ow2 = wpos();
+ wpos(ow);
+ putInt(ow2 - ow1);
+ wpos(ow2);
+ }
+
+ public void putRawPublicKey(PublicKey key) {
+ if (key instanceof RSAPublicKey) {
+ RSAPublicKey rsaPub = (RSAPublicKey) key;
+
+ putString(KeyPairProvider.SSH_RSA);
+ putMPInt(rsaPub.getPublicExponent());
+ putMPInt(rsaPub.getModulus());
+ } else if (key instanceof DSAPublicKey) {
+ DSAPublicKey dsaPub = (DSAPublicKey) key;
+ DSAParams dsaParams = dsaPub.getParams();
+
+ putString(KeyPairProvider.SSH_DSS);
+ putMPInt(dsaParams.getP());
+ putMPInt(dsaParams.getQ());
+ putMPInt(dsaParams.getG());
+ putMPInt(dsaPub.getY());
+ } else if (key instanceof ECPublicKey) {
+ ECPublicKey ecKey = (ECPublicKey) key;
+ ECParameterSpec ecParams = ecKey.getParams();
+ String curveName = ECCurves.getCurveName(ecParams);
+ putString(ECCurves.ECDSA_SHA2_PREFIX + curveName);
+ putString(curveName);
+ putBytes(ECCurves.encodeECPoint(ecKey.getW(), ecParams.getCurve()));
+ } else {
+ throw new BufferException("Unsupported raw public key algorithm: " + key.getAlgorithm());
+ }
+ }
+
+ public void putKeyPair(KeyPair kp) {
+ PublicKey pubKey = kp.getPublic();
+ PrivateKey prvKey = kp.getPrivate();
+ if (prvKey instanceof RSAPrivateCrtKey) {
+ RSAPublicKey rsaPub = (RSAPublicKey) pubKey;
+ RSAPrivateCrtKey rsaPrv = (RSAPrivateCrtKey) prvKey;
+
+ putString(KeyPairProvider.SSH_RSA);
+ putMPInt(rsaPub.getPublicExponent());
+ putMPInt(rsaPub.getModulus());
+ putMPInt(rsaPrv.getPrivateExponent());
+ putMPInt(rsaPrv.getCrtCoefficient());
+ putMPInt(rsaPrv.getPrimeQ());
+ putMPInt(rsaPrv.getPrimeP());
+ } else if (pubKey instanceof DSAPublicKey) {
+ DSAPublicKey dsaPub = (DSAPublicKey) pubKey;
+ DSAParams dsaParams = dsaPub.getParams();
+ DSAPrivateKey dsaPrv = (DSAPrivateKey) prvKey;
+
+ putString(KeyPairProvider.SSH_DSS);
+ putMPInt(dsaParams.getP());
+ putMPInt(dsaParams.getQ());
+ putMPInt(dsaParams.getG());
+ putMPInt(dsaPub.getY());
+ putMPInt(dsaPrv.getX());
+ } else if (pubKey instanceof ECPublicKey) {
+ ECPublicKey ecPub = (ECPublicKey) pubKey;
+ ECPrivateKey ecPriv = (ECPrivateKey) prvKey;
+ ECParameterSpec ecParams = ecPub.getParams();
+ String curveName = ECCurves.getCurveName(ecParams);
+
+ putString(ECCurves.ECDSA_SHA2_PREFIX + curveName);
+ putString(curveName);
+ putBytes(ECCurves.encodeECPoint(ecPub.getW(), ecParams.getCurve()));
+ putMPInt(ecPriv.getS());
+ } else {
+ throw new BufferException("Unsupported key pair algorithm: " + kp.getPublic().getAlgorithm());
+ }
+ }
+
+ protected abstract void ensureCapacity(int capacity);
+ protected abstract int size();
+
+ @Override
+ public String toString() {
+ return "Buffer [rpos=" + rpos() + ", wpos=" + wpos() + ", size=" + size() + "]";
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9f0bb1bc/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/BufferException.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/BufferException.java b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/BufferException.java
new file mode 100644
index 0000000..e8d298d
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/BufferException.java
@@ -0,0 +1,30 @@
+/*
+ * 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.util.buffer;
+
+/**
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public class BufferException extends RuntimeException {
+ private static final long serialVersionUID = 658645233475011039L;
+
+ public BufferException(String message) {
+ super(message);
+ }
+}
\ No newline at end of file