diff --git a/shadowsocks-csharp/Encryption/AEAD/AEADAesGcmNativeEncryptor.cs b/shadowsocks-csharp/Encryption/AEAD/AEADAesGcmNativeEncryptor.cs index dc6da1c7..aa122ac9 100644 --- a/shadowsocks-csharp/Encryption/AEAD/AEADAesGcmNativeEncryptor.cs +++ b/shadowsocks-csharp/Encryption/AEAD/AEADAesGcmNativeEncryptor.cs @@ -16,9 +16,9 @@ namespace Shadowsocks.Encryption.AEAD private static readonly Dictionary _ciphers = new Dictionary { - {"aes-128-gcm", new CipherInfo("AES-128-GCM", 16, 16, 12, 16, CipherFamily.AesGcm)}, - {"aes-192-gcm", new CipherInfo("AES-192-GCM", 24, 24, 12, 16, CipherFamily.AesGcm)}, - {"aes-256-gcm", new CipherInfo("AES-256-GCM", 32, 32, 12, 16, CipherFamily.AesGcm)}, + {"aes-128-gcm", new CipherInfo("aes-128-gcm", 16, 16, 12, 16, CipherFamily.AesGcm)}, + {"aes-192-gcm", new CipherInfo("aes-192-gcm", 24, 24, 12, 16, CipherFamily.AesGcm)}, + {"aes-256-gcm", new CipherInfo("aes-256-gcm", 32, 32, 12, 16, CipherFamily.AesGcm)}, }; protected override Dictionary getCiphers() diff --git a/shadowsocks-csharp/Encryption/CipherInfo.cs b/shadowsocks-csharp/Encryption/CipherInfo.cs index 149e3950..79753cbd 100644 --- a/shadowsocks-csharp/Encryption/CipherInfo.cs +++ b/shadowsocks-csharp/Encryption/CipherInfo.cs @@ -1,4 +1,5 @@ -using System; +using Shadowsocks.Controller; +using System; namespace Shadowsocks.Encryption { @@ -81,5 +82,10 @@ namespace Shadowsocks.Encryption }; } #endregion + + public override string ToString() + { + return StandardState == CipherStandardState.InUse ? Name : $"{Name} ({I18N.GetString("deprecated")})"; + } } } \ No newline at end of file diff --git a/shadowsocks-csharp/Encryption/EncryptorFactory.cs b/shadowsocks-csharp/Encryption/EncryptorFactory.cs index ce6dbc28..c9eadb7f 100644 --- a/shadowsocks-csharp/Encryption/EncryptorFactory.cs +++ b/shadowsocks-csharp/Encryption/EncryptorFactory.cs @@ -79,15 +79,25 @@ namespace Shadowsocks.Encryption { var sb = new StringBuilder(); sb.Append(Environment.NewLine); - sb.AppendLine("========================="); + sb.AppendLine("-------------------------"); sb.AppendLine("Registered Encryptor Info"); foreach (var encryptor in _registeredEncryptors) { sb.AppendLine(String.Format("{0}=>{1}", encryptor.Key, encryptor.Value.Name)); } - - sb.AppendLine("========================="); + // use ----- instead of =======, so when user paste it to Github, it won't became title + sb.AppendLine("-------------------------"); return sb.ToString(); } + + public static CipherInfo GetCipherInfo(string name) + { + return ciphers[name]; + } + + public static IEnumerable ListAvaliableCiphers() + { + return ciphers.Values; + } } } \ No newline at end of file diff --git a/shadowsocks-csharp/View/ConfigForm.cs b/shadowsocks-csharp/View/ConfigForm.cs index 1384b336..798aff30 100755 --- a/shadowsocks-csharp/View/ConfigForm.cs +++ b/shadowsocks-csharp/View/ConfigForm.cs @@ -1,4 +1,5 @@ using Shadowsocks.Controller; +using Shadowsocks.Encryption; using Shadowsocks.Model; using Shadowsocks.Properties; using System; @@ -19,98 +20,11 @@ namespace Shadowsocks.View private bool isChange = false; - private class EncryptionMethod - { - public readonly string name; - public readonly bool deprecated; - - // Edit here to add/delete encryption method displayed in UI - private static string[] deprecatedMethod = new string[] - { - "rc4-md5", - "salsa20", - "chacha20", - "bf-cfb", - - "rc4", - "plain", - "table", - }; - private static string[] inuseMethod = new string[] - { - "aes-256-gcm", - "aes-192-gcm", - "aes-128-gcm", - "chacha20-ietf-poly1305", - "xchacha20-ietf-poly1305", - "chacha20-ietf", - "aes-256-cfb", - "aes-192-cfb", - "aes-128-cfb", - "aes-256-ctr", - "aes-192-ctr", - "aes-128-ctr", - "camellia-256-cfb", - "camellia-192-cfb", - "camellia-128-cfb", - }; - - public static EncryptionMethod[] AllMethods - { - get - { - if (!init) Init(); - return allMethods; - } - } - private static bool init = false; - private static EncryptionMethod[] allMethods; - private static Dictionary methodByName = new Dictionary(); - private static void Init() - { - var all = new List(); - - all.AddRange(inuseMethod.Select(i => new EncryptionMethod(i, false))); - all.AddRange(deprecatedMethod.Select(d => new EncryptionMethod(d, true))); - - allMethods = all.ToArray(); - foreach (var item in all) - { - methodByName[item.name] = item; - } - init = true; - } - - public static EncryptionMethod GetMethod(string name) - { - if (!init) Init(); - bool success = methodByName.TryGetValue(name, out EncryptionMethod method); - if (!success) - { - string defaultMethod = Server.DefaultMethod; - MessageBox.Show(I18N.GetString("Encryption method {0} not exist, will replace with {1}", name, defaultMethod), I18N.GetString("Shadowsocks")); - return methodByName[defaultMethod]; - } - return method; - } - - private EncryptionMethod(string name, bool deprecated) - { - this.name = name; - this.deprecated = deprecated; - } - - public override string ToString() - { - return deprecated ? $"{name} ({I18N.GetString("deprecated")})" : name; - } - } - public ConfigForm(ShadowsocksController controller) { Font = SystemFonts.MessageBoxFont; InitializeComponent(); - EncryptionSelect.Items.AddRange(EncryptionMethod.AllMethods); + EncryptionSelect.Items.AddRange(EncryptorFactory.ListAvaliableCiphers().ToArray()); // a dirty hack ServersListBox.Dock = DockStyle.Fill; @@ -205,7 +119,7 @@ namespace Shadowsocks.View server = address, server_port = addressPort.Value, password = serverPassword, - method = ((EncryptionMethod)EncryptionSelect.SelectedItem).name, + method = ((CipherInfo)EncryptionSelect.SelectedItem).Name, plugin = PluginTextBox.Text, plugin_opts = PluginOptionsTextBox.Text, plugin_args = PluginArgumentsTextBox.Text, @@ -406,7 +320,7 @@ namespace Shadowsocks.View IPTextBox.Text = server.server; ServerPortTextBox.Text = server.server_port.ToString(); PasswordTextBox.Text = server.password; - EncryptionSelect.SelectedItem = EncryptionMethod.GetMethod(server.method ?? Server.DefaultMethod); + EncryptionSelect.SelectedItem = EncryptorFactory.GetCipherInfo(server.method ?? Server.DefaultMethod); PluginTextBox.Text = server.plugin; PluginOptionsTextBox.Text = server.plugin_opts; PluginArgumentsTextBox.Text = server.plugin_args;