OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CHROME_BROWSER_SSL_SSL_ERROR_CLASSIFICATION_H_ | 5 #ifndef CHROME_BROWSER_SSL_SSL_ERROR_CLASSIFICATION_H_ |
6 #define CHROME_BROWSER_SSL_SSL_ERROR_CLASSIFICATION_H_ | 6 #define CHROME_BROWSER_SSL_SSL_ERROR_CLASSIFICATION_H_ |
7 | 7 |
8 #include <string> | |
9 #include <vector> | |
10 | |
8 #include "base/time/time.h" | 11 #include "base/time/time.h" |
9 #include "net/cert/x509_certificate.h" | 12 #include "net/cert/x509_certificate.h" |
13 #include "url/gurl.h" | |
10 | 14 |
11 // This class calculates the severity scores for the different type of SSL | 15 // This class calculates the severity scores for the different type of SSL |
12 // errors. | 16 // errors. |
13 class SSLErrorClassification { | 17 class SSLErrorClassification { |
14 public: | 18 public: |
15 SSLErrorClassification(base::Time current_time, | 19 SSLErrorClassification(base::Time current_time, |
20 const GURL& url, | |
16 const net::X509Certificate& cert); | 21 const net::X509Certificate& cert); |
17 ~SSLErrorClassification(); | 22 ~SSLErrorClassification(); |
18 | 23 |
19 // This method checks whether the user clock is in the past or not. | 24 // Returns true if the system time is in the past. |
20 static bool IsUserClockInThePast(base::Time time_now); | 25 static bool IsUserClockInThePast(base::Time time_now); |
palmer
2014/08/04 23:48:29
Nit: Searching through the codebase shows a LOT of
radhikabhar
2014/08/05 02:17:37
Done.
| |
21 | 26 |
22 // This method checks whether the system time is too far in the future or | 27 // Returns true if the system time is too far in the future or the user is |
23 // the user is using a version of Chrome which is more than 1 year old. | 28 // using a version of Chrome which is more than 1 year old. |
24 static bool IsUserClockInTheFuture(base::Time time_now); | 29 static bool IsUserClockInTheFuture(base::Time time_now); |
25 | 30 |
26 static bool IsWindowsVersionSP3OrLower(); | 31 static bool IsWindowsVersionSP3OrLower(); |
27 | 32 |
28 // A method which calculates the severity score when the ssl error is | 33 // A function which calculates the severity score when the ssl error is |
29 // CERT_DATE_INVALID. | 34 // CERT_DATE_INVALID, returns a severity score between 0.0. and 1.0 (higher |
palmer
2014/08/04 23:48:29
Nit: Be more concise:
// Returns a score between
radhikabhar
2014/08/05 02:17:36
Done.
| |
30 float InvalidDateSeverityScore() const; | 35 // values being more severe). |
36 float InvalidDateSeverityScore(int cert_error) const; | |
31 | 37 |
32 static void RecordUMAStatistics(bool overridable); | 38 // A function which calculates the severity score when the ssl error is |
39 // when the SSL error is |CERT_COMMON_NAME_INVALID|, returns | |
40 // a severity score between 0.0 and 1.0 (higher values being | |
41 // more severe). | |
palmer
2014/08/04 23:48:29
Nit: Prefer the more concise style, as above.
radhikabhar
2014/08/05 02:17:37
Done.
| |
42 float InvalidCommonNameSeverityScore(int cert_error) const; | |
43 | |
44 void RecordUMAStatistics(bool overridable, int cert_error); | |
33 base::TimeDelta TimePassedSinceExpiry() const; | 45 base::TimeDelta TimePassedSinceExpiry() const; |
34 | 46 |
35 private: | 47 private: |
36 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassification, TestDateInvalidScore); | 48 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, TestDateInvalidScore); |
49 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, TestNameMismatch); | |
50 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, | |
51 TestHostNameHasKnownTLD); | |
52 | |
53 typedef std::vector<std::string> Tokens; | |
54 | |
55 // Returns true if the hostname has a known Top Level Domain. | |
56 static bool IsHostNameKnownTLD(const std::string& host_name); | |
57 | |
58 // Returns true if the site's hostname differs from one of the DNS | |
59 // names in the certificate (CN or SANs) only by the presence or | |
60 // absence of the single-label prefix "www". E.g.: | |
61 // | |
62 // www.example.com ~ example.com -> true | |
63 // example.com ~ www.example.com -> true | |
64 // www.food.example.com ~ example.com -> false | |
65 // mail.example.com ~ example.com -> false | |
66 bool IsWWWSubDomainMatch() const; | |
67 | |
68 // Returns true if |child| is a subdomain of any of the |potential_parents|. | |
69 bool NameUnderAnyNames(const Tokens& child, | |
70 const std::vector<Tokens>& potential_parents) const; | |
71 | |
72 // Returns true if any of the |potential_children| is a subdomain of the | |
73 // |parent|. | |
74 bool AnyNamesUnderName(const std::vector<Tokens>& potential_children, | |
75 const Tokens& parent) const; | |
76 | |
77 // Returns true if |hostname| is too broad for the scope of a wildcard | |
78 // certificate. E.g.: | |
79 // | |
80 // a.b.example.com ~ *.example.com --> true | |
81 // b.example.com ~ *.example.com --> false | |
82 bool IsSubDomainOutsideWildcard(const Tokens& hostname) const; | |
37 | 83 |
38 float CalculateScoreTimePassedSinceExpiry() const; | 84 float CalculateScoreTimePassedSinceExpiry() const; |
39 | 85 |
86 static std::vector<Tokens> GetTokenizedDNSNames( | |
87 const std::vector<std::string>& dns_names); | |
88 | |
89 // If |potential_subdomain| is a subdomain of |parent|, returns the | |
90 // number of DNS labels by which |potential_subdomain| is under | |
91 // |parent|. Otherwise, returns 0. | |
92 // | |
93 // For example, | |
94 // | |
95 // FindSubDomainDifference(Tokenize("a.b.example.com"), | |
96 // Tokenize("example.com")) | |
97 // --> 2. | |
98 size_t FindSubDomainDifference(const Tokens& potential_subdomain, | |
99 const Tokens& parent) const; | |
100 | |
101 static Tokens Tokenize(const std::string& name); | |
102 | |
40 // This stores the current time. | 103 // This stores the current time. |
41 base::Time current_time_; | 104 base::Time current_time_; |
42 | 105 |
106 const GURL& request_url_; | |
107 | |
43 // This stores the certificate. | 108 // This stores the certificate. |
44 const net::X509Certificate& cert_; | 109 const net::X509Certificate& cert_; |
45 }; | 110 }; |
46 | 111 |
47 #endif // CHROME_BROWSER_SSL_SSL_ERROR_CLASSIFICATION_H_ | 112 #endif // CHROME_BROWSER_SSL_SSL_ERROR_CLASSIFICATION_H_ |
OLD | NEW |