error_info.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_SSL_ERRORS_ERROR_INFO_H_
  5. #define COMPONENTS_SSL_ERRORS_ERROR_INFO_H_
  6. #include <string>
  7. #include <vector>
  8. #include "net/cert/cert_status_flags.h"
  9. #include "net/cert/x509_certificate.h"
  10. class GURL;
  11. namespace ssl_errors {
  12. // This class describes an error that happened while showing a page over SSL.
  13. // An ErrorInfo object only exists on the UI thread and only contains
  14. // information about an error (type of error and text details).
  15. // Note no DISALLOW_COPY_AND_ASSIGN as we want the copy constructor.
  16. class ErrorInfo {
  17. public:
  18. // This enum is being histogrammed; please only add new values at the end.
  19. enum ErrorType {
  20. CERT_COMMON_NAME_INVALID = 0,
  21. CERT_DATE_INVALID = 1,
  22. CERT_AUTHORITY_INVALID = 2,
  23. CERT_CONTAINS_ERRORS = 3,
  24. CERT_NO_REVOCATION_MECHANISM = 4,
  25. CERT_UNABLE_TO_CHECK_REVOCATION = 5,
  26. CERT_REVOKED = 6,
  27. CERT_INVALID = 7,
  28. CERT_WEAK_SIGNATURE_ALGORITHM = 8,
  29. CERT_WEAK_KEY = 9,
  30. CERT_NAME_CONSTRAINT_VIOLATION = 10,
  31. UNKNOWN = 11,
  32. // CERT_WEAK_KEY_DH = 12,
  33. CERT_PINNED_KEY_MISSING = 13,
  34. CERT_VALIDITY_TOO_LONG = 14,
  35. CERTIFICATE_TRANSPARENCY_REQUIRED = 15,
  36. CERT_SYMANTEC_LEGACY = 16,
  37. CERT_KNOWN_INTERCEPTION_BLOCKED = 17,
  38. LEGACY_TLS = 18,
  39. END_OF_ENUM
  40. };
  41. virtual ~ErrorInfo();
  42. // Converts a network error code to an ErrorType.
  43. static ErrorType NetErrorToErrorType(int net_error);
  44. static ErrorInfo CreateError(ErrorType error_type,
  45. net::X509Certificate* cert,
  46. const GURL& request_url);
  47. // Populates the specified |errors| vector with the errors contained in
  48. // |cert_status| for |cert|. Returns the number of errors found.
  49. // Callers only interested in the error count can pass NULL for |errors|.
  50. static void GetErrorsForCertStatus(
  51. const scoped_refptr<net::X509Certificate>& cert,
  52. net::CertStatus cert_status,
  53. const GURL& url,
  54. std::vector<ErrorInfo>* errors);
  55. // A description of the error.
  56. const std::u16string& details() const { return details_; }
  57. // A short message describing the error (1 line).
  58. const std::u16string& short_description() const { return short_description_; }
  59. private:
  60. ErrorInfo(const std::u16string& details,
  61. const std::u16string& short_description);
  62. std::u16string details_;
  63. std::u16string short_description_;
  64. };
  65. } // namespace ssl_errors
  66. #endif // COMPONENTS_SSL_ERRORS_ERROR_INFO_H_