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 2018/11/16 17:14:42 UTC
[1/2] mina-sshd git commit: [SSHD-866] Empty challenges should not be
considered as an authentication retry attempt if 'keyboard-interactive'
method is used
Repository: mina-sshd
Updated Branches:
refs/heads/master 750afe77c -> 34ac8a7ad
[SSHD-866] Empty challenges should not be considered as an authentication retry attempt if 'keyboard-interactive' method is used
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/34ac8a7a
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/34ac8a7a
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/34ac8a7a
Branch: refs/heads/master
Commit: 34ac8a7ad6c6116674805e57f543ed247a2832ab
Parents: 01fc9fe
Author: Lyor Goldstein <lg...@apache.org>
Authored: Fri Nov 16 18:14:09 2018 +0200
Committer: Lyor Goldstein <lg...@apache.org>
Committed: Fri Nov 16 19:20:22 2018 +0200
----------------------------------------------------------------------
.../apache/sshd/common/util/GenericUtils.java | 1 +
.../keyboard/UserAuthKeyboardInteractive.java | 52 ++--
.../java/org/apache/sshd/client/ClientTest.java | 242 +++++++++++--------
3 files changed, 177 insertions(+), 118 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/34ac8a7a/sshd-common/src/main/java/org/apache/sshd/common/util/GenericUtils.java
----------------------------------------------------------------------
diff --git a/sshd-common/src/main/java/org/apache/sshd/common/util/GenericUtils.java b/sshd-common/src/main/java/org/apache/sshd/common/util/GenericUtils.java
index 4dba3f2..b772e4f 100644
--- a/sshd-common/src/main/java/org/apache/sshd/common/util/GenericUtils.java
+++ b/sshd-common/src/main/java/org/apache/sshd/common/util/GenericUtils.java
@@ -65,6 +65,7 @@ public final class GenericUtils {
public static final char[] EMPTY_CHAR_ARRAY = {};
public static final String[] EMPTY_STRING_ARRAY = {};
public static final Object[] EMPTY_OBJECT_ARRAY = {};
+ public static final boolean[] EMPTY_BOOLEAN_ARRAY = {};
/**
* A value indicating a {@code null} value - to be used as a placeholder
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/34ac8a7a/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 3622a93..c97c72d 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
@@ -87,7 +87,8 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth {
public void init(ClientSession session, String service) throws Exception {
super.init(session, service);
passwords = ClientSession.passwordIteratorOf(session);
- maxTrials = session.getIntProperty(ClientAuthenticationManager.PASSWORD_PROMPTS, ClientAuthenticationManager.DEFAULT_PASSWORD_PROMPTS);
+ maxTrials = session.getIntProperty(
+ ClientAuthenticationManager.PASSWORD_PROMPTS, ClientAuthenticationManager.DEFAULT_PASSWORD_PROMPTS);
ValidateUtils.checkTrue(maxTrials > 0, "Non-positive max. trials: %d", maxTrials);
}
@@ -98,7 +99,7 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth {
if (requestPending.get()) {
if (debugEnabled) {
log.debug("sendAuthDataRequest({})[{}] no reply for previous request for {}",
- session, service, name);
+ session, service, name);
}
return false;
}
@@ -112,7 +113,7 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth {
String subMethods = getExchangeSubMethods(session);
if (debugEnabled) {
log.debug("sendAuthDataRequest({})[{}] send SSH_MSG_USERAUTH_REQUEST for {}: lang={}, methods={}",
- session, service, name, lang, subMethods);
+ session, service, name, lang, subMethods);
}
Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_REQUEST,
@@ -134,15 +135,11 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth {
int cmd = buffer.getUByte();
if (cmd != SshConstants.SSH_MSG_USERAUTH_INFO_REQUEST) {
throw new IllegalStateException("processAuthDataRequest(" + session + ")[" + service + "]"
- + " received unknown packet: cmd=" + SshConstants.getCommandMessageName(cmd));
+ + " received unknown packet: cmd=" + SshConstants.getCommandMessageName(cmd));
}
requestPending.set(false);
- if (!verifyTrialsCount(session, service, cmd, trialsCount.incrementAndGet(), maxTrials)) {
- return false;
- }
-
String name = buffer.getString();
String instruction = buffer.getString();
String lang = buffer.getString();
@@ -150,11 +147,18 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth {
boolean debugEnabled = log.isDebugEnabled();
if (debugEnabled) {
log.debug("processAuthDataRequest({})[{}] SSH_MSG_USERAUTH_INFO_REQUEST name={}, instruction={}, language={}, num-prompts={}",
- session, service, name, instruction, lang, num);
+ session, service, name, instruction, lang, num);
}
- String[] prompt = new String[num];
- boolean[] echo = new boolean[num];
+ if (num > 0) {
+ // SSHD-866
+ if (!verifyTrialsCount(session, service, cmd, trialsCount.incrementAndGet(), maxTrials)) {
+ return false;
+ }
+ }
+
+ String[] prompt = (num > 0) ? new String[num] : GenericUtils.EMPTY_STRING_ARRAY;
+ boolean[] echo = (num > 0) ? new boolean[num] : GenericUtils.EMPTY_BOOLEAN_ARRAY;
for (int i = 0; i < num; i++) {
// according to RFC4256: "The prompt field(s) MUST NOT be empty strings."
prompt[i] = buffer.getString();
@@ -186,12 +190,13 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth {
*/
if (num != rep.length) {
log.warn("processAuthDataRequest({})[{}] Mismatched prompts ({}) vs. responses count ({})",
- session, service, num, rep.length);
+ session, service, num, rep.length);
}
- buffer = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_INFO_RESPONSE, rep.length * Long.SIZE + Byte.SIZE);
- buffer.putInt(rep.length);
- for (int index = 0; index < rep.length; index++) {
+ int numResponses = rep.length;
+ buffer = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_INFO_RESPONSE, numResponses * Long.SIZE + Byte.SIZE);
+ buffer.putInt(numResponses);
+ for (int index = 0; index < numResponses; index++) {
String r = rep[index];
if (traceEnabled) {
log.trace("processAuthDataRequest({})[{}] response #{}: {}", session, service, index + 1, r);
@@ -219,10 +224,11 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth {
}
}
- protected boolean verifyTrialsCount(ClientSession session, String service, int cmd, int nbTrials, int maxAllowed) {
+ protected boolean verifyTrialsCount(
+ ClientSession session, String service, int cmd, int nbTrials, int maxAllowed) {
if (log.isDebugEnabled()) {
log.debug("verifyTrialsCount({})[{}] cmd={} - {} out of {}",
- session, service, getAuthCommandName(cmd), nbTrials, maxAllowed);
+ session, service, getAuthCommandName(cmd), nbTrials, maxAllowed);
}
return nbTrials <= maxAllowed;
@@ -243,10 +249,18 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth {
* enforce this we do not validate the response (other than logging it as
* a warning...)
*/
- protected String[] getUserResponses(String name, String instruction, String lang, String[] prompt, boolean[] echo) {
+ protected String[] getUserResponses(
+ String name, String instruction, String lang, String[] prompt, boolean[] echo) {
ClientSession session = getClientSession();
int num = GenericUtils.length(prompt);
boolean debugEnabled = log.isDebugEnabled();
+ /*
+ * According to RFC 4256 - section 3.4
+ *
+ * In the case that the server sends a `0' num-prompts field in the
+ * request message, the client MUST send a response message with a `0'
+ * num-responses field to complete the exchange.
+ */
if (num == 0) {
if (debugEnabled) {
log.debug("getUserResponses({}) no prompts for interaction={}", session, name);
@@ -269,7 +283,7 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth {
}
} catch (Error e) {
log.warn("getUserResponses({}) failed ({}) to consult interaction: {}",
- session, e.getClass().getSimpleName(), e.getMessage());
+ session, e.getClass().getSimpleName(), e.getMessage());
if (debugEnabled) {
log.debug("getUserResponses(" + session + ") interaction consultation failure details", e);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/34ac8a7a/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 4fdfb1d..1fa090a 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
@@ -122,8 +122,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * TODO Add javadoc
- *
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@@ -306,18 +304,25 @@ public class ClientTest extends BaseTestSupport {
});
client.start();
- try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) {
- assertSame("Session established", sessionConfigValueHolder.get(), PropertyResolverUtils.getObject(session, sessionPropName));
+ try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port)
+ .verify(7L, TimeUnit.SECONDS)
+ .getSession()) {
+ assertSame("Session established",
+ sessionConfigValueHolder.get(), PropertyResolverUtils.getObject(session, sessionPropName));
session.addPasswordIdentity(getCurrentTestName());
session.auth().verify(5L, TimeUnit.SECONDS);
- assertSame("Session authenticated", sessionConfigValueHolder.get(), PropertyResolverUtils.getObject(session, sessionPropName));
+ assertSame("Session authenticated",
+ sessionConfigValueHolder.get(), PropertyResolverUtils.getObject(session, sessionPropName));
try (ChannelExec channel = session.createExecChannel(getCurrentTestName());
OutputStream stdout = new NoCloseOutputStream(System.out);
OutputStream stderr = new NoCloseOutputStream(System.err)) {
- assertSame("Channel created", channelConfigValueHolder.get(), PropertyResolverUtils.getObject(channel, channelPropName));
- assertNull("Direct channel created session prop", PropertyResolverUtils.getObject(channel.getProperties(), sessionPropName));
- assertSame("Indirect channel created session prop", sessionConfigValueHolder.get(), PropertyResolverUtils.getObject(channel, sessionPropName));
+ assertSame("Channel created",
+ channelConfigValueHolder.get(), PropertyResolverUtils.getObject(channel, channelPropName));
+ assertNull("Direct channel created session prop",
+ PropertyResolverUtils.getObject(channel.getProperties(), sessionPropName));
+ assertSame("Indirect channel created session prop",
+ sessionConfigValueHolder.get(), PropertyResolverUtils.getObject(channel, sessionPropName));
channel.setOut(stdout);
channel.setErr(stderr);
@@ -478,7 +483,9 @@ public class ClientTest extends BaseTestSupport {
}
}
- private <C extends Closeable> void testClientListener(AtomicReference<Channel> channelHolder, Class<C> channelType, Factory<? extends C> factory) throws Exception {
+ private <C extends Closeable> void testClientListener(
+ AtomicReference<Channel> channelHolder, Class<C> channelType, Factory<? extends C> factory)
+ throws Exception {
assertNull(channelType.getSimpleName() + ": Unexpected currently active channel", channelHolder.get());
try (C instance = factory.create()) {
@@ -512,76 +519,79 @@ public class ClientTest extends BaseTestSupport {
channel.setStreaming(ClientChannel.Streaming.Async);
channel.open().verify(5L, TimeUnit.SECONDS);
- final byte[] message = "0123456789\n".getBytes(StandardCharsets.UTF_8);
+ byte[] message = "0123456789\n".getBytes(StandardCharsets.UTF_8);
final int nbMessages = 1000;
try (ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
ByteArrayOutputStream baosErr = new ByteArrayOutputStream()) {
AtomicInteger writes = new AtomicInteger(nbMessages);
IoOutputStream asyncIn = channel.getAsyncIn();
- asyncIn.writePacket(new ByteArrayBuffer(message)).addListener(new SshFutureListener<IoWriteFuture>() {
- @Override
- public void operationComplete(IoWriteFuture future) {
- try {
- if (future.isWritten()) {
- if (writes.decrementAndGet() > 0) {
- asyncIn.writePacket(new ByteArrayBuffer(message)).addListener(this);
+ asyncIn.writePacket(new ByteArrayBuffer(message))
+ .addListener(new SshFutureListener<IoWriteFuture>() {
+ @Override
+ public void operationComplete(IoWriteFuture future) {
+ try {
+ if (future.isWritten()) {
+ if (writes.decrementAndGet() > 0) {
+ asyncIn.writePacket(new ByteArrayBuffer(message)).addListener(this);
+ } else {
+ asyncIn.close(false);
+ }
} else {
- asyncIn.close(false);
+ throw new SshException("Error writing", future.getException());
+ }
+ } catch (IOException e) {
+ if (!channel.isClosing()) {
+ channel.close(true);
}
- } else {
- throw new SshException("Error writing", future.getException());
- }
- } catch (IOException e) {
- if (!channel.isClosing()) {
- channel.close(true);
}
}
- }
- });
+ });
IoInputStream asyncOut = channel.getAsyncOut();
- asyncOut.read(new ByteArrayBuffer()).addListener(new SshFutureListener<IoReadFuture>() {
- @Override
- public void operationComplete(IoReadFuture future) {
- try {
- future.verify(5L, TimeUnit.SECONDS);
-
- Buffer buffer = future.getBuffer();
- baosOut.write(buffer.array(), buffer.rpos(), buffer.available());
- buffer.rpos(buffer.rpos() + buffer.available());
- buffer.compact();
- asyncOut.read(buffer).addListener(this);
- } catch (IOException e) {
- if (!channel.isClosing()) {
- channel.close(true);
+ asyncOut.read(new ByteArrayBuffer())
+ .addListener(new SshFutureListener<IoReadFuture>() {
+ @Override
+ public void operationComplete(IoReadFuture future) {
+ try {
+ future.verify(5L, TimeUnit.SECONDS);
+
+ Buffer buffer = future.getBuffer();
+ baosOut.write(buffer.array(), buffer.rpos(), buffer.available());
+ buffer.rpos(buffer.rpos() + buffer.available());
+ buffer.compact();
+ asyncOut.read(buffer).addListener(this);
+ } catch (IOException e) {
+ if (!channel.isClosing()) {
+ channel.close(true);
+ }
}
}
- }
- });
+ });
IoInputStream asyncErr = channel.getAsyncErr();
- asyncErr.read(new ByteArrayBuffer()).addListener(new SshFutureListener<IoReadFuture>() {
- @Override
- public void operationComplete(IoReadFuture future) {
- try {
- future.verify(5L, TimeUnit.SECONDS);
-
- Buffer buffer = future.getBuffer();
- baosErr.write(buffer.array(), buffer.rpos(), buffer.available());
- buffer.rpos(buffer.rpos() + buffer.available());
- buffer.compact();
- asyncErr.read(buffer).addListener(this);
- } catch (IOException e) {
- if (!channel.isClosing()) {
- channel.close(true);
+ asyncErr.read(new ByteArrayBuffer())
+ .addListener(new SshFutureListener<IoReadFuture>() {
+ @Override
+ public void operationComplete(IoReadFuture future) {
+ try {
+ future.verify(5L, TimeUnit.SECONDS);
+
+ Buffer buffer = future.getBuffer();
+ baosErr.write(buffer.array(), buffer.rpos(), buffer.available());
+ buffer.rpos(buffer.rpos() + buffer.available());
+ buffer.compact();
+ asyncErr.read(buffer).addListener(this);
+ } catch (IOException e) {
+ if (!channel.isClosing()) {
+ channel.close(true);
+ }
}
}
- }
- });
+ });
Collection<ClientChannelEvent> result =
- channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), TimeUnit.SECONDS.toMillis(15L));
+ channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), TimeUnit.SECONDS.toMillis(15L));
assertFalse("Timeout while waiting for channel closure", result.contains(ClientChannelEvent.TIMEOUT));
assertEquals("Mismatched sent and received data size", nbMessages * message.length, baosOut.size());
}
@@ -598,18 +608,19 @@ public class ClientTest extends BaseTestSupport {
Logger log = LoggerFactory.getLogger(getClass());
client.start();
try (ClientSession session = createTestClientSession()) {
- final ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
- final ByteArrayOutputStream baosErr = new ByteArrayOutputStream();
+ ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
+ ByteArrayOutputStream baosErr = new ByteArrayOutputStream();
- final ChannelExec channel = session.createExecChannel("test");
- channel.setStreaming(ClientChannel.Streaming.Async);
- OpenFuture open = channel.open();
+ try (ChannelExec channel = session.createExecChannel("test")) {
+ channel.setStreaming(ClientChannel.Streaming.Async);
+ OpenFuture open = channel.open();
- Thread.sleep(100); // Removing this line will make the test succeed
- open.addListener(new SshFutureListener<OpenFuture>() {
- @Override
- public void operationComplete(OpenFuture future) {
- channel.getAsyncOut().read(new ByteArrayBuffer())
+ Thread.sleep(100L); // Removing this line will make the test succeed
+ open.addListener(new SshFutureListener<OpenFuture>() {
+ @Override
+ public void operationComplete(OpenFuture future) {
+ channel.getAsyncOut()
+ .read(new ByteArrayBuffer())
.addListener(new SshFutureListener<IoReadFuture>() {
@Override
public void operationComplete(IoReadFuture future) {
@@ -628,7 +639,8 @@ public class ClientTest extends BaseTestSupport {
}
}
});
- channel.getAsyncErr().read(new ByteArrayBuffer())
+ channel.getAsyncErr()
+ .read(new ByteArrayBuffer())
.addListener(new SshFutureListener<IoReadFuture>() {
@Override
public void operationComplete(IoReadFuture future) {
@@ -647,10 +659,11 @@ public class ClientTest extends BaseTestSupport {
}
}
});
- }
- });
+ }
+ });
- channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), 0);
+ channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), 0);
+ }
assertNotEquals(0, baosErr.size());
}
@@ -678,7 +691,8 @@ public class ClientTest extends BaseTestSupport {
}
} catch (SshException | SshChannelClosedException e) {
// That's ok, the channel is being closed by the other side
- outputDebugMessage("%s - ignore %s: %s", getCurrentTestName(), e.getClass().getSimpleName(), e.getMessage());
+ outputDebugMessage("%s - ignore %s: %s",
+ getCurrentTestName(), e.getClass().getSimpleName(), e.getMessage());
}
Collection<ClientChannelEvent> mask = EnumSet.of(ClientChannelEvent.CLOSED);
@@ -727,7 +741,7 @@ public class ClientTest extends BaseTestSupport {
teeOut.flush();
Collection<ClientChannelEvent> result =
- channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), TimeUnit.SECONDS.toMillis(15L));
+ channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), TimeUnit.SECONDS.toMillis(15L));
assertFalse("Timeout while waiting on channel close", result.contains(ClientChannelEvent.TIMEOUT));
channel.close(false);
@@ -772,7 +786,7 @@ public class ClientTest extends BaseTestSupport {
}
Collection<ClientChannelEvent> result =
- channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), TimeUnit.SECONDS.toMillis(15L));
+ channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), TimeUnit.SECONDS.toMillis(15L));
assertFalse("Timeout while waiting on channel close", result.contains(ClientChannelEvent.TIMEOUT));
channel.close(false);
@@ -838,7 +852,7 @@ public class ClientTest extends BaseTestSupport {
}
Collection<ClientChannelEvent> result =
- channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), TimeUnit.SECONDS.toMillis(15L));
+ channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), TimeUnit.SECONDS.toMillis(15L));
assertFalse("Timeout while waiting on channel close", result.contains(ClientChannelEvent.TIMEOUT));
channel.close(false);
@@ -895,7 +909,7 @@ public class ClientTest extends BaseTestSupport {
outputDebugMessage("Waiting for channel to be closed");
Collection<ClientChannelEvent> result =
- channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), TimeUnit.SECONDS.toMillis(35L));
+ channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), TimeUnit.SECONDS.toMillis(35L));
assertFalse("Timeout while waiting on channel close", result.contains(ClientChannelEvent.TIMEOUT));
channel.close(false);
client.stop();
@@ -938,7 +952,9 @@ public class ClientTest extends BaseTestSupport {
authLatch = new CountDownLatch(1);
client.start();
- try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) {
+ try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port)
+ .verify(7L, TimeUnit.SECONDS)
+ .getSession()) {
assertNotNull("Client session creation not signalled", clientSessionHolder.get());
session.addPasswordIdentity(getCurrentTestName());
@@ -1020,9 +1036,12 @@ public class ClientTest extends BaseTestSupport {
client.setUserAuthFactories(Collections.singletonList(UserAuthPublicKeyFactory.INSTANCE));
client.start();
- try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) {
+ try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port)
+ .verify(7L, TimeUnit.SECONDS)
+ .getSession()) {
assertNotNull("Client session creation not signalled", clientSessionHolder.get());
- session.addPublicKeyIdentity(createTestHostKeyProvider().loadKey(KeyPairProvider.SSH_RSA));
+ KeyPairProvider keys = createTestHostKeyProvider();
+ session.addPublicKeyIdentity(keys.loadKey(KeyPairProvider.SSH_RSA));
session.auth().verify(5L, TimeUnit.SECONDS);
} finally {
client.stop();
@@ -1035,12 +1054,15 @@ public class ClientTest extends BaseTestSupport {
SimpleGeneratorHostKeyProvider provider = new SimpleGeneratorHostKeyProvider();
provider.setAlgorithm(KeyUtils.RSA_ALGORITHM);
- final KeyPair pair = createTestHostKeyProvider().loadKey(KeyPairProvider.SSH_RSA);
+ KeyPairProvider keys = createTestHostKeyProvider();
+ KeyPair pair = keys.loadKey(KeyPairProvider.SSH_RSA);
sshd.setPublickeyAuthenticator((username, key, session) -> key.equals(pair.getPublic()));
client.setUserAuthFactories(Collections.singletonList(UserAuthPublicKeyFactory.INSTANCE));
client.start();
- try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) {
+ try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port)
+ .verify(7L, TimeUnit.SECONDS)
+ .getSession()) {
assertNotNull("Client session creation not signalled", clientSessionHolder.get());
session.addPublicKeyIdentity(provider.loadKey(KeyPairProvider.SSH_RSA));
session.addPublicKeyIdentity(pair);
@@ -1070,7 +1092,9 @@ public class ClientTest extends BaseTestSupport {
client.setUserAuthFactories(Collections.singletonList(UserAuthPasswordFactory.INSTANCE));
client.start();
- try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) {
+ try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port)
+ .verify(7L, TimeUnit.SECONDS)
+ .getSession()) {
assertNotNull("Client session creation not signalled", clientSessionHolder.get());
session.addPasswordIdentity(getClass().getSimpleName());
session.addPasswordIdentity(getCurrentTestName());
@@ -1100,7 +1124,9 @@ public class ClientTest extends BaseTestSupport {
client.setUserAuthFactories(Collections.singletonList(UserAuthKeyboardInteractiveFactory.INSTANCE));
client.start();
- try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) {
+ try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port)
+ .verify(7L, TimeUnit.SECONDS)
+ .getSession()) {
assertNotNull("Client session creation not signalled", clientSessionHolder.get());
session.addPasswordIdentity(getClass().getSimpleName());
session.addPasswordIdentity(getCurrentTestName());
@@ -1113,13 +1139,14 @@ public class ClientTest extends BaseTestSupport {
@Test // see SSHD-504
public void testDefaultKeyboardInteractivePasswordPromptLocationIndependence() throws Exception {
- final Collection<String> mismatchedPrompts = new LinkedList<>();
+ Collection<String> mismatchedPrompts = new LinkedList<>();
client.setUserAuthFactories(Collections.singletonList(new UserAuthKeyboardInteractiveFactory() {
@Override
public UserAuthKeyboardInteractive create() {
return new UserAuthKeyboardInteractive() {
@Override
- protected boolean useCurrentPassword(String password, String name, String instruction, String lang, String[] prompt, boolean[] echo) {
+ protected boolean useCurrentPassword(
+ String password, String name, String instruction, String lang, String[] prompt, boolean[] echo) {
boolean expected = GenericUtils.length(password) > 0;
boolean actual = super.useCurrentPassword(password, name, instruction, lang, prompt, echo);
if (expected != actual) {
@@ -1167,7 +1194,9 @@ public class ClientTest extends BaseTestSupport {
try {
for (int index = 0; index < xformers.size(); index++) {
- try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7, TimeUnit.SECONDS).getSession()) {
+ try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port)
+ .verify(7, TimeUnit.SECONDS)
+ .getSession()) {
assertNotNull("Client session creation not signalled at iteration #" + index, clientSessionHolder.get());
String password = "bad-" + getCurrentTestName() + "-" + index;
session.addPasswordIdentity(password);
@@ -1216,7 +1245,8 @@ public class ClientTest extends BaseTestSupport {
}
@Override
- public String[] interactive(ClientSession session, String name, String instruction, String lang, String[] prompt, boolean[] echo) {
+ public String[] interactive(
+ ClientSession session, String name, String instruction, String lang, String[] prompt, boolean[] echo) {
validateSession("interactive", session);
count.incrementAndGet();
return badResponse;
@@ -1240,7 +1270,9 @@ public class ClientTest extends BaseTestSupport {
client.start();
- try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) {
+ try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port)
+ .verify(7L, TimeUnit.SECONDS)
+ .getSession()) {
assertNotNull("Client session creation not signalled", clientSessionHolder.get());
AuthFuture future = session.auth();
@@ -1262,7 +1294,9 @@ public class ClientTest extends BaseTestSupport {
client.setUserAuthFactories(Collections.singletonList(UserAuthKeyboardInteractiveFactory.INSTANCE));
client.start();
- try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) {
+ try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port)
+ .verify(7L, TimeUnit.SECONDS)
+ .getSession()) {
assertNotNull("Client session creation not signalled", clientSessionHolder.get());
AtomicInteger count = new AtomicInteger();
session.setUserInteraction(new UserInteraction() {
@@ -1282,7 +1316,8 @@ public class ClientTest extends BaseTestSupport {
}
@Override
- public String[] interactive(ClientSession clientSession, String name, String instruction, String lang, String[] prompt, boolean[] echo) {
+ public String[] interactive(
+ ClientSession clientSession, String name, String instruction, String lang, String[] prompt, boolean[] echo) {
assertSame("Mismatched interactive session", session, clientSession);
count.incrementAndGet();
return new String[]{getCurrentTestName()};
@@ -1313,7 +1348,9 @@ public class ClientTest extends BaseTestSupport {
client.setUserAuthFactories(Collections.singletonList(UserAuthKeyboardInteractiveFactory.INSTANCE));
client.start();
- try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) {
+ try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port)
+ .verify(7L, TimeUnit.SECONDS)
+ .getSession()) {
assertNotNull("Client session creation not signalled", clientSessionHolder.get());
AtomicInteger count = new AtomicInteger();
session.setUserInteraction(new UserInteraction() {
@@ -1333,7 +1370,8 @@ public class ClientTest extends BaseTestSupport {
}
@Override
- public String[] interactive(ClientSession clientSession, String name, String instruction, String lang, String[] prompt, boolean[] echo) {
+ public String[] interactive(
+ ClientSession clientSession, String name, String instruction, String lang, String[] prompt, boolean[] echo) {
assertSame("Mismatched interactive session", session, clientSession);
int attemptId = count.incrementAndGet();
return new String[]{"bad#" + attemptId};
@@ -1407,10 +1445,12 @@ public class ClientTest extends BaseTestSupport {
);
client.start();
- try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) {
+ try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port)
+ .verify(7L, TimeUnit.SECONDS)
+ .getSession()) {
assertNotNull("Client session creation not signalled", clientSessionHolder.get());
Collection<ClientSession.ClientSessionEvent> result =
- session.waitFor(EnumSet.of(ClientSession.ClientSessionEvent.WAIT_AUTH), TimeUnit.SECONDS.toMillis(10L));
+ session.waitFor(EnumSet.of(ClientSession.ClientSessionEvent.WAIT_AUTH), TimeUnit.SECONDS.toMillis(10L));
assertFalse("Timeout while waiting on channel close", result.contains(ClientSession.ClientSessionEvent.TIMEOUT));
assertTrue("Server key verifier invoked ?", ok.get());
} finally {
@@ -1456,13 +1496,15 @@ public class ClientTest extends BaseTestSupport {
try {
testConnectUsingIPv6Address(SshdSocketAddress.IPV6_SHORT_LOCALHOST);
- for (Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); (nets != null) && nets.hasMoreElements();) {
+ for (Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
+ (nets != null) && nets.hasMoreElements();) {
NetworkInterface netint = nets.nextElement();
if (!netint.isUp()) {
continue; // ignore non-running interfaces
}
- for (Enumeration<InetAddress> inetAddresses = netint.getInetAddresses(); (inetAddresses != null) && inetAddresses.hasMoreElements();) {
+ for (Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
+ (inetAddresses != null) && inetAddresses.hasMoreElements();) {
InetAddress inetAddress = inetAddresses.nextElement();
if (!(inetAddress instanceof Inet6Address)) {
continue;
@@ -1504,7 +1546,9 @@ public class ClientTest extends BaseTestSupport {
}
private ClientSession createTestClientSession(String host) throws IOException {
- ClientSession session = client.connect(getCurrentTestName(), host, port).verify(7L, TimeUnit.SECONDS).getSession();
+ ClientSession session = client.connect(getCurrentTestName(), host, port)
+ .verify(7L, TimeUnit.SECONDS)
+ .getSession();
try {
assertNotNull("Client session creation not signalled", clientSessionHolder.get());
session.addPasswordIdentity(getCurrentTestName());
[2/2] mina-sshd git commit: [SSHD-867] HostConfigEntry#getProperty
may return null even if defaultValue != null
Posted by lg...@apache.org.
[SSHD-867] HostConfigEntry#getProperty may return null even if defaultValue != null
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/01fc9fec
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/01fc9fec
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/01fc9fec
Branch: refs/heads/master
Commit: 01fc9fec8d9790767b5def1f6aad21922a25ba29
Parents: 750afe7
Author: Lyor Goldstein <lg...@apache.org>
Authored: Fri Nov 16 17:43:23 2018 +0200
Committer: Lyor Goldstein <lg...@apache.org>
Committed: Fri Nov 16 19:20:22 2018 +0200
----------------------------------------------------------------------
.../java/org/apache/sshd/client/config/hosts/HostConfigEntry.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/01fc9fec/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/HostConfigEntry.java
----------------------------------------------------------------------
diff --git a/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/HostConfigEntry.java b/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/HostConfigEntry.java
index 90b6549..eafedd8 100644
--- a/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/HostConfigEntry.java
+++ b/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/HostConfigEntry.java
@@ -283,7 +283,7 @@ public class HostConfigEntry extends HostPatternsHolder implements MutableUserHo
String key = ValidateUtils.checkNotNullAndNotEmpty(name, "No property name");
Map<String, String> props = getProperties();
if (GenericUtils.isEmpty(props)) {
- return null;
+ return defaultValue;
}
String value = props.get(key);