Skip to content

Commit

Permalink
Merge pull request #3281 from shadowsocks/feature/plain-cipher
Browse files Browse the repository at this point in the history
Add the plain/none cipher
  • Loading branch information
Max Lv authored Feb 8, 2022
2 parents 1155ac5 + 3f6baa4 commit 9987188
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
4.4.1.0 2022-02-08
- Add plain/none ciphers

4.4.0.0 2021-01-01
- Security: remove infrastructure of stream ciphers (#3048)
- Show warning message when importing from deprecated legacy ss:// links.
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# version format
# Build version format is taken from UI if it is not set
version: 4.4.0.{build}
version: 4.4.1.{build}

# # branches to build
# branches:
Expand Down
2 changes: 1 addition & 1 deletion shadowsocks-csharp/Controller/Service/UpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class UpdateChecker

public event EventHandler CheckUpdateCompleted;

public const string Version = "4.4.0.0";
public const string Version = "4.4.1.0";
private readonly Version _version;

public UpdateChecker()
Expand Down
9 changes: 9 additions & 0 deletions shadowsocks-csharp/Encryption/EncryptorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Reflection;
using System.Text;
using Shadowsocks.Encryption.AEAD;
using Shadowsocks.Encryption.Stream;

namespace Shadowsocks.Encryption
{
Expand All @@ -16,6 +17,8 @@ static EncryptorFactory()
{
var AEADMbedTLSEncryptorSupportedCiphers = AEADMbedTLSEncryptor.SupportedCiphers();
var AEADSodiumEncryptorSupportedCiphers = AEADSodiumEncryptor.SupportedCiphers();
var PlainEncryptorSupportedCiphers = PlainEncryptor.SupportedCiphers();

if (Sodium.AES256GCMAvailable)
{
// prefer to aes-256-gcm in libsodium
Expand Down Expand Up @@ -43,6 +46,12 @@ static EncryptorFactory()
if (!_registeredEncryptors.ContainsKey(method))
_registeredEncryptors.Add(method, typeof(AEADMbedTLSEncryptor));
}

foreach (string method in PlainEncryptorSupportedCiphers)
{
if (!_registeredEncryptors.ContainsKey(method))
_registeredEncryptors.Add(method, typeof(PlainEncryptor));
}
}

public static IEncryptor GetEncryptor(string method, string password)
Expand Down
98 changes: 98 additions & 0 deletions shadowsocks-csharp/Encryption/Stream/PlainEncryptor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;

namespace Shadowsocks.Encryption.Stream
{
class PlainEncryptor
: EncryptorBase, IDisposable
{
const int CIPHER_NONE = 1;

private static Dictionary<string, EncryptorInfo> _ciphers = new Dictionary<string, EncryptorInfo> {
{ "plain", new EncryptorInfo("PLAIN", 0, 0, CIPHER_NONE) },
{ "none", new EncryptorInfo("PLAIN", 0, 0, CIPHER_NONE) }
};

public PlainEncryptor(string method, string password) : base(method, password)
{
}

public static List<string> SupportedCiphers()
{
return new List<string>(_ciphers.Keys);
}

protected Dictionary<string, EncryptorInfo> getCiphers()
{
return _ciphers;
}

#region TCP

public override void Encrypt(byte[] buf, int length, byte[] outbuf, out int outlength)
{
Buffer.BlockCopy(buf, 0, outbuf, 0, length);
outlength = length;
}

public override void Decrypt(byte[] buf, int length, byte[] outbuf, out int outlength)
{
Buffer.BlockCopy(buf, 0, outbuf, 0, length);
outlength = length;
}

#endregion

#region UDP

public override void EncryptUDP(byte[] buf, int length, byte[] outbuf, out int outlength)
{
Buffer.BlockCopy(buf, 0, outbuf, 0, length);
outlength = length;
}

public override void DecryptUDP(byte[] buf, int length, byte[] outbuf, out int outlength)
{
Buffer.BlockCopy(buf, 0, outbuf, 0, length);
outlength = length;
}

#endregion


#region IDisposable

private bool _disposed;

// instance based lock
private readonly object _lock = new object();

public override void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

~PlainEncryptor()
{
Dispose(false);
}

protected virtual void Dispose(bool disposing)
{
lock (_lock)
{
if (_disposed) return;
_disposed = true;
}

if (disposing)
{
// free managed objects
}
}

#endregion

}
}
7 changes: 7 additions & 0 deletions shadowsocks-csharp/View/ConfigForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ private class EncryptionMethod
// Edit here to add/delete encryption method displayed in UI
private static string[] inuseMethod = new string[]
{
"none",
"plain",
"aes-256-gcm",
"aes-192-gcm",
"aes-128-gcm",
Expand Down Expand Up @@ -611,5 +613,10 @@ private void UsePluginArgCheckBox_CheckedChanged(object sender, EventArgs e)
{
ShowHidePluginArgInput(NeedPluginArgCheckBox.Checked);
}

private void EncryptionSelect_SelectedIndexChanged(object sender, EventArgs e)
{

}
}
}
1 change: 1 addition & 0 deletions shadowsocks-csharp/shadowsocks-csharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
<Compile Include="Encryption\OpenSSL.cs" />
<Compile Include="Encryption\RNG.cs" />
<Compile Include="Encryption\Sodium.cs" />
<Compile Include="Encryption\Stream\PlainEncryptor.cs" />
<Compile Include="Localization\LocalizationProvider.cs" />
<Compile Include="Localization\Strings.Designer.cs">
<AutoGen>True</AutoGen>
Expand Down

0 comments on commit 9987188

Please sign in to comment.