Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: chrome/browser/ui/webui/interstitials/interstitial_ui.cc

Issue 2090683004: Unbreak chrome://interstitials/ssl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/webui/interstitials/interstitial_ui.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/interstitials/interstitial_ui.h" 5 #include "chrome/browser/ui/webui/interstitials/interstitial_ui.h"
6 6
7 #include "base/macros.h" 7 #include "base/atomic_sequence_num.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/time/time.h"
10 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 13 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
13 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 14 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
14 #include "chrome/browser/ssl/bad_clock_blocking_page.h" 15 #include "chrome/browser/ssl/bad_clock_blocking_page.h"
15 #include "chrome/browser/ssl/ssl_blocking_page.h" 16 #include "chrome/browser/ssl/ssl_blocking_page.h"
16 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
17 #include "chrome/grit/browser_resources.h" 18 #include "chrome/grit/browser_resources.h"
18 #include "components/grit/components_resources.h" 19 #include "components/grit/components_resources.h"
19 #include "components/security_interstitials/core/ssl_error_ui.h" 20 #include "components/security_interstitials/core/ssl_error_ui.h"
20 #include "content/public/browser/interstitial_page_delegate.h" 21 #include "content/public/browser/interstitial_page_delegate.h"
21 #include "content/public/browser/render_frame_host.h" 22 #include "content/public/browser/render_frame_host.h"
22 #include "content/public/browser/render_process_host.h" 23 #include "content/public/browser/render_process_host.h"
24 #include "content/public/browser/url_data_source.h"
23 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
24 #include "content/public/browser/web_ui.h" 26 #include "content/public/browser/web_ui.h"
25 #include "content/public/browser/web_ui_controller.h"
26 #include "content/public/browser/web_ui_data_source.h" 27 #include "content/public/browser/web_ui_data_source.h"
28 #include "crypto/rsa_private_key.h"
27 #include "net/base/net_errors.h" 29 #include "net/base/net_errors.h"
28 #include "net/base/url_util.h" 30 #include "net/base/url_util.h"
29 #include "net/cert/x509_certificate.h" 31 #include "net/cert/x509_certificate.h"
32 #include "net/cert/x509_util.h"
30 #include "net/ssl/ssl_info.h" 33 #include "net/ssl/ssl_info.h"
31 #include "ui/base/resource/resource_bundle.h" 34 #include "ui/base/resource/resource_bundle.h"
32 35
33 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) 36 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
34 #include "chrome/browser/ssl/captive_portal_blocking_page.h" 37 #include "chrome/browser/ssl/captive_portal_blocking_page.h"
35 #endif 38 #endif
36 39
37 namespace { 40 namespace {
38 41
42 // NSS requires that serial numbers be unique even for the same issuer;
43 // as all fake certificates will contain the same issuer name, it's
44 // necessary to ensure the serial number is unique, as otherwise
45 // NSS will fail to parse.
46 base::StaticAtomicSequenceNumber g_serial_number;
47
48 scoped_refptr<net::X509Certificate> CreateFakeCert() {
49 std::unique_ptr<crypto::RSAPrivateKey> unused_key;
50 std::string cert_der;
51 if (!net::x509_util::CreateKeyAndSelfSignedCert(
52 "CN=Error", static_cast<uint32_t>(g_serial_number.GetNext()),
53 base::Time::Now() - base::TimeDelta::FromMinutes(5),
54 base::Time::Now() + base::TimeDelta::FromMinutes(5), &unused_key,
55 &cert_der)) {
56 return nullptr;
57 }
58
59 return net::X509Certificate::CreateFromBytes(cert_der.data(),
60 cert_der.size());
61 }
62
39 // Implementation of chrome://interstitials demonstration pages. This code is 63 // Implementation of chrome://interstitials demonstration pages. This code is
40 // not used in displaying any real interstitials. 64 // not used in displaying any real interstitials.
41 class InterstitialHTMLSource : public content::URLDataSource { 65 class InterstitialHTMLSource : public content::URLDataSource {
42 public: 66 public:
43 explicit InterstitialHTMLSource(content::WebContents* web_contents); 67 explicit InterstitialHTMLSource(content::WebContents* web_contents);
44 ~InterstitialHTMLSource() override; 68 ~InterstitialHTMLSource() override;
45 69
46 // content::URLDataSource: 70 // content::URLDataSource:
47 std::string GetMimeType(const std::string& mime_type) const override; 71 std::string GetMimeType(const std::string& mime_type) const override;
48 std::string GetSource() const override; 72 std::string GetSource() const override;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 &overridable_param)) { 138 &overridable_param)) {
115 overridable = overridable_param == "1"; 139 overridable = overridable_param == "1";
116 } 140 }
117 std::string strict_enforcement_param; 141 std::string strict_enforcement_param;
118 if (net::GetValueForKeyInQuery(web_contents->GetURL(), 142 if (net::GetValueForKeyInQuery(web_contents->GetURL(),
119 "strict_enforcement", 143 "strict_enforcement",
120 &strict_enforcement_param)) { 144 &strict_enforcement_param)) {
121 strict_enforcement = strict_enforcement_param == "1"; 145 strict_enforcement = strict_enforcement_param == "1";
122 } 146 }
123 net::SSLInfo ssl_info; 147 net::SSLInfo ssl_info;
148 ssl_info.cert = ssl_info.unverified_cert = CreateFakeCert();
124 // This delegate doesn't create an interstitial. 149 // This delegate doesn't create an interstitial.
125 int options_mask = 0; 150 int options_mask = 0;
126 if (overridable) 151 if (overridable)
127 options_mask |= security_interstitials::SSLErrorUI::SOFT_OVERRIDE_ENABLED; 152 options_mask |= security_interstitials::SSLErrorUI::SOFT_OVERRIDE_ENABLED;
128 if (strict_enforcement) 153 if (strict_enforcement)
129 options_mask |= security_interstitials::SSLErrorUI::STRICT_ENFORCEMENT; 154 options_mask |= security_interstitials::SSLErrorUI::STRICT_ENFORCEMENT;
130 return new SSLBlockingPage(web_contents, cert_error, ssl_info, request_url, 155 return new SSLBlockingPage(web_contents, cert_error, ssl_info, request_url,
131 options_mask, time_triggered_, nullptr, 156 options_mask, time_triggered_, nullptr,
132 base::Callback<void(bool)>()); 157 base::Callback<void(bool)>());
133 } 158 }
(...skipping 27 matching lines...) Expand all
161 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "clock_manipulation", 186 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "clock_manipulation",
162 &clock_manipulation_param)) { 187 &clock_manipulation_param)) {
163 int time_offset; 188 int time_offset;
164 if (base::StringToInt(clock_manipulation_param, &time_offset)) { 189 if (base::StringToInt(clock_manipulation_param, &time_offset)) {
165 clock_state = time_offset > 0 ? ssl_errors::CLOCK_STATE_FUTURE 190 clock_state = time_offset > 0 ? ssl_errors::CLOCK_STATE_FUTURE
166 : ssl_errors::CLOCK_STATE_PAST; 191 : ssl_errors::CLOCK_STATE_PAST;
167 } 192 }
168 } 193 }
169 194
170 net::SSLInfo ssl_info; 195 net::SSLInfo ssl_info;
196 ssl_info.cert = ssl_info.unverified_cert = CreateFakeCert();
171 // This delegate doesn't create an interstitial. 197 // This delegate doesn't create an interstitial.
172 int options_mask = 0; 198 int options_mask = 0;
173 if (overridable) 199 if (overridable)
174 options_mask |= security_interstitials::SSLErrorUI::SOFT_OVERRIDE_ENABLED; 200 options_mask |= security_interstitials::SSLErrorUI::SOFT_OVERRIDE_ENABLED;
175 if (strict_enforcement) 201 if (strict_enforcement)
176 options_mask |= security_interstitials::SSLErrorUI::STRICT_ENFORCEMENT; 202 options_mask |= security_interstitials::SSLErrorUI::STRICT_ENFORCEMENT;
177 return new BadClockBlockingPage(web_contents, cert_error, ssl_info, 203 return new BadClockBlockingPage(web_contents, cert_error, ssl_info,
178 request_url, base::Time::Now(), clock_state, 204 request_url, base::Time::Now(), clock_state,
179 nullptr, base::Callback<void(bool)>()); 205 nullptr, base::Callback<void(bool)>());
180 } 206 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "is_wifi", 283 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "is_wifi",
258 &wifi_connection_param)) { 284 &wifi_connection_param)) {
259 is_wifi_connection = wifi_connection_param == "1"; 285 is_wifi_connection = wifi_connection_param == "1";
260 } 286 }
261 std::string wifi_ssid_param; 287 std::string wifi_ssid_param;
262 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "wifi_name", 288 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "wifi_name",
263 &wifi_ssid_param)) { 289 &wifi_ssid_param)) {
264 wifi_ssid = wifi_ssid_param; 290 wifi_ssid = wifi_ssid_param;
265 } 291 }
266 net::SSLInfo ssl_info; 292 net::SSLInfo ssl_info;
293 ssl_info.cert = ssl_info.unverified_cert = CreateFakeCert();
267 CaptivePortalBlockingPage* blocking_page = 294 CaptivePortalBlockingPage* blocking_page =
268 new CaptivePortalBlockingPageWithNetInfo( 295 new CaptivePortalBlockingPageWithNetInfo(
269 web_contents, request_url, landing_url, ssl_info, 296 web_contents, request_url, landing_url, ssl_info,
270 base::Callback<void(bool)>(), is_wifi_connection, wifi_ssid); 297 base::Callback<void(bool)>(), is_wifi_connection, wifi_ssid);
271 return blocking_page; 298 return blocking_page;
272 } 299 }
273 #endif 300 #endif
274 301
275 } // namespace 302 } // namespace
276 303
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 html = interstitial_delegate.get()->GetHTMLContents(); 370 html = interstitial_delegate.get()->GetHTMLContents();
344 } else { 371 } else {
345 html = ResourceBundle::GetSharedInstance() 372 html = ResourceBundle::GetSharedInstance()
346 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML) 373 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML)
347 .as_string(); 374 .as_string();
348 } 375 }
349 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; 376 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString;
350 html_bytes->data().assign(html.begin(), html.end()); 377 html_bytes->data().assign(html.begin(), html.end());
351 callback.Run(html_bytes.get()); 378 callback.Run(html_bytes.get());
352 } 379 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/interstitials/interstitial_ui.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698