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(const 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(const base::Time& time_now); |
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(const 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 score between 0.0 and 1.0, higher values |
30 float InvalidDateSeverityScore() const; | 35 // being more severe, indicating how severe the certificate's invalid |
| 36 // date error is. |
| 37 float InvalidDateSeverityScore(int cert_error) const; |
31 | 38 |
32 static void RecordUMAStatistics(bool overridable); | 39 // A function which calculates the severity score when the ssl error is |
| 40 // when the SSL error is |CERT_COMMON_NAME_INVALID|, returns a score between |
| 41 // between 0.0 and 1.0, higher values being more severe, indicating how |
| 42 // severe the certificate's common name invalid error is. |
| 43 float InvalidCommonNameSeverityScore(int cert_error) const; |
| 44 |
| 45 void RecordUMAStatistics(bool overridable, int cert_error); |
33 base::TimeDelta TimePassedSinceExpiry() const; | 46 base::TimeDelta TimePassedSinceExpiry() const; |
34 | 47 |
35 private: | 48 private: |
36 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassification, TestDateInvalidScore); | 49 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, TestDateInvalidScore); |
| 50 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, TestNameMismatch); |
| 51 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, |
| 52 TestHostNameHasKnownTLD); |
| 53 |
| 54 typedef std::vector<std::string> Tokens; |
| 55 |
| 56 // Returns true if the hostname has a known Top Level Domain. |
| 57 static bool IsHostNameKnownTLD(const std::string& host_name); |
| 58 |
| 59 // Returns true if the site's hostname differs from one of the DNS |
| 60 // names in the certificate (CN or SANs) only by the presence or |
| 61 // absence of the single-label prefix "www". E.g.: |
| 62 // |
| 63 // www.example.com ~ example.com -> true |
| 64 // example.com ~ www.example.com -> true |
| 65 // www.food.example.com ~ example.com -> false |
| 66 // mail.example.com ~ example.com -> false |
| 67 bool IsWWWSubDomainMatch() const; |
| 68 |
| 69 // Returns true if |child| is a subdomain of any of the |potential_parents|. |
| 70 bool NameUnderAnyNames(const Tokens& child, |
| 71 const std::vector<Tokens>& potential_parents) const; |
| 72 |
| 73 // Returns true if any of the |potential_children| is a subdomain of the |
| 74 // |parent|. The inverse case should be treated carefully as this is most |
| 75 // likely a MITM attack. We don't want foo.appspot.com to be able to MITM for |
| 76 // appspot.com. |
| 77 bool AnyNamesUnderName(const std::vector<Tokens>& potential_children, |
| 78 const Tokens& parent) const; |
| 79 |
| 80 // Returns true if |hostname| is too broad for the scope of a wildcard |
| 81 // certificate. E.g.: |
| 82 // |
| 83 // a.b.example.com ~ *.example.com --> true |
| 84 // b.example.com ~ *.example.com --> false |
| 85 bool IsSubDomainOutsideWildcard(const Tokens& hostname) const; |
37 | 86 |
38 float CalculateScoreTimePassedSinceExpiry() const; | 87 float CalculateScoreTimePassedSinceExpiry() const; |
39 | 88 |
| 89 static std::vector<Tokens> GetTokenizedDNSNames( |
| 90 const std::vector<std::string>& dns_names); |
| 91 |
| 92 // If |potential_subdomain| is a subdomain of |parent|, returns the |
| 93 // number of DNS labels by which |potential_subdomain| is under |
| 94 // |parent|. Otherwise, returns 0. |
| 95 // |
| 96 // For example, |
| 97 // |
| 98 // FindSubDomainDifference(Tokenize("a.b.example.com"), |
| 99 // Tokenize("example.com")) |
| 100 // --> 2. |
| 101 size_t FindSubDomainDifference(const Tokens& potential_subdomain, |
| 102 const Tokens& parent) const; |
| 103 |
| 104 static Tokens Tokenize(const std::string& name); |
| 105 |
40 // This stores the current time. | 106 // This stores the current time. |
41 base::Time current_time_; | 107 base::Time current_time_; |
42 | 108 |
| 109 const GURL& request_url_; |
| 110 |
43 // This stores the certificate. | 111 // This stores the certificate. |
44 const net::X509Certificate& cert_; | 112 const net::X509Certificate& cert_; |
45 }; | 113 }; |
46 | 114 |
47 #endif // CHROME_BROWSER_SSL_SSL_ERROR_CLASSIFICATION_H_ | 115 #endif // CHROME_BROWSER_SSL_SSL_ERROR_CLASSIFICATION_H_ |
OLD | NEW |