OLD | NEW |
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 #include "net/cert/internal/path_builder.h" | 5 #include "net/cert/internal/path_builder.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <unordered_set> | 8 #include <unordered_set> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 void GetNextIssuer(CertificateOrTrustAnchor* out); | 75 void GetNextIssuer(CertificateOrTrustAnchor* out); |
76 | 76 |
77 // Returns the |cert| for which issuers are being retrieved. | 77 // Returns the |cert| for which issuers are being retrieved. |
78 const ParsedCertificate* cert() const { return cert_.get(); } | 78 const ParsedCertificate* cert() const { return cert_.get(); } |
79 scoped_refptr<ParsedCertificate> reference_cert() const { return cert_; } | 79 scoped_refptr<ParsedCertificate> reference_cert() const { return cert_; } |
80 | 80 |
81 private: | 81 private: |
82 void AddIssuers(ParsedCertificateList issuers); | 82 void AddIssuers(ParsedCertificateList issuers); |
83 void DoAsyncIssuerQuery(); | 83 void DoAsyncIssuerQuery(); |
84 | 84 |
| 85 // Returns true if |issuers_| contains unconsumed certificates. |
| 86 bool HasCurrentIssuer() const { return cur_issuer_ < issuers_.size(); } |
| 87 |
85 scoped_refptr<ParsedCertificate> cert_; | 88 scoped_refptr<ParsedCertificate> cert_; |
86 CertIssuerSources* cert_issuer_sources_; | 89 CertIssuerSources* cert_issuer_sources_; |
87 const TrustStore* trust_store_; | 90 const TrustStore* trust_store_; |
88 | 91 |
89 // The list of trust anchors that match the issuer name for |cert_|. | 92 // The list of trust anchors that match the issuer name for |cert_|. |
90 TrustAnchors anchors_; | 93 TrustAnchors anchors_; |
91 // The index of the next trust anchor in |anchors_| to return. | 94 // The index of the next trust anchor in |anchors_| to return. |
92 size_t cur_anchor_ = 0; | 95 size_t cur_anchor_ = 0; |
93 | 96 |
94 // The list of issuers for |cert_|. This is added to incrementally (first | 97 // The list of issuers for |cert_|. This is added to incrementally (first |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 if (cur_anchor_ < anchors_.size()) { | 156 if (cur_anchor_ < anchors_.size()) { |
154 DVLOG(1) << "CertIssuersIter(" << CertDebugString(cert()) | 157 DVLOG(1) << "CertIssuersIter(" << CertDebugString(cert()) |
155 << "): returning anchor " << cur_anchor_ << " of " | 158 << "): returning anchor " << cur_anchor_ << " of " |
156 << anchors_.size(); | 159 << anchors_.size(); |
157 // Still have anchors that haven't been returned yet, return one of them. | 160 // Still have anchors that haven't been returned yet, return one of them. |
158 *out = CertificateOrTrustAnchor(anchors_[cur_anchor_++]); | 161 *out = CertificateOrTrustAnchor(anchors_[cur_anchor_++]); |
159 return; | 162 return; |
160 } | 163 } |
161 | 164 |
162 // If there aren't any issuers left, block until async results are ready. | 165 // If there aren't any issuers left, block until async results are ready. |
163 if (cur_issuer_ >= issuers_.size()) { | 166 if (!HasCurrentIssuer()) { |
164 if (!did_async_issuer_query_) { | 167 if (!did_async_issuer_query_) { |
165 // Now issue request(s) for async ones (AIA, etc). | 168 // Now issue request(s) for async ones (AIA, etc). |
166 DoAsyncIssuerQuery(); | 169 DoAsyncIssuerQuery(); |
167 } | 170 } |
168 | 171 |
169 // TODO(eroman): Rather than blocking on the async requests in FIFO order, | 172 // TODO(eroman): Rather than blocking on the async requests in FIFO order, |
170 // consume in the order they become ready. | 173 // consume in the order they become ready. |
171 while (cur_async_request_ < pending_async_requests_.size()) { | 174 while (!HasCurrentIssuer() && |
| 175 cur_async_request_ < pending_async_requests_.size()) { |
172 ParsedCertificateList new_issuers; | 176 ParsedCertificateList new_issuers; |
173 pending_async_requests_[cur_async_request_]->GetNext(&new_issuers); | 177 pending_async_requests_[cur_async_request_]->GetNext(&new_issuers); |
174 if (new_issuers.empty()) { | 178 if (new_issuers.empty()) { |
175 // Request is exhausted, no more results pending from that | 179 // Request is exhausted, no more results pending from that |
176 // CertIssuerSource. | 180 // CertIssuerSource. |
177 pending_async_requests_[cur_async_request_++].reset(); | 181 pending_async_requests_[cur_async_request_++].reset(); |
178 continue; | 182 } else { |
| 183 AddIssuers(std::move(new_issuers)); |
179 } | 184 } |
180 | |
181 AddIssuers(std::move(new_issuers)); | |
182 break; | |
183 } | 185 } |
184 } | 186 } |
185 | 187 |
186 if (cur_issuer_ < issuers_.size()) { | 188 if (HasCurrentIssuer()) { |
187 DVLOG(1) << "CertIssuersIter(" << CertDebugString(cert()) | 189 DVLOG(1) << "CertIssuersIter(" << CertDebugString(cert()) |
188 << "): returning issuer " << cur_issuer_ << " of " | 190 << "): returning issuer " << cur_issuer_ << " of " |
189 << issuers_.size(); | 191 << issuers_.size(); |
190 // Still have issuers that haven't been returned yet, return one of them. | 192 // Still have issuers that haven't been returned yet, return one of them. |
191 // A reference to the returned issuer is retained, since |present_issuers_| | 193 // A reference to the returned issuer is retained, since |present_issuers_| |
192 // points to data owned by it. | 194 // points to data owned by it. |
193 *out = CertificateOrTrustAnchor(issuers_[cur_issuer_++]); | 195 *out = CertificateOrTrustAnchor(issuers_[cur_issuer_++]); |
194 return; | 196 return; |
195 } | 197 } |
196 | 198 |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 | 559 |
558 void CertPathBuilder::AddResultPath(std::unique_ptr<ResultPath> result_path) { | 560 void CertPathBuilder::AddResultPath(std::unique_ptr<ResultPath> result_path) { |
559 // TODO(mattm): set best_result_index based on number or severity of errors. | 561 // TODO(mattm): set best_result_index based on number or severity of errors. |
560 if (result_path->valid) | 562 if (result_path->valid) |
561 out_result_->best_result_index = out_result_->paths.size(); | 563 out_result_->best_result_index = out_result_->paths.size(); |
562 // TODO(mattm): add flag to only return a single path or all attempted paths? | 564 // TODO(mattm): add flag to only return a single path or all attempted paths? |
563 out_result_->paths.push_back(std::move(result_path)); | 565 out_result_->paths.push_back(std::move(result_path)); |
564 } | 566 } |
565 | 567 |
566 } // namespace net | 568 } // namespace net |
OLD | NEW |