Skip to content

Commit

Permalink
Merge pull request #87 from clue-labs/socks5-uri
Browse files Browse the repository at this point in the history
URI scheme socks5:// acts only as an alias for default socks:// scheme
  • Loading branch information
clue authored Nov 20, 2018
2 parents f1003ea + cd4f80b commit 9db7fa7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,15 @@ a generic proxy allowing higher level application protocols to work through it.
By default, the `Client` communicates via SOCKS5 with the SOCKS server.
This is done because SOCKS5 is the latest version from the SOCKS protocol family
and generally has best support across other vendors.
You can also omit the default `socks://` URI scheme. Similarly, the `socks5://`
URI scheme acts as an alias for the default `socks://` URI scheme.

```php
// all three forms are equivalent
$client = new Client('127.0.0.1', $connector);
$client = new Client('socks://127.0.0.1', $connector);
$client = new Client('socks5://127.0.0.1', $connector);
```

If want to explicitly set the protocol version to SOCKS4(a), you can use the URI
scheme `socks4://` as part of the SOCKS URI:
Expand Down Expand Up @@ -544,7 +553,7 @@ You can use the `sockss://` URI scheme or use an explicit
```php
$client = new Client('sockss://127.0.0.1:1080', new Connector($loop));

$client = new Client('socks5s://127.0.0.1:1080', new Connector($loop));
$client = new Client('socks4s://127.0.0.1:1080', new Connector($loop));
```

See also [example 32](examples).
Expand Down Expand Up @@ -587,7 +596,7 @@ You can use the `socks+unix://` URI scheme or use an explicit
```php
$client = new Client('socks+unix:///tmp/proxy.sock', new Connector($loop));

$client = new Client('socks5+unix:///tmp/proxy.sock', new Connector($loop));
$client = new Client('socks4+unix:///tmp/proxy.sock', new Connector($loop));
```

Similarly, you can also combine this with [authentication](#authentication)
Expand Down Expand Up @@ -661,7 +670,8 @@ Internally, the `Server` uses ReactPHP's normal
[`connect()`](https://github.com/reactphp/socket#connect) method, but
it also passes the original client IP as the `?source={remote}` parameter.
The `source` parameter contains the full remote URI, including the protocol
and any authentication details, for example `socks5://user:[email protected]:5678`.
and any authentication details, for example `socks://user:[email protected]:5678`
or `socks4://1.2.3.4:5678` for legacy SOCKS4(a).
You can use this parameter for logging purposes or to restrict connection
requests for certain clients by providing a custom implementation of the
[`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface).
Expand Down Expand Up @@ -695,8 +705,9 @@ function that should return a `bool` value like this synchronous example:

```php
$server = new Clue\React\Socks\Server($loop, null, function ($user, $pass, $remote) {
// $remote is a full URI à la socks5://user:[email protected]:1234
// or socks5s://user:[email protected]:1234 for SOCKS over TLS
// $remote is a full URI à la socks://user:[email protected]:1234
// or sockss://user:[email protected]:1234 for SOCKS over TLS
// or may be null when remote is unknown (SOCKS over Unix Domain Sockets)
// useful for logging or extracting parts, such as the remote IP
$ip = parse_url($remote, PHP_URL_HOST);

Expand Down
2 changes: 1 addition & 1 deletion src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function handleSocks5(ConnectionInterface $stream, $auth, StreamReader $r
if (($pos = strpos($remote, '://')) !== false) {
$remote = substr($remote, $pos + 3);
}
$remote = 'socks5' . ($secure ? 's' : '') . '://' . $remote;
$remote = 'socks' . ($secure ? 's' : '') . '://' . $remote;
}

$that = $this;
Expand Down
2 changes: 1 addition & 1 deletion tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function testConnectionAuthenticationCallback()
++$called;
$that->assertEquals('name', $name);
$that->assertEquals('pass', $pass);
$that->assertStringStartsWith('socks5://name:[email protected]:', $remote);
$that->assertStringStartsWith('socks://name:[email protected]:', $remote);

return true;
});
Expand Down
8 changes: 4 additions & 4 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public function testConnectWillCreateConnectionWithSourceUri()

$promise = new Promise(function () { });

$this->connector->expects($this->once())->method('connect')->with('google.com:80?source=socks5%3A%2F%2F10.20.30.40%3A5060')->willReturn($promise);
$this->connector->expects($this->once())->method('connect')->with('google.com:80?source=socks%3A%2F%2F10.20.30.40%3A5060')->willReturn($promise);

$promise = $this->server->connectTarget($stream, array('google.com', 80, 'socks5://10.20.30.40:5060'));
$promise = $this->server->connectTarget($stream, array('google.com', 80, 'socks://10.20.30.40:5060'));

$this->assertInstanceOf('React\Promise\PromiseInterface', $promise);
}
Expand Down Expand Up @@ -291,7 +291,7 @@ public function testHandleSocks5ConnectionWithIpv4AndSourceAddressWillEstablishO

$promise = new Promise(function () { });

$this->connector->expects($this->once())->method('connect')->with('127.0.0.1:80?source=socks5%3A%2F%2F10.20.30.40%3A5060')->willReturn($promise);
$this->connector->expects($this->once())->method('connect')->with('127.0.0.1:80?source=socks%3A%2F%2F10.20.30.40%3A5060')->willReturn($promise);

$this->server->onConnection($connection);

Expand All @@ -305,7 +305,7 @@ public function testHandleSocks5ConnectionWithSecureTlsIpv4AndSourceAddressWillE

$promise = new Promise(function () { });

$this->connector->expects($this->once())->method('connect')->with('127.0.0.1:80?source=socks5s%3A%2F%2F10.20.30.40%3A5060')->willReturn($promise);
$this->connector->expects($this->once())->method('connect')->with('127.0.0.1:80?source=sockss%3A%2F%2F10.20.30.40%3A5060')->willReturn($promise);

$this->server->onConnection($connection);

Expand Down

0 comments on commit 9db7fa7

Please sign in to comment.