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

Side by Side Diff: chromeos/network/network_connection_handler.cc

Issue 135193007: Use user specific NSSDatabase in CertLoader. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chromeos/network/network_connection_handler.h" 5 #include "chromeos/network/network_connection_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "chromeos/chromeos_switches.h" 12 #include "chromeos/chromeos_switches.h"
13 #include "chromeos/dbus/dbus_thread_manager.h" 13 #include "chromeos/dbus/dbus_thread_manager.h"
14 #include "chromeos/dbus/shill_manager_client.h" 14 #include "chromeos/dbus/shill_manager_client.h"
15 #include "chromeos/dbus/shill_service_client.h" 15 #include "chromeos/dbus/shill_service_client.h"
16 #include "chromeos/network/client_cert_util.h" 16 #include "chromeos/network/client_cert_util.h"
17 #include "chromeos/network/network_configuration_handler.h" 17 #include "chromeos/network/network_configuration_handler.h"
18 #include "chromeos/network/network_event_log.h" 18 #include "chromeos/network/network_event_log.h"
19 #include "chromeos/network/network_handler_callbacks.h" 19 #include "chromeos/network/network_handler_callbacks.h"
20 #include "chromeos/network/network_profile_handler.h" 20 #include "chromeos/network/network_profile_handler.h"
21 #include "chromeos/network/network_state.h" 21 #include "chromeos/network/network_state.h"
22 #include "chromeos/network/network_state_handler.h" 22 #include "chromeos/network/network_state_handler.h"
23 #include "chromeos/network/network_ui_data.h" 23 #include "chromeos/network/network_ui_data.h"
24 #include "chromeos/network/shill_property_util.h" 24 #include "chromeos/network/shill_property_util.h"
25 #include "chromeos/tpm_token_loader.h"
25 #include "dbus/object_path.h" 26 #include "dbus/object_path.h"
26 #include "net/cert/x509_certificate.h" 27 #include "net/cert/x509_certificate.h"
27 #include "third_party/cros_system_api/dbus/service_constants.h" 28 #include "third_party/cros_system_api/dbus/service_constants.h"
28 29
29 namespace chromeos { 30 namespace chromeos {
30 31
31 namespace { 32 namespace {
32 33
33 void InvokeErrorCallback(const std::string& service_path, 34 void InvokeErrorCallback(const std::string& service_path,
34 const network_handler::ErrorCallback& error_callback, 35 const network_handler::ErrorCallback& error_callback,
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } 185 }
185 186
186 void NetworkConnectionHandler::OnCertificatesLoaded( 187 void NetworkConnectionHandler::OnCertificatesLoaded(
187 const net::CertificateList& cert_list, 188 const net::CertificateList& cert_list,
188 bool initial_load) { 189 bool initial_load) {
189 certificates_loaded_ = true; 190 certificates_loaded_ = true;
190 NET_LOG_EVENT("Certificates Loaded", ""); 191 NET_LOG_EVENT("Certificates Loaded", "");
191 if (queued_connect_) { 192 if (queued_connect_) {
192 NET_LOG_EVENT("Connecting to Queued Network", 193 NET_LOG_EVENT("Connecting to Queued Network",
193 queued_connect_->service_path); 194 queued_connect_->service_path);
194 ConnectToNetwork(queued_connect_->service_path, 195 // Make a copy of |queued_connect_| parameters, because |queued_connect_|
195 queued_connect_->success_callback, 196 // will get reset at the beginning of |ConnectToNetwork|.
stevenjb 2014/01/23 18:17:42 Ugh. Subtle. Good catch, thanks.
196 queued_connect_->error_callback, 197 std::string service_path = queued_connect_->service_path;
198 base::Closure success_callback = queued_connect_->success_callback;
199 network_handler::ErrorCallback error_callback =
200 queued_connect_->error_callback;
201
202 ConnectToNetwork(service_path, success_callback, error_callback,
197 false /* check_error_state */); 203 false /* check_error_state */);
198 } else if (initial_load) { 204 } else if (initial_load) {
199 // Once certificates have loaded, connect to the "best" available network. 205 // Once certificates have loaded, connect to the "best" available network.
200 network_state_handler_->ConnectToBestWifiNetwork(); 206 network_state_handler_->ConnectToBestWifiNetwork();
201 } 207 }
202 } 208 }
203 209
204 void NetworkConnectionHandler::ConnectToNetwork( 210 void NetworkConnectionHandler::ConnectToNetwork(
205 const std::string& service_path, 211 const std::string& service_path,
206 const base::Closure& success_callback, 212 const base::Closure& success_callback,
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 return; 423 return;
418 } 424 }
419 NET_LOG_EVENT("Connect Request Queued", service_path); 425 NET_LOG_EVENT("Connect Request Queued", service_path);
420 queued_connect_.reset(new ConnectRequest( 426 queued_connect_.reset(new ConnectRequest(
421 service_path, request->profile_path, 427 service_path, request->profile_path,
422 request->success_callback, request->error_callback)); 428 request->success_callback, request->error_callback));
423 pending_requests_.erase(service_path); 429 pending_requests_.erase(service_path);
424 return; 430 return;
425 } 431 }
426 432
427 pkcs11_id = CertificateIsConfigured(ui_data.get()); 433 pkcs11_id = CertificateIsConfigured(ui_data.get(),
434 cert_loader_->cert_list());
428 // Ensure the certificate is available and configured. 435 // Ensure the certificate is available and configured.
429 if (!cert_loader_->IsHardwareBacked() || pkcs11_id.empty()) { 436 if (!cert_loader_->is_hardware_backed() || pkcs11_id.empty()) {
430 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); 437 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired);
431 return; 438 return;
432 } 439 }
433 } else if (check_error_state && 440 } else if (check_error_state &&
434 !client_cert::IsCertificateConfigured(client_cert_type, 441 !client_cert::IsCertificateConfigured(client_cert_type,
435 service_properties)) { 442 service_properties)) {
436 // Network may not be configured. 443 // Network may not be configured.
437 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); 444 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired);
438 return; 445 return;
439 } 446 }
440 447
441 // The network may not be 'Connectable' because the TPM properties are not 448 // The network may not be 'Connectable' because the TPM properties are not
442 // set up, so configure tpm slot/pin before connecting. 449 // set up, so configure tpm slot/pin before connecting.
443 if (cert_loader_ && cert_loader_->IsHardwareBacked()) { 450 if (cert_loader_ && cert_loader_->is_hardware_backed()) {
451 std::string tpm_user_pin;
452 if (TPMTokenLoader::IsInitialized())
stevenjb 2014/01/23 18:17:42 Again, can a cert be hardware backed and TPMTokenL
tbarzic 2014/01/23 19:18:37 Done.
453 tpm_user_pin = TPMTokenLoader::Get()->tpm_user_pin();
444 // Pass NULL if pkcs11_id is empty, so that it doesn't clear any 454 // Pass NULL if pkcs11_id is empty, so that it doesn't clear any
445 // previously configured client cert. 455 // previously configured client cert.
446 client_cert::SetShillProperties( 456 client_cert::SetShillProperties(
447 client_cert_type, 457 client_cert_type,
448 base::IntToString(cert_loader_->tpm_token_slot_id()), 458 base::IntToString(cert_loader_->tpm_token_slot_id()),
449 cert_loader_->tpm_user_pin(), 459 tpm_user_pin,
450 pkcs11_id.empty() ? NULL : &pkcs11_id, 460 pkcs11_id.empty() ? NULL : &pkcs11_id,
451 &config_properties); 461 &config_properties);
452 } 462 }
453 } 463 }
454 464
455 if (type == shill::kTypeVPN) { 465 if (type == shill::kTypeVPN) {
456 // VPN may require a username, and/or passphrase to be set. (Check after 466 // VPN may require a username, and/or passphrase to be set. (Check after
457 // ensuring that any required certificates are configured). 467 // ensuring that any required certificates are configured).
458 DCHECK(provider_properties); 468 DCHECK(provider_properties);
459 if (VPNRequiresCredentials( 469 if (VPNRequiresCredentials(
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 } 624 }
615 625
616 void NetworkConnectionHandler::CheckAllPendingRequests() { 626 void NetworkConnectionHandler::CheckAllPendingRequests() {
617 for (std::map<std::string, ConnectRequest>::iterator iter = 627 for (std::map<std::string, ConnectRequest>::iterator iter =
618 pending_requests_.begin(); iter != pending_requests_.end(); ++iter) { 628 pending_requests_.begin(); iter != pending_requests_.end(); ++iter) {
619 CheckPendingRequest(iter->first); 629 CheckPendingRequest(iter->first);
620 } 630 }
621 } 631 }
622 632
623 std::string NetworkConnectionHandler::CertificateIsConfigured( 633 std::string NetworkConnectionHandler::CertificateIsConfigured(
624 NetworkUIData* ui_data) { 634 NetworkUIData* ui_data,
635 const net::CertificateList& cert_list) {
625 if (ui_data->certificate_pattern().Empty()) 636 if (ui_data->certificate_pattern().Empty())
626 return std::string(); 637 return std::string();
627 // Find the matching certificate. 638 // Find the matching certificate.
628 scoped_refptr<net::X509Certificate> matching_cert = 639 scoped_refptr<net::X509Certificate> matching_cert =
629 client_cert::GetCertificateMatch(ui_data->certificate_pattern()); 640 client_cert::GetCertificateMatch(ui_data->certificate_pattern(),
641 cert_list);
630 if (!matching_cert.get()) 642 if (!matching_cert.get())
631 return std::string(); 643 return std::string();
632 return CertLoader::GetPkcs11IdForCert(*matching_cert.get()); 644 return CertLoader::GetPkcs11IdForCert(*matching_cert.get());
633 } 645 }
634 646
635 void NetworkConnectionHandler::ErrorCallbackForPendingRequest( 647 void NetworkConnectionHandler::ErrorCallbackForPendingRequest(
636 const std::string& service_path, 648 const std::string& service_path,
637 const std::string& error_name) { 649 const std::string& error_name) {
638 ConnectRequest* request = GetPendingRequest(service_path); 650 ConnectRequest* request = GetPendingRequest(service_path);
639 if (!request) { 651 if (!request) {
(...skipping 24 matching lines...) Expand all
664 676
665 void NetworkConnectionHandler::HandleShillDisconnectSuccess( 677 void NetworkConnectionHandler::HandleShillDisconnectSuccess(
666 const std::string& service_path, 678 const std::string& service_path,
667 const base::Closure& success_callback) { 679 const base::Closure& success_callback) {
668 NET_LOG_EVENT("Disconnect Request Sent", service_path); 680 NET_LOG_EVENT("Disconnect Request Sent", service_path);
669 if (!success_callback.is_null()) 681 if (!success_callback.is_null())
670 success_callback.Run(); 682 success_callback.Run();
671 } 683 }
672 684
673 } // namespace chromeos 685 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698