OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ssl/ssl_blocking_page.h" | 5 #include "chrome/browser/ssl/ssl_blocking_page.h" |
6 | 6 |
7 #include "base/build_time.h" | 7 #include "base/build_time.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 | 198 |
199 #endif | 199 #endif |
200 // Don't add code here! (See the comment at the beginning of the function.) | 200 // Don't add code here! (See the comment at the beginning of the function.) |
201 } | 201 } |
202 | 202 |
203 bool IsErrorDueToBadClock(const base::Time& now, int error) { | 203 bool IsErrorDueToBadClock(const base::Time& now, int error) { |
204 if (SSLErrorInfo::NetErrorToErrorType(error) != | 204 if (SSLErrorInfo::NetErrorToErrorType(error) != |
205 SSLErrorInfo::CERT_DATE_INVALID) { | 205 SSLErrorInfo::CERT_DATE_INVALID) { |
206 return false; | 206 return false; |
207 } | 207 } |
208 | |
lgarron
2015/02/20 22:12:46
Nit: Remove all blank lines until the diff is sema
| |
208 return SSLErrorClassification::IsUserClockInThePast(now) || | 209 return SSLErrorClassification::IsUserClockInThePast(now) || |
209 SSLErrorClassification::IsUserClockInTheFuture(now); | 210 SSLErrorClassification::IsUserClockInTheFuture(now); |
210 } | 211 } |
211 | 212 |
212 } // namespace | 213 } // namespace |
213 | 214 |
214 // static | 215 // static |
215 const void* SSLBlockingPage::kTypeForTesting = | 216 const void* SSLBlockingPage::kTypeForTesting = |
216 &SSLBlockingPage::kTypeForTesting; | 217 &SSLBlockingPage::kTypeForTesting; |
217 | 218 |
218 // Note that we always create a navigation entry with SSL errors. | 219 // Note that we always create a navigation entry with SSL errors. |
219 // No error happening loading a sub-resource triggers an interstitial so far. | 220 // No error happening loading a sub-resource triggers an interstitial so far. |
220 SSLBlockingPage::SSLBlockingPage(content::WebContents* web_contents, | 221 SSLBlockingPage::SSLBlockingPage(content::WebContents* web_contents, |
221 int cert_error, | 222 int cert_error, |
222 const net::SSLInfo& ssl_info, | 223 const net::SSLInfo& ssl_info, |
223 const GURL& request_url, | 224 const GURL& request_url, |
224 int options_mask, | 225 int options_mask, |
225 const base::Callback<void(bool)>& callback) | 226 const base::Callback<void(bool)>& callback, |
227 const base::Time& base_time) | |
226 : SecurityInterstitialPage(web_contents, request_url), | 228 : SecurityInterstitialPage(web_contents, request_url), |
227 callback_(callback), | 229 callback_(callback), |
228 cert_error_(cert_error), | 230 cert_error_(cert_error), |
229 ssl_info_(ssl_info), | 231 ssl_info_(ssl_info), |
230 overridable_(IsOptionsOverridable(options_mask)), | 232 overridable_(IsOptionsOverridable(options_mask)), |
231 danger_overridable_(true), | 233 danger_overridable_(true), |
232 strict_enforcement_((options_mask & STRICT_ENFORCEMENT) != 0), | 234 strict_enforcement_((options_mask & STRICT_ENFORCEMENT) != 0), |
233 expired_but_previously_allowed_( | 235 expired_but_previously_allowed_( |
234 (options_mask & EXPIRED_BUT_PREVIOUSLY_ALLOWED) != 0) { | 236 (options_mask & EXPIRED_BUT_PREVIOUSLY_ALLOWED) != 0), |
235 interstitial_reason_ = | 237 base_time_(base_time) { |
236 IsErrorDueToBadClock(base::Time::NowFromSystemTime(), cert_error_) ? | 238 interstitial_reason_ = IsErrorDueToBadClock(base_time_, cert_error_) |
237 SSL_REASON_BAD_CLOCK : SSL_REASON_SSL; | 239 ? SSL_REASON_BAD_CLOCK |
240 : SSL_REASON_SSL; | |
238 | 241 |
239 // We collapse the Rappor metric name to just "ssl" so we don't leak | 242 // We collapse the Rappor metric name to just "ssl" so we don't leak |
240 // the "overridable" bit. We skip Rappor altogether for bad clocks. | 243 // the "overridable" bit. We skip Rappor altogether for bad clocks. |
241 // This must be done after calculating |interstitial_reason_| above. | 244 // This must be done after calculating |interstitial_reason_| above. |
242 metrics_helper_.reset(new SecurityInterstitialMetricsHelper( | 245 metrics_helper_.reset(new SecurityInterstitialMetricsHelper( |
243 web_contents, request_url, GetUmaHistogramPrefix(), kSSLRapporPrefix, | 246 web_contents, request_url, GetUmaHistogramPrefix(), kSSLRapporPrefix, |
244 (interstitial_reason_ == SSL_REASON_BAD_CLOCK | 247 (interstitial_reason_ == SSL_REASON_BAD_CLOCK |
245 ? SecurityInterstitialMetricsHelper::SKIP_RAPPOR | 248 ? SecurityInterstitialMetricsHelper::SKIP_RAPPOR |
246 : SecurityInterstitialMetricsHelper::REPORT_RAPPOR), | 249 : SecurityInterstitialMetricsHelper::REPORT_RAPPOR), |
247 GetSamplingEventName())); | 250 GetSamplingEventName())); |
248 | 251 |
249 metrics_helper_->RecordUserDecision(SecurityInterstitialMetricsHelper::SHOW); | 252 metrics_helper_->RecordUserDecision(SecurityInterstitialMetricsHelper::SHOW); |
250 metrics_helper_->RecordUserInteraction( | 253 metrics_helper_->RecordUserInteraction( |
251 SecurityInterstitialMetricsHelper::TOTAL_VISITS); | 254 SecurityInterstitialMetricsHelper::TOTAL_VISITS); |
252 | 255 |
253 ssl_error_classification_.reset(new SSLErrorClassification( | 256 ssl_error_classification_.reset( |
254 web_contents, | 257 new SSLErrorClassification(web_contents, base_time_, request_url, |
255 base::Time::NowFromSystemTime(), | 258 cert_error_, *ssl_info_.cert.get())); |
256 request_url, | |
257 cert_error_, | |
258 *ssl_info_.cert.get())); | |
259 ssl_error_classification_->RecordUMAStatistics(overridable_); | 259 ssl_error_classification_->RecordUMAStatistics(overridable_); |
260 | 260 |
261 // Creating an interstitial without showing (e.g. from chrome://interstitials) | 261 // Creating an interstitial without showing (e.g. from chrome://interstitials) |
262 // it leaks memory, so don't create it here. | 262 // it leaks memory, so don't create it here. |
263 } | 263 } |
264 | 264 |
265 bool SSLBlockingPage::ShouldCreateNewNavigation() const { | 265 bool SSLBlockingPage::ShouldCreateNewNavigation() const { |
266 return true; | 266 return true; |
267 } | 267 } |
268 | 268 |
(...skipping 19 matching lines...) Expand all Loading... | |
288 } | 288 } |
289 | 289 |
290 void SSLBlockingPage::PopulateInterstitialStrings( | 290 void SSLBlockingPage::PopulateInterstitialStrings( |
291 base::DictionaryValue* load_time_data) { | 291 base::DictionaryValue* load_time_data) { |
292 CHECK(load_time_data); | 292 CHECK(load_time_data); |
293 base::string16 url(GetFormattedHostName()); | 293 base::string16 url(GetFormattedHostName()); |
294 // Shared values for both the overridable and non-overridable versions. | 294 // Shared values for both the overridable and non-overridable versions. |
295 load_time_data->SetString("type", "SSL"); | 295 load_time_data->SetString("type", "SSL"); |
296 | 296 |
297 // Shared UI configuration for all SSL interstitials. | 297 // Shared UI configuration for all SSL interstitials. |
298 base::Time now = base::Time::NowFromSystemTime(); | 298 // base::Time now = base::Time::NowFromSystemTime(); |
felt
2015/02/20 16:01:53
why are these lines here but commented out?
lgarron
2015/02/20 22:12:46
I think we've removed the need for these; I would
fahl
2015/02/23 23:47:49
Acknowledged.
fahl
2015/02/23 23:47:49
Acknowledged.
| |
299 // base::Time now = base_time_; | |
299 load_time_data->SetString("errorCode", net::ErrorToString(cert_error_)); | 300 load_time_data->SetString("errorCode", net::ErrorToString(cert_error_)); |
300 load_time_data->SetString( | 301 load_time_data->SetString( |
301 "openDetails", | 302 "openDetails", |
302 l10n_util::GetStringUTF16(IDS_SSL_V2_OPEN_DETAILS_BUTTON)); | 303 l10n_util::GetStringUTF16(IDS_SSL_V2_OPEN_DETAILS_BUTTON)); |
303 load_time_data->SetString( | 304 load_time_data->SetString( |
304 "closeDetails", | 305 "closeDetails", |
305 l10n_util::GetStringUTF16(IDS_SSL_V2_CLOSE_DETAILS_BUTTON)); | 306 l10n_util::GetStringUTF16(IDS_SSL_V2_CLOSE_DETAILS_BUTTON)); |
306 | 307 |
307 // Conditional UI configuration. | 308 // Conditional UI configuration. |
308 if (interstitial_reason_ == SSL_REASON_BAD_CLOCK) { | 309 if (interstitial_reason_ == SSL_REASON_BAD_CLOCK) { |
309 load_time_data->SetBoolean("bad_clock", true); | 310 load_time_data->SetBoolean("bad_clock", true); |
310 load_time_data->SetBoolean("overridable", false); | 311 load_time_data->SetBoolean("overridable", false); |
311 | 312 |
312 #if defined(OS_IOS) | 313 #if defined(OS_IOS) |
313 load_time_data->SetBoolean("hide_primary_button", true); | 314 load_time_data->SetBoolean("hide_primary_button", true); |
314 #else | 315 #else |
315 load_time_data->SetBoolean("hide_primary_button", false); | 316 load_time_data->SetBoolean("hide_primary_button", false); |
316 #endif | 317 #endif |
317 | 318 |
318 // We're showing the SSL clock warning to be helpful, but we haven't warned | 319 // We're showing the SSL clock warning to be helpful, but we haven't warned |
319 // them about the risks. (And there might still be an SSL error after they | 320 // them about the risks. (And there might still be an SSL error after they |
320 // fix their clock.) Thus, we don't allow the "danger" override in this | 321 // fix their clock.) Thus, we don't allow the "danger" override in this |
321 // case. | 322 // case. |
322 danger_overridable_ = false; | 323 danger_overridable_ = false; |
323 | 324 |
324 int heading_string = SSLErrorClassification::IsUserClockInTheFuture(now) ? | 325 int heading_string = |
325 IDS_SSL_V2_CLOCK_AHEAD_HEADING : | 326 SSLErrorClassification::IsUserClockInTheFuture(base_time_) |
326 IDS_SSL_V2_CLOCK_BEHIND_HEADING; | 327 ? IDS_SSL_V2_CLOCK_AHEAD_HEADING |
328 : IDS_SSL_V2_CLOCK_BEHIND_HEADING; | |
327 | 329 |
328 load_time_data->SetString( | 330 load_time_data->SetString( |
329 "tabTitle", | 331 "tabTitle", |
330 l10n_util::GetStringUTF16(IDS_SSL_V2_CLOCK_TITLE)); | 332 l10n_util::GetStringUTF16(IDS_SSL_V2_CLOCK_TITLE)); |
331 load_time_data->SetString( | 333 load_time_data->SetString( |
332 "heading", | 334 "heading", |
333 l10n_util::GetStringUTF16(heading_string)); | 335 l10n_util::GetStringUTF16(heading_string)); |
334 load_time_data->SetString("primaryParagraph", | 336 load_time_data->SetString( |
335 l10n_util::GetStringFUTF16( | 337 "primaryParagraph", |
lgarron
2015/02/20 22:12:46
I see you're using `git cl format`? :-D
lgarron
2015/02/20 22:12:46
I see you're using `git cl format`? :-D
| |
336 IDS_SSL_V2_CLOCK_PRIMARY_PARAGRAPH , | 338 l10n_util::GetStringFUTF16( |
337 url, | 339 IDS_SSL_V2_CLOCK_PRIMARY_PARAGRAPH, url, |
338 base::TimeFormatFriendlyDateAndTime(now))); | 340 base::TimeFormatFriendlyDateAndTime(base_time_))); |
339 | 341 |
340 load_time_data->SetString( | 342 load_time_data->SetString( |
341 "primaryButtonText", | 343 "primaryButtonText", |
342 l10n_util::GetStringUTF16(IDS_SSL_V2_CLOCK_UPDATE_DATE_AND_TIME)); | 344 l10n_util::GetStringUTF16(IDS_SSL_V2_CLOCK_UPDATE_DATE_AND_TIME)); |
343 load_time_data->SetString( | 345 load_time_data->SetString( |
344 "explanationParagraph", | 346 "explanationParagraph", |
345 l10n_util::GetStringUTF16(IDS_SSL_V2_CLOCK_EXPLANATION)); | 347 l10n_util::GetStringUTF16(IDS_SSL_V2_CLOCK_EXPLANATION)); |
346 | 348 |
347 // The interstitial template expects this string, but we're not using it. So | 349 // The interstitial template expects this string, but we're not using it. So |
348 // we send a blank string for now. | 350 // we send a blank string for now. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 } | 420 } |
419 | 421 |
420 // Set debugging information at the bottom of the warning. | 422 // Set debugging information at the bottom of the warning. |
421 load_time_data->SetString( | 423 load_time_data->SetString( |
422 "subject", ssl_info_.cert->subject().GetDisplayName()); | 424 "subject", ssl_info_.cert->subject().GetDisplayName()); |
423 load_time_data->SetString( | 425 load_time_data->SetString( |
424 "issuer", ssl_info_.cert->issuer().GetDisplayName()); | 426 "issuer", ssl_info_.cert->issuer().GetDisplayName()); |
425 load_time_data->SetString( | 427 load_time_data->SetString( |
426 "expirationDate", | 428 "expirationDate", |
427 base::TimeFormatShortDate(ssl_info_.cert->valid_expiry())); | 429 base::TimeFormatShortDate(ssl_info_.cert->valid_expiry())); |
428 load_time_data->SetString( | 430 load_time_data->SetString("currentDate", |
felt
2015/02/20 16:01:53
nit: i liked putting all of these on the next line
lgarron
2015/02/20 22:12:46
I suggested Sascha use `git cl format`. In case he
fahl
2015/02/23 23:47:49
Acknowledged.
| |
429 "currentDate", base::TimeFormatShortDate(now)); | 431 base::TimeFormatShortDate(base_time_)); |
430 std::vector<std::string> encoded_chain; | 432 std::vector<std::string> encoded_chain; |
431 ssl_info_.cert->GetPEMEncodedChain(&encoded_chain); | 433 ssl_info_.cert->GetPEMEncodedChain(&encoded_chain); |
432 load_time_data->SetString("pem", JoinString(encoded_chain, std::string())); | 434 load_time_data->SetString("pem", JoinString(encoded_chain, std::string())); |
433 } | 435 } |
434 | 436 |
435 void SSLBlockingPage::OverrideEntry(NavigationEntry* entry) { | 437 void SSLBlockingPage::OverrideEntry(NavigationEntry* entry) { |
436 int cert_id = content::CertStore::GetInstance()->StoreCert( | 438 int cert_id = content::CertStore::GetInstance()->StoreCert( |
437 ssl_info_.cert.get(), web_contents()->GetRenderProcessHost()->GetID()); | 439 ssl_info_.cert.get(), web_contents()->GetRenderProcessHost()->GetID()); |
438 DCHECK(cert_id); | 440 DCHECK(cert_id); |
439 | 441 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 event_name.append(kEventNotOverridable); | 562 event_name.append(kEventNotOverridable); |
561 event_name.append(net::ErrorToString(cert_error_)); | 563 event_name.append(net::ErrorToString(cert_error_)); |
562 return event_name; | 564 return event_name; |
563 } | 565 } |
564 | 566 |
565 // static | 567 // static |
566 bool SSLBlockingPage::IsOptionsOverridable(int options_mask) { | 568 bool SSLBlockingPage::IsOptionsOverridable(int options_mask) { |
567 return (options_mask & SSLBlockingPage::OVERRIDABLE) && | 569 return (options_mask & SSLBlockingPage::OVERRIDABLE) && |
568 !(options_mask & SSLBlockingPage::STRICT_ENFORCEMENT); | 570 !(options_mask & SSLBlockingPage::STRICT_ENFORCEMENT); |
569 } | 571 } |
OLD | NEW |