Skip to content

Commit 85f58ef

Browse files
committed
Fix IPv6 addresses as hostnames for TLS certificates
1 parent 848b32f commit 85f58ef

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ public function connect($uri)
141141

142142
// append hostname from URI to query string unless explicitly given
143143
if (!isset($args['hostname'])) {
144-
$args['hostname'] = $parts['host'];
144+
$args['hostname'] = $host;
145145
}
146146

147147
// append query string
148-
$socksUri .= '?' . http_build_query($args, '', '&');;
148+
$socksUri .= '?' . http_build_query($args, '', '&');
149149

150150
// append fragment from URI if given
151151
if (isset($parts['fragment'])) {

tests/ClientTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,24 @@ public function testEmitSocks5DataInvalidAddressTypeWillRejectConnection()
262262
$promise->then(null, $this->expectCallableOnceWithExceptionCode(SOCKET_EBADMSG));
263263
}
264264

265+
public function testEmitSocks5DataIpv6AddressWillResolveConnection()
266+
{
267+
$stream = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('write', 'close'))->getMock();
268+
$stream->expects($this->never())->method('close');
269+
270+
$promise = \React\Promise\resolve($stream);
271+
272+
$this->connector->expects($this->once())->method('connect')->with('127.0.0.1:1080?hostname=%3A%3A1')->willReturn($promise);
273+
274+
$this->client = new Client('socks5://127.0.0.1:1080', $this->connector);
275+
276+
$promise = $this->client->connect('[::1]:80');
277+
278+
$stream->emit('data', array("\x05\x00" . "\x05\x00\x00\x04" . inet_pton('::1') . "\x00\x50"));
279+
280+
$promise->then($this->expectCallableOnce());
281+
}
282+
265283
public function testEmitSocks5DataHostnameAddressWillResolveConnection()
266284
{
267285
$stream = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('write', 'close'))->getMock();

0 commit comments

Comments
 (0)