Skip to content

Commit c1a25c5

Browse files
committed
3.8.7
1 parent 0867ccb commit c1a25c5

26 files changed

+425
-276
lines changed

shadowsocks-csharp/Controller/HttpProxyRunner.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ public void Start(Configuration configuration)
9797
_runningPort = this.GetFreePort();
9898
polipoConfig = polipoConfig.Replace("__SOCKS_PORT__", configuration.localPort.ToString());
9999
polipoConfig = polipoConfig.Replace("__PRIVOXY_BIND_PORT__", _runningPort.ToString());
100-
polipoConfig = polipoConfig.Replace("__KEEP_ALIVE_TIMEOUT__", "3600");
101-
polipoConfig = polipoConfig.Replace("__CONNECTION_SHARING__", "1");
102100
polipoConfig = polipoConfig.Replace("__PRIVOXY_BIND_IP__", "127.0.0.1");
103101
polipoConfig = polipoConfig.Replace("__BYPASS_ACTION__", "actionsfile " + _subPath + "/bypass.action");
104102
FileManager.ByteArrayToFile(runningPath + "/privoxy.conf", System.Text.Encoding.UTF8.GetBytes(polipoConfig));

shadowsocks-csharp/Controller/Local.cs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class HandlerConfig
104104
public int targetPort;
105105

106106
public Double TTL = 0; // Second
107+
public Double connect_timeout = 0;
107108
public int try_keep_alive = 0;
108109
public string dns_servers;
109110
public bool fouce_local_dns_query = false;
@@ -556,25 +557,20 @@ private void BeginConnect(IPAddress ipAddress, int serverPort)
556557
speedTester.BeginConnect();
557558
IAsyncResult result = remote.BeginConnect(remoteEP,
558559
new AsyncCallback(ConnectCallback), new CallbackStatus());
559-
double t = cfg.TTL;
560-
if (t <= 0) t = 4 * 30;
561-
else if (t <= 10) t = 10;
562-
if (cfg.reconnectTimesRemain + cfg.reconnectTimes > 0 || cfg.TTL > 0)
560+
double t = cfg.connect_timeout <= 0 ? 30 : cfg.connect_timeout;
561+
bool success = result.AsyncWaitHandle.WaitOne((int)(t * 1000), true);
562+
if (!success)
563563
{
564-
bool success = result.AsyncWaitHandle.WaitOne((int)(t * 250), true);
565-
if (!success)
564+
((CallbackStatus)result.AsyncState).SetIfEqu(-1, 0);
565+
if (((CallbackStatus)result.AsyncState).Status == -1)
566566
{
567-
((CallbackStatus)result.AsyncState).SetIfEqu(-1, 0);
568-
if (((CallbackStatus)result.AsyncState).Status == -1)
567+
if (lastErrCode == 0)
569568
{
570-
if (lastErrCode == 0)
571-
{
572-
lastErrCode = 8;
573-
server.ServerSpeedLog().AddTimeoutTimes();
574-
}
575-
CloseSocket(ref remote);
576-
Close();
569+
lastErrCode = 8;
570+
server.ServerSpeedLog().AddTimeoutTimes();
577571
}
572+
CloseSocket(ref remote);
573+
Close();
578574
}
579575
}
580576
}

shadowsocks-csharp/Controller/ProxyAuth.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ private void Connect()
540540
handler.cfg.proxyUserAgent = _config.proxyUserAgent;
541541
}
542542
handler.cfg.TTL = _config.TTL;
543+
handler.cfg.connect_timeout = _config.connect_timeout;
543544
handler.cfg.autoSwitchOff = _config.autoBan;
544545
if (_config.dns_server != null && _config.dns_server.Length > 0)
545546
{

shadowsocks-csharp/Controller/ShadowsocksController.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ public void SaveServersConfig(Configuration config)
201201
_config.reconnectTimes = config.reconnectTimes;
202202
_config.randomAlgorithm = config.randomAlgorithm;
203203
_config.TTL = config.TTL;
204+
_config.connect_timeout = config.connect_timeout;
204205
_config.dns_server = config.dns_server;
205206
_config.proxyEnable = config.proxyEnable;
206207
_config.pacDirectGoProxy = config.pacDirectGoProxy;
@@ -367,8 +368,8 @@ public string GetSSLinkForServer(Server server)
367368
public string GetSSRRemarksLinkForServer(Server server)
368369
{
369370
string main_part = server.server + ":" + server.server_port + ":" + server.protocol + ":" + server.method + ":" + server.obfs + ":" + Util.Utils.EncodeUrlSafeBase64(server.password).Replace("=", "");
370-
string param_str = "obfsparam=" + Util.Utils.EncodeUrlSafeBase64(server.obfsparam).Replace("=", "");
371-
if (server.remarks.Length > 0)
371+
string param_str = "obfsparam=" + Util.Utils.EncodeUrlSafeBase64(server.obfsparam??"").Replace("=", "");
372+
if (server.remarks != null && server.remarks.Length > 0)
372373
{
373374
param_str += "&remarks=" + Util.Utils.EncodeUrlSafeBase64(server.remarks).Replace("=", "");
374375
}
@@ -624,11 +625,11 @@ private void ReleaseMemory()
624625
}
625626
}
626627

