Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignoring proxy settings ? #99

Open
Frintrop opened this issue Mar 11, 2016 · 5 comments
Open

ignoring proxy settings ? #99

Frintrop opened this issue Mar 11, 2016 · 5 comments
Labels

Comments

@Frintrop
Copy link

Frintrop commented Mar 11, 2016

PusherOptions options = new PusherOptions();
options = options.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.100.0.100",  ))); //8081 not existing !
Pusher pusher = new Pusher("aaa", options);

Did i a mistake ?

@jameshfisher
Copy link
Contributor

jameshfisher commented Mar 11, 2016

@Frintrop thanks for the report. I'm not sure I understand the problem. I see you're instantiating a new java.net.Proxy using this constructor. I think you want to instantiate the InetSocketAddress like this:

new InetSocketAddress("10.100.0.100", 8081)

Do you have an HTTP proxy available on 10:100.0.100:8081?

When you say 8081 does not exist, what do you mean?

What happens when you run your program? What error do you see?

@jpatel531 could we add an example of using setProxy to the README?

@GeekQing
Copy link

GeekQing commented Jan 18, 2018

I saw the source of the proxy setting of pusher, then i found that the proxy does not effective;

In WebSocketClientWrapper, there set socket through SSLSocketFactory;

if (uri.getScheme().equals(WSS_SCHEME)) {
    try {
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, null, null); // will use java's default
                                           // key and trust store which
                                           // is sufficient unless you
                                           // deal with self-signed
                                           // certificates

        final SSLSocketFactory factory = sslContext.getSocketFactory();// (SSLSocketFactory)
                                                                       // SSLSocketFactory.getDefault();

        **setSocket(factory.createSocket());**
    }
    catch (final IOException e) {
        throw new SSLException(e);
    }
    catch (final NoSuchAlgorithmException e) {
        throw new SSLException(e);
    }
    catch (final KeyManagementException e) {
        throw new SSLException(e);
    }
}
this.webSocketListener = webSocketListener;
setProxy(proxy);

And then, in WebSocketClient.run(), the socket has already initialized, do not use the proxy parameter to construct;

try {
	if( socket == null ) {
		**socket = new Socket( proxy );**
	} else if( socket.isClosed() ) {
		throw new IOException();
	}
	if( !socket.isBound() )
		socket.connect( new InetSocketAddress( uri.getHost(), getPort() ), connectTimeout );
	istream = socket.getInputStream();
	ostream = socket.getOutputStream();

	sendHandshake();
} catch ( /*IOException | SecurityException | UnresolvedAddressException | InvalidHandshakeException | ClosedByInterruptException | SocketTimeoutException */Exception e ) {
	onWebsocketError( engine, e );
	engine.closeConnection( CloseFrame.NEVER_CONNECTED, e.getMessage() );
	return;
}

writeThread = new Thread( new WebsocketWriteThread() );
writeThread.start();

@jameshfisher

@jameshfisher
Copy link
Contributor

@GeekQing I think your steps-to-reproduce are:

  1. Set a proxy on the PusherOptions
  2. Create a Pusher connection to a WSS (TLS) endpoint

The expected behavior would be that it uses the proxy as an "SSL tunnel". The actual behavior, it seems, is to ignore the proxy setting in this case. The reason is that, if we're using TLS, we create a TLS socket and set this on the WebSocketClient, which then causes the WebSocketClient to ignore the proxy setting. (I haven't tested this.)

Unfortunately javax.net.ssl doesn't seem to support "tunnelling" out-of-the-box, e.g. I can't see where we can pass it a java.net.Proxy object. Google's first result is this hairy example, which I don't want to get into.

@bendav02
Copy link

bendav02 commented Mar 8, 2018

@jameshfisher I'm facing the same issue.
I'm not an expert, but would providing a (properly) connected socket to the socket factory work:

In WebSocketClientWrapper

      Socket socket = new Socket(proxy);
      socket.connect(new InetSocketAddress(uri.getHost(), port));
      setSocket(sslContext.getSocketFactory().createSocket(socket, uri.getHost(), port, true));

@stnelso2
Copy link

stnelso2 commented May 7, 2020

It looks like this is a regression. I modified PR #176 from @bendav02 to work with the new version of java_websocket. Will you please add this fix to the next version? New PR is #259

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants