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 #ifndef NET_CERT_INTERNAL_PATH_BUILDER_H_ | |
6 #define NET_CERT_INTERNAL_PATH_BUILDER_H_ | |
7 | |
8 #include <memory> | |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "base/callback.h" | |
13 #include "net/base/completion_callback.h" | |
14 #include "net/base/net_errors.h" | |
15 #include "net/base/net_export.h" | |
16 #include "net/cert/internal/completion_status.h" | |
17 #include "net/der/input.h" | |
18 #include "net/der/parse_values.h" | |
19 | |
20 namespace net { | |
21 | |
22 namespace der { | |
23 struct GeneralizedTime; | |
24 } | |
25 | |
26 class CertPathIter; | |
27 class CertIssuerSource; | |
28 class ParsedCertificate; | |
29 class TrustStore; | |
30 class SignaturePolicy; | |
31 | |
32 class NET_EXPORT CertPathBuilder { | |
eroman
2016/06/17 01:03:22
Please provide some documentation on the role of t
mattm
2016/06/18 04:28:56
Done.
| |
33 public: | |
34 struct NET_EXPORT ResultPath { | |
eroman
2016/06/17 01:03:22
Please document
mattm
2016/06/18 04:28:56
Done.
| |
35 ResultPath(); | |
36 ~ResultPath(); | |
37 | |
38 std::vector<scoped_refptr<ParsedCertificate>> path; | |
eroman
2016/06/17 01:03:23
Please document order, and where the target certif
mattm
2016/06/18 04:28:56
Done.
| |
39 int rv; | |
eroman
2016/06/17 01:03:23
Please document the domain of this error.
mattm
2016/06/18 04:28:56
Done.
| |
40 }; | |
41 | |
42 struct NET_EXPORT Result { | |
43 Result(); | |
44 ~Result(); | |
45 | |
46 // Returns the overall result. | |
47 int result() { | |
eroman
2016/06/17 01:03:23
const?
mattm
2016/06/18 04:28:56
Done.
| |
48 if (paths.empty()) | |
eroman
2016/06/17 01:03:23
Would it be worthwhile to instead use:
if (best_r
mattm
2016/06/18 04:28:56
My thought was it's a bug if paths is not empty bu
| |
49 return ERR_CERT_AUTHORITY_INVALID; | |
50 return paths[best_result_index]->rv; | |
51 } | |
52 | |
53 // List of paths that were attempted and the result for each. | |
54 std::vector<std::unique_ptr<ResultPath>> paths; | |
55 // Index into |paths|. Before use, |paths.empty()| must be checked. | |
eroman
2016/06/17 01:03:22
or should the recommendation be best_result_index
| |
56 size_t best_result_index = 0; | |
57 | |
58 private: | |
59 DISALLOW_COPY_AND_ASSIGN(Result); | |
60 }; | |
61 | |
62 // TODO(mattm): allow caller specified hook/callback to extend path | |
63 // verification. | |
64 // | |
65 // Creates a CertPathBuilder that attempts to find a path from |cert| to a | |
66 // trust anchor in |trust_store|, which satisfies |signature_policy| and is | |
67 // valid at |time|. Details of attempted path(s) are stored in |*result|. | |
68 // | |
69 // The caller must keep |trust_store|, |signature_policy|, and |*result| valid | |
70 // for the lifetime of the CertPathBuilder. | |
71 CertPathBuilder(scoped_refptr<ParsedCertificate> cert, | |
72 const TrustStore* trust_store, | |
73 const SignaturePolicy* signature_policy, | |
74 const der::GeneralizedTime& time, | |
75 Result* result); | |
76 ~CertPathBuilder(); | |
77 | |
78 // Adds a CertIssuerSource to provide intermediates for use in path building. | |
79 // Multiple sources may be added. Must not be called after Run is called. If | |
80 // no sources are added, the target cert will only verify if it is a trust | |
81 // anchor or is directly signed by a trust anchor. The |*cert_issuer_source| | |
82 // must remain valid for the lifetime of the CertPathBuilder. | |
83 void AddCertIssuerSource(CertIssuerSource* cert_issuer_source); | |
eroman
2016/06/17 01:03:22
todo: interface is a bit squirly (destruction, com
mattm
2016/06/18 04:28:56
Is this a leftover comment? since AddCertIssuerSou
eroman
2016/06/20 19:54:19
Yes sorry, disregard this.
I was a TODO for mysel
| |
84 | |
85 // Begins verification of |cert|. If the return value is SYNC then the | |
eroman
2016/06/17 01:03:23
nit: It is unclear what |cert| is here (it was the
mattm
2016/06/18 04:28:56
Done.
| |
86 // verification is complete and the |result| value can be inspected for the | |
87 // status, and |callback| will not be called. | |
88 // If the return value is ASYNC, the |callback| will be called asynchronously | |
89 // once the verification is complete. |result| should not be examined or | |
90 // modified until the |callback| is run. | |
91 // If |callback| is null, verification always completes synchronously, even if | |
92 // it fails to find a valid path and one could have been found asynchronously. | |
93 CompletionStatus Run(const base::Closure& callback); | |
eroman
2016/06/17 01:03:22
Please also mention somewhere:
* The cancellatio
mattm
2016/06/18 04:28:56
Done.
| |
94 | |
95 private: | |
96 enum State { | |
97 STATE_NONE, | |
98 STATE_GET_NEXT_PATH, | |
99 STATE_GET_NEXT_PATH_COMPLETE, | |
100 }; | |
101 | |
102 CompletionStatus DoLoop(bool allow_async); | |
103 | |
104 CompletionStatus DoGetNextPath(bool allow_async); | |
105 void HandleGotNextPath(); | |
106 CompletionStatus DoGetNextPathComplete(); | |
107 | |
108 void AddResultPath(const std::vector<scoped_refptr<ParsedCertificate>>& path, | |
109 bool result); | |
110 | |
111 base::Closure callback_; | |
112 | |
113 std::unique_ptr<CertPathIter> cert_path_iter_; | |
114 const TrustStore* trust_store_; | |
115 const SignaturePolicy* signature_policy_; | |
116 const der::GeneralizedTime time_; | |
117 | |
118 std::vector<scoped_refptr<ParsedCertificate>> next_path_; | |
119 State next_state_; | |
120 | |
121 Result* out_result_; | |
122 | |
123 DISALLOW_COPY_AND_ASSIGN(CertPathBuilder); | |
124 }; | |
125 | |
126 } // namespace net | |
127 | |
128 #endif // NET_CERT_INTERNAL_PATH_BUILDER_H_ | |
OLD | NEW |