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

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: fix components_unittests compile (hopefully) 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
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
70 // The trust anchor found for this path. May be nullptr if !is_success()
71 // and the path did not chain up to an anchor.
48 // The candidate path, in forward direction. 72 // The candidate path, in forward direction.
49 // * path[0] is the target certificate. 73 // * path[0] is the target certificate.
50 // * path[i+1] is a candidate issuer of path[i]. The subject matches 74 // * path[i+1] is a candidate issuer of path[i]. The subject matches
51 // path[i]'s issuer, but nothing else is guaranteed unless is_success() is 75 // path[i]'s issuer, but nothing else is guaranteed unless is_success() is
52 // true. 76 // true.
53 // * path[N-1] will be a trust anchor if is_success() is true, otherwise 77 CertPath path;
54 // it may or may not be a trust anchor.
55 ParsedCertificateList path;
56 78
57 // A net error code result of attempting to verify this path. 79 // A net error code result of attempting to verify this path.
58 // TODO(mattm): may want to have an independent result enum, which caller 80 // TODO(mattm): may want to have an independent result enum, which caller
59 // can map to a net error if they want. 81 // can map to a net error if they want.
60 int error = ERR_UNEXPECTED; 82 int error = ERR_UNEXPECTED;
61 }; 83 };
62 84
63 // Provides the overall result of path building. This includes the paths that 85 // Provides the overall result of path building. This includes the paths that
64 // were attempted. 86 // were attempted.
65 struct NET_EXPORT Result { 87 struct NET_EXPORT Result {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 STATE_GET_NEXT_PATH, 160 STATE_GET_NEXT_PATH,
139 STATE_GET_NEXT_PATH_COMPLETE, 161 STATE_GET_NEXT_PATH_COMPLETE,
140 }; 162 };
141 163
142 CompletionStatus DoLoop(bool allow_async); 164 CompletionStatus DoLoop(bool allow_async);
143 165
144 CompletionStatus DoGetNextPath(bool allow_async); 166 CompletionStatus DoGetNextPath(bool allow_async);
145 void HandleGotNextPath(); 167 void HandleGotNextPath();
146 CompletionStatus DoGetNextPathComplete(); 168 CompletionStatus DoGetNextPathComplete();
147 169
148 void AddResultPath(const ParsedCertificateList& path, bool is_success); 170 void AddResultPath(const CertPath& path, bool is_success);
149 171
150 base::Closure callback_; 172 base::Closure callback_;
151 173
152 std::unique_ptr<CertPathIter> cert_path_iter_; 174 std::unique_ptr<CertPathIter> cert_path_iter_;
153 const TrustStore* trust_store_;
154 const SignaturePolicy* signature_policy_; 175 const SignaturePolicy* signature_policy_;
155 const der::GeneralizedTime time_; 176 const der::GeneralizedTime time_;
156 177
157 // Stores the next complete path to attempt verification on. This is filled in 178 // 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 179 // 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. 180 // 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 181 // (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.) 182 // path starting with the target cert and ending with a
162 ParsedCertificateList next_path_; 183 // certificate issued by trust anchor.)
184 CertPath next_path_;
163 State next_state_; 185 State next_state_;
164 186
165 Result* out_result_; 187 Result* out_result_;
166 188
167 DISALLOW_COPY_AND_ASSIGN(CertPathBuilder); 189 DISALLOW_COPY_AND_ASSIGN(CertPathBuilder);
168 }; 190 };
169 191
170 } // namespace net 192 } // namespace net
171 193
172 #endif // NET_CERT_INTERNAL_PATH_BUILDER_H_ 194 #endif // NET_CERT_INTERNAL_PATH_BUILDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698