| OLD | NEW |
| 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/cert_loader.h" |
| 12 #include "chromeos/chromeos_switches.h" | 13 #include "chromeos/chromeos_switches.h" |
| 13 #include "chromeos/dbus/dbus_thread_manager.h" | 14 #include "chromeos/dbus/dbus_thread_manager.h" |
| 14 #include "chromeos/dbus/shill_manager_client.h" | 15 #include "chromeos/dbus/shill_manager_client.h" |
| 15 #include "chromeos/dbus/shill_service_client.h" | 16 #include "chromeos/dbus/shill_service_client.h" |
| 16 #include "chromeos/network/client_cert_util.h" | 17 #include "chromeos/network/client_cert_util.h" |
| 17 #include "chromeos/network/network_configuration_handler.h" | 18 #include "chromeos/network/network_configuration_handler.h" |
| 18 #include "chromeos/network/network_event_log.h" | 19 #include "chromeos/network/network_event_log.h" |
| 19 #include "chromeos/network/network_handler_callbacks.h" | 20 #include "chromeos/network/network_handler_callbacks.h" |
| 20 #include "chromeos/network/network_profile_handler.h" | 21 #include "chromeos/network/network_profile_handler.h" |
| 21 #include "chromeos/network/network_state.h" | 22 #include "chromeos/network/network_state.h" |
| 22 #include "chromeos/network/network_state_handler.h" | 23 #include "chromeos/network/network_state_handler.h" |
| 23 #include "chromeos/network/network_ui_data.h" | 24 #include "chromeos/network/network_ui_data.h" |
| 24 #include "chromeos/network/shill_property_util.h" | 25 #include "chromeos/network/shill_property_util.h" |
| 26 #include "chromeos/tpm_token_loader.h" |
| 25 #include "dbus/object_path.h" | 27 #include "dbus/object_path.h" |
| 26 #include "net/cert/x509_certificate.h" | 28 #include "net/cert/x509_certificate.h" |
| 27 #include "third_party/cros_system_api/dbus/service_constants.h" | 29 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 28 | 30 |
| 29 namespace chromeos { | 31 namespace chromeos { |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| 32 | 34 |
| 33 void InvokeErrorCallback(const std::string& service_path, | 35 void InvokeErrorCallback(const std::string& service_path, |
| 34 const network_handler::ErrorCallback& error_callback, | 36 const network_handler::ErrorCallback& error_callback, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 LoginState::Get()->RemoveObserver(this); | 156 LoginState::Get()->RemoveObserver(this); |
| 155 } | 157 } |
| 156 | 158 |
| 157 void NetworkConnectionHandler::Init( | 159 void NetworkConnectionHandler::Init( |
| 158 NetworkStateHandler* network_state_handler, | 160 NetworkStateHandler* network_state_handler, |
| 159 NetworkConfigurationHandler* network_configuration_handler) { | 161 NetworkConfigurationHandler* network_configuration_handler) { |
| 160 if (LoginState::IsInitialized()) { | 162 if (LoginState::IsInitialized()) { |
| 161 LoginState::Get()->AddObserver(this); | 163 LoginState::Get()->AddObserver(this); |
| 162 logged_in_ = LoginState::Get()->IsUserLoggedIn(); | 164 logged_in_ = LoginState::Get()->IsUserLoggedIn(); |
| 163 } | 165 } |
| 164 if (CertLoader::IsInitialized()) { | 166 |
| 165 cert_loader_ = CertLoader::Get(); | 167 cert_loader_ = CertLoader::Get(); |
| 166 cert_loader_->AddObserver(this); | 168 cert_loader_->AddObserver(this); |
| 167 certificates_loaded_ = cert_loader_->certificates_loaded(); | 169 certificates_loaded_ = cert_loader_->certificates_loaded(); |
| 168 } else { | 170 |
| 169 // TODO(stevenjb): Require a mock or stub cert_loader in tests. | |
| 170 certificates_loaded_ = true; | |
| 171 } | |
| 172 if (network_state_handler) { | 171 if (network_state_handler) { |
| 173 network_state_handler_ = network_state_handler; | 172 network_state_handler_ = network_state_handler; |
| 174 network_state_handler_->AddObserver(this, FROM_HERE); | 173 network_state_handler_->AddObserver(this, FROM_HERE); |
| 175 } | 174 } |
| 176 network_configuration_handler_ = network_configuration_handler; | 175 network_configuration_handler_ = network_configuration_handler; |
| 177 } | 176 } |
| 178 | 177 |
| 179 void NetworkConnectionHandler::LoggedInStateChanged() { | 178 void NetworkConnectionHandler::LoggedInStateChanged() { |
| 180 if (LoginState::Get()->IsUserLoggedIn()) { | 179 if (LoginState::Get()->IsUserLoggedIn()) { |
| 181 logged_in_ = true; | 180 logged_in_ = true; |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 return; | 443 return; |
| 445 } | 444 } |
| 446 | 445 |
| 447 // The network may not be 'Connectable' because the TPM properties are not | 446 // The network may not be 'Connectable' because the TPM properties are not |
| 448 // set up, so configure tpm slot/pin before connecting. | 447 // set up, so configure tpm slot/pin before connecting. |
| 449 if (cert_loader_ && cert_loader_->IsHardwareBacked()) { | 448 if (cert_loader_ && cert_loader_->IsHardwareBacked()) { |
| 450 // Pass NULL if pkcs11_id is empty, so that it doesn't clear any | 449 // Pass NULL if pkcs11_id is empty, so that it doesn't clear any |
| 451 // previously configured client cert. | 450 // previously configured client cert. |
| 452 client_cert::SetShillProperties( | 451 client_cert::SetShillProperties( |
| 453 client_cert_type, | 452 client_cert_type, |
| 454 base::IntToString(cert_loader_->tpm_token_slot_id()), | 453 base::IntToString(cert_loader_->TPMTokenSlotID()), |
| 455 cert_loader_->tpm_user_pin(), | 454 TPMTokenLoader::Get()->tpm_user_pin(), |
| 456 pkcs11_id.empty() ? NULL : &pkcs11_id, | 455 pkcs11_id.empty() ? NULL : &pkcs11_id, |
| 457 &config_properties); | 456 &config_properties); |
| 458 } | 457 } |
| 459 } | 458 } |
| 460 | 459 |
| 461 if (type == shill::kTypeVPN) { | 460 if (type == shill::kTypeVPN) { |
| 462 // VPN may require a username, and/or passphrase to be set. (Check after | 461 // VPN may require a username, and/or passphrase to be set. (Check after |
| 463 // ensuring that any required certificates are configured). | 462 // ensuring that any required certificates are configured). |
| 464 DCHECK(provider_properties); | 463 DCHECK(provider_properties); |
| 465 if (VPNRequiresCredentials( | 464 if (VPNRequiresCredentials( |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 CheckPendingRequest(iter->first); | 624 CheckPendingRequest(iter->first); |
| 626 } | 625 } |
| 627 } | 626 } |
| 628 | 627 |
| 629 std::string NetworkConnectionHandler::CertificateIsConfigured( | 628 std::string NetworkConnectionHandler::CertificateIsConfigured( |
| 630 NetworkUIData* ui_data) { | 629 NetworkUIData* ui_data) { |
| 631 if (ui_data->certificate_pattern().Empty()) | 630 if (ui_data->certificate_pattern().Empty()) |
| 632 return std::string(); | 631 return std::string(); |
| 633 // Find the matching certificate. | 632 // Find the matching certificate. |
| 634 scoped_refptr<net::X509Certificate> matching_cert = | 633 scoped_refptr<net::X509Certificate> matching_cert = |
| 635 client_cert::GetCertificateMatch(ui_data->certificate_pattern()); | 634 client_cert::GetCertificateMatch(ui_data->certificate_pattern(), |
| 635 cert_loader_->cert_list()); |
| 636 if (!matching_cert.get()) | 636 if (!matching_cert.get()) |
| 637 return std::string(); | 637 return std::string(); |
| 638 return CertLoader::GetPkcs11IdForCert(*matching_cert.get()); | 638 return CertLoader::GetPkcs11IdForCert(*matching_cert.get()); |
| 639 } | 639 } |
| 640 | 640 |
| 641 void NetworkConnectionHandler::ErrorCallbackForPendingRequest( | 641 void NetworkConnectionHandler::ErrorCallbackForPendingRequest( |
| 642 const std::string& service_path, | 642 const std::string& service_path, |
| 643 const std::string& error_name) { | 643 const std::string& error_name) { |
| 644 ConnectRequest* request = GetPendingRequest(service_path); | 644 ConnectRequest* request = GetPendingRequest(service_path); |
| 645 if (!request) { | 645 if (!request) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 670 | 670 |
| 671 void NetworkConnectionHandler::HandleShillDisconnectSuccess( | 671 void NetworkConnectionHandler::HandleShillDisconnectSuccess( |
| 672 const std::string& service_path, | 672 const std::string& service_path, |
| 673 const base::Closure& success_callback) { | 673 const base::Closure& success_callback) { |
| 674 NET_LOG_EVENT("Disconnect Request Sent", service_path); | 674 NET_LOG_EVENT("Disconnect Request Sent", service_path); |
| 675 if (!success_callback.is_null()) | 675 if (!success_callback.is_null()) |
| 676 success_callback.Run(); | 676 success_callback.Run(); |
| 677 } | 677 } |
| 678 | 678 |
| 679 } // namespace chromeos | 679 } // namespace chromeos |
| OLD | NEW |