Skip to content

Commit 9987188

Browse files
author
Max Lv
authored
Merge pull request #3281 from shadowsocks/feature/plain-cipher
Add the plain/none cipher
2 parents 1155ac5 + 3f6baa4 commit 9987188

File tree

7 files changed

+120
-2
lines changed

7 files changed

+120
-2
lines changed

Diff for: CHANGES

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
4.4.1.0 2022-02-08
2+
- Add plain/none ciphers
3+
14
4.4.0.0 2021-01-01
25
- Security: remove infrastructure of stream ciphers (#3048)
36
- Show warning message when importing from deprecated legacy ss:// links.

Diff for: appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
# version format
1313
# Build version format is taken from UI if it is not set
14-
version: 4.4.0.{build}
14+
version: 4.4.1.{build}
1515

1616
# # branches to build
1717
# branches:

Diff for: shadowsocks-csharp/Controller/Service/UpdateChecker.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class UpdateChecker
3333

3434
public event EventHandler CheckUpdateCompleted;
3535

36-
public const string Version = "4.4.0.0";
36+
public const string Version = "4.4.1.0";
3737
private readonly Version _version;
3838

3939
public UpdateChecker()

Diff for: shadowsocks-csharp/Encryption/EncryptorFactory.cs

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Reflection;
44
using System.Text;
55
using Shadowsocks.Encryption.AEAD;
6+
using Shadowsocks.Encryption.Stream;
67

78
namespace Shadowsocks.Encryption
89
{
@@ -16,6 +17,8 @@ static EncryptorFactory()
1617
{
1718
var AEADMbedTLSEncryptorSupportedCiphers = AEADMbedTLSEncryptor.SupportedCiphers();
1819
var AEADSodiumEncryptorSupportedCiphers = AEADSodiumEncryptor.SupportedCiphers();
20+
var PlainEncryptorSupportedCiphers = PlainEncryptor.SupportedCiphers();
21+
1922
if (Sodium.AES256GCMAvailable)
2023
{
2124
// prefer to aes-256-gcm in libsodium
@@ -43,6 +46,12 @@ static EncryptorFactory()
4346
if (!_registeredEncryptors.ContainsKey(method))
4447
_registeredEncryptors.Add(method, typeof(AEADMbedTLSEncryptor));
4548
}
49+
50+
foreach (string method in PlainEncryptorSupportedCiphers)
51+
{
52+
if (!_registeredEncryptors.ContainsKey(method))
53+
_registeredEncryptors.Add(method, typeof(PlainEncryptor));
54+
}
4655
}
4756

4857
public static IEncryptor GetEncryptor(string method, string password)
+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Shadowsocks.Encryption.Stream
5+
{
6+
class PlainEncryptor
7+
: EncryptorBase, IDisposable
8+
{
9+
const int CIPHER_NONE = 1;
10+
11+
private static Dictionary<string, EncryptorInfo> _ciphers = new Dictionary<string, EncryptorInfo> {
12+
{ "plain", new EncryptorInfo("PLAIN", 0, 0, CIPHER_NONE) },
13+
{ "none", new EncryptorInfo("PLAIN", 0, 0, CIPHER_NONE) }
14+
};
15+
16+
public PlainEncryptor(string method, string password) : base(method, password)
17+
{
18+
}
19+
20+
public static List<string> SupportedCiphers()
21+
{
22+
return new List<string>(_ciphers.Keys);
23+
}
24+
25+
protected Dictionary<string, EncryptorInfo> getCiphers()
26+
{
27+
return _ciphers;
28+
}
29+
30+
#region TCP
31+
32+
public override void Encrypt(byte[] buf, int length, byte[] outbuf, out int outlength)
33+
{
34+
Buffer.BlockCopy(buf, 0, outbuf, 0, length);
35+
outlength = length;
36+
}
37+
38+
public override void Decrypt(byte[] buf, int length, byte[] outbuf, out int outlength)
39+
{
40+
Buffer.BlockCopy(buf, 0, outbuf, 0, length);
41+
outlength = length;
42+
}
43+
44+
#endregion
45+
46+
#region UDP
47+
48+
public override void EncryptUDP(byte[] buf, int length, byte[] outbuf, out int outlength)
49+
{
50+
Buffer.BlockCopy(buf, 0, outbuf, 0, length);
51+
outlength = length;
52+
}
53+
54+
public override void DecryptUDP(byte[] buf, int length, byte[] outbuf, out int outlength)
55+
{
56+
Buffer.BlockCopy(buf, 0, outbuf, 0, length);
57+
outlength = length;
58+
}
59+
60+
#endregion
61+
62+
63+
#region IDisposable
64+
65+
private bool _disposed;
66+
67+
// instance based lock
68+
private readonly object _lock = new object();
69+
70+
public override void Dispose()
71+
{
72+
Dispose(true);
73+
GC.SuppressFinalize(this);
74+
}
75+
76+
~PlainEncryptor()
77+
{
78+
Dispose(false);
79+
}
80+
81+
protected virtual void Dispose(bool disposing)
82+
{
83+
lock (_lock)
84+
{
85+
if (_disposed) return;
86+
_disposed = true;
87+
}
88+
89+
if (disposing)
90+
{
91+
// free managed objects
92+
}
93+
}
94+
95+
#endregion
96+
97+
}
98+
}

Diff for: shadowsocks-csharp/View/ConfigForm.cs

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ private class EncryptionMethod
2727
// Edit here to add/delete encryption method displayed in UI
2828
private static string[] inuseMethod = new string[]
2929
{
30+
"none",
31+
"plain",
3032
"aes-256-gcm",
3133
"aes-192-gcm",
3234
"aes-128-gcm",
@@ -611,5 +613,10 @@ private void UsePluginArgCheckBox_CheckedChanged(object sender, EventArgs e)
611613
{
612614
ShowHidePluginArgInput(NeedPluginArgCheckBox.Checked);
613615
}
616+
617+
private void EncryptionSelect_SelectedIndexChanged(object sender, EventArgs e)
618+
{
619+
620+
}
614621
}
615622
}

Diff for: shadowsocks-csharp/shadowsocks-csharp.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@
240240
<Compile Include="Encryption\OpenSSL.cs" />
241241
<Compile Include="Encryption\RNG.cs" />
242242
<Compile Include="Encryption\Sodium.cs" />
243+
<Compile Include="Encryption\Stream\PlainEncryptor.cs" />
243244
<Compile Include="Localization\LocalizationProvider.cs" />
244245
<Compile Include="Localization\Strings.Designer.cs">
245246
<AutoGen>True</AutoGen>

0 commit comments

Comments
 (0)