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

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) 2012 The Chromium Authors. All rights reserved.
palmer 2014/07/10 21:40:04 2014
radhikabhar 2014/07/11 04:16:15 Done.
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 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
palmer 2014/07/10 21:40:05 nit: "...whether or not the system's clock is wron
palmer 2014/07/10 21:40:05 Typo: "Client-side characteristics."
radhikabhar 2014/07/11 04:16:14 Done.
radhikabhar 2014/07/11 04:16:14 Done.
50 // whether he has encountered this error before or not.
51 float severity_date_score = 0.0;
52 if (IsUserClockInThePast(current_time_) ||
53 IsUserClockInTheFuture(current_time_)) {
54 severity_date_score = 0.5 * 0.75 * 0.1;
palmer 2014/07/10 21:40:04 Perhaps explain these magic numbers by declaring t
radhikabhar 2014/07/11 04:16:14 Done.
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
palmer 2014/07/10 21:40:05 Typo: "Server-side characteristics."
radhikabhar 2014/07/11 04:16:15 Done.
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;
palmer 2014/07/10 21:40:04 These are going to get promoted to int64 when you
radhikabhar 2014/07/11 04:16:15 Done.
81 const int kLowThreshold = 4;
82 if (time_passed >= kHighThreshold)
83 return 0.4;
palmer 2014/07/10 21:40:05 More magic numbers to name. :)
radhikabhar 2014/07/11 04:16:15 Done.
84 else if (time_passed >= kLowThreshold)
85 return 0.3;
86 else
87 return 0.2;
88 }
89
90 bool SSLErrorClassification::IsUserClockInThePast(base::Time time_now) {
91 base::Time build_time = base::GetBuildTime();
92 if (time_now < build_time)
93 return true;
94 return false;
95 }
96
97 bool SSLErrorClassification::IsUserClockInTheFuture(base::Time time_now) {
98 base::Time build_time = base::GetBuildTime();
99 if (time_now > build_time + base::TimeDelta::FromDays(365))
100 return true;
101 return false;
102 }
103
104 void SSLErrorClassification::RecordUMAStatistics(bool overridable) {
105 if (IsUserClockInThePast(current_time_))
106 RecordSSLInterstitialCause(overridable, CLOCK_PAST);
107 if (IsUserClockInTheFuture(current_time_))
108 RecordSSLInterstitialCause(overridable, CLOCK_FUTURE);
109 }
110
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698