diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs index d1aafab3..e35f221a 100644 --- a/websocket-sharp/Ext.cs +++ b/websocket-sharp/Ext.cs @@ -554,7 +554,7 @@ namespace WebSocketSharp this TcpClient tcpClient, string protocol, bool secure, - ServerCertAuthConfiguration certificateConfig, + ServerSslAuthConfiguration certificateConfig, Logger logger) { return new TcpListenerWebSocketContext (tcpClient, protocol, secure, certificateConfig, logger); diff --git a/websocket-sharp/Net/ClientCertAuthConfiguration.cs b/websocket-sharp/Net/ClientCertAuthConfiguration.cs deleted file mode 100644 index 6cabd20b..00000000 --- a/websocket-sharp/Net/ClientCertAuthConfiguration.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Security.Authentication; -using System.Security.Cryptography.X509Certificates; - -namespace WebSocketSharp -{ - public class ClientCertAuthConfiguration - { - /// - /// Gets or sets the certificate configuration used to authenticate the clients on the secure connection. - /// - /// - /// A that represents the certificate collection used to authenticate - /// the clients. - /// - public X509CertificateCollection clientCertificates { get; set; } - - /// - /// Gets or sets the Ssl protocols type enabled. - /// - /// - /// The value that represents the protocol used for authentication. - /// - public SslProtocols EnabledSslProtocols { get; set; } - - /// - /// Gets or sets the verification of certificate revocation option. - /// - /// - /// A Boolean value that specifies whether the certificate revocation list is checked during authentication. - /// - public bool CheckCertificateRevocation { get; set; } - - /// - /// Initializes a new instance of the class. - /// - public ClientCertAuthConfiguration(X509CertificateCollection clientCertificates, - SslProtocols enabledSslProtocols = SslProtocols.Default, bool checkCertificateRevocation = false) - { - this.clientCertificates = clientCertificates; - this.EnabledSslProtocols = enabledSslProtocols; - this.CheckCertificateRevocation = checkCertificateRevocation; - } - } -} \ No newline at end of file diff --git a/websocket-sharp/Net/ClientSslAuthConfiguration.cs b/websocket-sharp/Net/ClientSslAuthConfiguration.cs new file mode 100644 index 00000000..0a518eb3 --- /dev/null +++ b/websocket-sharp/Net/ClientSslAuthConfiguration.cs @@ -0,0 +1,96 @@ +#region License +/* + * ClientSslAuthConfiguration.cs + * + * The MIT License + * + * Copyright (c) 2014 liryna + * + * 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 liryna.stark@gmail.com + */ +#endregion + +using System.Security.Authentication; +using System.Security.Cryptography.X509Certificates; + +namespace WebSocketSharp +{ + public class ClientSslAuthConfiguration + { + /// + /// Gets or sets the certificate configuration used to authenticate the clients on the secure connection. + /// + /// + /// A that represents the certificate collection used to authenticate + /// the clients. + /// + public X509CertificateCollection clientCertificates { get; set; } + + /// + /// Gets or sets the Ssl protocols type enabled. + /// + /// + /// The value that represents the protocol used for authentication. + /// + public SslProtocols EnabledSslProtocols { get; set; } + + /// + /// Gets or sets the verification of certificate revocation option. + /// + /// + /// A Boolean value that specifies whether the certificate revocation list is checked during authentication. + /// + public bool CheckCertificateRevocation { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public ClientSslAuthConfiguration(X509CertificateCollection clientCertificates) + : this(clientCertificates, SslProtocols.Default, false) + { + } + + /// + /// Initializes a new instance of the class. + /// + public ClientSslAuthConfiguration(X509CertificateCollection clientCertificates, + SslProtocols enabledSslProtocols) + : this(clientCertificates, enabledSslProtocols, false) + { + } + + /// + /// Initializes a new instance of the class. + /// + public ClientSslAuthConfiguration(X509CertificateCollection clientCertificates, + SslProtocols enabledSslProtocols, bool checkCertificateRevocation) + { + this.clientCertificates = clientCertificates; + this.EnabledSslProtocols = enabledSslProtocols; + this.CheckCertificateRevocation = checkCertificateRevocation; + } + } +} \ No newline at end of file diff --git a/websocket-sharp/Net/EndPointListener.cs b/websocket-sharp/Net/EndPointListener.cs index 46e6a7dc..41524702 100644 --- a/websocket-sharp/Net/EndPointListener.cs +++ b/websocket-sharp/Net/EndPointListener.cs @@ -54,7 +54,7 @@ namespace WebSocketSharp.Net #region Private Fields private List _all; // host == '+' - private ServerCertAuthConfiguration _certConfig; + private ServerSslAuthConfiguration _sslAuthenticationConfig; private static readonly string _defaultCertFolderPath; private IPEndPoint _endpoint; private Dictionary _prefixes; @@ -83,13 +83,13 @@ namespace WebSocketSharp.Net int port, bool secure, string certificateFolderPath, - ServerCertAuthConfiguration defaultCertificate, + ServerSslAuthConfiguration defaultCertificate, bool reuseAddress) { if (secure) { _secure = secure; - _certConfig = getCertificate (port, certificateFolderPath, defaultCertificate); - if (_certConfig == null) + _sslAuthenticationConfig = getCertificate(port, certificateFolderPath, defaultCertificate); + if (_sslAuthenticationConfig == null) throw new ArgumentException ("No server certificate could be found."); } @@ -116,10 +116,10 @@ namespace WebSocketSharp.Net #region Public Properties - public ServerCertAuthConfiguration CertificateConfig + public ServerSslAuthConfiguration CertificateConfig { get { - return _certConfig; + return _sslAuthenticationConfig; } } @@ -174,8 +174,8 @@ namespace WebSocketSharp.Net return rsa; } - private static ServerCertAuthConfiguration getCertificate( - int port, string certificateFolderPath, ServerCertAuthConfiguration defaultCertificate) + private static ServerSslAuthConfiguration getCertificate( + int port, string certificateFolderPath, ServerSslAuthConfiguration defaultCertificate) { if (certificateFolderPath == null || certificateFolderPath.Length == 0) certificateFolderPath = _defaultCertFolderPath; @@ -187,7 +187,7 @@ namespace WebSocketSharp.Net var cert = new X509Certificate2 (cer); cert.PrivateKey = createRSAFromFile (key); - return new ServerCertAuthConfiguration(cert); + return new ServerSslAuthConfiguration(cert); } } catch { diff --git a/websocket-sharp/Net/EndPointManager.cs b/websocket-sharp/Net/EndPointManager.cs index 8b135bf8..69f43293 100644 --- a/websocket-sharp/Net/EndPointManager.cs +++ b/websocket-sharp/Net/EndPointManager.cs @@ -107,7 +107,7 @@ namespace WebSocketSharp.Net port, secure, httpListener.CertificateFolderPath, - httpListener.DefaultCertificateConfig, + httpListener.DefaultSslAuthenticationConfig, httpListener.ReuseAddress); eps[port] = epl; diff --git a/websocket-sharp/Net/HttpListener.cs b/websocket-sharp/Net/HttpListener.cs index 3b5e9f55..161ba3c6 100644 --- a/websocket-sharp/Net/HttpListener.cs +++ b/websocket-sharp/Net/HttpListener.cs @@ -64,7 +64,7 @@ namespace WebSocketSharp.Net private Dictionary _ctxRegistry; private object _ctxRegistrySync; private Func _credFinder; - private ServerCertAuthConfiguration _defaultCert; + private ServerSslAuthConfiguration _defaultSslAuthenticationConfig; private bool _disposed; private bool _ignoreWriteExceptions; private bool _listening; @@ -213,27 +213,27 @@ namespace WebSocketSharp.Net } /// - /// Gets or sets the default certificate used to authenticate the server on the secure + /// Gets or sets the default Ssl configuration used to authenticate the server on the secure /// connection. /// /// - /// A used to authenticate the server if the certificate + /// A used to authenticate the server if the certificate /// files aren't found in the . The default value is /// . /// /// /// This listener has been closed. /// - public ServerCertAuthConfiguration DefaultCertificateConfig + public ServerSslAuthConfiguration DefaultSslAuthenticationConfig { get { CheckDisposed (); - return _defaultCert; + return _defaultSslAuthenticationConfig; } set { CheckDisposed (); - _defaultCert = value; + _defaultSslAuthenticationConfig = value; } } diff --git a/websocket-sharp/Net/WebSockets/TcpListenerWebSocketContext.cs b/websocket-sharp/Net/WebSockets/TcpListenerWebSocketContext.cs index 38d615f4..5c75b080 100644 --- a/websocket-sharp/Net/WebSockets/TcpListenerWebSocketContext.cs +++ b/websocket-sharp/Net/WebSockets/TcpListenerWebSocketContext.cs @@ -61,7 +61,7 @@ namespace WebSocketSharp.Net.WebSockets #region Internal Constructors internal TcpListenerWebSocketContext ( - TcpClient tcpClient, string protocol, bool secure, ServerCertAuthConfiguration certificateConfig, Logger logger) + TcpClient tcpClient, string protocol, bool secure, ServerSslAuthConfiguration certificateConfig, Logger logger) { _tcpClient = tcpClient; _secure = secure; diff --git a/websocket-sharp/Server/HttpServer.cs b/websocket-sharp/Server/HttpServer.cs index 1157683c..7fe86906 100644 --- a/websocket-sharp/Server/HttpServer.cs +++ b/websocket-sharp/Server/HttpServer.cs @@ -181,16 +181,16 @@ namespace WebSocketSharp.Server } /// - /// Gets or sets the certificate used to authenticate the server on the secure connection. + /// Gets or sets the Ssl configuration used to authenticate the server on the secure connection. /// /// - /// A that represents the certificate used to authenticate + /// A that represents the Ssl configuration used to authenticate /// the server. /// - public ServerCertAuthConfiguration CertificateConfig + public ServerSslAuthConfiguration CertificateConfig { get { - return _listener.DefaultCertificateConfig; + return _listener.DefaultSslAuthenticationConfig; } set { @@ -203,7 +203,7 @@ namespace WebSocketSharp.Server if (EndPointListener.CertificateExists (_port, _listener.CertificateFolderPath)) _logger.Warn ("The server certificate associated with the port number already exists."); - _listener.DefaultCertificateConfig = value; + _listener.DefaultSslAuthenticationConfig = value; } } @@ -509,7 +509,7 @@ namespace WebSocketSharp.Server { return _secure && !EndPointListener.CertificateExists (_port, _listener.CertificateFolderPath) && - _listener.DefaultCertificateConfig == null + _listener.DefaultSslAuthenticationConfig == null ? "The secure connection requires a server certificate." : null; } diff --git a/websocket-sharp/Server/ServerCertAuthConfiguration.cs b/websocket-sharp/Server/ServerCertAuthConfiguration.cs deleted file mode 100644 index 2f1252a1..00000000 --- a/websocket-sharp/Server/ServerCertAuthConfiguration.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.Security.Authentication; -using System.Security.Cryptography.X509Certificates; - -namespace WebSocketSharp -{ - public class ServerCertAuthConfiguration - { - /// - /// Gets or sets the certificate used to authenticate the server on the secure connection. - /// - /// - /// A that represents the certificate used to authenticate - /// the server. - /// - public X509Certificate2 ServerCertificate { get; set; } - - /// - /// Gets or sets the client certificate request option. - /// - /// - /// A Boolean value that specifies whether the client must supply a certificate for authentication. - /// - public bool ClientCertificateRequired { get; set; } - - /// - /// Gets or sets the Ssl protocols type enabled. - /// - /// - /// The value that represents the protocol used for authentication. - /// - public SslProtocols EnabledSslProtocols { get; set; } - - /// - /// Gets or sets the verification of certificate revocation option. - /// - /// - /// A Boolean value that specifies whether the certificate revocation list is checked during authentication. - /// - public bool CheckCertificateRevocation { get; set; } - - /// - /// Initializes a new instance of the class. - /// - public ServerCertAuthConfiguration(X509Certificate2 serverCertificate, bool clientCertificateRequired = false, - SslProtocols enabledSslProtocols = SslProtocols.Default, bool checkCertificateRevocation = false) - { - this.ServerCertificate = serverCertificate; - this.ClientCertificateRequired = clientCertificateRequired; - this.EnabledSslProtocols = enabledSslProtocols; - this.CheckCertificateRevocation = checkCertificateRevocation; - } - } -} \ No newline at end of file diff --git a/websocket-sharp/Server/ServerSslAuthConfiguration.cs b/websocket-sharp/Server/ServerSslAuthConfiguration.cs new file mode 100644 index 00000000..401ad5db --- /dev/null +++ b/websocket-sharp/Server/ServerSslAuthConfiguration.cs @@ -0,0 +1,113 @@ +#region License +/* + * ServerSslAuthConfiguration.cs + * + * The MIT License + * + * Copyright (c) 2014 liryna + * + * 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 liryna.stark@gmail.com + */ +#endregion + +using System.Security.Authentication; +using System.Security.Cryptography.X509Certificates; + +namespace WebSocketSharp +{ + public class ServerSslAuthConfiguration + { + /// + /// Gets or sets the certificate used to authenticate the server on the secure connection. + /// + /// + /// A that represents the certificate used to authenticate + /// the server. + /// + public X509Certificate2 ServerCertificate { get; set; } + + /// + /// Gets or sets the client certificate request option. + /// + /// + /// A Boolean value that specifies whether the client must supply a certificate for authentication. + /// + public bool ClientCertificateRequired { get; set; } + + /// + /// Gets or sets the Ssl protocols type enabled. + /// + /// + /// The value that represents the protocol used for authentication. + /// + public SslProtocols EnabledSslProtocols { get; set; } + + /// + /// Gets or sets the verification of certificate revocation option. + /// + /// + /// A Boolean value that specifies whether the certificate revocation list is checked during authentication. + /// + public bool CheckCertificateRevocation { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public ServerSslAuthConfiguration(X509Certificate2 serverCertificate) + : this(serverCertificate, false, SslProtocols.Default, false) + { + } + + /// + /// Initializes a new instance of the class. + /// + public ServerSslAuthConfiguration(X509Certificate2 serverCertificate, bool clientCertificateRequired) + : this(serverCertificate, clientCertificateRequired, SslProtocols.Default, false) + { + } + + /// + /// Initializes a new instance of the class. + /// + public ServerSslAuthConfiguration(X509Certificate2 serverCertificate, bool clientCertificateRequired, + SslProtocols enabledSslProtocols) + : this(serverCertificate, clientCertificateRequired, enabledSslProtocols, false) + { + } + + /// + /// Initializes a new instance of the class. + /// + public ServerSslAuthConfiguration(X509Certificate2 serverCertificate, bool clientCertificateRequired, + SslProtocols enabledSslProtocols, bool checkCertificateRevocation) + { + this.ServerCertificate = serverCertificate; + this.ClientCertificateRequired = clientCertificateRequired; + this.EnabledSslProtocols = enabledSslProtocols; + this.CheckCertificateRevocation = checkCertificateRevocation; + } + } +} \ No newline at end of file diff --git a/websocket-sharp/Server/WebSocketServer.cs b/websocket-sharp/Server/WebSocketServer.cs index efede111..a2a2a1f7 100644 --- a/websocket-sharp/Server/WebSocketServer.cs +++ b/websocket-sharp/Server/WebSocketServer.cs @@ -60,7 +60,7 @@ namespace WebSocketSharp.Server private System.Net.IPAddress _address; private AuthenticationSchemes _authSchemes; - private ServerCertAuthConfiguration _certificateConfig; + private ServerSslAuthConfiguration _certificateConfig; private Func _credentialsFinder; private TcpListener _listener; private Logger _logger; @@ -315,10 +315,10 @@ namespace WebSocketSharp.Server /// Gets or sets the certificate configuration used to authenticate the server on the secure connection. /// /// - /// A that represents the certificate configuration used to authenticate + /// A that represents the certificate configuration used to authenticate /// the server. /// - public ServerCertAuthConfiguration CertificateConfig + public ServerSslAuthConfiguration SslAuthenticationConfig { get { return _certificateConfig; diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 2c5acaeb..280cb2c0 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -71,7 +71,7 @@ namespace WebSocketSharp private string _base64Key; private LocalCertificateSelectionCallback _certSelectionCallback; - private ClientCertAuthConfiguration + private ClientSslAuthConfiguration _certificateConfig; private RemoteCertificateValidationCallback _certValidationCallback; @@ -467,10 +467,10 @@ namespace WebSocketSharp /// Gets or sets the certificate configuration used to authenticate the client on the secure connection. /// /// - /// A that represents the certificate configuration used to authenticate + /// A that represents the certificate configuration used to authenticate /// the client. /// - public ClientCertAuthConfiguration CertificateConfig + public ClientSslAuthConfiguration SslAuthenticationConfig { get { diff --git a/websocket-sharp/websocket-sharp.csproj b/websocket-sharp/websocket-sharp.csproj index 72dd9ae1..2f7ba597 100644 --- a/websocket-sharp/websocket-sharp.csproj +++ b/websocket-sharp/websocket-sharp.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -67,8 +67,8 @@ - - + +