Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientSocketConnection"/> class.
 /// </summary>
 /// <param name="id">The unique identifier of the connection.</param>
 /// <param name="endpoint">The socket endpoint.</param>
 /// <param name="options">Socket options.</param>
 /// <param name="sslOptions">SSL options.</param>
 /// <param name="loggerFactory">A logger factory.</param>
 /// <param name="prefixLength">An optional prefix length.</param>
 public ClientSocketConnection(int id, IPEndPoint endpoint, SocketOptions options, SslOptions sslOptions, ILoggerFactory loggerFactory, int prefixLength = 0)
     : base(id, prefixLength)
 {
     _endpoint      = endpoint ?? throw new ArgumentNullException(nameof(endpoint));
     _socketOptions = options ?? throw new ArgumentNullException(nameof(options));
     _sslOptions    = sslOptions ?? throw new ArgumentNullException(nameof(sslOptions));
     _loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
     HConsole.Configure(this, config => config.SetIndent(16).SetPrefix($"CONN.CLIENT [{id}]"));
 }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClientSocketConnection"/> class.
        /// </summary>
        /// <param name="id">The unique identifier of the connection.</param>
        /// <param name="endpoint">The socket endpoint.</param>
        /// <param name="options">Networking options.</param>
        /// <param name="sslOptions">SSL options.</param>
        /// <param name="loggerFactory">A logger factory.</param>
        /// <param name="prefixLength">An optional prefix length.</param>
        public ClientSocketConnection(Guid id, IPEndPoint endpoint, NetworkingOptions options, SslOptions sslOptions, ILoggerFactory loggerFactory, int prefixLength = 0)
            : base(id, prefixLength)
        {
            _endpoint      = endpoint ?? throw new ArgumentNullException(nameof(endpoint));
            _options       = options ?? throw new ArgumentNullException(nameof(options));
            _sslOptions    = sslOptions ?? throw new ArgumentNullException(nameof(sslOptions));
            _loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));

            HConsole.Configure(x => x.Configure(this).SetIndent(16).SetPrefix($"CLT.CONN [{id.ToShortString()}]"));
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SslOptions"/> class.
 /// </summary>
 private SslOptions(SslOptions other)
 {
     Enabled = other.Enabled;
     ValidateCertificateChain   = other.ValidateCertificateChain;
     ValidateCertificateName    = other.ValidateCertificateName;
     CheckCertificateRevocation = other.CheckCertificateRevocation;
     CertificateName            = other.CertificateName;
     CertificatePath            = other.CertificatePath;
     CertificatePassword        = other.CertificatePassword;
     _sslProtocol = other._sslProtocol;
 }
Esempio n. 4
0
        private X509Certificate2Collection GetClientCertificatesOrDefault(SslOptions options)
        {
            if (_options.CertificatePath == null)
            {
                return(null);
            }

            var clientCertificates = new X509Certificate2Collection();

            try
            {
                clientCertificates.Import(_options.CertificatePath, options.CertificatePassword, X509KeyStorageFlags.DefaultKeySet);
            }
            catch (Exception e)
            {
                _logger.LogWarning(e, $"Failed to load client certificate at \"{_options.CertificatePath}\".");
                throw;
            }

            return(clientCertificates);
        }
 public SslLayer(SslOptions options, ILoggerFactory loggerFactory)
 {
     _options = options ?? throw new ArgumentNullException(nameof(options));
     _logger  = loggerFactory?.CreateLogger <SslLayer>() ?? throw new ArgumentNullException(nameof(loggerFactory));
 }