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