Skip to content

Commit

Permalink
Do not emit undocumented events on foreign connection objects
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Nov 13, 2018
1 parent ce16df7 commit aa478fe
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,8 @@ public function unsetAuth()
public function onConnection(ConnectionInterface $connection)
{
$that = $this;
$handling = $this->handleSocks($connection)->then(function($remote) use ($connection){
$connection->emit('ready',array($remote));
}, function ($error) use ($connection, $that) {
if (!($error instanceof \Exception)) {
$error = new \Exception($error);
}
$connection->emit('error', array($error));
$handling = $this->handleSocks($connection)->then(null, function () use ($connection, $that) {
// SOCKS failed => close connection
$that->endConnection($connection);
});

Expand Down Expand Up @@ -280,9 +275,8 @@ public function handleSocks5(ConnectionInterface $stream, $auth=null, StreamRead
$remote = str_replace('://', '://' . rawurlencode($username) . ':' . rawurlencode($password) . '@', $remote);
}

return $auth($username, $password, $remote)->then(function () use ($stream, $username) {
return $auth($username, $password, $remote)->then(function () use ($stream) {
// accept
$stream->emit('auth', array($username));
$stream->write(pack('C2', 0x01, 0x00));
}, function() use ($stream) {
// reject => send any code but 0x00
Expand All @@ -296,7 +290,7 @@ public function handleSocks5(ConnectionInterface $stream, $auth=null, StreamRead
$stream->write(pack('C2', 0x05, 0xFF));
throw new UnexpectedValueException('No acceptable authentication mechanism found');
}
})->then(function ($method) use ($reader, $stream) {
})->then(function ($method) use ($reader) {
return $reader->readBinary(array(
'version' => 'C',
'command' => 'C',
Expand Down Expand Up @@ -368,7 +362,6 @@ public function connectTarget(ConnectionInterface $stream, array $target)
$uri .= '?source=' . rawurlencode($target[2]);
}

$stream->emit('target', $target);
$that = $this;
$connecting = $this->connector->connect($uri);

Expand All @@ -382,7 +375,6 @@ public function connectTarget(ConnectionInterface $stream, array $target)

// remote end closes connection => stop reading from local end, try to flush buffer to local and disconnect local
$remote->on('end', function() use ($stream, $that) {
$stream->emit('shutdown', array('remote', null));
$that->endConnection($stream);
});

Expand Down

0 comments on commit aa478fe

Please sign in to comment.