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

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

Issue 2126803004: WIP: NSS trust store integration for path builder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cert-command-line-path-builder-add_certpathbuilder
Patch Set: . Created 4 years, 4 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/net.gypi ('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" 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.h" 21 #include "net/cert/internal/trust_store_static.h"
22 #include "net/cert_net/cert_net_fetcher_impl.h" 22 #include "net/cert_net/cert_net_fetcher_impl.h"
23 #include "net/tools/cert_verify_tool/cert_verify_tool_util.h" 23 #include "net/tools/cert_verify_tool/cert_verify_tool_util.h"
24 #include "net/url_request/url_request_context.h" 24 #include "net/url_request/url_request_context.h"
25 #include "net/url_request/url_request_context_builder.h" 25 #include "net/url_request/url_request_context_builder.h"
26 26
27 // XXX should it be defined(OS_LINUX) || defined(OS_CHROMEOS) ?
28 #if defined(USE_NSS_CERTS)
29 #include "base/threading/thread_task_runner_handle.h"
30 #include "net/cert/internal/trust_store_nss.h"
31 #endif
32
27 #if defined(OS_LINUX) 33 #if defined(OS_LINUX)
28 #include "net/proxy/proxy_config.h" 34 #include "net/proxy/proxy_config.h"
29 #include "net/proxy/proxy_config_service_fixed.h" 35 #include "net/proxy/proxy_config_service_fixed.h"
30 #endif 36 #endif
31 37
32 namespace { 38 namespace {
33 39
34 std::string GetUserAgent() { 40 std::string GetUserAgent() {
35 return "cert_verify_tool/0.1"; 41 return "cert_verify_tool/0.1";
36 } 42 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 92
87 } // namespace 93 } // namespace
88 94
89 // Verifies |target_der_cert| using CertPathBuilder. 95 // Verifies |target_der_cert| using CertPathBuilder.
90 bool VerifyUsingPathBuilder( 96 bool VerifyUsingPathBuilder(
91 const CertInput& target_der_cert, 97 const CertInput& target_der_cert,
92 const std::vector<CertInput>& intermediate_der_certs, 98 const std::vector<CertInput>& intermediate_der_certs,
93 const std::vector<CertInput>& root_der_certs, 99 const std::vector<CertInput>& root_der_certs,
94 const base::Time at_time, 100 const base::Time at_time,
95 const base::FilePath& dump_prefix_path) { 101 const base::FilePath& dump_prefix_path) {
96 std::cout << "NOTE: CertPathBuilder does not currently use OS trust settings "
97 "(--roots must be specified).\n";
98 std::cerr << "WARNING: --hostname is not yet verified with CertPathBuilder\n"; 102 std::cerr << "WARNING: --hostname is not yet verified with CertPathBuilder\n";
99 103
100 base::Time::Exploded exploded_time; 104 base::Time::Exploded exploded_time;
101 at_time.UTCExplode(&exploded_time); 105 at_time.UTCExplode(&exploded_time);
102 net::der::GeneralizedTime time = ConvertExplodedTime(exploded_time); 106 net::der::GeneralizedTime time = ConvertExplodedTime(exploded_time);
103 107
104 net::TrustStore trust_store; 108 #if defined(USE_NSS_CERTS)
109 net::TrustStoreNSS trust_store_nss(base::ThreadTaskRunnerHandle::Get());
110 #else
111 std::cout << "NOTE: CertPathBuilder does not currently use OS trust settings "
112 "(--roots must be specified).\n";
113 #endif
114 net::TrustStoreStatic trust_store_static;
105 for (const auto& der_cert : root_der_certs) { 115 for (const auto& der_cert : root_der_certs) {
106 scoped_refptr<net::ParsedCertificate> cert = 116 scoped_refptr<net::ParsedCertificate> cert =
107 net::ParsedCertificate::CreateFromCertificateCopy(der_cert.der_cert, 117 net::ParsedCertificate::CreateFromCertificateCopy(der_cert.der_cert,
108 {}); 118 {});
109 if (!cert) 119 if (!cert)
110 PrintCertError("ERROR: ParsedCertificate failed:", der_cert); 120 PrintCertError("ERROR: ParsedCertificate failed:", der_cert);
111 else 121 else
112 trust_store.AddTrustedCertificate(cert); 122 trust_store_static.AddTrustedCertificate(cert);
113 } 123 }
114 124
115 net::CertIssuerSourceStatic intermediate_cert_issuer_source; 125 net::CertIssuerSourceStatic intermediate_cert_issuer_source;
116 for (const auto& der_cert : intermediate_der_certs) { 126 for (const auto& der_cert : intermediate_der_certs) {
117 scoped_refptr<net::ParsedCertificate> cert = 127 scoped_refptr<net::ParsedCertificate> cert =
118 net::ParsedCertificate::CreateFromCertificateCopy(der_cert.der_cert, 128 net::ParsedCertificate::CreateFromCertificateCopy(der_cert.der_cert,
119 {}); 129 {});
120 if (!cert) 130 if (!cert)
121 PrintCertError("ERROR: ParsedCertificate failed:", der_cert); 131 PrintCertError("ERROR: ParsedCertificate failed:", der_cert);
122 else 132 else
123 intermediate_cert_issuer_source.AddCert(cert); 133 intermediate_cert_issuer_source.AddCert(cert);
124 } 134 }
125 135
126 scoped_refptr<net::ParsedCertificate> target_cert = 136 scoped_refptr<net::ParsedCertificate> target_cert =
127 net::ParsedCertificate::CreateFromCertificateCopy( 137 net::ParsedCertificate::CreateFromCertificateCopy(
128 target_der_cert.der_cert, {}); 138 target_der_cert.der_cert, {});
129 if (!target_cert) { 139 if (!target_cert) {
130 PrintCertError("ERROR: ParsedCertificate failed:", target_der_cert); 140 PrintCertError("ERROR: ParsedCertificate failed:", target_der_cert);
131 return false; 141 return false;
132 } 142 }
133 143
134 // Verify the chain. 144 // Verify the chain.
135 net::SimpleSignaturePolicy signature_policy(2048); 145 net::SimpleSignaturePolicy signature_policy(2048);
136 net::CertPathBuilder::Result result; 146 net::CertPathBuilder::Result result;
137 net::CertPathBuilder path_builder(target_cert, &trust_store, 147 net::CertPathBuilder path_builder(target_cert, &signature_policy, time,
138 &signature_policy, time, &result); 148 &result);
149 path_builder.AddTrustStore(&trust_store_static);
150 #if defined(USE_NSS_CERTS)
151 path_builder.AddTrustStore(&trust_store_nss);
152 #endif
139 path_builder.AddCertIssuerSource(&intermediate_cert_issuer_source); 153 path_builder.AddCertIssuerSource(&intermediate_cert_issuer_source);
140 154
141 // TODO(mattm): add command line flags to configure using CertIssuerSourceAia 155 // TODO(mattm): add command line flags to configure using CertIssuerSourceAia
142 // (similar to VERIFY_CERT_IO_ENABLED flag for CertVerifyProc). 156 // (similar to VERIFY_CERT_IO_ENABLED flag for CertVerifyProc).
143 net::URLRequestContextBuilder url_request_context_builder; 157 net::URLRequestContextBuilder url_request_context_builder;
144 url_request_context_builder.set_user_agent(GetUserAgent()); 158 url_request_context_builder.set_user_agent(GetUserAgent());
145 #if defined(OS_LINUX) 159 #if defined(OS_LINUX)
146 // On Linux, use a fixed ProxyConfigService, since the default one 160 // On Linux, use a fixed ProxyConfigService, since the default one
147 // depends on glib. 161 // depends on glib.
148 // 162 //
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 if (!DumpParsedCertificateChain( 197 if (!DumpParsedCertificateChain(
184 dump_prefix_path.AddExtension( 198 dump_prefix_path.AddExtension(
185 FILE_PATH_LITERAL(".CertPathBuilder.pem")), 199 FILE_PATH_LITERAL(".CertPathBuilder.pem")),
186 result.paths[result.best_result_index]->path)) { 200 result.paths[result.best_result_index]->path)) {
187 return false; 201 return false;
188 } 202 }
189 } 203 }
190 204
191 return result.error() == net::OK; 205 return result.error() == net::OK;
192 } 206 }
OLDNEW
« no previous file with comments | « net/net.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698