Home | History | Annotate | Download | only in ssl
      1 // Copyright (c) 2010 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 #pragma once
      8 
      9 #include <string>
     10 #include <vector>
     11 
     12 #include "base/string16.h"
     13 #include "net/base/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   enum ErrorType {
     24     CERT_COMMON_NAME_INVALID = 0,
     25     CERT_DATE_INVALID,
     26     CERT_AUTHORITY_INVALID,
     27     CERT_CONTAINS_ERRORS,
     28     CERT_NO_REVOCATION_MECHANISM,
     29     CERT_UNABLE_TO_CHECK_REVOCATION,
     30     CERT_REVOKED,
     31     CERT_INVALID,
     32     CERT_WEAK_SIGNATURE_ALGORITHM,
     33     CERT_NOT_IN_DNS,
     34     UNKNOWN
     35   };
     36 
     37   virtual ~SSLErrorInfo();
     38 
     39   // Converts a network error code to an ErrorType.
     40   static ErrorType NetErrorToErrorType(int net_error);
     41 
     42   static SSLErrorInfo CreateError(ErrorType error_type,
     43                                   net::X509Certificate* cert,
     44                                   const GURL& request_url);
     45 
     46   // Populates the specified |errors| vector with the errors contained in
     47   // |cert_status|.  Returns the number of errors found.
     48   // Callers only interested in the error count can pass NULL for |errors|.
     49   static int GetErrorsForCertStatus(int cert_status,
     50                                     int cert_id,
     51                                     const GURL& request_url,
     52                                     std::vector<SSLErrorInfo>* errors);
     53 
     54   // A title describing the error, usually to be used with the details below.
     55   const string16& title() const { return title_; }
     56 
     57   // A description of the error.
     58   const string16& details() const { return details_; }
     59 
     60   // A short message describing the error (1 line).
     61   const string16& short_description() const { return short_description_; }
     62 
     63   // A lengthy explanation of what the error is.  Each entry in the returned
     64   // vector is a paragraph.
     65   const std::vector<string16>& extra_information() const {
     66     return extra_information_;
     67   }
     68 
     69  private:
     70   SSLErrorInfo(const string16& title,
     71                const string16& details,
     72                const string16& short_description,
     73                const std::vector<string16>& extra_info);
     74 
     75   string16 title_;
     76   string16 details_;
     77   string16 short_description_;
     78   // Extra-informations contains paragraphs of text explaining in details what
     79   // the error is and what the risks are.
     80   std::vector<string16> extra_information_;
     81 };
     82 
     83 #endif  // CHROME_BROWSER_SSL_SSL_ERROR_INFO_H_
     84