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(SSLErrorClassification, TestDateInvalidScore); |
| 44 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassification, TestNameMismatch); | |
| 45 FRIEND_TEST_ALL_PREFIXES(SSLErrorClassification, TestValidURL); | |
| 46 | |
| 47 // This method checks whether the URL has a known Top Level Domain or not. | |
|
palmer
2014/07/17 20:11:20
Nit: This function checks hostname strings, not en
radhikabhar
2014/07/18 16:29:29
Done.
| |
| 48 static bool IsNotValidURL(const std::string& host_name); | |
|
palmer
2014/07/17 20:11:20
Naming: The comment does not exactly match the nam
radhikabhar
2014/07/18 16:29:29
Done.
| |
| 49 | |
| 50 // This method checks whether or not the difference between the hostname in | |
| 51 // the given URL and any DNS name given in the CN or SAN fields of the SSL | |
| 52 // certificate is "www.". | |
| 53 bool IsWWWSubDomainMatch() const; | |
| 54 | |
| 55 // This method checks whether or not the hostname in the given URL is a | |
| 56 // subdomain of any DNS name given in the CN or SAN fields of the SSL | |
| 57 // certificate. | |
| 58 bool IsSubDomainMatch() const; | |
| 59 | |
| 60 // This method checks whether any DNS name given in the CN or SAN fields of | |
| 61 // the SSL certificate is a subdomain of the given URL or not. | |
| 62 bool IsSubDomainInverseMatch() const; | |
| 63 | |
| 64 // This method checks whether the hostname is too broad for the scope of a | |
| 65 // wildcard certificate or not. For e.g. it returns true if the host name of | |
| 66 // the URL is "a.b.example.com" and the DNS name in the CN or SAN field of the | |
| 67 // SSL certificate is "*.example.com". But, it retuns false for the hostname | |
| 68 // "b.example.com". | |
| 69 bool IsSubDomainOutsideWildcard() const; | |
| 70 bool IsSelfSigned() const; | |
| 35 | 71 |
| 36 float CalculateScoreTimePassedSinceExpiry() const; | 72 float CalculateScoreTimePassedSinceExpiry() const; |
| 37 | 73 |
| 38 // This stores the current time. | 74 // This stores the current time. |
| 39 base::Time current_time_; | 75 base::Time current_time_; |
| 40 | 76 |
| 77 const GURL& request_url_; | |
| 78 | |
| 41 // This stores the certificate. | 79 // This stores the certificate. |
| 42 const net::X509Certificate& cert_; | 80 const net::X509Certificate& cert_; |
| 43 }; | 81 }; |
| 44 | 82 |
| 45 #endif // CHROME_BROWSER_SSL_SSL_ERROR_CLASSIFICATION_H_ | 83 #endif // CHROME_BROWSER_SSL_SSL_ERROR_CLASSIFICATION_H_ |
| OLD | NEW |