arthurkushman / php-wss

Web-socket server/client with multi-process and parse templates support on server and send/receive options on client
MIT License
210 stars 32 forks source link

Proxy Connection Problem #48

Closed Devian1988 closed 3 years ago

Devian1988 commented 3 years ago

Hi,

in File WscMain and method proxy() i can see, that you send a CONNECT Request to the Proxy Server itselfs. Shouldn't it be the target Host (Line 135)?

For my undeerstanding otherwise the Messages are not sendet to the Target Host.

Regards

arthurkushman commented 3 years ago

Hi, thx for report. Have u tried to test it? What's the result, can u post the result?

https://www.infoq.com/articles/Web-Sockets-Proxy-Servers/ If a browser is configured to use an explicit proxy server then it will first issue the HTTP CONNECT method to that proxy server while establishing the WebSocket connection. For example, to connect to the server example.com using the ws:// scheme (typically over port 80), the browser client sends the HTTP CONNECT method shown in Example 2 to the proxy server.

Example 2—HTTP CONNECT method using port 80

CONNECT example.com:80 HTTP/1.1
Host: example.com 

When the explicit proxy server allows the CONNECT method, the WebSocket connection upgrade handshake can be made and when that handshake succeeds, WebSocket traffic can start flowing unimpeded through the proxy server.

and with ssl If a browser is configured to use an explicit proxy server then it will first issue an HTTP CONNECT method to that proxy server while establishing the WebSocket connection. For example, to connect to the server example.com using the wss:// scheme (typically over port 443), the browser client sends the HTTP CONNECT method shown in Example 3 to the proxy server.

CONNECT example.com:443 HTTP/1.1
Host: example.com 

When the explicit proxy server allows the CONNECT method, the TLS handshake is sent, followed by the WebSocket connection upgrade handshake. After those handshakes succeed, WebSocket traffic can start flowing unimpeded through the proxy server. HTTPS (HTTP over TLS) work the same way; the use of encryption typically triggers the HTTP CONNECT method.

Devian1988 commented 3 years ago

Everythink you say is right but: You dont send the target host to the Proxy in CONNECT Request. You send the proxy address.

Devian1988 commented 3 years ago

The Problem comes from this Checkin: https://github.com/arthurkushman/php-wss/commit/f4a37a68bc19a17b8ca40be9f4e4c1fda514f0fb#diff-187a569508348bfa8be927ed35ea1cb0d934c000c3205da7bc85def1e29d767e

Devian1988 commented 3 years ago

It is now: $write = "CONNECT {$this->config->getProxyIp()}:{$this->config->getProxyPort()} HTTP/1.1\r\n"; and has to be: $write = "CONNECT {$this->config->getHost()}:{$this->config->getPort()} HTTP/1.1\r\n";

arthurkushman commented 3 years ago

Yes, I can make diff on git - thank u very much, may I ask u a reasonable questions again? Have u tried to test it? What's the result, can u post the result? Please provide full information - proxy settings, server, etc

Devian1988 commented 3 years ago

I test against a proxy from fineproxy.de so i have not much informations about it. It gave me an "403 Access Denied" as i tried.

Devian1988 commented 3 years ago

An the Proxy seams to have another Problem related to the WebSocket upgrade Request. It gaves me the Response code "0". But i think this is just because the Proxy disallow WebSockets at the moment. May i ask you: Do you know a Proxy Hoster that allow it? I'm googleing since 2 Hours now ;)

arthurkushman commented 3 years ago

I'm closing this issue because it is not related to web socket proxy connection it-self, but rather to access denied with specific auth params login/password which should be set in php-wss correctly like this:

$config->setProxyAuth('proxyUser', 'proxyPass');