Exemple #1
0
        /// <summary>
        /// Initializes a new instance of <see cref="ClickHouseConnection"/> with the settings.
        /// </summary>
        /// <param name="connectionSettings">The connection settings.</param>
        /// <param name="typeInfoProvider">Optional parameter. The provider of types for the connection. If the value is not specified the default type provider (<see cref="DefaultTypeInfoProvider.Instance"/>) will be used.</param>
        public ClickHouseConnection(ClickHouseConnectionSettings connectionSettings, IClickHouseTypeInfoProvider?typeInfoProvider)
        {
            if (connectionSettings == null)
            {
                throw new ArgumentNullException(nameof(connectionSettings));
            }

            _connectionState  = new ClickHouseConnectionState(ConnectionState.Closed, null, connectionSettings, 0);
            _typeInfoProvider = typeInfoProvider;
        }
Exemple #2
0
 public ClickHouseTcpClient(
     TcpClient client,
     ClickHouseBinaryProtocolReader reader,
     ClickHouseBinaryProtocolWriter writer,
     ClickHouseConnectionSettings settings,
     ClickHouseServerInfo serverInfo,
     IClickHouseTypeInfoProvider typeInfoProvider)
 {
     _reader          = reader ?? throw new ArgumentNullException(nameof(reader));
     _writer          = writer ?? throw new ArgumentNullException(nameof(writer));
     _client          = client ?? throw new ArgumentNullException(nameof(client));
     _settings        = settings ?? throw new ArgumentNullException(nameof(settings));
     ServerInfo       = serverInfo;
     TypeInfoProvider = typeInfoProvider;
 }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of <see cref="ClickHouseConnection"/> with the settings and the default type provider.
 /// </summary>
 /// <param name="connectionSettings">The connection settings.</param>
 public ClickHouseConnection(ClickHouseConnectionSettings connectionSettings)
     : this(connectionSettings, null)
 {
 }
Exemple #4
0
        private static bool ValidateServerCertificate(ClickHouseConnectionSettings connectionSettings, X509Certificate?cert, X509Chain?chain, SslPolicyErrors errors)
        {
            if (errors == SslPolicyErrors.None)
            {
                return(true);
            }

            if (cert == null)
            {
                return(false);
            }

            if (!connectionSettings.ServerCertificateHash.IsEmpty)
            {
                var certHash = cert.GetCertHash();
                if (connectionSettings.ServerCertificateHash.Span.SequenceEqual(certHash))
                {
                    return(true);
                }
            }

            if (chain != null && connectionSettings.RootCertificate != null)
            {
                if ((errors & ~SslPolicyErrors.RemoteCertificateChainErrors) != SslPolicyErrors.None)
                {
                    return(false);
                }

                var collection = CertificateHelper.LoadFromFile(connectionSettings.RootCertificate);
#if NET5_0_OR_GREATER
                chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
                chain.ChainPolicy.CustomTrustStore.AddRange(collection);
                var isValid = chain.Build(cert as X509Certificate2 ?? new X509Certificate2(cert));
                return(isValid);
#else
                foreach (var chainElement in chain.ChainElements)
                {
                    if (chainElement.ChainElementStatus.Length != 0)
                    {
                        bool ignoreError = true;
                        foreach (var status in chainElement.ChainElementStatus)
                        {
                            if (status.Status == X509ChainStatusFlags.UntrustedRoot)
                            {
                                continue;
                            }

                            ignoreError = false;
                            break;
                        }

                        if (!ignoreError)
                        {
                            break;
                        }
                    }

                    if (collection.Contains(chainElement.Certificate))
                    {
                        return(true);
                    }
                }
#endif
            }

            return(false);
        }