OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 // ---------------------------- |
| 6 // Overview of error design |
| 7 // ---------------------------- |
| 8 // |
| 9 // Certificate path validation may emit a sequence of errors/warnings. These |
| 10 // are represented by |CertErrors|. |
| 11 // |
| 12 // |CertErrors| is basically just a sequence of errors. The order of the errors |
| 13 // reflects when they were added. |
| 14 // |
| 15 // Each |CertError| has three parts: |
| 16 // |
| 17 // * A unique identifier for the error/warning |
| 18 // - essentially an error code |
| 19 // |
| 20 // * Optional parameters specific to this error type |
| 21 // - May identify relevant DER or OIDs in the certificate |
| 22 // |
| 23 // * Optional context that describes where the error happened |
| 24 // - Which certificate or trust anchor were we processing when the error |
| 25 // was encountered? |
| 26 // |
| 27 |
| 28 #ifndef NET_CERT_INTERNAL_CERT_ERRORS_H_ |
| 29 #define NET_CERT_INTERNAL_CERT_ERRORS_H_ |
| 30 |
| 31 #include <memory> |
| 32 #include <vector> |
| 33 |
| 34 #include "base/compiler_specific.h" |
| 35 #include "base/memory/ref_counted.h" |
| 36 #include "net/base/net_export.h" |
| 37 #include "net/der/input.h" |
| 38 |
| 39 namespace base { |
| 40 class Value; |
| 41 } |
| 42 |
| 43 namespace net { |
| 44 |
| 45 class ParsedCertificate; |
| 46 class TrustAnchor; |
| 47 |
| 48 // Certificate error types are identified by null-terminated C-strings, with |
| 49 // unique pointer values. |
| 50 // |
| 51 // Equality of CertErrorType is done using (pointer) equality and not string |
| 52 // comparison. |
| 53 // |
| 54 // To ensure uniqueness define errors using the macro DEFINE_CERT_ERROR_TYPE(). |
| 55 using CertErrorType = const char*; |
| 56 |
| 57 // TODO(crbug.com/634443): Implement this -- add magic to ensure that storage |
| 58 // of identical strings isn't pool. |
| 59 #define DEFINE_CERT_ERROR_TYPE(name, c_str_literal) \ |
| 60 CertErrorType name = c_str_literal |
| 61 |
| 62 // CertErrorParams is a base class for describing parameters for a particular |
| 63 // CertErrorType. |
| 64 // |
| 65 // Parameters may be used to associate extra information with an error. An |
| 66 // example use for parameters is to identify the OID for an unconsumed critical |
| 67 // extension. |
| 68 class NET_EXPORT CertErrorParams { |
| 69 public: |
| 70 CertErrorParams(); |
| 71 virtual ~CertErrorParams(); |
| 72 |
| 73 // Creates a representation of this parameter as a base::Value, which may be |
| 74 // used for pretty printing the error. |
| 75 virtual std::unique_ptr<base::Value> ToValue() const = 0; |
| 76 |
| 77 // TODO(crbug.com/634443): Add methods access the underlying structure. |
| 78 // ToValue() alone is not a great way to get at the data. |
| 79 |
| 80 private: |
| 81 DISALLOW_COPY_AND_ASSIGN(CertErrorParams); |
| 82 }; |
| 83 |
| 84 // CertError represents a single error during path validation. |
| 85 struct NET_EXPORT CertError { |
| 86 CertError(); |
| 87 CertError(CertError&& other); |
| 88 ~CertError(); |
| 89 |
| 90 // The "type" of the error. This describes the error class -- what is |
| 91 // typically done using an integer error code. |
| 92 CertErrorType type = nullptr; |
| 93 |
| 94 // This describes any parameter relevant to the error. |
| 95 std::unique_ptr<CertErrorParams> params; |
| 96 |
| 97 // TODO(crbug.com/634443): Add context (i.e. associated certificate/trust |
| 98 // anchor). |
| 99 }; |
| 100 |
| 101 class NET_EXPORT CertErrors { |
| 102 public: |
| 103 CertErrors(); |
| 104 ~CertErrors(); |
| 105 |
| 106 void Add(CertErrorType type); |
| 107 |
| 108 void AddWithParam(CertErrorType type, |
| 109 std::unique_ptr<CertErrorParams> params); |
| 110 |
| 111 void AddWith1DerParam(CertErrorType type, const der::Input& der1); |
| 112 void AddWith2DerParams(CertErrorType type, |
| 113 const der::Input& der1, |
| 114 const der::Input& der2); |
| 115 |
| 116 const std::vector<CertError>& errors() const { return errors_; } |
| 117 |
| 118 private: |
| 119 std::vector<CertError> errors_; |
| 120 |
| 121 DISALLOW_COPY_AND_ASSIGN(CertErrors); |
| 122 }; |
| 123 |
| 124 // -------------------------- |
| 125 // Context scopers |
| 126 // -------------------------- |
| 127 |
| 128 // TODO(crbug.com/634443): Implement. |
| 129 class NET_EXPORT ScopedCertErrorsCertContext { |
| 130 public: |
| 131 ScopedCertErrorsCertContext(CertErrors* parent, |
| 132 const ParsedCertificate* cert, |
| 133 size_t i); |
| 134 ~ScopedCertErrorsCertContext(); |
| 135 |
| 136 private: |
| 137 DISALLOW_COPY_AND_ASSIGN(ScopedCertErrorsCertContext); |
| 138 }; |
| 139 |
| 140 // TODO(crbug.com/634443): Implement. |
| 141 class NET_EXPORT ScopedCertErrorsTrustAnchorContext { |
| 142 public: |
| 143 ScopedCertErrorsTrustAnchorContext(CertErrors* parent, |
| 144 const TrustAnchor* trust_anchor); |
| 145 ~ScopedCertErrorsTrustAnchorContext(); |
| 146 |
| 147 private: |
| 148 DISALLOW_COPY_AND_ASSIGN(ScopedCertErrorsTrustAnchorContext); |
| 149 }; |
| 150 |
| 151 // -------------------------- |
| 152 // Error parameters |
| 153 // -------------------------- |
| 154 |
| 155 class NET_EXPORT CertErrorParamsDer1 : public CertErrorParams { |
| 156 public: |
| 157 explicit CertErrorParamsDer1(const der::Input& der1); |
| 158 |
| 159 std::unique_ptr<base::Value> ToValue() const override; |
| 160 |
| 161 private: |
| 162 const std::string der1_; |
| 163 |
| 164 DISALLOW_COPY_AND_ASSIGN(CertErrorParamsDer1); |
| 165 }; |
| 166 |
| 167 class NET_EXPORT CertErrorParamsDer2 : public CertErrorParams { |
| 168 public: |
| 169 CertErrorParamsDer2(const der::Input& der1, const der::Input& der2); |
| 170 |
| 171 std::unique_ptr<base::Value> ToValue() const override; |
| 172 |
| 173 private: |
| 174 const std::string der1_; |
| 175 const std::string der2_; |
| 176 |
| 177 DISALLOW_COPY_AND_ASSIGN(CertErrorParamsDer2); |
| 178 }; |
| 179 |
| 180 } // namespace net |
| 181 |
| 182 #endif // NET_CERT_INTERNAL_CERT_ERRORS_H_ |
OLD | NEW |