From b7f7cc4dc6c5da4facc11c7eb972723df65284f0 Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 13 Dec 2016 10:20:25 +1000 Subject: [PATCH] Minor formatting changes to CefCertificateCallbackWrapper Update WinFormsRequestHandler so the X509Certificate2UI.SelectFromCollection is made on the UI thread and Follow up to #1878 --- .../Internals/CefCertificateCallbackWrapper.h | 8 +++++--- .../Handlers/WinFormsRequestHandler.cs | 16 +++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CefSharp.Core/Internals/CefCertificateCallbackWrapper.h b/CefSharp.Core/Internals/CefCertificateCallbackWrapper.h index 0a3ba1a21..9a2171140 100644 --- a/CefSharp.Core/Internals/CefCertificateCallbackWrapper.h +++ b/CefSharp.Core/Internals/CefCertificateCallbackWrapper.h @@ -9,7 +9,8 @@ #include "include\cef_request_handler.h" #include "CefWrapper.h" -using namespace System::Text; +using namespace System::Security::Cryptography::X509Certificates; + namespace CefSharp { namespace Internals @@ -39,9 +40,10 @@ namespace CefSharp _disposed = true; } - virtual void Select(System::Security::Cryptography::X509Certificates::X509Certificate2^ cert) + virtual void Select(X509Certificate2^ cert) { ThrowIfDisposed(); + if (cert == nullptr) { _callback->Select(NULL); @@ -50,7 +52,7 @@ namespace CefSharp { auto certSerial = cert->SerialNumber; - std::vector >::const_iterator it = + std::vector>::const_iterator it = _certificateList.begin(); for (; it != _certificateList.end(); ++it) { diff --git a/CefSharp.WinForms.Example/Handlers/WinFormsRequestHandler.cs b/CefSharp.WinForms.Example/Handlers/WinFormsRequestHandler.cs index 2d44ed30f..909484f26 100644 --- a/CefSharp.WinForms.Example/Handlers/WinFormsRequestHandler.cs +++ b/CefSharp.WinForms.Example/Handlers/WinFormsRequestHandler.cs @@ -31,18 +31,24 @@ namespace CefSharp.WinForms.Example.Handlers control.InvokeOnUiThreadIfRequired(delegate () { openNewTab(targetUrl, null); - }); + }); return true; } protected override bool OnSelectClientCertificate(IWebBrowser browserControl, IBrowser browser, bool isProxy, string host, int port, X509Certificate2Collection certificates, ISelectClientCertificateCallback callback) { - X509Certificate2Collection selectedCertificateCollection = X509Certificate2UI.SelectFromCollection(certificates, "Certificates Dialog", "Select Certificate for authentication", X509SelectionFlag.SingleSelection); - foreach (X509Certificate2 x509 in selectedCertificateCollection) + var control = (Control)browserControl; + + control.InvokeOnUiThreadIfRequired(delegate() { - callback.Select(x509); - } + var selectedCertificateCollection = X509Certificate2UI.SelectFromCollection(certificates, "Certificates Dialog", "Select Certificate for authentication", X509SelectionFlag.SingleSelection); + + //X509Certificate2UI.SelectFromCollection returns a collection, we've used SingleSelection, so just take the first + //The underlying CEF implementation only accepts a single certificate + callback.Select(selectedCertificateCollection[0]); + }); + return true; } }