Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3bca7b7

Browse files
committedSep 24, 2017
Finish 4.8.1
添加 auth_chain_e/f 添加 Xchacha20 Xsalsa20 支持 更新 libsodium 到 v1.0.13
2 parents f34fe78 + dd9fb57 commit 3bca7b7

File tree

9 files changed

+181
-7
lines changed

9 files changed

+181
-7
lines changed
 

‎shadowsocks-csharp/Data/cn.txt

+1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ Illegal port number format=非法端口格式
216216
Please add at least one server=请添加至少一个服务器
217217
Server IP can not be blank=服务器 IP 不能为空
218218
Password can not be blank=密码不能为空
219+
Password are blank=密码为空
219220
Port out of range=端口超出范围
220221
{0} {1} Update Found={0} {1} 更新
221222
Click menu to download=点击菜单项下载
67.9 KB
Binary file not shown.
74.2 KB
Binary file not shown.

‎shadowsocks-csharp/Data/zh-tw.txt

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ Illegal port number format=非法連接埠格式
204204
Please add at least one server=請添加至少一個伺服器
205205
Server IP can not be blank=伺服器 IP 不能為空
206206
Password can not be blank=密碼不能為空
207+
Password are blank=密碼為空
207208
Port out of range=連接埠超出範圍
208209
{0} {1} Update Found={0} {1} 更新
209210
Click menu to download=點擊菜單項下載

‎shadowsocks-csharp/Encryption/Sodium.cs

+6
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,15 @@ static Sodium()
4242
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
4343
public extern static void crypto_stream_salsa20_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k);
4444

45+
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
46+
public extern static void crypto_stream_xsalsa20_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k);
47+
4548
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
4649
public extern static void crypto_stream_chacha20_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k);
4750

51+
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
52+
public extern static void crypto_stream_xchacha20_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k);
53+
4854
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
4955
public extern static int crypto_stream_chacha20_ietf_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, uint ic, byte[] k);
5056
}

‎shadowsocks-csharp/Encryption/SodiumEncryptor.cs

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class SodiumEncryptor
1010
const int CIPHER_SALSA20 = 1;
1111
const int CIPHER_CHACHA20 = 2;
1212
const int CIPHER_CHACHA20_IETF = 3;
13+
const int CIPHER_XSALSA20 = 4 + 1;
14+
const int CIPHER_XCHACHA20 = 4 + 2;
1315

1416
const int SODIUM_BLOCK_SIZE = 64;
1517

@@ -37,6 +39,12 @@ public SodiumEncryptor(string method, string password)
3739
case CIPHER_CHACHA20:
3840
encryptor_delegate = Sodium.crypto_stream_chacha20_xor_ic;
3941
break;
42+
case CIPHER_XSALSA20:
43+
encryptor_delegate = Sodium.crypto_stream_xsalsa20_xor_ic;
44+
break;
45+
case CIPHER_XCHACHA20:
46+
encryptor_delegate = Sodium.crypto_stream_xchacha20_xor_ic;
47+
break;
4048
case CIPHER_CHACHA20_IETF:
4149
encryptor_delegate = crypto_stream_chacha20_ietf_xor_ic;
4250
break;
@@ -46,6 +54,8 @@ public SodiumEncryptor(string method, string password)
4654
private static Dictionary<string, EncryptorInfo> _ciphers = new Dictionary<string, EncryptorInfo> {
4755
{"salsa20", new EncryptorInfo(32, 8, true, CIPHER_SALSA20)},
4856
{"chacha20", new EncryptorInfo(32, 8, true, CIPHER_CHACHA20)},
57+
{"xsalsa20", new EncryptorInfo(32, 24, true, CIPHER_XSALSA20)},
58+
{"xchacha20", new EncryptorInfo(32, 24, true, CIPHER_XCHACHA20)},
4959
{"chacha20-ietf", new EncryptorInfo(32, 12, true, CIPHER_CHACHA20_IETF)},
5060
};
5161

‎shadowsocks-csharp/Model/Configuration.cs

+37-7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,27 @@ public class GlobalConfiguration
7878
public static string config_password = "";
7979
}
8080

