| 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" |
| 12 #include "net/cert/x509_certificate.h" | 14 #include "net/cert/x509_certificate.h" |
| 13 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 14 | 16 |
| 17 namespace content { |
| 18 class WebContents; |
| 19 } |
| 20 |
| 15 // This class calculates the severity scores for the different type of SSL | 21 // This class calculates the severity scores for the different type of SSL |
| 16 // errors. | 22 // errors. |
| 17 class SSLErrorClassification { | 23 class SSLErrorClassification : public content::NotificationObserver { |
| 18 public: | 24 public: |
| 19 SSLErrorClassification(const base::Time& current_time, | 25 SSLErrorClassification(content::WebContents* web_contents, |
| 26 const base::Time& current_time, |
| 20 const GURL& url, | 27 const GURL& url, |
| 28 int cert_error, |
| 21 const net::X509Certificate& cert); | 29 const net::X509Certificate& cert); |
| 22 ~SSLErrorClassification(); | 30 virtual ~SSLErrorClassification(); |
| 23 | 31 |
| 24 // Returns true if the system time is in the past. | 32 // Returns true if the system time is in the past. |
| 25 static bool IsUserClockInThePast(const base::Time& time_now); | 33 static bool IsUserClockInThePast(const base::Time& time_now); |
| 26 | 34 |
| 27 // Returns true if the system time is too far in the future or the user is | 35 // Returns true if the system time is too far in the future or the user is |
| 28 // using a version of Chrome which is more than 1 year old. | 36 // using a version of Chrome which is more than 1 year old. |
| 29 static bool IsUserClockInTheFuture(const base::Time& time_now); | 37 static bool IsUserClockInTheFuture(const base::Time& time_now); |
| 30 | 38 |
| 31 static bool IsWindowsVersionSP3OrLower(); | 39 static bool IsWindowsVersionSP3OrLower(); |
| 32 | 40 |
| 33 // A function which calculates the severity score when the ssl error is | 41 // A function which calculates the severity score when the ssl error is |
| 34 // CERT_DATE_INVALID, returns a score between 0.0 and 1.0, higher values | 42 // CERT_DATE_INVALID, calculates a score between 0.0 and 1.0, higher values |
| 35 // being more severe, indicating how severe the certificate's invalid | 43 // being more severe, indicating how severe the certificate's invalid |
| 36 // date error is. | 44 // date error is. |
| 37 float InvalidDateSeverityScore(int cert_error) const; | 45 void InvalidDateSeverityScore() const; |
| 38 | 46 |
| 39 // A function which calculates the severity score when the ssl error is | 47 // 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 | 48 // when the SSL error is |CERT_COMMON_NAME_INVALID|, calcualates a score |
| 41 // between 0.0 and 1.0, higher values being more severe, indicating how | 49 // between 0.0 and 1.0, higher values being more severe, indicating how |
| 42 // severe the certificate's common name invalid error is. | 50 // severe the certificate's common name invalid error is. |
| 43 float InvalidCommonNameSeverityScore(int cert_error) const; | 51 void InvalidCommonNameSeverityScore() const; |
| 44 | 52 |
| 45 void RecordUMAStatistics(bool overridable, int cert_error); | 53 void RecordUMAStatistics(bool overridable) const; |
| 54 void RecordCaptivePortalUMAStatistics(bool overridable) const; |
| 46 base::TimeDelta TimePassedSinceExpiry() const; | 55 base::TimeDelta TimePassedSinceExpiry() const; |
| 47 | 56 |
| 48 private: | 57 private: |
| 49 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, TestDateInvalidScore); | 58 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, TestDateInvalidScore); |
| 50 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, TestNameMismatch); | 59 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, TestNameMismatch); |
| 51 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, | 60 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassificationTest, |
| 52 TestHostNameHasKnownTLD); | 61 TestHostNameHasKnownTLD); |
| 53 | 62 |
| 54 typedef std::vector<std::string> Tokens; | 63 typedef std::vector<std::string> Tokens; |
| 55 | 64 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 77 bool AnyNamesUnderName(const std::vector<Tokens>& potential_children, | 86 bool AnyNamesUnderName(const std::vector<Tokens>& potential_children, |
| 78 const Tokens& parent) const; | 87 const Tokens& parent) const; |
| 79 | 88 |
| 80 // Returns true if |hostname| is too broad for the scope of a wildcard | 89 // Returns true if |hostname| is too broad for the scope of a wildcard |
| 81 // certificate. E.g.: | 90 // certificate. E.g.: |
| 82 // | 91 // |
| 83 // a.b.example.com ~ *.example.com --> true | 92 // a.b.example.com ~ *.example.com --> true |
| 84 // b.example.com ~ *.example.com --> false | 93 // b.example.com ~ *.example.com --> false |
| 85 bool IsSubDomainOutsideWildcard(const Tokens& hostname) const; | 94 bool IsSubDomainOutsideWildcard(const Tokens& hostname) const; |
| 86 | 95 |
| 87 float CalculateScoreTimePassedSinceExpiry() const; | |
| 88 | |
| 89 static std::vector<Tokens> GetTokenizedDNSNames( | 96 static std::vector<Tokens> GetTokenizedDNSNames( |
| 90 const std::vector<std::string>& dns_names); | 97 const std::vector<std::string>& dns_names); |
| 91 | 98 |
| 92 // If |potential_subdomain| is a subdomain of |parent|, returns the | 99 // If |potential_subdomain| is a subdomain of |parent|, returns the |
| 93 // number of DNS labels by which |potential_subdomain| is under | 100 // number of DNS labels by which |potential_subdomain| is under |
| 94 // |parent|. Otherwise, returns 0. | 101 // |parent|. Otherwise, returns 0. |
| 95 // | 102 // |
| 96 // For example, | 103 // For example, |
| 97 // | 104 // |
| 98 // FindSubDomainDifference(Tokenize("a.b.example.com"), | 105 // FindSubDomainDifference(Tokenize("a.b.example.com"), |
| 99 // Tokenize("example.com")) | 106 // Tokenize("example.com")) |
| 100 // --> 2. | 107 // --> 2. |
| 101 size_t FindSubDomainDifference(const Tokens& potential_subdomain, | 108 size_t FindSubDomainDifference(const Tokens& potential_subdomain, |
| 102 const Tokens& parent) const; | 109 const Tokens& parent) const; |
| 103 | 110 |
| 104 static Tokens Tokenize(const std::string& name); | 111 static Tokens Tokenize(const std::string& name); |
| 105 | 112 |
| 113 float CalculateScoreTimePassedSinceExpiry() const; |
| 114 float CalculateScoreEnvironments() const; |
| 115 |
| 116 // content::NotificationObserver: |
| 117 virtual void Observe( |
| 118 int type, |
| 119 const content::NotificationSource& source, |
| 120 const content::NotificationDetails& details) OVERRIDE; |
| 121 |
| 122 content::WebContents* web_contents_; |
| 106 // This stores the current time. | 123 // This stores the current time. |
| 107 base::Time current_time_; | 124 base::Time current_time_; |
| 108 | |
| 109 const GURL& request_url_; | 125 const GURL& request_url_; |
| 110 | 126 int cert_error_; |
| 111 // This stores the certificate. | 127 // This stores the certificate. |
| 112 const net::X509Certificate& cert_; | 128 const net::X509Certificate& cert_; |
| 129 // Is captive portal detection enabled? |
| 130 bool captive_portal_detection_enabled_; |
| 131 // Did the probe complete before the interstitial was closed? |
| 132 bool captive_portal_probe_completed_; |
| 133 // Did the captive portal probe receive an error or get a non-HTTP response? |
| 134 bool captive_portal_no_response_; |
| 135 // Was a captive portal detected? |
| 136 bool captive_portal_detected_; |
| 137 |
| 138 content::NotificationRegistrar registrar_; |
| 113 }; | 139 }; |
| 114 | 140 |
| 115 #endif // CHROME_BROWSER_SSL_SSL_ERROR_CLASSIFICATION_H_ | 141 #endif // CHROME_BROWSER_SSL_SSL_ERROR_CLASSIFICATION_H_ |
| OLD | NEW |