Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ssl/ssl_error_classification.h" | |
| 6 | |
| 7 #include "base/build_time.h" | |
| 8 #include "base/metrics/field_trial.h" | |
| 9 #include "base/metrics/histogram.h" | |
| 10 #include "base/time/time.h" | |
| 11 #include "chrome/browser/browser_process.h" | |
| 12 #include "components/network_time/network_time_tracker.h" | |
| 13 #include "net/cert/x509_certificate.h" | |
| 14 | |
| 15 using base::Time; | |
| 16 using base::TimeTicks; | |
| 17 using base::TimeDelta; | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 // Events for UMA. Do not reorder or change! | |
| 22 enum SSLInterstitialCause { | |
| 23 CLOCK_PAST, | |
|
felt
2014/07/10 18:41:10
nit: how many spaces in the indentation here? it l
radhikabhar
2014/07/10 20:04:43
Done.
| |
| 24 CLOCK_FUTURE, | |
| 25 UNUSED_INTERSTITIAL_CAUSE_ENTRY, | |
| 26 }; | |
| 27 | |
| 28 void RecordSSLInterstitialCause(bool overridable, SSLInterstitialCause event) { | |
| 29 if (overridable) { | |
| 30 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.cause.overridable", event, | |
| 31 UNUSED_INTERSTITIAL_CAUSE_ENTRY); | |
| 32 } else { | |
| 33 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.cause.nonoverridable", event, | |
| 34 UNUSED_INTERSTITIAL_CAUSE_ENTRY); | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 } // namespace | |
| 39 | |
| 40 SSLErrorClassification::SSLErrorClassification( | |
| 41 base::Time current_time, | |
| 42 net::X509Certificate* cert) | |
| 43 : current_time_(current_time), | |
| 44 cert_(cert) { } | |
| 45 | |
| 46 SSLErrorClassification::~SSLErrorClassification() { } | |
| 47 | |
| 48 float SSLErrorClassification::InvalidDateSeverityScore() { | |
| 49 // Client side characterisitics. Check whether the user clock is wrong and | |
| 50 // whether he has encountered this error before or not. | |
| 51 float severity_date_score = 0.0; | |
| 52 if (IsUserClockInThePast(true, current_time_) || | |
| 53 IsUserClockInTheFuture(true, current_time_)) { | |
| 54 severity_date_score = 0.5 * 0.75 * 0.1; | |
| 55 } else { | |
| 56 severity_date_score = 0.5 * 0.75 * 1; | |
| 57 } | |
| 58 // TODO(radhikabhar): Check website settings. | |
| 59 | |
| 60 // Server Side characterisitics. Check whether the certificate has expired or | |
| 61 // is not yet valid. If the certificate has expired then factor the time which | |
| 62 // has passed since expiry. | |
| 63 if (cert_->HasExpired()) { | |
| 64 severity_date_score += 0.5 * 0.3 * | |
| 65 CalculateScoreTimePassedSinceExpiry(); | |
| 66 } | |
| 67 if (current_time_ < cert_->valid_start()) | |
| 68 severity_date_score += 0.5 * 0.2; | |
| 69 return severity_date_score; | |
| 70 } | |
| 71 | |
| 72 base::TimeDelta SSLErrorClassification::TimePassedSinceExpiry() { | |
| 73 base::TimeDelta delta = current_time_ - cert_->valid_expiry(); | |
| 74 return delta; | |
| 75 } | |
| 76 | |
| 77 float SSLErrorClassification::CalculateScoreTimePassedSinceExpiry() { | |
| 78 base::TimeDelta delta = TimePassedSinceExpiry(); | |
| 79 int64 time_passed = delta.InDays(); | |
| 80 const int kHighThreshold = 7; | |
| 81 const int kLowThreshold = 4; | |
| 82 if (time_passed >= kHighThreshold) | |
| 83 return 0.4; | |
| 84 else if (time_passed >= kLowThreshold) | |
| 85 return 0.3; | |
| 86 else | |
| 87 return 0.2; | |
| 88 } | |
| 89 | |
| 90 bool SSLErrorClassification::IsUserClockInThePast(bool overridable, | |
| 91 base::Time time_now) { | |
| 92 base::Time build_time = base::GetBuildTime(); | |
| 93 if (time_now < build_time) { | |
| 94 RecordSSLInterstitialCause(overridable, CLOCK_PAST); | |
|
felt
2014/07/10 18:41:10
since IsUserClockInThePast() has multiple call sit
radhikabhar
2014/07/10 20:04:43
Done.
| |
| 95 return true; | |
| 96 } | |
| 97 return false; | |
| 98 } | |
| 99 | |
| 100 bool SSLErrorClassification::IsUserClockInTheFuture(bool overridable, | |
| 101 base::Time time_now) { | |
| 102 base::Time build_time = base::GetBuildTime(); | |
| 103 if (time_now > build_time + base::TimeDelta::FromDays(365)) { | |
| 104 RecordSSLInterstitialCause(overridable, CLOCK_FUTURE); | |
| 105 return true; | |
| 106 } | |
| 107 return false; | |
| 108 } | |
| OLD | NEW |