81+
[Serializable()]
82+
class ConfigurationException : System.Exception
83+
{
84+
public ConfigurationException() : base() { }
85+
public ConfigurationException(string message) : base(message) { }
86+
public ConfigurationException(string message, System.Exception inner) : base(message, inner) { }
87+
protected ConfigurationException(System.Runtime.Serialization.SerializationInfo info,
88+
System.Runtime.Serialization.StreamingContext context)
89+
{ }
90+
}
91+
[Serializable()]
92+
class ConfigurationWarning : System.Exception
93+
{
94+
public ConfigurationWarning() : base() { }
95+
public ConfigurationWarning(string message) : base(message) { }
96+
public ConfigurationWarning(string message, System.Exception inner) : base(message, inner) { }
97+
protected ConfigurationWarning(System.Runtime.Serialization.SerializationInfo info,
98+
System.Runtime.Serialization.StreamingContext context)
99+
{ }
100+
}
101+
81102
[Serializable]
82103
public class Configuration
83104
{
@@ -219,7 +240,7 @@ public Server GetCurrentServer(int localPort, ServerSelectStrategy.FilterFunc fi
219240
if (selServer != null)
220241
return selServer.group == server.group;
221242
return false;
222-
} , true);
243+
}, true);
223244
}
224245
else
225246
{
@@ -370,7 +391,15 @@ public static void CheckServer(Server server)
370391
CheckPort(server.server_port);
371392
if (server.server_udp_port != 0)
372393
CheckPort(server.server_udp_port);
373-
CheckPassword(server.password);
394+
try
395+
{
396+
CheckPassword(server.password);
397+
}
398+
catch (ConfigurationWarning cw)
399+
{
400+
server.password = "";
401+
MessageBox.Show(cw.Message, cw.Message, MessageBoxButtons.OK, MessageBoxIcon.Warning);
402+
}
374403
CheckServer(server.server);
375404
}
376405

@@ -619,23 +648,24 @@ public static void CheckPort(int port)
619648
{
620649
if (port <= 0 || port > 65535)
621650
{
622-
throw new ArgumentException(I18N.GetString("Port out of range"));
651+
throw new ConfigurationException(I18N.GetString("Port out of range"));
623652
}
624653
}
625654

626655
private static void CheckPassword(string password)
627656
{
628657
if (string.IsNullOrEmpty(password))
629658
{
630-
throw new ArgumentException(I18N.GetString("Password can not be blank"));
659+
throw new ConfigurationWarning(I18N.GetString("Password are blank"));
660+
//throw new ConfigurationException(I18N.GetString("Password can not be blank"));
631661
}
632662
}
633663

634664
private static void CheckServer(string server)
635665
{
636666
if (string.IsNullOrEmpty(server))
637667
{
638-
throw new ArgumentException(I18N.GetString("Server IP can not be blank"));
668+
throw new ConfigurationException(I18N.GetString("Server IP can not be blank"));
639669
}
640670
}
641671

