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

Side by Side Diff: net/tools/cert_verify_tool/verify_using_path_builder.cc

Issue 2292333002: Add errors per ResultPath for CertPathBuilder. (Closed)
Patch Set: remove error for null trust anchor Created 4 years, 3 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 | « net/cert/internal/path_builder_verify_certificate_chain_unittest.cc ('k') | no next file » | 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 #include "net/tools/cert_verify_tool/verify_using_path_builder.h" 5 #include "net/tools/cert_verify_tool/verify_using_path_builder.h"
6 6
7 #include <iostream> 7 #include <iostream>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "crypto/sha2.h" 12 #include "crypto/sha2.h"
13 #include "net/base/net_errors.h"
14 #include "net/base/test_completion_callback.h" 13 #include "net/base/test_completion_callback.h"
15 #include "net/cert/internal/cert_issuer_source_aia.h" 14 #include "net/cert/internal/cert_issuer_source_aia.h"
16 #include "net/cert/internal/cert_issuer_source_static.h" 15 #include "net/cert/internal/cert_issuer_source_static.h"
17 #include "net/cert/internal/parse_name.h" 16 #include "net/cert/internal/parse_name.h"
18 #include "net/cert/internal/parsed_certificate.h" 17 #include "net/cert/internal/parsed_certificate.h"
19 #include "net/cert/internal/path_builder.h" 18 #include "net/cert/internal/path_builder.h"
20 #include "net/cert/internal/signature_policy.h" 19 #include "net/cert/internal/signature_policy.h"
21 #include "net/cert/internal/trust_store_in_memory.h" 20 #include "net/cert/internal/trust_store_in_memory.h"
22 #include "net/cert_net/cert_net_fetcher_impl.h" 21 #include "net/cert_net/cert_net_fetcher_impl.h"
23 #include "net/tools/cert_verify_tool/cert_verify_tool_util.h" 22 #include "net/tools/cert_verify_tool/cert_verify_tool_util.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // the normalized subject. 106 // the normalized subject.
108 if (trust_anchor->cert()) 107 if (trust_anchor->cert())
109 return SubjectFromParsedCertificate(trust_anchor->cert().get()); 108 return SubjectFromParsedCertificate(trust_anchor->cert().get());
110 109
111 net::RDNSequence parsed_subject; 110 net::RDNSequence parsed_subject;
112 if (!net::ParseNameValue(trust_anchor->normalized_subject(), &parsed_subject)) 111 if (!net::ParseNameValue(trust_anchor->normalized_subject(), &parsed_subject))
113 return std::string(); 112 return std::string();
114 return SubjectToString(parsed_subject); 113 return SubjectToString(parsed_subject);
115 } 114 }
116 115
116 void PrintCertErrors(const net::CertErrors& errors) {
117 // TODO(crbug.com/634443): Include more detailed error information. Also this
118 // should likely be extracted to a common location and used by unit-tests and
119 // other debugging needs.
120 for (const auto& error : errors.errors()) {
121 std::cout << " " << error.type;
122 }
123 }
124
125 // Dumps a ResultPath to std::cout.
126 void PrintResultPath(const net::CertPathBuilder::ResultPath* result_path,
127 size_t index,
128 bool is_best) {
129 std::cout << "path " << index << " "
130 << (result_path->valid ? "valid" : "invalid")
131 << (is_best ? " (best)" : "") << "\n";
132
133 // Print the certificate chain.
134 for (const auto& cert : result_path->path.certs) {
135 std::cout << " " << FingerPrintParsedCertificate(cert.get()) << " "
136 << SubjectFromParsedCertificate(cert.get()) << "\n";
137 }
138
139 // Print the trust anchor (if there was one).
140 const auto& trust_anchor = result_path->path.trust_anchor;
141 if (trust_anchor) {
142 std::string trust_anchor_cert_fingerprint = "<no cert>";
143 if (trust_anchor->cert()) {
144 trust_anchor_cert_fingerprint =
145 FingerPrintParsedCertificate(trust_anchor->cert().get());
146 }
147 std::cout << " " << trust_anchor_cert_fingerprint << " "
148 << SubjectFromTrustAnchor(trust_anchor.get()) << "\n";
149 }
150
151 // Print the errors.
152 if (result_path->errors.errors().empty()) {
153 std::cout << "Errors:\n";
154 PrintCertErrors(result_path->errors);
155 }
156 }
157
117 } // namespace 158 } // namespace
118 159
119 // Verifies |target_der_cert| using CertPathBuilder. 160 // Verifies |target_der_cert| using CertPathBuilder.
120 bool VerifyUsingPathBuilder( 161 bool VerifyUsingPathBuilder(
121 const CertInput& target_der_cert, 162 const CertInput& target_der_cert,
122 const std::vector<CertInput>& intermediate_der_certs, 163 const std::vector<CertInput>& intermediate_der_certs,
123 const std::vector<CertInput>& root_der_certs, 164 const std::vector<CertInput>& root_der_certs,
124 const base::Time at_time, 165 const base::Time at_time,
125 const base::FilePath& dump_prefix_path) { 166 const base::FilePath& dump_prefix_path) {
126 std::cout << "NOTE: CertPathBuilder does not currently use OS trust settings " 167 std::cout << "NOTE: CertPathBuilder does not currently use OS trust settings "
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 231
191 net::TestClosure callback; 232 net::TestClosure callback;
192 net::CompletionStatus rv = path_builder.Run(callback.closure()); 233 net::CompletionStatus rv = path_builder.Run(callback.closure());
193 234
194 if (rv == net::CompletionStatus::ASYNC) { 235 if (rv == net::CompletionStatus::ASYNC) {
195 DVLOG(1) << "waiting for async completion..."; 236 DVLOG(1) << "waiting for async completion...";
196 callback.WaitForResult(); 237 callback.WaitForResult();
197 DVLOG(1) << "async completed."; 238 DVLOG(1) << "async completed.";
198 } 239 }
199 240
200 // TODO(crbug.com/634443): Display the full error information. 241 // TODO(crbug.com/634443): Display any errors/warnings associated with path
201 std::cout << "CertPathBuilder best result: " 242 // building that were not part of a particular
202 << net::ErrorToShortString(result.error()) << "\n"; 243 // PathResult.
244 std::cout << "CertPathBuilder result: "
245 << (result.HasValidPath() ? "SUCCESS" : "FAILURE") << "\n";
203 246
204 for (size_t i = 0; i < result.paths.size(); ++i) { 247 for (size_t i = 0; i < result.paths.size(); ++i) {
205 std::cout << "path " << i << " " 248 PrintResultPath(result.paths[i].get(), i, i == result.best_result_index);
206 << net::ErrorToShortString(result.paths[i]->error)
207 << ((result.best_result_index == i) ? " (best)" : "") << "\n";
208 for (const auto& cert : result.paths[i]->path.certs) {
209 std::cout << " " << FingerPrintParsedCertificate(cert.get()) << " "
210 << SubjectFromParsedCertificate(cert.get()) << "\n";
211 }
212
213 const auto& trust_anchor = result.paths[i]->path.trust_anchor;
214 if (trust_anchor) {
215 std::string trust_anchor_cert_fingerprint = "<no cert>";
216 if (trust_anchor->cert()) {
217 trust_anchor_cert_fingerprint =
218 FingerPrintParsedCertificate(trust_anchor->cert().get());
219 }
220 std::cout << " " << trust_anchor_cert_fingerprint << " "
221 << SubjectFromTrustAnchor(trust_anchor.get()) << "\n";
222 }
223 } 249 }
224 250
225 // TODO(mattm): add flag to dump all paths, not just the final one? 251 // TODO(mattm): add flag to dump all paths, not just the final one?
226 if (!dump_prefix_path.empty() && result.paths.size()) { 252 if (!dump_prefix_path.empty() && result.paths.size()) {
227 if (!DumpParsedCertificateChain( 253 if (!DumpParsedCertificateChain(
228 dump_prefix_path.AddExtension( 254 dump_prefix_path.AddExtension(
229 FILE_PATH_LITERAL(".CertPathBuilder.pem")), 255 FILE_PATH_LITERAL(".CertPathBuilder.pem")),
230 result.paths[result.best_result_index]->path)) { 256 result.paths[result.best_result_index]->path)) {
231 return false; 257 return false;
232 } 258 }
233 } 259 }
234 260
235 return result.error() == net::OK; 261 return result.HasValidPath();
236 } 262 }
OLDNEW
« no previous file with comments | « net/cert/internal/path_builder_verify_certificate_chain_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698