Added SslConfiguration class to be base of ClientSslConfiguration and ServerSslConfiguration classes
This commit is contained in:
parent
214103b7e8
commit
06585e48b5
@ -43,16 +43,12 @@ namespace WebSocketSharp.Net
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Stores the parameters used to configure a <see cref="SslStream"/> instance as a client.
|
/// Stores the parameters used to configure a <see cref="SslStream"/> instance as a client.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ClientSslConfiguration
|
public class ClientSslConfiguration : SslConfiguration
|
||||||
{
|
{
|
||||||
#region Private Fields
|
#region Private Fields
|
||||||
|
|
||||||
private X509CertificateCollection _certs;
|
private X509CertificateCollection _certs;
|
||||||
private LocalCertificateSelectionCallback _certSelectionCallback;
|
private string _host;
|
||||||
private bool _checkCertRevocation;
|
|
||||||
private SslProtocols _enabledProtocols;
|
|
||||||
private string _host;
|
|
||||||
private RemoteCertificateValidationCallback _serverCertValidationCallback;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -96,34 +92,16 @@ namespace WebSocketSharp.Net
|
|||||||
X509CertificateCollection clientCertificates,
|
X509CertificateCollection clientCertificates,
|
||||||
SslProtocols enabledSslProtocols,
|
SslProtocols enabledSslProtocols,
|
||||||
bool checkCertificateRevocation)
|
bool checkCertificateRevocation)
|
||||||
|
: base (enabledSslProtocols, checkCertificateRevocation)
|
||||||
{
|
{
|
||||||
_host = targetHost;
|
_host = targetHost;
|
||||||
_certs = clientCertificates;
|
_certs = clientCertificates;
|
||||||
_enabledProtocols = enabledSslProtocols;
|
|
||||||
_checkCertRevocation = checkCertificateRevocation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Properties
|
#region Public Properties
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets a value indicating whether the certificate revocation list is checked
|
|
||||||
/// during authentication.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// <c>true</c> if the certificate revocation list is checked; otherwise, <c>false</c>.
|
|
||||||
/// </value>
|
|
||||||
public bool CheckCertificateRevocation {
|
|
||||||
get {
|
|
||||||
return _checkCertRevocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
set {
|
|
||||||
_checkCertRevocation = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the collection that contains client certificates.
|
/// Gets or sets the collection that contains client certificates.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -153,31 +131,11 @@ namespace WebSocketSharp.Net
|
|||||||
/// </value>
|
/// </value>
|
||||||
public LocalCertificateSelectionCallback ClientCertificateSelectionCallback {
|
public LocalCertificateSelectionCallback ClientCertificateSelectionCallback {
|
||||||
get {
|
get {
|
||||||
return _certSelectionCallback ??
|
return CertificateSelectionCallback;
|
||||||
(_certSelectionCallback =
|
|
||||||
(sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) =>
|
|
||||||
null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set {
|
set {
|
||||||
_certSelectionCallback = value;
|
CertificateSelectionCallback = value;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the SSL protocols used for authentication.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// The <see cref="SslProtocols"/> enum value that represents the protocols used for
|
|
||||||
/// authentication.
|
|
||||||
/// </value>
|
|
||||||
public SslProtocols EnabledSslProtocols {
|
|
||||||
get {
|
|
||||||
return _enabledProtocols;
|
|
||||||
}
|
|
||||||
|
|
||||||
set {
|
|
||||||
_enabledProtocols = value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,13 +152,11 @@ namespace WebSocketSharp.Net
|
|||||||
/// </value>
|
/// </value>
|
||||||
public RemoteCertificateValidationCallback ServerCertificateValidationCallback {
|
public RemoteCertificateValidationCallback ServerCertificateValidationCallback {
|
||||||
get {
|
get {
|
||||||
return _serverCertValidationCallback ??
|
return CertificateValidationCallback;
|
||||||
(_serverCertValidationCallback =
|
|
||||||
(sender, certificate, chain, sslPolicyErrors) => true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set {
|
set {
|
||||||
_serverCertValidationCallback = value;
|
CertificateValidationCallback = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,4 +179,4 @@ namespace WebSocketSharp.Net
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,15 +43,12 @@ namespace WebSocketSharp.Net
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Stores the parameters used to configure a <see cref="SslStream"/> instance as a server.
|
/// Stores the parameters used to configure a <see cref="SslStream"/> instance as a server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ServerSslConfiguration
|
public class ServerSslConfiguration : SslConfiguration
|
||||||
{
|
{
|
||||||
#region Private Fields
|
#region Private Fields
|
||||||
|
|
||||||
private X509Certificate2 _cert;
|
private X509Certificate2 _cert;
|
||||||
private bool _checkCertRevocation;
|
private bool _clientCertRequired;
|
||||||
private bool _clientCertRequired;
|
|
||||||
private RemoteCertificateValidationCallback _clientCertValidationCallback;
|
|
||||||
private SslProtocols _enabledProtocols;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -97,34 +94,16 @@ namespace WebSocketSharp.Net
|
|||||||
bool clientCertificateRequired,
|
bool clientCertificateRequired,
|
||||||
SslProtocols enabledSslProtocols,
|
SslProtocols enabledSslProtocols,
|
||||||
bool checkCertificateRevocation)
|
bool checkCertificateRevocation)
|
||||||
|
: base (enabledSslProtocols, checkCertificateRevocation)
|
||||||
{
|
{
|
||||||
_cert = serverCertificate;
|
_cert = serverCertificate;
|
||||||
_clientCertRequired = clientCertificateRequired;
|
_clientCertRequired = clientCertificateRequired;
|
||||||
_enabledProtocols = enabledSslProtocols;
|
|
||||||
_checkCertRevocation = checkCertificateRevocation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Properties
|
#region Public Properties
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets a value indicating whether the certificate revocation list is checked
|
|
||||||
/// during authentication.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// <c>true</c> if the certificate revocation list is checked; otherwise, <c>false</c>.
|
|
||||||
/// </value>
|
|
||||||
public bool CheckCertificateRevocation {
|
|
||||||
get {
|
|
||||||
return _checkCertRevocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
set {
|
|
||||||
_checkCertRevocation = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether the client must supply a certificate for
|
/// Gets or sets a value indicating whether the client must supply a certificate for
|
||||||
/// authentication.
|
/// authentication.
|
||||||
@ -155,30 +134,11 @@ namespace WebSocketSharp.Net
|
|||||||
/// </value>
|
/// </value>
|
||||||
public RemoteCertificateValidationCallback ClientCertificateValidationCallback {
|
public RemoteCertificateValidationCallback ClientCertificateValidationCallback {
|
||||||
get {
|
get {
|
||||||
return _clientCertValidationCallback ??
|
return CertificateValidationCallback;
|
||||||
(_clientCertValidationCallback =
|
|
||||||
(sender, certificate, chain, sslPolicyErrors) => true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set {
|
set {
|
||||||
_clientCertValidationCallback = value;
|
CertificateValidationCallback = value;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the SSL protocols used for authentication.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// The <see cref="SslProtocols"/> enum value that represents the protocols used for
|
|
||||||
/// authentication.
|
|
||||||
/// </value>
|
|
||||||
public SslProtocols EnabledSslProtocols {
|
|
||||||
get {
|
|
||||||
return _enabledProtocols;
|
|
||||||
}
|
|
||||||
|
|
||||||
set {
|
|
||||||
_enabledProtocols = value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,4 +161,4 @@ namespace WebSocketSharp.Net
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
172
websocket-sharp/Net/SslConfiguration.cs
Normal file
172
websocket-sharp/Net/SslConfiguration.cs
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
#region License
|
||||||
|
/*
|
||||||
|
* SslConfiguration.cs
|
||||||
|
*
|
||||||
|
* This code is derived from ClientSslConfiguration.cs.
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 liryna
|
||||||
|
* Copyright (c) 2014 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 <liryna.stark@gmail.com>
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Net.Security;
|
||||||
|
using System.Security.Authentication;
|
||||||
|
|
||||||
|
namespace WebSocketSharp.Net
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Stores the parameters used to configure a <see cref="SslStream"/> instance.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The SslConfiguration class is an abstract class.
|
||||||
|
/// </remarks>
|
||||||
|
public abstract class SslConfiguration
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private LocalCertificateSelectionCallback _certSelectionCallback;
|
||||||
|
private RemoteCertificateValidationCallback _certValidationCallback;
|
||||||
|
private bool _checkCertRevocation;
|
||||||
|
private SslProtocols _enabledProtocols;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Protected Constructors
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="SslConfiguration"/> class with
|
||||||
|
/// the specified <paramref name="enabledSslProtocols"/> and
|
||||||
|
/// <paramref name="checkCertificateRevocation"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="enabledSslProtocols">
|
||||||
|
/// The <see cref="SslProtocols"/> enum value that represents the protocols used for
|
||||||
|
/// authentication.
|
||||||
|
/// </param>
|
||||||
|
/// <param name="checkCertificateRevocation">
|
||||||
|
/// <c>true</c> if the certificate revocation list is checked during authentication;
|
||||||
|
/// otherwise, <c>false</c>.
|
||||||
|
/// </param>
|
||||||
|
protected SslConfiguration (SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
|
||||||
|
{
|
||||||
|
_enabledProtocols = enabledSslProtocols;
|
||||||
|
_checkCertRevocation = checkCertificateRevocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Protected Properties
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the callback used to select a certificate to supply to the remote party.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// If this callback returns <see langword="null"/>, no certificate will be supplied.
|
||||||
|
/// </remarks>
|
||||||
|
/// <value>
|
||||||
|
/// A <see cref="LocalCertificateSelectionCallback"/> delegate that references the method
|
||||||
|
/// used to select a certificate. The default value is a function that only returns
|
||||||
|
/// <see langword="null"/>.
|
||||||
|
/// </value>
|
||||||
|
protected LocalCertificateSelectionCallback CertificateSelectionCallback {
|
||||||
|
get {
|
||||||
|
return _certSelectionCallback ??
|
||||||
|
(_certSelectionCallback =
|
||||||
|
(sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) =>
|
||||||
|
null);
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
_certSelectionCallback = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the callback used to validate the certificate supplied by the remote party.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// If this callback returns <c>true</c>, the certificate will be valid.
|
||||||
|
/// </remarks>
|
||||||
|
/// <value>
|
||||||
|
/// A <see cref="RemoteCertificateValidationCallback"/> delegate that references the method
|
||||||
|
/// used to validate the certificate. The default value is a function that only returns
|
||||||
|
/// <c>true</c>.
|
||||||
|
/// </value>
|
||||||
|
protected RemoteCertificateValidationCallback CertificateValidationCallback {
|
||||||
|
get {
|
||||||
|
return _certValidationCallback ??
|
||||||
|
(_certValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true);
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
_certValidationCallback = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether the certificate revocation list is checked
|
||||||
|
/// during authentication.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// <c>true</c> if the certificate revocation list is checked; otherwise, <c>false</c>.
|
||||||
|
/// </value>
|
||||||
|
public bool CheckCertificateRevocation {
|
||||||
|
get {
|
||||||
|
return _checkCertRevocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
_checkCertRevocation = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the SSL protocols used for authentication.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The <see cref="SslProtocols"/> enum value that represents the protocols used for
|
||||||
|
/// authentication.
|
||||||
|
/// </value>
|
||||||
|
public SslProtocols EnabledSslProtocols {
|
||||||
|
get {
|
||||||
|
return _enabledProtocols;
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
_enabledProtocols = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
@ -136,6 +136,7 @@
|
|||||||
<Compile Include="Net\HttpListenerPrefix.cs" />
|
<Compile Include="Net\HttpListenerPrefix.cs" />
|
||||||
<Compile Include="Net\ClientSslConfiguration.cs" />
|
<Compile Include="Net\ClientSslConfiguration.cs" />
|
||||||
<Compile Include="Net\ServerSslConfiguration.cs" />
|
<Compile Include="Net\ServerSslConfiguration.cs" />
|
||||||
|
<Compile Include="Net\SslConfiguration.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
Loading…
Reference in New Issue
Block a user