@@ -777,7 +807,7 @@ public void AddUpload(string server, Int64 size)
777807
if (--saveCounter <= 0)
778808
{
779809
saveCounter = 256;
780-
if ((DateTime.Now - saveTime).TotalMinutes > 10 )
810+
if ((DateTime.Now - saveTime).TotalMinutes > 10)
781811
{
782812
lock (servers)
783813
{
@@ -798,7 +828,7 @@ public void AddDownload(string server, Int64 size)
798828
if (--saveCounter <= 0)
799829
{
800830
saveCounter = 256;
801-
if ((DateTime.Now - saveTime).TotalMinutes > 10 )
831+
if ((DateTime.Now - saveTime).TotalMinutes > 10)
802832
{
803833
lock (servers)
804834
{

‎shadowsocks-csharp/Obfs/AuthChain.cs

+118
Original file line numberDiff line numberDiff line change
@@ -802,4 +802,122 @@ protected override int GetRandLen(int datalength, xorshift128plus random, byte[]
802802
}
803803

804804
}
805+
806+
class AuthChain_e : AuthChain_d
807+
{
808+
public AuthChain_e(string method)
809+
: base(method)
810+
{
811+
812+
}
813+
814+
private static Dictionary<string, int[]> _obfs = new Dictionary<string, int[]> {
815+
{"auth_chain_e", new int[]{1, 0, 1}},
816+
};
817+
818+
public static new List<string> SupportedObfs()
819+
{
820+
return new List<string>(_obfs.Keys);
821+
}
822+
823+
public override Dictionary<string, int[]> GetObfs()
824+
{
825+
return _obfs;
826+
}
827+
828+
protected override int GetRandLen(int datalength, xorshift128plus random, byte[] last_hash)
829+
{
830+
int other_data_size = datalength + Server.overhead;
831+
832+
if (other_data_size >= data_size_list0[data_size_list0.Length - 1])
833+
{
834+
return 0;
835+
}
836+
837+
int pos = FindPos(data_size_list0, other_data_size);
838+
return data_size_list0[pos] - other_data_size;
839+
}
840+
841+
}
842+
843+
class AuthChain_f : AuthChain_e
844+
{
845+
public AuthChain_f(string method)
846+
: base(method)
847+
{
848+
849+
}
850+
851+
private static Dictionary<string, int[]> _obfs = new Dictionary<string, int[]> {
852+
{"auth_chain_f", new int[]{1, 0, 1}},
853+
};
854+
855+
public static new List<string> SupportedObfs()
856+
{
857+
return new List<string>(_obfs.Keys);
858+
}
859+
860+
public override Dictionary<string, int[]> GetObfs()
861+
{
862+
return _obfs;
863+
}
864+
865+
protected UInt64 key_change_interval = 60 * 60 * 24; // a day by second
866+
protected UInt64 key_change_datetime_key;
867+
protected List<byte> key_change_datetime_key_bytes = new List<byte>();
868+
869+
protected new void InitDataSizeList()
870+
{
871+
xorshift128plus random = new xorshift128plus();
872+
byte[] newKey = new byte[Server.key.Length];
873+
Server.key.CopyTo(newKey, 0);
874+
for (int i = 0; i < 8; i++)
875+
{
876+
newKey[i] ^= key_change_datetime_key_bytes[i];
877+
}
878+
random.init_from_bin(newKey);
879+
int len = (int)(random.next() % (8 + 16) + (4 + 8));
880+
List<int> data_list = new List<int>();
881+
for (int i = 0; i < len; ++i)
882+
{
883+
data_list.Add((int)(random.next() % 2340 % 2040 % 1440));
884+
}
885+
data_list.Sort();
886+
int old_len = data_list.Count;
887+
CheckAndPatchDataSize(data_list, random);
888+
if (old_len != data_list.Count)
889+
{
890+
data_list.Sort();
891+
}
892+
data_size_list0 = data_list.ToArray();
893+
}
894+
895+
public override void SetServerInfo(ServerInfo serverInfo)
896+
{
897+
Server = serverInfo;
898+
string protocalParams = serverInfo.param;
899+
if (protocalParams != "")
900+
{
901+
if (-1 != protocalParams.IndexOf("#", StringComparison.Ordinal))
902+
{
903+
protocalParams = protocalParams.Split('#')[1];
904+
}
905+
UInt64 interval;
906+
if (UInt64.TryParse(protocalParams, out interval))
907+
{
908+
key_change_interval = interval;
909+
}
910+
}
911+
// https://stackoverflow.com/a/17632585/3548568
912+
UInt64 unixTimestamp = (UInt64)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
913+
key_change_datetime_key = unixTimestamp / key_change_interval;
914+
for (int i = 7; i > -1; --i)
915+
{
916+
byte b = (byte)(key_change_datetime_key >> (8 * i) & 0xFF);
917+
key_change_datetime_key_bytes.Add(b);
918+
}
919+
InitDataSizeList();
920+
}
921+
922+
}
805923
}

‎shadowsocks-csharp/Obfs/ObfsFactory.cs

+8
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ static ObfsFactory()
6363
{
6464
_registeredObfs.Add(method, typeof(AuthChain_d));
6565
}
66+
foreach (string method in AuthChain_e.SupportedObfs())
67+
{
68+
_registeredObfs.Add(method, typeof(AuthChain_e));
69+
}
70+
foreach (string method in AuthChain_f.SupportedObfs())
71+
{
72+
_registeredObfs.Add(method, typeof(AuthChain_f));
73+
}
6674
}
6775

6876
public static IObfs GetObfs(string method)

0 commit comments

Comments
 (0)
Please sign in to comment.