org.apache.sshd.common.util.net.SshdSocketAddress Java Examples
The following examples show how to use
org.apache.sshd.common.util.net.SshdSocketAddress.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SSHUtilTest.java From xenon with Apache License 2.0 | 6 votes |
@Test public void test_extractCredentials_double() throws CredentialNotFoundException { SshdSocketAddress[] address = new SshdSocketAddress[] { new SshdSocketAddress("somehost", 33), new SshdSocketAddress("somehost", 44) }; DefaultCredential dc = new DefaultCredential(); PasswordCredential pc = new PasswordCredential("aap", "noot".toCharArray()); CredentialMap cm = new CredentialMap(); cm.put("somehost:33", pc); cm.put("somehost", dc); Credential[] c = SSHUtil.extractCredentials("test", address, cm); assertNotNull(c); assertEquals(2, c.length); assertEquals(pc, c[0]); assertEquals(dc, c[1]); }
Example #2
Source File: SSHUtilTest.java From xenon with Apache License 2.0 | 6 votes |
@Test public void test_extractCredentials_single() throws CredentialNotFoundException { SshdSocketAddress[] address = new SshdSocketAddress[] { new SshdSocketAddress("somehost", 33) }; DefaultCredential dc = new DefaultCredential(); PasswordCredential pc = new PasswordCredential("aap", "noot".toCharArray()); CredentialMap cm = new CredentialMap(); cm.put("somehost:33", pc); cm.put("somehost", dc); Credential[] c = SSHUtil.extractCredentials("test", address, cm); assertNotNull(c); assertEquals(1, c.length); assertEquals(pc, c[0]); }
Example #3
Source File: PortForwardingTest.java From termd with Apache License 2.0 | 6 votes |
@Test public void testForwardingChannel() throws Exception { try (ClientSession session = createNativeSession()) { SshdSocketAddress local = new SshdSocketAddress("", 0); SshdSocketAddress remote = new SshdSocketAddress(TEST_LOCALHOST, echoPort); try (ChannelDirectTcpip channel = session.createDirectTcpipChannel(local, remote)) { channel.open().verify(9L, TimeUnit.SECONDS); String expected = getCurrentTestName(); byte[] bytes = expected.getBytes(StandardCharsets.UTF_8); try (OutputStream output = channel.getInvertedIn(); InputStream input = channel.getInvertedOut()) { output.write(bytes); output.flush(); byte[] buf = new byte[bytes.length + Long.SIZE]; int n = input.read(buf); String res = new String(buf, 0, n); assertEquals("Mismatched data", expected, res); } channel.close(false); } } }
Example #4
Source File: PortForwardingTest.java From termd with Apache License 2.0 | 6 votes |
@Test public void testForwardingChannel() throws Exception { try (ClientSession session = createNativeSession()) { SshdSocketAddress local = new SshdSocketAddress("", 0); SshdSocketAddress remote = new SshdSocketAddress(TEST_LOCALHOST, echoPort); try (ChannelDirectTcpip channel = session.createDirectTcpipChannel(local, remote)) { channel.open().verify(9L, TimeUnit.SECONDS); String expected = getCurrentTestName(); byte[] bytes = expected.getBytes(StandardCharsets.UTF_8); try (OutputStream output = channel.getInvertedIn(); InputStream input = channel.getInvertedOut()) { output.write(bytes); output.flush(); byte[] buf = new byte[bytes.length + Long.SIZE]; int n = input.read(buf); String res = new String(buf, 0, n); assertEquals("Mismatched data", expected, res); } channel.close(false); } } }
Example #5
Source File: PortForwardingTest.java From termd with Apache License 2.0 | 5 votes |
@Test public void testRemoteForwardingNative() throws Exception { try (ClientSession session = createNativeSession()) { SshdSocketAddress remote = new SshdSocketAddress("", 0); SshdSocketAddress local = new SshdSocketAddress(TEST_LOCALHOST, echoPort); SshdSocketAddress bound = session.startRemotePortForwarding(remote, local); try (Socket s = new Socket(bound.getHostName(), bound.getPort()); OutputStream output = s.getOutputStream(); InputStream input = s.getInputStream()) { s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L)); String expected = getCurrentTestName(); byte[] bytes = expected.getBytes(StandardCharsets.UTF_8); output.write(bytes); output.flush(); byte[] buf = new byte[bytes.length + Long.SIZE]; int n = input.read(buf); String res = new String(buf, 0, n); assertEquals("Mismatched data", expected, res); } finally { session.stopRemotePortForwarding(remote); } } }
Example #6
Source File: SSHUtilTest.java From xenon with Apache License 2.0 | 5 votes |
@Test(expected = CredentialNotFoundException.class) public void test_extractCredentials_not_found() throws CredentialNotFoundException { SshdSocketAddress[] address = new SshdSocketAddress[] { new SshdSocketAddress("aap", 33) }; DefaultCredential dc = new DefaultCredential(); PasswordCredential pc = new PasswordCredential("aap", "noot".toCharArray()); CredentialMap cm = new CredentialMap(); cm.put("somehost:33", pc); cm.put("somehost", dc); SSHUtil.extractCredentials("test", address, cm); }
Example #7
Source File: SSHUtilTest.java From xenon with Apache License 2.0 | 5 votes |
@Test public void test_extractCredential_mapNotFound() { SshdSocketAddress address = new SshdSocketAddress("someOtherHost", 33); DefaultCredential dc = new DefaultCredential(); PasswordCredential pc = new PasswordCredential("aap", "noot".toCharArray()); CredentialMap cm = new CredentialMap(); cm.put("somehost:33", pc); cm.put("somehost", dc); Credential c = SSHUtil.extractCredential(address, cm); assertNull(c); }
Example #8
Source File: SSHUtilTest.java From xenon with Apache License 2.0 | 5 votes |
@Test public void test_extractCredential_mapWithoutPort() { SshdSocketAddress address = new SshdSocketAddress("somehost", 44); DefaultCredential dc = new DefaultCredential(); PasswordCredential pc = new PasswordCredential("aap", "noot".toCharArray()); CredentialMap cm = new CredentialMap(); cm.put("somehost:33", pc); cm.put("somehost", dc); Credential c = SSHUtil.extractCredential(address, cm); assertNotNull(c); assertEquals(dc, c); }
Example #9
Source File: SSHUtilTest.java From xenon with Apache License 2.0 | 5 votes |
@Test public void test_extractCredential_mapWithPort() { SshdSocketAddress address = new SshdSocketAddress("somehost", 33); DefaultCredential dc = new DefaultCredential(); PasswordCredential pc = new PasswordCredential("aap", "noot".toCharArray()); CredentialMap cm = new CredentialMap(); cm.put("somehost:33", pc); cm.put("somehost", dc); Credential c = SSHUtil.extractCredential(address, cm); assertNotNull(c); assertEquals(pc, c); }
Example #10
Source File: SSHUtilTest.java From xenon with Apache License 2.0 | 5 votes |
@Test public void test_extractCredential_direct() { SshdSocketAddress address = new SshdSocketAddress("somehost", 33); DefaultCredential dc = new DefaultCredential(); Credential c = SSHUtil.extractCredential(address, dc); assertNotNull(c); assertEquals(dc, c); }
Example #11
Source File: SSHUtilTest.java From xenon with Apache License 2.0 | 5 votes |
@Test public void test_extractCredential_null() { SshdSocketAddress address = new SshdSocketAddress("somehost", 33); Credential c = SSHUtil.extractCredential(address, null); assertNull(c); }
Example #12
Source File: SSHUtilTest.java From xenon with Apache License 2.0 | 5 votes |
@Test public void test_extractLocations_dualLocationWhitespace() throws InvalidLocationException { SshdSocketAddress[] expected = new SshdSocketAddress[] { new SshdSocketAddress("somehost", 33), new SshdSocketAddress("localhost", 22) }; SshdSocketAddress[] result = SSHUtil.extractLocations("Test", "localhost:22/tmp via: somehost:33"); assertArrayEquals(expected, result); }
Example #13
Source File: SSHUtilTest.java From xenon with Apache License 2.0 | 5 votes |
@Test public void test_extractLocations_quadLocation() throws InvalidLocationException { SshdSocketAddress[] expected = new SshdSocketAddress[] { new SshdSocketAddress("cloudhost", 55), new SshdSocketAddress("myhost", 44), new SshdSocketAddress("somehost", 33), new SshdSocketAddress("localhost", 22) }; SshdSocketAddress[] result = SSHUtil.extractLocations("Test", "localhost:22/tmp via:somehost:33 via:myhost:44 via:cloudhost:55"); assertArrayEquals(expected, result); }
Example #14
Source File: SSHUtilTest.java From xenon with Apache License 2.0 | 5 votes |
@Test public void test_extractLocations_dualLocation() throws InvalidLocationException { SshdSocketAddress[] expected = new SshdSocketAddress[] { new SshdSocketAddress("somehost", 33), new SshdSocketAddress("localhost", 22) }; SshdSocketAddress[] result = SSHUtil.extractLocations("Test", "localhost:22/tmp via:somehost:33"); assertArrayEquals(expected, result); }
Example #15
Source File: SSHUtilTest.java From xenon with Apache License 2.0 | 5 votes |
@Test public void test_extractLocations_singleLocationNoPort() throws InvalidLocationException { SshdSocketAddress[] expected = new SshdSocketAddress[] { new SshdSocketAddress("localhost", 22) }; SshdSocketAddress[] result = SSHUtil.extractLocations("Test", "localhost/tmp"); assertArrayEquals(expected, result); }
Example #16
Source File: SSHUtilTest.java From xenon with Apache License 2.0 | 5 votes |
@Test public void test_extractLocations_singleLocation() throws InvalidLocationException { SshdSocketAddress[] expected = new SshdSocketAddress[] { new SshdSocketAddress("localhost", 22) }; SshdSocketAddress[] result = SSHUtil.extractLocations("Test", "localhost:22/tmp"); assertArrayEquals(expected, result); }
Example #17
Source File: SSHUtil.java From xenon with Apache License 2.0 | 5 votes |
public static UserCredential[] extractCredentials(String adaptorName, SshdSocketAddress[] locations, Credential credentials) throws CredentialNotFoundException { UserCredential[] result = new UserCredential[locations.length]; for (int i = 0; i < locations.length; i++) { result[i] = extractCredential(locations[i], credentials); if (result[i] == null) { throw new CredentialNotFoundException(adaptorName, "No credential provided for location: " + locations[i]); } } return result; }
Example #18
Source File: AuthenticationTest.java From termd with Apache License 2.0 | 5 votes |
@Test // see SSHD-620 public void testHostBasedAuthentication() throws Exception { final String hostClienUser = getClass().getSimpleName(); final String hostClientName = SshdSocketAddress.toAddressString(SshdSocketAddress.getFirstExternalNetwork4Address()); final KeyPair hostClientKey = Utils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024); final AtomicInteger invocationCount = new AtomicInteger(0); sshd.setHostBasedAuthenticator(new HostBasedAuthenticator() { @Override public boolean authenticate(ServerSession session, String username, PublicKey clientHostKey, String clientHostName, String clientUsername, List<X509Certificate> certificates) { invocationCount.incrementAndGet(); return hostClienUser.equals(clientUsername) && hostClientName.equals(clientHostName) && KeyUtils.compareKeys(hostClientKey.getPublic(), clientHostKey); } }); sshd.setPasswordAuthenticator(RejectAllPasswordAuthenticator.INSTANCE); sshd.setKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator.NONE); sshd.setPublickeyAuthenticator(RejectAllPublickeyAuthenticator.INSTANCE); sshd.setUserAuthFactories( Collections.<NamedFactory<org.apache.sshd.server.auth.UserAuth>>singletonList( org.apache.sshd.server.auth.hostbased.UserAuthHostBasedFactory.INSTANCE)); try (SshClient client = setupTestClient()) { org.apache.sshd.client.auth.hostbased.UserAuthHostBasedFactory factory = new org.apache.sshd.client.auth.hostbased.UserAuthHostBasedFactory(); // TODO factory.setClientHostname(CLIENT_HOSTNAME); factory.setClientUsername(hostClienUser); factory.setClientHostKeys(HostKeyIdentityProvider.Utils.wrap(hostClientKey)); client.setUserAuthFactories(Collections.<NamedFactory<org.apache.sshd.client.auth.UserAuth>>singletonList(factory)); client.start(); try (ClientSession s = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { s.auth().verify(11L, TimeUnit.SECONDS); assertEquals("Mismatched authenticator invocation count", 1, invocationCount.get()); } finally { client.stop(); } } }
Example #19
Source File: PortForwardingTest.java From termd with Apache License 2.0 | 5 votes |
@Test public void testRemoteForwardingNativeBigPayload() throws Exception { try (ClientSession session = createNativeSession()) { SshdSocketAddress remote = new SshdSocketAddress("", 0); SshdSocketAddress local = new SshdSocketAddress(TEST_LOCALHOST, echoPort); SshdSocketAddress bound = session.startRemotePortForwarding(remote, local); try (Socket s = new Socket(bound.getHostName(), bound.getPort()); OutputStream output = s.getOutputStream(); InputStream input = s.getInputStream()) { s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L)); String expected = getCurrentTestName(); byte[] bytes = expected.getBytes(StandardCharsets.UTF_8); byte[] buf = new byte[bytes.length + Long.SIZE]; for (int i = 0; i < 1000; i++) { output.write(bytes); output.flush(); int n = input.read(buf); String res = new String(buf, 0, n); assertEquals("Mismatched data at iteration #" + i, expected, res); } } finally { session.stopRemotePortForwarding(remote); } } }
Example #20
Source File: PortForwardingTest.java From termd with Apache License 2.0 | 5 votes |
@Test public void testLocalForwardingNative() throws Exception { try (ClientSession session = createNativeSession()) { SshdSocketAddress local = new SshdSocketAddress("", 0); SshdSocketAddress remote = new SshdSocketAddress(TEST_LOCALHOST, echoPort); SshdSocketAddress bound = session.startLocalPortForwarding(local, remote); try (Socket s = new Socket(bound.getHostName(), bound.getPort()); OutputStream output = s.getOutputStream(); InputStream input = s.getInputStream()) { s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L)); String expected = getCurrentTestName(); byte[] bytes = expected.getBytes(StandardCharsets.UTF_8); output.write(bytes); output.flush(); byte[] buf = new byte[bytes.length + Long.SIZE]; int n = input.read(buf); String res = new String(buf, 0, n); assertEquals("Mismatched data", expected, res); } finally { session.stopLocalPortForwarding(bound); } } }
Example #21
Source File: PortForwardingTest.java From termd with Apache License 2.0 | 5 votes |
@Test public void testLocalForwardingNativeReuse() throws Exception { try (ClientSession session = createNativeSession()) { SshdSocketAddress local = new SshdSocketAddress("", 0); SshdSocketAddress remote = new SshdSocketAddress(TEST_LOCALHOST, echoPort); SshdSocketAddress bound = session.startLocalPortForwarding(local, remote); session.stopLocalPortForwarding(bound); SshdSocketAddress bound2 = session.startLocalPortForwarding(local, remote); session.stopLocalPortForwarding(bound2); } }
Example #22
Source File: PortForwardingTest.java From termd with Apache License 2.0 | 5 votes |
@Test public void testLocalForwardingNativeBigPayload() throws Exception { try (ClientSession session = createNativeSession()) { String expected = getCurrentTestName(); byte[] bytes = expected.getBytes(StandardCharsets.UTF_8); byte[] buf = new byte[bytes.length + Long.SIZE]; SshdSocketAddress local = new SshdSocketAddress("", 0); SshdSocketAddress remote = new SshdSocketAddress(TEST_LOCALHOST, echoPort); SshdSocketAddress bound = session.startLocalPortForwarding(local, remote); try (Socket s = new Socket(bound.getHostName(), bound.getPort()); OutputStream output = s.getOutputStream(); InputStream input = s.getInputStream()) { s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L)); for (int i = 0; i < 1000; i++) { output.write(bytes); output.flush(); int n = input.read(buf); String res = new String(buf, 0, n); assertEquals("Mismatched data at iteration #" + i, expected, res); } } finally { session.stopLocalPortForwarding(bound); } } }
Example #23
Source File: AuthenticationTest.java From termd with Apache License 2.0 | 5 votes |
@Test // see SSHD-620 public void testHostBasedAuthentication() throws Exception { final String hostClienUser = getClass().getSimpleName(); final String hostClientName = SshdSocketAddress.toAddressString(SshdSocketAddress.getFirstExternalNetwork4Address()); final KeyPair hostClientKey = Utils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024); final AtomicInteger invocationCount = new AtomicInteger(0); sshd.setHostBasedAuthenticator(new HostBasedAuthenticator() { @Override public boolean authenticate(ServerSession session, String username, PublicKey clientHostKey, String clientHostName, String clientUsername, List<X509Certificate> certificates) { invocationCount.incrementAndGet(); return hostClienUser.equals(clientUsername) && hostClientName.equals(clientHostName) && KeyUtils.compareKeys(hostClientKey.getPublic(), clientHostKey); } }); sshd.setPasswordAuthenticator(RejectAllPasswordAuthenticator.INSTANCE); sshd.setKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator.NONE); sshd.setPublickeyAuthenticator(RejectAllPublickeyAuthenticator.INSTANCE); sshd.setUserAuthFactories( Collections.<NamedFactory<org.apache.sshd.server.auth.UserAuth>>singletonList( org.apache.sshd.server.auth.hostbased.UserAuthHostBasedFactory.INSTANCE)); try (SshClient client = setupTestClient()) { org.apache.sshd.client.auth.hostbased.UserAuthHostBasedFactory factory = new org.apache.sshd.client.auth.hostbased.UserAuthHostBasedFactory(); // TODO factory.setClientHostname(CLIENT_HOSTNAME); factory.setClientUsername(hostClienUser); factory.setClientHostKeys(HostKeyIdentityProvider.Utils.wrap(hostClientKey)); client.setUserAuthFactories(Collections.<NamedFactory<org.apache.sshd.client.auth.UserAuth>>singletonList(factory)); client.start(); try (ClientSession s = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { s.auth().verify(11L, TimeUnit.SECONDS); assertEquals("Mismatched authenticator invocation count", 1, invocationCount.get()); } finally { client.stop(); } } }
Example #24
Source File: PortForwardingTest.java From termd with Apache License 2.0 | 5 votes |
@Test public void testRemoteForwardingNative() throws Exception { try (ClientSession session = createNativeSession()) { SshdSocketAddress remote = new SshdSocketAddress("", 0); SshdSocketAddress local = new SshdSocketAddress(TEST_LOCALHOST, echoPort); SshdSocketAddress bound = session.startRemotePortForwarding(remote, local); try (Socket s = new Socket(bound.getHostName(), bound.getPort()); OutputStream output = s.getOutputStream(); InputStream input = s.getInputStream()) { s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L)); String expected = getCurrentTestName(); byte[] bytes = expected.getBytes(StandardCharsets.UTF_8); output.write(bytes); output.flush(); byte[] buf = new byte[bytes.length + Long.SIZE]; int n = input.read(buf); String res = new String(buf, 0, n); assertEquals("Mismatched data", expected, res); } finally { session.stopRemotePortForwarding(remote); } } }
Example #25
Source File: PortForwardingTest.java From termd with Apache License 2.0 | 5 votes |
@Test public void testRemoteForwardingNativeBigPayload() throws Exception { try (ClientSession session = createNativeSession()) { SshdSocketAddress remote = new SshdSocketAddress("", 0); SshdSocketAddress local = new SshdSocketAddress(TEST_LOCALHOST, echoPort); SshdSocketAddress bound = session.startRemotePortForwarding(remote, local); try (Socket s = new Socket(bound.getHostName(), bound.getPort()); OutputStream output = s.getOutputStream(); InputStream input = s.getInputStream()) { s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L)); String expected = getCurrentTestName(); byte[] bytes = expected.getBytes(StandardCharsets.UTF_8); byte[] buf = new byte[bytes.length + Long.SIZE]; for (int i = 0; i < 1000; i++) { output.write(bytes); output.flush(); int n = input.read(buf); String res = new String(buf, 0, n); assertEquals("Mismatched data at iteration #" + i, expected, res); } } finally { session.stopRemotePortForwarding(remote); } } }
Example #26
Source File: PortForwardingTest.java From termd with Apache License 2.0 | 5 votes |
@Test public void testLocalForwardingNative() throws Exception { try (ClientSession session = createNativeSession()) { SshdSocketAddress local = new SshdSocketAddress("", 0); SshdSocketAddress remote = new SshdSocketAddress(TEST_LOCALHOST, echoPort); SshdSocketAddress bound = session.startLocalPortForwarding(local, remote); try (Socket s = new Socket(bound.getHostName(), bound.getPort()); OutputStream output = s.getOutputStream(); InputStream input = s.getInputStream()) { s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L)); String expected = getCurrentTestName(); byte[] bytes = expected.getBytes(StandardCharsets.UTF_8); output.write(bytes); output.flush(); byte[] buf = new byte[bytes.length + Long.SIZE]; int n = input.read(buf); String res = new String(buf, 0, n); assertEquals("Mismatched data", expected, res); } finally { session.stopLocalPortForwarding(bound); } } }
Example #27
Source File: PortForwardingTest.java From termd with Apache License 2.0 | 5 votes |
@Test public void testLocalForwardingNativeReuse() throws Exception { try (ClientSession session = createNativeSession()) { SshdSocketAddress local = new SshdSocketAddress("", 0); SshdSocketAddress remote = new SshdSocketAddress(TEST_LOCALHOST, echoPort); SshdSocketAddress bound = session.startLocalPortForwarding(local, remote); session.stopLocalPortForwarding(bound); SshdSocketAddress bound2 = session.startLocalPortForwarding(local, remote); session.stopLocalPortForwarding(bound2); } }
Example #28
Source File: PortForwardingTest.java From termd with Apache License 2.0 | 5 votes |
@Test public void testLocalForwardingNativeBigPayload() throws Exception { try (ClientSession session = createNativeSession()) { String expected = getCurrentTestName(); byte[] bytes = expected.getBytes(StandardCharsets.UTF_8); byte[] buf = new byte[bytes.length + Long.SIZE]; SshdSocketAddress local = new SshdSocketAddress("", 0); SshdSocketAddress remote = new SshdSocketAddress(TEST_LOCALHOST, echoPort); SshdSocketAddress bound = session.startLocalPortForwarding(local, remote); try (Socket s = new Socket(bound.getHostName(), bound.getPort()); OutputStream output = s.getOutputStream(); InputStream input = s.getInputStream()) { s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L)); for (int i = 0; i < 1000; i++) { output.write(bytes); output.flush(); int n = input.read(buf); String res = new String(buf, 0, n); assertEquals("Mismatched data at iteration #" + i, expected, res); } } finally { session.stopLocalPortForwarding(bound); } } }
Example #29
Source File: MockClientSession.java From xenon with Apache License 2.0 | 4 votes |
@Override public List<Map.Entry<Integer, SshdSocketAddress>> getRemoteForwardsBindings() { return null; }
Example #30
Source File: SSHUtil.java From xenon with Apache License 2.0 | 4 votes |
public static UserCredential extractCredential(SshdSocketAddress location, Credential credential) { // Figure out which type of credential we are using if (credential instanceof CredentialMap) { CredentialMap map = (CredentialMap) credential; String key = location.toString(); if (map.containsCredential(key)) { return map.get(key); } // May return null! return map.get(location.getHostName()); } return (UserCredential) credential; }