Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014 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, | |
| 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 const net::X509Certificate& cert) | |
| 43 : current_time_(current_time), | |
| 44 cert_(cert) { } | |
| 45 | |
| 46 SSLErrorClassification::~SSLErrorClassification() { } | |
| 47 | |
| 48 float SSLErrorClassification::InvalidDateSeverityScore() const{ | |
|
palmer
2014/07/11 17:24:17
Niot: Space: "const {".
radhikabhar
2014/07/11 18:59:34
Done.
| |
| 49 // Client-side characterisitics. Check whether the system's clock is wrong or | |
| 50 // not and whether the user has encountered this error before or not. | |
| 51 float severity_date_score = 0.0; | |
| 52 | |
| 53 static const float kClientWeightage = 0.5; | |
|
palmer
2014/07/11 17:24:18
Nit: I'd go with "Weight" or "Weighting".
radhikabhar
2014/07/11 18:59:34
Done.
| |
| 54 static const float kSystemClockWeightage = 0.75; | |
| 55 static const float kSystemClockWrongWeightage = 0.1; | |
| 56 static const float kSystemClockRightWeightage = 1.0; | |
| 57 | |
| 58 static const float kServerWeightage = 0.5; | |
| 59 static const float kCertificateExpiredWeightage = 0.3; | |
| 60 static const float kNotYetValidWeightage = 0.2; | |
| 61 | |
| 62 if (IsUserClockInThePast(current_time_) || | |
| 63 IsUserClockInTheFuture(current_time_)) { | |
| 64 severity_date_score = kClientWeightage * kSystemClockWeightage * | |
| 65 kSystemClockWrongWeightage; | |
| 66 } else { | |
| 67 severity_date_score = kClientWeightage * kSystemClockWeightage * | |
| 68 kSystemClockRightWeightage; | |
| 69 } | |
| 70 // TODO(radhikabhar): Check website settings. | |
|
palmer
2014/07/11 17:24:18
Does this refer to the "Server-side characteristic
radhikabhar
2014/07/11 18:59:34
Done.
| |
| 71 | |
| 72 // Server-side characteristics. Check whether the certificate has expired or | |
| 73 // is not yet valid. If the certificate has expired then factor the time which | |
| 74 // has passed since expiry. | |
| 75 if (cert_.HasExpired()) { | |
| 76 severity_date_score += kServerWeightage * kCertificateExpiredWeightage * | |
| 77 CalculateScoreTimePassedSinceExpiry(); | |
| 78 } | |
| 79 if (current_time_ < cert_.valid_start()) | |
| 80 severity_date_score += kServerWeightage * kNotYetValidWeightage; | |
| 81 return severity_date_score; | |
| 82 } | |
| 83 | |
| 84 base::TimeDelta SSLErrorClassification::TimePassedSinceExpiry() const{ | |
|
palmer
2014/07/11 17:24:17
"const {" here and on line 89.
radhikabhar
2014/07/11 18:59:34
Done.
| |
| 85 base::TimeDelta delta = current_time_ - cert_.valid_expiry(); | |
| 86 return delta; | |
| 87 } | |
| 88 | |
| 89 float SSLErrorClassification::CalculateScoreTimePassedSinceExpiry() const{ | |
| 90 base::TimeDelta delta = TimePassedSinceExpiry(); | |
| 91 int64 time_passed = delta.InDays(); | |
| 92 const int64 kHighThreshold = 7; | |
| 93 const int64 kLowThreshold = 4; | |
| 94 static const float kHighThresholdWeightage = 0.4; | |
| 95 static const float kMediumThresholdWeightage = 0.3; | |
| 96 static const float kLowThresholdWeightage = 0.2; | |
| 97 if (time_passed >= kHighThreshold) | |
| 98 return kHighThresholdWeightage; | |
| 99 else if (time_passed >= kLowThreshold) | |
| 100 return kMediumThresholdWeightage; | |
| 101 else | |
| 102 return kLowThresholdWeightage; | |
| 103 } | |
| 104 | |
| 105 bool SSLErrorClassification::IsUserClockInThePast(base::Time time_now) { | |
| 106 base::Time build_time = base::GetBuildTime(); | |
| 107 if (time_now < build_time - base::TimeDelta::FromDays(2)) | |
| 108 return true; | |
| 109 return false; | |
| 110 } | |
| 111 | |
| 112 bool SSLErrorClassification::IsUserClockInTheFuture(base::Time time_now) { | |
| 113 base::Time build_time = base::GetBuildTime(); | |
| 114 if (time_now > build_time + base::TimeDelta::FromDays(365)) | |
| 115 return true; | |
| 116 return false; | |
| 117 } | |
| 118 | |
| 119 void SSLErrorClassification::RecordUMAStatistics(bool overridable) { | |
| 120 if (IsUserClockInThePast(base::Time::NowFromSystemTime())) | |
| 121 RecordSSLInterstitialCause(overridable, CLOCK_PAST); | |
| 122 if (IsUserClockInTheFuture(base::Time::NowFromSystemTime())) | |
| 123 RecordSSLInterstitialCause(overridable, CLOCK_FUTURE); | |
| 124 } | |
| 125 | |
| OLD | NEW |