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

Side by Side Diff: chrome/browser/chrome_content_browser_client.cc

Issue 2898573002: Refactor client cert private key handling. (Closed)
Patch Set: rebase Created 3 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/chrome_content_browser_client.h" 5 #include "chrome/browser/chrome_content_browser_client.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 2252 matching lines...) Expand 10 before | Expand all | Expand 10 after
2263 new CertificateReportingServiceCertReporter(cert_reporting_service)); 2263 new CertificateReportingServiceCertReporter(cert_reporting_service));
2264 2264
2265 SSLErrorHandler::HandleSSLError(web_contents, cert_error, ssl_info, 2265 SSLErrorHandler::HandleSSLError(web_contents, cert_error, ssl_info,
2266 request_url, options_mask, 2266 request_url, options_mask,
2267 std::move(cert_reporter), callback); 2267 std::move(cert_reporter), callback);
2268 } 2268 }
2269 2269
2270 void ChromeContentBrowserClient::SelectClientCertificate( 2270 void ChromeContentBrowserClient::SelectClientCertificate(
2271 content::WebContents* web_contents, 2271 content::WebContents* web_contents,
2272 net::SSLCertRequestInfo* cert_request_info, 2272 net::SSLCertRequestInfo* cert_request_info,
2273 net::CertificateList client_certs, 2273 net::ClientCertIdentityList client_certs,
2274 std::unique_ptr<content::ClientCertificateDelegate> delegate) { 2274 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
2275 prerender::PrerenderContents* prerender_contents = 2275 prerender::PrerenderContents* prerender_contents =
2276 prerender::PrerenderContents::FromWebContents(web_contents); 2276 prerender::PrerenderContents::FromWebContents(web_contents);
2277 if (prerender_contents) { 2277 if (prerender_contents) {
2278 prerender_contents->Destroy( 2278 prerender_contents->Destroy(
2279 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED); 2279 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
2280 return; 2280 return;
2281 } 2281 }
2282 2282
2283 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString()); 2283 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
2284 DCHECK(requesting_url.is_valid()) 2284 DCHECK(requesting_url.is_valid())
2285 << "Invalid URL string: https://" 2285 << "Invalid URL string: https://"
2286 << cert_request_info->host_and_port.ToString(); 2286 << cert_request_info->host_and_port.ToString();
2287 2287
2288 Profile* profile = 2288 Profile* profile =
2289 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 2289 Profile::FromBrowserContext(web_contents->GetBrowserContext());
2290 std::unique_ptr<base::Value> filter = 2290 std::unique_ptr<base::Value> filter =
2291 HostContentSettingsMapFactory::GetForProfile(profile)->GetWebsiteSetting( 2291 HostContentSettingsMapFactory::GetForProfile(profile)->GetWebsiteSetting(
2292 requesting_url, requesting_url, 2292 requesting_url, requesting_url,
2293 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), NULL); 2293 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), NULL);
2294 2294
2295 if (filter.get()) { 2295 if (filter.get()) {
2296 // Try to automatically select a client certificate. 2296 // Try to automatically select a client certificate.
2297 if (filter->IsType(base::Value::Type::DICTIONARY)) { 2297 if (filter->IsType(base::Value::Type::DICTIONARY)) {
2298 base::DictionaryValue* filter_dict = 2298 base::DictionaryValue* filter_dict =
2299 static_cast<base::DictionaryValue*>(filter.get()); 2299 static_cast<base::DictionaryValue*>(filter.get());
2300 2300
2301 for (size_t i = 0; i < client_certs.size(); ++i) { 2301 for (size_t i = 0; i < client_certs.size(); ++i) {
2302 if (CertMatchesFilter(*client_certs[i].get(), *filter_dict)) { 2302 if (CertMatchesFilter(*client_certs[i]->certificate(), *filter_dict)) {
2303 // Use the first certificate that is matched by the filter. 2303 // Use the first certificate that is matched by the filter.
2304 delegate->ContinueWithCertificate(client_certs[i].get()); 2304 // The callback will own |client_certs[i]| and |delegate|, keeping
2305 // them alive until after ContinueWithCertificate is called.
2306 scoped_refptr<net::X509Certificate> cert =
2307 client_certs[i]->certificate();
2308 net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
2309 std::move(client_certs[i]),
2310 base::Bind(
2311 &content::ClientCertificateDelegate::ContinueWithCertificate,
2312 base::Passed(&delegate), std::move(cert)));
2305 return; 2313 return;
2306 } 2314 }
2307 } 2315 }
2308 } else { 2316 } else {
2309 NOTREACHED(); 2317 NOTREACHED();
2310 } 2318 }
2311 } 2319 }
2312 2320
2313 chrome::ShowSSLClientCertificateSelector(web_contents, cert_request_info, 2321 chrome::ShowSSLClientCertificateSelector(web_contents, cert_request_info,
2314 std::move(client_certs), 2322 std::move(client_certs),
(...skipping 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after
3441 RedirectNonUINonIOBrowserThreadsToTaskScheduler() { 3449 RedirectNonUINonIOBrowserThreadsToTaskScheduler() {
3442 return variations::GetVariationParamValue( 3450 return variations::GetVariationParamValue(
3443 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true"; 3451 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true";
3444 } 3452 }
3445 3453
3446 // static 3454 // static
3447 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( 3455 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting(
3448 const storage::QuotaSettings* settings) { 3456 const storage::QuotaSettings* settings) {
3449 g_default_quota_settings = settings; 3457 g_default_quota_settings = settings;
3450 } 3458 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698