| 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" |
| 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" | 13 #include "net/base/net_errors.h" |
| 14 #include "net/base/test_completion_callback.h" | 14 #include "net/base/test_completion_callback.h" |
| 15 #include "net/cert/internal/cert_issuer_source_aia.h" | 15 #include "net/cert/internal/cert_issuer_source_aia.h" |
| 16 #include "net/cert/internal/cert_issuer_source_static.h" | 16 #include "net/cert/internal/cert_issuer_source_static.h" |
| 17 #include "net/cert/internal/parse_name.h" | 17 #include "net/cert/internal/parse_name.h" |
| 18 #include "net/cert/internal/parsed_certificate.h" | 18 #include "net/cert/internal/parsed_certificate.h" |
| 19 #include "net/cert/internal/path_builder.h" | 19 #include "net/cert/internal/path_builder.h" |
| 20 #include "net/cert/internal/signature_policy.h" | 20 #include "net/cert/internal/signature_policy.h" |
| 21 #include "net/cert/internal/trust_store_collection.h" |
| 21 #include "net/cert/internal/trust_store_in_memory.h" | 22 #include "net/cert/internal/trust_store_in_memory.h" |
| 22 #include "net/cert_net/cert_net_fetcher_impl.h" | 23 #include "net/cert_net/cert_net_fetcher_impl.h" |
| 23 #include "net/tools/cert_verify_tool/cert_verify_tool_util.h" | 24 #include "net/tools/cert_verify_tool/cert_verify_tool_util.h" |
| 24 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
| 25 #include "net/url_request/url_request_context_builder.h" | 26 #include "net/url_request/url_request_context_builder.h" |
| 26 | 27 |
| 28 // XXX should it be defined(OS_LINUX) || defined(OS_CHROMEOS) ? |
| 29 #if defined(USE_NSS_CERTS) |
| 30 #include "base/threading/thread_task_runner_handle.h" |
| 31 #include "net/cert/internal/trust_store_nss.h" |
| 32 #endif |
| 33 |
| 27 #if defined(OS_LINUX) | 34 #if defined(OS_LINUX) |
| 28 #include "net/proxy/proxy_config.h" | 35 #include "net/proxy/proxy_config.h" |
| 29 #include "net/proxy/proxy_config_service_fixed.h" | 36 #include "net/proxy/proxy_config_service_fixed.h" |
| 30 #endif | 37 #endif |
| 31 | 38 |
| 32 namespace { | 39 namespace { |
| 33 | 40 |
| 34 std::string GetUserAgent() { | 41 std::string GetUserAgent() { |
| 35 return "cert_verify_tool/0.1"; | 42 return "cert_verify_tool/0.1"; |
| 36 } | 43 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 123 |
| 117 } // namespace | 124 } // namespace |
| 118 | 125 |
| 119 // Verifies |target_der_cert| using CertPathBuilder. | 126 // Verifies |target_der_cert| using CertPathBuilder. |
| 120 bool VerifyUsingPathBuilder( | 127 bool VerifyUsingPathBuilder( |
| 121 const CertInput& target_der_cert, | 128 const CertInput& target_der_cert, |
| 122 const std::vector<CertInput>& intermediate_der_certs, | 129 const std::vector<CertInput>& intermediate_der_certs, |
| 123 const std::vector<CertInput>& root_der_certs, | 130 const std::vector<CertInput>& root_der_certs, |
| 124 const base::Time at_time, | 131 const base::Time at_time, |
| 125 const base::FilePath& dump_prefix_path) { | 132 const base::FilePath& dump_prefix_path) { |
| 126 std::cout << "NOTE: CertPathBuilder does not currently use OS trust settings " | |
| 127 "(--roots must be specified).\n"; | |
| 128 std::cerr << "WARNING: --hostname is not yet verified with CertPathBuilder\n"; | 133 std::cerr << "WARNING: --hostname is not yet verified with CertPathBuilder\n"; |
| 129 | 134 |
| 130 base::Time::Exploded exploded_time; | 135 base::Time::Exploded exploded_time; |
| 131 at_time.UTCExplode(&exploded_time); | 136 at_time.UTCExplode(&exploded_time); |
| 132 net::der::GeneralizedTime time = ConvertExplodedTime(exploded_time); | 137 net::der::GeneralizedTime time = ConvertExplodedTime(exploded_time); |
| 133 | 138 |
| 134 net::TrustStoreInMemory trust_store; | 139 net::TrustStoreCollection trust_store; |
| 140 |
| 141 net::TrustStoreInMemory trust_store_in_memory; |
| 142 trust_store.AddTrustStoreSynchronousOnly(&trust_store_in_memory); |
| 135 for (const auto& der_cert : root_der_certs) { | 143 for (const auto& der_cert : root_der_certs) { |
| 136 scoped_refptr<net::ParsedCertificate> cert = | 144 scoped_refptr<net::ParsedCertificate> cert = |
| 137 net::ParsedCertificate::CreateFromCertificateCopy(der_cert.der_cert, | 145 net::ParsedCertificate::CreateFromCertificateCopy(der_cert.der_cert, |
| 138 {}); | 146 {}); |
| 139 if (!cert) | 147 if (!cert) |
| 140 PrintCertError("ERROR: ParsedCertificate failed:", der_cert); | 148 PrintCertError("ERROR: ParsedCertificate failed:", der_cert); |
| 141 else { | 149 else { |
| 142 trust_store.AddTrustAnchor( | 150 trust_store_in_memory.AddTrustAnchor( |
| 143 net::TrustAnchor::CreateFromCertificateNoConstraints(cert)); | 151 net::TrustAnchor::CreateFromCertificateNoConstraints(cert)); |
| 144 } | 152 } |
| 145 } | 153 } |
| 146 | 154 |
| 155 #if defined(USE_NSS_CERTS) |
| 156 net::TrustStoreNSS trust_store_nss(base::ThreadTaskRunnerHandle::Get()); |
| 157 trust_store.SetPrimaryTrustStore(&trust_store_nss); |
| 158 #else |
| 159 std::cout << "NOTE: CertPathBuilder does not currently use OS trust settings " |
| 160 "(--roots must be specified).\n"; |
| 161 #endif |
| 162 |
| 147 net::CertIssuerSourceStatic intermediate_cert_issuer_source; | 163 net::CertIssuerSourceStatic intermediate_cert_issuer_source; |
| 148 for (const auto& der_cert : intermediate_der_certs) { | 164 for (const auto& der_cert : intermediate_der_certs) { |
| 149 scoped_refptr<net::ParsedCertificate> cert = | 165 scoped_refptr<net::ParsedCertificate> cert = |
| 150 net::ParsedCertificate::CreateFromCertificateCopy(der_cert.der_cert, | 166 net::ParsedCertificate::CreateFromCertificateCopy(der_cert.der_cert, |
| 151 {}); | 167 {}); |
| 152 if (!cert) | 168 if (!cert) |
| 153 PrintCertError("ERROR: ParsedCertificate failed:", der_cert); | 169 PrintCertError("ERROR: ParsedCertificate failed:", der_cert); |
| 154 else | 170 else |
| 155 intermediate_cert_issuer_source.AddCert(cert); | 171 intermediate_cert_issuer_source.AddCert(cert); |
| 156 } | 172 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 if (!DumpParsedCertificateChain( | 242 if (!DumpParsedCertificateChain( |
| 227 dump_prefix_path.AddExtension( | 243 dump_prefix_path.AddExtension( |
| 228 FILE_PATH_LITERAL(".CertPathBuilder.pem")), | 244 FILE_PATH_LITERAL(".CertPathBuilder.pem")), |
| 229 result.paths[result.best_result_index]->path)) { | 245 result.paths[result.best_result_index]->path)) { |
| 230 return false; | 246 return false; |
| 231 } | 247 } |
| 232 } | 248 } |
| 233 | 249 |
| 234 return result.error() == net::OK; | 250 return result.error() == net::OK; |
| 235 } | 251 } |
| OLD | NEW |