#region License /* * ServerSslConfiguration.cs * * The MIT License * * Copyright (c) 2014 liryna * Copyright (c) 2014-2017 sta.blockhead * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #endregion #region Authors /* * Authors: * - Liryna */ #endregion using System; using System.Net.Security; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; namespace WebSocketSharp.Net { /// /// Stores the parameters for the used by servers. /// public class ServerSslConfiguration { #region Private Fields private bool _checkCertRevocation; private bool _clientCertRequired; private RemoteCertificateValidationCallback _clientCertValidationCallback; private SslProtocols _enabledSslProtocols; private X509Certificate2 _serverCert; #endregion #region Public Constructors /// /// Initializes a new instance of the class. /// public ServerSslConfiguration () { _enabledSslProtocols = SslProtocols.Default; } /// /// Initializes a new instance of the class /// with the specified . /// /// /// A that represents the certificate used to /// authenticate the server. /// public ServerSslConfiguration (X509Certificate2 serverCertificate) { _serverCert = serverCertificate; _enabledSslProtocols = SslProtocols.Default; } /// /// Copies the parameters from the specified to /// a new instance of the class. /// /// /// A from which to copy. /// /// /// is . /// public ServerSslConfiguration (ServerSslConfiguration configuration) { if (configuration == null) throw new ArgumentNullException ("configuration"); _checkCertRevocation = configuration._checkCertRevocation; _clientCertRequired = configuration._clientCertRequired; _clientCertValidationCallback = configuration._clientCertValidationCallback; _enabledSslProtocols = configuration._enabledSslProtocols; _serverCert = configuration._serverCert; } #endregion #region Public Properties /// /// Gets or sets a value indicating whether the certificate revocation /// list is checked during authentication. /// /// /// /// true if the certificate revocation list is checked during /// authentication; otherwise, false. /// /// /// The default value is false. /// /// public bool CheckCertificateRevocation { get { return _checkCertRevocation; } set { _checkCertRevocation = value; } } /// /// Gets or sets a value indicating whether the client is asked for /// a certificate for authentication. /// /// /// /// true if the client is asked for a certificate for /// authentication; otherwise, false. /// /// /// The default value is false. /// /// public bool ClientCertificateRequired { get { return _clientCertRequired; } set { _clientCertRequired = value; } } /// /// Gets or sets the callback used to validate the certificate /// supplied by the client. /// /// /// The certificate is valid if the callback returns true. /// /// /// /// A delegate that /// invokes the method called for validating the certificate. /// /// /// The default value is a delegate that invokes a method that /// only returns true. /// /// public RemoteCertificateValidationCallback ClientCertificateValidationCallback { get { if (_clientCertValidationCallback == null) _clientCertValidationCallback = defaultValidateClientCertificate; return _clientCertValidationCallback; } set { _clientCertValidationCallback = value; } } /// /// Gets or sets the protocols used for authentication. /// /// /// /// The enum values that represent /// the protocols used for authentication. /// /// /// The default value is . /// /// public SslProtocols EnabledSslProtocols { get { return _enabledSslProtocols; } set { _enabledSslProtocols = value; } } /// /// Gets or sets the certificate used to authenticate the server. /// /// /// /// A or /// if not specified. /// /// /// That instance represents an X.509 certificate. /// /// public X509Certificate2 ServerCertificate { get { return _serverCert; } set { _serverCert = value; } } #endregion #region Private Methods private static bool defaultValidateClientCertificate ( object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors ) { return true; } #endregion } }