2014-10-28 18:24:00 +08:00
|
|
|
|
#region License
|
|
|
|
|
/*
|
2014-11-06 10:51:38 +08:00
|
|
|
|
* ClientSslConfiguration.cs
|
2014-10-28 18:24:00 +08:00
|
|
|
|
*
|
|
|
|
|
* The MIT License
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2014 liryna
|
2014-10-30 18:09:12 +08:00
|
|
|
|
* Copyright (c) 2014 sta.blockhead
|
2014-10-28 18:24:00 +08:00
|
|
|
|
*
|
|
|
|
|
* 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:
|
2014-10-30 18:09:12 +08:00
|
|
|
|
* - Liryna <liryna.stark@gmail.com>
|
2014-10-28 18:24:00 +08:00
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
2014-11-03 14:11:43 +08:00
|
|
|
|
using System.Net.Security;
|
2014-10-28 18:24:00 +08:00
|
|
|
|
using System.Security.Authentication;
|
|
|
|
|
using System.Security.Cryptography.X509Certificates;
|
|
|
|
|
|
2014-10-29 18:57:34 +08:00
|
|
|
|
namespace WebSocketSharp.Net
|
2014-10-28 18:24:00 +08:00
|
|
|
|
{
|
2014-10-30 18:09:12 +08:00
|
|
|
|
/// <summary>
|
2017-05-10 13:22:40 +08:00
|
|
|
|
/// Stores the parameters for the <see cref="SslStream"/> used by clients.
|
2014-10-30 18:09:12 +08:00
|
|
|
|
/// </summary>
|
2014-11-08 14:57:47 +08:00
|
|
|
|
public class ClientSslConfiguration : SslConfiguration
|
2014-10-30 18:09:12 +08:00
|
|
|
|
{
|
2014-11-04 10:01:40 +08:00
|
|
|
|
#region Private Fields
|
|
|
|
|
|
2014-11-08 14:57:47 +08:00
|
|
|
|
private X509CertificateCollection _certs;
|
|
|
|
|
private string _host;
|
2014-11-04 10:01:40 +08:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2014-10-30 18:09:12 +08:00
|
|
|
|
#region Public Constructors
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2014-11-06 10:51:38 +08:00
|
|
|
|
/// Initializes a new instance of the <see cref="ClientSslConfiguration"/> class with
|
2014-11-03 14:11:43 +08:00
|
|
|
|
/// the specified <paramref name="targetHost"/>.
|
2014-10-30 18:09:12 +08:00
|
|
|
|
/// </summary>
|
2014-11-03 14:11:43 +08:00
|
|
|
|
/// <param name="targetHost">
|
|
|
|
|
/// A <see cref="string"/> that represents the name of the server that shares
|
|
|
|
|
/// a secure connection.
|
2014-10-30 18:09:12 +08:00
|
|
|
|
/// </param>
|
2014-11-06 10:51:38 +08:00
|
|
|
|
public ClientSslConfiguration (string targetHost)
|
2014-11-03 14:11:43 +08:00
|
|
|
|
: this (targetHost, null, SslProtocols.Default, false)
|
2014-10-30 18:09:12 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2014-11-06 10:51:38 +08:00
|
|
|
|
/// Initializes a new instance of the <see cref="ClientSslConfiguration"/> class with
|
2014-11-03 14:11:43 +08:00
|
|
|
|
/// the specified <paramref name="targetHost"/>, <paramref name="clientCertificates"/>,
|
|
|
|
|
/// <paramref name="enabledSslProtocols"/>, and <paramref name="checkCertificateRevocation"/>.
|
2014-10-30 18:09:12 +08:00
|
|
|
|
/// </summary>
|
2014-11-03 14:11:43 +08:00
|
|
|
|
/// <param name="targetHost">
|
|
|
|
|
/// A <see cref="string"/> that represents the name of the server that shares
|
|
|
|
|
/// a secure connection.
|
2014-10-30 18:09:12 +08:00
|
|
|
|
/// </param>
|
|
|
|
|
/// <param name="clientCertificates">
|
|
|
|
|
/// A <see cref="X509CertificateCollection"/> that contains client certificates.
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <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>
|
2014-11-06 10:51:38 +08:00
|
|
|
|
public ClientSslConfiguration (
|
2014-11-03 14:11:43 +08:00
|
|
|
|
string targetHost,
|
2014-10-30 18:09:12 +08:00
|
|
|
|
X509CertificateCollection clientCertificates,
|
|
|
|
|
SslProtocols enabledSslProtocols,
|
|
|
|
|
bool checkCertificateRevocation)
|
2014-11-08 14:57:47 +08:00
|
|
|
|
: base (enabledSslProtocols, checkCertificateRevocation)
|
2014-10-28 18:24:00 +08:00
|
|
|
|
{
|
2014-11-05 10:06:55 +08:00
|
|
|
|
_host = targetHost;
|
|
|
|
|
_certs = clientCertificates;
|
2014-10-30 18:09:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2014-10-28 18:24:00 +08:00
|
|
|
|
|
2014-10-30 18:09:12 +08:00
|
|
|
|
#region Public Properties
|
2014-10-28 18:24:00 +08:00
|
|
|
|
|
2014-10-30 18:09:12 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the collection that contains client certificates.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>
|
|
|
|
|
/// A <see cref="X509CertificateCollection"/> that contains client certificates.
|
|
|
|
|
/// </value>
|
2014-11-05 10:06:55 +08:00
|
|
|
|
public X509CertificateCollection ClientCertificates {
|
|
|
|
|
get {
|
|
|
|
|
return _certs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set {
|
|
|
|
|
_certs = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the callback used to select a client certificate to supply to the server.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// If this callback returns <see langword="null"/>, no client certificate will be supplied.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
/// <value>
|
|
|
|
|
/// A <see cref="LocalCertificateSelectionCallback"/> delegate that references the method
|
|
|
|
|
/// used to select the client certificate. The default value is a function that only returns
|
|
|
|
|
/// <see langword="null"/>.
|
|
|
|
|
/// </value>
|
|
|
|
|
public LocalCertificateSelectionCallback ClientCertificateSelectionCallback {
|
|
|
|
|
get {
|
2014-11-08 14:57:47 +08:00
|
|
|
|
return CertificateSelectionCallback;
|
2014-11-05 10:06:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set {
|
2014-11-08 14:57:47 +08:00
|
|
|
|
CertificateSelectionCallback = value;
|
2014-11-05 10:06:55 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-28 18:24:00 +08:00
|
|
|
|
|
2014-11-04 10:01:40 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the callback used to validate the certificate supplied by the server.
|
|
|
|
|
/// </summary>
|
2014-11-05 10:06:55 +08:00
|
|
|
|
/// <remarks>
|
|
|
|
|
/// If this callback returns <c>true</c>, the server certificate will be valid.
|
|
|
|
|
/// </remarks>
|
2014-11-04 10:01:40 +08:00
|
|
|
|
/// <value>
|
|
|
|
|
/// A <see cref="RemoteCertificateValidationCallback"/> delegate that references the method
|
|
|
|
|
/// used to validate the server certificate. The default value is a function that only returns
|
|
|
|
|
/// <c>true</c>.
|
|
|
|
|
/// </value>
|
|
|
|
|
public RemoteCertificateValidationCallback ServerCertificateValidationCallback {
|
|
|
|
|
get {
|
2014-11-08 14:57:47 +08:00
|
|
|
|
return CertificateValidationCallback;
|
2014-11-04 10:01:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set {
|
2014-11-08 14:57:47 +08:00
|
|
|
|
CertificateValidationCallback = value;
|
2014-11-04 10:01:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-03 14:11:43 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the name of the server that shares a secure connection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>
|
|
|
|
|
/// A <see cref="string"/> that represents the name of the server that shares
|
|
|
|
|
/// a secure connection.
|
|
|
|
|
/// </value>
|
2014-11-05 10:06:55 +08:00
|
|
|
|
public string TargetHost {
|
|
|
|
|
get {
|
|
|
|
|
return _host;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set {
|
|
|
|
|
_host = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-03 14:11:43 +08:00
|
|
|
|
|
2014-10-30 18:09:12 +08:00
|
|
|
|
#endregion
|
|
|
|
|
}
|
2014-11-08 14:57:47 +08:00
|
|
|
|
}
|