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

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

Issue 2540853005: Test interstitials shouldn't use null SSLCertReporters (Closed)
Patch Set: Fix the checks Created 4 years 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/ssl/ssl_browser_tests.cc ('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/atomic_sequence_num.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 "base/time/time.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 13 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 14 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
15 #include "chrome/browser/safe_browsing/ui_manager.h" 15 #include "chrome/browser/safe_browsing/ui_manager.h"
16 #include "chrome/browser/ssl/bad_clock_blocking_page.h" 16 #include "chrome/browser/ssl/bad_clock_blocking_page.h"
17 #include "chrome/browser/ssl/ssl_blocking_page.h" 17 #include "chrome/browser/ssl/ssl_blocking_page.h"
18 #include "chrome/browser/ssl/ssl_cert_reporter.h"
18 #include "chrome/common/features.h" 19 #include "chrome/common/features.h"
19 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
20 #include "components/grit/components_resources.h" 21 #include "components/grit/components_resources.h"
21 #include "components/security_interstitials/core/ssl_error_ui.h" 22 #include "components/security_interstitials/core/ssl_error_ui.h"
22 #include "content/public/browser/interstitial_page_delegate.h" 23 #include "content/public/browser/interstitial_page_delegate.h"
23 #include "content/public/browser/render_frame_host.h" 24 #include "content/public/browser/render_frame_host.h"
24 #include "content/public/browser/render_process_host.h" 25 #include "content/public/browser/render_process_host.h"
25 #include "content/public/browser/url_data_source.h" 26 #include "content/public/browser/url_data_source.h"
26 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
27 #include "content/public/browser/web_ui.h" 28 #include "content/public/browser/web_ui.h"
28 #include "content/public/browser/web_ui_data_source.h" 29 #include "content/public/browser/web_ui_data_source.h"
29 #include "crypto/rsa_private_key.h" 30 #include "crypto/rsa_private_key.h"
30 #include "net/base/net_errors.h" 31 #include "net/base/net_errors.h"
31 #include "net/base/url_util.h" 32 #include "net/base/url_util.h"
32 #include "net/cert/x509_certificate.h" 33 #include "net/cert/x509_certificate.h"
33 #include "net/cert/x509_util.h" 34 #include "net/cert/x509_util.h"
34 #include "net/ssl/ssl_info.h" 35 #include "net/ssl/ssl_info.h"
35 #include "ui/base/resource/resource_bundle.h" 36 #include "ui/base/resource/resource_bundle.h"
36 37
37 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) 38 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
38 #include "chrome/browser/ssl/captive_portal_blocking_page.h" 39 #include "chrome/browser/ssl/captive_portal_blocking_page.h"
39 #endif 40 #endif
40 41
41 namespace { 42 namespace {
42 43
44 class EmptySSLCertReporter : public SSLCertReporter {
45 public:
46 // SSLCertReporter methods:
47 void ReportInvalidCertificateChain(
48 const std::string& serialized_report) override {}
49 };
50
43 // NSS requires that serial numbers be unique even for the same issuer; 51 // NSS requires that serial numbers be unique even for the same issuer;
44 // as all fake certificates will contain the same issuer name, it's 52 // as all fake certificates will contain the same issuer name, it's
45 // necessary to ensure the serial number is unique, as otherwise 53 // necessary to ensure the serial number is unique, as otherwise
46 // NSS will fail to parse. 54 // NSS will fail to parse.
47 base::StaticAtomicSequenceNumber g_serial_number; 55 base::StaticAtomicSequenceNumber g_serial_number;
48 56
49 scoped_refptr<net::X509Certificate> CreateFakeCert() { 57 scoped_refptr<net::X509Certificate> CreateFakeCert() {
50 std::unique_ptr<crypto::RSAPrivateKey> unused_key; 58 std::unique_ptr<crypto::RSAPrivateKey> unused_key;
51 std::string cert_der; 59 std::string cert_der;
52 if (!net::x509_util::CreateKeyAndSelfSignedCert( 60 if (!net::x509_util::CreateKeyAndSelfSignedCert(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 public: 98 public:
91 CaptivePortalBlockingPageWithNetInfo( 99 CaptivePortalBlockingPageWithNetInfo(
92 content::WebContents* web_contents, 100 content::WebContents* web_contents,
93 const GURL& request_url, 101 const GURL& request_url,
94 const GURL& login_url, 102 const GURL& login_url,
95 const net::SSLInfo& ssl_info, 103 const net::SSLInfo& ssl_info,
96 const base::Callback<void(content::CertificateRequestResultType)>& 104 const base::Callback<void(content::CertificateRequestResultType)>&
97 callback, 105 callback,
98 bool is_wifi, 106 bool is_wifi,
99 const std::string& wifi_ssid) 107 const std::string& wifi_ssid)
100 : CaptivePortalBlockingPage(web_contents, 108 : CaptivePortalBlockingPage(
101 request_url, 109 web_contents,
102 login_url, 110 request_url,
103 nullptr, 111 login_url,
104 ssl_info, 112 std::unique_ptr<SSLCertReporter>(new EmptySSLCertReporter()),
105 callback), 113 ssl_info,
114 callback),
106 is_wifi_(is_wifi), 115 is_wifi_(is_wifi),
107 wifi_ssid_(wifi_ssid) {} 116 wifi_ssid_(wifi_ssid) {}
108 117
109 private: 118 private:
110 // CaptivePortalBlockingPage methods: 119 // CaptivePortalBlockingPage methods:
111 bool IsWifiConnection() const override { return is_wifi_; } 120 bool IsWifiConnection() const override { return is_wifi_; }
112 std::string GetWiFiSSID() const override { return wifi_ssid_; } 121 std::string GetWiFiSSID() const override { return wifi_ssid_; }
113 122
114 const bool is_wifi_; 123 const bool is_wifi_;
115 const std::string wifi_ssid_; 124 const std::string wifi_ssid_;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 net::SSLInfo ssl_info; 156 net::SSLInfo ssl_info;
148 ssl_info.cert = ssl_info.unverified_cert = CreateFakeCert(); 157 ssl_info.cert = ssl_info.unverified_cert = CreateFakeCert();
149 // This delegate doesn't create an interstitial. 158 // This delegate doesn't create an interstitial.
150 int options_mask = 0; 159 int options_mask = 0;
151 if (overridable) 160 if (overridable)
152 options_mask |= security_interstitials::SSLErrorUI::SOFT_OVERRIDE_ENABLED; 161 options_mask |= security_interstitials::SSLErrorUI::SOFT_OVERRIDE_ENABLED;
153 if (strict_enforcement) 162 if (strict_enforcement)
154 options_mask |= security_interstitials::SSLErrorUI::STRICT_ENFORCEMENT; 163 options_mask |= security_interstitials::SSLErrorUI::STRICT_ENFORCEMENT;
155 return SSLBlockingPage::Create( 164 return SSLBlockingPage::Create(
156 web_contents, cert_error, ssl_info, request_url, options_mask, 165 web_contents, cert_error, ssl_info, request_url, options_mask,
157 time_triggered_, nullptr, 166 time_triggered_,
167 std::unique_ptr<SSLCertReporter>(new EmptySSLCertReporter()),
158 base::Callback<void(content::CertificateRequestResultType)>()); 168 base::Callback<void(content::CertificateRequestResultType)>());
159 } 169 }
160 170
161 BadClockBlockingPage* CreateBadClockBlockingPage( 171 BadClockBlockingPage* CreateBadClockBlockingPage(
162 content::WebContents* web_contents) { 172 content::WebContents* web_contents) {
163 // Set up a fake clock error. 173 // Set up a fake clock error.
164 int cert_error = net::ERR_CERT_DATE_INVALID; 174 int cert_error = net::ERR_CERT_DATE_INVALID;
165 GURL request_url("https://example.com"); 175 GURL request_url("https://example.com");
166 bool overridable = false; 176 bool overridable = false;
167 bool strict_enforcement = false; 177 bool strict_enforcement = false;
(...skipping 28 matching lines...) Expand all
196 net::SSLInfo ssl_info; 206 net::SSLInfo ssl_info;
197 ssl_info.cert = ssl_info.unverified_cert = CreateFakeCert(); 207 ssl_info.cert = ssl_info.unverified_cert = CreateFakeCert();
198 // This delegate doesn't create an interstitial. 208 // This delegate doesn't create an interstitial.
199 int options_mask = 0; 209 int options_mask = 0;
200 if (overridable) 210 if (overridable)
201 options_mask |= security_interstitials::SSLErrorUI::SOFT_OVERRIDE_ENABLED; 211 options_mask |= security_interstitials::SSLErrorUI::SOFT_OVERRIDE_ENABLED;
202 if (strict_enforcement) 212 if (strict_enforcement)
203 options_mask |= security_interstitials::SSLErrorUI::STRICT_ENFORCEMENT; 213 options_mask |= security_interstitials::SSLErrorUI::STRICT_ENFORCEMENT;
204 return new BadClockBlockingPage( 214 return new BadClockBlockingPage(
205 web_contents, cert_error, ssl_info, request_url, base::Time::Now(), 215 web_contents, cert_error, ssl_info, request_url, base::Time::Now(),
206 clock_state, nullptr, 216 clock_state, std::unique_ptr<SSLCertReporter>(new EmptySSLCertReporter()),
207 base::Callback<void(content::CertificateRequestResultType)>()); 217 base::Callback<void(content::CertificateRequestResultType)>());
208 } 218 }
209 219
210 safe_browsing::SafeBrowsingBlockingPage* CreateSafeBrowsingBlockingPage( 220 safe_browsing::SafeBrowsingBlockingPage* CreateSafeBrowsingBlockingPage(
211 content::WebContents* web_contents) { 221 content::WebContents* web_contents) {
212 safe_browsing::SBThreatType threat_type = 222 safe_browsing::SBThreatType threat_type =
213 safe_browsing::SB_THREAT_TYPE_URL_MALWARE; 223 safe_browsing::SB_THREAT_TYPE_URL_MALWARE;
214 GURL request_url("http://example.com"); 224 GURL request_url("http://example.com");
215 std::string url_param; 225 std::string url_param;
216 if (net::GetValueForKeyInQuery(web_contents->GetURL(), 226 if (net::GetValueForKeyInQuery(web_contents->GetURL(),
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 html = interstitial_delegate.get()->GetHTMLContents(); 374 html = interstitial_delegate.get()->GetHTMLContents();
365 } else { 375 } else {
366 html = ResourceBundle::GetSharedInstance() 376 html = ResourceBundle::GetSharedInstance()
367 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML) 377 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML)
368 .as_string(); 378 .as_string();
369 } 379 }
370 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; 380 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString;
371 html_bytes->data().assign(html.begin(), html.end()); 381 html_bytes->data().assign(html.begin(), html.end());
372 callback.Run(html_bytes.get()); 382 callback.Run(html_bytes.get());
373 } 383 }
OLDNEW
« no previous file with comments | « chrome/browser/ssl/ssl_browser_tests.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698