| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_SSL_ERRORS_ERROR_CLASSIFICATION_H_ | 5 #ifndef COMPONENTS_SSL_ERRORS_ERROR_CLASSIFICATION_H_ |
| 6 #define COMPONENTS_SSL_ERRORS_ERROR_CLASSIFICATION_H_ | 6 #define COMPONENTS_SSL_ERRORS_ERROR_CLASSIFICATION_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 namespace base { | 11 namespace base { |
| 12 class Time; | 12 class Time; |
| 13 } | 13 } |
| 14 | 14 |
| 15 class GURL; | 15 class GURL; |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 class X509Certificate; | 18 class X509Certificate; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace network_time { |
| 22 class NetworkTimeTracker; |
| 23 } |
| 24 |
| 21 namespace ssl_errors { | 25 namespace ssl_errors { |
| 22 | 26 |
| 23 typedef std::vector<std::string> HostnameTokens; | 27 typedef std::vector<std::string> HostnameTokens; |
| 24 | 28 |
| 25 // Methods for identifying specific error causes. ------------------------------ | 29 // Methods for identifying specific error causes. ------------------------------ |
| 26 | 30 |
| 27 // Returns true if the system time is in the past. | 31 // What is known about the accuracy of system clock. Do not change or |
| 28 bool IsUserClockInThePast(const base::Time& time_now); | 32 // reorder; these values are used in an UMA histogram. |
| 33 enum ClockState { |
| 34 // Not known whether system clock is close enough. |
| 35 CLOCK_STATE_UNKNOWN, |
| 29 | 36 |
| 30 // Returns true if the system time is too far in the future or the user is | 37 // System clock is "close enough", per network time. |
| 31 // using a version of Chrome which is more than 1 year old. | 38 CLOCK_STATE_OK, |
| 32 bool IsUserClockInTheFuture(const base::Time& time_now); | 39 |
| 40 // System clock is behind. |
| 41 CLOCK_STATE_PAST, |
| 42 |
| 43 // System clock is ahead. |
| 44 CLOCK_STATE_FUTURE, |
| 45 }; |
| 46 |
| 47 // Returns the current state of the clock. The states are documented with the |
| 48 // |CLOCK_STATE| enum. A result from network time, if available, will always be |
| 49 // preferred to a result from the build time. |
| 50 ClockState GetClockState( |
| 51 const base::Time& now_system, |
| 52 const network_time::NetworkTimeTracker* network_time_tracker, |
| 53 bool record_results); |
| 33 | 54 |
| 34 // Returns true if |hostname| is too broad for the scope of a wildcard | 55 // Returns true if |hostname| is too broad for the scope of a wildcard |
| 35 // certificate. E.g.: | 56 // certificate. E.g.: |
| 36 // a.b.example.com ~ *.example.com --> true | 57 // a.b.example.com ~ *.example.com --> true |
| 37 // b.example.com ~ *.example.com --> false | 58 // b.example.com ~ *.example.com --> false |
| 38 bool IsSubDomainOutsideWildcard(const GURL& request_url, | 59 bool IsSubDomainOutsideWildcard(const GURL& request_url, |
| 39 const net::X509Certificate& cert); | 60 const net::X509Certificate& cert); |
| 40 | 61 |
| 41 // Returns true if the certificate is a shared certificate. Note - This | 62 // Returns true if the certificate is a shared certificate. Note - This |
| 42 // function should be used with caution (only for UMA histogram) as an | 63 // function should be used with caution (only for UMA histogram) as an |
| (...skipping 17 matching lines...) Expand all Loading... |
| 60 // www.food.example.com ~ example.com -> false | 81 // www.food.example.com ~ example.com -> false |
| 61 // mail.example.com ~ example.com -> false | 82 // mail.example.com ~ example.com -> false |
| 62 bool GetWWWSubDomainMatch(const GURL& request_url, | 83 bool GetWWWSubDomainMatch(const GURL& request_url, |
| 63 const std::vector<std::string>& dns_names, | 84 const std::vector<std::string>& dns_names, |
| 64 std::string* www_match_host_name); | 85 std::string* www_match_host_name); |
| 65 | 86 |
| 66 // Method for recording results. ----------------------------------------------- | 87 // Method for recording results. ----------------------------------------------- |
| 67 | 88 |
| 68 void RecordUMAStatistics(bool overridable, | 89 void RecordUMAStatistics(bool overridable, |
| 69 const base::Time& current_time, | 90 const base::Time& current_time, |
| 91 const network_time::NetworkTimeTracker* network_time, |
| 70 const GURL& request_url, | 92 const GURL& request_url, |
| 71 int cert_error, | 93 int cert_error, |
| 72 const net::X509Certificate& cert); | 94 const net::X509Certificate& cert); |
| 73 | 95 |
| 74 // Helper methods for classification. ------------------------------------------ | 96 // Helper methods for classification. ------------------------------------------ |
| 75 | 97 |
| 76 // Tokenize DNS names and hostnames. | 98 // Tokenize DNS names and hostnames. |
| 77 HostnameTokens Tokenize(const std::string& name); | 99 HostnameTokens Tokenize(const std::string& name); |
| 78 | 100 |
| 79 // Sets a clock for browser tests that check the build time. Used by | 101 // Sets a clock for browser tests that check the build time. Used by |
| (...skipping 19 matching lines...) Expand all Loading... |
| 99 // appspot.com. | 121 // appspot.com. |
| 100 bool AnyNamesUnderName(const std::vector<HostnameTokens>& potential_children, | 122 bool AnyNamesUnderName(const std::vector<HostnameTokens>& potential_children, |
| 101 const HostnameTokens& parent); | 123 const HostnameTokens& parent); |
| 102 | 124 |
| 103 // Exposed for teshting. | 125 // Exposed for teshting. |
| 104 size_t GetLevenshteinDistance(const std::string& str1, const std::string& str2); | 126 size_t GetLevenshteinDistance(const std::string& str1, const std::string& str2); |
| 105 | 127 |
| 106 } // namespace ssl_errors | 128 } // namespace ssl_errors |
| 107 | 129 |
| 108 #endif // COMPONENTS_SSL_ERRORS_ERROR_CLASSIFICATION_H_ | 130 #endif // COMPONENTS_SSL_ERRORS_ERROR_CLASSIFICATION_H_ |
| OLD | NEW |