Exemplo n.º 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 TestStreamMbedTLSEncryption()
        {
            var failed = false;

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

            foreach (var cipher in StreamMbedTLSEncryptor.SupportedCiphers())
            {
                if (cipher.EndsWith(@"-cbc"))
                {
                    continue;
                }
                var t = new Task(() =>
                {
                    try
                    {
                        RunSingleStreamMbedTLSEncryptionThread(cipher);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($@"{cipher}:{e.Message}");
                        failed = true;
                        throw;
                    }
                });
                tasks.Add(t);
                t.Start();
            }

            Task.WaitAll(tasks.ToArray());
            Assert.IsFalse(failed);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
     }
 }
Exemplo n.º 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));
                }
            }
        }