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 // This method checks whether the system time is in the past. |
20 static bool IsUserClockInThePast(base::Time time_now); | 25 static bool IsUserClockInThePast(base::Time time_now); |
21 | 26 |
22 // This method checks whether the system time is too far in the future or | 27 // This method checks whether the system time is too far in the future or |
23 // the user is using a version of Chrome which is more than 1 year old. | 28 // the user is 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 method which calculates the severity score when the ssl error is |
29 // CERT_DATE_INVALID. | 34 // CERT_DATE_INVALID. |
30 float InvalidDateSeverityScore() const; | 35 float InvalidDateSeverityScore() const; |
31 | 36 |
32 static void RecordUMAStatistics(bool overridable); | 37 // A method which calculates the severity score when the ssl error is |
palmer
2014/07/31 22:40:30
// When the SSL error is |CERT_COMMON_NAME_INVALID
radhikabhar
2014/08/01 23:06:57
Done.
| |
38 // CERT_COMMON_NAME_INVALID. | |
39 float InvalidCommonNameSeverityScore() const; | |
40 | |
41 void RecordUMAStatistics(bool overridable, int cert_error); | |
33 base::TimeDelta TimePassedSinceExpiry() const; | 42 base::TimeDelta TimePassedSinceExpiry() const; |
34 | 43 |
35 private: | 44 private: |
36 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassification, TestDateInvalidScore); | 45 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, TestDateInvalidScore); |
46 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, TestNameMismatch); | |
47 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, | |
48 TestHostNameHasKnownTLD); | |
49 | |
50 typedef std::vector<std::string> Tokens; | |
51 | |
52 // This method checks whether the hostname has a known Top Level Domain or | |
53 // not. | |
54 static bool IsHostNameKnownTLD(const std::string& host_name); | |
palmer
2014/07/31 22:40:30
// Returns true if |hostname| has a known top-leve
radhikabhar
2014/08/01 23:06:57
Done.
| |
55 | |
56 // A certificate for bank.com does not work for www.bank.com and vice versa. | |
57 // This method checks whteher the error is caused because of "www" difference | |
58 // between the host name and any DNS name given in the CN or SAN fields of | |
59 // the SSL certificate. | |
60 bool IsWWWSubDomainMatch() const; | |
palmer
2014/07/31 22:40:30
This should be more concise, and maybe illustrate
radhikabhar
2014/08/01 23:06:57
Done.
| |
61 | |
62 // Returns true if |child| is a subdomain of any of the |potential_parents|. | |
63 bool NameUnderAnyNames(const Tokens& child, | |
64 const std::vector<Tokens>& potential_parents) const; | |
65 | |
66 // Returns true if any of the |potential_children| is a subdomain of any of | |
palmer
2014/07/31 22:40:30
"...is a subdomain of the |parent|." (I.e. remove
radhikabhar
2014/08/01 23:06:57
Done.
| |
67 // the |parent|. | |
68 bool AnyNamesUnderName(const std::vector<Tokens>& potential_children, | |
69 const Tokens& parent) const; | |
70 | |
71 // This method checks whether the hostname is too broad for the scope of a | |
72 // wildcard certificate or not. For e.g. it returns true if the host name of | |
73 // the URL is "a.b.example.com" and the DNS name in the CN or SAN field of the | |
74 // SSL certificate is "*.example.com". But, it returns false for the hostname | |
75 // "b.example.com". | |
76 bool IsSubDomainOutsideWildcard(const Tokens& host_name_tokens) const; | |
palmer
2014/07/31 22:40:30
// Returns true if |hostname| is too broad for the
radhikabhar
2014/08/01 23:06:57
Done.
| |
37 | 77 |
38 float CalculateScoreTimePassedSinceExpiry() const; | 78 float CalculateScoreTimePassedSinceExpiry() const; |
39 | 79 |
80 std::vector<Tokens> GetTokenizedDNSNames( | |
81 std::vector<std::string>& dns_names) const; | |
palmer
2014/07/31 22:40:30
|dns_names| can be a const &?
Can this function b
radhikabhar
2014/08/01 23:06:57
Done.
| |
82 | |
40 // This stores the current time. | 83 // This stores the current time. |
41 base::Time current_time_; | 84 base::Time current_time_; |
42 | 85 |
86 const GURL& request_url_; | |
87 | |
43 // This stores the certificate. | 88 // This stores the certificate. |
44 const net::X509Certificate& cert_; | 89 const net::X509Certificate& cert_; |
45 }; | 90 }; |
46 | 91 |
47 #endif // CHROME_BROWSER_SSL_SSL_ERROR_CLASSIFICATION_H_ | 92 #endif // CHROME_BROWSER_SSL_SSL_ERROR_CLASSIFICATION_H_ |
OLD | NEW |