Exemple #1
0
        static EncryptorFactory()
        {
            var AEADMbedTLSEncryptorSupportedCiphers = AEADMbedTLSEncryptor.SupportedCiphers();
            var AEADSodiumEncryptorSupportedCiphers  = AEADSodiumEncryptor.SupportedCiphers();

            if (Sodium.AES256GCMAvailable)
            {
                // prefer to aes-256-gcm in libsodium
                AEADMbedTLSEncryptorSupportedCiphers.Remove("aes-256-gcm");
            }
            else
            {
                AEADSodiumEncryptorSupportedCiphers.Remove("aes-256-gcm");
            }

            foreach (string method in StreamMbedTLSEncryptor.SupportedCiphers())
            {
                _registeredEncryptors.Add(method, typeof(StreamMbedTLSEncryptor));
            }
            foreach (string method in StreamSodiumEncryptor.SupportedCiphers())
            {
                _registeredEncryptors.Add(method, typeof(StreamSodiumEncryptor));
            }
            foreach (string method in AEADMbedTLSEncryptorSupportedCiphers)
            {
                _registeredEncryptors.Add(method, typeof(AEADMbedTLSEncryptor));
            }
            foreach (string method in AEADSodiumEncryptorSupportedCiphers)
            {
                _registeredEncryptors.Add(method, typeof(AEADSodiumEncryptor));
            }
        }
        public void TestStreamSodiumEncryption()
        {
            var failed = false;

            // run it once before the multi-threading test to initialize global tables
            RunSingleStreamSodiumEncryptionThread();
            var tasks = new List <Task>();

            foreach (var cipher in StreamSodiumEncryptor.SupportedCiphers())
            {
                if (cipher.StartsWith(@"x"))
                {
                    continue;
                }
                var t = new Task(() =>
                {
                    try
                    {
                        RunSingleStreamSodiumEncryptionThread(cipher);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($@"{cipher}:{e.Message}");
                        failed = true;
                        throw;
                    }
                });
                tasks.Add(t);
                t.Start();
            }

            Task.WaitAll(tasks.ToArray());
            Assert.IsFalse(failed);
        }
Exemple #3
0
        static EncryptorFactory()
        {
            foreach (var method in NoneEncryptor.SupportedCiphers())
            {
                if (!_registeredEncryptors.ContainsKey(method))
                {
                    _registeredEncryptors.Add(method, typeof(NoneEncryptor));
                }
            }

            foreach (var method in StreamOpenSSLEncryptor.SupportedCiphers())
            {
                if (!_registeredEncryptors.ContainsKey(method))
                {
                    _registeredEncryptors.Add(method, typeof(StreamOpenSSLEncryptor));
                }
            }


            foreach (var method in StreamSodiumEncryptor.SupportedCiphers())
            {
                if (!_registeredEncryptors.ContainsKey(method))
                {
                    _registeredEncryptors.Add(method, typeof(StreamSodiumEncryptor));
                }
            }

            foreach (var method in StreamMbedTLSEncryptor.SupportedCiphers())
            {
                if (!_registeredEncryptors.ContainsKey(method))
                {
                    _registeredEncryptors.Add(method, typeof(StreamMbedTLSEncryptor));
                }
            }
        }
        static EncryptorFactory()
        {
            foreach (var method in NoneEncryptor.SupportedCiphers().Where(method => !RegisteredEncryptors.ContainsKey(method)))
            {
                RegisteredEncryptors.Add(method, typeof(NoneEncryptor));
            }

            foreach (var method in StreamOpenSSLEncryptor.SupportedCiphers().Where(method => !RegisteredEncryptors.ContainsKey(method)))
            {
                RegisteredEncryptors.Add(method, typeof(StreamOpenSSLEncryptor));
            }

            foreach (var method in StreamSodiumEncryptor.SupportedCiphers().Where(method => !RegisteredEncryptors.ContainsKey(method)))
            {
                RegisteredEncryptors.Add(method, typeof(StreamSodiumEncryptor));
            }

            foreach (var method in StreamMbedTLSEncryptor.SupportedCiphers().Where(method => !RegisteredEncryptors.ContainsKey(method)))
            {
                RegisteredEncryptors.Add(method, typeof(StreamMbedTLSEncryptor));
            }

            var allEncryptor = new StringBuilder(Environment.NewLine);

            allEncryptor.AppendLine(@"============================");
            allEncryptor.AppendLine(@"Registered Encryptor Info");
            foreach (var encryptor in RegisteredEncryptors)
            {
                allEncryptor.AppendLine($@"{encryptor.Key}=>{encryptor.Value.Name}");
            }
            allEncryptor.AppendLine(@"============================");
            Console.WriteLine(allEncryptor);
        }
Exemple #5
0
 static EncryptorFactory()
 {
     foreach (string method in StreamMbedTLSEncryptor.SupportedCiphers())
     {
         _registeredEncryptors.Add(method, typeof(StreamMbedTLSEncryptor));
     }
     foreach (string method in StreamSodiumEncryptor.SupportedCiphers())
     {
         _registeredEncryptors.Add(method, typeof(StreamSodiumEncryptor));
     }
     foreach (string method in AEADMbedTLSEncryptor.SupportedCiphers())
     {
         _registeredEncryptors.Add(method, typeof(AEADMbedTLSEncryptor));
     }
     foreach (string method in AEADSodiumEncryptor.SupportedCiphers())
     {
         _registeredEncryptors.Add(method, typeof(AEADSodiumEncryptor));
     }
 }
Exemple #6
0
        static EncryptorFactory()
        {
            var AEADMbedTLSEncryptorSupportedCiphers = AEADMbedTLSEncryptor.SupportedCiphers();
            var AEADSodiumEncryptorSupportedCiphers  = AEADSodiumEncryptor.SupportedCiphers();

            if (Sodium.AES256GCMAvailable)
            {
                // prefer to aes-256-gcm in libsodium
                AEADMbedTLSEncryptorSupportedCiphers.Remove("aes-256-gcm");
            }
            else
            {
                AEADSodiumEncryptorSupportedCiphers.Remove("aes-256-gcm");
            }
#if I_KNOW_STREAM_CIPHER_IS_UNSAFE
            // XXX: sequence matters, OpenSSL > Sodium > MbedTLS
            foreach (string method in StreamOpenSSLEncryptor.SupportedCiphers())
            {
                if (!_registeredEncryptors.ContainsKey(method))
                {
                    _registeredEncryptors.Add(method, typeof(StreamOpenSSLEncryptor));
                }
            }

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

            foreach (string method in StreamMbedTLSEncryptor.SupportedCiphers())
            {
                if (!_registeredEncryptors.ContainsKey(method))
                {
                    _registeredEncryptors.Add(method, typeof(StreamMbedTLSEncryptor));
                }
            }
#endif

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

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

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