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/12/07 08:30:03 UTC
[1/7] mina-sshd git commit: Process exceptions caught in
AbstractSession also if session is currently being gracefully closed
Repository: mina-sshd
Updated Branches:
refs/heads/master 799f1cca4 -> 6f956abf4
Process exceptions caught in AbstractSession also if session is currently being gracefully closed
* Related to SSHD-595
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/cab835ab
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/cab835ab
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/cab835ab
Branch: refs/heads/master
Commit: cab835ab757151c3f73f04970efccbfc615aa479
Parents: 799f1cc
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Mon Dec 7 08:16:48 2015 +0200
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Mon Dec 7 08:16:48 2015 +0200
----------------------------------------------------------------------
.../sshd/common/session/AbstractSession.java | 57 +++++++++++++++-----
.../util/closeable/AbstractCloseable.java | 28 +++++++---
2 files changed, 64 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/cab835ab/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 b7559ec..4b32ba8 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
@@ -585,32 +585,42 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
/**
* Handle any exceptions that occurred on this session.
* The session will be closed and a disconnect packet will be
- * sent before if the given exception is an
- * {@link SshException}.
+ * sent before if the given exception is an {@link SshException}.
*
* @param t the exception to process
*/
@Override
public void exceptionCaught(Throwable t) {
- // Ignore exceptions that happen while closing
- synchronized (lock) {
- if (isClosing()) {
- return;
+ State curState = state.get();
+ // Ignore exceptions that happen while closing immediately
+ if ((!State.Opened.equals(curState)) && (!State.Graceful.equals(curState))) {
+ if (log.isDebugEnabled()) {
+ log.debug("exceptionCaught({}) ignore {} due to state={}, message={}",
+ this, t.getClass().getSimpleName(), curState, t.getMessage());
+ }
+ if (log.isTraceEnabled()) {
+ log.trace("exceptionCaught(" + this + ")[state=" + curState + "] ignored exception details", t);
}
+ return;
}
- log.warn("exceptionCaught({}) {}: {}", this, t.getClass().getSimpleName(), t.getMessage());
+
+ log.warn("exceptionCaught({})[state={}] {}: {}", this, curState, t.getClass().getSimpleName(), t.getMessage());
if (log.isDebugEnabled()) {
- log.debug("execeptionCaught(" + this + ") details", t);
+ log.debug("exceptionCaught(" + this + ")[state=" + curState + "] details", t);
}
- if (t instanceof SshException) {
+ if (State.Opened.equals(curState) && (t instanceof SshException)) {
int code = ((SshException) t).getDisconnectCode();
if (code > 0) {
try {
disconnect(code, t.getMessage());
} catch (Throwable t2) {
if (log.isDebugEnabled()) {
- log.debug("Exception while disconnect with code=" + code, t2);
+ log.debug("exceptionCaught({}) {} while disconnect with code={}: {}",
+ this, t2.getClass().getSimpleName(), SshConstants.getDisconnectReasonName(code), t2.getMessage());
+ }
+ if (log.isTraceEnabled()) {
+ log.trace("exceptionCaught(" + this + ")[code=" + SshConstants.getDisconnectReasonName(code) + "] disconnect exception details", t2);
}
}
return;
@@ -647,9 +657,9 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
listener.sessionClosed(this);
} catch (RuntimeException t) {
Throwable e = GenericUtils.peelException(t);
- log.warn(e.getClass().getSimpleName() + " while signal session " + toString() + " closed: " + e.getMessage());
+ log.warn("preClose({}) {} while signal session closed: {}", this, e.getClass().getSimpleName(), e.getMessage());
if (log.isDebugEnabled()) {
- log.debug("preClose exception details", e);
+ log.debug("preClose(" + this + ") signal session closed exception details", e);
}
} finally {
// clear the listeners since we are closing the session (quicker GC)
@@ -1352,7 +1362,7 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
}
@Override
- public void disconnect(int reason, String msg) throws IOException {
+ public void disconnect(final int reason, final String msg) throws IOException {
log.info("Disconnecting({}): {} - {}", this, SshConstants.getDisconnectReasonName(reason), msg);
Buffer buffer = createBuffer(SshConstants.SSH_MSG_DISCONNECT, msg.length() + Short.SIZE);
buffer.putInt(reason);
@@ -1363,7 +1373,26 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
long disconnectTimeoutMs = PropertyResolverUtils.getLongProperty(this, FactoryManager.DISCONNECT_TIMEOUT, FactoryManager.DEFAULT_DISCONNECT_TIMEOUT);
writePacket(buffer, disconnectTimeoutMs, TimeUnit.MILLISECONDS).addListener(new SshFutureListener<IoWriteFuture>() {
@Override
+ @SuppressWarnings("synthetic-access")
public void operationComplete(IoWriteFuture future) {
+ Throwable t = future.getException();
+ if (log.isDebugEnabled()) {
+ if (t == null) {
+ log.debug("disconnect({}) operation successfully completed for reason={} [{}]",
+ AbstractSession.this, SshConstants.getDisconnectReasonName(reason), msg);
+ } else {
+ log.debug("disconnect({}) operation failed ({}) for reason={} [{}]: {}",
+ AbstractSession.this, t.getClass().getSimpleName(),
+ SshConstants.getDisconnectReasonName(reason), msg, t.getMessage());
+ }
+ }
+
+ if (t != null) {
+ if (log.isTraceEnabled()) {
+ log.trace("disconnect(" + AbstractSession.this + ") reason=" + SshConstants.getDisconnectReasonName(reason)+ " failure details", t);
+ }
+ }
+
close(true);
}
});
@@ -1593,7 +1622,7 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
}
}
- return ValidateUtils.checkNotNull(kexFutureHolder.get(), "No current KEX future");
+ return ValidateUtils.checkNotNull(kexFutureHolder.get(), "No current KEX future on state=%s", kexState.get());
}
protected void checkRekey() throws IOException {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/cab835ab/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/AbstractCloseable.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/AbstractCloseable.java b/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/AbstractCloseable.java
index a86abaa..e32cf3d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/AbstractCloseable.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/AbstractCloseable.java
@@ -62,16 +62,24 @@ public abstract class AbstractCloseable extends IoBaseCloseable {
if (immediately) {
if (state.compareAndSet(State.Opened, State.Immediate)
|| state.compareAndSet(State.Graceful, State.Immediate)) {
- log.debug("Closing {} immediately", this);
+ if (log.isDebugEnabled()) {
+ log.debug("close({}) Closing immediately", this);
+ }
preClose();
doCloseImmediately();
- log.debug("{} closed", this);
+ if (log.isDebugEnabled()) {
+ log.debug("close({})[Immediately] closed", this);
+ }
} else {
- log.debug("{} is already {}", this, state.get() == State.Closed ? "closed" : "closing");
+ if (log.isDebugEnabled()) {
+ log.debug("close({})[Immediately] state already {}", this, state.get());
+ }
}
} else {
if (state.compareAndSet(State.Opened, State.Graceful)) {
- log.debug("Closing {} gracefully", this);
+ if (log.isDebugEnabled()) {
+ log.debug("close({}) Closing gracefully", this);
+ }
preClose();
SshFuture<CloseFuture> grace = doCloseGracefully();
if (grace != null) {
@@ -81,18 +89,24 @@ public abstract class AbstractCloseable extends IoBaseCloseable {
public void operationComplete(CloseFuture future) {
if (state.compareAndSet(State.Graceful, State.Immediate)) {
doCloseImmediately();
- log.debug("{} closed", AbstractCloseable.this);
+ if (log.isDebugEnabled()) {
+ log.debug("close({}][Graceful] - operationComplete() closed", AbstractCloseable.this);
+ }
}
}
});
} else {
if (state.compareAndSet(State.Graceful, State.Immediate)) {
doCloseImmediately();
- log.debug("{} closed", this);
+ if (log.isDebugEnabled()) {
+ log.debug("close({})[Graceful] closed", this);
+ }
}
}
} else {
- log.debug("{} is already {}", this, state.get() == State.Closed ? "closed" : "closing");
+ if (log.isDebugEnabled()) {
+ log.debug("close({})[Graceful] state already {}", this, state.get());
+ }
}
}
return closeFuture;
[5/7] mina-sshd git commit: Added RC4 ciphers to CipherTest
Posted by lg...@apache.org.
Added RC4 ciphers to CipherTest
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/f135b61c
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/f135b61c
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/f135b61c
Branch: refs/heads/master
Commit: f135b61cd98b8f892fa90737ea5809e41e8e151d
Parents: f7ca304
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Mon Dec 7 09:05:51 2015 +0200
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Mon Dec 7 09:05:51 2015 +0200
----------------------------------------------------------------------
.../src/test/java/org/apache/sshd/common/cipher/CipherTest.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f135b61c/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java
index 8c561dc..873a931 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java
@@ -66,7 +66,9 @@ public class CipherTest extends BaseTestSupport {
new Object[]{BuiltinCiphers.tripledescbc, com.jcraft.jsch.jce.TripleDESCBC.class, NUM_LOADTEST_ROUNDS},
new Object[]{BuiltinCiphers.blowfishcbc, com.jcraft.jsch.jce.BlowfishCBC.class, NUM_LOADTEST_ROUNDS},
new Object[]{BuiltinCiphers.aes192cbc, com.jcraft.jsch.jce.AES192CBC.class, NUM_LOADTEST_ROUNDS},
- new Object[]{BuiltinCiphers.aes256cbc, com.jcraft.jsch.jce.AES256CBC.class, NUM_LOADTEST_ROUNDS}
+ new Object[]{BuiltinCiphers.aes256cbc, com.jcraft.jsch.jce.AES256CBC.class, NUM_LOADTEST_ROUNDS},
+ new Object[]{BuiltinCiphers.arcfour128, com.jcraft.jsch.jce.ARCFOUR128.class, NUM_LOADTEST_ROUNDS},
+ new Object[]{BuiltinCiphers.arcfour256, com.jcraft.jsch.jce.ARCFOUR256.class, NUM_LOADTEST_ROUNDS}
));
@SuppressWarnings("synthetic-access")
[7/7] mina-sshd git commit: Removed un-necessart @SuppressWarning
Posted by lg...@apache.org.
Removed un-necessart @SuppressWarning
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/6f956abf
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/6f956abf
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/6f956abf
Branch: refs/heads/master
Commit: 6f956abf4a052c80610df976c5520f85ab2f91f9
Parents: 7c0f681
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Mon Dec 7 09:25:41 2015 +0200
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Mon Dec 7 09:25:41 2015 +0200
----------------------------------------------------------------------
.../main/java/org/apache/sshd/common/util/closeable/Builder.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6f956abf/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/Builder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/Builder.java b/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/Builder.java
index d857ec0..58c8819 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/Builder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/Builder.java
@@ -63,7 +63,7 @@ public final class Builder implements ObjectBuilder<Closeable> {
@SuppressWarnings("rawtypes")
@SafeVarargs
- public final <T extends SshFuture> Builder when(@SuppressWarnings("unchecked") SshFuture<T>... futures) {
+ public final <T extends SshFuture> Builder when(SshFuture<T>... futures) {
return when(Arrays.asList(futures));
}
[2/7] mina-sshd git commit: Expose
ConnectionService#isAllowMoreSessions method
Posted by lg...@apache.org.
Expose ConnectionService#isAllowMoreSessions method
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/1d265b7d
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/1d265b7d
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/1d265b7d
Branch: refs/heads/master
Commit: 1d265b7d6aa02852663902dc19f369e85e9b7872
Parents: cab835a
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Mon Dec 7 08:17:28 2015 +0200
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Mon Dec 7 08:17:28 2015 +0200
----------------------------------------------------------------------
.../session/AbstractConnectionService.java | 35 ++++++++++++++------
.../sshd/common/session/ConnectionService.java | 1 +
2 files changed, 25 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/1d265b7d/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 1cd68e4..90f0a6a 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
@@ -23,6 +23,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.sshd.agent.common.AgentForwardSupport;
@@ -84,7 +85,7 @@ public abstract class AbstractConnectionService extends AbstractInnerCloseable i
protected final TcpipForwarder tcpipForwarder;
protected final AgentForwardSupport agentForward;
protected final X11ForwardSupport x11Forward;
- protected boolean allowMoreSessions = true;
+ private final AtomicBoolean allowMoreSessions = new AtomicBoolean(true);
protected AbstractConnectionService(Session session) {
ValidateUtils.checkTrue(session instanceof AbstractSession, "Not an AbstractSession");
@@ -162,7 +163,10 @@ public abstract class AbstractConnectionService extends AbstractInnerCloseable i
*/
@Override
public void unregisterChannel(Channel channel) {
- channels.remove(channel.getId());
+ Channel result = channels.remove(channel.getId());
+ if (log.isDebugEnabled()) {
+ log.debug("unregisterChannel({}) result={}", channel, result);
+ }
}
@Override
@@ -208,21 +212,29 @@ public abstract class AbstractConnectionService extends AbstractInnerCloseable i
requestFailure(buffer);
break;
default:
- throw new IllegalStateException("Unsupported command: " + cmd);
+ throw new IllegalStateException("Unsupported command: " + SshConstants.getCommandMessageName(cmd));
}
}
@Override
+ public boolean isAllowMoreSessions() {
+ return allowMoreSessions.get();
+ }
+
+ @Override
public void setAllowMoreSessions(boolean allow) {
- allowMoreSessions = allow;
+ if (log.isDebugEnabled()) {
+ log.debug("setAllowMoreSessions({}): {}", this, allow);
+ }
+ allowMoreSessions.set(allow);
}
public void channelOpenConfirmation(Buffer buffer) throws IOException {
Channel channel = getChannel(buffer);
+ int recipient = buffer.getInt();
if (log.isDebugEnabled()) {
- log.debug("Received SSH_MSG_CHANNEL_OPEN_CONFIRMATION on channel {}", Integer.valueOf(channel.getId()));
+ log.debug("channelOpenConfirmation({}) Received SSH_MSG_CHANNEL_OPEN_CONFIRMATION recipient=", channel, recipient);
}
- int recipient = buffer.getInt();
int rwsize = buffer.getInt();
int rmpsize = buffer.getInt();
channel.handleOpenSuccess(recipient, rwsize, rmpsize, buffer);
@@ -232,7 +244,7 @@ public abstract class AbstractConnectionService extends AbstractInnerCloseable i
AbstractClientChannel channel = (AbstractClientChannel) getChannel(buffer);
int id = channel.getId();
if (log.isDebugEnabled()) {
- log.debug("Received SSH_MSG_CHANNEL_OPEN_FAILURE on channel {}", id);
+ log.debug("channelOpenFailure({}) Received SSH_MSG_CHANNEL_OPEN_FAILURE", channel);
}
channels.remove(id);
channel.handleOpenFailure(buffer);
@@ -263,7 +275,7 @@ public abstract class AbstractConnectionService extends AbstractInnerCloseable i
/**
* Process a window adjust packet on a channel
*
- * @param buffer the buffer containing the window adjustement parameters
+ * @param buffer the buffer containing the window adjustment parameters
* @throws IOException if an error occurs
*/
public void channelWindowAdjust(Buffer buffer) throws IOException {
@@ -344,8 +356,9 @@ public abstract class AbstractConnectionService extends AbstractInnerCloseable i
final int id = buffer.getInt();
final int rwsize = buffer.getInt();
final int rmpsize = buffer.getInt();
-
- log.debug("Received SSH_MSG_CHANNEL_OPEN {}", type);
+ if (log.isDebugEnabled()) {
+ log.debug("Received SSH_MSG_CHANNEL_OPEN id={}, type={}", id, type);
+ }
if (isClosing()) {
Buffer buf = session.prepareBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN_FAILURE, BufferUtils.clear(buffer));
@@ -356,7 +369,7 @@ public abstract class AbstractConnectionService extends AbstractInnerCloseable i
session.writePacket(buf);
return;
}
- if (!allowMoreSessions) {
+ if (!isAllowMoreSessions()) {
Buffer buf = session.prepareBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN_FAILURE, BufferUtils.clear(buffer));
buf.putInt(id);
buf.putInt(SshConstants.SSH_OPEN_CONNECT_FAILED);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/1d265b7d/sshd-core/src/main/java/org/apache/sshd/common/session/ConnectionService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/ConnectionService.java b/sshd-core/src/main/java/org/apache/sshd/common/session/ConnectionService.java
index a0b3d3d..638c2d1 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/ConnectionService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/ConnectionService.java
@@ -59,5 +59,6 @@ public interface ConnectionService extends Service {
// TODO: remove from interface, it's server side only
String createX11Display(boolean singleConnection, String authenticationProtocol, String authenticationCookie, int screen) throws IOException;
+ boolean isAllowMoreSessions();
void setAllowMoreSessions(boolean allow);
}
[3/7] mina-sshd git commit: Make Random interface a NamedResource
Posted by lg...@apache.org.
Make Random interface a NamedResource
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/8403509d
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/8403509d
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/8403509d
Branch: refs/heads/master
Commit: 8403509d126b5fd9e6b29af6ed6b0f163b33a428
Parents: 1d265b7
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Mon Dec 7 08:50:56 2015 +0200
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Mon Dec 7 08:50:56 2015 +0200
----------------------------------------------------------------------
.../sshd/common/random/AbstractRandom.java | 5 ++
.../common/random/AbstractRandomFactory.java | 43 +++++++++++
.../apache/sshd/common/random/JceRandom.java | 16 ++--
.../sshd/common/random/JceRandomFactory.java | 12 +--
.../org/apache/sshd/common/random/Random.java | 4 +-
.../common/random/SingletonRandomFactory.java | 3 +-
.../apache/sshd/common/util/SecurityUtils.java | 41 +++++-----
.../sshd/common/random/RandomFactoryTest.java | 79 ++++++++++++++++++++
.../apache/sshd/common/random/RandomTest.java | 62 ---------------
9 files changed, 167 insertions(+), 98 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/8403509d/sshd-core/src/main/java/org/apache/sshd/common/random/AbstractRandom.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/random/AbstractRandom.java b/sshd-core/src/main/java/org/apache/sshd/common/random/AbstractRandom.java
index 4f3c080..8bb8df7 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/random/AbstractRandom.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/random/AbstractRandom.java
@@ -31,4 +31,9 @@ public abstract class AbstractRandom implements Random {
public void fill(byte[] bytes) {
fill(bytes, 0, bytes.length);
}
+
+ @Override
+ public String toString() {
+ return getName();
+ }
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/8403509d/sshd-core/src/main/java/org/apache/sshd/common/random/AbstractRandomFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/random/AbstractRandomFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/random/AbstractRandomFactory.java
new file mode 100644
index 0000000..c1d7893
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/common/random/AbstractRandomFactory.java
@@ -0,0 +1,43 @@
+/*
+ * 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.random;
+
+import org.apache.sshd.common.util.ValidateUtils;
+
+/**
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public abstract class AbstractRandomFactory implements RandomFactory {
+ private final String name;
+
+ protected AbstractRandomFactory(String name) {
+ this.name = ValidateUtils.checkNotNullAndNotEmpty(name, "No name");
+ }
+
+ @Override
+ public final String getName() {
+ return name;
+ }
+
+ @Override
+ public String toString() {
+ return getName();
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/8403509d/sshd-core/src/main/java/org/apache/sshd/common/random/JceRandom.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/random/JceRandom.java b/sshd-core/src/main/java/org/apache/sshd/common/random/JceRandom.java
index bed250f..ba050e6 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/random/JceRandom.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/random/JceRandom.java
@@ -26,6 +26,7 @@ import java.security.SecureRandom;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class JceRandom extends AbstractRandom {
+ public static final String NAME = "JCE";
private byte[] tmp = new byte[16];
private final SecureRandom random = new SecureRandom();
@@ -35,17 +36,20 @@ public class JceRandom extends AbstractRandom {
}
@Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
public synchronized void fill(byte[] foo, int start, int len) {
if ((start == 0) && (len == foo.length)) {
random.nextBytes(foo);
} else {
- synchronized (this) {
- if (len > tmp.length) {
- tmp = new byte[len];
- }
- random.nextBytes(tmp);
- System.arraycopy(tmp, 0, foo, start, len);
+ if (len > tmp.length) {
+ tmp = new byte[len];
}
+ random.nextBytes(tmp);
+ System.arraycopy(tmp, 0, foo, start, len);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/8403509d/sshd-core/src/main/java/org/apache/sshd/common/random/JceRandomFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/random/JceRandomFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/random/JceRandomFactory.java
index 6358d93..450a85e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/random/JceRandomFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/random/JceRandomFactory.java
@@ -20,18 +20,14 @@
package org.apache.sshd.common.random;
/**
- * Named factory for the BouncyCastle <code>Random</code>
+ * Named factory for the JCE <code>Random</code>
*/
-public class JceRandomFactory implements RandomFactory {
+public class JceRandomFactory extends AbstractRandomFactory {
+ public static final String NAME = "default";
public static final JceRandomFactory INSTANCE = new JceRandomFactory();
public JceRandomFactory() {
- super();
- }
-
- @Override
- public String getName() {
- return "default";
+ super(NAME);
}
@Override
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/8403509d/sshd-core/src/main/java/org/apache/sshd/common/random/Random.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/random/Random.java b/sshd-core/src/main/java/org/apache/sshd/common/random/Random.java
index 89e81c6..ab4eff8 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/random/Random.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/random/Random.java
@@ -18,12 +18,14 @@
*/
package org.apache.sshd.common.random;
+import org.apache.sshd.common.NamedResource;
+
/**
* A pseudo random number generator.
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public interface Random {
+public interface Random extends NamedResource {
/**
* Fill the buffer with random values
*
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/8403509d/sshd-core/src/main/java/org/apache/sshd/common/random/SingletonRandomFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/random/SingletonRandomFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/random/SingletonRandomFactory.java
index bbbb9cb..eb9e175 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/random/SingletonRandomFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/random/SingletonRandomFactory.java
@@ -20,6 +20,7 @@ package org.apache.sshd.common.random;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.OptionalFeature;
+import org.apache.sshd.common.util.ValidateUtils;
/**
* A random factory wrapper that uses a single random instance.
@@ -33,7 +34,7 @@ public class SingletonRandomFactory extends AbstractRandom implements RandomFact
private final Random random;
public SingletonRandomFactory(NamedFactory<Random> factory) {
- this.factory = factory;
+ this.factory = ValidateUtils.checkNotNull(factory, "No factory");
this.random = factory.create();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/8403509d/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
index 7e23452..9aa4751 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
@@ -46,6 +46,7 @@ import org.apache.sshd.common.config.keys.FilePasswordProvider;
import org.apache.sshd.common.keyprovider.AbstractClassLoadableResourceKeyPairProvider;
import org.apache.sshd.common.keyprovider.AbstractFileKeyPairProvider;
import org.apache.sshd.common.random.AbstractRandom;
+import org.apache.sshd.common.random.AbstractRandomFactory;
import org.apache.sshd.common.random.JceRandomFactory;
import org.apache.sshd.common.random.Random;
import org.apache.sshd.common.random.RandomFactory;
@@ -421,11 +422,12 @@ public final class SecurityUtils {
/**
* Named factory for the BouncyCastle <code>Random</code>
*/
- public static final class BouncyCastleRandomFactory implements RandomFactory {
+ public static final class BouncyCastleRandomFactory extends AbstractRandomFactory {
+ public static final String NAME = "bouncycastle";
private static final BouncyCastleRandomFactory INSTANCE = new BouncyCastleRandomFactory();
public BouncyCastleRandomFactory() {
- super();
+ super(NAME);
}
@Override
@@ -434,11 +436,6 @@ public final class SecurityUtils {
}
@Override
- public String getName() {
- return "bouncycastle";
- }
-
- @Override
public Random create() {
return new BouncyCastleRandom();
}
@@ -453,7 +450,7 @@ public final class SecurityUtils {
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public static final class BouncyCastleRandom extends AbstractRandom {
-
+ public static final String NAME = BOUNCY_CASTLE;
private final RandomGenerator random;
BouncyCastleRandom() {
@@ -464,6 +461,11 @@ public final class SecurityUtils {
}
@Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
public void fill(byte[] bytes, int start, int len) {
this.random.nextBytes(bytes, start, len);
}
@@ -474,19 +476,18 @@ public final class SecurityUtils {
*/
@Override
public int random(int n) {
- if (n > 0) {
- if ((n & -n) == n) {
- return (int) ((n * (long) next(31)) >> 31);
- }
- int bits;
- int val;
- do {
- bits = next(31);
- val = bits % n;
- } while (bits - val + (n - 1) < 0);
- return val;
+ ValidateUtils.checkTrue(n > 0, "Limit must be positive: %d", n);
+ if ((n & -n) == n) {
+ return (int) ((n * (long) next(31)) >> 31);
}
- throw new IllegalArgumentException("Limit must be positive: " + n);
+
+ int bits;
+ int val;
+ do {
+ bits = next(31);
+ val = bits % n;
+ } while (bits - val + (n - 1) < 0);
+ return val;
}
private int next(int numBits) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/8403509d/sshd-core/src/test/java/org/apache/sshd/common/random/RandomFactoryTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/random/RandomFactoryTest.java b/sshd-core/src/test/java/org/apache/sshd/common/random/RandomFactoryTest.java
new file mode 100644
index 0000000..5d56dde
--- /dev/null
+++ b/sshd-core/src/test/java/org/apache/sshd/common/random/RandomFactoryTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.random;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.sshd.common.util.SecurityUtils;
+import org.apache.sshd.util.test.BaseTestSupport;
+import org.junit.Assume;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * TODO Add javadoc
+ *
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+@RunWith(Parameterized.class) // see https://github.com/junit-team/junit/wiki/Parameterized-tests
+public class RandomFactoryTest extends BaseTestSupport {
+ @Parameters(name = "type={0}")
+ public static Collection<Object[]> parameters() {
+ Collection<RandomFactory> testCases = new LinkedList<>();
+ testCases.add(JceRandomFactory.INSTANCE);
+ if (SecurityUtils.isBouncyCastleRegistered()) {
+ testCases.add(SecurityUtils.getRandomFactory());
+ } else {
+ System.out.println("Skip BouncyCastleRandomFactory - unsupported");
+ }
+
+ return parameterize(testCases);
+ }
+
+ private final RandomFactory factory;
+
+ public RandomFactoryTest(RandomFactory factory) {
+ this.factory = factory;
+ }
+
+ @Test
+ public void testRandomFactory() {
+ Assume.assumeTrue("Skip unsupported factory: " + factory.getName(), factory.isSupported());
+ long t = testRandom(factory.create());
+ System.out.println(factory.getName() + " duration: " + t + " " + TimeUnit.MICROSECONDS);
+ }
+
+ // returns duration in microseconds
+ private static long testRandom(Random random) {
+ byte[] bytes = new byte[32];
+ long l0 = System.nanoTime();
+ for (int i = 0; i < 1000; i++) {
+ random.fill(bytes, 8, 16);
+ }
+ long l1 = System.nanoTime();
+ return TimeUnit.NANOSECONDS.toMicros(l1 - l0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/8403509d/sshd-core/src/test/java/org/apache/sshd/common/random/RandomTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/random/RandomTest.java b/sshd-core/src/test/java/org/apache/sshd/common/random/RandomTest.java
deleted file mode 100644
index d512fe1..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/random/RandomTest.java
+++ /dev/null
@@ -1,62 +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.random;
-
-import org.apache.sshd.common.util.SecurityUtils;
-import org.apache.sshd.util.test.BaseTestSupport;
-import org.apache.sshd.util.test.Utils;
-import org.junit.Assume;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-
-/**
- * TODO Add javadoc
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class RandomTest extends BaseTestSupport {
- public RandomTest() {
- super();
- }
-
- @Test
- public void testJce() {
- long t = testRandom(new JceRandom());
- System.out.println("JCE: " + t + " micro");
- }
-
- @Test
- public void testBc() {
- Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
- long t = testRandom(Utils.getRandomizerInstance());
- System.out.println("BC: " + t + " micro");
- }
-
- private static long testRandom(Random random) {
- byte[] bytes = new byte[32];
- long l0 = System.nanoTime();
- for (int i = 0; i < 1000; i++) {
- random.fill(bytes, 8, 16);
- }
- long l1 = System.nanoTime();
- return (l1 - l0) / 1000;
- }
-}
[4/7] mina-sshd git commit: Using outputDebugMessage instead of
System.out for some more test related messages
Posted by lg...@apache.org.
Using outputDebugMessage instead of System.out for some more test related messages
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/f7ca304c
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/f7ca304c
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/f7ca304c
Branch: refs/heads/master
Commit: f7ca304c4d0d3e723b4e5439a09d88d10f95ba36
Parents: 8403509
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Mon Dec 7 08:58:28 2015 +0200
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Mon Dec 7 08:58:28 2015 +0200
----------------------------------------------------------------------
.../sshd/common/session/AbstractSession.java | 2 +-
.../java/org/apache/sshd/KeyReExchangeTest.java | 18 ++++++++++--------
.../java/org/apache/sshd/client/ClientTest.java | 14 +++++---------
.../java/org/apache/sshd/client/kex/KexTest.java | 2 --
.../client/subsystem/sftp/SftpFileSystemTest.java | 2 +-
.../common/config/keys/BuiltinIdentitiesTest.java | 2 +-
.../sshd/common/config/keys/KeyUtilsTest.java | 4 ++--
.../AbstractSignatureFactoryTestSupport.java | 2 +-
.../java/org/apache/sshd/server/ServerTest.java | 12 ++++++------
.../config/keys/AuthorizedKeyEntryTest.java | 2 +-
10 files changed, 28 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f7ca304c/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 4b32ba8..e60cf85 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
@@ -1389,7 +1389,7 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
if (t != null) {
if (log.isTraceEnabled()) {
- log.trace("disconnect(" + AbstractSession.this + ") reason=" + SshConstants.getDisconnectReasonName(reason)+ " failure details", t);
+ log.trace("disconnect(" + AbstractSession.this + ") reason=" + SshConstants.getDisconnectReasonName(reason) + " failure details", t);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f7ca304c/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java b/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
index 3362a4f..fd006b7 100644
--- a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
@@ -88,7 +88,9 @@ public class KeyReExchangeTest extends BaseTestSupport {
@After
public void tearDown() throws Exception {
- sshd.stop(true);
+ if (sshd != null) {
+ sshd.stop(true);
+ }
}
protected void setUp(long bytesLimit, long timeLimit, long packetsLimit) throws Exception {
@@ -223,7 +225,7 @@ public class KeyReExchangeTest extends BaseTestSupport {
String expected = "this is my command\n";
byte[] bytes = expected.getBytes(StandardCharsets.UTF_8);
byte[] data = new byte[bytes.length + Long.SIZE];
- for (int i = 0; i < 10; i++) {
+ for (int i = 1; i <= 10; i++) {
os.write(bytes);
os.flush();
@@ -267,14 +269,14 @@ public class KeyReExchangeTest extends BaseTestSupport {
teeOut.write("this is my command\n".getBytes(StandardCharsets.UTF_8));
teeOut.flush();
- StringBuilder sb = new StringBuilder();
+ StringBuilder sb = new StringBuilder(Byte.MAX_VALUE);
for (int i = 0; i < 10; i++) {
sb.append("0123456789");
}
sb.append('\n');
byte[] data = sb.toString().getBytes(StandardCharsets.UTF_8);
- for (int i = 0; i < 10; i++) {
+ for (int i = 1; i <= 10; i++) {
teeOut.write(data);
teeOut.flush();
@@ -298,7 +300,7 @@ public class KeyReExchangeTest extends BaseTestSupport {
@Test
public void testReExchangeFromServerBySize() throws Exception {
- final long LIMIT = 8192L;
+ final long LIMIT = 10 * 1024L;
setUp(LIMIT, 0L, 0L);
try (SshClient client = setupTestClient()) {
@@ -324,7 +326,7 @@ public class KeyReExchangeTest extends BaseTestSupport {
teeOut.write("this is my command\n".getBytes(StandardCharsets.UTF_8));
teeOut.flush();
- StringBuilder sb = new StringBuilder();
+ StringBuilder sb = new StringBuilder(101 * 10);
for (int i = 0; i < 100; i++) {
sb.append("0123456789");
}
@@ -410,7 +412,7 @@ public class KeyReExchangeTest extends BaseTestSupport {
teeOut.write("this is my command\n".getBytes(StandardCharsets.UTF_8));
teeOut.flush();
- StringBuilder sb = new StringBuilder();
+ StringBuilder sb = new StringBuilder(101 * 10);
for (int i = 0; i < 100; i++) {
sb.append("0123456789");
}
@@ -487,7 +489,7 @@ public class KeyReExchangeTest extends BaseTestSupport {
@Test // see SSHD-601
public void testReExchangeFromServerByPackets() throws Exception {
- final int PACKETS = 128;
+ final int PACKETS = 135;
setUp(0L, 0L, PACKETS);
try (SshClient client = setupTestClient()) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f7ca304c/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
index 32b32e0..26fb505 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
@@ -786,7 +786,7 @@ public class ClientTest extends BaseTestSupport {
teeOut.flush();
bytes += data.length;
if ((bytes & 0xFFF00000) != ((bytes - data.length) & 0xFFF00000)) {
- System.out.println("Bytes written: " + bytes);
+ outputDebugMessage("Bytes written: %d", bytes);
}
}
teeOut.write("exit\n".getBytes(StandardCharsets.UTF_8));
@@ -794,9 +794,9 @@ public class ClientTest extends BaseTestSupport {
}
long t1 = System.currentTimeMillis();
- System.out.println("Sent " + (bytes / 1024) + " Kb in " + (t1 - t0) + " ms");
+ outputDebugMessage("Sent %d Kb in %d ms", bytes / 1024, t1 - t0);
- System.out.println("Waiting for channel to be closed");
+ outputDebugMessage("Waiting for channel to be closed");
Collection<ClientChannel.ClientChannelEvent> result =
channel.waitFor(EnumSet.of(ClientChannel.ClientChannelEvent.CLOSED), TimeUnit.SECONDS.toMillis(15L));
assertFalse("Timeout while waiting on channel close", result.contains(ClientChannel.ClientChannelEvent.TIMEOUT));
@@ -1321,12 +1321,8 @@ public class ClientTest extends BaseTestSupport {
client.setServerKeyVerifier(
new ServerKeyVerifier() {
@Override
- public boolean verifyServerKey(
- ClientSession sshClientSession,
- SocketAddress remoteAddress,
- PublicKey serverKey
- ) {
- System.out.println(serverKey);
+ public boolean verifyServerKey(ClientSession sshClientSession, SocketAddress remoteAddress, PublicKey serverKey) {
+ outputDebugMessage("verifyServerKey(%s): %s", remoteAddress, serverKey);
ok.set(true);
return true;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f7ca304c/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java b/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
index 439210d..6d9a7bd 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
@@ -98,8 +98,6 @@ public class KexTest extends BaseTestSupport {
}
private void testClient(NamedFactory<KeyExchange> kex) throws Exception {
- System.out.println("testClient - KEX=" + kex.getName());
-
try (ByteArrayOutputStream sent = new ByteArrayOutputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream()) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f7ca304c/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
index 64ca4aa..547a0d9 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
@@ -178,7 +178,7 @@ public class SftpFileSystemTest extends BaseTestSupport {
try (FileSystem fs = FileSystems.newFileSystem(URI.create("root:" + rootNative.toUri().toString() + "!/"), null)) {
Path dir = assertHierarchyTargetFolderExists(fs.getPath("test/foo"));
- System.out.println("Created " + dir);
+ outputDebugMessage("Created %s", dir);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f7ca304c/sshd-core/src/test/java/org/apache/sshd/common/config/keys/BuiltinIdentitiesTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/BuiltinIdentitiesTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/BuiltinIdentitiesTest.java
index b4bdcd7..b8859ae 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/BuiltinIdentitiesTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/BuiltinIdentitiesTest.java
@@ -73,7 +73,7 @@ public class BuiltinIdentitiesTest extends BaseTestSupport {
KeyPairGenerator gen = SecurityUtils.getKeyPairGenerator(expected.getAlgorithm());
KeyPair kp = gen.generateKeyPair();
- System.out.println("Checking built-in identity: " + name);
+ outputDebugMessage("Checking built-in identity: %s", name);
assertSame(name + "[pair]", expected, BuiltinIdentities.fromKeyPair(kp));
assertSame(name + "[public]", expected, BuiltinIdentities.fromKey(kp.getPublic()));
assertSame(name + "[private]", expected, BuiltinIdentities.fromKey(kp.getPrivate()));
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f7ca304c/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java
index 03af665..afe9268 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java
@@ -224,7 +224,7 @@ public class KeyUtilsTest extends BaseTestSupport {
private static KeyPair generateKeyPair(String keyType, int keySize) throws GeneralSecurityException {
try {
- System.out.println("generateKeyPair(" + keyType + ")[" + keySize + "]");
+ outputDebugMessage("generateKeyPair(%s)[%d]", keyType, keySize);
return KeyUtils.generateKeyPair(keyType, keySize);
} catch (GeneralSecurityException e) {
System.err.println("Failed (" + e.getClass().getSimpleName() + ") to generate key-pair for " + keyType + "/" + keySize + ": " + e.getMessage());
@@ -234,7 +234,7 @@ public class KeyUtilsTest extends BaseTestSupport {
private static void testKeyPairCloning(String keyType, int keySize, KeyPair kp) throws GeneralSecurityException {
String prefix = keyType + "[" + keySize + "]";
- System.out.println("testKeyPairCloning(" + prefix + ")");
+ outputDebugMessage("testKeyPairCloning(%s)", prefix);
KeyPair cloned = KeyUtils.cloneKeyPair(keyType, kp);
assertNotSame(prefix + ": Key pair not cloned", kp, cloned);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f7ca304c/sshd-core/src/test/java/org/apache/sshd/common/signature/AbstractSignatureFactoryTestSupport.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/signature/AbstractSignatureFactoryTestSupport.java b/sshd-core/src/test/java/org/apache/sshd/common/signature/AbstractSignatureFactoryTestSupport.java
index 14a88b3..0979a6c 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/signature/AbstractSignatureFactoryTestSupport.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/signature/AbstractSignatureFactoryTestSupport.java
@@ -90,7 +90,7 @@ public abstract class AbstractSignatureFactoryTestSupport extends BaseTestSuppor
public Iterable<KeyPair> create() {
try {
KeyPair kp = decoder.generateKeyPair(keySize);
- System.out.println("Generated key pair for " + keyName + "[" + keySize + "]");
+ outputDebugMessage("Generated key pair for %s - key size=%d", keyName, keySize);
return Collections.singletonList(kp);
} catch (Exception e) {
throw new RuntimeSshException(e);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f7ca304c/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java b/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
index bfdb958..a5dfd53 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
@@ -199,17 +199,17 @@ public class ServerTest extends BaseTestSupport {
sshd.addSessionListener(new SessionListener() {
@Override
public void sessionCreated(Session session) {
- System.out.println("Session created");
+ outputDebugMessage("Session created: %s", session);
}
@Override
public void sessionEvent(Session session, Event event) {
- System.out.println("Session event: " + event);
+ outputDebugMessage("Session %s event: ", session, event);
}
@Override
public void sessionClosed(Session session) {
- System.out.println("Session closed");
+ outputDebugMessage("Session closed: %s", session);
latch.countDown();
}
});
@@ -265,17 +265,17 @@ public class ServerTest extends BaseTestSupport {
sshd.addSessionListener(new SessionListener() {
@Override
public void sessionCreated(Session session) {
- System.out.println("Session created");
+ outputDebugMessage("Session created: %s", session);
}
@Override
public void sessionEvent(Session session, Event event) {
- System.out.println("Session event: " + event);
+ outputDebugMessage("Session %s event: %s", session, event);
}
@Override
public void sessionClosed(Session session) {
- System.out.println("Session closed");
+ outputDebugMessage("Session closed: %s", session);
latch.countDown();
}
});
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f7ca304c/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntryTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntryTest.java b/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntryTest.java
index 674812f..2420f8c 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntryTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntryTest.java
@@ -87,7 +87,7 @@ public class AuthorizedKeyEntryTest extends AuthorizedKeysTestSupport {
LinkOption[] options = IoUtils.getLinkOptions(false);
if (!Files.exists(path, options)) {
- System.out.append(getCurrentTestName()).append(": verify non-existing ").println(path);
+ outputDebugMessage("Verify non-existing %s", path);
Collection<AuthorizedKeyEntry> entries = AuthorizedKeyEntry.readDefaultAuthorizedKeys();
assertTrue("Non-empty keys even though file not found: " + entries, GenericUtils.isEmpty(entries));
} else {
[6/7] mina-sshd git commit: Re-use buffer in
AbstractSession#resizeKey loop
Posted by lg...@apache.org.
Re-use buffer in AbstractSession#resizeKey loop
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/7c0f681f
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/7c0f681f
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/7c0f681f
Branch: refs/heads/master
Commit: 7c0f681feaa616dd03bd3cf99ceb51383b3df026
Parents: f135b61
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Mon Dec 7 09:07:06 2015 +0200
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Mon Dec 7 09:07:06 2015 +0200
----------------------------------------------------------------------
.../org/apache/sshd/common/session/AbstractSession.java | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/7c0f681f/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 e60cf85..02af7cf 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
@@ -1338,16 +1338,19 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
* initialize the cipher to the needed length.
*
* @param e the key to resize
- * @param blockSize the cipher block size
+ * @param blockSize the cipher block size (in bytes)
* @param hash the hash algorithm
* @param k the key exchange k parameter
* @param h the key exchange h parameter
- * @return the resize key
+ * @return the resized key
* @throws Exception if a problem occur while resizing the key
*/
protected byte[] resizeKey(byte[] e, int blockSize, Digest hash, byte[] k, byte[] h) throws Exception {
- while (blockSize > e.length) {
- Buffer buffer = new ByteArrayBuffer();
+ for (Buffer buffer = null; blockSize > e.length; buffer = BufferUtils.clear(buffer)) {
+ if (buffer == null) {
+ buffer = new ByteArrayBuffer();
+ }
+
buffer.putMPInt(k);
buffer.putRawBytes(h);
buffer.putRawBytes(e);