Moved WebSocket.ServerCertificateValidationCallback property to ClientSslAuthConfiguration class

This commit is contained in:
sta 2014-11-04 11:01:40 +09:00
parent c511f9d7ac
commit 5502e4bdda
3 changed files with 36 additions and 44 deletions

View File

@ -66,15 +66,16 @@ namespace Example
//ws.Compression = CompressionMethod.Deflate; //ws.Compression = CompressionMethod.Deflate;
/* To validate the server certificate. /* To validate the server certificate.
ws.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => { ws.SslConfiguration.ServerCertificateValidationCallback =
ws.Log.Debug ( (sender, certificate, chain, sslPolicyErrors) => {
String.Format ( ws.Log.Debug (
"Certificate:\n- Issuer: {0}\n- Subject: {1}", String.Format (
certificate.Issuer, "Certificate:\n- Issuer: {0}\n- Subject: {1}",
certificate.Subject)); certificate.Issuer,
certificate.Subject));
return true; // If the server certificate is valid. return true; // If the server certificate is valid.
}; };
*/ */
// To set the credentials for the HTTP Authentication (Basic/Digest). // To set the credentials for the HTTP Authentication (Basic/Digest).

View File

@ -45,6 +45,12 @@ namespace WebSocketSharp.Net
/// </summary> /// </summary>
public class ClientSslAuthConfiguration public class ClientSslAuthConfiguration
{ {
#region Private Fields
private RemoteCertificateValidationCallback _serverCertValidationCallback;
#endregion
#region Public Constructors #region Public Constructors
/// <summary> /// <summary>
@ -122,6 +128,26 @@ namespace WebSocketSharp.Net
/// </value> /// </value>
public SslProtocols EnabledSslProtocols { get; set; } public SslProtocols EnabledSslProtocols { get; set; }
/// <summary>
/// Gets or sets the callback used to validate the certificate supplied by the server.
/// </summary>
/// <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 {
return _serverCertValidationCallback ??
(_serverCertValidationCallback =
(sender, certificate, chain, sslPolicyErrors) => true);
}
set {
_serverCertValidationCallback = value;
}
}
/// <summary> /// <summary>
/// Gets or sets the name of the server that shares a secure connection. /// Gets or sets the name of the server that shares a secure connection.
/// </summary> /// </summary>

View File

@ -72,8 +72,6 @@ namespace WebSocketSharp
private string _base64Key; private string _base64Key;
private LocalCertificateSelectionCallback private LocalCertificateSelectionCallback
_certSelectionCallback; _certSelectionCallback;
private RemoteCertificateValidationCallback
_certValidationCallback;
private bool _client; private bool _client;
private Action _closeContext; private Action _closeContext;
private CompressionMethod _compression; private CompressionMethod _compression;
@ -464,39 +462,6 @@ namespace WebSocketSharp
} }
} }
/// <summary>
/// Gets or sets the callback used to validate the certificate supplied by the server.
/// </summary>
/// <remarks>
/// If the value of this property is <see langword="null"/>, the validation does nothing with
/// the server certificate, and always returns valid.
/// </remarks>
/// <value>
/// A <see cref="RemoteCertificateValidationCallback"/> delegate that references the method
/// used to validate the server certificate. The default value is <see langword="null"/>.
/// </value>
public RemoteCertificateValidationCallback ServerCertificateValidationCallback {
get {
return _certValidationCallback;
}
set {
lock (_forConn) {
var msg = checkIfAvailable (false, false);
if (msg != null) {
_logger.Error (msg);
error (
"An error has occurred in setting the server certificate validation callback.",
null);
return;
}
_certValidationCallback = value;
}
}
}
/// <summary> /// <summary>
/// Gets or sets the SSL configuration used to authenticate the server and /// Gets or sets the SSL configuration used to authenticate the server and
/// optionally the client for secure connection. /// optionally the client for secure connection.
@ -1378,7 +1343,7 @@ namespace WebSocketSharp
var sslStream = new SslStream ( var sslStream = new SslStream (
_stream, _stream,
false, false,
_certValidationCallback ?? ((sender, certificate, chain, sslPolicyErrors) => true), conf.ServerCertificateValidationCallback,
_certSelectionCallback ?? _certSelectionCallback ??
((sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) => ((sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) =>
null)); null));