627-
public void ShowConfigForm()
628+
public void ShowConfigForm(int index)
628629
{
629630
if (ShowConfigFormEvent != null)
630631
{
631-
ShowConfigFormEvent(this, new EventArgs());
632+
ShowConfigFormEvent(index, new EventArgs());
632633
}
633634
}
634635
}

shadowsocks-csharp/Controller/SystemProxy.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public static void Update(Configuration config, bool forceDisable)
7878
string pacUrl;
7979
pacUrl = "http://127.0.0.1:" + config.localPort.ToString() + "/pac?t=" + GetTimestamp(DateTime.Now);
8080
RegistrySetValue(registry, "ProxyEnable", 0);
81-
var readProxyServer = registry.GetValue("ProxyServer");
8281
RegistrySetValue(registry, "ProxyServer", "");
8382
RegistrySetValue(registry, "AutoConfigURL", pacUrl);
8483
}
@@ -127,12 +126,16 @@ private static void CopyProxySettingFromLan()
127126
var connections = registry.GetValueNames();
128127
foreach (String each in connections)
129128
{
130-
if (!(each.Equals("DefaultConnectionSettings")
131-
|| each.Equals("LAN Connection")
132-
|| each.Equals("SavedLegacySettings")))
129+
switch (each.ToUpperInvariant())
133130
{
134-
//set all the connections's proxy as the lan
135-
registry.SetValue(each, defaultValue);
131+
case "DEFAULTCONNECTIONSETTINGS":
132+
case "LAN CONNECTION":
133+
case "SAVEDLEGACYSETTINGS":
134+
continue;
135+
default:
136+
//set all the connections's proxy as the lan
137+
registry.SetValue(each, defaultValue);
138+
continue;
136139
}
137140
}
138141
SystemProxy.NotifyIE();
@@ -174,15 +177,19 @@ private static void IEAutoDetectProxy(bool set)
174177
registry = OpenUserRegKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections",
175178
true);
176179
byte[] defConnection = (byte[])registry.GetValue("DefaultConnectionSettings");
177-
byte[] savedLegacySetting = (byte[])registry.GetValue("SavedLegacySettings");
178180
if (defConnection == null)
179181
{
180182
defConnection = new byte[32];
181183
defConnection[0] = 0x46;
182-
defConnection[4] = 0xcc;
183-
defConnection[5] = 0xe;
184184
defConnection[8] = 0x1;
185185
}
186+
byte[] savedLegacySetting = (byte[])registry.GetValue("SavedLegacySettings");
187+
if (savedLegacySetting == null)
188+
{
189+
savedLegacySetting = new byte[32];
190+
savedLegacySetting[0] = 0x46;
191+
savedLegacySetting[8] = 0x1;
192+
}
186193
if (set)
187194
{
188195
defConnection[8] = Convert.ToByte(defConnection[8] & 8);

shadowsocks-csharp/Controller/UpdateChecker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class UpdateChecker
2222

2323
public const string Name = "ShadowsocksR";
2424
public const string Copyright = "Copyright © BreakWall 2015";
25-
public const string Version = "3.8.6.0";
25+
public const string Version = "3.8.7.0";
2626
public const string FullVersion = Version + "";
2727

2828
private static bool UseProxy = true;

shadowsocks-csharp/Data/cn.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Local proxy=本地代理
9494
Build-in http proxy=内置http代理(目前有bug)
9595
Proxy Port=本地端口
9696
Reconnect Times=重连次数
97+
Timeout=连接超时
9798
TTL=空闲断开秒数
9899

99100
OK=确定

shadowsocks-csharp/Data/privoxy_conf.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@ show-on-task-bar 0
33
activity-animation 0
44
forward-socks5 / 127.0.0.1:__SOCKS_PORT__ .
55
hide-console
6-
keep-alive-timeout __KEEP_ALIVE_TIMEOUT__
7-
connection-sharing __CONNECTION_SHARING__
86
__BYPASS_ACTION__
97

shadowsocks-csharp/Data/zh-tw.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Global Settings...=選項設置...
1414
Start on Boot=開機啟動
1515
Allow Clients from LAN=允許來自局域網的連接
1616
Enable balance=伺服器負載均衡
17-
Same host for same address=優先相同節點連接同壹地址
17+
Same host for same address=優先相同節點連接同壹位址
1818
Enable domain white list(http proxy only)=使用域名白名單(僅http代理)
1919
Local PAC=使用本地 PAC
2020
Online PAC=使用在線 PAC
@@ -25,9 +25,9 @@ Update Local PAC from GFWList=更新PAC為GFWList
2525
Update Local PAC from Chn Only List=更新PAC為僅通過大陸常見域名(國外訪問大陸)
2626
Edit Local PAC File...=編輯本地 PAC 文件...
2727
Edit User Rule for GFWList...=編輯 GFWList 的用戶規則...
28-
Show QRCode...=顯示二維碼...
29-
Scan QRCode from Screen...=掃描屏幕上的二維碼...
30-
Copy Address from clipboard...=從剪貼板復制地址...
28+
Show QRCode...=顯示 QR 碼...
29+
Scan QRCode from Screen...=掃描螢幕上的 QR 碼...
30+
Copy Address from clipboard...=從剪貼板復制位址...
3131
Server Statistic...=伺服器連接統計...
3232
Disconnect Current=斷開當前所有連接
3333
New version {0} {1} available=【點擊下載新版本{0} {1}】
@@ -94,6 +94,7 @@ Local proxy=本地代理
9494
Build-in http proxy=內置http代理(目前有bug)
9595
Proxy Port=本地端口
9696
Reconnect Times=重連次數
97+
Timeout=連接超時
9798
TTL=空閑斷開秒數
9899

99100
OK=確定
@@ -127,7 +128,7 @@ Continuous=連錯
127128

128129
# QRCode Form
129130

130-
QRCode=二維碼
131+
QRCode=QR 碼
131132

132133
# PAC Url Form
133134

@@ -156,9 +157,9 @@ Domain white list list updated=更新域名白名單成功
156157
No updates found. Please report to GFWList if you have problems with it.=未發現更新。如有問題請提交給 GFWList。
157158
No QRCode found. Try to zoom in or move it to the center of the screen.=未發現二維碼,嘗試把它放大或移動到靠近屏幕中間的位置
158159
ShadowsocksR is already running.=ShadowsocksR 已經在運行。
159-
Find Shadowsocks icon in your notify tray.=請在任務欄裏尋找 ShadowsocksR 圖標。
160+
Find Shadowsocks icon in your notify tray.=請在工作列裏尋找 ShadowsocksR 圖標。
160161
If you want to start multiple Shadowsocks, make a copy in another directory.=如果想啟動多份,可以另外復制壹份到別的目錄。
161-
Failed to decode QRCode=無法解析二維碼
162+
Failed to decode QRCode=無法解析 QR 碼
162163
Failed to update registry=無法修改註冊表\n解決方案見https://github.com/shadowsocks/shadowsocks-windows/issues/253
163164
System Proxy On: =系統代理已啟用:
164165
Running: Port {0}=正在運行:端口 {0}

shadowsocks-csharp/Encryption/EncryptorBase.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
33

44
namespace Shadowsocks.Encryption
55
{
6+
public struct EncryptorInfo
7+
{
8+
public int iv_size;
9+
public int key_size;
10+
public bool display;
11+
public int type;
12+
public int ctx_size;
13+
14+
public EncryptorInfo(int key, int iv, bool display, int type, int ctx = 0)
15+
{
16+
key_size = key;
17+
iv_size = iv;
18+
this.display = display;
19+
this.type = type;
20+
ctx_size = ctx;
21+
}
22+
}
623
public abstract class EncryptorBase
724
: IEncryptor
825
{
@@ -33,5 +50,6 @@ protected byte[] GetPasswordHash()
3350
public abstract void Dispose();
3451
public abstract byte[] getIV();
3552
public abstract byte[] getKey();
53+
public abstract EncryptorInfo getInfo();
3654
}
3755
}

shadowsocks-csharp/Encryption/EncryptorFactory.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,20 @@ public static IEncryptor GetEncryptor(string method, string password)
5656
IEncryptor result = (IEncryptor)c.Invoke(new object[] { method, password });
5757
return result;
5858
}
59+
60+
public static EncryptorInfo GetEncryptorInfo(string method)
61+
{
62+
if (string.IsNullOrEmpty(method))
63+
{
64+
method = "aes-256-cfb";
65+
}
66+
method = method.ToLowerInvariant();
67+
Type t = _registeredEncryptors[method];
68+
ConstructorInfo c = t.GetConstructor(_constructorTypes);
69+
IEncryptor result = (IEncryptor)c.Invoke(new object[] { method, "0" });
70+
EncryptorInfo info = result.getInfo();
71+
result.Dispose();
72+
return info;
73+
}
5974
}
6075
}

