Chromium Code Reviews| 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> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "content/public/browser/notification_observer.h" | |
| 13 #include "content/public/browser/notification_registrar.h" | |
| 14 #include "net/cert/x509_certificate.h" | 12 #include "net/cert/x509_certificate.h" |
| 15 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 16 | 14 |
| 17 namespace content { | 15 class SSLErrorClassification { |
|
estark
2015/09/25 23:53:35
Are you planning to leave this as a class, or turn
felt
2015/09/27 20:08:15
I'm going to turn it into a namespace of static me
| |
| 18 class WebContents; | |
| 19 } | |
| 20 | |
| 21 // This class classifies characteristics of SSL errors, including information | |
| 22 // about captive portal detection. | |
| 23 // | |
| 24 // This class should only be used on the UI thread because its | |
| 25 // implementation uses captive_portal::CaptivePortalService which can only be | |
| 26 // accessed on the UI thread. | |
| 27 class SSLErrorClassification : public content::NotificationObserver { | |
| 28 public: | 16 public: |
| 29 SSLErrorClassification(content::WebContents* web_contents, | 17 SSLErrorClassification(const base::Time& current_time, |
| 30 const base::Time& current_time, | |
| 31 const GURL& url, | 18 const GURL& url, |
| 32 int cert_error, | 19 int cert_error, |
| 33 const net::X509Certificate& cert); | 20 const net::X509Certificate& cert); |
| 34 ~SSLErrorClassification() override; | 21 ~SSLErrorClassification(); |
| 35 | 22 |
| 36 // Returns true if the system time is in the past. | 23 // Returns true if the system time is in the past. |
| 37 static bool IsUserClockInThePast(const base::Time& time_now); | 24 static bool IsUserClockInThePast(const base::Time& time_now); |
| 38 | 25 |
| 39 // Returns true if the system time is too far in the future or the user is | 26 // Returns true if the system time is too far in the future or the user is |
| 40 // using a version of Chrome which is more than 1 year old. | 27 // using a version of Chrome which is more than 1 year old. |
| 41 static bool IsUserClockInTheFuture(const base::Time& time_now); | 28 static bool IsUserClockInTheFuture(const base::Time& time_now); |
| 42 | 29 |
| 43 // Sets a clock for browser tests that check the build time. Used by | 30 // Sets a clock for browser tests that check the build time. Used by |
| 44 // IsUserClockInThePast and IsUserClockInTheFuture. | 31 // IsUserClockInThePast and IsUserClockInTheFuture. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 55 // | 42 // |
| 56 // www.example.com ~ example.com -> true | 43 // www.example.com ~ example.com -> true |
| 57 // example.com ~ www.example.com -> true | 44 // example.com ~ www.example.com -> true |
| 58 // www.food.example.com ~ example.com -> false | 45 // www.food.example.com ~ example.com -> false |
| 59 // mail.example.com ~ example.com -> false | 46 // mail.example.com ~ example.com -> false |
| 60 static bool GetWWWSubDomainMatch(const std::string& host_name, | 47 static bool GetWWWSubDomainMatch(const std::string& host_name, |
| 61 const std::vector<std::string>& dns_names, | 48 const std::vector<std::string>& dns_names, |
| 62 std::string* www_match_host_name); | 49 std::string* www_match_host_name); |
| 63 | 50 |
| 64 void RecordUMAStatistics(bool overridable) const; | 51 void RecordUMAStatistics(bool overridable) const; |
| 65 void RecordCaptivePortalUMAStatistics(bool overridable) const; | |
| 66 | 52 |
| 67 private: | 53 private: |
| 68 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, TestDateInvalidScore); | 54 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, TestDateInvalidScore); |
| 69 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, TestNameMismatch); | 55 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, TestNameMismatch); |
| 70 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, | 56 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, |
| 71 TestHostNameHasKnownTLD); | 57 TestHostNameHasKnownTLD); |
| 72 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, TestPrivateURL); | 58 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, TestPrivateURL); |
| 73 | 59 |
| 74 typedef std::vector<std::string> Tokens; | 60 typedef std::vector<std::string> Tokens; |
| 75 | 61 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 // For example, | 110 // For example, |
| 125 // | 111 // |
| 126 // FindSubDomainDifference(Tokenize("a.b.example.com"), | 112 // FindSubDomainDifference(Tokenize("a.b.example.com"), |
| 127 // Tokenize("example.com")) | 113 // Tokenize("example.com")) |
| 128 // --> 2. | 114 // --> 2. |
| 129 size_t FindSubDomainDifference(const Tokens& potential_subdomain, | 115 size_t FindSubDomainDifference(const Tokens& potential_subdomain, |
| 130 const Tokens& parent) const; | 116 const Tokens& parent) const; |
| 131 | 117 |
| 132 static Tokens Tokenize(const std::string& name); | 118 static Tokens Tokenize(const std::string& name); |
| 133 | 119 |
| 134 // content::NotificationObserver: | |
| 135 void Observe(int type, | |
| 136 const content::NotificationSource& source, | |
| 137 const content::NotificationDetails& details) override; | |
| 138 | |
| 139 content::WebContents* web_contents_; | |
| 140 base::Time current_time_; | 120 base::Time current_time_; |
| 141 const GURL request_url_; | 121 const GURL request_url_; |
| 142 int cert_error_; | 122 int cert_error_; |
| 143 const net::X509Certificate& cert_; | 123 const net::X509Certificate& cert_; |
| 144 bool captive_portal_detection_enabled_; | |
| 145 // Did the probe complete before the interstitial was closed? | |
| 146 bool captive_portal_probe_completed_; | |
| 147 // Did the captive portal probe receive an error or get a non-HTTP response? | |
| 148 bool captive_portal_no_response_; | |
| 149 bool captive_portal_detected_; | |
| 150 | |
| 151 content::NotificationRegistrar registrar_; | |
| 152 }; | 124 }; |
| 153 | 125 |
| 154 #endif // CHROME_BROWSER_SSL_SSL_ERROR_CLASSIFICATION_H_ | 126 #endif // CHROME_BROWSER_SSL_SSL_ERROR_CLASSIFICATION_H_ |
| OLD | NEW |