Chromium Code Reviews| 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/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" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 if (!net::ParseNameValue(trust_anchor->normalized_subject(), &parsed_subject)) | 111 if (!net::ParseNameValue(trust_anchor->normalized_subject(), &parsed_subject)) |
| 112 return std::string(); | 112 return std::string(); |
| 113 return SubjectToString(parsed_subject); | 113 return SubjectToString(parsed_subject); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void PrintCertErrors(const net::CertErrors& errors) { | 116 void PrintCertErrors(const net::CertErrors& errors) { |
| 117 // TODO(crbug.com/634443): Include more detailed error information. Also this | 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 | 118 // should likely be extracted to a common location and used by unit-tests and |
| 119 // other debugging needs. | 119 // other debugging needs. |
| 120 for (const auto& error : errors.errors()) { | 120 for (const auto& error : errors.errors()) { |
| 121 std::cout << " " << error.type; | 121 std::cout << " " << error.type << "\n"; |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 // Dumps a ResultPath to std::cout. | 125 // Dumps a ResultPath to std::cout. |
| 126 void PrintResultPath(const net::CertPathBuilder::ResultPath* result_path, | 126 void PrintResultPath(const net::CertPathBuilder::ResultPath* result_path, |
| 127 size_t index, | 127 size_t index, |
| 128 bool is_best) { | 128 bool is_best) { |
| 129 std::cout << "path " << index << " " | 129 std::cout << "path " << index << " " |
| 130 << (result_path->valid ? "valid" : "invalid") | 130 << (result_path->valid ? "valid" : "invalid") |
| 131 << (is_best ? " (best)" : "") << "\n"; | 131 << (is_best ? " (best)" : "") << "\n"; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 142 std::string trust_anchor_cert_fingerprint = "<no cert>"; | 142 std::string trust_anchor_cert_fingerprint = "<no cert>"; |
| 143 if (trust_anchor->cert()) { | 143 if (trust_anchor->cert()) { |
| 144 trust_anchor_cert_fingerprint = | 144 trust_anchor_cert_fingerprint = |
| 145 FingerPrintParsedCertificate(trust_anchor->cert().get()); | 145 FingerPrintParsedCertificate(trust_anchor->cert().get()); |
| 146 } | 146 } |
| 147 std::cout << " " << trust_anchor_cert_fingerprint << " " | 147 std::cout << " " << trust_anchor_cert_fingerprint << " " |
| 148 << SubjectFromTrustAnchor(trust_anchor.get()) << "\n"; | 148 << SubjectFromTrustAnchor(trust_anchor.get()) << "\n"; |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Print the errors. | 151 // Print the errors. |
| 152 if (result_path->errors.errors().empty()) { | 152 if (!result_path->errors.errors().empty()) { |
|
eroman
2016/09/02 21:32:28
Oops!
Clearly I didn't even test this when I wrot
| |
| 153 std::cout << "Errors:\n"; | 153 std::cout << "Errors:\n"; |
| 154 PrintCertErrors(result_path->errors); | 154 PrintCertErrors(result_path->errors); |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| 158 } // namespace | 158 } // namespace |
| 159 | 159 |
| 160 // Verifies |target_der_cert| using CertPathBuilder. | 160 // Verifies |target_der_cert| using CertPathBuilder. |
| 161 bool VerifyUsingPathBuilder( | 161 bool VerifyUsingPathBuilder( |
| 162 const CertInput& target_der_cert, | 162 const CertInput& target_der_cert, |
| 163 const std::vector<CertInput>& intermediate_der_certs, | 163 const std::vector<CertInput>& intermediate_der_certs, |
| 164 const std::vector<CertInput>& root_der_certs, | 164 const std::vector<CertInput>& root_der_certs, |
| 165 const base::Time at_time, | 165 const base::Time at_time, |
| 166 const base::FilePath& dump_prefix_path) { | 166 const base::FilePath& dump_prefix_path) { |
| 167 std::cout << "NOTE: CertPathBuilder does not currently use OS trust settings " | |
| 168 "(--roots must be specified).\n"; | |
| 169 std::cerr << "WARNING: --hostname is not yet verified with CertPathBuilder\n"; | |
| 170 | |
| 171 base::Time::Exploded exploded_time; | 167 base::Time::Exploded exploded_time; |
| 172 at_time.UTCExplode(&exploded_time); | 168 at_time.UTCExplode(&exploded_time); |
| 173 net::der::GeneralizedTime time = ConvertExplodedTime(exploded_time); | 169 net::der::GeneralizedTime time = ConvertExplodedTime(exploded_time); |
| 174 | 170 |
| 175 net::TrustStoreInMemory trust_store; | 171 net::TrustStoreInMemory trust_store; |
| 176 for (const auto& der_cert : root_der_certs) { | 172 for (const auto& der_cert : root_der_certs) { |
| 177 scoped_refptr<net::ParsedCertificate> cert = | 173 scoped_refptr<net::ParsedCertificate> cert = |
| 178 net::ParsedCertificate::CreateFromCertificateCopy(der_cert.der_cert, | 174 net::ParsedCertificate::CreateFromCertificateCopy(der_cert.der_cert, |
| 179 {}); | 175 {}); |
| 180 if (!cert) | 176 if (!cert) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 if (!DumpParsedCertificateChain( | 249 if (!DumpParsedCertificateChain( |
| 254 dump_prefix_path.AddExtension( | 250 dump_prefix_path.AddExtension( |
| 255 FILE_PATH_LITERAL(".CertPathBuilder.pem")), | 251 FILE_PATH_LITERAL(".CertPathBuilder.pem")), |
| 256 result.paths[result.best_result_index]->path)) { | 252 result.paths[result.best_result_index]->path)) { |
| 257 return false; | 253 return false; |
| 258 } | 254 } |
| 259 } | 255 } |
| 260 | 256 |
| 261 return result.HasValidPath(); | 257 return result.HasValidPath(); |
| 262 } | 258 } |
| OLD | NEW |