From 70fb1b72ccb40ae6e815afcdd4526ddb030a3e0a Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Wed, 15 Feb 2017 23:36:49 +0800 Subject: [PATCH] View Certificate on Mac & Windows Defer view certificate support on linux fix https://github.com/brave/browser-laptop/issues/2611 Auditors: @bridiver, @bbondy --- atom/browser/api/atom_api_web_contents.cc | 12 ++++++++++++ atom/browser/api/atom_api_web_contents.h | 1 + atom/browser/common_web_contents_delegate.cc | 12 ++++++++++++ atom/browser/common_web_contents_delegate.h | 3 +++ atom/common/api/resources/web_view_api_bindings.js | 1 + brave/browser/BUILD.gn | 1 + brave/browser/certificate_viewer_mac.mm | 13 +++++++++++++ chromium_src/BUILD.gn | 14 ++++++++++++++ lib/browser/api/browser-window.js | 3 +++ 9 files changed, 60 insertions(+) create mode 100644 brave/browser/certificate_viewer_mac.mm diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 2e5b12aa6f..aa583bde4c 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -78,6 +78,7 @@ #include "content/public/browser/security_style_explanations.h" #include "content/public/browser/service_worker_context.h" #include "content/public/browser/site_instance.h" +#include "content/public/browser/ssl_status.h" #include "content/public/browser/storage_partition.h" #include "content/public/browser/web_contents.h" #include "content/public/child/v8_value_converter.h" @@ -1613,6 +1614,15 @@ void WebContents::StopFindInPage(content::StopFindAction action) { web_contents()->StopFinding(action); } +void WebContents::ShowCertificate() { + scoped_refptr certificate = + web_contents()->GetController().GetVisibleEntry()->GetSSL().certificate; + if (!certificate) + return; + web_contents()->GetDelegate()->ShowCertificateViewerInDevTools( + web_contents(), certificate); +} + void WebContents::ShowDefinitionForSelection() { #if defined(OS_MACOSX) const auto view = web_contents()->GetRenderWidgetHostView(); @@ -2091,6 +2101,8 @@ void WebContents::BuildPrototype(v8::Isolate* isolate, .SetMethod("_printToPDF", &WebContents::PrintToPDF) .SetMethod("addWorkSpace", &WebContents::AddWorkSpace) .SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace) + .SetMethod("showCertificate", + &WebContents::ShowCertificate) .SetMethod("showDefinitionForSelection", &WebContents::ShowDefinitionForSelection) .SetMethod("copyImageAt", &WebContents::CopyImageAt) diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 0274914e9c..5f48d7a5ec 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -209,6 +209,7 @@ class WebContents : public mate::TrackableObject, void ReplaceMisspelling(const base::string16& word); uint32_t FindInPage(mate::Arguments* args); void StopFindInPage(content::StopFindAction action); + void ShowCertificate(); void ShowDefinitionForSelection(); void CopyImageAt(int x, int y); diff --git a/atom/browser/common_web_contents_delegate.cc b/atom/browser/common_web_contents_delegate.cc index 8818803230..b5c0469a6f 100644 --- a/atom/browser/common_web_contents_delegate.cc +++ b/atom/browser/common_web_contents_delegate.cc @@ -19,6 +19,7 @@ #include "base/files/file_util.h" #include "base/strings/utf_string_conversions.h" #include "brave/browser/brave_javascript_dialog_manager.h" +#include "chrome/browser/certificate_viewer.h" #include "chrome/browser/printing/print_preview_message_handler.h" #include "chrome/browser/printing/print_view_manager_basic.h" #include "chrome/browser/ssl/security_state_tab_helper.h" @@ -321,6 +322,17 @@ bool CommonWebContentsDelegate::IsFullscreenForTabOrPending( return html_fullscreen_; } +void CommonWebContentsDelegate::ShowCertificateViewerInDevTools( + content::WebContents* web_contents, + scoped_refptr certificate) { + // TODO(Anthony): Support linux certificate viewing modal +#if !defined(OS_LINUX) + ::ShowCertificateViewer(web_contents_->GetWebContents(), + owner_window_->GetNativeWindow(), + certificate.get()); +#endif +} + blink::WebSecurityStyle CommonWebContentsDelegate::GetSecurityStyle( content::WebContents* web_contents, content::SecurityStyleExplanations* security_style_explanations) { diff --git a/atom/browser/common_web_contents_delegate.h b/atom/browser/common_web_contents_delegate.h index a4d2bf1505..4da6fe7d4d 100644 --- a/atom/browser/common_web_contents_delegate.h +++ b/atom/browser/common_web_contents_delegate.h @@ -81,6 +81,9 @@ class CommonWebContentsDelegate void ExitFullscreenModeForTab(content::WebContents* source) override; bool IsFullscreenForTabOrPending( const content::WebContents* source) const override; + void ShowCertificateViewerInDevTools( + content::WebContents* web_contents, + scoped_refptr certificate) override; blink::WebSecurityStyle GetSecurityStyle( content::WebContents* web_contents, content::SecurityStyleExplanations* explanations) override; diff --git a/atom/common/api/resources/web_view_api_bindings.js b/atom/common/api/resources/web_view_api_bindings.js index 31ad3eee3a..d1813e730e 100644 --- a/atom/common/api/resources/web_view_api_bindings.js +++ b/atom/common/api/resources/web_view_api_bindings.js @@ -40,6 +40,7 @@ const asyncMethods = [ 'inspectServiceWorker', 'print', 'printToPDF', + 'showCertificate', 'showDefinitionForSelection', 'capturePage', 'setActive', diff --git a/brave/browser/BUILD.gn b/brave/browser/BUILD.gn index 93155e10c5..1c4f82f812 100644 --- a/brave/browser/BUILD.gn +++ b/brave/browser/BUILD.gn @@ -32,6 +32,7 @@ source_set("browser") { "brave_javascript_dialog_manager.cc", "brave_permission_manager.h", "brave_permission_manager.cc", + "certificate_viewer_mac.mm", "renderer_preferences_helper.h", "renderer_preferences_helper.cc", ] diff --git a/brave/browser/certificate_viewer_mac.mm b/brave/browser/certificate_viewer_mac.mm new file mode 100644 index 0000000000..ddc2d45faa --- /dev/null +++ b/brave/browser/certificate_viewer_mac.mm @@ -0,0 +1,13 @@ +#include "chrome/browser/certificate_viewer.h" + +#import "chrome/browser/ui/certificate_viewer_mac.h" + +void ShowCertificateViewer(content::WebContents* web_contents, + gfx::NativeWindow parent, + net::X509Certificate* cert) { + SSLCertificateViewerMac* viewer = ([[SSLCertificateViewerMac alloc] + initWithCertificate:cert + forWebContents:web_contents]); + [viewer showCertificateSheet:parent]; + [viewer releaseSheetWindow]; +} diff --git a/chromium_src/BUILD.gn b/chromium_src/BUILD.gn index f80d102767..eea5846bf8 100644 --- a/chromium_src/BUILD.gn +++ b/chromium_src/BUILD.gn @@ -258,11 +258,15 @@ source_set("browser") { "chrome/browser/ui/views/color_chooser_win.cc", "//chrome/browser/printing/pdf_to_emf_converter.cc", "//chrome/browser/printing/pdf_to_emf_converter.h", + "//chrome/browser/ui/views/certificate_viewer_win.cc", ] deps += [ "//ui/shell_dialogs", ] + libs = [ + "cryptui.lib", + ] } if (is_linux) { @@ -272,6 +276,16 @@ source_set("browser") { ] } + if (is_mac) { + sources += [ + "//chrome/browser/ui/certificate_viewer_mac.h", + "//chrome/browser/ui/certificate_viewer_mac.mm", + ] + libs = [ + "SecurityInterface.framework", + ] + } + if (use_nss_certs) { sources += [ "chrome/browser/certificate_manager_model.cc", diff --git a/lib/browser/api/browser-window.js b/lib/browser/api/browser-window.js index 0b94d35954..735ae4cd0d 100644 --- a/lib/browser/api/browser-window.js +++ b/lib/browser/api/browser-window.js @@ -162,6 +162,9 @@ Object.assign(BrowserWindow.prototype, { inspectServiceWorker () { return this.webContents.inspectServiceWorker() }, + showCertificate () { + return this.webContents.showCertificate() + }, showDefinitionForSelection () { return this.webContents.showDefinitionForSelection() },