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;
/* To validate the server certificate.
ws.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => {
ws.Log.Debug (
String.Format (
"Certificate:\n- Issuer: {0}\n- Subject: {1}",
certificate.Issuer,
certificate.Subject));
ws.SslConfiguration.ServerCertificateValidationCallback =
(sender, certificate, chain, sslPolicyErrors) => {
ws.Log.Debug (
String.Format (
"Certificate:\n- Issuer: {0}\n- Subject: {1}",
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).

View File

@ -45,6 +45,12 @@ namespace WebSocketSharp.Net
/// </summary>
public class ClientSslAuthConfiguration
{
#region Private Fields
private RemoteCertificateValidationCallback _serverCertValidationCallback;
#endregion
#region Public Constructors
/// <summary>
@ -122,6 +128,26 @@ namespace WebSocketSharp.Net
/// </value>
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>
/// Gets or sets the name of the server that shares a secure connection.
/// </summary>

View File

@ -72,8 +72,6 @@ namespace WebSocketSharp
private string _base64Key;
private LocalCertificateSelectionCallback
_certSelectionCallback;
private RemoteCertificateValidationCallback
_certValidationCallback;
private bool _client;
private Action _closeContext;
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>
/// Gets or sets the SSL configuration used to authenticate the server and
/// optionally the client for secure connection.
@ -1378,7 +1343,7 @@ namespace WebSocketSharp
var sslStream = new SslStream (
_stream,
false,
_certValidationCallback ?? ((sender, certificate, chain, sslPolicyErrors) => true),
conf.ServerCertificateValidationCallback,
_certSelectionCallback ??
((sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) =>
null));