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_severity_date_invalid.h" | |
| 6 | |
| 7 #include "base/build_time.h" | |
| 8 #include "base/time/time.h" | |
| 9 #include "chrome/browser/browser_process.h" | |
| 10 #include "components/network_time/network_time_tracker.h" | |
| 11 #include "net/cert/x509_certificate.h" | |
| 12 | |
| 13 using base::Time; | |
| 14 using base::TimeTicks; | |
| 15 using base::TimeDelta; | |
| 16 | |
| 17 SSLSeverityDateInvalid::SSLSeverityDateInvalid( | |
| 18 base::Time current_time, | |
| 19 net::X509Certificate* cert) | |
| 20 : current_time_(current_time), | |
| 21 cert_(cert) { } | |
| 22 | |
| 23 SSLSeverityDateInvalid::~SSLSeverityDateInvalid() { } | |
| 24 | |
| 25 float SSLSeverityDateInvalid::ServerCharacteristics(){ | |
| 26 if (cert_->HasExpired()) { | |
| 27 return 0.3 * TimePassedSinceExpiry(); | |
| 28 } | |
| 29 if (current_time_ < cert_->valid_start()) | |
| 30 return 0.2; | |
| 31 return 0.0; | |
| 32 } | |
| 33 | |
| 34 float SSLSeverityDateInvalid::ClientCharacteristics() { | |
| 35 float severity_client_score = 0.0; | |
| 36 severity_client_score = 0.75 * IsUserClockWrong(); | |
| 37 //TODO(radhikabhar): Check website settings. | |
| 38 return severity_client_score; | |
| 39 } | |
| 40 | |
| 41 float SSLSeverityDateInvalid::TimePassedSinceExpiry() { | |
| 42 base::TimeDelta delta = current_time_ - cert_->valid_expiry(); | |
| 43 int64 time_passed = delta.InDays(); | |
| 44 const int kHighThreshold = 7; | |
| 45 const int kLowThreshold = 4; | |
| 46 if (time_passed >= kHighThreshold) | |
| 47 return 0.4; | |
| 48 else if (time_passed >= kLowThreshold) | |
| 49 return 0.3; | |
| 50 else | |
| 51 return 0.2; | |
| 52 } | |
| 53 | |
| 54 float SSLSeverityDateInvalid::IsUserClockWrong() { | |
|
felt
2014/07/07 22:01:34
It doesn't make sense to have both ::IsUserClockWr
radhikabhar
2014/07/09 17:17:12
Done.
| |
| 55 base::Time network_time; | |
| 56 base::TimeDelta uncertainty; | |
| 57 if (!g_browser_process->network_time_tracker()->GetNetworkTime( | |
| 58 base::TimeTicks::Now(), &network_time, &uncertainty)) { | |
| 59 // When network time has not been initialized yet, simply rely on the | |
| 60 // machine's build time. | |
| 61 network_time = base::GetBuildTime(); | |
|
felt
2014/07/07 22:01:34
Why not check *both* the build time and the networ
radhikabhar
2014/07/09 17:17:12
Done.
| |
| 62 } | |
| 63 if (current_time_ < network_time - base::TimeDelta::FromDays(1)) { | |
| 64 return 0.1; | |
| 65 } | |
| 66 if (current_time_ > network_time + base::TimeDelta::FromDays(1)) { | |
| 67 return 0.1; | |
| 68 } | |
| 69 return 0.9; | |
| 70 } | |
| OLD | NEW |