Add some constructors for C# 3.0

Rename ClientCertAuthConfiguration to ClientSslAuthConfiguration
Rename ServerCertAuthConfiguration to ServerSslAuthConfiguration
Add the licence comment to new files
This commit is contained in:
Adrien JUND
2014-10-28 11:24:00 +01:00
parent cc0ab61eb9
commit 4e7bca4f38
13 changed files with 242 additions and 130 deletions

View File

@@ -1,44 +0,0 @@
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
namespace WebSocketSharp
{
public class ClientCertAuthConfiguration
{
/// <summary>
/// Gets or sets the certificate configuration used to authenticate the clients on the secure connection.
/// </summary>
/// <value>
/// A <see cref="X509CertificateCollection"/> that represents the certificate collection used to authenticate
/// the clients.
/// </value>
public X509CertificateCollection clientCertificates { get; set; }
/// <summary>
/// Gets or sets the Ssl protocols type enabled.
/// </summary>
/// <value>
/// The <see cref="SslProtocols"/> value that represents the protocol used for authentication.
/// </value>
public SslProtocols EnabledSslProtocols { get; set; }
/// <summary>
/// Gets or sets the verification of certificate revocation option.
/// </summary>
/// <value>
/// A Boolean value that specifies whether the certificate revocation list is checked during authentication.
/// </value>
public bool CheckCertificateRevocation { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="ClientCertAuthConfiguration"/> class.
/// </summary>
public ClientCertAuthConfiguration(X509CertificateCollection clientCertificates,
SslProtocols enabledSslProtocols = SslProtocols.Default, bool checkCertificateRevocation = false)
{
this.clientCertificates = clientCertificates;
this.EnabledSslProtocols = enabledSslProtocols;
this.CheckCertificateRevocation = checkCertificateRevocation;
}
}
}

View File

@@ -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
{
/// <summary>
/// Gets or sets the certificate configuration used to authenticate the clients on the secure connection.
/// </summary>
/// <value>
/// A <see cref="X509CertificateCollection"/> that represents the certificate collection used to authenticate
/// the clients.
/// </value>
public X509CertificateCollection clientCertificates { get; set; }
/// <summary>
/// Gets or sets the Ssl protocols type enabled.
/// </summary>
/// <value>
/// The <see cref="SslProtocols"/> value that represents the protocol used for authentication.
/// </value>
public SslProtocols EnabledSslProtocols { get; set; }
/// <summary>
/// Gets or sets the verification of certificate revocation option.
/// </summary>
/// <value>
/// A Boolean value that specifies whether the certificate revocation list is checked during authentication.
/// </value>
public bool CheckCertificateRevocation { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="ClientSslAuthConfiguration"/> class.
/// </summary>
public ClientSslAuthConfiguration(X509CertificateCollection clientCertificates)
: this(clientCertificates, SslProtocols.Default, false)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ClientSslAuthConfiguration"/> class.
/// </summary>
public ClientSslAuthConfiguration(X509CertificateCollection clientCertificates,
SslProtocols enabledSslProtocols)
: this(clientCertificates, enabledSslProtocols, false)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ClientSslAuthConfiguration"/> class.
/// </summary>
public ClientSslAuthConfiguration(X509CertificateCollection clientCertificates,
SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
{
this.clientCertificates = clientCertificates;
this.EnabledSslProtocols = enabledSslProtocols;
this.CheckCertificateRevocation = checkCertificateRevocation;
}
}
}

View File

@@ -54,7 +54,7 @@ namespace WebSocketSharp.Net
#region Private Fields
private List<HttpListenerPrefix> _all; // host == '+'
private ServerCertAuthConfiguration _certConfig;
private ServerSslAuthConfiguration _sslAuthenticationConfig;
private static readonly string _defaultCertFolderPath;
private IPEndPoint _endpoint;
private Dictionary<HttpListenerPrefix, HttpListener> _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 {

View File

@@ -107,7 +107,7 @@ namespace WebSocketSharp.Net
port,
secure,
httpListener.CertificateFolderPath,
httpListener.DefaultCertificateConfig,
httpListener.DefaultSslAuthenticationConfig,
httpListener.ReuseAddress);
eps[port] = epl;

View File

@@ -64,7 +64,7 @@ namespace WebSocketSharp.Net
private Dictionary<HttpListenerContext, HttpListenerContext> _ctxRegistry;
private object _ctxRegistrySync;
private Func<IIdentity, NetworkCredential> _credFinder;
private ServerCertAuthConfiguration _defaultCert;
private ServerSslAuthConfiguration _defaultSslAuthenticationConfig;
private bool _disposed;
private bool _ignoreWriteExceptions;
private bool _listening;
@@ -213,27 +213,27 @@ namespace WebSocketSharp.Net
}
/// <summary>
/// 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.
/// </summary>
/// <value>
/// A <see cref="X509Certificate2"/> used to authenticate the server if the certificate
/// A <see cref="ServerSslAuthConfiguration"/> used to authenticate the server if the certificate
/// files aren't found in the <see cref="CertificateFolderPath"/>. The default value is
/// <see langword="null"/>.
/// </value>
/// <exception cref="ObjectDisposedException">
/// This listener has been closed.
/// </exception>
public ServerCertAuthConfiguration DefaultCertificateConfig
public ServerSslAuthConfiguration DefaultSslAuthenticationConfig
{
get {
CheckDisposed ();
return _defaultCert;
return _defaultSslAuthenticationConfig;
}
set {
CheckDisposed ();
_defaultCert = value;
_defaultSslAuthenticationConfig = value;
}
}

View File

@@ -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;