diff --git a/websocket-sharp/Net/ClientSslConfiguration.cs b/websocket-sharp/Net/ClientSslConfiguration.cs
index 82e71b04..5344164f 100644
--- a/websocket-sharp/Net/ClientSslConfiguration.cs
+++ b/websocket-sharp/Net/ClientSslConfiguration.cs
@@ -43,16 +43,12 @@ namespace WebSocketSharp.Net
///
/// Stores the parameters used to configure a instance as a client.
///
- public class ClientSslConfiguration
+ public class ClientSslConfiguration : SslConfiguration
{
#region Private Fields
- private X509CertificateCollection _certs;
- private LocalCertificateSelectionCallback _certSelectionCallback;
- private bool _checkCertRevocation;
- private SslProtocols _enabledProtocols;
- private string _host;
- private RemoteCertificateValidationCallback _serverCertValidationCallback;
+ private X509CertificateCollection _certs;
+ private string _host;
#endregion
@@ -96,34 +92,16 @@ namespace WebSocketSharp.Net
X509CertificateCollection clientCertificates,
SslProtocols enabledSslProtocols,
bool checkCertificateRevocation)
+ : base (enabledSslProtocols, checkCertificateRevocation)
{
_host = targetHost;
_certs = clientCertificates;
- _enabledProtocols = enabledSslProtocols;
- _checkCertRevocation = checkCertificateRevocation;
}
#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; otherwise, false.
- ///
- public bool CheckCertificateRevocation {
- get {
- return _checkCertRevocation;
- }
-
- set {
- _checkCertRevocation = value;
- }
- }
-
///
/// Gets or sets the collection that contains client certificates.
///
@@ -153,31 +131,11 @@ namespace WebSocketSharp.Net
///
public LocalCertificateSelectionCallback ClientCertificateSelectionCallback {
get {
- return _certSelectionCallback ??
- (_certSelectionCallback =
- (sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) =>
- null);
- }
-
- set {
- _certSelectionCallback = value;
- }
- }
-
- ///
- /// Gets or sets the SSL protocols used for authentication.
- ///
- ///
- /// The enum value that represents the protocols used for
- /// authentication.
- ///
- public SslProtocols EnabledSslProtocols {
- get {
- return _enabledProtocols;
+ return CertificateSelectionCallback;
}
set {
- _enabledProtocols = value;
+ CertificateSelectionCallback = value;
}
}
@@ -194,13 +152,11 @@ namespace WebSocketSharp.Net
///
public RemoteCertificateValidationCallback ServerCertificateValidationCallback {
get {
- return _serverCertValidationCallback ??
- (_serverCertValidationCallback =
- (sender, certificate, chain, sslPolicyErrors) => true);
+ return CertificateValidationCallback;
}
set {
- _serverCertValidationCallback = value;
+ CertificateValidationCallback = value;
}
}
@@ -223,4 +179,4 @@ namespace WebSocketSharp.Net
#endregion
}
-}
\ No newline at end of file
+}
diff --git a/websocket-sharp/Net/ServerSslConfiguration.cs b/websocket-sharp/Net/ServerSslConfiguration.cs
index f0dbb3de..3f0883af 100644
--- a/websocket-sharp/Net/ServerSslConfiguration.cs
+++ b/websocket-sharp/Net/ServerSslConfiguration.cs
@@ -43,15 +43,12 @@ namespace WebSocketSharp.Net
///
/// Stores the parameters used to configure a instance as a server.
///
- public class ServerSslConfiguration
+ public class ServerSslConfiguration : SslConfiguration
{
#region Private Fields
- private X509Certificate2 _cert;
- private bool _checkCertRevocation;
- private bool _clientCertRequired;
- private RemoteCertificateValidationCallback _clientCertValidationCallback;
- private SslProtocols _enabledProtocols;
+ private X509Certificate2 _cert;
+ private bool _clientCertRequired;
#endregion
@@ -97,34 +94,16 @@ namespace WebSocketSharp.Net
bool clientCertificateRequired,
SslProtocols enabledSslProtocols,
bool checkCertificateRevocation)
+ : base (enabledSslProtocols, checkCertificateRevocation)
{
_cert = serverCertificate;
_clientCertRequired = clientCertificateRequired;
- _enabledProtocols = enabledSslProtocols;
- _checkCertRevocation = checkCertificateRevocation;
}
#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; otherwise, false.
- ///
- public bool CheckCertificateRevocation {
- get {
- return _checkCertRevocation;
- }
-
- set {
- _checkCertRevocation = value;
- }
- }
-
///
/// Gets or sets a value indicating whether the client must supply a certificate for
/// authentication.
@@ -155,30 +134,11 @@ namespace WebSocketSharp.Net
///
public RemoteCertificateValidationCallback ClientCertificateValidationCallback {
get {
- return _clientCertValidationCallback ??
- (_clientCertValidationCallback =
- (sender, certificate, chain, sslPolicyErrors) => true);
- }
-
- set {
- _clientCertValidationCallback = value;
- }
- }
-
- ///
- /// Gets or sets the SSL protocols used for authentication.
- ///
- ///
- /// The enum value that represents the protocols used for
- /// authentication.
- ///
- public SslProtocols EnabledSslProtocols {
- get {
- return _enabledProtocols;
+ return CertificateValidationCallback;
}
set {
- _enabledProtocols = value;
+ CertificateValidationCallback = value;
}
}
@@ -201,4 +161,4 @@ namespace WebSocketSharp.Net
#endregion
}
-}
\ No newline at end of file
+}
diff --git a/websocket-sharp/Net/SslConfiguration.cs b/websocket-sharp/Net/SslConfiguration.cs
new file mode 100644
index 00000000..bfd3e5ac
--- /dev/null
+++ b/websocket-sharp/Net/SslConfiguration.cs
@@ -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
+ */
+#endregion
+
+using System.Net.Security;
+using System.Security.Authentication;
+
+namespace WebSocketSharp.Net
+{
+ ///
+ /// Stores the parameters used to configure a instance.
+ ///
+ ///
+ /// The SslConfiguration class is an abstract class.
+ ///
+ public abstract class SslConfiguration
+ {
+ #region Private Fields
+
+ private LocalCertificateSelectionCallback _certSelectionCallback;
+ private RemoteCertificateValidationCallback _certValidationCallback;
+ private bool _checkCertRevocation;
+ private SslProtocols _enabledProtocols;
+
+ #endregion
+
+ #region Protected Constructors
+
+ ///
+ /// Initializes a new instance of the class with
+ /// the specified and
+ /// .
+ ///
+ ///
+ /// The enum value that represents the protocols used for
+ /// authentication.
+ ///
+ ///
+ /// true if the certificate revocation list is checked during authentication;
+ /// otherwise, false.
+ ///
+ protected SslConfiguration (SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
+ {
+ _enabledProtocols = enabledSslProtocols;
+ _checkCertRevocation = checkCertificateRevocation;
+ }
+
+ #endregion
+
+ #region Protected Properties
+
+ ///
+ /// Gets or sets the callback used to select a certificate to supply to the remote party.
+ ///
+ ///
+ /// If this callback returns , no certificate will be supplied.
+ ///
+ ///
+ /// A delegate that references the method
+ /// used to select a certificate. The default value is a function that only returns
+ /// .
+ ///
+ protected LocalCertificateSelectionCallback CertificateSelectionCallback {
+ get {
+ return _certSelectionCallback ??
+ (_certSelectionCallback =
+ (sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) =>
+ null);
+ }
+
+ set {
+ _certSelectionCallback = value;
+ }
+ }
+
+ ///
+ /// Gets or sets the callback used to validate the certificate supplied by the remote party.
+ ///
+ ///
+ /// If this callback returns true, the certificate will be valid.
+ ///
+ ///
+ /// A delegate that references the method
+ /// used to validate the certificate. The default value is a function that only returns
+ /// true.
+ ///
+ protected RemoteCertificateValidationCallback CertificateValidationCallback {
+ get {
+ return _certValidationCallback ??
+ (_certValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true);
+ }
+
+ set {
+ _certValidationCallback = value;
+ }
+ }
+
+ #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; otherwise, false.
+ ///
+ public bool CheckCertificateRevocation {
+ get {
+ return _checkCertRevocation;
+ }
+
+ set {
+ _checkCertRevocation = value;
+ }
+ }
+
+ ///
+ /// Gets or sets the SSL protocols used for authentication.
+ ///
+ ///
+ /// The enum value that represents the protocols used for
+ /// authentication.
+ ///
+ public SslProtocols EnabledSslProtocols {
+ get {
+ return _enabledProtocols;
+ }
+
+ set {
+ _enabledProtocols = value;
+ }
+ }
+
+ #endregion
+ }
+}
diff --git a/websocket-sharp/websocket-sharp.csproj b/websocket-sharp/websocket-sharp.csproj
index 620786c5..e581fbff 100644
--- a/websocket-sharp/websocket-sharp.csproj
+++ b/websocket-sharp/websocket-sharp.csproj
@@ -136,6 +136,7 @@
+