Add support for client certificate selection.

This commit is contained in:
David Wood 2014-10-07 11:03:09 +01:00
parent 34648413e5
commit 4852d3c38b

View File

@ -70,6 +70,8 @@ namespace WebSocketSharp
private string _base64Key; private string _base64Key;
private RemoteCertificateValidationCallback private RemoteCertificateValidationCallback
_certValidationCallback; _certValidationCallback;
private LocalCertificateSelectionCallback
_certSelectionCallback;
private bool _client; private bool _client;
private Action _closeContext; private Action _closeContext;
private CompressionMethod _compression; private CompressionMethod _compression;
@ -457,6 +459,40 @@ namespace WebSocketSharp
} }
} }
/// <summary>
/// Gets or sets the callback used to select a client certificate to supply to the server.
/// </summary>
/// <remarks>
/// If the value of this property is 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 <see langword="null"/>.
/// </value>
public LocalCertificateSelectionCallback ClientCertificateSelectionCallback
{
get {
return _certSelectionCallback;
}
set {
lock (_forConn) {
var msg = checkIfAvailable (false, false);
if (msg != null) {
_logger.Error (msg);
error (
"An error has occurred in setting the client certificate selection callback.",
null);
return;
}
_certSelectionCallback = value;
}
}
}
/// <summary> /// <summary>
/// Gets the WebSocket URL to connect. /// Gets the WebSocket URL to connect.
/// </summary> /// </summary>
@ -1301,7 +1337,8 @@ namespace WebSocketSharp
var sslStream = new SslStream ( var sslStream = new SslStream (
_stream, _stream,
false, false,
_certValidationCallback ?? ((sender, certificate, chain, sslPolicyErrors) => true)); _certValidationCallback ?? ((sender, certificate, chain, sslPolicyErrors) => true),
_certSelectionCallback ?? ((sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) => null));
sslStream.AuthenticateAsClient (_uri.DnsSafeHost); sslStream.AuthenticateAsClient (_uri.DnsSafeHost);
_stream = sslStream; _stream = sslStream;