Browse Source

Use MD5 hash instead of timestamp for PAC URL

tags/4.1.9.0
Student Main 5 years ago
parent
commit
a0786a435f
1 changed files with 9 additions and 4 deletions
  1. +9
    -4
      shadowsocks-csharp/Controller/Service/PACServer.cs

+ 9
- 4
shadowsocks-csharp/Controller/Service/PACServer.cs View File

@@ -44,13 +44,18 @@ namespace Shadowsocks.Controller
PacSecret = "";
}
PacUrl = $"http://{config.localHost}:{config.localPort}/{RESOURCE_NAME}?t={GetTimestamp(DateTime.Now)}{PacSecret}";
PacUrl = $"http://{config.localHost}:{config.localPort}/{RESOURCE_NAME}?hash={GetHash(_pacDaemon.GetPACContent())}{PacSecret}";
}
private static string GetTimestamp(DateTime value)
private static string GetHash(string content)
{
return value.ToString("yyyyMMddHHmmssfff");
var contentBytes = Encoding.ASCII.GetBytes(content);
using (var md5 = System.Security.Cryptography.MD5.Create())
{
var md5Bytes = md5.ComputeHash(contentBytes);
return BitConverter.ToString(md5Bytes).Replace("-", "");
};
}
public override bool Handle(byte[] firstPacket, int length, Socket socket, object state)
@@ -165,7 +170,7 @@ namespace Shadowsocks.Controller
string proxy = GetPACAddress(localEndPoint, useSocks);
string pacContent = $"var __PROXY__ = '{proxy}';\n" + _pacDaemon.GetPACContent();
string responseHead =
string responseHead =
$@"HTTP/1.1 200 OK
Server: ShadowsocksWindows/{UpdateChecker.Version}
Content-Type: application/x-ns-proxy-autoconfig


Loading…
Cancel
Save