shadowsocks-csharp/Encryption/IEncryptor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ public interface IEncryptor : IDisposable
1212
void ResetDecrypt();
1313
byte[] getIV();
1414
byte[] getKey();
15+
EncryptorInfo getInfo();
1516
}
1617
}

shadowsocks-csharp/Encryption/IVEncryptor.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public abstract class IVEncryptor
1010
{
1111
protected static byte[] tempbuf = new byte[MAX_INPUT_SIZE];
1212

13-
protected Dictionary<string, int[]> ciphers;
13+
protected Dictionary<string, EncryptorInfo> ciphers;
1414

1515
private static readonly Dictionary<string, byte[]> CachedKeys = new Dictionary<string, byte[]>();
1616
protected byte[] _encryptIV;
@@ -21,7 +21,7 @@ public abstract class IVEncryptor
2121
protected int _decryptIVOffset = 0;
2222
protected string _method;
2323
protected int _cipher;
24-
protected int[] _cipherInfo;
24+
protected EncryptorInfo _cipherInfo;
2525
protected byte[] _key;
2626
protected int keyLen;
2727
protected byte[] _iv;
@@ -34,7 +34,7 @@ public IVEncryptor(string method, string password)
3434
InitKey(method, password);
3535
}
3636

37-
protected abstract Dictionary<string, int[]> getCiphers();
37+
protected abstract Dictionary<string, EncryptorInfo> getCiphers();
3838

