Ejemplo n.º 1
0
        public override bool UsingEncryptedCommunicationChannel()
        {
            switch (SqlProviderParser.GetSupportedProvider(FactoryName))
            {
            case SqlProvider.SqlClient:
                var encrypt = SqlConnectionStringParser.GetConnectionStringValue(Connection.ConnectionString, new[] { "Encrypt" }, throwIfNotFound: false);

                if (string.IsNullOrEmpty(encrypt))
                {
                    return(false);
                }

                if (bool.TryParse(encrypt, out var encryptBool) == false)
                {
                    return(false);
                }

                return(encryptBool);

            case SqlProvider.Npgsql:
                var sslMode = SqlConnectionStringParser.GetConnectionStringValue(Connection.ConnectionString, new[] { "SslMode" }, throwIfNotFound: false);

                if (string.IsNullOrEmpty(sslMode))
                {
                    return(false);
                }

                switch (sslMode.ToLower())
                {
                case "require":
                case "verify-ca":
                case "verify-full":
                    return(true);
                }

                return(false);

            default:
                throw new NotSupportedException($"Factory '{FactoryName}' is not supported");
            }
        }