Using HTTP or SOCKS Proxies

You can use an HTTP or SOCKS 4/5 proxy to establish client connections with Maverick Synergy.

This requires that you create the SshClientContext and pass this to the SshClient constructor.

HTTP

For a simple anonymous HTTP Proxy

SshClientContext ctx = new SshClientContext();
ctx.enableHTTPProxy("localhost", 9999);

Then, establish the connection with your SshClient, passing the SshClientContext to the constructor.

try (SshClient ssh = SshClientBuilder.create()
		.withHostname("localhost")
		.withPort(2222)
		.withUsername("root")
		.withPassword("xxxx")
		.withSshContext(ctx)
		.build()) {
}

If required, you can pass credentials when setting up the proxy.

ctx.enableHTTPProxy("localhost", 9999, "lee", "password123?");

SOCKS

There are options for SOCKS 4 and SOCKS 5 Proxies. Again as outlined above this is a configuration on the SshClientContext.

SOCKS 4 does not support authentication.

ctx.enableSocks4Proxy("localhost", 8889, "lee");

Now, connect with your SshClient, passing the SshClientContext to the constructor.

try (SshClient ssh = SshClientBuilder.create()
		.withHostname("localhost")
		.withPort(2222)
		.withUsername("root")
		.withPassword("xxxx")
		.withSshContext(ctx)
		.build()) {
}

SOCKS 5 supports authentication; you can pass an empty or null string if you don’t need to use authentication. The boolean flag on the end determines if the API tries to resolve the hostname locally (true) or remotely (false).

ctx.enableSocks5Proxy("localhost", 8889, "lee", "", false);