Browse Source

add new obfs protocol

pull/373/head
breakwa11 9 years ago
parent
commit
b5eeea3933
8 changed files with 59 additions and 57 deletions
  1. +22
    -18
      shadowsocks-csharp/Controller/Local.cs
  2. +5
    -24
      shadowsocks-csharp/Controller/TDP.cs
  3. +2
    -2
      shadowsocks-csharp/Controller/UpdateChecker.cs
  4. +1
    -1
      shadowsocks-csharp/Data/cn.txt
  5. +19
    -0
      shadowsocks-csharp/Util/CRC.cs
  6. +8
    -10
      shadowsocks-csharp/View/ConfigForm.Designer.cs
  7. +1
    -1
      shadowsocks-csharp/View/ConfigForm.cs
  8. +1
    -1
      shadowsocks-csharp/View/ServerLogForm.cs

+ 22
- 18
shadowsocks-csharp/Controller/Local.cs View File

@@ -1912,28 +1912,24 @@ namespace Shadowsocks.Controller
}
}

private void RemoteSend(byte[] bytes, int length, bool obfs = false, int obfs_max = 255)
private void RemoteSend(byte[] bytes, int length, bool obfs = false, int obfs_max = 32)
{
int bytesToSend;
if (obfs)
{
byte[] bytesToEncrypt = null;
int obfs_len = random.Next(obfs_max) + 1;
if (obfs_len == 1)
{
bytesToEncrypt = new byte[length + 1];
Array.Copy(bytes, 0, bytesToEncrypt, 1, length);
bytesToEncrypt[0] = 0x81;
length += 1;
}
else
{
int len = obfs_len - 2;
bytesToEncrypt = new byte[length + len + 2];
Array.Copy(bytes, 0, bytesToEncrypt, len + 2, length);
bytesToEncrypt[0] = 0x80;
bytesToEncrypt[1] = (byte)len;
length += len + 2;
int obfs_len = random.Next(obfs_max - 1) + 1;
{
int len = obfs_len;
int total_len = length + len + 3 + 4;
bytesToEncrypt = new byte[total_len];
Array.Copy(bytes, 0, bytesToEncrypt, 3 + len, length);
bytesToEncrypt[0] = 0x88;
bytesToEncrypt[1] = (byte)(total_len >> 8);
bytesToEncrypt[2] = (byte)(total_len);
bytesToEncrypt[3] = (byte)(obfs_len);
Util.CRC32.SetCRC32(bytesToEncrypt);
length = total_len;
}
Logging.LogBin(LogLevel.Debug, "remote send", bytesToEncrypt, length);
lock (encryptionLock)
@@ -2112,7 +2108,15 @@ namespace Shadowsocks.Controller
else
{
{
RemoteSend(connetionRecvBuffer, bytesRead);
int packet = ++connectionPacketNumber;
if (packet == 1)
{
RemoteSend(connetionRecvBuffer, bytesRead, server.obfs_tcp);
}
else
{
RemoteSend(connetionRecvBuffer, bytesRead);
}
}
}
}


+ 5
- 24
shadowsocks-csharp/Controller/TDP.cs View File

@@ -448,25 +448,6 @@ namespace Shadowsocks.Controller
{
return (DateTime.Now - updateTime).TotalSeconds > TTL;
}

private static void SetCRC32(byte[] buffer)
{
ulong crc = ~Shadowsocks.Util.CRC32.CalcCRC32(buffer, buffer.Length - 4);
buffer[buffer.Length - 1] = (byte)(crc >> 24);
buffer[buffer.Length - 2] = (byte)(crc >> 16);
buffer[buffer.Length - 3] = (byte)(crc >> 8);
buffer[buffer.Length - 4] = (byte)(crc);
}

private byte[] CheckCRC32(byte[] buffer)
{
ulong crc = ~Shadowsocks.Util.CRC32.CalcCRC32(buffer, buffer.Length);
if (crc != 0xffffffff00000000u)
return null;
byte[] ret = new byte[buffer.Length - 4];
Array.Copy(buffer, ret, buffer.Length - 4);
return ret;
}
private byte[] CheckRecvData(byte[] buffer)
{
if (buffer[buffer.Length - 2] != buffer[2] || buffer[buffer.Length - 1] != buffer[3])
@@ -1036,7 +1017,7 @@ namespace Shadowsocks.Controller
buffer[0] = 0x8;
buffer[1] = (byte)Command.CMD_CONNECT;
localid.CopyTo(buffer, 4);
SetCRC32(buffer);
Util.CRC32.SetCRC32(buffer);
return buffer;
}

@@ -1050,7 +1031,7 @@ namespace Shadowsocks.Controller
buffer[3] = (byte)(requestid % 256);
localid.CopyTo(buffer, 4);
Array.Copy(connectInfo, 0, buffer, 8, connectInfo.Length);
SetCRC32(buffer);
Util.CRC32.SetCRC32(buffer);
return buffer;
}

@@ -1063,7 +1044,7 @@ namespace Shadowsocks.Controller
buffer[2] = (byte)(requestid / 256);
buffer[3] = (byte)(requestid % 256);
localid.CopyTo(buffer, 4);
SetCRC32(buffer);
Util.CRC32.SetCRC32(buffer);
return buffer;
}

