Home | History | Annotate | Download | only in ssl
      1 // Copyright (c) 2011 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 
      5 #ifndef CHROME_BROWSER_SSL_SSL_ERROR_INFO_H_
      6 #define CHROME_BROWSER_SSL_SSL_ERROR_INFO_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/strings/string16.h"
     12 #include "net/cert/cert_status_flags.h"
     13 #include "net/cert/x509_certificate.h"
     14 
     15 class GURL;
     16 
     17 // This class describes an error that happened while showing a page over SSL.
     18 // An SSLErrorInfo object only exists on the UI thread and only contains
     19 // information about an error (type of error and text details).
     20 // Note no DISALLOW_COPY_AND_ASSIGN as we want the copy constructor.
     21 class SSLErrorInfo {
     22  public:
     23   // This enum is being histogrammed; please only add new values at the end.
     24   enum ErrorType {
     25     CERT_COMMON_NAME_INVALID = 0,
     26     CERT_DATE_INVALID,
     27     CERT_AUTHORITY_INVALID,
     28     CERT_CONTAINS_ERRORS,
     29     CERT_NO_REVOCATION_MECHANISM,
     30     CERT_UNABLE_TO_CHECK_REVOCATION,
     31     CERT_REVOKED,
     32     CERT_INVALID,
     33     CERT_WEAK_SIGNATURE_ALGORITHM,
     34     CERT_WEAK_KEY,
     35     UNKNOWN,
     36     END_OF_ENUM
     37   };
     38 
     39   virtual ~SSLErrorInfo();
     40 
     41   // Converts a network error code to an ErrorType.
     42   static ErrorType NetErrorToErrorType(int net_error);
     43 
     44   static SSLErrorInfo CreateError(ErrorType error_type,
     45                                   net::X509Certificate* cert,
     46                                   const GURL& request_url);
     47 
     48   // Populates the specified |errors| vector with the errors contained in
     49   // |cert_status|.  Returns the number of errors found.
     50   // Callers only interested in the error count can pass NULL for |errors|.
     51   // TODO(wtc): Document |cert_id| and |url| arguments.
     52   static int GetErrorsForCertStatus(int cert_id,
     53                                     net::CertStatus cert_status,
     54                                     const GURL& url,
     55                                     std::vector<SSLErrorInfo>* errors);
     56 
     57   // A title describing the error, usually to be used with the details below.
     58   const string16& title() const { return title_; }
     59 
     60   // A description of the error.
     61   const string16& details() const { return details_; }
     62 
     63   // A short message describing the error (1 line).
     64   const string16& short_description() const { return short_description_; }
     65 
     66   // A lengthy explanation of what the error is.  Each entry in the returned
     67   // vector is a paragraph.
     68   const std::vector<string16>& extra_information() const {
     69     return extra_information_;
     70   }
     71 
     72  private:
     73   SSLErrorInfo(const string16& title,
     74                const string16& details,
     75                const string16& short_description,
     76                const std::vector<string16>& extra_info);
     77 
     78   string16 title_;
     79   string16 details_;
     80   string16 short_description_;
     81   // Extra-informations contains paragraphs of text explaining in details what
     82   // the error is and what the risks are.
     83   std::vector<string16> extra_information_;
     84 };
     85 
     86 #endif  // CHROME_BROWSER_SSL_SSL_ERROR_INFO_H_
     87