Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: net/cert/internal/path_builder.h

Issue 2225493003: Don't treat trust anchors as certificates during path building. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address moar feedback Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/cast_certificate/cast_crl_unittest.cc ('k') | net/cert/internal/path_builder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 NET_CERT_INTERNAL_PATH_BUILDER_H_ 5 #ifndef NET_CERT_INTERNAL_PATH_BUILDER_H_
6 #define NET_CERT_INTERNAL_PATH_BUILDER_H_ 6 #define NET_CERT_INTERNAL_PATH_BUILDER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "net/base/completion_callback.h" 13 #include "net/base/completion_callback.h"
14 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
15 #include "net/base/net_export.h" 15 #include "net/base/net_export.h"
16 #include "net/cert/internal/completion_status.h" 16 #include "net/cert/internal/completion_status.h"
17 #include "net/cert/internal/parsed_certificate.h" 17 #include "net/cert/internal/parsed_certificate.h"
18 #include "net/cert/internal/trust_store.h"
18 #include "net/der/input.h" 19 #include "net/der/input.h"
19 #include "net/der/parse_values.h" 20 #include "net/der/parse_values.h"
20 21
21 namespace net { 22 namespace net {
22 23
23 namespace der { 24 namespace der {
24 struct GeneralizedTime; 25 struct GeneralizedTime;
25 } 26 }
26 27
27 class CertPathIter; 28 class CertPathIter;
28 class CertIssuerSource; 29 class CertIssuerSource;
29 class TrustStore;
30 class SignaturePolicy; 30 class SignaturePolicy;
31 31
32 // CertPath describes a chain of certificates in the "forward" direction.
33 //
34 // By convention:
35 // certs[0] is the target certificate
36 // certs[i] was issued by certs[i+1]
37 // certs.back() was issued by trust_anchor
38 struct NET_EXPORT CertPath {
39 CertPath();
40 ~CertPath();
41
42 scoped_refptr<TrustAnchor> trust_anchor;
43
44 // Path in the forward direction (path[0] is the target cert).
45 ParsedCertificateList certs;
46
47 // Resets the path to empty path (same as if default constructed).
48 void Clear();
49
50 // Returns true if the path is empty.
51 bool IsEmpty() const;
52 };
53
32 // Checks whether a certificate is trusted by building candidate paths to trust 54 // Checks whether a certificate is trusted by building candidate paths to trust
33 // anchors and verifying those paths according to RFC 5280. Each instance of 55 // anchors and verifying those paths according to RFC 5280. Each instance of
34 // CertPathBuilder is used for a single verification. 56 // CertPathBuilder is used for a single verification.
35 // 57 //
36 // WARNING: This implementation is currently experimental. Consult an OWNER 58 // WARNING: This implementation is currently experimental. Consult an OWNER
37 // before using it. 59 // before using it.
38 class NET_EXPORT CertPathBuilder { 60 class NET_EXPORT CertPathBuilder {
39 public: 61 public:
40 // Represents a single candidate path that was built. 62 // Represents a single candidate path that was built.
41 struct NET_EXPORT ResultPath { 63 struct NET_EXPORT ResultPath {
42 ResultPath(); 64 ResultPath();
43 ~ResultPath(); 65 ~ResultPath();
44 66
45 // Returns true if this path was successfully verified. 67 // Returns true if this path was successfully verified.
46 bool is_success() const { return error == OK; } 68 bool is_success() const { return error == OK; }
47 69
48 // The candidate path, in forward direction. 70 // The (possibly partial) certificate path. In the case of an
49 // * path[0] is the target certificate. 71 // error path.trust_anchor may be nullptr.
50 // * path[i+1] is a candidate issuer of path[i]. The subject matches 72 CertPath path;
51 // path[i]'s issuer, but nothing else is guaranteed unless is_success() is
52 // true.
53 // * path[N-1] will be a trust anchor if is_success() is true, otherwise
54 // it may or may not be a trust anchor.
55 ParsedCertificateList path;
56 73
57 // A net error code result of attempting to verify this path. 74 // A net error code result of attempting to verify this path.
58 // TODO(mattm): may want to have an independent result enum, which caller 75 // TODO(mattm): may want to have an independent result enum, which caller
59 // can map to a net error if they want. 76 // can map to a net error if they want.
60 int error = ERR_UNEXPECTED; 77 int error = ERR_UNEXPECTED;
61 }; 78 };
62 79
63 // Provides the overall result of path building. This includes the paths that 80 // Provides the overall result of path building. This includes the paths that
64 // were attempted. 81 // were attempted.
65 struct NET_EXPORT Result { 82 struct NET_EXPORT Result {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 STATE_GET_NEXT_PATH, 155 STATE_GET_NEXT_PATH,
139 STATE_GET_NEXT_PATH_COMPLETE, 156 STATE_GET_NEXT_PATH_COMPLETE,
140 }; 157 };
141 158
142 CompletionStatus DoLoop(bool allow_async); 159 CompletionStatus DoLoop(bool allow_async);
143 160
144 CompletionStatus DoGetNextPath(bool allow_async); 161 CompletionStatus DoGetNextPath(bool allow_async);
145 void HandleGotNextPath(); 162 void HandleGotNextPath();
146 CompletionStatus DoGetNextPathComplete(); 163 CompletionStatus DoGetNextPathComplete();
147 164
148 void AddResultPath(const ParsedCertificateList& path, bool is_success); 165 void AddResultPath(const CertPath& path, bool is_success);
149 166
150 base::Closure callback_; 167 base::Closure callback_;
151 168
152 std::unique_ptr<CertPathIter> cert_path_iter_; 169 std::unique_ptr<CertPathIter> cert_path_iter_;
153 const TrustStore* trust_store_;
154 const SignaturePolicy* signature_policy_; 170 const SignaturePolicy* signature_policy_;
155 const der::GeneralizedTime time_; 171 const der::GeneralizedTime time_;
156 172
157 // Stores the next complete path to attempt verification on. This is filled in 173 // Stores the next complete path to attempt verification on. This is filled in
158 // by |cert_path_iter_| during the STATE_GET_NEXT_PATH step, and thus should 174 // by |cert_path_iter_| during the STATE_GET_NEXT_PATH step, and thus should
159 // only be accessed during the STATE_GET_NEXT_PATH_COMPLETE step. 175 // only be accessed during the STATE_GET_NEXT_PATH_COMPLETE step.
160 // (Will be empty if all paths have been tried, otherwise will be a candidate 176 // (Will be empty if all paths have been tried, otherwise will be a candidate
161 // path starting with the target cert and ending with a trust anchor.) 177 // path starting with the target cert and ending with a
162 ParsedCertificateList next_path_; 178 // certificate issued by trust anchor.)
179 CertPath next_path_;
163 State next_state_; 180 State next_state_;
164 181
165 Result* out_result_; 182 Result* out_result_;
166 183
167 DISALLOW_COPY_AND_ASSIGN(CertPathBuilder); 184 DISALLOW_COPY_AND_ASSIGN(CertPathBuilder);
168 }; 185 };
169 186
170 } // namespace net 187 } // namespace net
171 188
172 #endif // NET_CERT_INTERNAL_PATH_BUILDER_H_ 189 #endif // NET_CERT_INTERNAL_PATH_BUILDER_H_
OLDNEW
« no previous file with comments | « components/cast_certificate/cast_crl_unittest.cc ('k') | net/cert/internal/path_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698