@@ -1110,7 +1091,7 @@ namespace Shadowsocks.Controller
}
localid.CopyTo(buffer, 4);
Array.Copy(data, 0, buffer, beginIndex, data.Length);
SetCRC32(buffer);
Util.CRC32.SetCRC32(buffer);
return buffer;
}

@@ -1190,7 +1171,7 @@ namespace Shadowsocks.Controller
// );
}
localid.CopyTo(buffer, 4);
SetCRC32(buffer);
Util.CRC32.SetCRC32(buffer);
return buffer;
}



+ 2
- 2
shadowsocks-csharp/Controller/UpdateChecker.cs View File

@@ -21,8 +21,8 @@ namespace Shadowsocks.Controller
public const string Name = "ShadowsocksR";
public const string Copyright = "Copyright © BreakWall 2015";
public const string Version = "3.4.0";
public const string FullVersion = Version + " Final";
public const string Version = "3.4.1";
public const string FullVersion = Version + " Beta";
private static bool UseProxy = true;


+ 1
- 1
shadowsocks-csharp/Data/cn.txt View File

@@ -50,7 +50,7 @@ Remarks=备注
Adv. Setting=高级选项
TCPoverUDP=TCP over UDP
UDPoverTCP=UDP over TCP
Obfs TCP=混淆TCP协议头
Obfs TCP=新TCP连接协议
Obfs UDP=混淆UDP协议
NOT all server support belows=以下选项不是所有服务端都支持
TCP over TCP if not checked=不打钩使用 TCP over TCP


+ 19
- 0
shadowsocks-csharp/Util/CRC.cs View File

@@ -40,5 +40,24 @@ namespace Shadowsocks.Util
}
return value ^ 0xffffffff;
}

public static void SetCRC32(byte[] buffer)
{
ulong crc = ~CalcCRC32(buffer, buffer.Length - 4);
buffer[buffer.Length - 1] = (byte)(crc >> 24);
buffer[buffer.Length - 2] = (byte)(crc >> 16);
buffer[buffer.Length - 3] = (byte)(crc >> 8);
buffer[buffer.Length - 4] = (byte)(crc);
}

public byte[] CheckCRC32(byte[] buffer)
{
ulong crc = ~CalcCRC32(buffer, buffer.Length);
if (crc != 0xffffffff00000000u)
return null;
byte[] ret = new byte[buffer.Length - 4];
Array.Copy(buffer, ret, buffer.Length - 4);
return ret;
}
}
}

+ 8
- 10
shadowsocks-csharp/View/ConfigForm.Designer.cs View File

