try (ClientSession session = cf.getSession()) { for (KeyPair pair : provider.getKeys()) { CLI.LOGGER.log(FINE, "Offering {0} private key", pair.getPrivate().getAlgorithm());
ClientSession session = client.connect("localhost", port).await().getSession(); session.authPassword("root", "");
protected ClientSession authSession(ConnectFuture future, String password) throws IOException { ClientSession session = future.getSession(); session.addPasswordIdentity(password); return authSession(session); }
protected ClientSession authSession(ConnectFuture future, KeyPair identity) throws IOException { ClientSession session = future.getSession(); session.addPublicKeyIdentity(identity); return authSession(session); }
protected ClientSession authSession(ConnectFuture future, String password) throws IOException { ClientSession session = future.getSession(); session.addPasswordIdentity(password); return authSession(session); }
protected ClientSession authSession(ConnectFuture future, KeyPair identity) throws IOException { ClientSession session = future.getSession(); session.addPublicKeyIdentity(identity); return authSession(session); }
@Override public void connect(String hostname, String username, String password, Long port, Long timeout) throws IOException { if (port == null) port = 22l; if (timeout == null) timeout = 10000l; if (sftp != null) return; ClientSession session = client.connect(username, hostname, port.intValue()).verify(timeout.intValue()).getSession(); session.addPasswordIdentity(password); session.auth().verify(timeout.intValue()); sftp = session.createSftpClient(); }
@Test public void testAuthenticationTimeout() throws Exception { final long testAuthTimeout = TimeUnit.SECONDS.toMillis(5L); PropertyResolverUtils.updateProperty(sshd, FactoryManager.AUTH_TIMEOUT, testAuthTimeout); sshd.start(); client.start(); try (ClientSession s = client.connect(getCurrentTestName(), TEST_LOCALHOST, sshd.getPort()).verify(7L, TimeUnit.SECONDS).getSession()) { Collection<ClientSession.ClientSessionEvent> res = s.waitFor(EnumSet.of(ClientSession.ClientSessionEvent.CLOSED), 2L * testAuthTimeout); assertTrue("Session should be closed: " + res, res.containsAll(EnumSet.of(ClientSession.ClientSessionEvent.CLOSED, ClientSession.ClientSessionEvent.WAIT_AUTH))); } finally { client.stop(); } }
@Test public void testAuthenticationTimeout() throws Exception { final long testAuthTimeout = TimeUnit.SECONDS.toMillis(5L); PropertyResolverUtils.updateProperty(sshd, FactoryManager.AUTH_TIMEOUT, testAuthTimeout); sshd.start(); client.start(); try (ClientSession s = client.connect(getCurrentTestName(), TEST_LOCALHOST, sshd.getPort()).verify(7L, TimeUnit.SECONDS).getSession()) { Collection<ClientSession.ClientSessionEvent> res = s.waitFor(EnumSet.of(ClientSession.ClientSessionEvent.CLOSED), 2L * testAuthTimeout); assertTrue("Session should be closed: " + res, res.containsAll(EnumSet.of(ClientSession.ClientSessionEvent.CLOSED, ClientSession.ClientSessionEvent.WAIT_AUTH))); } finally { client.stop(); } }
private void testKexFutureExceptionPropagation(String failureType, AtomicBoolean successFlag, SshClient client) throws Exception { try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); successFlag.set(false); KeyExchangeFuture kexFuture = session.switchToNoneCipher(); assertTrue(failureType + ": failed to complete KEX on time", kexFuture.await(7L, TimeUnit.SECONDS)); assertNotNull(failureType + ": unexpected success", kexFuture.getException()); } }
private void testKexFutureExceptionPropagation(String failureType, AtomicBoolean successFlag, SshClient client) throws Exception { try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); successFlag.set(false); KeyExchangeFuture kexFuture = session.switchToNoneCipher(); assertTrue(failureType + ": failed to complete KEX on time", kexFuture.await(7L, TimeUnit.SECONDS)); assertNotNull(failureType + ": unexpected success", kexFuture.getException()); } }
private void testKexFutureExceptionPropagation(String failureType, AtomicBoolean successFlag, SshClient client) throws Exception { try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); successFlag.set(false); KeyExchangeFuture kexFuture = session.switchToNoneCipher(); assertTrue(failureType + ": failed to complete KEX on time", kexFuture.await(7L, TimeUnit.SECONDS)); assertNotNull(failureType + ": unexpected success", kexFuture.getException()); } }
@Test public void testWrongPassword() throws Exception { try (SshClient client = setupTestClient()) { client.start(); try (ClientSession s = client.connect("user", TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { s.addPasswordIdentity("bad password"); assertAuthenticationResult(getCurrentTestName(), s.auth(), false); } } }
@Test public void testWrongPassword() throws Exception { try (SshClient client = setupTestClient()) { client.start(); try (ClientSession s = client.connect("user", TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { s.addPasswordIdentity("bad password"); assertAuthenticationResult(getCurrentTestName(), s.auth(), false); } } }
@Test public void testWrongPassword() throws Exception { try (SshClient client = setupTestClient()) { client.start(); try (ClientSession s = client.connect("user", TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { s.addPasswordIdentity("bad password"); assertAuthenticationResult(getCurrentTestName(), s.auth(), false); } } }
private ClientSession createTestClientSession(SshServer server) throws Exception { ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, server.getPort()).verify(7L, TimeUnit.SECONDS).getSession(); try { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); ClientSession returnValue = session; session = null; // avoid 'finally' close return returnValue; } finally { if (session != null) { session.close(); } } }
private ClientSession createTestClientSession(SshServer server) throws Exception { ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, server.getPort()).verify(7L, TimeUnit.SECONDS).getSession(); try { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); ClientSession returnValue = session; session = null; // avoid 'finally' close return returnValue; } finally { if (session != null) { session.close(); } } }
protected ClientSession createNativeSession() throws Exception { client = setupTestClient(); PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 2048); PropertyResolverUtils.updateProperty(client, FactoryManager.MAX_PACKET_SIZE, 256); client.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE); client.start(); ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, sshPort).verify(7L, TimeUnit.SECONDS).getSession(); session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(11L, TimeUnit.SECONDS); return session; } }
protected ClientSession createNativeSession() throws Exception { client = setupTestClient(); PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 2048); PropertyResolverUtils.updateProperty(client, FactoryManager.MAX_PACKET_SIZE, 256); client.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE); client.start(); ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, sshPort).verify(7L, TimeUnit.SECONDS).getSession(); session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(11L, TimeUnit.SECONDS); return session; } }
protected ClientSession createNativeSession() throws Exception { client = setupTestClient(); PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 2048); PropertyResolverUtils.updateProperty(client, FactoryManager.MAX_PACKET_SIZE, 256); client.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE); client.start(); ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, sshPort).verify(7L, TimeUnit.SECONDS).getSession(); session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(11L, TimeUnit.SECONDS); return session; } }