From 4852d3c38bbaa4f0a37e3695e891c9530346799a Mon Sep 17 00:00:00 2001 From: David Wood Date: Tue, 7 Oct 2014 11:03:09 +0100 Subject: [PATCH] Add support for client certificate selection. --- websocket-sharp/WebSocket.cs | 39 +++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 2ed6259e..808a96f7 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -70,6 +70,8 @@ namespace WebSocketSharp private string _base64Key; private RemoteCertificateValidationCallback _certValidationCallback; + private LocalCertificateSelectionCallback + _certSelectionCallback; private bool _client; private Action _closeContext; private CompressionMethod _compression; @@ -457,6 +459,40 @@ namespace WebSocketSharp } } + /// + /// Gets or sets the callback used to select a client certificate to supply to the server. + /// + /// + /// If the value of this property is null, no client certificate will be supplied. + /// + /// + /// A delegate that references the method + /// used to select the client certificate. The default value is . + /// + 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; + } + } + } + + /// /// Gets the WebSocket URL to connect. /// @@ -1301,7 +1337,8 @@ namespace WebSocketSharp var sslStream = new SslStream ( _stream, false, - _certValidationCallback ?? ((sender, certificate, chain, sslPolicyErrors) => true)); + _certValidationCallback ?? ((sender, certificate, chain, sslPolicyErrors) => true), + _certSelectionCallback ?? ((sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) => null)); sslStream.AuthenticateAsClient (_uri.DnsSafeHost); _stream = sslStream;