@@ -309,7 +309,6 @@
this.ObfsTCPLabel.Size = new System.Drawing.Size(58, 14);
this.ObfsTCPLabel.TabIndex = 24;
this.ObfsTCPLabel.Text = "Obfs TCP";
this.ObfsTCPLabel.Visible = false;
//
// UDPoverTCPLabel
//
@@ -327,11 +326,10 @@
this.CheckObfsTCP.AutoSize = true;
this.CheckObfsTCP.Location = new System.Drawing.Point(92, 218);
this.CheckObfsTCP.Name = "CheckObfsTCP";
this.CheckObfsTCP.Size = new System.Drawing.Size(144, 18);
this.CheckObfsTCP.Size = new System.Drawing.Size(166, 18);
this.CheckObfsTCP.TabIndex = 27;
this.CheckObfsTCP.Text = "Recommend checked";
this.CheckObfsTCP.Text = "Checked if server support";
this.CheckObfsTCP.UseVisualStyleBackColor = true;
this.CheckObfsTCP.Visible = false;
//
// CheckUDPoverUDP
//
@@ -464,7 +462,7 @@
this.ServersListBox.Location = new System.Drawing.Point(0, 0);
this.ServersListBox.Margin = new System.Windows.Forms.Padding(0);
this.ServersListBox.Name = "ServersListBox";
this.ServersListBox.Size = new System.Drawing.Size(200, 350);
this.ServersListBox.Size = new System.Drawing.Size(200, 390);
this.ServersListBox.TabIndex = 5;
this.ServersListBox.SelectedIndexChanged += new System.EventHandler(this.ServersListBox_SelectedIndexChanged);
//
@@ -624,10 +622,10 @@
this.tableLayoutPanel7.Name = "tableLayoutPanel7";
this.tableLayoutPanel7.RowCount = 4;
this.tableLayoutPanel2.SetRowSpan(this.tableLayoutPanel7, 3);
this.tableLayoutPanel7.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 350F));
this.tableLayoutPanel7.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 390F));
this.tableLayoutPanel7.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel7.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel7.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel7.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 8F));
this.tableLayoutPanel7.Size = new System.Drawing.Size(200, 505);
this.tableLayoutPanel7.TabIndex = 16;
//
@@ -636,7 +634,7 @@
this.CheckAutoBan.Anchor = System.Windows.Forms.AnchorStyles.None;
this.CheckAutoBan.AutoSize = true;
this.tableLayoutPanel7.SetColumnSpan(this.CheckAutoBan, 2);
this.CheckAutoBan.Location = new System.Drawing.Point(63, 461);
this.CheckAutoBan.Location = new System.Drawing.Point(63, 481);
this.CheckAutoBan.Name = "CheckAutoBan";
this.CheckAutoBan.Size = new System.Drawing.Size(73, 18);
this.CheckAutoBan.TabIndex = 17;
@@ -651,7 +649,7 @@
this.tableLayoutPanel6.Controls.Add(this.RandomComboBox, 1, 0);
this.tableLayoutPanel6.Controls.Add(this.LabelRandom, 0, 0);
this.tableLayoutPanel6.Dock = System.Windows.Forms.DockStyle.Bottom;
this.tableLayoutPanel6.Location = new System.Drawing.Point(0, 401);
this.tableLayoutPanel6.Location = new System.Drawing.Point(0, 441);
this.tableLayoutPanel6.Margin = new System.Windows.Forms.Padding(0);
this.tableLayoutPanel6.Name = "tableLayoutPanel6";
this.tableLayoutPanel6.RowCount = 1;
@@ -698,7 +696,7 @@
this.tableLayoutPanel4.Controls.Add(this.DeleteButton, 1, 0);
this.tableLayoutPanel4.Controls.Add(this.AddButton, 0, 0);
this.tableLayoutPanel4.Dock = System.Windows.Forms.DockStyle.Bottom;
this.tableLayoutPanel4.Location = new System.Drawing.Point(0, 355);
this.tableLayoutPanel4.Location = new System.Drawing.Point(0, 395);
this.tableLayoutPanel4.Margin = new System.Windows.Forms.Padding(0, 5, 0, 0);
this.tableLayoutPanel4.Name = "tableLayoutPanel4";
this.tableLayoutPanel4.RowCount = 2;


+ 1
- 1
shadowsocks-csharp/View/ConfigForm.cs View File

@@ -47,7 +47,7 @@ namespace Shadowsocks.View
{
this.Text = I18N.GetString("Edit Servers") + "("
+ (controller.GetCurrentConfiguration().shareOverLan ? "any" : "local") + ":" + controller.GetCurrentConfiguration().localPort.ToString()
+ I18N.GetString(" Version") + UpdateChecker.Version
+ I18N.GetString(" Version") + UpdateChecker.FullVersion
+ ")";
AddButton.Text = I18N.GetString("&Add");


+ 1
- 1
shadowsocks-csharp/View/ServerLogForm.cs View File

@@ -62,7 +62,7 @@ namespace Shadowsocks.View
{
this.Text = I18N.GetString("ServerLog") + "("
+ (controller.GetCurrentConfiguration().shareOverLan ? "any" : "local") + ":" + controller.GetCurrentConfiguration().localPort.ToString()
+ I18N.GetString(" Version") + UpdateChecker.Version
+ I18N.GetString(" Version") + UpdateChecker.FullVersion
+ ")";
}
private void UpdateTexts()


Loading…
Cancel
Save