@@ -227,12 +227,14 @@ public function handleSocks5(Stream $stream, $auth=null)
227227 })->then (function ($ password ) use ($ username , $ auth , $ stream ) {
228228 // username and password known => authenticate
229229 // echo 'auth: ' . $username.' : ' . $password . PHP_EOL;
230- return $ auth ($ username , $ password )->then (function () use ($ stream ) {
230+ return $ auth ($ username , $ password )->then (function () use ($ stream, $ username ) {
231231 // accept
232+ $ stream ->emit ('auth ' , array ($ username ));
232233 $ stream ->write (pack ('C2 ' , 0x01 , 0x00 ));
233234 }, function () use ($ stream ) {
234235 // reject => send any code but 0x00
235- $ stream ->write (pack ('C2 ' , 0x01 , 0xFF ));
236+ $ stream ->end (pack ('C2 ' , 0x01 , 0xFF ));
237+ throw new UnexpectedValueException ('Unable to authenticate ' );
236238 });
237239 });
238240 });
@@ -242,7 +244,6 @@ public function handleSocks5(Stream $stream, $auth=null)
242244 throw new UnexpectedValueException ('No acceptable authentication mechanism found ' );
243245 }
244246 })->then (function ($ method ) use ($ reader , $ stream ) {
245- $ stream ->emit ('authenticate ' ,array ($ method ));
246247 return $ reader ->readBinary (array (
247248 'version ' => 'C ' ,
248249 'command ' => 'C ' ,
0 commit comments