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. |
28 bool IsUserClockInThePast(const base::Time& time_now); | 32 enum ClockState { |
| 33 // Not known whether system clock is close enough. |
| 34 CLOCK_STATE_UNKNOWN, |
29 | 35 |
30 // Returns true if the system time is too far in the future or the user is | 36 // System clock is "close enough", per network time. |
31 // using a version of Chrome which is more than 1 year old. | 37 CLOCK_STATE_OK, |
32 bool IsUserClockInTheFuture(const base::Time& time_now); | 38 |
| 39 // System clock is behind. |
| 40 CLOCK_STATE_PAST, |
| 41 |
| 42 // System clock is ahead. |
| 43 CLOCK_STATE_FUTURE, |
| 44 }; |
| 45 |
| 46 // Returns the current state of the clock. The states are documented with the |
| 47 // |CLOCK_STATE| enum. A result from network time, if available, will always be |
| 48 // preferred to a result from the build time. |
| 49 ClockState GetClockState( |
| 50 const base::Time& now_system, |
| 51 const network_time::NetworkTimeTracker* network_time_tracker); |
33 | 52 |
34 // Returns true if |hostname| is too broad for the scope of a wildcard | 53 // Returns true if |hostname| is too broad for the scope of a wildcard |
35 // certificate. E.g.: | 54 // certificate. E.g.: |
36 // a.b.example.com ~ *.example.com --> true | 55 // a.b.example.com ~ *.example.com --> true |
37 // b.example.com ~ *.example.com --> false | 56 // b.example.com ~ *.example.com --> false |
38 bool IsSubDomainOutsideWildcard(const GURL& request_url, | 57 bool IsSubDomainOutsideWildcard(const GURL& request_url, |
39 const net::X509Certificate& cert); | 58 const net::X509Certificate& cert); |
40 | 59 |
41 // Returns true if the certificate is a shared certificate. Note - This | 60 // Returns true if the certificate is a shared certificate. Note - This |
42 // function should be used with caution (only for UMA histogram) as an | 61 // 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 | 79 // www.food.example.com ~ example.com -> false |
61 // mail.example.com ~ example.com -> false | 80 // mail.example.com ~ example.com -> false |
62 bool GetWWWSubDomainMatch(const GURL& request_url, | 81 bool GetWWWSubDomainMatch(const GURL& request_url, |
63 const std::vector<std::string>& dns_names, | 82 const std::vector<std::string>& dns_names, |
64 std::string* www_match_host_name); | 83 std::string* www_match_host_name); |
65 | 84 |
66 // Method for recording results. ----------------------------------------------- | 85 // Method for recording results. ----------------------------------------------- |
67 | 86 |
68 void RecordUMAStatistics(bool overridable, | 87 void RecordUMAStatistics(bool overridable, |
69 const base::Time& current_time, | 88 const base::Time& current_time, |
| 89 const network_time::NetworkTimeTracker* network_time, |
70 const GURL& request_url, | 90 const GURL& request_url, |
71 int cert_error, | 91 int cert_error, |
72 const net::X509Certificate& cert); | 92 const net::X509Certificate& cert); |
73 | 93 |
74 // Helper methods for classification. ------------------------------------------ | 94 // Helper methods for classification. ------------------------------------------ |
75 | 95 |
76 // Tokenize DNS names and hostnames. | 96 // Tokenize DNS names and hostnames. |
77 HostnameTokens Tokenize(const std::string& name); | 97 HostnameTokens Tokenize(const std::string& name); |
78 | 98 |
79 // Sets a clock for browser tests that check the build time. Used by | 99 // Sets a clock for browser tests that check the build time. Used by |
(...skipping 19 matching lines...) Expand all Loading... |
99 // appspot.com. | 119 // appspot.com. |
100 bool AnyNamesUnderName(const std::vector<HostnameTokens>& potential_children, | 120 bool AnyNamesUnderName(const std::vector<HostnameTokens>& potential_children, |
101 const HostnameTokens& parent); | 121 const HostnameTokens& parent); |
102 | 122 |
103 // Exposed for teshting. | 123 // Exposed for teshting. |
104 size_t GetLevenshteinDistance(const std::string& str1, const std::string& str2); | 124 size_t GetLevenshteinDistance(const std::string& str1, const std::string& str2); |
105 | 125 |
106 } // namespace ssl_errors | 126 } // namespace ssl_errors |
107 | 127 |
108 #endif // COMPONENTS_SSL_ERRORS_ERROR_CLASSIFICATION_H_ | 128 #endif // COMPONENTS_SSL_ERRORS_ERROR_CLASSIFICATION_H_ |
OLD | NEW |