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

Side by Side Diff: chrome/browser/ssl/ssl_error_classification.cc

Issue 376663002: Calculate severity score for date_invalid error (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 6 years, 5 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
OLDNEW
(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{
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;
54 static const float kSystemClockWeightage = 0.75;
55 static const float kSystemClockWrongWeightage = 1;
56 static const float kSystemClockRightWeightage = 0.1;
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.
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{
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)
felt 2014/07/11 14:12:48 this code used to add a little buffer (2 days), in
radhikabhar 2014/07/11 16:34:46 Done.
108 return true;
109 return false;
110 }
111
112 bool SSLErrorClassification::IsUserClockInTheFuture(base::Time time_now) {
felt 2014/07/11 14:12:48 In the .h file, you should probably clarify that t
radhikabhar 2014/07/11 16:34:46 Done.
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(current_time_))
121 RecordSSLInterstitialCause(overridable, CLOCK_PAST);
122 if (IsUserClockInTheFuture(current_time_))
123 RecordSSLInterstitialCause(overridable, CLOCK_FUTURE);
124 }
125
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698