3939
public override byte[] getIV()
4040
{
@@ -46,6 +46,10 @@ public override byte[] getKey()
4646
Array.Resize(ref key, keyLen);
4747
return key;
4848
}
49+
public override EncryptorInfo getInfo()
50+
{
51+
return _cipherInfo;
52+
}
4953

5054
protected void InitKey(string method, string password)
5155
{
@@ -54,13 +58,13 @@ protected void InitKey(string method, string password)
5458
string k = method + ":" + password;
5559
ciphers = getCiphers();
5660
_cipherInfo = ciphers[_method];
57-
_cipher = _cipherInfo[2];
61+
_cipher = _cipherInfo.type;
5862
if (_cipher == 0)
5963
{
6064
throw new Exception("method not found");
6165
}
62-
keyLen = ciphers[_method][0];
63-
ivLen = ciphers[_method][1];
66+
keyLen = ciphers[_method].key_size;
67+
ivLen = ciphers[_method].iv_size;
6468
if (!CachedKeys.ContainsKey(k))
6569
{
6670
lock (CachedKeys)

shadowsocks-csharp/Encryption/LibcryptoEncryptor.cs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,26 @@ public static void InitAviable()
3838
}
3939
}
4040

41-
private static Dictionary<string, int[]> _ciphers = new Dictionary<string, int[]> {
42-
{"aes-128-cfb", new int[]{16, 16, CIPHER_AES}},
43-
{"aes-192-cfb", new int[]{24, 16, CIPHER_AES}},
44-
{"aes-256-cfb", new int[]{32, 16, CIPHER_AES}},
45-
{"aes-128-ctr", new int[]{16, 16, CIPHER_AES}},
46-
{"aes-192-ctr", new int[]{24, 16, CIPHER_AES}},
47-
{"aes-256-ctr", new int[]{32, 16, CIPHER_AES}},
48-
{"camellia-128-cfb", new int[]{16, 16, CIPHER_CAMELLIA}},
49-
{"camellia-192-cfb", new int[]{24, 16, CIPHER_CAMELLIA}},
50-
{"camellia-256-cfb", new int[]{32, 16, CIPHER_CAMELLIA}},
51-
//{"camellia-128-ofb", new int[]{16, 16, CIPHER_CAMELLIA}},
52-
//{"camellia-192-ofb", new int[]{24, 16, CIPHER_CAMELLIA}},
53-
//{"camellia-256-ofb", new int[]{32, 16, CIPHER_CAMELLIA}},
54-
{"bf-cfb", new int[]{16, 8, CIPHER_OTHER_CFB}},
55-
{"cast5-cfb", new int[]{16, 8, CIPHER_OTHER_CFB}},
56-
{"des-cfb", new int[]{8, 8, CIPHER_OTHER_CFB}}, // weak
57-
{"des-ede3-cfb", new int[]{24, 8, CIPHER_OTHER_CFB}},
58-
{"idea-cfb", new int[]{16, 8, CIPHER_OTHER_CFB}},
59-
{"rc2-cfb", new int[]{16, 8, CIPHER_OTHER_CFB}},
60-
//{"rc4", new int[]{16, 0, CIPHER_RC4}}, // weak
61-
{"rc4-md5", new int[]{16, 16, CIPHER_RC4}}, // weak
62-
{"rc4-md5-6", new int[]{16, 6, CIPHER_RC4}}, // weak
63-
{"seed-cfb", new int[]{16, 16, CIPHER_OTHER_CFB}},
41+
private static Dictionary<string, EncryptorInfo> _ciphers = new Dictionary<string, EncryptorInfo> {
42+
{"aes-128-cfb", new EncryptorInfo(16, 16, true, CIPHER_AES)},
43+
{"aes-192-cfb", new EncryptorInfo(24, 16, true, CIPHER_AES)},
44+
{"aes-256-cfb", new EncryptorInfo(32, 16, true, CIPHER_AES)},
45+
{"aes-128-ctr", new EncryptorInfo(16, 16, true, CIPHER_AES)},
46+
{"aes-192-ctr", new EncryptorInfo(24, 16, true, CIPHER_AES)},
47+
{"aes-256-ctr", new EncryptorInfo(32, 16, true, CIPHER_AES)},
48+
{"camellia-128-cfb", new EncryptorInfo(16, 16, true, CIPHER_CAMELLIA)},
49+
{"camellia-192-cfb", new EncryptorInfo(24, 16, true, CIPHER_CAMELLIA)},
50+
{"camellia-256-cfb", new EncryptorInfo(32, 16, true, CIPHER_CAMELLIA)},
51+
{"bf-cfb", new EncryptorInfo(16, 8, true, CIPHER_OTHER_CFB)},
52+
{"cast5-cfb", new EncryptorInfo(16, 8, true, CIPHER_OTHER_CFB)},
53+
//{"des-cfb", new EncryptorInfo(8, 8, true, CIPHER_OTHER_CFB)}, // weak
54+
//{"des-ede3-cfb", new EncryptorInfo(24, 8, true, CIPHER_OTHER_CFB)},
55+
{"idea-cfb", new EncryptorInfo(16, 8, true, CIPHER_OTHER_CFB)},
56+
{"rc2-cfb", new EncryptorInfo(16, 8, true, CIPHER_OTHER_CFB)},
57+
{"rc4", new EncryptorInfo(16, 0, false, CIPHER_RC4)}, // weak
58+
{"rc4-md5", new EncryptorInfo(16, 16, true, CIPHER_RC4)}, // weak
59+
{"rc4-md5-6", new EncryptorInfo(16, 6, true, CIPHER_RC4)}, // weak
60+
{"seed-cfb", new EncryptorInfo(16, 16, true, CIPHER_OTHER_CFB)},
6461
};
6562

6663
public static List<string> SupportedCiphers()
@@ -73,7 +70,7 @@ public static bool isSupport()
7370
return Libcrypto.isSupport();
7471
}
7572

76-
protected override Dictionary<string, int[]> getCiphers()
73+
protected override Dictionary<string, EncryptorInfo> getCiphers()
7774
{
7875
return _ciphers;
7976
}

0 commit comments

Comments
 (0)