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 2016/01/27 13:26:21 UTC
[2/2] mina-sshd git commit: [SSHD-625] Use catch(Throwable) where
possible to avoid stopping performing queries and to log errors
[SSHD-625] Use catch(Throwable) where possible to avoid stopping performing queries and to log errors
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/d6bd4add
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/d6bd4add
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/d6bd4add
Branch: refs/heads/master
Commit: d6bd4add053017f54c538bc900c9d063fee0ae88
Parents: e0e66e7
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Wed Jan 27 14:25:58 2016 +0200
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Wed Jan 27 14:25:58 2016 +0200
----------------------------------------------------------------------
.../sshd/agent/common/AbstractAgentClient.java | 3 +
.../sshd/agent/common/AgentForwardSupport.java | 9 ++-
.../agent/local/ChannelAgentForwarding.java | 9 +++
.../org/apache/sshd/agent/unix/AgentClient.java | 4 ++
.../sshd/agent/unix/AgentForwardedChannel.java | 9 ++-
.../sshd/agent/unix/AgentServerProxy.java | 10 +--
.../org/apache/sshd/agent/unix/AprLibrary.java | 17 +++--
.../sshd/agent/unix/ChannelAgentForwarding.java | 10 ++-
.../keyboard/UserAuthKeyboardInteractive.java | 15 +++-
.../client/auth/password/UserAuthPassword.java | 30 ++++++--
.../client/auth/pubkey/UserAuthPublicKey.java | 73 +++++++++++++++++---
.../client/channel/AbstractClientChannel.java | 8 +++
.../sshd/client/channel/ChannelSession.java | 3 +
.../hosts/ConfigFileHostEntryResolver.java | 5 +-
.../config/keys/ClientIdentitiesWatcher.java | 5 +-
.../sshd/client/session/ClientSessionImpl.java | 12 +++-
.../client/session/ClientUserAuthService.java | 15 +++-
.../client/simple/AbstractSimpleClient.java | 11 +++
.../sshd/common/channel/AbstractChannel.java | 22 ++++--
.../common/forward/DefaultTcpipForwarder.java | 16 ++++-
.../io/BuiltinIoServiceFactoryFactories.java | 2 +-
.../AbstractResourceKeyPairProvider.java | 3 +
.../session/AbstractConnectionService.java | 10 ++-
.../sshd/common/session/AbstractSession.java | 35 ++++++++--
.../session/AbstractSessionIoHandler.java | 12 +++-
.../auth/hostbased/UserAuthHostBased.java | 16 ++++-
...DefaultKeyboardInteractiveAuthenticator.java | 13 +++-
.../keyboard/UserAuthKeyboardInteractive.java | 27 +++++++-
.../server/auth/password/UserAuthPassword.java | 14 +++-
.../pubkey/CachingPublicKeyAuthenticator.java | 38 ++++++++--
.../server/auth/pubkey/UserAuthPublicKey.java | 15 +++-
.../server/channel/AbstractServerChannel.java | 10 ++-
.../sshd/server/channel/ChannelSession.java | 37 +++++++---
.../keys/AuthorizedKeysAuthenticator.java | 5 +-
.../sshd/server/forward/TcpipServerChannel.java | 69 +++++++++++++++---
.../server/global/OpenSshHostKeysHandler.java | 14 +++-
.../AbstractGeneratorHostKeyProvider.java | 8 +--
.../sshd/server/session/ServerSessionImpl.java | 40 +++++++++--
.../server/session/ServerUserAuthService.java | 12 ++--
.../sshd/server/shell/InvertedShellWrapper.java | 15 ++--
.../sshd/server/x11/X11ForwardSupport.java | 2 +-
.../java/org/apache/sshd/agent/AgentTest.java | 11 ++-
.../java/org/apache/sshd/client/ClientTest.java | 4 +-
.../config/hosts/HostConfigEntryTest.java | 2 +-
.../client/simple/SimpleSessionClientTest.java | 8 +--
.../sshd/client/subsystem/sftp/SftpTest.java | 4 +-
.../subsystem/sftp/SftpVersionSelectorTest.java | 2 +-
.../client/subsystem/sftp/SftpVersionsTest.java | 2 +-
.../sshd/common/auth/AuthenticationTest.java | 62 ++++++++++++++++-
.../common/config/keys/PublicKeyEntryTest.java | 2 +-
.../sshd/server/auth/BaseAuthenticatorTest.java | 2 +-
51 files changed, 663 insertions(+), 119 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/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 770f967..60dfebb 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
@@ -81,6 +81,9 @@ public abstract class AbstractAgentClient extends AbstractLoggingBean {
log.debug("Failed ({}) to handle command={}: {}",
e.getClass().getSimpleName(), cmd, e.getMessage());
}
+ if (log.isTraceEnabled()) {
+ log.trace("Received command=" + cmd + " handling failure details", e);
+ }
rep.clear();
rep.putInt(0);
rep.rpos(rep.wpos());
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/agent/common/AgentForwardSupport.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/common/AgentForwardSupport.java b/sshd-core/src/main/java/org/apache/sshd/agent/common/AgentForwardSupport.java
index b1ad269..a52dcb5 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/common/AgentForwardSupport.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/common/AgentForwardSupport.java
@@ -20,9 +20,13 @@ package org.apache.sshd.agent.common;
import java.io.IOException;
+import org.apache.sshd.agent.SshAgentFactory;
import org.apache.sshd.agent.SshAgentServer;
+import org.apache.sshd.common.FactoryManager;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.session.ConnectionService;
+import org.apache.sshd.common.session.Session;
+import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.closeable.AbstractCloseable;
/**
@@ -41,7 +45,10 @@ public class AgentForwardSupport extends AbstractCloseable {
public String initialize() throws IOException {
try {
if (agentId == null) {
- agentServer = service.getSession().getFactoryManager().getAgentFactory().createServer(service);
+ Session session = ValidateUtils.checkNotNull(service.getSession(), "No session");
+ FactoryManager manager = ValidateUtils.checkNotNull(session.getFactoryManager(), "No session factory manager");
+ SshAgentFactory factory = ValidateUtils.checkNotNull(manager.getAgentFactory(), "No agent factory");
+ agentServer = ValidateUtils.checkNotNull(factory.createServer(service), "No agent server created");
agentId = agentServer.getId();
}
return agentId;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/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 cf0f707..2aefbdc 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
@@ -77,6 +77,15 @@ public class ChannelAgentForwarding extends AbstractServerChannel {
if (log.isDebugEnabled()) {
log.debug("doInit(" + this + ") inform listener open failure details", ignored);
}
+
+ if (log.isTraceEnabled()) {
+ Throwable[] suppressed = ignored.getSuppressed();
+ if (GenericUtils.length(suppressed) > 0) {
+ for (Throwable s : suppressed) {
+ log.trace("doInit(" + this + ") suppressed channel open failure signalling", s);
+ }
+ }
+ }
}
f.setException(e);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/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 36d60b5..23c301d 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
@@ -97,6 +97,10 @@ public class AgentClient extends AbstractAgentProxy implements Runnable {
} catch (Exception e) {
if (isOpen()) {
log.warn(e.getClass().getSimpleName() + " while still open: " + e.getMessage());
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Closed client loop exception", e);
+ }
}
} finally {
try {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentForwardedChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentForwardedChannel.java b/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentForwardedChannel.java
index 4cf3ad8..ecd3283 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentForwardedChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentForwardedChannel.java
@@ -19,6 +19,7 @@
package org.apache.sshd.agent.unix;
import java.io.IOException;
+import java.io.OutputStream;
import org.apache.sshd.client.channel.AbstractClientChannel;
import org.apache.sshd.common.SshConstants;
@@ -40,6 +41,7 @@ public class AgentForwardedChannel extends AbstractClientChannel implements Runn
public void run() {
try {
byte[] buf = new byte[1024];
+ OutputStream invIn = getInvertedIn();
while (true) {
int result = Socket.recv(socket, buf, 0, buf.length);
if (result == -Status.APR_EOF) {
@@ -47,11 +49,12 @@ public class AgentForwardedChannel extends AbstractClientChannel implements Runn
} else if (result < Status.APR_SUCCESS) {
AgentServerProxy.throwException(result);
}
- getInvertedIn().write(buf, 0, result);
- getInvertedIn().flush();
+
+ invIn.write(buf, 0, result);
+ invIn.flush();
}
} catch (Exception e) {
- e.printStackTrace();
+ log.warn("Processing loop exception", e);
} finally {
close(false);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java b/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java
index 5c1e9af..9cb4487 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java
@@ -110,10 +110,12 @@ public class AgentServerProxy extends AbstractLoggingBean implements SshAgentSer
AgentServerProxy.this.service.registerChannel(channel);
channel.open().verify(PropertyResolverUtils.getLongProperty(session, CHANNEL_OPEN_TIMEOUT_PROP, DEFAULT_CHANNEL_OPEN_TIMEOUT));
} catch (Exception e) {
- if (isOpen()) {
- if (log.isDebugEnabled()) {
- log.debug(e.getClass().getSimpleName() + " while authentication forwarding: " + e.getMessage(), e);
- }
+ if (log.isDebugEnabled()) {
+ log.debug("run(open={}) {} while authentication forwarding: {}",
+ isOpen(), e.getClass().getSimpleName(), e.getMessage());
+ }
+ if (log.isTraceEnabled()) {
+ log.trace("run(open=" + isOpen() + ") authentication forwarding failure details", e);
}
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/agent/unix/AprLibrary.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/unix/AprLibrary.java b/sshd-core/src/main/java/org/apache/sshd/agent/unix/AprLibrary.java
index e355212..d77e2c3 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/unix/AprLibrary.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/unix/AprLibrary.java
@@ -51,15 +51,22 @@ final class AprLibrary {
/**
* APR library singleton constructor. Called only when accessing the
- * singleton the first time.
- * It's initializing an APR memory pool for the whole package (a.k.a mother or root pool).
+ * singleton the first time. It is initializing an APR memory pool for
+ * the whole package (a.k.a mother or root pool).
+ *
+ * @throws RuntimeException if failed to load the library. <B>Note:</B>
+ * callers should inspect the <U>cause</U> of the exception in case an
+ * {@link Error} was thrown (e.g., {@code UnsatisfiedLinkError}).
*/
private AprLibrary() {
try {
Library.initialize(null);
- } catch (Exception e) {
- throw new RuntimeException(
- "Error loading Apache Portable Runtime (APR).", e);
+ } catch (Throwable e) {
+ if (e instanceof RuntimeException) {
+ throw (RuntimeException) e;
+ } else {
+ throw new RuntimeException("Error loading Apache Portable Runtime (APR).", e);
+ }
}
pool = Pool.create(0);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/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 3093321..06e2c92 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
@@ -115,7 +115,7 @@ public class ChannelAgentForwarding extends AbstractServerChannel {
listener.channelOpenSuccess(this);
f.setOpened();
- } catch (Exception t) {
+ } catch (Throwable t) {
Throwable e = GenericUtils.peelException(t);
try {
listener.channelOpenFailure(this, e);
@@ -126,6 +126,14 @@ public class ChannelAgentForwarding extends AbstractServerChannel {
if (log.isDebugEnabled()) {
log.debug("doInit(" + this + ") inform listener open failure details", ignored);
}
+ if (log.isTraceEnabled()) {
+ Throwable[] suppressed = ignored.getSuppressed();
+ if (GenericUtils.length(suppressed) > 0) {
+ for (Throwable s : suppressed) {
+ log.trace("doInit(" + this + ") suppressed channel open failure signalling", s);
+ }
+ }
+ }
}
f.setException(e);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/client/auth/keyboard/UserAuthKeyboardInteractive.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/keyboard/UserAuthKeyboardInteractive.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/keyboard/UserAuthKeyboardInteractive.java
index 608f451..a845687 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/keyboard/UserAuthKeyboardInteractive.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/keyboard/UserAuthKeyboardInteractive.java
@@ -28,6 +28,7 @@ import org.apache.sshd.client.auth.AbstractUserAuth;
import org.apache.sshd.client.auth.password.PasswordIdentityProvider;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.PropertyResolverUtils;
+import org.apache.sshd.common.RuntimeSshException;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.ValidateUtils;
@@ -261,8 +262,18 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth {
}
UserInteraction ui = session.getUserInteraction();
- if ((ui != null) && ui.isInteractionAllowed(session)) {
- return ui.interactive(session, name, instruction, lang, prompt, echo);
+ try {
+ if ((ui != null) && ui.isInteractionAllowed(session)) {
+ return ui.interactive(session, name, instruction, lang, prompt, echo);
+ }
+ } catch (Error e) {
+ log.warn("getUserResponses({}) failed ({}) to consult interaction: {}",
+ session, e.getClass().getSimpleName(), e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("getUserResponses(" + session + ") interaction consultation failure details", e);
+ }
+
+ throw new RuntimeSshException(e);
}
if (log.isDebugEnabled()) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/client/auth/password/UserAuthPassword.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/password/UserAuthPassword.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/password/UserAuthPassword.java
index 3db61be..0d4adee 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/password/UserAuthPassword.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/password/UserAuthPassword.java
@@ -25,6 +25,7 @@ import java.util.Objects;
import org.apache.sshd.client.auth.AbstractUserAuth;
import org.apache.sshd.client.auth.keyboard.UserInteraction;
import org.apache.sshd.client.session.ClientSession;
+import org.apache.sshd.common.RuntimeSshException;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.buffer.Buffer;
@@ -79,22 +80,37 @@ public class UserAuthPassword extends AbstractUserAuth {
String prompt = buffer.getString();
String lang = buffer.getString();
UserInteraction ui = session.getUserInteraction();
- if ((ui != null) && ui.isInteractionAllowed(session)) {
- String password = ui.getUpdatedPassword(session, prompt, lang);
+ boolean interactive;
+ String password;
+ try {
+ interactive = (ui != null) && ui.isInteractionAllowed(session);
+ password = interactive ? ui.getUpdatedPassword(session, prompt, lang) : null;
+ } catch (Error e) {
+ log.warn("processAuthDataRequest({})[{}] failed ({}) to consult interaction: {}",
+ session, service, e.getClass().getSimpleName(), e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("processAuthDataRequest(" + session + ")[" + service + "] interaction consultation failure details", e);
+ }
+
+ throw new RuntimeSshException(e);
+ }
+
+ if (interactive) {
if (GenericUtils.isEmpty(password)) {
if (log.isDebugEnabled()) {
log.debug("processAuthDataRequest({})[{}] No updated password for prompt={}, lang={}",
session, service, prompt, lang);
}
+ return false;
} else {
sendPassword(buffer, session, password, password);
return true;
}
- } else {
- if (log.isDebugEnabled()) {
- log.debug("processAuthDataRequest({})[{}] no UI for password change request for prompt={}, lang={}",
- session, service, prompt, lang);
- }
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("processAuthDataRequest({})[{}] no UI for password change request for prompt={}, lang={}",
+ session, service, prompt, lang);
}
return false;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKey.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKey.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKey.java
index 49a203f..53d3feb 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKey.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKey.java
@@ -28,6 +28,7 @@ import java.util.List;
import org.apache.sshd.client.auth.AbstractUserAuth;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.NamedFactory;
+import org.apache.sshd.common.RuntimeSshException;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.signature.Signature;
@@ -70,25 +71,58 @@ public class UserAuthPublicKey extends AbstractUserAuth implements SignatureFact
public void init(ClientSession session, String service) throws Exception {
super.init(session, service);
releaseKeys(); // just making sure in case multiple calls to the method
- keys = new UserAuthPublicKeyIterator(session, this);
+
+ try {
+ keys = new UserAuthPublicKeyIterator(session, this);
+ } catch (Error e) {
+ log.warn("init({})[{}] failed ({}) to initialize session keys: {}",
+ session, service, e.getClass().getSimpleName(), e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("init(" + session + ")[" + service + "] session keys initialization failure details", e);
+ }
+
+ throw new RuntimeSshException(e);
+ }
}
@Override
protected boolean sendAuthDataRequest(ClientSession session, String service) throws Exception {
- if ((keys == null) || (!keys.hasNext())) {
+ try {
+ if ((keys == null) || (!keys.hasNext())) {
+ if (log.isDebugEnabled()) {
+ log.debug("sendAuthDataRequest({})[{}] no more keys to send", session, service);
+ }
+
+ return false;
+ }
+
+ current = keys.next();
+ } catch (Error e) {
+ log.warn("sendAuthDataRequest({})[{}] failed ({}) to get next key: {}",
+ session, service, e.getClass().getSimpleName(), e.getMessage());
if (log.isDebugEnabled()) {
- log.debug("sendAuthDataRequest({})[{}] no more keys to send", session, service);
+ log.debug("sendAuthDataRequest(" + session + ")[" + service + "] next key fetch failure details", e);
}
- return false;
+ throw new RuntimeSshException(e);
}
- current = keys.next();
if (log.isTraceEnabled()) {
log.trace("sendAuthDataRequest({})[{}] current key details: {}", session, service, current);
}
- PublicKey key = current.getPublicKey();
+ PublicKey key;
+ try {
+ key = current.getPublicKey();
+ } catch (Error e) {
+ log.warn("sendAuthDataRequest({})[{}] failed ({}) to retrieve public key: {}",
+ session, service, e.getClass().getSimpleName(), e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("sendAuthDataRequest(" + session + ")[" + service + "] public key retrieval failure details", e);
+ }
+
+ throw new RuntimeSshException(e);
+ }
String algo = KeyUtils.getKeyType(key);
String name = getName();
if (log.isDebugEnabled()) {
@@ -119,7 +153,18 @@ public class UserAuthPublicKey extends AbstractUserAuth implements SignatureFact
* Make sure the server echo-ed the same key we sent as
* sanctioned by RFC4252 section 7
*/
- PublicKey key = current.getPublicKey();
+ PublicKey key;
+ try {
+ key = current.getPublicKey();
+ } catch (Error e) {
+ log.warn("processAuthDataRequest({})[{}][{}] failed ({}) to retrieve public key: {}",
+ session, service, name, e.getClass().getSimpleName(), e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("processAuthDataRequest(" + session + ")[" + service + "][" + name + "] public key retrieval failure details", e);
+ }
+
+ throw new RuntimeSshException(e);
+ }
String algo = KeyUtils.getKeyType(key);
String rspKeyType = buffer.getString();
if (!rspKeyType.equals(algo)) {
@@ -165,7 +210,19 @@ public class UserAuthPublicKey extends AbstractUserAuth implements SignatureFact
bs.putPublicKey(key);
byte[] contents = bs.getCompactData();
- byte[] sig = current.sign(contents);
+ byte[] sig;
+ try {
+ sig = current.sign(contents);
+ } catch (Error e) {
+ log.warn("appendSignature({})[{}][{}] failed ({}) to sign contents: {}",
+ session, service, name, e.getClass().getSimpleName(), e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("appendSignature(" + session + ")[" + service + "][" + name + "] signing failure details", e);
+ }
+
+ throw new RuntimeSshException(e);
+ }
+
if (log.isTraceEnabled()) {
log.trace("appendSignature({})[{}] name={}, key type={}, fingerprint={} - verification data={}",
session, service, name, algo, KeyUtils.getFingerPrint(key), BufferUtils.printHex(contents));
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/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 5673280..e14b318 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
@@ -327,6 +327,14 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
if (log.isDebugEnabled()) {
log.debug("handleOpenSuccess(" + this + ") inform listener open failure details", ignored);
}
+ if (log.isTraceEnabled()) {
+ Throwable[] suppressed = ignored.getSuppressed();
+ if (GenericUtils.length(suppressed) > 0) {
+ for (Throwable s : suppressed) {
+ log.trace("handleOpenSuccess(" + this + ") suppressed channel open failure signalling", s);
+ }
+ }
+ }
}
this.openFuture.setException(e);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSession.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSession.java
index aa50f3e..5d951cc 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSession.java
@@ -144,6 +144,9 @@ public class ChannelSession extends AbstractClientChannel {
log.debug("doCloseImmediately({}) failed {} to shutdown stream pumper: {}",
this, e.getClass().getSimpleName(), e.getMessage());
}
+ if (log.isTraceEnabled()) {
+ log.trace("doCloseImmediately(" + this + ") stream pumper shutdown error details", e);
+ }
} finally {
pumper = null;
pumperService = null;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolver.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolver.java b/sshd-core/src/main/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolver.java
index 2a694c6..b5d5372 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolver.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolver.java
@@ -63,12 +63,15 @@ public class ConfigFileHostEntryResolver extends ModifiableFileWatcher implement
}
return entry;
- } catch (Exception e) {
+ } catch (Throwable e) {
if (log.isDebugEnabled()) {
log.debug("resolveEffectiveHost({}@{}:{}) failed ({}) to resolve: {}",
username, host, port, e.getClass().getSimpleName(), e.getMessage());
}
+ if (log.isTraceEnabled()) {
+ log.trace("resolveEffectiveHost(" + username + "@" + host + ":" + port + ") resolution failure details", e);
+ }
if (e instanceof IOException) {
throw (IOException) e;
} else {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentitiesWatcher.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentitiesWatcher.java b/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentitiesWatcher.java
index 7d1aca0..4abd4f7 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentitiesWatcher.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentitiesWatcher.java
@@ -86,8 +86,11 @@ public class ClientIdentitiesWatcher extends AbstractKeyPairProvider implements
}
keys.add(kp);
- } catch (Exception e) {
+ } catch (Throwable e) {
log.warn("loadKeys({}) failed ({}) to load key: {}", p, e.getClass().getSimpleName(), e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("loadKeys(" + p + ") key load failure details", e);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/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 44c6e9c..de10873 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
@@ -36,6 +36,7 @@ import org.apache.sshd.client.future.AuthFuture;
import org.apache.sshd.client.future.DefaultAuthFuture;
import org.apache.sshd.client.keyverifier.ServerKeyVerifier;
import org.apache.sshd.common.FactoryManager;
+import org.apache.sshd.common.RuntimeSshException;
import org.apache.sshd.common.Service;
import org.apache.sshd.common.ServiceFactory;
import org.apache.sshd.common.SshConstants;
@@ -99,7 +100,16 @@ public class ClientSessionImpl extends AbstractClientSession {
// Inform the listener of the newly created session
SessionListener listener = getSessionListenerProxy();
- listener.sessionCreated(this);
+ try {
+ listener.sessionCreated(this);
+ } catch (Throwable t) {
+ Throwable e = GenericUtils.peelException(t);
+ if (e instanceof Exception) {
+ throw (Exception) e;
+ } else {
+ throw new RuntimeSshException(e);
+ }
+ }
sendClientIdentification();
kexState.set(KexState.INIT);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/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 f13f8f7..7d98a61 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
@@ -33,6 +33,7 @@ import org.apache.sshd.client.future.DefaultAuthFuture;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.NamedResource;
import org.apache.sshd.common.PropertyResolverUtils;
+import org.apache.sshd.common.RuntimeSshException;
import org.apache.sshd.common.Service;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
@@ -180,8 +181,18 @@ public class ClientUserAuthService
}
UserInteraction ui = session.getUserInteraction();
- if ((ui != null) && ui.isInteractionAllowed(session)) {
- ui.welcome(session, welcome, lang);
+ try {
+ if ((ui != null) && ui.isInteractionAllowed(session)) {
+ ui.welcome(session, welcome, lang);
+ }
+ } catch (Error e) {
+ log.warn("process({}) failed ({}) to consult interaction: {}",
+ session, e.getClass().getSimpleName(), e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("process(" + session + ") interaction consultation failure details", e);
+ }
+
+ throw new RuntimeSshException(e);
}
} else {
buffer.rpos(buffer.rpos() - 1);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/client/simple/AbstractSimpleClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/simple/AbstractSimpleClient.java b/sshd-core/src/main/java/org/apache/sshd/client/simple/AbstractSimpleClient.java
index dd42ebf..4a65e5c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/simple/AbstractSimpleClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/simple/AbstractSimpleClient.java
@@ -109,6 +109,10 @@ public abstract class AbstractSimpleClient extends AbstractLoggingBean implement
log.debug("createSftpClient({}) failed ({}) to close client: {}",
session, t.getClass().getSimpleName(), t.getMessage());
}
+
+ if (log.isTraceEnabled()) {
+ log.trace("createSftpClient(" + session + ") client close failure details", t);
+ }
err = GenericUtils.accumulateException(err, t);
}
}
@@ -128,6 +132,9 @@ public abstract class AbstractSimpleClient extends AbstractLoggingBean implement
session, e.getClass().getSimpleName(), e.getMessage());
}
+ if (log.isTraceEnabled()) {
+ log.trace("createSftpClient(" + session + ") session close failure details", e);
+ }
err = GenericUtils.accumulateException(err, e);
}
@@ -265,6 +272,10 @@ public abstract class AbstractSimpleClient extends AbstractLoggingBean implement
log.debug("createScpClient({}) failed ({}) to close session: {}",
session, t.getClass().getSimpleName(), t.getMessage());
}
+
+ if (log.isTraceEnabled()) {
+ log.trace("createScpClient(" + session + ") session close failure details", t);
+ }
e.addSuppressed(t);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/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 c46cfe0..a958d72 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
@@ -225,7 +225,7 @@ public abstract class AbstractChannel
RequestHandler.Result result;
try {
result = handler.process(this, req, wantReply, buffer);
- } catch (Exception e) {
+ } catch (Throwable e) {
log.warn("handleRequest({}) {} while {}#process({})[want-reply={}]: {}",
this, e.getClass().getSimpleName(), handler.getClass().getSimpleName(),
req, wantReply, e.getMessage());
@@ -327,9 +327,15 @@ public abstract class AbstractChannel
ChannelListener listener = session.getChannelListenerProxy();
try {
listener.channelInitialized(this);
- } catch (RuntimeException t) {
+ } catch (Throwable t) {
Throwable e = GenericUtils.peelException(t);
- throw new IOException("Failed (" + e.getClass().getSimpleName() + ") to notify channel " + this + " initialization: " + e.getMessage(), e);
+ if (e instanceof IOException) {
+ throw (IOException) e;
+ } else if (e instanceof RuntimeException) {
+ throw (RuntimeException) e;
+ } else {
+ throw new IOException("Failed (" + e.getClass().getSimpleName() + ") to notify channel " + this + " initialization: " + e.getMessage(), e);
+ }
}
// delegate the rest of the notifications to the channel
addChannelListener(listener);
@@ -507,12 +513,20 @@ public abstract class AbstractChannel
ChannelListener listener = getChannelListenerProxy();
try {
listener.channelClosed(this, null);
- } catch (RuntimeException t) {
+ } catch (Throwable t) {
Throwable e = GenericUtils.peelException(t);
log.warn("preClose({}) {} while signal channel closed: {}", this, e.getClass().getSimpleName(), e.getMessage());
if (log.isDebugEnabled()) {
log.debug("preClose(" + this + ") channel closed signalling failure details", e);
}
+ if (log.isTraceEnabled()) {
+ Throwable[] suppressed = e.getSuppressed();
+ if (GenericUtils.length(suppressed) > 0) {
+ for (Throwable s : suppressed) {
+ log.trace("preClose(" + this + ") suppressed closed channel signalling failure", s);
+ }
+ }
+ }
} finally {
// clear the listeners since we are closing the channel (quicker GC)
this.channelListeners.clear();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/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 69dc6db..facf9bd 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
@@ -35,6 +35,7 @@ import org.apache.sshd.common.Closeable;
import org.apache.sshd.common.Factory;
import org.apache.sshd.common.FactoryManager;
import org.apache.sshd.common.PropertyResolverUtils;
+import org.apache.sshd.common.RuntimeSshException;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.future.SshFutureListener;
@@ -299,11 +300,20 @@ public class DefaultTcpipForwarder
Session session = getSession();
FactoryManager manager = ValidateUtils.checkNotNull(session.getFactoryManager(), "No factory manager");
ForwardingFilter filter = manager.getTcpipForwardingFilter();
- if ((filter == null) || (!filter.canListen(local, session))) {
+ try {
+ if ((filter == null) || (!filter.canListen(local, session))) {
+ if (log.isDebugEnabled()) {
+ log.debug("localPortForwardingRequested(" + session + ")[" + local + "][haveFilter=" + (filter != null) + "] rejected");
+ }
+ return null;
+ }
+ } catch (Error e) {
+ log.warn("localPortForwardingRequested({})[{}] failed ({}) to consult forwarding filter: {}",
+ session, local, e.getClass().getSimpleName(), e.getMessage());
if (log.isDebugEnabled()) {
- log.debug("localPortForwardingRequested(" + session + ")[" + local + "][haveFilter=" + (filter != null) + "] rejected");
+ log.debug("localPortForwardingRequested(" + this + ")[" + local + "] filter consultation failure details", e);
}
- return null;
+ throw new RuntimeSshException(e);
}
InetSocketAddress bound = doBind(local, staticIoHandlerFactory);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/common/io/BuiltinIoServiceFactoryFactories.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/BuiltinIoServiceFactoryFactories.java b/sshd-core/src/main/java/org/apache/sshd/common/io/BuiltinIoServiceFactoryFactories.java
index dec2792..ba0d014 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/BuiltinIoServiceFactoryFactories.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/BuiltinIoServiceFactoryFactories.java
@@ -58,7 +58,7 @@ public enum BuiltinIoServiceFactoryFactories implements NamedFactory<IoServiceFa
Class<? extends IoServiceFactoryFactory> clazz = getFactoryClass();
try {
return clazz.newInstance();
- } catch (Exception e) {
+ } catch (Throwable e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/AbstractResourceKeyPairProvider.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/AbstractResourceKeyPairProvider.java b/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/AbstractResourceKeyPairProvider.java
index b05c06f..eed682a 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/AbstractResourceKeyPairProvider.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/AbstractResourceKeyPairProvider.java
@@ -194,6 +194,9 @@ public abstract class AbstractResourceKeyPairProvider<R> extends AbstractKeyPair
} catch (Exception e) {
log.warn("Failed (" + e.getClass().getSimpleName() + ")"
+ " to load key resource=" + r + ": " + e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("Key resource=" + r + " load failure details", e);
+ }
nextKeyPair = null;
continue;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/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 a1e93a0..1e7969e 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
@@ -175,6 +175,14 @@ public abstract class AbstractConnectionService<S extends AbstractSession> exten
if (log.isDebugEnabled()) {
log.debug("registerChannel(" + this + ")[" + channel + "] inform closure failure details", ignored);
}
+ if (log.isTraceEnabled()) {
+ Throwable[] suppressed = ignored.getSuppressed();
+ if (GenericUtils.length(suppressed) > 0) {
+ for (Throwable s : suppressed) {
+ log.trace("registerChannel(" + this + ")[" + channel + "] suppressed channel closed signalling", s);
+ }
+ }
+ }
}
throw reason;
@@ -519,7 +527,7 @@ public abstract class AbstractConnectionService<S extends AbstractSession> exten
RequestHandler.Result result;
try {
result = handler.process(this, req, wantReply, buffer);
- } catch (Exception e) {
+ } catch (Throwable e) {
log.warn("globalRequest({})[{}, want-reply={}] failed ({}) to process: {}",
this, req, wantReply, e.getClass().getSimpleName(), e.getMessage());
if (log.isDebugEnabled()) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/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 88447ae..34618f0 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
@@ -46,6 +46,7 @@ import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.NamedResource;
import org.apache.sshd.common.PropertyResolver;
import org.apache.sshd.common.PropertyResolverUtils;
+import org.apache.sshd.common.RuntimeSshException;
import org.apache.sshd.common.Service;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
@@ -277,7 +278,7 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
* @param session the session to attach
*/
public static void attachSession(IoSession ioSession, AbstractSession session) {
- ioSession.setAttribute(SESSION, session);
+ ValidateUtils.checkNotNull(ioSession, "No I/O session").setAttribute(SESSION, ValidateUtils.checkNotNull(session, "No SSH session"));
}
@Override
@@ -425,7 +426,7 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
synchronized (lock) {
doHandleMessage(buffer);
}
- } catch (Exception e) {
+ } catch (Throwable e) {
DefaultKeyExchangeFuture kexFuture = kexFutureHolder.get();
// if have any ongoing KEX notify it about the failure
if (kexFuture != null) {
@@ -437,7 +438,11 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
}
}
- throw e;
+ if (e instanceof Exception) {
+ throw (Exception) e;
+ } else {
+ throw new RuntimeSshException(e);
+ }
}
}
@@ -782,12 +787,21 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
SessionListener listener = getSessionListenerProxy();
try {
listener.sessionClosed(this);
- } catch (RuntimeException t) {
+ } catch (Throwable t) {
Throwable e = GenericUtils.peelException(t);
log.warn("preClose({}) {} while signal session closed: {}", this, e.getClass().getSimpleName(), e.getMessage());
if (log.isDebugEnabled()) {
log.debug("preClose(" + this + ") signal session closed exception details", e);
}
+
+ if (log.isTraceEnabled()) {
+ Throwable[] suppressed = e.getSuppressed();
+ if (GenericUtils.length(suppressed) > 0) {
+ for (Throwable s : suppressed) {
+ log.trace("preClose(" + this + ") suppressed session closed signalling", s);
+ }
+ }
+ }
} finally {
// clear the listeners since we are closing the session (quicker GC)
this.sessionListeners.clear();
@@ -1832,7 +1846,18 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
protected void sendSessionEvent(SessionListener.Event event) throws IOException {
SessionListener listener = getSessionListenerProxy();
- listener.sessionEvent(this, event);
+ try {
+ listener.sessionEvent(this, event);
+ } catch (Throwable e) {
+ Throwable t = GenericUtils.peelException(e);
+ if (t instanceof IOException) {
+ throw (IOException) t;
+ } else if (t instanceof RuntimeException) {
+ throw (RuntimeException) t;
+ } else {
+ throw new IOException("Failed (" + t.getClass().getSimpleName() + ") to send session event: " + t.getMessage(), t);
+ }
+ }
}
@Override
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSessionIoHandler.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSessionIoHandler.java b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSessionIoHandler.java
index 51cc7da..23b296d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSessionIoHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSessionIoHandler.java
@@ -21,6 +21,7 @@ package org.apache.sshd.common.session;
import org.apache.sshd.common.io.IoHandler;
import org.apache.sshd.common.io.IoSession;
import org.apache.sshd.common.util.Readable;
+import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.logging.AbstractLoggingBean;
/**
@@ -35,13 +36,16 @@ public abstract class AbstractSessionIoHandler extends AbstractLoggingBean imple
@Override
public void sessionCreated(IoSession ioSession) throws Exception {
- AbstractSession session = createSession(ioSession);
+ AbstractSession session = ValidateUtils.checkNotNull(
+ createSession(ioSession), "No session created for %s", ioSession);
AbstractSession.attachSession(ioSession, session);
}
@Override
public void sessionClosed(IoSession ioSession) throws Exception {
- AbstractSession.getSession(ioSession).close(true);
+ AbstractSession session = ValidateUtils.checkNotNull(
+ AbstractSession.getSession(ioSession), "No abstract session to handle closure of %s", ioSession);
+ session.close(true);
}
@Override
@@ -56,7 +60,9 @@ public abstract class AbstractSessionIoHandler extends AbstractLoggingBean imple
@Override
public void messageReceived(IoSession ioSession, Readable message) throws Exception {
- AbstractSession.getSession(ioSession).messageReceived(message);
+ AbstractSession session = ValidateUtils.checkNotNull(
+ AbstractSession.getSession(ioSession), "No abstract session to handle incoming message for %s", ioSession);
+ session.messageReceived(message);
}
protected abstract AbstractSession createSession(IoSession ioSession) throws Exception;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/server/auth/hostbased/UserAuthHostBased.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/hostbased/UserAuthHostBased.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/hostbased/UserAuthHostBased.java
index 607bb36..33c17c9 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/hostbased/UserAuthHostBased.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/hostbased/UserAuthHostBased.java
@@ -29,6 +29,7 @@ import java.util.Collections;
import java.util.List;
import org.apache.sshd.common.NamedFactory;
+import org.apache.sshd.common.RuntimeSshException;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.signature.Signature;
@@ -113,7 +114,20 @@ public class UserAuthHostBased extends AbstractUserAuth implements SignatureFact
return Boolean.FALSE;
}
- boolean authed = authenticator.authenticate(session, username, clientKey, clientHostName, clientUsername, certs);
+ boolean authed;
+ try {
+ authed = authenticator.authenticate(session, username, clientKey, clientHostName, clientUsername, certs);
+ } catch (Error e) {
+ log.warn("doAuth({}@{}) failed ({}) to consult authenticator for {} key={}: {}",
+ username, session, e.getClass().getSimpleName(),
+ keyType, KeyUtils.getFingerPrint(clientKey), e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("doAuth(" + username + "@" + session + ") delegate consultation failure details", e);
+ }
+
+ throw new RuntimeSshException(e);
+ }
+
if (log.isDebugEnabled()) {
log.debug("doAuth({}@{}) key type={}, fingerprint={}, client={}@{}, num-certs={} - authentication result: {}",
username, session, keyType, KeyUtils.getFingerPrint(clientKey),
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/DefaultKeyboardInteractiveAuthenticator.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/DefaultKeyboardInteractiveAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/DefaultKeyboardInteractiveAuthenticator.java
index 92bf59b..2423124 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/DefaultKeyboardInteractiveAuthenticator.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/DefaultKeyboardInteractiveAuthenticator.java
@@ -22,6 +22,7 @@ package org.apache.sshd.server.auth.keyboard;
import java.util.List;
import org.apache.sshd.common.PropertyResolverUtils;
+import org.apache.sshd.common.RuntimeSshException;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.logging.AbstractLoggingBean;
@@ -88,7 +89,17 @@ public class DefaultKeyboardInteractiveAuthenticator
throw new SshException("Mismatched number of responses");
}
- return auth.authenticate(username, responses.get(0), session);
+ try {
+ return auth.authenticate(username, responses.get(0), session);
+ } catch (Error e) {
+ log.warn("authenticate({}) failed ({}) to consult password authenticator: {}",
+ session, e.getClass().getSimpleName(), e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("authenticate(" + session + ") authenticator failure details", e);
+ }
+
+ throw new RuntimeSshException(e);
+ }
}
protected String getInteractionName(ServerSession session) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/UserAuthKeyboardInteractive.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/UserAuthKeyboardInteractive.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/UserAuthKeyboardInteractive.java
index 009ddb4..63b25cb 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/UserAuthKeyboardInteractive.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/UserAuthKeyboardInteractive.java
@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import org.apache.sshd.common.RuntimeSshException;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.util.GenericUtils;
@@ -58,7 +59,18 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth {
return false;
}
- InteractiveChallenge challenge = auth.generateChallenge(session, getUsername(), lang, subMethods);
+ InteractiveChallenge challenge;
+ try {
+ challenge = auth.generateChallenge(session, username, lang, subMethods);
+ } catch (Error e) {
+ log.warn("doAuth({}@{}) failed ({}) to generate authenticator challenge: {}",
+ username, session, e.getClass().getSimpleName(), e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("doAuth(" + username + "@" + session + ") authenticator challenge failure details", e);
+ }
+ throw new RuntimeSshException(e);
+ }
+
if (challenge == null) {
if (log.isDebugEnabled()) {
log.debug("doAuth({}@{})[methods={}, lang={}] - no interactive challenge generated",
@@ -103,7 +115,18 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth {
return false;
}
- boolean authed = auth.authenticate(session, username, responses);
+ boolean authed;
+ try {
+ authed = auth.authenticate(session, username, responses);
+ } catch (Error e) {
+ log.warn("doAuth({}@{}) failed ({}) to consult authenticator: {}",
+ username, session, e.getClass().getSimpleName(), e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("doAuth(" + username + "@" + session + ") authenticator consultation failure details", e);
+ }
+ throw new RuntimeSshException(e);
+ }
+
if (log.isDebugEnabled()) {
log.debug("doAuth({}@{}) authenticate {} responses result: {}",
username, session, num, authed);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/server/auth/password/UserAuthPassword.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/password/UserAuthPassword.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/password/UserAuthPassword.java
index 35704bc..a9608c9 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/password/UserAuthPassword.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/password/UserAuthPassword.java
@@ -18,6 +18,7 @@
*/
package org.apache.sshd.server.auth.password;
+import org.apache.sshd.common.RuntimeSshException;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.Buffer;
@@ -76,7 +77,18 @@ public class UserAuthPassword extends AbstractUserAuth {
}
try {
- boolean authed = auth.authenticate(username, password, session);
+ boolean authed;
+ try {
+ authed = auth.authenticate(username, password, session);
+ } catch (Error e) {
+ log.warn("checkPassword({}) failed ({}) to consult authenticator: {}",
+ session, e.getClass().getSimpleName(), e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("checkPassword(" + session + ") authenticator failure details", e);
+ }
+
+ throw new RuntimeSshException(e);
+ }
if (log.isDebugEnabled()) {
log.debug("checkPassword({}) authentication result: {}", session, authed);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/CachingPublicKeyAuthenticator.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/CachingPublicKeyAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/CachingPublicKeyAuthenticator.java
index 61667b1..1991f70 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/CachingPublicKeyAuthenticator.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/CachingPublicKeyAuthenticator.java
@@ -22,8 +22,12 @@ import java.security.PublicKey;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import org.apache.sshd.common.RuntimeSshException;
+import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.session.SessionListener;
+import org.apache.sshd.common.util.ValidateUtils;
+import org.apache.sshd.common.util.logging.AbstractLoggingBean;
import org.apache.sshd.server.session.ServerSession;
/**
@@ -31,13 +35,13 @@ import org.apache.sshd.server.session.ServerSession;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class CachingPublicKeyAuthenticator implements PublickeyAuthenticator, SessionListener {
+public class CachingPublicKeyAuthenticator extends AbstractLoggingBean implements PublickeyAuthenticator, SessionListener {
protected final PublickeyAuthenticator authenticator;
protected final Map<ServerSession, Map<PublicKey, Boolean>> cache = new ConcurrentHashMap<ServerSession, Map<PublicKey, Boolean>>();
public CachingPublicKeyAuthenticator(PublickeyAuthenticator authenticator) {
- this.authenticator = authenticator;
+ this.authenticator = ValidateUtils.checkNotNull(authenticator, "No delegate authenticator");
}
@Override
@@ -51,8 +55,28 @@ public class CachingPublicKeyAuthenticator implements PublickeyAuthenticator, Se
Boolean result = map.get(key);
if (result == null) {
- result = authenticator.authenticate(username, key, session);
+ try {
+ result = authenticator.authenticate(username, key, session);
+ } catch (Error e) {
+ log.warn("authenticate({}@{}) failed ({}) to consult delegate for {} key={}: {}",
+ username, session, e.getClass().getSimpleName(),
+ KeyUtils.getKeyType(key), KeyUtils.getFingerPrint(key), e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("authenticate(" + username + "@" + session + ") delegate failure details", e);
+ }
+
+ throw new RuntimeSshException(e);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("authenticate({}@{}) cache result={} for {} key={}",
+ username, session, result, KeyUtils.getKeyType(key), KeyUtils.getFingerPrint(key));
+ }
map.put(key, result);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("authenticate({}@{}) use cached result={} for {} key={}",
+ username, session, result, KeyUtils.getKeyType(key), KeyUtils.getFingerPrint(key));
+ }
}
return result;
@@ -70,6 +94,12 @@ public class CachingPublicKeyAuthenticator implements PublickeyAuthenticator, Se
@Override
public void sessionClosed(Session session) {
- cache.remove(session);
+ Map<PublicKey, Boolean> map = cache.remove(session);
+ if (map == null) {
+ log.debug("sessionClosed({}) not cached", session);
+ } else {
+ log.debug("sessionClosed({}) removed from cache", session);
+ }
+ session.removeSessionListener(this);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/UserAuthPublicKey.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/UserAuthPublicKey.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/UserAuthPublicKey.java
index e00960f..4687600 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/UserAuthPublicKey.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/UserAuthPublicKey.java
@@ -25,6 +25,7 @@ import java.util.List;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.NamedResource;
+import org.apache.sshd.common.RuntimeSshException;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.signature.Signature;
@@ -106,7 +107,19 @@ public class UserAuthPublicKey extends AbstractUserAuth implements SignatureFact
return Boolean.FALSE;
}
- boolean authed = authenticator.authenticate(username, key, session);
+ boolean authed;
+ try {
+ authed = authenticator.authenticate(username, key, session);
+ } catch (Error e) {
+ log.warn("doAuth({}@{}) failed ({}) to consult delegate for {} key={}: {}",
+ username, session, e.getClass().getSimpleName(), alg, KeyUtils.getFingerPrint(key), e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("doAuth(" + username + "@" + session + ") delegate failure details", e);
+ }
+
+ throw new RuntimeSshException(e);
+ }
+
if (log.isDebugEnabled()) {
log.debug("doAuth({}@{}) key type={}, fingerprint={} - authentication result: {}",
username, session, alg, KeyUtils.getFingerPrint(key), authed);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/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 9765091..8e2f5df 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
@@ -81,7 +81,7 @@ public abstract class AbstractServerChannel extends AbstractChannel implements S
try {
listener.channelOpenSuccess(this);
f.setOpened();
- } catch (RuntimeException t) {
+ } catch (Throwable t) {
Throwable e = GenericUtils.peelException(t);
try {
listener.channelOpenFailure(this, e);
@@ -92,6 +92,14 @@ public abstract class AbstractServerChannel extends AbstractChannel implements S
if (log.isDebugEnabled()) {
log.debug("doInit(" + this + ") listener inform failure details", ignored);
}
+ if (log.isTraceEnabled()) {
+ Throwable[] suppressed = ignored.getSuppressed();
+ if (GenericUtils.length(suppressed) > 0) {
+ for (Throwable s : suppressed) {
+ log.trace("doInit(" + this + ") suppressed channel open failure signalling", s);
+ }
+ }
+ }
}
f.setException(e);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/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 1df3dff..5da3993 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
@@ -33,6 +33,7 @@ import org.apache.sshd.common.Factory;
import org.apache.sshd.common.FactoryManager;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.PropertyResolverUtils;
+import org.apache.sshd.common.RuntimeSshException;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.channel.Channel;
import org.apache.sshd.common.channel.ChannelAsyncOutputStream;
@@ -162,7 +163,7 @@ public class ChannelSession extends AbstractServerChannel {
if (command != null) {
try {
command.destroy();
- } catch (Exception e) {
+ } catch (Throwable e) {
log.warn("doCloseImmediately({}) failed ({}) to destroy command: {}",
this, e.getClass().getSimpleName(), e.getMessage());
if (log.isDebugEnabled()) {
@@ -580,11 +581,20 @@ public class ChannelSession extends AbstractServerChannel {
FactoryManager manager = ValidateUtils.checkNotNull(session.getFactoryManager(), "No session factory manager");
ForwardingFilter filter = manager.getTcpipForwardingFilter();
SshAgentFactory factory = manager.getAgentFactory();
- if ((factory == null) || (filter == null) || (!filter.canForwardAgent(session))) {
+ try {
+ if ((factory == null) || (filter == null) || (!filter.canForwardAgent(session))) {
+ if (log.isDebugEnabled()) {
+ log.debug("handleAgentForwarding(" + this + ")[haveFactory=" + (factory != null) + ",haveFilter=" + (filter != null) + "] filtered out");
+ }
+ return RequestHandler.Result.ReplyFailure;
+ }
+ } catch (Error e) {
+ log.warn("handleAgentForwarding({}) failed ({}) to consult forwarding filter: {}",
+ this, e.getClass().getSimpleName(), e.getMessage());
if (log.isDebugEnabled()) {
- log.debug("handleAgentForwarding(" + this + ")[haveFactory=" + (factory != null) + ",haveFilter=" + (filter != null) + "] filtered out");
+ log.debug("handleAgentForwarding(" + this + ") filter consultation failure details", e);
}
- return RequestHandler.Result.ReplyFailure;
+ throw new RuntimeSshException(e);
}
String authSocket = service.initAgentForward();
@@ -599,14 +609,23 @@ public class ChannelSession extends AbstractServerChannel {
String authCookie = buffer.getString();
int screenId = buffer.getInt();
- FactoryManager manager = session.getFactoryManager();
+ FactoryManager manager = ValidateUtils.checkNotNull(session.getFactoryManager(), "No factory manager");
ForwardingFilter filter = manager.getTcpipForwardingFilter();
- if ((filter == null) || (!filter.canForwardX11(session))) {
+ try {
+ if ((filter == null) || (!filter.canForwardX11(session))) {
+ if (log.isDebugEnabled()) {
+ log.debug("handleX11Forwarding({}) single={}, protocol={}, cookie={}, screen={}, filter={}: filtered",
+ this, singleConnection, authProtocol, authCookie, screenId, filter);
+ }
+ return RequestHandler.Result.ReplyFailure;
+ }
+ } catch (Error e) {
+ log.warn("handleX11Forwarding({}) failed ({}) to consult forwarding filter: {}",
+ this, e.getClass().getSimpleName(), e.getMessage());
if (log.isDebugEnabled()) {
- log.debug("handleX11Forwarding({}) single={}, protocol={}, cookie={}, screen={}, filter={}: filtered",
- this, singleConnection, authProtocol, authCookie, screenId, filter);
+ log.debug("handleX11Forwarding(" + this + ") filter consultation failure details", e);
}
- return RequestHandler.Result.ReplyFailure;
+ throw new RuntimeSshException(e);
}
String display = service.createX11Display(singleConnection, authProtocol, authCookie, screenId);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticator.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticator.java
index da09c66..e4f844a 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticator.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticator.java
@@ -80,13 +80,16 @@ public class AuthorizedKeysAuthenticator extends ModifiableFileWatcher implement
}
return accepted;
- } catch (Exception e) {
+ } catch (Throwable e) {
if (log.isDebugEnabled()) {
log.debug("authenticate(" + username + ")[" + session + "][" + getPath() + "]"
+ " failed (" + e.getClass().getSimpleName() + ")"
+ " to resolve delegate: " + e.getMessage());
}
+ if (log.isTraceEnabled()) {
+ log.trace("authenticate(" + username + ")[" + session + "][" + getPath() + "] failure details", e);
+ }
return false;
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java b/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
index acd5410..c9a3920 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
@@ -27,6 +27,7 @@ import java.util.concurrent.ExecutorService;
import org.apache.sshd.client.future.DefaultOpenFuture;
import org.apache.sshd.client.future.OpenFuture;
import org.apache.sshd.common.FactoryManager;
+import org.apache.sshd.common.RuntimeSshException;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.channel.Channel;
import org.apache.sshd.common.channel.ChannelFactory;
@@ -43,6 +44,7 @@ import org.apache.sshd.common.io.IoWriteFuture;
import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.Readable;
+import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.common.util.net.SshdSocketAddress;
@@ -106,8 +108,6 @@ public class TcpipServerChannel extends AbstractServerChannel {
@Override
protected OpenFuture doInit(Buffer buffer) {
- final OpenFuture f = new DefaultOpenFuture(this);
-
String hostToConnect = buffer.getString();
int portToConnect = buffer.getInt();
String originatorIpAddress = buffer.getString();
@@ -130,15 +130,25 @@ public class TcpipServerChannel extends AbstractServerChannel {
}
Session session = getSession();
- FactoryManager manager = session.getFactoryManager();
+ FactoryManager manager = ValidateUtils.checkNotNull(session.getFactoryManager(), "No factory manager");
ForwardingFilter filter = manager.getTcpipForwardingFilter();
- if ((address == null) || (filter == null) || (!filter.canConnect(type, address, session))) {
+ final OpenFuture f = new DefaultOpenFuture(this);
+ try {
+ if ((address == null) || (filter == null) || (!filter.canConnect(type, address, session))) {
+ if (log.isDebugEnabled()) {
+ log.debug("doInit(" + this + ")[" + type + "][haveFilter=" + (filter != null) + "] filtered out " + address);
+ }
+ super.close(true);
+ f.setException(new OpenChannelException(SshConstants.SSH_OPEN_ADMINISTRATIVELY_PROHIBITED, "Connection denied"));
+ return f;
+ }
+ } catch (Error e) {
+ log.warn("doInit({})[{}] failed ({}) to consult forwarding filter: {}",
+ session, type, e.getClass().getSimpleName(), e.getMessage());
if (log.isDebugEnabled()) {
- log.debug("doInit(" + this + ")[" + type + "][haveFilter=" + (filter != null) + "] filtered out " + address);
+ log.debug("doInit(" + this + ")[" + type + "] filter consultation failure details", e);
}
- super.close(true);
- f.setException(new OpenChannelException(SshConstants.SSH_OPEN_ADMINISTRATIVELY_PROHIBITED, "Connection denied"));
- return f;
+ throw new RuntimeSshException(e);
}
// TODO: revisit for better threading. Use async io ?
@@ -209,6 +219,14 @@ public class TcpipServerChannel extends AbstractServerChannel {
if (log.isDebugEnabled()) {
log.debug("handleChannelConnectResult(" + this + ")[exception] listener exception details", ignored);
}
+ if (log.isTraceEnabled()) {
+ Throwable[] suppressed = ignored.getSuppressed();
+ if (GenericUtils.length(suppressed) > 0) {
+ for (Throwable s : suppressed) {
+ log.trace("handleChannelConnectResult(" + this + ") suppressed channel open failure signalling", s);
+ }
+ }
+ }
}
f.setException(e);
}
@@ -218,8 +236,31 @@ public class TcpipServerChannel extends AbstractServerChannel {
ioSession = session;
ChannelListener listener = getChannelListenerProxy();
- listener.channelOpenSuccess(this);
- f.setOpened();
+ try {
+ listener.channelOpenSuccess(this);
+ f.setOpened();
+ } catch (Throwable t) {
+ Throwable e = GenericUtils.peelException(t);
+ try {
+ listener.channelOpenFailure(this, e);
+ } catch (Throwable err) {
+ Throwable ignored = GenericUtils.peelException(err);
+ log.warn("handleChannelOpenSuccess({}) failed ({}) to inform listener of open failure={}: {}",
+ this, ignored.getClass().getSimpleName(), e.getClass().getSimpleName(), ignored.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("doInit(" + this + ") listener inform failure details", ignored);
+ }
+ if (log.isTraceEnabled()) {
+ Throwable[] suppressed = ignored.getSuppressed();
+ if (GenericUtils.length(suppressed) > 0) {
+ for (Throwable s : suppressed) {
+ log.trace("handleChannelOpenSuccess(" + this + ") suppressed channel open failure signalling", s);
+ }
+ }
+ }
+ }
+ f.setException(e);
+ }
}
protected void handleChannelOpenFailure(OpenFuture f, Throwable problem) {
@@ -233,6 +274,14 @@ public class TcpipServerChannel extends AbstractServerChannel {
if (log.isDebugEnabled()) {
log.debug("handleChannelOpenFailure(" + this + ") listener inform open failure details", ignored);
}
+ if (log.isTraceEnabled()) {
+ Throwable[] suppressed = ignored.getSuppressed();
+ if (GenericUtils.length(suppressed) > 0) {
+ for (Throwable s : suppressed) {
+ log.trace("handleOpenChannelFailure(" + this + ") suppressed channel open failure signalling", s);
+ }
+ }
+ }
}
closeImmediately0();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/server/global/OpenSshHostKeysHandler.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/global/OpenSshHostKeysHandler.java b/sshd-core/src/main/java/org/apache/sshd/server/global/OpenSshHostKeysHandler.java
index 92c49b9..a1b9a23 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/global/OpenSshHostKeysHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/global/OpenSshHostKeysHandler.java
@@ -26,6 +26,7 @@ import java.util.List;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.NamedResource;
+import org.apache.sshd.common.RuntimeSshException;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.global.AbstractOpenSshHostKeysHandler;
@@ -108,7 +109,18 @@ public class OpenSshHostKeysHandler extends AbstractOpenSshHostKeysHandler imple
"No signer could be located for key type=%s",
keyType);
- KeyPair kp = ValidateUtils.checkNotNull(kpp.loadKey(keyType), "No key of type=%s available", keyType);
+ KeyPair kp;
+ try {
+ kp = ValidateUtils.checkNotNull(kpp.loadKey(keyType), "No key of type=%s available", keyType);
+ } catch (Error e) {
+ log.warn("handleHostKeys({}) failed ({}) to load key of type={}: {}",
+ session, e.getClass().getSimpleName(), keyType, e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("handleHostKey(" + session + ") " + keyType + " key load failure details", e);
+ }
+
+ throw new RuntimeSshException(e);
+ }
verifier.initSigner(kp.getPrivate());
buf.clear();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bd4add/sshd-core/src/main/java/org/apache/sshd/server/keyprovider/AbstractGeneratorHostKeyProvider.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/keyprovider/AbstractGeneratorHostKeyProvider.java b/sshd-core/src/main/java/org/apache/sshd/server/keyprovider/AbstractGeneratorHostKeyProvider.java
index de00461..fa7ca36 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/keyprovider/AbstractGeneratorHostKeyProvider.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/keyprovider/AbstractGeneratorHostKeyProvider.java
@@ -114,7 +114,7 @@ public abstract class AbstractGeneratorHostKeyProvider extends AbstractKeyPairPr
if (Files.exists(keyPath, options) && Files.isRegularFile(keyPath, options)) {
try {
keyPair = readKeyPair(keyPath, IoUtils.EMPTY_OPEN_OPTIONS);
- } catch (Exception e) {
+ } catch (Throwable e) {
log.warn("Failed ({}) to load from {}: {}",
e.getClass().getSimpleName(), keyPath, e.getMessage());
if (log.isDebugEnabled()) {
@@ -129,7 +129,7 @@ public abstract class AbstractGeneratorHostKeyProvider extends AbstractKeyPairPr
String alg = getAlgorithm();
try {
keyPair = generateKeyPair(alg);
- } catch (Exception e) {
+ } catch (Throwable e) {
log.warn("loadKeys({})[{}] Failed ({}) to generate {} key-pair: {}",
keyPath, alg, e.getClass().getSimpleName(), alg, e.getMessage());
if (log.isDebugEnabled()) {
@@ -140,7 +140,7 @@ public abstract class AbstractGeneratorHostKeyProvider extends AbstractKeyPairPr
if ((keyPair != null) && (keyPath != null)) {
try {
writeKeyPair(keyPair, keyPath);
- } catch (Exception e) {
+ } catch (Throwable e) {
log.warn("loadKeys({})[{}] Failed ({}) to write {} key: {}",
alg, keyPath, e.getClass().getSimpleName(), alg, e.getMessage());
if (log.isDebugEnabled()) {
@@ -169,7 +169,7 @@ public abstract class AbstractGeneratorHostKeyProvider extends AbstractKeyPairPr
if ((!Files.exists(keyPath)) || isOverwriteAllowed()) {
try (OutputStream os = Files.newOutputStream(keyPath, options)) {
doWriteKeyPair(keyPath.toString(), kp, os);
- } catch (Exception e) {
+ } catch (Throwable e) {
log.warn("writeKeyPair({}) failed ({}) to write key {}: {}",
keyPath, e.getClass().getSimpleName(), e.getMessage());
if (log.isDebugEnabled()) {