Skip to content

ignoring proxy settings ?  #99

@Frintrop

Description

@Frintrop
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 ?

Activity

jameshfisher

jameshfisher commented on Mar 11, 2016

@jameshfisher
Contributor

@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

GeekQing commented on Jan 18, 2018

@GeekQing

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

jameshfisher commented on Jan 18, 2018

@jameshfisher
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

bendav02 commented on Mar 8, 2018

@bendav02

@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));
added a commit that references this issue on Feb 14, 2019
stnelso2

stnelso2 commented on May 7, 2020

@stnelso2

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jameshfisher@GeekQing@stnelso2@kn100@Frintrop

        Issue actions

          ignoring proxy settings ? · Issue #99 · pusher/pusher-websocket-java