Skip to content

Commit fdc189d

Browse files
committed
ISelectClientCertificateCallback - Update xml doc, return null means no certificate selected.
Update WinForms Example to deal with user cancellation of certificate selection UI Resolves #2853
1 parent 247b1d0 commit fdc189d

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

CefSharp.WinForms.Example/Handlers/WinFormsRequestHandler.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,17 @@ protected override bool OnSelectClientCertificate(IWebBrowser chromiumWebBrowser
4343
control.InvokeOnUiThreadIfRequired(delegate ()
4444
{
4545
var selectedCertificateCollection = X509Certificate2UI.SelectFromCollection(certificates, "Certificates Dialog", "Select Certificate for authentication", X509SelectionFlag.SingleSelection);
46-
47-
//X509Certificate2UI.SelectFromCollection returns a collection, we've used SingleSelection, so just take the first
48-
//The underlying CEF implementation only accepts a single certificate
49-
callback.Select(selectedCertificateCollection[0]);
46+
if (selectedCertificateCollection.Count > 0)
47+
{
48+
//X509Certificate2UI.SelectFromCollection returns a collection, we've used SingleSelection, so just take the first
49+
//The underlying CEF implementation only accepts a single certificate
50+
callback.Select(selectedCertificateCollection[0]);
51+
}
52+
else
53+
{
54+
//User canceled no certificate should be selected.
55+
callback.Select(null);
56+
}
5057
});
5158

5259
return true;

CefSharp/Callback/ISelectClientCertificateCallback.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public interface ISelectClientCertificateCallback : IDisposable
1414
{
1515
/// <summary>
1616
/// Callback interface used to select a client certificate for authentication.
17+
/// <see langword="null"/> value means that no client certificate should be used.
1718
/// </summary>
1819
/// <param name="selectedCert">selected certificate</param>
1920
void Select(X509Certificate2 selectedCert);

0 commit comments

Comments
 (0)