From 76a252a03e68f4ae89765672c3336f23ae847ac9 Mon Sep 17 00:00:00 2001 From: Sasha Perigo Date: Thu, 2 Nov 2017 16:37:21 -0700 Subject: [PATCH 1/2] Added code to broadcast the EV string to the frontend --- atom/browser/api/atom_api_web_contents.cc | 24 ++++++++++++++++++-- lib/renderer/web-view/guest-view-internal.js | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 9f856d16f3..53b660313e 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1363,12 +1363,32 @@ void WebContents::DidChangeVisibleSecurityState() { blink::WebSecurityStyle security_style = web_contents()->GetDelegate()->GetSecurityStyle( web_contents(), &explanations); - if (explanations.displayed_mixed_content && - security_style == blink::kWebSecurityStyleNeutral) { + + SecurityStateTabHelper* helper = + SecurityStateTabHelper::FromWebContents(this); + DCHECK(helper); + security_state::SecurityInfo security_info; + helper->GetSecurityInfo(&security_info); + + if (explanations.displayed_mixed_content && + security_style == blink::kWebSecurityStyleNeutral) { Emit("security-style-changed", "passive-mixed-content"); + } else { + if (security_info.security_level == security_state::EV_SECURE) { + DCHECK(!security_info.certificate->subject().organization_names.empty()); + std::string organization_name = + security_info.certificate->subject().organization_names[0]; + + DCHECK(!security_info.certificate->subject().country_name.empty()); + std::string country_code = + security_info.certificate->subject().country_name; + std::string ev_string = organization_name + " [" + country_code + "]"; + + Emit("security-style-changed", security_style, ev_string); } else { Emit("security-style-changed", security_style); } + } } void WebContents::TitleWasSet(content::NavigationEntry* entry, diff --git a/lib/renderer/web-view/guest-view-internal.js b/lib/renderer/web-view/guest-view-internal.js index ce10e601e1..78ed6ea11b 100644 --- a/lib/renderer/web-view/guest-view-internal.js +++ b/lib/renderer/web-view/guest-view-internal.js @@ -21,7 +21,7 @@ var WEB_VIEW_EVENTS = { 'plugin-crashed': ['name', 'version'], 'will-destroy': [], 'destroyed': [], - 'security-style-changed': ['securityState'], + 'security-style-changed': ['securityState', 'evString'], 'page-favicon-updated': ['favicons'], 'enter-html-full-screen': [], 'leave-html-full-screen': [], From 6c7c9aeece14c57d69c348748433886fc65198e8 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Tue, 21 Nov 2017 14:21:54 -0800 Subject: [PATCH 2/2] Follow-up of 76a252a03e68f4ae89765672c3336f23ae847ac9 Auditors: @bridiver, @diracdeltas, @bbondy --- atom/browser/api/atom_api_web_contents.cc | 81 +++++++++++++------ .../native_mate_converters/net_converter.cc | 4 + lib/renderer/web-view/guest-view-internal.js | 2 +- 3 files changed, 62 insertions(+), 25 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 53b660313e..4a33098976 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -298,6 +298,59 @@ struct Converter { } }; +template<> +struct Converter { + static v8::Local ToV8(v8::Isolate* isolate, + security_state::SecurityInfo val) { + mate::Dictionary dict(isolate, v8::Object::New(isolate)); + // see components/security_state/core/security_state.h + switch (val.security_level) { + case security_state::NONE: + dict.Set("securityLevel", "none"); + break; + case security_state::HTTP_SHOW_WARNING: + dict.Set("securityLevel", "http-show-warning"); + break; + case security_state::EV_SECURE: + dict.Set("securityLevel", "ev-secure"); + break; + case security_state::SECURE: + dict.Set("securityLevel", "secure"); + break; + case security_state::SECURE_WITH_POLICY_INSTALLED_CERT: + // Currently used only on ChromeOS. + break; + case security_state::DANGEROUS: + dict.Set("securityLevel", "dangerous"); + break; + } + + if (val.certificate) + dict.Set("certificate", val.certificate); + + switch (val.mixed_content_status) { + case security_state::CONTENT_STATUS_UNKNOWN: + dict.Set("mixedContentStatus", "content-status-unkown"); + break; + case security_state::CONTENT_STATUS_NONE: + dict.Set("mixedContentStatus", "content-status-none"); + break; + case security_state::CONTENT_STATUS_DISPLAYED: + dict.Set("mixedContentStatus", "content-status-displayed"); + break; + case security_state::CONTENT_STATUS_RAN: + dict.Set("mixedContentStatus", "content-status-ran"); + break; + case security_state::CONTENT_STATUS_DISPLAYED_AND_RAN: + dict.Set("mixedContentStatus", "content-status-displayed-and-ran"); + break; + } + + // TODO(darkdh): add more info + return dict.GetHandle(); + } +}; + template<> struct Converter { static v8::Local ToV8(v8::Isolate* isolate, @@ -1360,35 +1413,15 @@ void WebContents::DidFinishNavigation( void WebContents::DidChangeVisibleSecurityState() { content::SecurityStyleExplanations explanations; - blink::WebSecurityStyle security_style = - web_contents()->GetDelegate()->GetSecurityStyle( - web_contents(), &explanations); - + blink::WebSecurityStyle security_style = GetSecurityStyle(web_contents(), + &explanations); SecurityStateTabHelper* helper = - SecurityStateTabHelper::FromWebContents(this); + SecurityStateTabHelper::FromWebContents(web_contents()); DCHECK(helper); security_state::SecurityInfo security_info; helper->GetSecurityInfo(&security_info); - if (explanations.displayed_mixed_content && - security_style == blink::kWebSecurityStyleNeutral) { - Emit("security-style-changed", "passive-mixed-content"); - } else { - if (security_info.security_level == security_state::EV_SECURE) { - DCHECK(!security_info.certificate->subject().organization_names.empty()); - std::string organization_name = - security_info.certificate->subject().organization_names[0]; - - DCHECK(!security_info.certificate->subject().country_name.empty()); - std::string country_code = - security_info.certificate->subject().country_name; - std::string ev_string = organization_name + " [" + country_code + "]"; - - Emit("security-style-changed", security_style, ev_string); - } else { - Emit("security-style-changed", security_style); - } - } + Emit("security-style-changed", security_style, security_info); } void WebContents::TitleWasSet(content::NavigationEntry* entry, diff --git a/atom/common/native_mate_converters/net_converter.cc b/atom/common/native_mate_converters/net_converter.cc index e177c46425..980a3cf490 100644 --- a/atom/common/native_mate_converters/net_converter.cc +++ b/atom/common/native_mate_converters/net_converter.cc @@ -63,6 +63,10 @@ v8::Local Converter::ToV8( dict.Set("data", encoded_data); dict.Set("issuerName", val.issuer().GetDisplayName()); dict.Set("subjectName", val.subject().GetDisplayName()); + if (!val.subject().organization_names.empty()) + dict.Set("organizationNames", val.subject().organization_names); + if (!val.subject().country_name.empty()) + dict.Set("countryName", val.subject().country_name); dict.Set("serialNumber", base::HexEncode(val.serial_number().data(), val.serial_number().size())); dict.Set("validStart", val.valid_start().ToDoubleT()); diff --git a/lib/renderer/web-view/guest-view-internal.js b/lib/renderer/web-view/guest-view-internal.js index 78ed6ea11b..85790ab243 100644 --- a/lib/renderer/web-view/guest-view-internal.js +++ b/lib/renderer/web-view/guest-view-internal.js @@ -21,7 +21,7 @@ var WEB_VIEW_EVENTS = { 'plugin-crashed': ['name', 'version'], 'will-destroy': [], 'destroyed': [], - 'security-style-changed': ['securityState', 'evString'], + 'security-style-changed': ['securityState', 'securityInfo'], 'page-favicon-updated': ['favicons'], 'enter-html-full-screen': [], 'leave-html-full-screen': [],