Check secret in PACServer

This commit is contained in:
noisyfox
2016-12-08 18:54:57 +11:00
parent 22d8cdeff7
commit 983c1adb28
@@ -60,6 +60,7 @@ namespace Shadowsocks.Controller
string request = Encoding.UTF8.GetString(firstPacket, 0, length);
string[] lines = request.Split('\r', '\n');
bool hostMatch = false, pathMatch = false, useSocks = false;
bool secretMatch = PacSecret.IsNullOrEmpty();
foreach (string line in lines)
{
string[] kv = line.Split(new char[] { ':' }, 2);
@@ -87,11 +88,25 @@ namespace Shadowsocks.Controller
{
pathMatch = true;
}
if (!secretMatch)
{
if(line.IndexOf(PacSecret, StringComparison.Ordinal) >= 0)
{
secretMatch = true;
}
}
}
}
if (hostMatch && pathMatch)
{
SendResponse(firstPacket, length, socket, useSocks);
if (!secretMatch)
{
socket.Close(); // Close immediately
}
else
{
SendResponse(firstPacket, length, socket, useSocks);
}
return true;
}
return false;